package com.entryrise.afkguard; import java.io.File; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; import com.entryrise.afkguard.antiafk.AFKManager; import com.entryrise.afkguard.antiafk.captcha.CaptchaCategory; import com.entryrise.afkguard.antiafk.captcha.CaptchaGUI; import com.entryrise.afkguard.antiafk.captcha.CaptchaGUI.CaptchaData; import com.entryrise.afkguard.cmd.CommandListener; import com.entryrise.afkguard.cmd.CommandTabListener; import com.entryrise.afkguard.listeners.ListenersMain; import com.entryrise.afkguard.utils.Others; import com.entryrise.afkguard.utils.VersionMgr; import net.milkbowl.vault.economy.Economy; public class Main extends JavaPlugin implements Listener { public static String USER = "%%__USER__%%"; public static final String PREFIX = "§2§lAFK§f§lGuard §e» §f"; public static JavaPlugin p; public static boolean paper = false; private static File file; public static FileConfiguration config = new YamlConfiguration(); public static Economy econ; public void onEnable() { p = this; file = new File(getDataFolder(), "server.yml"); config = Others.getConfig(file, 1); paper = VersionMgr.isPaper(); Bukkit.getLogger().info(PREFIX + "Enabling Systems:"); setupEconomy(); EnableClasses(false); getServer().getPluginManager().registerEvents(this, this); getCommand("afkguard").setExecutor(new CommandListener()); getCommand("afkguard").setTabCompleter(new CommandTabListener()); } private boolean setupEconomy() { if (getServer().getPluginManager().getPlugin("Vault") == null) { return false; } RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class); if (rsp == null) { return false; } econ = rsp.getProvider(); return econ != null; } private static void EnableClasses(boolean reload) { ListenersMain.Enabler(reload); CaptchaCategory.Enabler(reload); AFKManager.Enabler(reload); } public static void ReloadPlugin(CommandSender s) { config = Others.getConfig(file, 1); Bukkit.getLogger().info(PREFIX + "Reloading Systems:"); EnableClasses(true); s.sendMessage(PREFIX + "Reloaded the config successfully."); } @Override public void onDisable() { // PacketInjector.Disabler(); <- SEEMS UNIMPORTANT AND GLITCHY } public static void failedAttempt(Player p) { CaptchaGUI.invs.remove(p.getUniqueId()); p.closeInventory(); // p.kickPlayer(getKickMsg()); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), Main.config.getString("settings.captcha.fail-command").replace("%player%", p.getName())); } public static void goodAttempt(Player p, int target) { CaptchaGUI.invs.remove(p.getUniqueId()); p.closeInventory(); // p.sendMessage(getSuccessfulsg()); Bukkit.dispatchCommand(Bukkit.getConsoleSender(), Main.config.getString("settings.captcha.success-command").replace("%player%", p.getName())); AFKManager.setScore(p, target); } public static void captchaResult(Player p, Material mat) { CaptchaData cd = CaptchaGUI.invs.get(p.getUniqueId()); if (!cd.category.getAllowed().contains(mat)) { failedAttempt(p); return; } goodAttempt(p, cd.counter); } public static void openCapcha(Player p, int resetcounter) { Bukkit.getScheduler().runTaskLater(Main.p, () -> p.openInventory(CaptchaGUI.getInventory(p, resetcounter)), 20); } public static void penalizePlayer(Player p, double payment, int reset) { OfflinePlayer op = Bukkit.getOfflinePlayer(p.getUniqueId()); if (!econ.has(op, payment)) { return; } econ.withdrawPlayer(op, payment); AFKManager.setScore(p, reset); } }