From c9c3b2397f59f63565e71c061b30c1a57ff93e1e Mon Sep 17 00:00:00 2001 From: Rammelkast Date: Fri, 28 Feb 2020 12:40:27 +0100 Subject: [PATCH] Updated Metrics, made small code changes --- README.md | 1 - pom.xml | 2 +- .../anticheatreloaded/AntiCheatReloaded.java | 47 +- .../anticheatreloaded/check/Backend.java | 66 +- .../anticheatreloaded/check/CheckType.java | 1 - .../check/combat/KillAuraCheck.java | 100 --- .../check/movement/BlinkCheck.java | 2 +- .../check/movement/FlightCheck.java | 21 +- .../check/movement/GlideCheck.java | 38 +- .../check/movement/SpeedCheck.java | 6 +- .../check/movement/WaterWalkCheck.java | 41 +- .../check/movement/YAxisCheck.java | 61 +- .../event/EntityListener.java | 11 +- .../anticheatreloaded/metrics/Metrics.java | 725 ++++++++---------- .../anticheatreloaded/util/Permission.java | 2 +- src/main/resources/plugin.yml | 7 +- 16 files changed, 448 insertions(+), 683 deletions(-) delete mode 100644 src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java diff --git a/README.md b/README.md index 99c686d..6c1d4e7 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,6 @@ Hacks blocked * Jesus * Step * Criticals -* KillAura (not available on MC > 1.12.2 * Anti-Knockback * FastBow * FastDrop diff --git a/pom.xml b/pom.xml index 7db5051..50f2e62 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.rammelkast.anticheatreloaded AntiCheatReloaded - 1.7.0-ALPHA + 1.7.1-ALPHA AntiCheatReloaded https://rammelkast.com diff --git a/src/main/java/com/rammelkast/anticheatreloaded/AntiCheatReloaded.java b/src/main/java/com/rammelkast/anticheatreloaded/AntiCheatReloaded.java index 24d3c4f..9a6a2e1 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/AntiCheatReloaded.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/AntiCheatReloaded.java @@ -23,6 +23,7 @@ import java.security.SecureRandom; import java.util.ArrayList; import java.util.List; import java.util.UUID; +import java.util.concurrent.Callable; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -32,7 +33,6 @@ import org.bukkit.plugin.java.JavaPlugin; import com.comphenix.protocol.ProtocolLibrary; import com.comphenix.protocol.ProtocolManager; -import com.rammelkast.anticheatreloaded.check.combat.KillAuraCheck; import com.rammelkast.anticheatreloaded.check.movement.BlinkCheck; import com.rammelkast.anticheatreloaded.command.CommandHandler; import com.rammelkast.anticheatreloaded.config.Configuration; @@ -92,7 +92,6 @@ public class AntiCheatReloaded extends JavaPlugin { } getLogger().info("Found ProtocolLib, enabling checks that use ProtcolLib..."); // Enable packetlisteners - KillAuraCheck.listenPackets(); BlinkCheck.startTimer(); BlinkCheck.listenPackets(); @@ -149,46 +148,38 @@ public class AntiCheatReloaded extends JavaPlugin { // Metrics try { - Metrics metrics = new Metrics(this); - metrics.addCustomChart(new Metrics.SingleLineChart("cheaters_kicked") { + Metrics metrics = new Metrics(this, 202); + metrics.addCustomChart(new Metrics.SingleLineChart("cheaters_kicked", new Callable() { @Override - public int getValue() { + public Integer call() throws Exception { int kicked = playersKicked; // Reset so we don't keep sending the same value playersKicked = 0; return kicked; } - }); - metrics.addCustomChart(new Metrics.SingleLineChart("killaura_violations") { + })); + metrics.addCustomChart(new Metrics.SingleLineChart("glide_violations", new Callable() { @Override - public int getValue() { - int violations = killauraViolations; - // Reset so we don't keep sending the same value - killauraViolations = 0; - return violations; - } - }); - metrics.addCustomChart(new Metrics.SingleLineChart("glide_violations") { - @Override - public int getValue() { + public Integer call() throws Exception { int violations = glideViolations; // Reset so we don't keep sending the same value glideViolations = 0; return violations; } - }); - metrics.addCustomChart(new Metrics.SimplePie("protocollib_version") { + })); + metrics.addCustomChart(new Metrics.SimplePie("protocollib_version", new Callable() { @Override - public String getValue() { + public String call() throws Exception { return Bukkit.getPluginManager().getPlugin("ProtocolLib").getDescription().getVersion(); } - }); - metrics.addCustomChart(new Metrics.SimplePie("nms_version") { + })); + metrics.addCustomChart(new Metrics.SimplePie("nms_version", new Callable() { @Override - public String getValue() { + public String call() throws Exception { return VersionUtil.getVersion(); } - }); + + })); } catch (Exception e) { e.printStackTrace(); } @@ -309,10 +300,6 @@ public class AntiCheatReloaded extends JavaPlugin { * Amount of players kicked since start */ private int playersKicked = 0; - /** - * Amount of killaura violations since start - */ - private int killauraViolations = 0; /** * Amount of glide violations since start */ @@ -322,10 +309,6 @@ public class AntiCheatReloaded extends JavaPlugin { this.playersKicked++; } - public void onKillAuraViolation() { - this.killauraViolations++; - } - public void onGlideViolation() { this.glideViolations++; } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java b/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java index 4110266..6a62b37 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java @@ -39,7 +39,6 @@ import org.bukkit.event.player.PlayerToggleSprintEvent; import org.bukkit.potion.PotionEffectType; import com.rammelkast.anticheatreloaded.AntiCheatReloaded; -import com.rammelkast.anticheatreloaded.check.combat.KillAuraCheck; import com.rammelkast.anticheatreloaded.check.combat.VelocityCheck; import com.rammelkast.anticheatreloaded.check.movement.BlinkCheck; import com.rammelkast.anticheatreloaded.check.movement.FlightCheck; @@ -121,29 +120,28 @@ public class Backend { UUID pU = player.getUniqueId(); VelocityCheck.cleanPlayer(player); - KillAuraCheck.cleanPlayer(player); BlinkCheck.MOVE_COUNT.remove(player.getUniqueId()); blocksDropped.remove(pU); blockTime.remove(pU); - FlightCheck.movingExempt.remove(pU); + FlightCheck.MOVING_EXEMPT.remove(pU); brokenBlock.remove(pU); placedBlock.remove(pU); bowWindUp.remove(pU); startEat.remove(pU); lastHeal.remove(pU); sprinted.remove(pU); - WaterWalkCheck.isInWater.remove(pU); - WaterWalkCheck.isInWaterCache.remove(pU); + WaterWalkCheck.IS_IN_WATER.remove(pU); + WaterWalkCheck.IS_IN_WATER_CACHE.remove(pU); instantBreakExempt.remove(pU); isAscending.remove(player.getUniqueId()); ascensionCount.remove(player.getUniqueId()); - FlightCheck.blocksOverFlight.remove(pU); + FlightCheck.BLOCKS_OVER_FLIGHT.remove(pU); nofallViolation.remove(pU); fastBreakViolation.remove(pU); - YAxisCheck.yAxisViolations.remove(pU); - YAxisCheck.yAxisLastViolation.remove(pU); - YAxisCheck.lastYcoord.remove(pU); - YAxisCheck.lastYtime.remove(pU); + YAxisCheck.Y_AXIS_VIOLATIONS.remove(pU); + YAxisCheck.LAST_Y_AXIS_VIOLATION.remove(pU); + YAxisCheck.LAST_Y_COORD_CACHE.remove(pU); + YAxisCheck.LAST_Y_TIME.remove(pU); fastBreaks.remove(pU); blockBreakHolder.remove(pU); lastBlockBroken.remove(pU); @@ -151,8 +149,8 @@ public class Backend { lastBlockPlaced.remove(pU); lastBlockPlaceTime.remove(pU); blockPunches.remove(pU); - WaterWalkCheck.waterAscensionViolation.remove(pU); - WaterWalkCheck.waterSpeedViolation.remove(pU); + WaterWalkCheck.WATER_ASCENSION_VIOLATIONS.remove(pU); + WaterWalkCheck.WATER_SPEED_VIOLATIONS.remove(pU); projectilesShot.remove(pU); velocitized.remove(pU); velocitytrack.remove(pU); @@ -164,17 +162,17 @@ public class Backend { sprinted.remove(pU); brokenBlock.remove(pU); placedBlock.remove(pU); - FlightCheck.movingExempt.remove(pU); + FlightCheck.MOVING_EXEMPT.remove(pU); blockTime.remove(pU); blocksDropped.remove(pU); lastInventoryTime.remove(pU); inventoryTime.remove(pU); inventoryClicks.remove(pU); lastFallPacket.remove(pU); - GlideCheck.lastDiff.remove(pU); - GlideCheck.lastFallDistance.remove(pU); - GlideCheck.violations.remove(pU); - SpeedCheck.speedViolation.remove(player.getUniqueId()); + GlideCheck.LAST_DIFFERENCE.remove(pU); + GlideCheck.LAST_FALL_DISTANCE.remove(pU); + GlideCheck.VIOLATIONS.remove(pU); + SpeedCheck.SPEED_VIOLATIONS.remove(player.getUniqueId()); } public CheckResult checkFastBow(Player player, float force) { @@ -703,8 +701,8 @@ public class Backend { } public boolean isHoveringOverWaterAfterViolation(Player player) { - if (WaterWalkCheck.waterSpeedViolation.containsKey(player.getUniqueId())) { - if (WaterWalkCheck.waterSpeedViolation.get(player.getUniqueId()) >= magic.WATER_SPEED_VIOLATION_MAX() && Utilities.isHoveringOverWater(player.getLocation())) { + if (WaterWalkCheck.WATER_SPEED_VIOLATIONS.containsKey(player.getUniqueId())) { + if (WaterWalkCheck.WATER_SPEED_VIOLATIONS.get(player.getUniqueId()) >= magic.WATER_SPEED_VIOLATION_MAX() && Utilities.isHoveringOverWater(player.getLocation())) { return true; } } @@ -771,43 +769,43 @@ public class Backend { break; } - FlightCheck.movingExempt.put(player.getUniqueId(), System.currentTimeMillis() + time); + FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + time); // Only map in which termination time is calculated beforehand. } public void logEnterExit(final Player player) { - FlightCheck.movingExempt.put(player.getUniqueId(), System.currentTimeMillis() + magic.ENTERED_EXITED_TIME()); + FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + magic.ENTERED_EXITED_TIME()); } public void logToggleSneak(final Player player) { - FlightCheck.movingExempt.put(player.getUniqueId(), System.currentTimeMillis() + magic.SNEAK_TIME()); + FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + magic.SNEAK_TIME()); } public void logTeleport(final Player player) { - FlightCheck.movingExempt.put(player.getUniqueId(), System.currentTimeMillis() + magic.TELEPORT_TIME()); + FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + magic.TELEPORT_TIME()); /* Data for fly/speed should be reset */ nofallViolation.remove(player.getUniqueId()); - FlightCheck.blocksOverFlight.remove(player.getUniqueId()); - YAxisCheck.yAxisViolations.remove(player.getUniqueId()); - YAxisCheck.yAxisLastViolation.remove(player.getUniqueId()); - YAxisCheck.lastYcoord.remove(player.getUniqueId()); - YAxisCheck.lastYtime.remove(player.getUniqueId()); - GlideCheck.lastFallDistance.remove(player.getUniqueId()); - GlideCheck.lastDiff.remove(player.getUniqueId()); - GlideCheck.violations.remove(player.getUniqueId()); + FlightCheck.BLOCKS_OVER_FLIGHT.remove(player.getUniqueId()); + YAxisCheck.Y_AXIS_VIOLATIONS.remove(player.getUniqueId()); + YAxisCheck.LAST_Y_AXIS_VIOLATION.remove(player.getUniqueId()); + YAxisCheck.LAST_Y_COORD_CACHE.remove(player.getUniqueId()); + YAxisCheck.LAST_Y_TIME.remove(player.getUniqueId()); + GlideCheck.LAST_FALL_DISTANCE.remove(player.getUniqueId()); + GlideCheck.LAST_DIFFERENCE.remove(player.getUniqueId()); + GlideCheck.VIOLATIONS.remove(player.getUniqueId()); } public void logExitFly(final Player player) { - FlightCheck.movingExempt.put(player.getUniqueId(), System.currentTimeMillis() + magic.EXIT_FLY_TIME()); + FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + magic.EXIT_FLY_TIME()); } public void logJoin(final Player player) { - FlightCheck.movingExempt.put(player.getUniqueId(), System.currentTimeMillis() + magic.JOIN_TIME()); + FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + magic.JOIN_TIME()); } public boolean isMovingExempt(Player player) { - return isDoing(player, FlightCheck.movingExempt, -1); + return isDoing(player, FlightCheck.MOVING_EXEMPT, -1); } public boolean isAscending(Player player) { diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/CheckType.java b/src/main/java/com/rammelkast/anticheatreloaded/check/CheckType.java index a05ace4..2045774 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/CheckType.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/CheckType.java @@ -62,7 +62,6 @@ public enum CheckType { ITEM_SPAM(Permission.CHECK_ITEMSPAM), FAST_INVENTORY(Permission.CHECK_FASTINVENTORY), AUTOTOOL(Permission.CHECK_AUTOTOOL), - KILLAURA(Permission.CHECK_KILLAURA), BLINK(Permission.CHECK_BLINK), VELOCITY(Permission.CHECK_VELOCITY), CRITICALS(Permission.CHECK_CRITICALS), diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java deleted file mode 100644 index eb728ae..0000000 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * AntiCheatReloaded for Bukkit and Spigot. - * Copyright (c) 2012-2015 AntiCheat Team - * Copyright (c) 2016-2020 Rammelkast - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.rammelkast.anticheatreloaded.check.combat; - -import org.bukkit.entity.Player; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.event.player.PlayerMoveEvent; - -/** - * @author Rammelkast - */ -@Deprecated -public class KillAuraCheck { - - //private static final Map NPC_LIST = new HashMap(); - //private static final Map VL_COUNT = new HashMap(); - - public static void cleanPlayer(Player p) { - /*if (!VersionUtil.getVersion().equals("v1_12_R1")) { - return; - } - NPC_LIST.remove(p.getUniqueId());*/ - } - - public static void listenPackets() { - /*if (!VersionUtil.getVersion().equals("v1_12_R1")) { - return; - } - AntiCheatReloaded.getProtocolManager().addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(), - ListenerPriority.NORMAL, new PacketType[] { PacketType.Play.Client.USE_ENTITY }) { - @Override - public void onPacketReceiving(PacketEvent e) { - Player p = e.getPlayer(); - if (!NPC_LIST.containsKey(p.getUniqueId())) - return; - int id = e.getPacket().getIntegers().read(0); - if (NPC_LIST.containsKey(p.getUniqueId())) { - if (NPC_LIST.get(p.getUniqueId()).getID() != id) { - return; - } - } - if (!VL_COUNT.containsKey(p.getUniqueId())) { - VL_COUNT.put(p.getUniqueId(), 1); - NPC_LIST.get(p.getUniqueId()).damage(); - } else { - VL_COUNT.put(p.getUniqueId(), VL_COUNT.get(p.getUniqueId()) + 1); - if (VL_COUNT.get(p.getUniqueId()) >= 5) { - EventListener.log( - new CheckResult(CheckResult.Result.FAILED, - p.getName() + " failed KillAura (botcheck), hit the bot " - + VL_COUNT.get(p.getUniqueId()) + " times (max=5)").getMessage(), - p, CheckType.KILLAURA); - AntiCheatReloaded.getPlugin().onKillAuraViolation(); - VL_COUNT.remove(p.getUniqueId()); - } - } - } - });*/ - } - - public static void doDamageEvent(EntityDamageByEntityEvent e, Player p) { - /*if (!VersionUtil.getVersion().equals("v1_12_R1")) { - return; - } - if (NPC_LIST.containsKey(p.getUniqueId())) - NPC_LIST.get(p.getUniqueId()).damage(e, p); - else { - NPC_1_12 npc = new NPC_1_12(p); - NPC_LIST.put(p.getUniqueId(), npc); - npc.spawn(); - }*/ - } - - public static void doMove(PlayerMoveEvent e) { - /*if (!VersionUtil.getVersion().equals("v1_12_R1")) { - return; - } - if (NPC_LIST.containsKey(e.getPlayer().getUniqueId())) { - NPC_LIST.get(e.getPlayer().getUniqueId()).move(e); - }*/ - } - -} diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/BlinkCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/BlinkCheck.java index cfe1a68..d96e952 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/BlinkCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/BlinkCheck.java @@ -51,7 +51,7 @@ public class BlinkCheck { public void run() { MOVE_COUNT.clear(); } - }.runTaskTimer(AntiCheatReloaded.getPlugin(), 100, 20); + }.runTaskTimer(AntiCheatReloaded.getPlugin(), 20, 20); } public static void listenPackets() { diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FlightCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FlightCheck.java index a89029c..ebac095 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FlightCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FlightCheck.java @@ -38,11 +38,10 @@ import com.rammelkast.anticheatreloaded.util.VersionUtil; */ public class FlightCheck { + public static final Map BLOCKS_OVER_FLIGHT = new HashMap(); + public static final Map MOVING_EXEMPT = new HashMap(); private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); - public static Map blocksOverFlight = new HashMap(); - public static Map movingExempt = new HashMap(); - public static CheckResult runCheck(Player player, Distance distance) { if (distance.getYDifference() > AntiCheatReloaded.getManager().getBackend().getMagic().TELEPORT_MIN() || VersionUtil.isFlying(player)) { @@ -62,32 +61,32 @@ public class FlightCheck { "FENCE_GATE" })) { - if (!blocksOverFlight.containsKey(uuid)) { - blocksOverFlight.put(uuid, 0D); + if (!BLOCKS_OVER_FLIGHT.containsKey(uuid)) { + BLOCKS_OVER_FLIGHT.put(uuid, 0D); } - blocksOverFlight.put(uuid, (blocksOverFlight.get(uuid) + distance.getXDifference() + BLOCKS_OVER_FLIGHT.put(uuid, (BLOCKS_OVER_FLIGHT.get(uuid) + distance.getXDifference() + distance.getYDifference() + distance.getZDifference())); if (y1 > y2) { - blocksOverFlight.put(uuid, (blocksOverFlight.get(uuid) - distance.getYDifference())); + BLOCKS_OVER_FLIGHT.put(uuid, (BLOCKS_OVER_FLIGHT.get(uuid) - distance.getYDifference())); } - if (blocksOverFlight.get(uuid) > AntiCheatReloaded.getManager().getBackend().getMagic().FLIGHT_BLOCK_LIMIT() + if (BLOCKS_OVER_FLIGHT.get(uuid) > AntiCheatReloaded.getManager().getBackend().getMagic().FLIGHT_BLOCK_LIMIT() && (y1 <= y2)) { return new CheckResult(CheckResult.Result.FAILED, - player.getName() + " flew over " + blocksOverFlight.get(uuid) + " blocks (max=" + player.getName() + " flew over " + BLOCKS_OVER_FLIGHT.get(uuid) + " blocks (max=" + AntiCheatReloaded.getManager().getBackend().getMagic().FLIGHT_BLOCK_LIMIT() + ")"); } } else { - blocksOverFlight.put(uuid, 0D); + BLOCKS_OVER_FLIGHT.put(uuid, 0D); } return PASS; } public static boolean isMovingExempt(Player player) { - return isDoing(player, movingExempt, -1); + return isDoing(player, MOVING_EXEMPT, -1); } private static boolean isDoing(Player player, Map map, double max) { diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/GlideCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/GlideCheck.java index 8905eb0..aa31bb1 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/GlideCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/GlideCheck.java @@ -20,6 +20,7 @@ package com.rammelkast.anticheatreloaded.check.movement; import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.HashMap; import java.util.Map; import java.util.UUID; @@ -35,36 +36,37 @@ import com.rammelkast.anticheatreloaded.util.VersionUtil; public class GlideCheck { + public static final Map LAST_DIFFERENCE = new HashMap(); + public static final Map LAST_FALL_DISTANCE = new HashMap(); + public static final Map VIOLATIONS = new HashMap(); private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); - public static Map lastDiff = new HashMap(); - public static Map lastFallDistance = new HashMap(); - public static Map violations = new HashMap(); - public static CheckResult runCheck(Player player, Distance distance) { if (VersionUtil.isFlying(player)) { return PASS; } - if (player.getLocation().getBlock().getType() == Material.LADDER || player.getLocation().getBlock().getRelative(0, 1, 0).getType() == Material.LADDER) { + if (player.getLocation().getBlock().getType() == Material.LADDER + || player.getLocation().getBlock().getRelative(0, 1, 0).getType() == Material.LADDER) { return PASS; } - if (!lastDiff.containsKey(player.getUniqueId())) { - lastDiff.put(player.getUniqueId(), distance.getYDifference()); + if (!LAST_DIFFERENCE.containsKey(player.getUniqueId())) { + LAST_DIFFERENCE.put(player.getUniqueId(), distance.getYDifference()); return PASS; } - if (!lastFallDistance.containsKey(player.getUniqueId())) { - lastFallDistance.put(player.getUniqueId(), player.getFallDistance()); + if (!LAST_FALL_DISTANCE.containsKey(player.getUniqueId())) { + LAST_FALL_DISTANCE.put(player.getUniqueId(), player.getFallDistance()); return PASS; } double yDiff = distance.getYDifference(); float fallDistance = player.getFallDistance(); - if (yDiff == lastDiff.get(player.getUniqueId()) && fallDistance > lastFallDistance.get(player.getUniqueId())) { - if (!violations.containsKey(player.getUniqueId())) { - violations.put(player.getUniqueId(), 1); + if (yDiff == LAST_DIFFERENCE.get(player.getUniqueId()) + && fallDistance > LAST_FALL_DISTANCE.get(player.getUniqueId())) { + if (!VIOLATIONS.containsKey(player.getUniqueId())) { + VIOLATIONS.put(player.getUniqueId(), 1); } else { - if (violations.get(player.getUniqueId()) + 1 >= AntiCheatReloaded.getManager().getBackend().getMagic() + if (VIOLATIONS.get(player.getUniqueId()) + 1 >= AntiCheatReloaded.getManager().getBackend().getMagic() .GLIDE_LIMIT()) { - violations.remove(player.getUniqueId()); + VIOLATIONS.remove(player.getUniqueId()); Location to = player.getLocation(); to.setY(to.getY() - distanceToFall(to)); player.teleport(to); @@ -72,16 +74,16 @@ public class GlideCheck { AntiCheatReloaded.getPlugin().onGlideViolation(); return new CheckResult(CheckResult.Result.FAILED, player.getName() + " was set back for gliding (yDiff=" - + new BigDecimal(yDiff).setScale(2, BigDecimal.ROUND_UP) + ")"); + + new BigDecimal(yDiff).setScale(2, RoundingMode.HALF_UP) + ")"); } else { - violations.put(player.getUniqueId(), violations.get(player.getUniqueId()) + 1); + VIOLATIONS.put(player.getUniqueId(), VIOLATIONS.get(player.getUniqueId()) + 1); } } } else { // TODO more sophisticated check } - lastDiff.put(player.getUniqueId(), distance.getYDifference()); - lastFallDistance.put(player.getUniqueId(), player.getFallDistance()); + LAST_DIFFERENCE.put(player.getUniqueId(), distance.getYDifference()); + LAST_FALL_DISTANCE.put(player.getUniqueId(), player.getFallDistance()); return PASS; } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/SpeedCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/SpeedCheck.java index dd7aa86..2c6bb04 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/SpeedCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/SpeedCheck.java @@ -32,8 +32,8 @@ import com.rammelkast.anticheatreloaded.util.VersionUtil; public class SpeedCheck { + public static final Map SPEED_VIOLATIONS = new HashMap(); private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); - public static Map speedViolation = new HashMap(); public static boolean isSpeedExempt(Player player) { return AntiCheatReloaded.getManager().getBackend().isMovingExempt(player) @@ -75,7 +75,7 @@ public class SpeedCheck { max += speed > 0 ? player.getWalkSpeed() - 0.2f : 0; if (x > max || z > max) { - int num = AntiCheatReloaded.getManager().getBackend().increment(player, speedViolation, + int num = AntiCheatReloaded.getManager().getBackend().increment(player, SPEED_VIOLATIONS, AntiCheatReloaded.getManager().getBackend().getMagic().SPEED_MAX()); if (num >= AntiCheatReloaded.getManager().getBackend().getMagic().SPEED_MAX()) { return new CheckResult(CheckResult.Result.FAILED, @@ -86,7 +86,7 @@ public class SpeedCheck { return PASS; } } else { - speedViolation.put(player.getUniqueId(), 0); + SPEED_VIOLATIONS.put(player.getUniqueId(), 0); return PASS; } } else { diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/WaterWalkCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/WaterWalkCheck.java index 4752a5d..2815b3d 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/WaterWalkCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/WaterWalkCheck.java @@ -40,21 +40,20 @@ import com.rammelkast.anticheatreloaded.util.VersionUtil; */ public class WaterWalkCheck { + public static final List IS_IN_WATER = new ArrayList(); + public static final List IS_IN_WATER_CACHE = new ArrayList(); + public static final Map WATER_SPEED_VIOLATIONS = new HashMap(); + public static final Map WATER_ASCENSION_VIOLATIONS = new HashMap(); private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); - public static List isInWater = new ArrayList(); - public static List isInWaterCache = new ArrayList(); - public static Map waterSpeedViolation = new HashMap(); - public static Map waterAscensionViolation = new HashMap(); - public static CheckResult runCheck(Player player, double x, double y, double z) { Block block = player.getLocation().getBlock(); UUID uuid = player.getUniqueId(); if (player.getVehicle() == null && !player.isFlying() && !VersionUtil.isFrostWalk(player)) { if (block.isLiquid()) { - if (isInWater.contains(uuid)) { - if (isInWaterCache.contains(uuid)) { + if (IS_IN_WATER.contains(uuid)) { + if (IS_IN_WATER_CACHE.contains(uuid)) { if (player.getNearbyEntities(1, 1, 1).isEmpty()) { boolean b; if (!Utilities.sprintFly(player)) { @@ -73,50 +72,50 @@ public class WaterWalkCheck { b = true; } if (b) { - if (waterSpeedViolation.containsKey(uuid)) { - int v = waterSpeedViolation.get(uuid); + if (WATER_SPEED_VIOLATIONS.containsKey(uuid)) { + int v = WATER_SPEED_VIOLATIONS.get(uuid); if (v >= AntiCheatReloaded.getManager().getBackend().getMagic() .WATER_SPEED_VIOLATION_MAX()) { - waterSpeedViolation.put(uuid, 0); + WATER_SPEED_VIOLATIONS.put(uuid, 0); return new CheckResult(CheckResult.Result.FAILED, player.getName() + " stood on water " + v + " times (can't stand on " + block.getType() + " or " + block.getRelative(BlockFace.DOWN).getType() + ")"); } else { - waterSpeedViolation.put(uuid, v + 1); + WATER_SPEED_VIOLATIONS.put(uuid, v + 1); } } else { - waterSpeedViolation.put(uuid, 1); + WATER_SPEED_VIOLATIONS.put(uuid, 1); } } } } else { - isInWaterCache.add(uuid); + IS_IN_WATER_CACHE.add(uuid); return PASS; } } else { - isInWater.add(uuid); + IS_IN_WATER.add(uuid); return PASS; } } else if (block.getRelative(BlockFace.DOWN).isLiquid() && !AntiCheatReloaded.getManager().getBackend().isAscending(player) && Utilities.cantStandAt(block) && Utilities.cantStandAt(block.getRelative(BlockFace.DOWN))) { - if (waterAscensionViolation.containsKey(uuid)) { - int v = waterAscensionViolation.get(uuid); + if (WATER_ASCENSION_VIOLATIONS.containsKey(uuid)) { + int v = WATER_ASCENSION_VIOLATIONS.get(uuid); if (v >= AntiCheatReloaded.getManager().getBackend().getMagic().WATER_ASCENSION_VIOLATION_MAX()) { - waterAscensionViolation.put(uuid, 0); + WATER_ASCENSION_VIOLATIONS.put(uuid, 0); return new CheckResult(CheckResult.Result.FAILED, player.getName() + " stood on water " + v + " times (can't stand on " + block.getType() + " or " + block.getRelative(BlockFace.DOWN).getType() + ")"); } else { - waterAscensionViolation.put(uuid, v + 1); + WATER_ASCENSION_VIOLATIONS.put(uuid, v + 1); } } else { - waterAscensionViolation.put(uuid, 1); + WATER_ASCENSION_VIOLATIONS.put(uuid, 1); } } else { - isInWater.remove(uuid); - isInWaterCache.remove(uuid); + IS_IN_WATER.remove(uuid); + IS_IN_WATER_CACHE.remove(uuid); } } return PASS; diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/YAxisCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/YAxisCheck.java index d8a92d2..8effb4b 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/YAxisCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/YAxisCheck.java @@ -37,13 +37,12 @@ import com.rammelkast.anticheatreloaded.util.VersionUtil; public class YAxisCheck { + public static final Map LAST_Y_COORD_CACHE = new HashMap(); + public static final Map LAST_Y_TIME = new HashMap(); + public static final Map Y_AXIS_VIOLATIONS = new HashMap(); + public static final Map LAST_Y_AXIS_VIOLATION = new HashMap(); private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); - public static Map lastYcoord = new HashMap(); - public static Map lastYtime = new HashMap(); - public static Map yAxisViolations = new HashMap(); - public static Map yAxisLastViolation = new HashMap(); - private static boolean hasJumpPotion(Player player) { return player.hasPotionEffect(PotionEffectType.JUMP); } @@ -61,49 +60,49 @@ public class YAxisCheck { double y1 = player.getLocation().getY(); UUID uuid = player.getUniqueId(); // Fix Y axis spam. - if (!lastYcoord.containsKey(uuid) || !lastYtime.containsKey(uuid) - || !yAxisLastViolation.containsKey(uuid)) { - lastYcoord.put(uuid, y1); - yAxisViolations.put(uuid, 0); - yAxisLastViolation.put(uuid, 0L); - lastYtime.put(uuid, System.currentTimeMillis()); + if (!LAST_Y_COORD_CACHE.containsKey(uuid) || !LAST_Y_TIME.containsKey(uuid) + || !LAST_Y_AXIS_VIOLATION.containsKey(uuid)) { + LAST_Y_COORD_CACHE.put(uuid, y1); + Y_AXIS_VIOLATIONS.put(uuid, 0); + LAST_Y_AXIS_VIOLATION.put(uuid, 0L); + LAST_Y_TIME.put(uuid, System.currentTimeMillis()); } else { - if (y1 > lastYcoord.get(uuid) - && yAxisViolations.get(uuid) > AntiCheatReloaded.getManager().getBackend().getMagic() + if (y1 > LAST_Y_COORD_CACHE.get(uuid) + && Y_AXIS_VIOLATIONS.get(uuid) > AntiCheatReloaded.getManager().getBackend().getMagic() .Y_MAXVIOLATIONS() - && (System.currentTimeMillis() - yAxisLastViolation.get(uuid)) < AntiCheatReloaded.getManager() + && (System.currentTimeMillis() - LAST_Y_AXIS_VIOLATION.get(uuid)) < AntiCheatReloaded.getManager() .getBackend().getMagic().Y_MAXVIOTIME()) { Location g = player.getLocation(); - yAxisViolations.put(uuid, yAxisViolations.get(uuid) + 1); - yAxisLastViolation.put(uuid, System.currentTimeMillis()); + Y_AXIS_VIOLATIONS.put(uuid, Y_AXIS_VIOLATIONS.get(uuid) + 1); + LAST_Y_AXIS_VIOLATION.put(uuid, System.currentTimeMillis()); if (!AntiCheatReloaded.getManager().getBackend().silentMode()) { - g.setY(lastYcoord.get(uuid)); + g.setY(LAST_Y_COORD_CACHE.get(uuid)); if (g.getBlock().getType() == Material.AIR) { player.teleport(g); } } return new CheckResult(CheckResult.Result.FAILED, - player.getName() + " tried to fly on y-axis " + yAxisViolations.get(uuid) + " times (max =" + player.getName() + " tried to fly on y-axis " + Y_AXIS_VIOLATIONS.get(uuid) + " times (max =" + AntiCheatReloaded.getManager().getBackend().getMagic().Y_MAXVIOLATIONS() + ")"); } else { - if (yAxisViolations.get(uuid) > AntiCheatReloaded.getManager().getBackend().getMagic() + if (Y_AXIS_VIOLATIONS.get(uuid) > AntiCheatReloaded.getManager().getBackend().getMagic() .Y_MAXVIOLATIONS() - && (System.currentTimeMillis() - yAxisLastViolation.get(uuid)) > AntiCheatReloaded + && (System.currentTimeMillis() - LAST_Y_AXIS_VIOLATION.get(uuid)) > AntiCheatReloaded .getManager().getBackend().getMagic().Y_MAXVIOTIME()) { - yAxisViolations.put(uuid, 0); - yAxisLastViolation.put(uuid, 0L); + Y_AXIS_VIOLATIONS.put(uuid, 0); + LAST_Y_AXIS_VIOLATION.put(uuid, 0L); } } - long i = System.currentTimeMillis() - lastYtime.get(uuid); + long i = System.currentTimeMillis() - LAST_Y_TIME.get(uuid); double diff = AntiCheatReloaded.getManager().getBackend().getMagic().Y_MAXDIFF() + (Utilities.isStair(player.getLocation().add(0, -1, 0).getBlock()) ? 0.5 : 0.0); - if ((y1 - lastYcoord.get(uuid)) > diff + if ((y1 - LAST_Y_COORD_CACHE.get(uuid)) > diff && i < AntiCheatReloaded.getManager().getBackend().getMagic().Y_TIME()) { Location g = player.getLocation(); - yAxisViolations.put(uuid, yAxisViolations.get(uuid) + 1); - yAxisLastViolation.put(uuid, System.currentTimeMillis()); + Y_AXIS_VIOLATIONS.put(uuid, Y_AXIS_VIOLATIONS.get(uuid) + 1); + LAST_Y_AXIS_VIOLATION.put(uuid, System.currentTimeMillis()); if (!AntiCheatReloaded.getManager().getBackend().silentMode()) { - g.setY(lastYcoord.get(uuid)); + g.setY(LAST_Y_COORD_CACHE.get(uuid)); if (g.getBlock().getType() == Material.AIR) { player.teleport(g); } @@ -111,12 +110,12 @@ public class YAxisCheck { return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to fly on y-axis in " + i + " ms (min =" + AntiCheatReloaded.getManager().getBackend().getMagic().Y_TIME() + ")"); } else { - if ((y1 - lastYcoord.get(uuid)) > AntiCheatReloaded.getManager().getBackend().getMagic().Y_MAXDIFF() + if ((y1 - LAST_Y_COORD_CACHE.get(uuid)) > AntiCheatReloaded.getManager().getBackend().getMagic().Y_MAXDIFF() + 1 - || (System.currentTimeMillis() - lastYtime.get(uuid)) > AntiCheatReloaded.getManager() + || (System.currentTimeMillis() - LAST_Y_TIME.get(uuid)) > AntiCheatReloaded.getManager() .getBackend().getMagic().Y_TIME()) { - lastYtime.put(uuid, System.currentTimeMillis()); - lastYcoord.put(uuid, y1); + LAST_Y_TIME.put(uuid, System.currentTimeMillis()); + LAST_Y_COORD_CACHE.put(uuid, y1); } } } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java b/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java index 3a64fe8..39f8b2e 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java @@ -29,18 +29,16 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; +import org.bukkit.event.entity.EntityShootBowEvent; +import org.bukkit.event.entity.FoodLevelChangeEvent; import com.rammelkast.anticheatreloaded.AntiCheatReloaded; import com.rammelkast.anticheatreloaded.check.CheckResult; import com.rammelkast.anticheatreloaded.check.CheckType; import com.rammelkast.anticheatreloaded.check.combat.CriticalsCheck; -import com.rammelkast.anticheatreloaded.check.combat.KillAuraCheck; import com.rammelkast.anticheatreloaded.check.combat.VelocityCheck; import com.rammelkast.anticheatreloaded.util.Distance; -import org.bukkit.event.entity.EntityShootBowEvent; -import org.bukkit.event.entity.FoodLevelChangeEvent; - public class EntityListener extends EventListener { @EventHandler @@ -105,9 +103,6 @@ public class EntityListener extends EventListener { if (event instanceof EntityDamageByEntityEvent) { EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event; if (e.getDamager() instanceof Player) { - if (getCheckManager().willCheck((Player)e.getDamager(), CheckType.KILLAURA)) { - KillAuraCheck.doDamageEvent(e, (Player)e.getDamager()); - } if (getCheckManager().willCheck((Player)e.getDamager(), CheckType.CRITICALS)) { CriticalsCheck.doDamageEvent(e, (Player)e.getDamager()); } @@ -118,7 +113,7 @@ public class EntityListener extends EventListener { if (e.getDamager() instanceof Player) { Player p = (Player) e.getDamager(); getBackend().logDamage(p, 1); - int value = p.getInventory().getItemInHand().containsEnchantment(Enchantment.KNOCKBACK) ? 2 : 1; + int value = p.getInventory().getItemInMainHand().containsEnchantment(Enchantment.KNOCKBACK) ? 2 : 1; getBackend().logDamage(player, value); if (getCheckManager().willCheck(p, CheckType.LONG_REACH)) { Distance distance = new Distance(player.getLocation(), p.getLocation()); diff --git a/src/main/java/com/rammelkast/anticheatreloaded/metrics/Metrics.java b/src/main/java/com/rammelkast/anticheatreloaded/metrics/Metrics.java index bae14ee..ac47bab 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/metrics/Metrics.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/metrics/Metrics.java @@ -19,20 +19,24 @@ package com.rammelkast.anticheatreloaded.metrics; +import java.io.BufferedReader; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.File; import java.io.IOException; +import java.io.InputStreamReader; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.HashMap; +import java.util.Collection; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Timer; import java.util.TimerTask; import java.util.UUID; +import java.util.concurrent.Callable; import java.util.logging.Level; import java.util.zip.GZIPOutputStream; @@ -40,28 +44,69 @@ import javax.net.ssl.HttpsURLConnection; import org.bukkit.Bukkit; import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.ServicePriority; -import org.bukkit.plugin.java.JavaPlugin; -import org.json.simple.JSONArray; -import org.json.simple.JSONObject; -//bStats.org/ to learn more about bStats! +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import com.google.gson.JsonPrimitive; + +/** + * bStats collects some data for plugin authors. + *

+ * Check out https://bStats.org/ to learn more about bStats! + */ +@SuppressWarnings({ "WeakerAccess", "unused" }) public class Metrics { + static { + // You can use the property to disable the check in your test environment + if (System.getProperty("bstats.relocatecheck") == null + || !System.getProperty("bstats.relocatecheck").equals("false")) { + // Maven's Relocate is clever and changes strings, too. So we have to use this + // little "trick" ... :D + final String defaultPackage = new String( + new byte[] { 'o', 'r', 'g', '.', 'b', 's', 't', 'a', 't', 's', '.', 'b', 'u', 'k', 'k', 'i', 't' }); + final String examplePackage = new String( + new byte[] { 'y', 'o', 'u', 'r', '.', 'p', 'a', 'c', 'k', 'a', 'g', 'e' }); + // We want to make sure nobody just copy & pastes the example and use the wrong + // package names + if (Metrics.class.getPackage().getName().equals(defaultPackage) + || Metrics.class.getPackage().getName().equals(examplePackage)) { + throw new IllegalStateException("bStats Metrics class has not been relocated correctly!"); + } + } + } + // The version of this bStats class public static final int B_STATS_VERSION = 1; // The url to which the data is sent - private static final String URL = "https://bStats.org/submitData"; + private static final String URL = "https://bStats.org/submitData/bukkit"; + + // Is bStats enabled on this server? + private boolean enabled; // Should failed requests be logged? private static boolean logFailedRequests; + // Should the sent data be logged? + private static boolean logSentData; + + // Should the response text be logged? + private static boolean logResponseStatusText; + // The uuid of the server private static String serverUUID; // The plugin - private final JavaPlugin plugin; + private final Plugin plugin; + + // The plugin id + private final int pluginId; // A list with all custom charts private final List charts = new ArrayList<>(); @@ -69,13 +114,17 @@ public class Metrics { /** * Class constructor. * - * @param plugin The plugin which stats should be submitted. + * @param plugin The plugin which stats should be submitted. + * @param pluginId The id of the plugin. It can be found at + * What is my + * plugin id? */ - public Metrics(JavaPlugin plugin) { + public Metrics(Plugin plugin, int pluginId) { if (plugin == null) { throw new IllegalArgumentException("Plugin cannot be null!"); } this.plugin = plugin; + this.pluginId = pluginId; // Get the config file File bStatsFolder = new File(plugin.getDataFolder().getParentFile(), "bStats"); @@ -91,6 +140,10 @@ public class Metrics { config.addDefault("serverUuid", UUID.randomUUID().toString()); // Should failed request be logged? config.addDefault("logFailedRequests", false); + // Should the sent data be logged? + config.addDefault("logSentData", false); + // Should the response text be logged? + config.addDefault("logResponseStatusText", false); // Inform the server owners about bStats config.options().header( @@ -106,9 +159,13 @@ public class Metrics { } // Load the data + enabled = config.getBoolean("enabled", true); serverUUID = config.getString("serverUuid"); logFailedRequests = config.getBoolean("logFailedRequests", false); - if (config.getBoolean("enabled", true)) { + logSentData = config.getBoolean("logSentData", false); + logResponseStatusText = config.getBoolean("logResponseStatusText", false); + + if (enabled) { boolean found = false; // Search for all other bStats Metrics classes to see if we are the first one for (Class service : Bukkit.getServicesManager().getKnownServices()) { @@ -128,6 +185,15 @@ public class Metrics { } } + /** + * Checks if bStats is enabled. + * + * @return Whether bStats is enabled or not. + */ + public boolean isEnabled() { + return enabled; + } + /** * Adds a custom chart. * @@ -156,12 +222,7 @@ public class Metrics { // use the Bukkit scheduler // Don't be afraid! The connection to the bStats server is still async, only the // stats collection is sync ;) - Bukkit.getScheduler().runTask(plugin, new Runnable() { - @Override - public void run() { - submitData(); - } - }); + Bukkit.getScheduler().runTask(plugin, () -> submitData()); } }, 1000 * 60 * 5, 1000 * 60 * 30); // Submit the data every 30 minutes, first time after 5 minutes to give other @@ -176,24 +237,25 @@ public class Metrics { * * @return The plugin specific data. */ - public JSONObject getPluginData() { - JSONObject data = new JSONObject(); + public JsonObject getPluginData() { + JsonObject data = new JsonObject(); String pluginName = plugin.getDescription().getName(); String pluginVersion = plugin.getDescription().getVersion(); - data.put("pluginName", pluginName); // Append the name of the plugin - data.put("pluginVersion", pluginVersion); // Append the version of the plugin - JSONArray customCharts = new JSONArray(); + data.addProperty("pluginName", pluginName); // Append the name of the plugin + data.addProperty("id", pluginId); // Append the id of the plugin + data.addProperty("pluginVersion", pluginVersion); // Append the version of the plugin + JsonArray customCharts = new JsonArray(); for (CustomChart customChart : charts) { // Add the data of the custom charts - JSONObject chart = customChart.getRequestJsonObject(); + JsonObject chart = customChart.getRequestJsonObject(); if (chart == null) { // If the chart is null, we skip it continue; } customCharts.add(chart); } - data.put("customCharts", customCharts); + data.add("customCharts", customCharts); return data; } @@ -203,12 +265,23 @@ public class Metrics { * * @return The server specific data. */ - private JSONObject getServerData() { + private JsonObject getServerData() { // Minecraft specific data - int playerAmount = Bukkit.getOnlinePlayers().size(); + int playerAmount; + try { + // Around MC 1.8 the return type was changed to a collection from an array, + // This fixes java.lang.NoSuchMethodError: + // org.bukkit.Bukkit.getOnlinePlayers()Ljava/util/Collection; + Method onlinePlayersMethod = Class.forName("org.bukkit.Server").getMethod("getOnlinePlayers"); + playerAmount = onlinePlayersMethod.getReturnType().equals(Collection.class) + ? ((Collection) onlinePlayersMethod.invoke(Bukkit.getServer())).size() + : ((Player[]) onlinePlayersMethod.invoke(Bukkit.getServer())).length; + } catch (Exception e) { + playerAmount = Bukkit.getOnlinePlayers().size(); // Just use the new method if the Reflection failed + } int onlineMode = Bukkit.getOnlineMode() ? 1 : 0; - String bukkitVersion = org.bukkit.Bukkit.getVersion(); - bukkitVersion = bukkitVersion.substring(bukkitVersion.indexOf("MC: ") + 4, bukkitVersion.length() - 1); + String bukkitVersion = Bukkit.getVersion(); + String bukkitName = Bukkit.getName(); // OS/Java specific data String javaVersion = System.getProperty("java.version"); @@ -217,19 +290,20 @@ public class Metrics { String osVersion = System.getProperty("os.version"); int coreCount = Runtime.getRuntime().availableProcessors(); - JSONObject data = new JSONObject(); + JsonObject data = new JsonObject(); - data.put("serverUUID", serverUUID); + data.addProperty("serverUUID", serverUUID); - data.put("playerAmount", playerAmount); - data.put("onlineMode", onlineMode); - data.put("bukkitVersion", bukkitVersion); + data.addProperty("playerAmount", playerAmount); + data.addProperty("onlineMode", onlineMode); + data.addProperty("bukkitVersion", bukkitVersion); + data.addProperty("bukkitName", bukkitName); - data.put("javaVersion", javaVersion); - data.put("osName", osName); - data.put("osArch", osArch); - data.put("osVersion", osVersion); - data.put("coreCount", coreCount); + data.addProperty("javaVersion", javaVersion); + data.addProperty("osName", osName); + data.addProperty("osArch", osArch); + data.addProperty("osVersion", osVersion); + data.addProperty("coreCount", coreCount); return data; } @@ -238,57 +312,77 @@ public class Metrics { * Collects the data and sends it afterwards. */ private void submitData() { - final JSONObject data = getServerData(); + final JsonObject data = getServerData(); - JSONArray pluginData = new JSONArray(); + JsonArray pluginData = new JsonArray(); // Search for all other bStats Metrics classes to get their plugin data for (Class service : Bukkit.getServicesManager().getKnownServices()) { try { service.getField("B_STATS_VERSION"); // Our identifier :) + + for (RegisteredServiceProvider provider : Bukkit.getServicesManager().getRegistrations(service)) { + try { + Object plugin = provider.getService().getMethod("getPluginData").invoke(provider.getProvider()); + if (plugin instanceof JsonObject) { + pluginData.add((JsonObject) plugin); + } else { // old bstats version compatibility + try { + Class jsonObjectJsonSimple = Class.forName("org.json.simple.JSONObject"); + if (plugin.getClass().isAssignableFrom(jsonObjectJsonSimple)) { + Method jsonStringGetter = jsonObjectJsonSimple.getDeclaredMethod("toJSONString"); + jsonStringGetter.setAccessible(true); + String jsonString = (String) jsonStringGetter.invoke(plugin); + JsonObject object = new JsonParser().parse(jsonString).getAsJsonObject(); + pluginData.add(object); + } + } catch (ClassNotFoundException e) { + // minecraft version 1.14+ + if (logFailedRequests) { + this.plugin.getLogger().log(Level.SEVERE, "Encountered unexpected exception", e); + } + } + } + } catch (NullPointerException | NoSuchMethodException | IllegalAccessException + | InvocationTargetException ignored) { + } + } } catch (NoSuchFieldException ignored) { - continue; // Continue "searching" - } - // Found one! - try { - pluginData.add(service.getMethod("getPluginData").invoke(Bukkit.getServicesManager().load(service))); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { } } - data.put("plugins", pluginData); + data.add("plugins", pluginData); // Create a new thread for the connection to the bStats server - new Thread(new Runnable() { - @Override - public void run() { - try { - // Send the data - sendData(data); - } catch (Exception e) { - // Something went wrong! :( - if (logFailedRequests) { - plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), - e); - } + new Thread(() -> { + try { + // Send the data + sendData(plugin, data); + } catch (Exception e) { + // Something went wrong! :( + if (logFailedRequests) { + plugin.getLogger().log(Level.WARNING, "Could not submit plugin stats of " + plugin.getName(), e); } } }).start(); - } /** * Sends the data to the bStats server. * - * @param data The data to send. + * @param plugin Any plugin. It's just used to get a logger instance. + * @param data The data to send. * @throws Exception If the request failed. */ - private static void sendData(JSONObject data) throws Exception { + private static void sendData(Plugin plugin, JsonObject data) throws Exception { if (data == null) { throw new IllegalArgumentException("Data cannot be null!"); } if (Bukkit.isPrimaryThread()) { throw new IllegalAccessException("This method must not be called from the main thread!"); } + if (logSentData) { + plugin.getLogger().info("Sending data to bStats: " + data); + } HttpsURLConnection connection = (HttpsURLConnection) new URL(URL).openConnection(); // Compress the data to save bandwidth @@ -305,12 +399,21 @@ public class Metrics { // Send data connection.setDoOutput(true); - DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream()); - outputStream.write(compressedData); - outputStream.flush(); - outputStream.close(); + try (DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream())) { + outputStream.write(compressedData); + } - connection.getInputStream().close(); // We don't care about the response - Just send our data :) + StringBuilder builder = new StringBuilder(); + try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { + String line; + while ((line = bufferedReader.readLine()) != null) { + builder.append(line); + } + } + + if (logResponseStatusText) { + plugin.getLogger().info("Sent data to bStats and received response: " + builder); + } } /** @@ -325,9 +428,9 @@ public class Metrics { return null; } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - GZIPOutputStream gzip = new GZIPOutputStream(outputStream); - gzip.write(str.getBytes("UTF-8")); - gzip.close(); + try (GZIPOutputStream gzip = new GZIPOutputStream(outputStream)) { + gzip.write(str.getBytes(StandardCharsets.UTF_8)); + } return outputStream.toByteArray(); } @@ -337,30 +440,30 @@ public class Metrics { public static abstract class CustomChart { // The id of the chart - protected final String chartId; + final String chartId; /** * Class constructor. * * @param chartId The id of the chart. */ - public CustomChart(String chartId) { + CustomChart(String chartId) { if (chartId == null || chartId.isEmpty()) { throw new IllegalArgumentException("ChartId cannot be null or empty!"); } this.chartId = chartId; } - protected JSONObject getRequestJsonObject() { - JSONObject chart = new JSONObject(); - chart.put("chartId", chartId); + private JsonObject getRequestJsonObject() { + JsonObject chart = new JsonObject(); + chart.addProperty("chartId", chartId); try { - JSONObject data = getChartData(); + JsonObject data = getChartData(); if (data == null) { // If the data is null we don't send the chart. return null; } - chart.put("data", data); + chart.add("data", data); } catch (Throwable t) { if (logFailedRequests) { Bukkit.getLogger().log(Level.WARNING, "Failed to get data for custom chart with id " + chartId, t); @@ -370,40 +473,37 @@ public class Metrics { return chart; } - protected abstract JSONObject getChartData(); + protected abstract JsonObject getChartData() throws Exception; } /** * Represents a custom simple pie. */ - public static abstract class SimplePie extends CustomChart { + public static class SimplePie extends CustomChart { + + private final Callable callable; /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. */ - public SimplePie(String chartId) { + public SimplePie(String chartId, Callable callable) { super(chartId); + this.callable = callable; } - /** - * Gets the value of the pie. - * - * @return The value of the pie. - */ - public abstract String getValue(); - @Override - protected JSONObject getChartData() { - JSONObject data = new JSONObject(); - String value = getValue(); + protected JsonObject getChartData() throws Exception { + JsonObject data = new JsonObject(); + String value = callable.call(); if (value == null || value.isEmpty()) { // Null = skip the chart return null; } - data.put("value", value); + data.addProperty("value", value); return data; } } @@ -411,31 +511,26 @@ public class Metrics { /** * Represents a custom advanced pie. */ - public static abstract class AdvancedPie extends CustomChart { + public static class AdvancedPie extends CustomChart { + + private final Callable> callable; /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. */ - public AdvancedPie(String chartId) { + public AdvancedPie(String chartId, Callable> callable) { super(chartId); + this.callable = callable; } - /** - * Gets the values of the pie. - * - * @param valueMap Just an empty map. The only reason it exists is to make your - * life easier. You don't have to create a map yourself! - * @return The values of the pie. - */ - public abstract HashMap getValues(HashMap valueMap); - @Override - protected JSONObject getChartData() { - JSONObject data = new JSONObject(); - JSONObject values = new JSONObject(); - HashMap map = getValues(new HashMap()); + protected JsonObject getChartData() throws Exception { + JsonObject data = new JsonObject(); + JsonObject values = new JsonObject(); + Map map = callable.call(); if (map == null || map.isEmpty()) { // Null = skip the chart return null; @@ -446,13 +541,62 @@ public class Metrics { continue; // Skip this invalid } allSkipped = false; - values.put(entry.getKey(), entry.getValue()); + values.addProperty(entry.getKey(), entry.getValue()); } if (allSkipped) { // Null = skip the chart return null; } - data.put("values", values); + data.add("values", values); + return data; + } + } + + /** + * Represents a custom drilldown pie. + */ + public static class DrilldownPie extends CustomChart { + + private final Callable>> callable; + + /** + * Class constructor. + * + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. + */ + public DrilldownPie(String chartId, Callable>> callable) { + super(chartId); + this.callable = callable; + } + + @Override + public JsonObject getChartData() throws Exception { + JsonObject data = new JsonObject(); + JsonObject values = new JsonObject(); + Map> map = callable.call(); + if (map == null || map.isEmpty()) { + // Null = skip the chart + return null; + } + boolean reallyAllSkipped = true; + for (Map.Entry> entryValues : map.entrySet()) { + JsonObject value = new JsonObject(); + boolean allSkipped = true; + for (Map.Entry valueEntry : map.get(entryValues.getKey()).entrySet()) { + value.addProperty(valueEntry.getKey(), valueEntry.getValue()); + allSkipped = false; + } + if (!allSkipped) { + reallyAllSkipped = false; + values.add(entryValues.getKey(), value); + } + } + if (reallyAllSkipped) { + // Null = skip the chart + return null; + } + data.add("values", values); return data; } } @@ -460,33 +604,30 @@ public class Metrics { /** * Represents a custom single line chart. */ - public static abstract class SingleLineChart extends CustomChart { + public static class SingleLineChart extends CustomChart { + + private final Callable callable; /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. */ - public SingleLineChart(String chartId) { + public SingleLineChart(String chartId, Callable callable) { super(chartId); + this.callable = callable; } - /** - * Gets the value of the chart. - * - * @return The value of the chart. - */ - public abstract int getValue(); - @Override - protected JSONObject getChartData() { - JSONObject data = new JSONObject(); - int value = getValue(); + protected JsonObject getChartData() throws Exception { + JsonObject data = new JsonObject(); + int value = callable.call(); if (value == 0) { // Null = skip the chart return null; } - data.put("value", value); + data.addProperty("value", value); return data; } @@ -495,31 +636,26 @@ public class Metrics { /** * Represents a custom multi line chart. */ - public static abstract class MultiLineChart extends CustomChart { + public static class MultiLineChart extends CustomChart { + + private final Callable> callable; /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. */ - public MultiLineChart(String chartId) { + public MultiLineChart(String chartId, Callable> callable) { super(chartId); + this.callable = callable; } - /** - * Gets the values of the chart. - * - * @param valueMap Just an empty map. The only reason it exists is to make your - * life easier. You don't have to create a map yourself! - * @return The values of the chart. - */ - public abstract HashMap getValues(HashMap valueMap); - @Override - protected JSONObject getChartData() { - JSONObject data = new JSONObject(); - JSONObject values = new JSONObject(); - HashMap map = getValues(new HashMap()); + protected JsonObject getChartData() throws Exception { + JsonObject data = new JsonObject(); + JsonObject values = new JsonObject(); + Map map = callable.call(); if (map == null || map.isEmpty()) { // Null = skip the chart return null; @@ -530,13 +666,13 @@ public class Metrics { continue; // Skip this invalid } allSkipped = false; - values.put(entry.getKey(), entry.getValue()); + values.addProperty(entry.getKey(), entry.getValue()); } if (allSkipped) { // Null = skip the chart return null; } - data.put("values", values); + data.add("values", values); return data; } @@ -545,41 +681,36 @@ public class Metrics { /** * Represents a custom simple bar chart. */ - public static abstract class SimpleBarChart extends CustomChart { + public static class SimpleBarChart extends CustomChart { + + private final Callable> callable; /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. */ - public SimpleBarChart(String chartId) { + public SimpleBarChart(String chartId, Callable> callable) { super(chartId); + this.callable = callable; } - /** - * Gets the value of the chart. - * - * @param valueMap Just an empty map. The only reason it exists is to make your - * life easier. You don't have to create a map yourself! - * @return The value of the chart. - */ - public abstract HashMap getValues(HashMap valueMap); - @Override - protected JSONObject getChartData() { - JSONObject data = new JSONObject(); - JSONObject values = new JSONObject(); - HashMap map = getValues(new HashMap()); + protected JsonObject getChartData() throws Exception { + JsonObject data = new JsonObject(); + JsonObject values = new JsonObject(); + Map map = callable.call(); if (map == null || map.isEmpty()) { // Null = skip the chart return null; } for (Map.Entry entry : map.entrySet()) { - JSONArray categoryValues = new JSONArray(); - categoryValues.add(entry.getValue()); - values.put(entry.getKey(), categoryValues); + JsonArray categoryValues = new JsonArray(); + categoryValues.add(new JsonPrimitive(entry.getValue())); + values.add(entry.getKey(), categoryValues); } - data.put("values", values); + data.add("values", values); return data; } @@ -588,31 +719,26 @@ public class Metrics { /** * Represents a custom advanced bar chart. */ - public static abstract class AdvancedBarChart extends CustomChart { + public static class AdvancedBarChart extends CustomChart { + + private final Callable> callable; /** * Class constructor. * - * @param chartId The id of the chart. + * @param chartId The id of the chart. + * @param callable The callable which is used to request the chart data. */ - public AdvancedBarChart(String chartId) { + public AdvancedBarChart(String chartId, Callable> callable) { super(chartId); + this.callable = callable; } - /** - * Gets the value of the chart. - * - * @param valueMap Just an empty map. The only reason it exists is to make your - * life easier. You don't have to create a map yourself! - * @return The value of the chart. - */ - public abstract HashMap getValues(HashMap valueMap); - @Override - protected JSONObject getChartData() { - JSONObject data = new JSONObject(); - JSONObject values = new JSONObject(); - HashMap map = getValues(new HashMap()); + protected JsonObject getChartData() throws Exception { + JsonObject data = new JsonObject(); + JsonObject values = new JsonObject(); + Map map = callable.call(); if (map == null || map.isEmpty()) { // Null = skip the chart return null; @@ -623,254 +749,19 @@ public class Metrics { continue; // Skip this invalid } allSkipped = false; - JSONArray categoryValues = new JSONArray(); + JsonArray categoryValues = new JsonArray(); for (int categoryValue : entry.getValue()) { - categoryValues.add(categoryValue); + categoryValues.add(new JsonPrimitive(categoryValue)); } - values.put(entry.getKey(), categoryValues); + values.add(entry.getKey(), categoryValues); } if (allSkipped) { // Null = skip the chart return null; } - data.put("values", values); + data.add("values", values); return data; } - } - /** - * Represents a custom simple map chart. - */ - public static abstract class SimpleMapChart extends CustomChart { - - /** - * Class constructor. - * - * @param chartId The id of the chart. - */ - public SimpleMapChart(String chartId) { - super(chartId); - } - - /** - * Gets the value of the chart. - * - * @return The value of the chart. - */ - public abstract Country getValue(); - - @Override - protected JSONObject getChartData() { - JSONObject data = new JSONObject(); - Country value = getValue(); - - if (value == null) { - // Null = skip the chart - return null; - } - data.put("value", value.getCountryIsoTag()); - return data; - } - - } - - /** - * Represents a custom advanced map chart. - */ - public static abstract class AdvancedMapChart extends CustomChart { - - /** - * Class constructor. - * - * @param chartId The id of the chart. - */ - public AdvancedMapChart(String chartId) { - super(chartId); - } - - /** - * Gets the value of the chart. - * - * @param valueMap Just an empty map. The only reason it exists is to make your - * life easier. You don't have to create a map yourself! - * @return The value of the chart. - */ - public abstract HashMap getValues(HashMap valueMap); - - @Override - protected JSONObject getChartData() { - JSONObject data = new JSONObject(); - JSONObject values = new JSONObject(); - HashMap map = getValues(new HashMap()); - if (map == null || map.isEmpty()) { - // Null = skip the chart - return null; - } - boolean allSkipped = true; - for (Map.Entry entry : map.entrySet()) { - if (entry.getValue() == 0) { - continue; // Skip this invalid - } - allSkipped = false; - values.put(entry.getKey().getCountryIsoTag(), entry.getValue()); - } - if (allSkipped) { - // Null = skip the chart - return null; - } - data.put("values", values); - return data; - } - - } - - /** - * A enum which is used for custom maps. - */ - public enum Country { - - /** - * bStats will use the country of the server. - */ - AUTO_DETECT("AUTO", "Auto Detected"), - - ANDORRA("AD", "Andorra"), UNITED_ARAB_EMIRATES("AE", "United Arab Emirates"), AFGHANISTAN("AF", "Afghanistan"), - ANTIGUA_AND_BARBUDA("AG", "Antigua and Barbuda"), ANGUILLA("AI", "Anguilla"), ALBANIA("AL", "Albania"), - ARMENIA("AM", "Armenia"), NETHERLANDS_ANTILLES("AN", "Netherlands Antilles"), ANGOLA("AO", "Angola"), - ANTARCTICA("AQ", "Antarctica"), ARGENTINA("AR", "Argentina"), AMERICAN_SAMOA("AS", "American Samoa"), - AUSTRIA("AT", "Austria"), AUSTRALIA("AU", "Australia"), ARUBA("AW", "Aruba"), - ÅLAND_ISLANDS("AX", "Åland Islands"), AZERBAIJAN("AZ", "Azerbaijan"), - BOSNIA_AND_HERZEGOVINA("BA", "Bosnia and Herzegovina"), BARBADOS("BB", "Barbados"), - BANGLADESH("BD", "Bangladesh"), BELGIUM("BE", "Belgium"), BURKINA_FASO("BF", "Burkina Faso"), - BULGARIA("BG", "Bulgaria"), BAHRAIN("BH", "Bahrain"), BURUNDI("BI", "Burundi"), BENIN("BJ", "Benin"), - SAINT_BARTHÉLEMY("BL", "Saint Barthélemy"), BERMUDA("BM", "Bermuda"), BRUNEI("BN", "Brunei"), - BOLIVIA("BO", "Bolivia"), BONAIRE_SINT_EUSTATIUS_AND_SABA("BQ", "Bonaire, Sint Eustatius and Saba"), - BRAZIL("BR", "Brazil"), BAHAMAS("BS", "Bahamas"), BHUTAN("BT", "Bhutan"), BOUVET_ISLAND("BV", "Bouvet Island"), - BOTSWANA("BW", "Botswana"), BELARUS("BY", "Belarus"), BELIZE("BZ", "Belize"), CANADA("CA", "Canada"), - COCOS_ISLANDS("CC", "Cocos Islands"), - THE_DEMOCRATIC_REPUBLIC_OF_CONGO("CD", "The Democratic Republic Of Congo"), - CENTRAL_AFRICAN_REPUBLIC("CF", "Central African Republic"), CONGO("CG", "Congo"), - SWITZERLAND("CH", "Switzerland"), CÔTE_D_IVOIRE("CI", "Côte d'Ivoire"), COOK_ISLANDS("CK", "Cook Islands"), - CHILE("CL", "Chile"), CAMEROON("CM", "Cameroon"), CHINA("CN", "China"), COLOMBIA("CO", "Colombia"), - COSTA_RICA("CR", "Costa Rica"), CUBA("CU", "Cuba"), CAPE_VERDE("CV", "Cape Verde"), CURAÇAO("CW", "Curaçao"), - CHRISTMAS_ISLAND("CX", "Christmas Island"), CYPRUS("CY", "Cyprus"), CZECH_REPUBLIC("CZ", "Czech Republic"), - GERMANY("DE", "Germany"), DJIBOUTI("DJ", "Djibouti"), DENMARK("DK", "Denmark"), DOMINICA("DM", "Dominica"), - DOMINICAN_REPUBLIC("DO", "Dominican Republic"), ALGERIA("DZ", "Algeria"), ECUADOR("EC", "Ecuador"), - ESTONIA("EE", "Estonia"), EGYPT("EG", "Egypt"), WESTERN_SAHARA("EH", "Western Sahara"), - ERITREA("ER", "Eritrea"), SPAIN("ES", "Spain"), ETHIOPIA("ET", "Ethiopia"), FINLAND("FI", "Finland"), - FIJI("FJ", "Fiji"), FALKLAND_ISLANDS("FK", "Falkland Islands"), MICRONESIA("FM", "Micronesia"), - FAROE_ISLANDS("FO", "Faroe Islands"), FRANCE("FR", "France"), GABON("GA", "Gabon"), - UNITED_KINGDOM("GB", "United Kingdom"), GRENADA("GD", "Grenada"), GEORGIA("GE", "Georgia"), - FRENCH_GUIANA("GF", "French Guiana"), GUERNSEY("GG", "Guernsey"), GHANA("GH", "Ghana"), - GIBRALTAR("GI", "Gibraltar"), GREENLAND("GL", "Greenland"), GAMBIA("GM", "Gambia"), GUINEA("GN", "Guinea"), - GUADELOUPE("GP", "Guadeloupe"), EQUATORIAL_GUINEA("GQ", "Equatorial Guinea"), GREECE("GR", "Greece"), - SOUTH_GEORGIA_AND_THE_SOUTH_SANDWICH_ISLANDS("GS", "South Georgia And The South Sandwich Islands"), - GUATEMALA("GT", "Guatemala"), GUAM("GU", "Guam"), GUINEA_BISSAU("GW", "Guinea-Bissau"), GUYANA("GY", "Guyana"), - HONG_KONG("HK", "Hong Kong"), HEARD_ISLAND_AND_MCDONALD_ISLANDS("HM", "Heard Island And McDonald Islands"), - HONDURAS("HN", "Honduras"), CROATIA("HR", "Croatia"), HAITI("HT", "Haiti"), HUNGARY("HU", "Hungary"), - INDONESIA("ID", "Indonesia"), IRELAND("IE", "Ireland"), ISRAEL("IL", "Israel"), - ISLE_OF_MAN("IM", "Isle Of Man"), INDIA("IN", "India"), - BRITISH_INDIAN_OCEAN_TERRITORY("IO", "British Indian Ocean Territory"), IRAQ("IQ", "Iraq"), IRAN("IR", "Iran"), - ICELAND("IS", "Iceland"), ITALY("IT", "Italy"), JERSEY("JE", "Jersey"), JAMAICA("JM", "Jamaica"), - JORDAN("JO", "Jordan"), JAPAN("JP", "Japan"), KENYA("KE", "Kenya"), KYRGYZSTAN("KG", "Kyrgyzstan"), - CAMBODIA("KH", "Cambodia"), KIRIBATI("KI", "Kiribati"), COMOROS("KM", "Comoros"), - SAINT_KITTS_AND_NEVIS("KN", "Saint Kitts And Nevis"), NORTH_KOREA("KP", "North Korea"), - SOUTH_KOREA("KR", "South Korea"), KUWAIT("KW", "Kuwait"), CAYMAN_ISLANDS("KY", "Cayman Islands"), - KAZAKHSTAN("KZ", "Kazakhstan"), LAOS("LA", "Laos"), LEBANON("LB", "Lebanon"), SAINT_LUCIA("LC", "Saint Lucia"), - LIECHTENSTEIN("LI", "Liechtenstein"), SRI_LANKA("LK", "Sri Lanka"), LIBERIA("LR", "Liberia"), - LESOTHO("LS", "Lesotho"), LITHUANIA("LT", "Lithuania"), LUXEMBOURG("LU", "Luxembourg"), LATVIA("LV", "Latvia"), - LIBYA("LY", "Libya"), MOROCCO("MA", "Morocco"), MONACO("MC", "Monaco"), MOLDOVA("MD", "Moldova"), - MONTENEGRO("ME", "Montenegro"), SAINT_MARTIN("MF", "Saint Martin"), MADAGASCAR("MG", "Madagascar"), - MARSHALL_ISLANDS("MH", "Marshall Islands"), MACEDONIA("MK", "Macedonia"), MALI("ML", "Mali"), - MYANMAR("MM", "Myanmar"), MONGOLIA("MN", "Mongolia"), MACAO("MO", "Macao"), - NORTHERN_MARIANA_ISLANDS("MP", "Northern Mariana Islands"), MARTINIQUE("MQ", "Martinique"), - MAURITANIA("MR", "Mauritania"), MONTSERRAT("MS", "Montserrat"), MALTA("MT", "Malta"), - MAURITIUS("MU", "Mauritius"), MALDIVES("MV", "Maldives"), MALAWI("MW", "Malawi"), MEXICO("MX", "Mexico"), - MALAYSIA("MY", "Malaysia"), MOZAMBIQUE("MZ", "Mozambique"), NAMIBIA("NA", "Namibia"), - NEW_CALEDONIA("NC", "New Caledonia"), NIGER("NE", "Niger"), NORFOLK_ISLAND("NF", "Norfolk Island"), - NIGERIA("NG", "Nigeria"), NICARAGUA("NI", "Nicaragua"), NETHERLANDS("NL", "Netherlands"), - NORWAY("NO", "Norway"), NEPAL("NP", "Nepal"), NAURU("NR", "Nauru"), NIUE("NU", "Niue"), - NEW_ZEALAND("NZ", "New Zealand"), OMAN("OM", "Oman"), PANAMA("PA", "Panama"), PERU("PE", "Peru"), - FRENCH_POLYNESIA("PF", "French Polynesia"), PAPUA_NEW_GUINEA("PG", "Papua New Guinea"), - PHILIPPINES("PH", "Philippines"), PAKISTAN("PK", "Pakistan"), POLAND("PL", "Poland"), - SAINT_PIERRE_AND_MIQUELON("PM", "Saint Pierre And Miquelon"), PITCAIRN("PN", "Pitcairn"), - PUERTO_RICO("PR", "Puerto Rico"), PALESTINE("PS", "Palestine"), PORTUGAL("PT", "Portugal"), - PALAU("PW", "Palau"), PARAGUAY("PY", "Paraguay"), QATAR("QA", "Qatar"), REUNION("RE", "Reunion"), - ROMANIA("RO", "Romania"), SERBIA("RS", "Serbia"), RUSSIA("RU", "Russia"), RWANDA("RW", "Rwanda"), - SAUDI_ARABIA("SA", "Saudi Arabia"), SOLOMON_ISLANDS("SB", "Solomon Islands"), SEYCHELLES("SC", "Seychelles"), - SUDAN("SD", "Sudan"), SWEDEN("SE", "Sweden"), SINGAPORE("SG", "Singapore"), SAINT_HELENA("SH", "Saint Helena"), - SLOVENIA("SI", "Slovenia"), SVALBARD_AND_JAN_MAYEN("SJ", "Svalbard And Jan Mayen"), SLOVAKIA("SK", "Slovakia"), - SIERRA_LEONE("SL", "Sierra Leone"), SAN_MARINO("SM", "San Marino"), SENEGAL("SN", "Senegal"), - SOMALIA("SO", "Somalia"), SURINAME("SR", "Suriname"), SOUTH_SUDAN("SS", "South Sudan"), - SAO_TOME_AND_PRINCIPE("ST", "Sao Tome And Principe"), EL_SALVADOR("SV", "El Salvador"), - SINT_MAARTEN_DUTCH_PART("SX", "Sint Maarten (Dutch part)"), SYRIA("SY", "Syria"), SWAZILAND("SZ", "Swaziland"), - TURKS_AND_CAICOS_ISLANDS("TC", "Turks And Caicos Islands"), CHAD("TD", "Chad"), - FRENCH_SOUTHERN_TERRITORIES("TF", "French Southern Territories"), TOGO("TG", "Togo"), - THAILAND("TH", "Thailand"), TAJIKISTAN("TJ", "Tajikistan"), TOKELAU("TK", "Tokelau"), - TIMOR_LESTE("TL", "Timor-Leste"), TURKMENISTAN("TM", "Turkmenistan"), TUNISIA("TN", "Tunisia"), - TONGA("TO", "Tonga"), TURKEY("TR", "Turkey"), TRINIDAD_AND_TOBAGO("TT", "Trinidad and Tobago"), - TUVALU("TV", "Tuvalu"), TAIWAN("TW", "Taiwan"), TANZANIA("TZ", "Tanzania"), UKRAINE("UA", "Ukraine"), - UGANDA("UG", "Uganda"), UNITED_STATES_MINOR_OUTLYING_ISLANDS("UM", "United States Minor Outlying Islands"), - UNITED_STATES("US", "United States"), URUGUAY("UY", "Uruguay"), UZBEKISTAN("UZ", "Uzbekistan"), - VATICAN("VA", "Vatican"), SAINT_VINCENT_AND_THE_GRENADINES("VC", "Saint Vincent And The Grenadines"), - VENEZUELA("VE", "Venezuela"), BRITISH_VIRGIN_ISLANDS("VG", "British Virgin Islands"), - U_S__VIRGIN_ISLANDS("VI", "U.S. Virgin Islands"), VIETNAM("VN", "Vietnam"), VANUATU("VU", "Vanuatu"), - WALLIS_AND_FUTUNA("WF", "Wallis And Futuna"), SAMOA("WS", "Samoa"), YEMEN("YE", "Yemen"), - MAYOTTE("YT", "Mayotte"), SOUTH_AFRICA("ZA", "South Africa"), ZAMBIA("ZM", "Zambia"), - ZIMBABWE("ZW", "Zimbabwe"); - - private String isoTag; - private String name; - - Country(String isoTag, String name) { - this.isoTag = isoTag; - this.name = name; - } - - /** - * Gets the name of the country. - * - * @return The name of the country. - */ - public String getCountryName() { - return name; - } - - /** - * Gets the iso tag of the country. - * - * @return The iso tag of the country. - */ - public String getCountryIsoTag() { - return isoTag; - } - - /** - * Gets a country by it's iso tag. - * - * @param isoTag The iso tag of the county. - * @return The country with the given iso tag or null if unknown. - */ - public static Country byIsoTag(String isoTag) { - for (Country country : Country.values()) { - if (country.getCountryIsoTag().equals(isoTag)) { - return country; - } - } - return null; - } - - /** - * Gets a country by a locale. - * - * @param locale The locale. - * @return The country from the giben locale or null if unknown - * country or if the locale does not contain a country. - */ - public static Country byLocale(Locale locale) { - return byIsoTag(locale.getCountry()); - } - - } } \ No newline at end of file diff --git a/src/main/java/com/rammelkast/anticheatreloaded/util/Permission.java b/src/main/java/com/rammelkast/anticheatreloaded/util/Permission.java index ef37059..e356518 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/util/Permission.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/util/Permission.java @@ -26,7 +26,7 @@ public enum Permission { CHECK_ZOMBE_FLY, CHECK_ZOMBE_NOCLIP, CHECK_ZOMBE_CHEAT, CHECK_FLIGHT, CHECK_ELYTRA, CHECK_WATERWALK, CHECK_NOSWING, CHECK_FASTBREAK, CHECK_FASTPLACE, CHECK_CHATSPAM, CHECK_COMMANDSPAM, CHECK_SPRINT, CHECK_SNEAK, CHECK_SPEED, CHECK_VCLIP, CHECK_SPIDER, CHECK_NOFALL, CHECK_FASTBOW, CHECK_FASTEAT, CHECK_FASTHEAL, CHECK_FORCEFIELD, CHECK_LONGREACH, - CHECK_FASTPROJECTILE, CHECK_ITEMSPAM, CHECK_VISUAL, CHECK_FASTINVENTORY, CHECK_AUTOTOOL, CHECK_KILLAURA, CHECK_BLINK, CHECK_VELOCITY, CHECK_CRITICALS, CHECK_UNICODE, + CHECK_FASTPROJECTILE, CHECK_ITEMSPAM, CHECK_VISUAL, CHECK_FASTINVENTORY, CHECK_AUTOTOOL, CHECK_BLINK, CHECK_VELOCITY, CHECK_CRITICALS, CHECK_UNICODE, /* System Nodes */ SYSTEM_LOG, SYSTEM_RESET, SYSTEM_SPY, SYSTEM_HELP, SYSTEM_UPDATE, SYSTEM_REPORT, SYSTEM_ALERT, SYSTEM_NOTICE, diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index ceff7b2..d3a85fb 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -130,9 +130,6 @@ permissions: anticheat.check.autotool: description: Allow players to use autotool to switch tools quickly default: false - anticheat.check.killaura: - description: Allow players to use killaura - default: false anticheat.check.blink: description: Allow players to send lots of movement packets default: false @@ -175,3 +172,7 @@ permissions: anticheat.check.fastinventory: true anticheat.check.autotool: true anticheat.check.fastanimation: true + anticheat.check.blink: true + anticheat.check.velocity: true + anticheat.check.criticals: true + anticheat.check.unicode: true \ No newline at end of file