Advertisement
Guest User

Untitled

a guest
Nov 4th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.93 KB | None | 0 0
  1. package com.ecocitycraft.lsvanilla;
  2.  
  3.  
  4. import com.ecocitycraft.liquidcore.LiquidCorePlugin;
  5. import com.ecocitycraft.liquidcore.commands.LiquidCommandHub;
  6. import com.ecocitycraft.liquidcore.forum.bank.BankLink;
  7. import com.ecocitycraft.liquidcore.protocol.ProtocolLibMaster;
  8. import com.ecocitycraft.lsvanilla.runnables.BookletDBWrite;
  9. import com.ecocitycraft.lsvanilla.runnables.MasterRunnable;
  10. import com.ecocitycraft.lsvanilla.util.Booklet;
  11. import com.ecocitycraft.lsvanilla.util.BookletEntry;
  12. import net.ess3.api.IEssentials;
  13. import org.bukkit.command.Command;
  14. import org.bukkit.command.PluginCommandYamlParser;
  15. import org.bukkit.configuration.ConfigurationSection;
  16. import org.bukkit.plugin.Plugin;
  17. import org.bukkit.plugin.PluginManager;
  18.  
  19. import java.sql.Connection;
  20. import java.sql.DriverManager;
  21. import java.sql.SQLException;
  22. import java.util.ArrayList;
  23. import java.util.HashMap;
  24. import java.util.List;
  25. import java.util.UUID;
  26.  
  27. public class LiquidSafeVanilla extends LiquidCorePlugin
  28. {
  29. private static LiquidSafeVanilla plugin;
  30. private BankLink bl;
  31. private transient IEssentials ess = null;
  32. private HashMap<String, Boolean> toggles = new HashMap<>();
  33. private HashMap<String, Double> values = new HashMap<>();
  34. private HashMap<String, String> strings = new HashMap<>();
  35. private ArrayList<String> chatBlock;
  36. private ArrayList<String> nickBlock;
  37. private HashMap<String, Long> nickCooldown = new HashMap<>();
  38. private HashMap<String, Long> warnCooldown = new HashMap<>();
  39. private HashMap<String, Long> hcColourCooldown = new HashMap<>();
  40.  
  41. private List<String> loginBlockList = new ArrayList<>();
  42. private HashMap<Integer, Integer> achievements = new HashMap<>();
  43. private List<BookletEntry> bookletWriteCache = new ArrayList<>();
  44. private HashMap<String, String> bookletDBCon = new HashMap<>();
  45. private static HashMap<UUID, Booklet> booklets = new HashMap<>();
  46. private HashMap<String, Integer> customBookletLimits = new HashMap<>();
  47. private static LiquidSafeVanilla instance;
  48.  
  49. @Override
  50. public void enable()
  51. {
  52. instance = this;
  53. bl = BankLink.getInstance();
  54. bl.setup(this);
  55.  
  56. plugin = this;
  57. this.saveDefaultConfig();
  58. class loadHooks implements Runnable
  59. {
  60. @Override
  61. public void run()
  62. {
  63. hookEss();
  64. }
  65. }
  66. getServer().getScheduler().scheduleSyncDelayedTask(
  67. this, new loadHooks());
  68. reloadConfigData();
  69. if (hookProtocolLib())
  70. new ProtocolLibMaster(plugin);
  71. final List<Command> commands = PluginCommandYamlParser.parse(this);
  72. for (Command command : commands)
  73. getCommand(command.getName()).setExecutor(new LiquidCommandHub(this, "com.ecocitycraft.lsvanilla.commands"));
  74. this.getServer().getPluginManager().registerEvents(new LiquidListener(this), this);
  75. MasterRunnable masterRunnable = new MasterRunnable(this);
  76. masterRunnable.start();
  77.  
  78. // Cache booklet.
  79. this.getServer().getScheduler().runTaskAsynchronously(this, new BookletDBWrite(this, false));
  80. }
  81.  
  82. @Override
  83. public void onDisable()
  84. {
  85. BookletDBWrite write = new BookletDBWrite(this, true);
  86. write.run();
  87. }
  88.  
  89. public void reloadConfigData()
  90. {
  91. HashMap<String, Boolean> tempToggles = new HashMap<>();
  92. HashMap<String, Double> tempValues = new HashMap<>();
  93. HashMap<String, String> tempConfigStrings = new HashMap<>();
  94. HashMap<Integer, Integer> tempAchieve = new HashMap<>();
  95. HashMap<String, String> tempBookletDB = new HashMap<>();
  96. HashMap<String, Integer> tempBookletLimits = new HashMap<>();
  97.  
  98. tempValues.put("nickcooldown", this.getConfig().getDouble("nick.cooldown", 300));
  99. tempValues.put("warntemplen", this.getConfig().getDouble("warn.templength", 24));
  100. tempValues.put("warntemplimit", this.getConfig().getDouble("warn.templimit", 3));
  101. tempValues.put("warncooldown", this.getConfig().getDouble("warn.cooldown", 45));
  102. tempValues.put("hccolourcd", this.getConfig().getDouble("hccolourcd"));
  103. ArrayList<String> tempNick = new ArrayList<>(this.getConfig().getStringList("nick.blocked"));
  104. ArrayList<String> tempChat = new ArrayList<>(this.getConfig().getStringList("chatblock"));
  105.  
  106. List<String> tempLoginBlock = new ArrayList<>(this.getConfig().getStringList("loginblock"));
  107.  
  108. if (this.getConfig().isConfigurationSection("booklet"))
  109. {
  110. final ConfigurationSection section = this.getConfig().getConfigurationSection("booklet");
  111. tempBookletDB.put("db", section.getString("db"));
  112. tempBookletDB.put("host", section.getString("host"));
  113. tempBookletDB.put("user", section.getString("user"));
  114. tempBookletDB.put("pass", section.getString("pass"));
  115.  
  116.  
  117. }
  118. if (this.getConfig().isConfigurationSection("customLimits"))
  119. {
  120. final ConfigurationSection limits = this.getConfig().getConfigurationSection("customLimits");
  121. for (String key : limits.getKeys(false))
  122. {
  123. this.getLogger().info("Loaded custom booklet limit for: " + key + " with value: " + limits.getInt(key));
  124. tempBookletLimits.put(key, limits.getInt(key));
  125. }
  126. }
  127.  
  128.  
  129. getLogger().info("Reloading config, found " + tempChat.size() + " blacklisted chat strings.");
  130. // Set all values.
  131. toggles = tempToggles;
  132. values = tempValues;
  133. chatBlock = tempChat;
  134. strings = tempConfigStrings;
  135. nickBlock = tempNick;
  136. loginBlockList = tempLoginBlock;
  137. achievements = tempAchieve;
  138. bookletDBCon = tempBookletDB;
  139. customBookletLimits = tempBookletLimits;
  140. }
  141.  
  142. public HashMap<String, Boolean> getConfigToggles()
  143. {
  144. return toggles;
  145. }
  146.  
  147. public HashMap<String, Double> getConfigValues()
  148. {
  149. return values;
  150. }
  151.  
  152. public IEssentials getEss()
  153. {
  154. if (ess == null)
  155. {
  156. getLogger().warning("Ess object was null");
  157. }
  158. return ess;
  159. }
  160.  
  161.  
  162.  
  163. public void hookEss()
  164. {
  165. final PluginManager pm = this.getServer().getPluginManager();
  166.  
  167. final Plugin essPlugin = pm.getPlugin("Essentials");
  168. if (essPlugin == null || !essPlugin.isEnabled())
  169. {
  170. this.setEnabled(false);
  171. this.getLogger().warning("Couldn't hook Ess, disabling.");
  172. return;
  173. }
  174. ess = (IEssentials) essPlugin;
  175.  
  176. }
  177.  
  178. public ArrayList<String> getChatList()
  179. {
  180. return chatBlock;
  181. }
  182.  
  183. public HashMap<String, String> getConfigStrings()
  184. {
  185. return strings;
  186. }
  187.  
  188. public ArrayList<String> getNickBlockList()
  189. {
  190. return nickBlock;
  191. }
  192.  
  193. public void setNickCooldown(String nick)
  194. {
  195. nickCooldown.put(nick, System.currentTimeMillis());
  196. }
  197.  
  198. public boolean isNickCooldown(String nick)
  199. {
  200. if (nickCooldown.containsKey(nick))
  201. {
  202. long oldTime = getNickCooldown(nick);
  203. if (System.currentTimeMillis() < oldTime)
  204. {
  205. return true;
  206. }
  207. }
  208. return false;
  209. }
  210.  
  211. public long getNickCooldown(String nick)
  212. {
  213. if (nickCooldown.containsKey(nick))
  214. {
  215. return (long) (nickCooldown.get(nick) + (getConfigValues().get("nickcooldown") * 1000));
  216. }
  217. return System.currentTimeMillis();
  218. }
  219.  
  220. public void setWarnCooldown(String name)
  221. {
  222. warnCooldown.put(name, System.currentTimeMillis());
  223. }
  224.  
  225. public boolean isWarnCooldown(String name)
  226. {
  227. if (warnCooldown.containsKey(name))
  228. {
  229. long oldTime = getWarnCooldown(name);
  230. if (System.currentTimeMillis() < oldTime)
  231. {
  232. return true;
  233. }
  234. }
  235. return false;
  236. }
  237.  
  238. public long getWarnCooldown(String name)
  239. {
  240. if (warnCooldown.containsKey(name))
  241. {
  242. return (long) (warnCooldown.get(name) + (getConfigValues().get("warncooldown") * 1000));
  243. }
  244. return System.currentTimeMillis();
  245. }
  246.  
  247. public static boolean hookProtocolLib()
  248. {
  249. final PluginManager pm = plugin.getServer().getPluginManager();
  250.  
  251. final Plugin p = pm.getPlugin("ProtocolLib");
  252. if (p == null || !p.isEnabled())
  253. {
  254. plugin.getLogger().warning("Couldn't hook ProtocolLib");
  255. return false;
  256. }
  257. plugin.getLogger().info("Hooking ProtocolLib");
  258. return true;
  259. }
  260.  
  261. public List<String> getLoginBlockList()
  262. {
  263. return loginBlockList;
  264. }
  265.  
  266. public HashMap<Integer, Integer> getAchievements()
  267. {
  268. return achievements;
  269. }
  270.  
  271. public List<BookletEntry> getBookletWriteCache()
  272. {
  273. return bookletWriteCache;
  274. }
  275.  
  276. public Connection connectToBookletDB()
  277. {
  278. Connection conn;
  279. try
  280. {
  281. Class.forName("com.mysql.jdbc.Driver");
  282. conn = DriverManager.getConnection("jdbc:mysql://" + bookletDBCon.get("host") + ":"
  283. + 3306 + "/" + bookletDBCon.get("db"), bookletDBCon.get("user"), bookletDBCon.get("pass"));
  284. return conn;
  285. }
  286. catch (ClassNotFoundException e)
  287. {
  288. getLogger().warning("Could not find the Java SQL Driver. - com.mysql.jdbc.Driver");
  289. return null;
  290. }
  291. catch (SQLException e)
  292. {
  293. getLogger().severe("Could not connect to database. Booklets are not logged.");
  294. return null;
  295. }
  296. }
  297.  
  298. public void setBookletWriteCache(List<BookletEntry> entries)
  299. {
  300. bookletWriteCache = entries;
  301. }
  302.  
  303. public static HashMap<UUID, Booklet> getBooklets()
  304. {
  305. return booklets;
  306. }
  307.  
  308. public HashMap<String, Integer> getCustomBookletLimits()
  309. {
  310. return customBookletLimits;
  311. }
  312.  
  313.  
  314. public static LiquidSafeVanilla getInstance()
  315. {
  316. return instance;
  317. }
  318.  
  319. public long getHCColourCooldown(String nick)
  320. {
  321. if (hcColourCooldown.containsKey(nick))
  322. {
  323. return (long)(hcColourCooldown.get(nick) + (getConfigValues().get("hccolourcd") *60*1000));
  324. }
  325. return System.currentTimeMillis();
  326. }
  327.  
  328.  
  329. public void setHcColourCooldown(String nick)
  330. {
  331. hcColourCooldown.put(nick, System.currentTimeMillis());
  332. }
  333.  
  334. public boolean isHCColourCooldown(String nick)
  335. {
  336. if (hcColourCooldown.containsKey(nick))
  337. {
  338. long oldTime = getHCColourCooldown(nick);
  339. if (System.currentTimeMillis() < oldTime)
  340. {
  341. return true;
  342. }
  343. }
  344. return false;
  345. }
  346.  
  347. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement