From 671329369e08eaf2986f22921acfec9ee6a59659 Mon Sep 17 00:00:00 2001 From: Rammelkast Date: Mon, 30 May 2016 19:45:02 +0200 Subject: [PATCH] Fixed killaura, added auto-updater --- pom.xml | 8 +++++- .../anticheat/AntiCheat.java | 28 +++++++++++++++++-- .../anticheat/check/combat/KillAuraCheck.java | 9 +++++- .../anticheat/command/CommandBase.java | 8 +++--- .../command/executors/CommandUpdate.java | 2 +- 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index bd32393..0a2da7e 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 net.gravitydevelopment.anticheat AntiCheat - 1.1.0-ALPHA + 1.2.0-ALPHA AntiCheatReloaded https://rammelkast.com @@ -93,6 +93,12 @@ 1.8.8-R0.1-SNAPSHOT provided + + net.gravitydevelopment.updater + updater + 2.1 + compile + com.comphenix.protocol ProtocolLib-API diff --git a/src/main/java/net/gravitydevelopment/anticheat/AntiCheat.java b/src/main/java/net/gravitydevelopment/anticheat/AntiCheat.java index 5e376d3..b764266 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/AntiCheat.java +++ b/src/main/java/net/gravitydevelopment/anticheat/AntiCheat.java @@ -18,12 +18,14 @@ package net.gravitydevelopment.anticheat; +import java.io.File; import java.util.ArrayList; import java.util.List; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; import org.bukkit.plugin.java.JavaPlugin; import com.comphenix.protocol.ProtocolLibrary; @@ -38,9 +40,9 @@ import net.gravitydevelopment.anticheat.event.InventoryListener; import net.gravitydevelopment.anticheat.event.PlayerListener; import net.gravitydevelopment.anticheat.event.VehicleListener; import net.gravitydevelopment.anticheat.manage.AntiCheatManager; -import net.gravitydevelopment.anticheat.manage.PacketManager; import net.gravitydevelopment.anticheat.util.User; import net.gravitydevelopment.anticheat.util.VersionUtil; +import net.gravitydevelopment.updater.Updater; public class AntiCheat extends JavaPlugin { @@ -52,7 +54,7 @@ public class AntiCheat extends JavaPlugin { private static Configuration config; private static boolean verbose; private static boolean developer; - private static final int PROJECT_ID = 38723; + private static final int PROJECT_ID = 100229; private static ProtocolManager protocolManager; private static boolean protocolLib = false; private static Long loadTime; @@ -71,6 +73,7 @@ public class AntiCheat extends JavaPlugin { setupConfig(); setupEvents(); setupCommands(); + setupUpdater(); setupProtocol(); // Enterprise must come before levels setupEnterprise(); @@ -98,7 +101,26 @@ public class AntiCheat extends JavaPlugin { KillAuraCheck.listenPackets(); } - @Override + private void setupUpdater() { + if (config.getConfig().autoUpdate.getValue()) { + final File file = this.getFile(); + final Plugin plugin = this; + getServer().getScheduler().runTaskAsynchronously(this, new Runnable() { + @Override + public void run() { + verboseLog("Checking for a new update..."); + Updater updater = new Updater(plugin, PROJECT_ID, file, Updater.UpdateType.DEFAULT, false); + update = updater.getResult() == Updater.UpdateResult.SUCCESS; + verboseLog("Update available: " + update); + if (update) { + updateDetails = updater.getLatestName() + " for " + updater.getLatestGameVersion(); + } + } + }); + } + } + + @Override public void onDisable() { verboseLog("Saving user levels..."); config.getLevels().saveLevelsFromUsers(getManager().getUserManager().getUsers()); diff --git a/src/main/java/net/gravitydevelopment/anticheat/check/combat/KillAuraCheck.java b/src/main/java/net/gravitydevelopment/anticheat/check/combat/KillAuraCheck.java index 11f8af0..176e7e5 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/check/combat/KillAuraCheck.java +++ b/src/main/java/net/gravitydevelopment/anticheat/check/combat/KillAuraCheck.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; +import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.player.PlayerMoveEvent; @@ -40,7 +41,7 @@ public class KillAuraCheck { @Override public void onPacketReceiving(PacketEvent e) { Player p = e.getPlayer(); - if (!CHECKER_NPCS.containsKey(p.getUniqueId())) + if (!CHECKER_NPCS.containsKey(p.getUniqueId()) || AntiCheat.getManager().getCheckManager().isOpExempt(p) || AntiCheat.getManager().getCheckManager().isExempt(p, CheckType.KILLAURA)) return; int entityId = ((Integer)e.getPacket().getIntegers().read(0)); boolean isBot = CHECKER_NPCS.get(p.getUniqueId()).onHit(entityId); @@ -60,6 +61,8 @@ public class KillAuraCheck { } public static void doDamageEvent(EntityDamageByEntityEvent e, Player p) { + if (AntiCheat.getManager().getCheckManager().isOpExempt(p) || AntiCheat.getManager().getCheckManager().isExempt(p, CheckType.KILLAURA)) + return; if (VersionUtil.getVersion().equals("v1_8_R3")) { // TODO 1.9 support if (!CHECKER_NPCS.containsKey(p.getUniqueId())) { // Enable killaura check after player damaged other player, this is more efficient CHECKER_NPCS.put(p.getUniqueId(), new CheckerNPCS(p)); @@ -69,6 +72,10 @@ public class KillAuraCheck { public static void doMove(PlayerMoveEvent e) { if (CHECKER_NPCS.containsKey(e.getPlayer().getUniqueId())) { + if (AntiCheat.getManager().getCheckManager().isOpExempt(e.getPlayer()) || AntiCheat.getManager().getCheckManager().isExempt(e.getPlayer(), CheckType.KILLAURA)) { + cleanPlayer(e.getPlayer()); + return; + } CHECKER_NPCS.get(e.getPlayer().getUniqueId()).doMove(e); } } diff --git a/src/main/java/net/gravitydevelopment/anticheat/command/CommandBase.java b/src/main/java/net/gravitydevelopment/anticheat/command/CommandBase.java index 59b30e6..9e86197 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/command/CommandBase.java +++ b/src/main/java/net/gravitydevelopment/anticheat/command/CommandBase.java @@ -43,7 +43,7 @@ public class CommandBase { public static final ChatColor GOLD = ChatColor.GOLD; public static final ChatColor AQUA = ChatColor.AQUA; public static final Server SERVER = Bukkit.getServer(); - public static final String PERMISSIONS_ERROR = RED + "Insufficient Permissions."; + public static final String PERMISSIONS_ERROR = RED + "You don't have the permissions to use this command."; public static final String MENU_END = "-----------------------------------------------------"; private final String name; @@ -73,9 +73,9 @@ public class CommandBase { } public void sendHelp(CommandSender cs) { - cs.sendMessage(GREEN + "== " + GRAY + getName() + GREEN + " =="); - cs.sendMessage(GREEN + "Usage: " + GRAY + (cs instanceof Player ? "/" : "") + getUsage()); - cs.sendMessage(GREEN + "Permission: " + GRAY + getPermission().toString()); + cs.sendMessage(RED + "== " + GRAY + getName() + RED + " =="); + cs.sendMessage(RED + "Usage: " + GRAY + (cs instanceof Player ? "/" : "") + getUsage()); + cs.sendMessage(RED + "Permission: " + GRAY + getPermission().toString()); for (String string : getHelp()) { cs.sendMessage(string); } diff --git a/src/main/java/net/gravitydevelopment/anticheat/command/executors/CommandUpdate.java b/src/main/java/net/gravitydevelopment/anticheat/command/executors/CommandUpdate.java index 680a1e2..4ef7415 100644 --- a/src/main/java/net/gravitydevelopment/anticheat/command/executors/CommandUpdate.java +++ b/src/main/java/net/gravitydevelopment/anticheat/command/executors/CommandUpdate.java @@ -48,7 +48,7 @@ public class CommandUpdate extends CommandBase { } } else { cs.sendMessage(GRAY + "Your config settings have disabled update checking."); - cs.sendMessage(GRAY + "Please enable this setting or visit http://dev.bukkit.org/bukkit-plugins/anticheat/"); + cs.sendMessage(GRAY + "Please enable this setting or visit http://dev.bukkit.org/bukkit-plugins/anticheatreloaded/"); } } }