Advertisement
Guest User

Untitled

a guest
Sep 13th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.09 KB | None | 0 0
  1. package net.minedev.cronikkk.economycraft;
  2.  
  3. import java.io.File;
  4. import java.net.MalformedURLException;
  5. import java.util.logging.Logger;
  6.  
  7. import org.bukkit.event.Event;
  8. import org.bukkit.plugin.Plugin;
  9. import org.bukkit.plugin.PluginDescriptionFile;
  10. import org.bukkit.plugin.PluginManager;
  11. import org.bukkit.plugin.java.JavaPlugin;
  12. import com.alta189.sqlLibrary.MySQL.*;
  13. import com.nijiko.permissions.PermissionHandler;
  14. import com.nijikokun.bukkit.Permissions.Permissions;
  15.  
  16. import net.minedev.cronikkk.economycraft.SettingsHandler;
  17.  
  18. public class EconomyCraft extends JavaPlugin{
  19.     public mysqlCore dbManager;
  20.     public String logPrefix = "[EconomyCraft] ";
  21.     public File pFolder = new File("plugins/EconomyCraft");
  22.     public Logger log = Logger.getLogger("Minecraft");
  23.     public static PermissionHandler permissionHandler;
  24.     public SettingsHandler settings = new SettingsHandler("settings.properties", "plugins/EconomyCraft/settings.properties");
  25.     public MoneyFunctions functions = new MoneyFunctions(this);
  26.    
  27.    
  28.     //MySQL Details Variables\\
  29.     public String dbHost = null;
  30.     public String dbUser = null;
  31.     public String dbPass = null;
  32.     public String dbName = null;
  33.    
  34.     //Money Variables
  35.     public String currencyName;
  36.     public int startingMoney;
  37.    
  38.     @Override
  39.     public void onEnable() {
  40.         // Get Version Etc
  41.         PluginDescriptionFile pdfFile = this.getDescription();
  42.        
  43.         //Plugin Manager
  44.         PluginManager pm = this.getServer().getPluginManager();
  45.        
  46.         //Register Events
  47.         pm.registerEvent(Event.Type.PLAYER_JOIN, new ECraftPlayerListener(this), Event.Priority.Normal, this);
  48.        
  49.         // Load Settings
  50.         this.createPluginFolder();
  51.         settings.load();
  52.        
  53.        
  54.         //Money Variables Define
  55.         currencyName = this.settings.getPropertyString("currencyname");
  56.         startingMoney = this.settings.getPropertyInteger("startingcurrency");
  57.        
  58.         //Check if settings file is existant
  59.         if(settings.file.exists()) {
  60.             //Get Database information
  61.             dbHost = this.settings.getPropertyString("dbhost");
  62.             dbUser = this.settings.getPropertyString("dbuser");
  63.             dbPass = this.settings.getPropertyString("dbpass");
  64.             dbName = this.settings.getPropertyString("dbname");
  65.            
  66.             //Create core
  67.             dbManager = new mysqlCore(log, logPrefix, dbHost, dbName, dbUser, dbPass);
  68.             log.info(logPrefix + "Initializing EconomyCraft MySQL!");
  69.             dbManager.initialize();
  70.            
  71.             try {
  72.                 //Connect to mysql (test it)
  73.                 if(dbManager.checkConnection()){
  74.                     log.info(logPrefix + "MySQL Connection Successful!");
  75.                     if(!dbManager.checkTable("users")) {
  76.                         log.info(logPrefix + "Creating Users Table..");
  77.                         String query = "CREATE TABLE users (id INT AUTO_INCREMENT PRIMARY KEY, player VARCHAR(80), money INT);";
  78.                         dbManager.createTable(query);
  79.                         log.info(logPrefix + "MySQL Initilized!");
  80.                     }
  81.                 } else {
  82.                     log.severe(logPrefix + "MySQL Connection Failed...");
  83.                 }
  84.             } catch (MalformedURLException e) {
  85.                 // TODO Auto-generated catch block
  86.                 e.printStackTrace();
  87.             } catch (InstantiationException e) {
  88.                 // TODO Auto-generated catch block
  89.                 e.printStackTrace();
  90.             } catch (IllegalAccessException e) {
  91.                 // TODO Auto-generated catch block
  92.                 e.printStackTrace();
  93.             }
  94.         }
  95.        
  96.         //Initiate permissions
  97.         setupPermissions();
  98.         log.info(logPrefix + "Permissions initated.");
  99.         log.info(logPrefix + "v" + pdfFile.getVersion() + " started!");
  100.        
  101.         //Register commands
  102.         getCommand("balance").setExecutor(new ECraftCommandHandler(this));
  103.         getCommand("money").setExecutor(new ECraftCommandHandler(this));
  104.     }
  105.    
  106.     @Override
  107.     public void onDisable() {
  108.        
  109.     }
  110.    
  111.     private void setupPermissions() {
  112.         Plugin permissionsPlugin = this.getServer().getPluginManager().getPlugin("Permissions");
  113.  
  114.         if (EconomyCraft.permissionHandler == null) {
  115.             if (permissionsPlugin != null) {
  116.                 EconomyCraft.permissionHandler = ((Permissions) permissionsPlugin).getHandler();
  117.             } else {
  118.                 log.info("Permission system not detected! ITS REQUIRED FOR THIS PLUGIN!");
  119.             }
  120.         }
  121.     }
  122.    
  123.     public void createPluginFolder() {
  124.         if (!this.pFolder.exists()) {
  125.             pFolder.mkdir();
  126.         }
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement