Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ecocitycraft.lsvanilla;
- import com.ecocitycraft.liquidcore.LiquidCorePlugin;
- import com.ecocitycraft.liquidcore.commands.LiquidCommandHub;
- import com.ecocitycraft.liquidcore.forum.bank.BankLink;
- import com.ecocitycraft.liquidcore.protocol.ProtocolLibMaster;
- import com.ecocitycraft.lsvanilla.runnables.BookletDBWrite;
- import com.ecocitycraft.lsvanilla.runnables.MasterRunnable;
- import com.ecocitycraft.lsvanilla.util.Booklet;
- import com.ecocitycraft.lsvanilla.util.BookletEntry;
- import net.ess3.api.IEssentials;
- import org.bukkit.command.Command;
- import org.bukkit.command.PluginCommandYamlParser;
- import org.bukkit.configuration.ConfigurationSection;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.PluginManager;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.UUID;
- public class LiquidSafeVanilla extends LiquidCorePlugin
- {
- private static LiquidSafeVanilla plugin;
- private BankLink bl;
- private transient IEssentials ess = null;
- private HashMap<String, Boolean> toggles = new HashMap<>();
- private HashMap<String, Double> values = new HashMap<>();
- private HashMap<String, String> strings = new HashMap<>();
- private ArrayList<String> chatBlock;
- private ArrayList<String> nickBlock;
- private HashMap<String, Long> nickCooldown = new HashMap<>();
- private HashMap<String, Long> warnCooldown = new HashMap<>();
- private HashMap<String, Long> hcColourCooldown = new HashMap<>();
- private List<String> loginBlockList = new ArrayList<>();
- private HashMap<Integer, Integer> achievements = new HashMap<>();
- private List<BookletEntry> bookletWriteCache = new ArrayList<>();
- private HashMap<String, String> bookletDBCon = new HashMap<>();
- private static HashMap<UUID, Booklet> booklets = new HashMap<>();
- private HashMap<String, Integer> customBookletLimits = new HashMap<>();
- private static LiquidSafeVanilla instance;
- @Override
- public void enable()
- {
- instance = this;
- bl = BankLink.getInstance();
- bl.setup(this);
- plugin = this;
- this.saveDefaultConfig();
- class loadHooks implements Runnable
- {
- @Override
- public void run()
- {
- hookEss();
- }
- }
- getServer().getScheduler().scheduleSyncDelayedTask(
- this, new loadHooks());
- reloadConfigData();
- if (hookProtocolLib())
- new ProtocolLibMaster(plugin);
- final List<Command> commands = PluginCommandYamlParser.parse(this);
- for (Command command : commands)
- getCommand(command.getName()).setExecutor(new LiquidCommandHub(this, "com.ecocitycraft.lsvanilla.commands"));
- this.getServer().getPluginManager().registerEvents(new LiquidListener(this), this);
- MasterRunnable masterRunnable = new MasterRunnable(this);
- masterRunnable.start();
- // Cache booklet.
- this.getServer().getScheduler().runTaskAsynchronously(this, new BookletDBWrite(this, false));
- }
- @Override
- public void onDisable()
- {
- BookletDBWrite write = new BookletDBWrite(this, true);
- write.run();
- }
- public void reloadConfigData()
- {
- HashMap<String, Boolean> tempToggles = new HashMap<>();
- HashMap<String, Double> tempValues = new HashMap<>();
- HashMap<String, String> tempConfigStrings = new HashMap<>();
- HashMap<Integer, Integer> tempAchieve = new HashMap<>();
- HashMap<String, String> tempBookletDB = new HashMap<>();
- HashMap<String, Integer> tempBookletLimits = new HashMap<>();
- tempValues.put("nickcooldown", this.getConfig().getDouble("nick.cooldown", 300));
- tempValues.put("warntemplen", this.getConfig().getDouble("warn.templength", 24));
- tempValues.put("warntemplimit", this.getConfig().getDouble("warn.templimit", 3));
- tempValues.put("warncooldown", this.getConfig().getDouble("warn.cooldown", 45));
- tempValues.put("hccolourcd", this.getConfig().getDouble("hccolourcd"));
- ArrayList<String> tempNick = new ArrayList<>(this.getConfig().getStringList("nick.blocked"));
- ArrayList<String> tempChat = new ArrayList<>(this.getConfig().getStringList("chatblock"));
- List<String> tempLoginBlock = new ArrayList<>(this.getConfig().getStringList("loginblock"));
- if (this.getConfig().isConfigurationSection("booklet"))
- {
- final ConfigurationSection section = this.getConfig().getConfigurationSection("booklet");
- tempBookletDB.put("db", section.getString("db"));
- tempBookletDB.put("host", section.getString("host"));
- tempBookletDB.put("user", section.getString("user"));
- tempBookletDB.put("pass", section.getString("pass"));
- }
- if (this.getConfig().isConfigurationSection("customLimits"))
- {
- final ConfigurationSection limits = this.getConfig().getConfigurationSection("customLimits");
- for (String key : limits.getKeys(false))
- {
- this.getLogger().info("Loaded custom booklet limit for: " + key + " with value: " + limits.getInt(key));
- tempBookletLimits.put(key, limits.getInt(key));
- }
- }
- getLogger().info("Reloading config, found " + tempChat.size() + " blacklisted chat strings.");
- // Set all values.
- toggles = tempToggles;
- values = tempValues;
- chatBlock = tempChat;
- strings = tempConfigStrings;
- nickBlock = tempNick;
- loginBlockList = tempLoginBlock;
- achievements = tempAchieve;
- bookletDBCon = tempBookletDB;
- customBookletLimits = tempBookletLimits;
- }
- public HashMap<String, Boolean> getConfigToggles()
- {
- return toggles;
- }
- public HashMap<String, Double> getConfigValues()
- {
- return values;
- }
- public IEssentials getEss()
- {
- if (ess == null)
- {
- getLogger().warning("Ess object was null");
- }
- return ess;
- }
- public void hookEss()
- {
- final PluginManager pm = this.getServer().getPluginManager();
- final Plugin essPlugin = pm.getPlugin("Essentials");
- if (essPlugin == null || !essPlugin.isEnabled())
- {
- this.setEnabled(false);
- this.getLogger().warning("Couldn't hook Ess, disabling.");
- return;
- }
- ess = (IEssentials) essPlugin;
- }
- public ArrayList<String> getChatList()
- {
- return chatBlock;
- }
- public HashMap<String, String> getConfigStrings()
- {
- return strings;
- }
- public ArrayList<String> getNickBlockList()
- {
- return nickBlock;
- }
- public void setNickCooldown(String nick)
- {
- nickCooldown.put(nick, System.currentTimeMillis());
- }
- public boolean isNickCooldown(String nick)
- {
- if (nickCooldown.containsKey(nick))
- {
- long oldTime = getNickCooldown(nick);
- if (System.currentTimeMillis() < oldTime)
- {
- return true;
- }
- }
- return false;
- }
- public long getNickCooldown(String nick)
- {
- if (nickCooldown.containsKey(nick))
- {
- return (long) (nickCooldown.get(nick) + (getConfigValues().get("nickcooldown") * 1000));
- }
- return System.currentTimeMillis();
- }
- public void setWarnCooldown(String name)
- {
- warnCooldown.put(name, System.currentTimeMillis());
- }
- public boolean isWarnCooldown(String name)
- {
- if (warnCooldown.containsKey(name))
- {
- long oldTime = getWarnCooldown(name);
- if (System.currentTimeMillis() < oldTime)
- {
- return true;
- }
- }
- return false;
- }
- public long getWarnCooldown(String name)
- {
- if (warnCooldown.containsKey(name))
- {
- return (long) (warnCooldown.get(name) + (getConfigValues().get("warncooldown") * 1000));
- }
- return System.currentTimeMillis();
- }
- public static boolean hookProtocolLib()
- {
- final PluginManager pm = plugin.getServer().getPluginManager();
- final Plugin p = pm.getPlugin("ProtocolLib");
- if (p == null || !p.isEnabled())
- {
- plugin.getLogger().warning("Couldn't hook ProtocolLib");
- return false;
- }
- plugin.getLogger().info("Hooking ProtocolLib");
- return true;
- }
- public List<String> getLoginBlockList()
- {
- return loginBlockList;
- }
- public HashMap<Integer, Integer> getAchievements()
- {
- return achievements;
- }
- public List<BookletEntry> getBookletWriteCache()
- {
- return bookletWriteCache;
- }
- public Connection connectToBookletDB()
- {
- Connection conn;
- try
- {
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection("jdbc:mysql://" + bookletDBCon.get("host") + ":"
- + 3306 + "/" + bookletDBCon.get("db"), bookletDBCon.get("user"), bookletDBCon.get("pass"));
- return conn;
- }
- catch (ClassNotFoundException e)
- {
- getLogger().warning("Could not find the Java SQL Driver. - com.mysql.jdbc.Driver");
- return null;
- }
- catch (SQLException e)
- {
- getLogger().severe("Could not connect to database. Booklets are not logged.");
- return null;
- }
- }
- public void setBookletWriteCache(List<BookletEntry> entries)
- {
- bookletWriteCache = entries;
- }
- public static HashMap<UUID, Booklet> getBooklets()
- {
- return booklets;
- }
- public HashMap<String, Integer> getCustomBookletLimits()
- {
- return customBookletLimits;
- }
- public static LiquidSafeVanilla getInstance()
- {
- return instance;
- }
- public long getHCColourCooldown(String nick)
- {
- if (hcColourCooldown.containsKey(nick))
- {
- return (long)(hcColourCooldown.get(nick) + (getConfigValues().get("hccolourcd") *60*1000));
- }
- return System.currentTimeMillis();
- }
- public void setHcColourCooldown(String nick)
- {
- hcColourCooldown.put(nick, System.currentTimeMillis());
- }
- public boolean isHCColourCooldown(String nick)
- {
- if (hcColourCooldown.containsKey(nick))
- {
- long oldTime = getHCColourCooldown(nick);
- if (System.currentTimeMillis() < oldTime)
- {
- return true;
- }
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement