SHARE
TWEET

Untitled

a guest Dec 23rd, 2017 72 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.         saveDefaultConfig();
  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.         saveDefaultConfig();
  63.         disconnectDatabase();
  64.         System.out.println("SkyHandReward > Disabled !");
  65.     }
  66.  
  67.     public void setupPlayers() {
  68.         for (Player pls : Bukkit.getOnlinePlayers()) {
  69.             SHRPlayer shrPlayer = SHRPlayer.get(pls);
  70.             shrPlayer.createAccount();
  71.             shrPlayer.loadData();
  72.         }
  73.     }
  74.  
  75.     private void registerListeners() {
  76.         Bukkit.getPluginManager().registerEvents(new PlayerListeners(), this);
  77.     }
  78.  
  79.     private void setConfigType() {
  80.         if (getConfig().getBoolean("mysql.enabled") == true) {
  81.             CacheType.setType(CacheType.MYSQL);
  82.             System.out.println("SkyHandReward is using MySQL configuration.");
  83.             try {
  84.                 sqlConnection.playersql = new PlayerDataSQL("jdbc:mysql://", getConfig().getString("mysql.hostname"), getConfig().getString("mysql.database"), getConfig().getString("mysql.username"),
  85.                         getConfig().getString("mysql.password"), getConfig().getString("mysql.playerstable"));
  86.                 sqlConnection.playersql.createTable();
  87.             } catch (Exception e) {
  88.                 System.out.println("[WARNING] DATABASE CONNECTION > FAILED !");
  89.             }
  90.         }
  91.         if (getConfig().getBoolean("mysql.enabled") == false) {
  92.             CacheType.setType(CacheType.YAML);
  93.             System.out.println("SkyHandReward is using YAML configuration.");
  94.         }
  95.     }
  96.  
  97.  
  98.     public void connectDatabase() {
  99.         if (CacheType.isType(CacheType.MYSQL)) {
  100.             sqlConnection.connection();
  101.         }
  102.     }
  103.  
  104.     public void disconnectDatabase() {
  105.         if (CacheType.isType(CacheType.MYSQL)) {
  106.             sqlConnection.disconnect();
  107.         }
  108.     }
  109.  
  110.  
  111.     public static SkyHandReward get() {
  112.         return instance;
  113.     }
  114. }
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