SHARE
TWEET

Untitled

a guest Dec 23rd, 2017 21 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package fr.jsonarray.skyhandreward;
  2.  
  3. import fr.jsonarray.skyhandreward.commands.SkyHandRewardCommands;
  4. import fr.jsonarray.skyhandreward.configurations.PlayerDataConfiguration;
  5. import fr.jsonarray.skyhandreward.data.RewardData;
  6. import fr.jsonarray.skyhandreward.data.SHRPlayer;
  7. import fr.jsonarray.skyhandreward.listeners.PlayerListeners;
  8. import fr.jsonarray.skyhandreward.runnable.SkyHandRewardRunnable;
  9. import fr.jsonarray.skyhandreward.sql.PlayerDataSQL;
  10. import fr.jsonarray.skyhandreward.sql.SQLConnection;
  11. import fr.jsonarray.skyhandreward.utils.FileManager;
  12. import org.bukkit.Bukkit;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.plugin.java.JavaPlugin;
  15.  
  16. import java.util.Arrays;
  17.  
  18. public class SkyHandReward extends JavaPlugin {
  19.  
  20.     private static SkyHandReward instance;
  21.     public FileManager fileManager;
  22.     public SQLConnection sqlConnection;
  23.  
  24.     public void onEnable() {
  25.         instance = this;
  26.         fileManager = new FileManager(this);
  27.         sqlConnection = new SQLConnection();
  28.  
  29.         registerListeners();
  30.  
  31.         PlayerDataConfiguration.setupConfig();
  32.         getConfig().options().copyDefaults(false);
  33.         saveConfig();
  34.  
  35.         setConfigType();
  36.  
  37.         getCommand("SkyHandReward").setExecutor(new SkyHandRewardCommands());
  38.         getCommand("SkyHandReward").setAliases(Arrays.asList("shr"));
  39.  
  40.         setupPlayers();
  41.         RewardData.loadRewardData();
  42.         connectDatabase();
  43.  
  44.         new SkyHandRewardRunnable().runTaskTimer(this, 20, 20);
  45.  
  46.         System.out.println("SkyHandReward > Enabled !");
  47.     }
  48.  
  49.     public void onDisable() {
  50.         Bukkit.getScheduler().cancelTasks(this);
  51.         RewardData.getRewardData().clear();
  52.  
  53.  
  54.         for (Player pls : Bukkit.getOnlinePlayers()) {
  55.             SHRPlayer.get(pls).saveData();
  56.         }
  57.  
  58.  
  59.         PlayerDataConfiguration.getDataConfig().reload();
  60.         PlayerDataConfiguration.getDataConfig().save();
  61.  
  62.         disconnectDatabase();
  63.         System.out.println("SkyHandReward > Disabled !");
  64.     }
  65.  
  66.     public void setupPlayers() {
  67.         for (Player pls : Bukkit.getOnlinePlayers()) {
  68.             SHRPlayer shrPlayer = SHRPlayer.get(pls);
  69.             shrPlayer.createAccount();
  70.             shrPlayer.loadData();
  71.         }
  72.     }
  73.  
  74.     private void registerListeners() {
  75.         Bukkit.getPluginManager().registerEvents(new PlayerListeners(), this);
  76.     }
  77.  
  78.     private void setConfigType() {
  79.         if (getConfig().getBoolean("mysql.enabled") == true) {
  80.             CacheType.setType(CacheType.MYSQL);
  81.             System.out.println("SkyHandReward is using MySQL configuration.");
  82.             try {
  83.                 sqlConnection.playersql = new PlayerDataSQL("jdbc:mysql://", getConfig().getString("mysql.hostname"), getConfig().getString("mysql.database"), getConfig().getString("mysql.username"),
  84.                         getConfig().getString("mysql.password"), getConfig().getString("mysql.playerstable"));
  85.                 sqlConnection.playersql.createTable();
  86.             } catch (Exception e) {
  87.                 System.out.println("[WARNING] DATABASE CONNECTION > FAILED !");
  88.             }
  89.         }
  90.         if (getConfig().getBoolean("mysql.enabled") == false) {
  91.             CacheType.setType(CacheType.YAML);
  92.             System.out.println("SkyHandReward is using YAML configuration.");
  93.         }
  94.     }
  95.  
  96.  
  97.     public void connectDatabase() {
  98.         if (CacheType.isType(CacheType.MYSQL)) {
  99.             sqlConnection.connection();
  100.         }
  101.     }
  102.  
  103.     public void disconnectDatabase() {
  104.         if (CacheType.isType(CacheType.MYSQL)) {
  105.             sqlConnection.disconnect();
  106.         }
  107.     }
  108.  
  109.  
  110.     public static SkyHandReward get() {
  111.         return instance;
  112.     }
  113. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top