From add3fe5eaeb7115134c7f23e5b2ecc2a6c6bbf32 Mon Sep 17 00:00:00 2001 From: Rammelkast Date: Fri, 3 Jul 2020 17:00:32 +0200 Subject: [PATCH] Update to 1.16, migrate config and more movement changes --- pom.xml | 4 +- .../anticheatreloaded/check/Backend.java | 44 +- .../anticheatreloaded/check/CheckType.java | 87 ++-- .../check/combat/KillAuraCheck.java | 3 + .../check/movement/AimbotCheck.java | 4 +- .../check/movement/FlightCheck.java | 83 +++- .../check/movement/GlideCheck.java | 7 +- .../check/movement/NoSlowdownCheck.java | 23 ++ .../check/movement/SpeedCheck.java | 171 ++++---- .../check/movement/WaterWalkCheck.java | 11 +- .../check/movement/YAxisCheck.java | 131 ------ .../command/executors/CommandReport.java | 2 +- .../config/Configuration.java | 38 +- .../config/holders/yaml/YamlChecksHolder.java | 85 ++++ .../config/providers/Checks.java | 41 ++ .../config/providers/Magic.java | 76 ---- .../event/EntityListener.java | 13 +- .../event/EventListener.java | 8 +- .../anticheatreloaded/manage/UserManager.java | 4 +- .../util/MovementManager.java | 49 ++- .../anticheatreloaded/util/Utilities.java | 103 ++--- .../anticheatreloaded/util/VersionUtil.java | 34 +- .../anticheatreloaded/util/XMaterial.java | 387 ++++++++++-------- src/main/resources/checks.yml | 192 +++++++++ src/main/resources/enterprise.yml | 2 +- src/main/resources/groups.yml | 6 +- src/main/resources/magic.yml | 70 +--- 27 files changed, 986 insertions(+), 692 deletions(-) create mode 100644 src/main/java/com/rammelkast/anticheatreloaded/check/movement/NoSlowdownCheck.java delete mode 100644 src/main/java/com/rammelkast/anticheatreloaded/check/movement/YAxisCheck.java create mode 100644 src/main/java/com/rammelkast/anticheatreloaded/config/holders/yaml/YamlChecksHolder.java create mode 100644 src/main/java/com/rammelkast/anticheatreloaded/config/providers/Checks.java create mode 100644 src/main/resources/checks.yml diff --git a/pom.xml b/pom.xml index ff8890b..d4af67e 100644 --- a/pom.xml +++ b/pom.xml @@ -69,7 +69,7 @@ com.comphenix.protocol ProtocolLib - 4.5.1-SNAPSHOT + 4.6.0-SNAPSHOT org.spigotmc @@ -80,7 +80,7 @@ org.spigotmc spigot - 1.15.2-R0.1-SNAPSHOT + 1.16.1-R0.1-SNAPSHOT provided diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java b/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java index 2e5f03b..d542fcb 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java @@ -44,9 +44,7 @@ import com.rammelkast.anticheatreloaded.check.movement.AimbotCheck; import com.rammelkast.anticheatreloaded.check.movement.ElytraCheck; import com.rammelkast.anticheatreloaded.check.movement.FlightCheck; import com.rammelkast.anticheatreloaded.check.movement.GlideCheck; -import com.rammelkast.anticheatreloaded.check.movement.SpeedCheck; import com.rammelkast.anticheatreloaded.check.movement.WaterWalkCheck; -import com.rammelkast.anticheatreloaded.check.movement.YAxisCheck; import com.rammelkast.anticheatreloaded.check.packet.MorePacketsCheck; import com.rammelkast.anticheatreloaded.config.Configuration; import com.rammelkast.anticheatreloaded.config.providers.Lang; @@ -59,6 +57,7 @@ import com.rammelkast.anticheatreloaded.util.VersionUtil; public class Backend { public Map velocitized = new HashMap(); + private Map levitatingEnd = new HashMap(); private List isAscending = new ArrayList(); private Map chatLevel = new HashMap(); private Map commandLevel = new HashMap(); @@ -80,7 +79,7 @@ public class Backend { private Map instantBreakExempt = new HashMap(); private Map sprinted = new HashMap(); private Map brokenBlock = new HashMap(); - private Map placedBlock = new HashMap(); + public Map placedBlock = new HashMap(); private Map blockTime = new HashMap(); private Map blocksDropped = new HashMap(); private Map lastInventoryTime = new HashMap(); @@ -158,6 +157,7 @@ public class Backend { lastFallPacket.remove(uuid); fastSneakViolations.remove(uuid); lastSneak.remove(uuid); + levitatingEnd.remove(uuid); AimbotCheck.LAST_DELTA_YAW.remove(uuid); VelocityCheck.VIOLATIONS.remove(uuid); MorePacketsCheck.LAST_PACKET_TIME.remove(uuid); @@ -169,10 +169,6 @@ public class Backend { ElytraCheck.JUMP_Y_VALUE.remove(uuid); KillAuraCheck.ANGLE_FLAGS.remove(uuid); FlightCheck.MOVING_EXEMPT.remove(uuid); - YAxisCheck.Y_AXIS_VIOLATIONS.remove(uuid); - YAxisCheck.LAST_Y_AXIS_VIOLATION.remove(uuid); - YAxisCheck.LAST_Y_COORD_CACHE.remove(uuid); - YAxisCheck.LAST_Y_TIME.remove(uuid); WaterWalkCheck.IS_IN_WATER.remove(uuid); WaterWalkCheck.IS_IN_WATER_CACHE.remove(uuid); WaterWalkCheck.WATER_ASCENSION_VIOLATIONS.remove(uuid); @@ -472,7 +468,7 @@ public class Backend { if (lastBlockPlaced.get(uuid) > 0 && math < magic.FASTPLACE_MAXVIOLATIONTIME()) { lastBlockPlaced.put(uuid, time); return new CheckResult(CheckResult.Result.FAILED, "placed blocks too fast " - + fastBreakViolation.get(uuid) + " times in a row (max=" + violations + ")"); + + fastPlaceViolation.get(uuid) + " times in a row (max=" + violations + ")"); } else if (lastBlockPlaced.get(uuid) > 0 && math > magic.FASTPLACE_MAXVIOLATIONTIME()) { fastPlaceViolation.put(uuid, 0); } @@ -548,7 +544,9 @@ public class Backend { if (Character.UnicodeBlock.of(ch) != Character.UnicodeBlock.BASIC_LATIN && Character.UnicodeBlock.of(ch) != Character.UnicodeBlock.LATIN_1_SUPPLEMENT && Character.UnicodeBlock.of(ch) != Character.UnicodeBlock.LATIN_EXTENDED_A - && Character.UnicodeBlock.of(ch) != Character.UnicodeBlock.GENERAL_PUNCTUATION) { + && Character.UnicodeBlock.of(ch) != Character.UnicodeBlock.GENERAL_PUNCTUATION + && Character.UnicodeBlock.of(ch) != Character.UnicodeBlock.CYRILLIC + && Character.UnicodeBlock.of(ch) != Character.UnicodeBlock.CYRILLIC_EXTENDED_A) { return new CheckResult(CheckResult.Result.FAILED, "Unicode chat is not allowed."); } } @@ -678,16 +676,6 @@ public class Backend { sprinted.put(player.getUniqueId(), System.currentTimeMillis()); } - public boolean isHoveringOverWaterAfterViolation(Player player) { - 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; - } - } - return false; - } - public void logBlockBreak(final Player player) { brokenBlock.put(player.getUniqueId(), System.currentTimeMillis()); } @@ -700,11 +688,21 @@ public class Backend { velocitized.put(player.getUniqueId(), System.currentTimeMillis()); } + public void logLevitating(final Player player, final int duration) { + levitatingEnd.put(player.getUniqueId(), System.currentTimeMillis() + (duration * 1000L)); + } + public boolean justVelocity(Player player) { return (velocitized.containsKey(player.getUniqueId()) ? (System.currentTimeMillis() - velocitized.get(player.getUniqueId())) < magic.VELOCITY_CHECKTIME() : false); } + + public boolean justLevitated(Player player) { + return (levitatingEnd.containsKey(player.getUniqueId()) + ? (System.currentTimeMillis() - levitatingEnd.get(player.getUniqueId())) < magic.VELOCITY_CHECKTIME() + : false); + } public boolean extendVelocityTime(final Player player) { if (velocitytrack.containsKey(player.getUniqueId())) { @@ -765,15 +763,9 @@ public class Backend { } public void logTeleport(final Player player) { - // TODO check this - //FlightCheck.MOVING_EXEMPT.put(player.getUniqueId(), System.currentTimeMillis() + magic.TELEPORT_TIME()); - + manager.getUserManager().getUser(player.getUniqueId()).getMovementManager().lastTeleport = System.currentTimeMillis(); /* Data for fly/speed should be reset */ nofallViolation.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_MOTION_Y.remove(player.getUniqueId()); GlideCheck.VIOLATIONS.remove(player.getUniqueId()); diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/CheckType.java b/src/main/java/com/rammelkast/anticheatreloaded/check/CheckType.java index bbb5a6d..be6f748 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/CheckType.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/CheckType.java @@ -36,47 +36,50 @@ import java.util.UUID; */ public enum CheckType { - FLIGHT(Permission.CHECK_FLIGHT), - ELYTRAFLY(Permission.CHECK_FLIGHT), - WATER_WALK(Permission.CHECK_WATERWALK), - NO_SWING(Permission.CHECK_NOSWING), - FAST_BREAK(Permission.CHECK_FASTBREAK), - FAST_PLACE(Permission.CHECK_FASTPLACE), - CHAT_SPAM(Permission.CHECK_CHATSPAM), - COMMAND_SPAM(Permission.CHECK_COMMANDSPAM), - SPRINT(Permission.CHECK_SPRINT), - SNEAK(Permission.CHECK_SNEAK), - SPEED(Permission.CHECK_SPEED), - VCLIP(Permission.CHECK_VCLIP), - SPIDER(Permission.CHECK_SPIDER), - NOFALL(Permission.CHECK_NOFALL), - FAST_BOW(Permission.CHECK_FASTBOW), - FAST_EAT(Permission.CHECK_FASTEAT), - FAST_HEAL(Permission.CHECK_FASTHEAL), - KILLAURA(Permission.CHECK_KILLAURA), - FAST_PROJECTILE(Permission.CHECK_FASTPROJECTILE), - ITEM_SPAM(Permission.CHECK_ITEMSPAM), - FAST_INVENTORY(Permission.CHECK_FASTINVENTORY), - AUTOTOOL(Permission.CHECK_AUTOTOOL), - MOREPACKETS(Permission.CHECK_MOREPACKETS), - BADPACKETS(Permission.CHECK_BADPACKETS), - VELOCITY(Permission.CHECK_VELOCITY), - CRITICALS(Permission.CHECK_CRITICALS), - CHAT_UNICODE(Permission.CHECK_UNICODE), - ILLEGAL_INTERACT(Permission.CHECK_ILLEGALINTERACT), - FASTLADDER(Permission.CHECK_FASTLADDER), - AIMBOT(Permission.CHECK_AIMBOT); + FLIGHT(Permission.CHECK_FLIGHT, "Flight"), + ELYTRAFLY(Permission.CHECK_FLIGHT, "ElytraFly"), + WATER_WALK(Permission.CHECK_WATERWALK, "WaterWalk"), + NO_SWING(Permission.CHECK_NOSWING, "NoSwing"), + FAST_BREAK(Permission.CHECK_FASTBREAK, "FastBreak"), + FAST_PLACE(Permission.CHECK_FASTPLACE, "FastPlace"), + CHAT_SPAM(Permission.CHECK_CHATSPAM, "ChatSpam"), + COMMAND_SPAM(Permission.CHECK_COMMANDSPAM, "CommandSpam"), + SPRINT(Permission.CHECK_SPRINT, "Sprint"), + SNEAK(Permission.CHECK_SNEAK, "Sneak"), + SPEED(Permission.CHECK_SPEED, "Speed"), + VCLIP(Permission.CHECK_VCLIP, "vClip"), + SPIDER(Permission.CHECK_SPIDER, "Spider"), + NOFALL(Permission.CHECK_NOFALL, "NoFall"), + FAST_BOW(Permission.CHECK_FASTBOW, "FastBow"), + FAST_EAT(Permission.CHECK_FASTEAT, "FastEat"), + FAST_HEAL(Permission.CHECK_FASTHEAL, "FastHeal"), + KILLAURA(Permission.CHECK_KILLAURA, "KillAura"), + FAST_PROJECTILE(Permission.CHECK_FASTPROJECTILE, "FastProjectile"), + ITEM_SPAM(Permission.CHECK_ITEMSPAM, "ItemSpam"), + FAST_INVENTORY(Permission.CHECK_FASTINVENTORY, "FastInventory"), + AUTOTOOL(Permission.CHECK_AUTOTOOL, "AutoTool"), + MOREPACKETS(Permission.CHECK_MOREPACKETS, "MorePackets"), + BADPACKETS(Permission.CHECK_BADPACKETS, "BadPackets"), + VELOCITY(Permission.CHECK_VELOCITY, "Velocity"), + CRITICALS(Permission.CHECK_CRITICALS, "Criticals"), + CHAT_UNICODE(Permission.CHECK_UNICODE, "ChatUnicode"), + ILLEGAL_INTERACT(Permission.CHECK_ILLEGALINTERACT, "IllegalInteract"), + FASTLADDER(Permission.CHECK_FASTLADDER, "FastLadder"), + AIMBOT(Permission.CHECK_AIMBOT, "Aimbot"); private final Permission permission; + private final String displayName; private final Map level = new HashMap(); /** * Initialize a CheckType * - * @param perm Permission that applies to this check + * @param permission Permission that applies to this check + * @peram displayName The chat display name */ - private CheckType(Permission perm) { - this.permission = perm; + private CheckType(Permission permission, String displayName) { + this.permission = permission; + this.displayName = displayName; } /** @@ -122,23 +125,9 @@ public enum CheckType { /** * Get the reference name of a check * - * @param type Type of check * @return reference name */ - public static String getName(CheckType type) { - if (type.name().contains("_")) { - String[] split = type.name().toLowerCase().split("_"); - String name = ""; - for (String part : split) { - char[] chars = part.toCharArray(); - chars[0] = Character.toUpperCase(chars[0]); - name += new String(chars); - } - return name; - } else { - char[] chars = type.name().toLowerCase().toCharArray(); - chars[0] = Character.toUpperCase(chars[0]); - return new String(chars); - } + public String getName() { + return this.displayName; } } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java index 684caac..051932e 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/combat/KillAuraCheck.java @@ -27,10 +27,12 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.potion.PotionEffectType; import org.bukkit.util.Vector; import com.rammelkast.anticheatreloaded.AntiCheatReloaded; import com.rammelkast.anticheatreloaded.check.CheckResult; +import com.rammelkast.anticheatreloaded.util.MovementManager; import com.rammelkast.anticheatreloaded.util.User; public class KillAuraCheck { @@ -104,4 +106,5 @@ public class KillAuraCheck { clonedFrom.setDirection(targetVector.subtract(startVector)); return clonedFrom.getYaw(); } + } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/AimbotCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/AimbotCheck.java index f4dd15f..ba9ffd9 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/AimbotCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/AimbotCheck.java @@ -40,6 +40,7 @@ public class AimbotCheck { if (backend.isMovingExempt(player)) { return PASS; } + UUID uuid = player.getUniqueId(); float dYaw = Math.abs(event.getTo().getYaw() - event.getFrom().getYaw()); float dPitch = Math.abs(event.getTo().getPitch() - event.getFrom().getPitch()); @@ -56,9 +57,8 @@ public class AimbotCheck { LAST_DELTA_YAW.put(uuid, dYaw); float absoluteYawDifference = Math.abs(dYaw - lastDeltaYaw); - if (absoluteYawDifference < 1E-8 && dYaw > 30 && dYaw < 355) { + if (absoluteYawDifference < 1E-8 && dYaw > 30 && dYaw < 355) return new CheckResult(CheckResult.Result.FAILED, "repeated yaw difference (dYaw=" + dYaw + ")"); - } return PASS; } 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 716fa3c..64237ea 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FlightCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/FlightCheck.java @@ -22,12 +22,18 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; +import org.bukkit.block.BlockFace; import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffectType; import com.rammelkast.anticheatreloaded.AntiCheatReloaded; import com.rammelkast.anticheatreloaded.check.CheckResult; +import com.rammelkast.anticheatreloaded.check.CheckType; +import com.rammelkast.anticheatreloaded.config.providers.Checks; import com.rammelkast.anticheatreloaded.util.Distance; import com.rammelkast.anticheatreloaded.util.MovementManager; +import com.rammelkast.anticheatreloaded.util.User; +import com.rammelkast.anticheatreloaded.util.Utilities; import com.rammelkast.anticheatreloaded.util.VersionUtil; /** @@ -37,7 +43,7 @@ public class FlightCheck { public static final Map MOVING_EXEMPT = new HashMap(); private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED); - + public static CheckResult runCheck(Player player, Distance distance) { if (distance.getYDifference() >= AntiCheatReloaded.getManager().getBackend().getMagic().TELEPORT_MIN() || VersionUtil.isFlying(player)) { @@ -46,8 +52,79 @@ public class FlightCheck { return PASS; } - MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId()) - .getMovementManager(); + User user = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId()); + MovementManager movementManager = user.getMovementManager(); + Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks(); + + if (Utilities.isNearWater(player) || movementManager.halfMovement + || Utilities.isClimbableBlock(distance.getFrom().getBlock()) + || Utilities.isClimbableBlock(distance.getFrom().getBlock().getRelative(BlockFace.DOWN)) + || Utilities.isClimbableBlock(distance.getFrom().getBlock().getRelative(BlockFace.UP))) + return PASS; + + int minAirTicks = 13; + if (player.hasPotionEffect(PotionEffectType.JUMP) ) { + minAirTicks += player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() * 3; + } + + if (movementManager.halfMovementHistoryCounter > 25) + minAirTicks += 5; + + // Start AirFlight + if (checksConfig.isSubcheckEnabled(CheckType.FLIGHT, "airFlight") && movementManager.airTicks > minAirTicks) { + // Config default base is 1200ms + // Ping clamped to max. 1000 to prevent spoofing for an advantage + int blockPlaceAccountingTime = (int) (checksConfig.getInteger(CheckType.FLIGHT, "airFlight", "accountForBlockPlacement") + (0.25 * (user.getPing() > 1000 ? 1000 : user.getPing()))); + // Config default account is 250ms + if (AntiCheatReloaded.getPlugin().getTPS() < 18.0) + blockPlaceAccountingTime += checksConfig.getInteger(CheckType.FLIGHT, "airFlight", "accountForTpsDrops"); + long lastPlacedBlock = AntiCheatReloaded.getManager().getBackend().placedBlock + .containsKey(player.getUniqueId()) + ? AntiCheatReloaded.getManager().getBackend().placedBlock.get(player.getUniqueId()) + : (blockPlaceAccountingTime + 1); + double maxMotionY = System.currentTimeMillis() - lastPlacedBlock > blockPlaceAccountingTime ? 0 : 0.42; + if (movementManager.motionY > maxMotionY && movementManager.slimeInfluenceTicks <= 0) + return new CheckResult(CheckResult.Result.FAILED, + "tried to fly on the Y-axis (mY=" + movementManager.motionY + ", max=" + maxMotionY + ")"); + + if (Math.abs(movementManager.motionY - movementManager.lastMotionY) < 0.01 + && !Utilities.couldBeOnBoat(player) + && (System.currentTimeMillis() - movementManager.lastTeleport >= checksConfig.getInteger(CheckType.FLIGHT, "airFlight", "accountForTeleports")) + && !VersionUtil.isSlowFalling(player)) + return new CheckResult(CheckResult.Result.FAILED, "had too little Y dropoff (diff=" + + Math.abs(movementManager.motionY - movementManager.lastMotionY) + ")"); + } + // End AirFlight + + // Start AirClimb + // TODO two hardcoded values here shouldn't be there, temp against false positive + if (checksConfig.isSubcheckEnabled(CheckType.FLIGHT, "airClimb") && movementManager.lastMotionY > 0 + && movementManager.motionY > 0 && movementManager.airTicks == 2 + && Math.round(movementManager.lastMotionY * 1000) != 420 + && !(Math.round(movementManager.motionY * 1000) == 333 && Math.round(movementManager.lastMotionY * 1000) != 333) + && !AntiCheatReloaded.getManager().getBackend().justVelocity(player) + && !player.hasPotionEffect(PotionEffectType.JUMP) + && (System.currentTimeMillis() - movementManager.lastTeleport >= checksConfig.getInteger(CheckType.FLIGHT, "airClimb", "accountForTeleports"))) + return new CheckResult(CheckResult.Result.FAILED, + "tried to climb air (mY=" + movementManager.motionY + ")"); + + if (checksConfig.isSubcheckEnabled(CheckType.FLIGHT, "airClimb") && movementManager.motionY > 0.42 + && movementManager.airTicks > 2 && !AntiCheatReloaded.getManager().getBackend().justVelocity(player) + && !player.hasPotionEffect(PotionEffectType.JUMP) + && (System.currentTimeMillis() - movementManager.lastTeleport >= checksConfig.getInteger(CheckType.FLIGHT, "airClimb", "accountForTeleports"))) + return new CheckResult(CheckResult.Result.FAILED, + "tried to climb air (mY=" + movementManager.motionY + ", at=" + movementManager.airTicks + ")"); + // End AirClimb + + // Start GroundFlight + if (checksConfig.isSubcheckEnabled(CheckType.FLIGHT, "groundFlight") && movementManager.onGround + && Utilities.cantStandAt(distance.getTo().getBlock().getRelative(BlockFace.DOWN)) + && Utilities.cantStandAt(distance.getFrom().getBlock().getRelative(BlockFace.DOWN)) + && movementManager.groundTicks > 2) { + return new CheckResult(CheckResult.Result.FAILED, + "faked ground to fly (mY=" + movementManager.motionY + ", gt=" + movementManager.groundTicks + ")"); + } + // End GroundFlight return PASS; } 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 1e3b4da..6b2b86b 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/GlideCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/GlideCheck.java @@ -19,8 +19,6 @@ 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; @@ -32,6 +30,7 @@ import org.bukkit.entity.Player; import com.rammelkast.anticheatreloaded.AntiCheatReloaded; import com.rammelkast.anticheatreloaded.check.CheckResult; import com.rammelkast.anticheatreloaded.util.Distance; +import com.rammelkast.anticheatreloaded.util.Utilities; import com.rammelkast.anticheatreloaded.util.VersionUtil; public class GlideCheck { @@ -78,13 +77,11 @@ public class GlideCheck { .getGoodLocation(prev)); } return new CheckResult(CheckResult.Result.FAILED, - "type=glide, desc_amount=" + new BigDecimal(motionY).setScale(2, RoundingMode.HALF_UP) + ")"); + "had gliding behaviour (amt=" + Utilities.roundDouble(motionY, 5) + ")"); } else { VIOLATIONS.put(player.getUniqueId(), violations + 1); return PASS; } - } else { - // TODO redo this } LAST_MOTION_Y.put(player.getUniqueId(), distance.getYDifference()); LAST_FALL_DISTANCE.put(player.getUniqueId(), player.getFallDistance()); diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/NoSlowdownCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/NoSlowdownCheck.java new file mode 100644 index 0000000..0b8cb64 --- /dev/null +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/NoSlowdownCheck.java @@ -0,0 +1,23 @@ +/* + * 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.movement; + +public class NoSlowdownCheck { + +} 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 4bbbee5..f85814f 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/SpeedCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/SpeedCheck.java @@ -26,6 +26,8 @@ import org.bukkit.potion.PotionEffectType; import com.rammelkast.anticheatreloaded.AntiCheatReloaded; import com.rammelkast.anticheatreloaded.check.Backend; import com.rammelkast.anticheatreloaded.check.CheckResult; +import com.rammelkast.anticheatreloaded.check.CheckType; +import com.rammelkast.anticheatreloaded.config.providers.Checks; import com.rammelkast.anticheatreloaded.util.Distance; import com.rammelkast.anticheatreloaded.util.MovementManager; import com.rammelkast.anticheatreloaded.util.Utilities; @@ -33,18 +35,6 @@ import com.rammelkast.anticheatreloaded.util.VersionUtil; /** * @author Rammelkast - * - * Features: - * + AirSpeed A - * + AirAcceleration A - * + JumpBehaviour A - * + VerticalSpeed - * - * Planned: - * + GroundSpeed A - * + GroundAcceleration A - * + AirSpeed B - * + JumpBehaviour B */ public class SpeedCheck { @@ -56,27 +46,30 @@ public class SpeedCheck { public static CheckResult checkXZSpeed(Player player, double x, double z, Location movingTowards) { Backend backend = AntiCheatReloaded.getManager().getBackend(); - if (isSpeedExempt(player, backend) || player.getVehicle() != null) + if (isSpeedExempt(player, backend) || player.getVehicle() != null || Utilities.isInWater(player)) return PASS; MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId()) .getMovementManager(); - double distanceXZ = Math.sqrt(x * x + z * z); + Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks(); + double distanceXZ = movementManager.distanceXZ; boolean boxedIn = movementManager.topSolid && movementManager.bottomSolid; - // AirSpeed A - if (movementManager.airTicks > 1) { - double multiplier = 0.9808305131D; - double predict = 0.3597320645 * Math.pow(multiplier, movementManager.airTicks + 1); - double limit = 0.03075D; + // AirSpeed + if (checksConfig.isSubcheckEnabled(CheckType.SPEED, "airSpeed") && movementManager.airTicks > 1 && movementManager.elytraEffectTicks <= 0) { + double multiplier = 0.985D; + double predict = 0.36 * Math.pow(multiplier, movementManager.airTicks + 1); + double limit = checksConfig.getDouble(CheckType.SPEED, "airSpeed", "baseLimit"); // Default 0.03125 // Adjust for ice if (movementManager.iceInfluenceTicks > 0) { - double iceIncrement = 0.02 * Math.pow(1.0375, movementManager.iceInfluenceTicks); + double iceIncrement = 0.025 * Math.pow(1.038, movementManager.iceInfluenceTicks); // Clamp to max value if (iceIncrement > 0.18D) iceIncrement = 0.18D; if (boxedIn) iceIncrement += 0.5D; + if (!Utilities.couldBeOnIce(movingTowards)) + iceIncrement *= 2.5D; predict += iceIncrement; } // Adjust for slime @@ -89,85 +82,108 @@ public class SpeedCheck { } // Adjust for speed effects if (player.hasPotionEffect(PotionEffectType.SPEED)) - predict += player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() * 0.05D; + predict += (player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() + 1) * 0.05D; + // Adjust for jump boost effects + if (player.hasPotionEffect(PotionEffectType.JUMP)) + predict += (player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() + 1) * 0.05D; // Adjust for custom walking speed - predict += 1.4D * (Math.pow(1.1, ((player.getWalkSpeed() / 0.20) - 1)) - 1); + double walkSpeedMultiplier = checksConfig.getDouble(CheckType.SPEED, "airSpeed", "walkSpeedMultiplier"); // Default 1.4 + predict += walkSpeedMultiplier * (Math.pow(1.1, ((player.getWalkSpeed() / 0.20) - 1)) - 1); // Slabs sometimes allow for a slight boost after jump if (movementManager.halfMovementHistoryCounter > 0) predict *= 2.125D; if (Utilities.couldBeOnHalfblock(movingTowards) && movementManager.halfMovementHistoryCounter == 0) predict *= 1.25D; + // Boats sometimes give a false positive + if (Utilities.couldBeOnBoat(player, 0.5)) + predict *= 1.25D; + // Strafing in air when nearing terminal velocity gives false positives + // This fixes the issue but gives hackers some leniency which means we need another check for this + double deltaMotionY = movementManager.motionY - movementManager.lastMotionY; + if (deltaMotionY < 0 && deltaMotionY >= -0.06) + predict *= 1.5D; + // Players can move faster in air with slow falling + if (VersionUtil.isSlowFalling(player)) + predict *= 1.25D; + if (distanceXZ - predict > limit) { return new CheckResult(CheckResult.Result.FAILED, "moved too fast in air (speed=" + distanceXZ + ", limit=" + predict + ")"); } } - // AirAcceleration A + // AirAcceleration // As of right now, this falses sometimes, dont know why - if (movementManager.airTicks > 1 && movementManager.iceInfluenceTicks <= 0 && movementManager.slimeInfluenceTicks <= 0) { + if (checksConfig.isSubcheckEnabled(CheckType.SPEED, "airAcceleration") && movementManager.airTicks > 1 + && movementManager.iceInfluenceTicks <= 0 && movementManager.slimeInfluenceTicks <= 0 + && movementManager.elytraEffectTicks <= 0) { double initialAcceleration = movementManager.acceleration; - double limit = 0.3725D; + double limit = checksConfig.getDouble(CheckType.SPEED, "airAcceleration", "baseLimit"); // Default 0.3725 // Adjust for speed effects - if (player.hasPotionEffect(PotionEffectType.SPEED) ) - limit += player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() * 0.0225D; + if (player.hasPotionEffect(PotionEffectType.SPEED)) + limit += (player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() + 1) * 0.0225D; // Adjust for slabs if (movementManager.halfMovementHistoryCounter > 15) limit *= 2.0D; // Adjust for custom walking speed - limit += 1.4D * (Math.pow(1.1, ((player.getWalkSpeed() / 0.20) - 1)) - 1); + double walkSpeedMultiplier = checksConfig.getDouble(CheckType.SPEED, "airAcceleration", "walkSpeedMultiplier"); // Default 1.4 + limit += walkSpeedMultiplier * (Math.pow(1.1, ((player.getWalkSpeed() / 0.20) - 1)) - 1); + // Boats sometimes give a false positive + if (Utilities.couldBeOnBoat(player)) + limit *= 1.25D; if (initialAcceleration > limit) { return new CheckResult(CheckResult.Result.FAILED, "exceeded acceleration limits (acceleration=" + initialAcceleration + ", max=" + limit + ")"); } } - // JumpBehaviour A + // JumpBehaviour // Works against YPorts and mini jumps - if (movementManager.touchedGroundThisTick && !boxedIn && movementManager.slimeInfluenceTicks <= 10) { - // This happens naturally as well when walking next to walls + if (checksConfig.isSubcheckEnabled(CheckType.SPEED, "jumpBehaviour") && movementManager.touchedGroundThisTick + && !boxedIn && movementManager.slimeInfluenceTicks <= 10) { + // This happens naturally if (movementManager.airTicksBeforeGrounded == movementManager.groundTicks) { - boolean movingFreely = Utilities.cantStandClose(movingTowards.getBlock()) - && Utilities.cantStandFar(movingTowards.getBlock()); - // TODO calculation for distanceXZ value - if (movingFreely && distanceXZ >= 0.42) { - return new CheckResult(CheckResult.Result.FAILED, - "had unexpected jumping behaviour"); + double minimumDistXZ = checksConfig.getDouble(CheckType.SPEED, "jumpBehaviour", "minimumDistXZ"); // Default 0.42 + if (distanceXZ >= minimumDistXZ) { + return new CheckResult(CheckResult.Result.FAILED, "had unexpected jumping behaviour"); } } } - // GroundSpeed A - if (movementManager.groundTicks > 1) { - double limit = 0.34 - 0.0055 * Math.min(9, movementManager.groundTicks); - if (movementManager.groundTicks < 5) - limit += 0.1D; - if (!Utilities.cantStandAtExp(movingTowards.clone().add(0, 0.51, 0)) - || !Utilities.cantStandAtExp(movingTowards.clone().add(0, 0.11, 0))) - limit *= 2.2D; - if (movementManager.halfMovementHistoryCounter > 8) - limit += 0.2D; - if (movementManager.iceInfluenceTicks >= 55) { - if (!Utilities.isIce(movingTowards.getBlock().getRelative(BlockFace.DOWN))) - limit += 0.75D; - else { - if (movementManager.topSolid && movementManager.bottomSolid) - limit *= 2.5D; - else - limit += 0.03D; - } - } - if (Utilities.isNearBed(movingTowards) || Utilities.couldBeOnHalfblock(movingTowards) - || Utilities.isNearBed(movingTowards.clone().add(0, -0.5, 0))) - limit *= 2.0D; - if (Utilities.couldBeOnBoat(player)) - limit += 0.2D; - if (movementManager.signInfluenceTicks > 0) - limit += 0.08D; - if (distanceXZ - limit > 0) { - return new CheckResult(CheckResult.Result.FAILED, - "moved too fast on ground (speed=" + distanceXZ + ", limit=" + limit + ")"); - } + // GroundSpeed + if (checksConfig.isSubcheckEnabled(CheckType.SPEED, "groundSpeed") && movementManager.groundTicks > 1) { + double initialLimit = checksConfig.getDouble(CheckType.SPEED, "groundSpeed", "initialLimit"); // Default 0.34 + double limit = initialLimit - 0.0055 * Math.min(9, movementManager.groundTicks); + // Leniency when moving back on ground + if (movementManager.groundTicks < 5) + limit += 0.1D; + // Slab leniency + if (movementManager.halfMovementHistoryCounter > 8) + limit += 0.2D; + // Adjust for speed effects + if (player.hasPotionEffect(PotionEffectType.SPEED)) + limit += (player.getPotionEffect(PotionEffectType.SPEED).getAmplifier() + 1) * 0.06D; + if (movementManager.iceInfluenceTicks >= 50) { + // When moving off ice + if (!Utilities.couldBeOnIce(movingTowards)) + limit *= 2.5D; + else { + // When boxed in and spamming space for boost + if (movementManager.topSolid && movementManager.bottomSolid) + limit *= 3.0D; + else + limit *= 1.25D; + } + } + if (Utilities.isNearBed(movingTowards) || Utilities.couldBeOnHalfblock(movingTowards) + || Utilities.isNearBed(movingTowards.clone().add(0, -0.5, 0))) + limit *= 2.0D; + if (Utilities.couldBeOnBoat(player)) + limit += 0.2D; + if (distanceXZ - limit > 0) { + return new CheckResult(CheckResult.Result.FAILED, + "moved too fast on ground (speed=" + distanceXZ + ", limit=" + limit + ")"); + } } return PASS; } @@ -176,6 +192,10 @@ public class SpeedCheck { Backend backend = AntiCheatReloaded.getManager().getBackend(); MovementManager movementManager = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId()) .getMovementManager(); + Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks(); + if (!checksConfig.isSubcheckEnabled(CheckType.SPEED, "verticalSpeed")) + return PASS; + if (player.isInsideVehicle() || player.isSleeping() || backend.isDoing(player, backend.velocitized, backend.getMagic().VELOCITY_TIME()) || VersionUtil.isFlying(player) || VersionUtil.isRiptiding(player)) { @@ -184,21 +204,20 @@ public class SpeedCheck { double maxMotionY = getMaxAcceptableMotionY(player, Utilities.isNearBed(distance.getTo()), Utilities.couldBeOnBoat(player), Utilities.isClimbableBlock(distance.getFrom().getBlock()) - || Utilities.isClimbableBlock(distance.getFrom().getBlock().getRelative(BlockFace.DOWN))); - if (movementManager.motionY > maxMotionY && movementManager.slimeInfluenceTicks <= 0 - && !movementManager.halfMovement) { + || Utilities.isClimbableBlock(distance.getFrom().getBlock().getRelative(BlockFace.DOWN)), movementManager.halfMovement, checksConfig); + if (movementManager.motionY > maxMotionY && movementManager.slimeInfluenceTicks <= 0) { return new CheckResult(CheckResult.Result.FAILED, "exceeded vertical speed limit (mY=" + movementManager.motionY + ", max=" + maxMotionY + ")"); } return PASS; } - private static double getMaxAcceptableMotionY(Player player, boolean nearBed, boolean couldBeOnBoat, boolean fromClimbable) { - double base = couldBeOnBoat ? 0.600000025 : (nearBed ? 0.5625 : 0.42); + private static double getMaxAcceptableMotionY(Player player, boolean nearBed, boolean couldBeOnBoat, boolean fromClimbable, boolean halfMovement, Checks checksConfig) { + double base = couldBeOnBoat ? 0.600000025 : (nearBed ? 0.5625 : (halfMovement ? 0.6 : 0.42)); if (fromClimbable) - base += 0.04; - if (player.hasPotionEffect(PotionEffectType.JUMP) ) { - base += player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() * 0.15D; + base += checksConfig.getDouble(CheckType.SPEED, "verticalSpeed", "climbableCompensation"); // Default 0.04 + if (player.hasPotionEffect(PotionEffectType.JUMP)) { + base += player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() * 0.2D; } return base; } 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 4e11ebb..eca2fb5 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/WaterWalkCheck.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/WaterWalkCheck.java @@ -36,7 +36,7 @@ import com.rammelkast.anticheatreloaded.util.Utilities; import com.rammelkast.anticheatreloaded.util.VersionUtil; /** - * This check should be replaced It works, but not great + * TODO recode */ public class WaterWalkCheck { @@ -57,13 +57,14 @@ public class WaterWalkCheck { if (IS_IN_WATER_CACHE.contains(uuid)) { if (player.getNearbyEntities(1, 1, 1).isEmpty()) { boolean violation; - if (!Utilities.sprintFly(player)) { + /*if (!Utilities.sprintFly(player)) { violation = x > backend.getMagic().XZ_SPEED_MAX_WATER() || z > backend.getMagic().XZ_SPEED_MAX_WATER(); } else { violation = x > backend.getMagic().XZ_SPEED_MAX_WATER_SPRINT() || z > backend.getMagic().XZ_SPEED_MAX_WATER_SPRINT(); - } + }*/ + violation = false; if (!violation && !Utilities.isFullyInWater(player.getLocation()) && Utilities.isHoveringOverWater(player.getLocation(), 1) && y == 0D && !block.getType().equals(Utilities.LILY_PAD)) { @@ -72,7 +73,7 @@ public class WaterWalkCheck { if (violation) { if (WATER_SPEED_VIOLATIONS.containsKey(uuid)) { int v = WATER_SPEED_VIOLATIONS.get(uuid); - if (v >= backend.getMagic().WATER_SPEED_VIOLATION_MAX()) { + if (v >= 8) { WATER_SPEED_VIOLATIONS.put(uuid, 0); return new CheckResult(CheckResult.Result.FAILED, "stood on water " + v + " times (can't stand on " + block.getType() @@ -99,7 +100,7 @@ public class WaterWalkCheck { || y == 0.04999999999999982)) { if (WATER_ASCENSION_VIOLATIONS.containsKey(uuid)) { int v = WATER_ASCENSION_VIOLATIONS.get(uuid); - if (v >= backend.getMagic().WATER_ASCENSION_VIOLATION_MAX()) { + if (v >= 8) { WATER_ASCENSION_VIOLATIONS.put(uuid, 0); return new CheckResult(CheckResult.Result.FAILED, "stood on water " + v + " times (can't stand on " + block.getType() + " or " diff --git a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/YAxisCheck.java b/src/main/java/com/rammelkast/anticheatreloaded/check/movement/YAxisCheck.java deleted file mode 100644 index 87cfc35..0000000 --- a/src/main/java/com/rammelkast/anticheatreloaded/check/movement/YAxisCheck.java +++ /dev/null @@ -1,131 +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.movement; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; - -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.potion.PotionEffectType; - -import com.rammelkast.anticheatreloaded.AntiCheatReloaded; -import com.rammelkast.anticheatreloaded.check.CheckResult; -import com.rammelkast.anticheatreloaded.util.Distance; -import com.rammelkast.anticheatreloaded.util.Utilities; -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); - - private static boolean hasJumpPotion(Player player) { - return player.hasPotionEffect(PotionEffectType.JUMP); - } - - public static CheckResult runCheck(Player player, Distance distance) { - if (distance.getYDifference() > AntiCheatReloaded.getManager().getBackend().getMagic().TELEPORT_MIN() - || distance.getYDifference() < 0 || VersionUtil.isFlying(player)) { - return PASS; - } - if (!FlightCheck.isMovingExempt(player) && !Utilities.isClimbableBlock(player.getLocation().getBlock()) - && !Utilities.isClimbableBlock(player.getLocation().add(0, -1, 0).getBlock()) - && !player.isInsideVehicle() && !Utilities.isInWater(player) && !hasJumpPotion(player) - && !isMoveUpBlock(player.getLocation().add(0, -1, 0).getBlock()) - && !isMoveUpBlock(player.getLocation().add(0, -1.5, 0).getBlock())) { - double y1 = player.getLocation().getY(); - UUID uuid = player.getUniqueId(); - // Fix Y axis spam. - 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 > LAST_Y_COORD_CACHE.get(uuid) - && Y_AXIS_VIOLATIONS.get(uuid) > AntiCheatReloaded.getManager().getBackend().getMagic() - .Y_MAXVIOLATIONS() - && (System.currentTimeMillis() - LAST_Y_AXIS_VIOLATION.get(uuid)) < AntiCheatReloaded - .getManager().getBackend().getMagic().Y_MAXVIOTIME()) { - Location g = player.getLocation(); - 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(LAST_Y_COORD_CACHE.get(uuid)); - if (g.getBlock().getType() == Material.AIR) { - player.teleport(g); - } - } - return new CheckResult(CheckResult.Result.FAILED, - "tried to fly on y-axis " + Y_AXIS_VIOLATIONS.get(uuid) + " times (max=" - + AntiCheatReloaded.getManager().getBackend().getMagic().Y_MAXVIOLATIONS() + ")"); - } else { - if (Y_AXIS_VIOLATIONS.get(uuid) > AntiCheatReloaded.getManager().getBackend().getMagic() - .Y_MAXVIOLATIONS() - && (System.currentTimeMillis() - LAST_Y_AXIS_VIOLATION.get(uuid)) > AntiCheatReloaded - .getManager().getBackend().getMagic().Y_MAXVIOTIME()) { - Y_AXIS_VIOLATIONS.put(uuid, 0); - LAST_Y_AXIS_VIOLATION.put(uuid, 0L); - } - } - 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()) || Utilities.isStair(player.getLocation().add(0, -0.5, 0).getBlock())) ? 0.5 : 0.0); - if ((y1 - LAST_Y_COORD_CACHE.get(uuid)) > diff - && i < AntiCheatReloaded.getManager().getBackend().getMagic().Y_TIME()) { - Location g = player.getLocation(); - 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(LAST_Y_COORD_CACHE.get(uuid)); - if (g.getBlock().getType() == Material.AIR) { - player.teleport(g); - } - } - return new CheckResult(CheckResult.Result.FAILED, "tried to fly on y-axis in " + i + " ms (min=" - + AntiCheatReloaded.getManager().getBackend().getMagic().Y_TIME() + ")"); - } else { - if ((y1 - LAST_Y_COORD_CACHE.get(uuid)) > AntiCheatReloaded.getManager().getBackend().getMagic() - .Y_MAXDIFF() + 1 - || (System.currentTimeMillis() - LAST_Y_TIME.get(uuid)) > AntiCheatReloaded.getManager() - .getBackend().getMagic().Y_TIME()) { - LAST_Y_TIME.put(uuid, System.currentTimeMillis()); - LAST_Y_COORD_CACHE.put(uuid, y1); - } - } - } - } - // Fix Y axis spam - return PASS; - } - - public static boolean isMoveUpBlock(Block block) { - return Utilities.isStair(block); - } - -} diff --git a/src/main/java/com/rammelkast/anticheatreloaded/command/executors/CommandReport.java b/src/main/java/com/rammelkast/anticheatreloaded/command/executors/CommandReport.java index af570b1..6fca5c4 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/command/executors/CommandReport.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/command/executors/CommandReport.java @@ -170,7 +170,7 @@ public class CommandReport extends CommandBase { } else if (use > 50) { color = RED; } - cs.sendMessage(GRAY + CheckType.getName(type) + ": " + color + use); + cs.sendMessage(GRAY + type.getName() + ": " + color + use); } } cs.sendMessage(MENU_END); diff --git a/src/main/java/com/rammelkast/anticheatreloaded/config/Configuration.java b/src/main/java/com/rammelkast/anticheatreloaded/config/Configuration.java index 3c76b41..70d4451 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/config/Configuration.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/config/Configuration.java @@ -19,21 +19,35 @@ package com.rammelkast.anticheatreloaded.config; +import java.io.File; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Proxy; +import java.util.ArrayList; + import org.bukkit.configuration.file.YamlConfiguration; import com.rammelkast.anticheatreloaded.AntiCheatReloaded; import com.rammelkast.anticheatreloaded.config.files.Config; import com.rammelkast.anticheatreloaded.config.files.Enterprise; -import com.rammelkast.anticheatreloaded.config.holders.mysql.*; -import com.rammelkast.anticheatreloaded.config.holders.yaml.*; -import com.rammelkast.anticheatreloaded.config.providers.*; +import com.rammelkast.anticheatreloaded.config.holders.mysql.MySQLGroupsHolder; +import com.rammelkast.anticheatreloaded.config.holders.mysql.MySQLLangHolder; +import com.rammelkast.anticheatreloaded.config.holders.mysql.MySQLLevelsHolder; +import com.rammelkast.anticheatreloaded.config.holders.mysql.MySQLMagicHolder; +import com.rammelkast.anticheatreloaded.config.holders.mysql.MySQLRulesHolder; +import com.rammelkast.anticheatreloaded.config.holders.yaml.YamlChecksHolder; +import com.rammelkast.anticheatreloaded.config.holders.yaml.YamlGroupsHolder; +import com.rammelkast.anticheatreloaded.config.holders.yaml.YamlLangHolder; +import com.rammelkast.anticheatreloaded.config.holders.yaml.YamlLevelsHolder; +import com.rammelkast.anticheatreloaded.config.holders.yaml.YamlMagicHolder; +import com.rammelkast.anticheatreloaded.config.holders.yaml.YamlRulesHolder; +import com.rammelkast.anticheatreloaded.config.providers.Checks; +import com.rammelkast.anticheatreloaded.config.providers.Groups; +import com.rammelkast.anticheatreloaded.config.providers.Lang; +import com.rammelkast.anticheatreloaded.config.providers.Levels; +import com.rammelkast.anticheatreloaded.config.providers.Magic; +import com.rammelkast.anticheatreloaded.config.providers.Rules; import com.rammelkast.anticheatreloaded.manage.AntiCheatManager; -import java.io.File; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Proxy; -import java.util.ArrayList; - public class Configuration { private AntiCheatManager manager; @@ -45,6 +59,7 @@ public class Configuration { private Groups groups; private Levels levels; private Rules rules; + private Checks checks; private ArrayList flatfiles; private ArrayList dbfiles; @@ -83,6 +98,9 @@ public class Configuration { rules = new YamlRulesHolder(plugin, this); flatfiles.add((YamlRulesHolder) rules); } + + checks = new YamlChecksHolder(plugin, this); + flatfiles.add((YamlChecksHolder) checks); InvocationHandler handler; if (config.enterprise.getValue() && enterprise.configMagic.getValue()) { @@ -195,4 +213,8 @@ public class Configuration { public Magic getMagic() { return magic; } + + public Checks getChecks() { + return checks; + } } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/config/holders/yaml/YamlChecksHolder.java b/src/main/java/com/rammelkast/anticheatreloaded/config/holders/yaml/YamlChecksHolder.java new file mode 100644 index 0000000..3fe11cc --- /dev/null +++ b/src/main/java/com/rammelkast/anticheatreloaded/config/holders/yaml/YamlChecksHolder.java @@ -0,0 +1,85 @@ +/* + * 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.config.holders.yaml; + +import com.rammelkast.anticheatreloaded.AntiCheatReloaded; +import com.rammelkast.anticheatreloaded.check.CheckType; +import com.rammelkast.anticheatreloaded.config.Configuration; +import com.rammelkast.anticheatreloaded.config.ConfigurationFile; +import com.rammelkast.anticheatreloaded.config.providers.Checks; + +public class YamlChecksHolder extends ConfigurationFile implements Checks { + + public static final String FILENAME = "checks.yml"; + + public YamlChecksHolder(AntiCheatReloaded plugin, Configuration config) { + super(plugin, config, FILENAME); + } + + @Override + public void open() { + + } + + @Override + public boolean getBoolean(CheckType checkType, String subcheck, String name) { + return this.getConfigFile().getConfigurationSection(checkType.name().toLowerCase()).getConfigurationSection(subcheck) + .getBoolean(name); + } + + @Override + public boolean isSubcheckEnabled(CheckType checkType, String subcheck) { + return this.getBoolean(checkType, subcheck, "enabled"); + } + + @Override + public double getDouble(CheckType checkType, String subcheck, String name) { + return this.getConfigFile().getConfigurationSection(checkType.name().toLowerCase()).getConfigurationSection(subcheck) + .getDouble(name); + } + + @Override + public int getInteger(CheckType checkType, String subcheck, String name) { + return this.getConfigFile().getConfigurationSection(checkType.name().toLowerCase()).getConfigurationSection(subcheck) + .getInt(name); + } + + @Override + public boolean getBoolean(CheckType checkType, String name) { + return this.getConfigFile().getConfigurationSection(checkType.name().toLowerCase()).getBoolean(name); + } + + @Override + public double getDouble(CheckType checkType, String name) { + return this.getConfigFile().getConfigurationSection(checkType.name().toLowerCase()).getDouble(name); + } + + @Override + public int getInteger(CheckType checkType, String name) { + return this.getConfigFile().getConfigurationSection(checkType.name().toLowerCase()).getInt(name); + } + + @Override + public boolean isEnabled(CheckType checkType) { + // If the root of a check has no enabled or disabled option, it has to be configured on a subcheck basis + if (!this.getConfigFile().getConfigurationSection(checkType.name().toLowerCase()).contains("enabled")) + return true; + return this.getConfigFile().getConfigurationSection(checkType.name().toLowerCase()).getBoolean("enabled"); + } +} diff --git a/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Checks.java b/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Checks.java new file mode 100644 index 0000000..846cdda --- /dev/null +++ b/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Checks.java @@ -0,0 +1,41 @@ +/* + * 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.config.providers; + +import com.rammelkast.anticheatreloaded.check.CheckType; + +public interface Checks { + + public boolean getBoolean(CheckType checkType, String name); + + public boolean getBoolean(CheckType checkType, String subcheck, String name); + + public double getDouble(CheckType checkType, String name); + + public double getDouble(CheckType checkType, String subcheck, String name); + + public int getInteger(CheckType checkType, String name); + + public int getInteger(CheckType checkType, String subcheck, String name); + + public boolean isEnabled(CheckType checkType); + + public boolean isSubcheckEnabled(CheckType checkType, String subcheck); + +} diff --git a/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Magic.java b/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Magic.java index f68d0a4..942a393 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Magic.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/config/providers/Magic.java @@ -166,14 +166,6 @@ public interface Magic { * Maximum speed that a player can climb a waterfall; Type=DOUBLE, Leniency=INCREASE. */ public double WATER_CLIMB_MAX(); - /** - * Number of times a player can fly on the y-axis before action is taken; Type=INTEGER, Leniency=INCREASE. - */ - public int Y_MAXVIOLATIONS(); - /** - * Time a player is forced to wait after flying on the y-axis; Type=SYSTEM, Leniency=DECREASE. - */ - public int Y_MAXVIOTIME(); /** * Number of times a player can fail a velocity check before action is taken; Type=INTEGER, Leniency=INCREASE. */ @@ -198,18 +190,6 @@ public interface Magic { * Number of times a player can fail the nofall check before action is taken; Type=INTEGER, Leniency=INCREASE. */ public int NOFALL_LIMIT(); - /** - * Number of times a player can fail the ascension check before action is taken; Type=INTEGER, Leniency=INCREASE. - */ - public int ASCENSION_COUNT_MAX(); - /** - * Number of times a player can fail the ascension check while in water before action is taken; Type=INTEGER, Leniency=INCREASE. - */ - public int WATER_ASCENSION_VIOLATION_MAX(); - /** - * Number of times a player can be caught speeding in water before action is taken; Type=INTEGER, Leniency=INCREASE. - */ - public int WATER_SPEED_VIOLATION_MAX(); /** * Number of times a player can sprint without proper food level before action is taken; Type=INTEGER, Leniency=INCREASE. */ @@ -286,66 +266,10 @@ public interface Magic { * Maximum speed a player on a ladder can travel downwards */ public double LADDER_DOWN_MAX(); - /** - * Maximum speed a player can travel up; Type=DOUBLE, Leniency=INCREASE. - */ - public double Y_SPEED_MAX(); - /** - * Maximum difference between the player's last 2 Y values when traveling up; Type=DOUBLE, Leniency=INCREASE. - */ - public double Y_MAXDIFF(); - /** - * Time in between Y difference measures; Type=SYSTEM, Leniency=DECREASE. - */ - public int Y_TIME(); - /** - * Maximum speed a player can travel forwards or backwards; Type=DOUBLE, Leniency=INCREASE. - */ - public double XZ_SPEED_MAX(); - /** - * Maximum speed a player can travel forwards or backwards while sprinting; Type=DOUBLE, Leniency=INCREASE. - */ - public double XZ_SPEED_MAX_SPRINT(); - /** - * Maximum speed a player can travel forwards or backwards while flying; Type=DOUBLE, Leniency=INCREASE. - */ - public double XZ_SPEED_MAX_FLY(); - /** - * Maximum speed a player can travel forwards or backwards while under the influence; Type=DOUBLE, Leniency=INCREASE. - */ - public double XZ_SPEED_MAX_POTION(); - /** - * Maximum speed a player can travel forwards or backwards while sprinting while under the influence; Type=DOUBLE, Leniency=INCREASE. - */ - public double XZ_SPEED_MAX_POTION_SPRINT(); /** * Maximum speed a player can travel forwards or backwards while sneaking; Type=DOUBLE, Leniency=INCREASE. */ public double XZ_SPEED_MAX_SNEAK(); - /** - * Maximum speed a player can travel forwards or backwards in water; Type=DOUBLE, Leniency=INCREASE. - */ - public double XZ_SPEED_MAX_WATER(); - /** - * Maximum speed a player can travel forwards or backwards in water while sprinting; Type=DOUBLE, Leniency=INCREASE. - */ - public double XZ_SPEED_MAX_WATER_SPRINT(); - /** - * Maximum speed a player can travel forwards or backwards on soul sand; Type=DOUBLE, Leniency=INCREASE. - */ - public double XZ_SPEED_MAX_SOULSAND(); - /** - * Maximum speed a player can travel forwards or backwards on soul sand while sprinting; Type=DOUBLE, Leniency=INCREASE. - */ - public double XZ_SPEED_MAX_SOULSAND_SPRINT(); - /** - * Maximum speed a player can travel forwards or backwards on soul sand while under the influence; Type=DOUBLE, Leniency=INCREASE. - */ - public double XZ_SPEED_MAX_SOULSAND_POTION(); - /** - * Maximum times a player can fail the speed check before action is taken; Type=INTEGER, Leniency=INCREASE. - */ - public int SPEED_MAX(); /** * The number of clicks we should wait before checking if the player has used fast inventory; Type=INTEGER; Leniency=INCREASE. */ diff --git a/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java b/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java index 5cde719..c93a965 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/event/EntityListener.java @@ -27,6 +27,7 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityPotionEffectEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; import org.bukkit.event.entity.EntityShootBowEvent; @@ -38,11 +39,21 @@ 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 com.rammelkast.anticheatreloaded.util.VersionUtil; public class EntityListener extends EventListener { + @EventHandler + public void onEntityPotionEffect(EntityPotionEffectEvent event) { + if (!(event.getEntity() instanceof Player)) + return; + if (event.getNewEffect() == null) + return; + if (!VersionUtil.isLevitationEffect(event.getNewEffect())) + return; + getBackend().logLevitating((Player) event.getEntity(), event.getNewEffect().getDuration()); + } + @EventHandler public void onEntityShootBow(EntityShootBowEvent event) { if (event.getEntity() instanceof Player) { diff --git a/src/main/java/com/rammelkast/anticheatreloaded/event/EventListener.java b/src/main/java/com/rammelkast/anticheatreloaded/event/EventListener.java index 0c340e6..1fc8e2e 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/event/EventListener.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/event/EventListener.java @@ -59,20 +59,20 @@ public class EventListener implements Listener { if (message == null || message.equals("")) { if (debugMode) { message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.DARK_GRAY + "> " + ChatColor.GRAY + player.getName() + " failed " - + CheckType.getName(type); + + type.getName(); } else { message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.DARK_GRAY + "> " + ChatColor.GRAY + player.getName() + " failed " - + CheckType.getName(type) + ChatColor.GOLD + " (x" + vlForType + ")"; + + type.getName() + ChatColor.GOLD + " (x" + vlForType + ")"; } } else { if (debugMode) { message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.DARK_GRAY + "> " + ChatColor.GRAY + player.getName() + " failed " - + CheckType.getName(type) + ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + message + + type.getName() + ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + message + ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + "ping: " + user.getPing() + "ms" + ", tps: " + TPS_FORMAT.format(AntiCheatReloaded.getPlugin().getTPS()); } else { message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.DARK_GRAY + "> " + ChatColor.GRAY + player.getName() + " failed " - + CheckType.getName(type) + ChatColor.GOLD + " (x" + vlForType + ")" + ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + "ping: " + user.getPing() + "ms" + + type.getName() + ChatColor.GOLD + " (x" + vlForType + ")" + ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + "ping: " + user.getPing() + "ms" + ", tps: " + TPS_FORMAT.format(AntiCheatReloaded.getPlugin().getTPS()); } } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/manage/UserManager.java b/src/main/java/com/rammelkast/anticheatreloaded/manage/UserManager.java index 24479ec..c522cac 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/manage/UserManager.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/manage/UserManager.java @@ -209,7 +209,7 @@ public class UserManager { } else if (event.equalsIgnoreCase("KICK")) { user.getPlayer().kickPlayer(ChatColor.translateAlternateColorCodes('&', kickReason)); AntiCheatReloaded.getPlugin().onPlayerKicked(); - String msg = ChatColor.translateAlternateColorCodes('&', config.getLang().KICK_BROADCAST().replaceAll("%player%", name) + " (" + CheckType.getName(type) + ")"); + String msg = ChatColor.translateAlternateColorCodes('&', config.getLang().KICK_BROADCAST().replaceAll("%player%", name) + " (" + type.getName() + ")"); if (!msg.equals("")) { manager.log(msg); manager.playerLog(msg); @@ -224,7 +224,7 @@ public class UserManager { } else if (event.equalsIgnoreCase("BAN")) { Bukkit.getBanList(Type.NAME).addBan(user.getPlayer().getName(), ChatColor.translateAlternateColorCodes('&', banReason), null, null); user.getPlayer().kickPlayer(ChatColor.translateAlternateColorCodes('&', banReason)); - String msg = ChatColor.translateAlternateColorCodes('&', config.getLang().BAN_BROADCAST().replaceAll("%player%", name) + " (" + CheckType.getName(type) + ")"); + String msg = ChatColor.translateAlternateColorCodes('&', config.getLang().BAN_BROADCAST().replaceAll("%player%", name) + " (" + type.getName() + ")"); if (!msg.equals("")) { manager.log(msg); manager.playerLog(msg); diff --git a/src/main/java/com/rammelkast/anticheatreloaded/util/MovementManager.java b/src/main/java/com/rammelkast/anticheatreloaded/util/MovementManager.java index fd92328..d527547 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/util/MovementManager.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/util/MovementManager.java @@ -18,7 +18,12 @@ */ package com.rammelkast.anticheatreloaded.util; +import java.util.ArrayList; +import java.util.List; + import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; import org.bukkit.entity.Player; public class MovementManager { @@ -37,10 +42,12 @@ public class MovementManager { public int iceInfluenceTicks = 0; // Ticks influenced by slime public int slimeInfluenceTicks = 0; - // Ticks influenced by sign - public int signInfluenceTicks = 0; - // Last Y motion + // Y motion of the movement public double motionY; + // Previous Y motion of the movement + public double lastMotionY; + // Horizontal distance of movement + public double distanceXZ; // If the player touched the ground again this tick public boolean touchedGroundThisTick = false; // Last recorded distance @@ -53,14 +60,29 @@ public class MovementManager { public boolean bottomSolid; // If the current movement is up a slab or stair public boolean halfMovement; + // If the player is on the ground + public boolean onGround; // Ticks counter for last halfMovement public int halfMovementHistoryCounter = 0; + // Time of last teleport + public long lastTeleport; + // Elytra effect ticks + public int elytraEffectTicks; public void handle(Player player, Location from, Location to, Distance distance) { - boolean serverOnGround = !Utilities.cantStandAtExp(to) || Utilities.couldBeOnBoat(player); + this.onGround = player.isOnGround(); // TODO temp solution, can be spoofed + + double x = distance.getXDifference(); + double z = distance.getZDifference(); + this.distanceXZ = Math.sqrt(x * x + z * z); + + // Account for standing on boat + if (Utilities.couldBeOnBoat(player, 0.25)) + this.onGround = true; + this.touchedGroundThisTick = false; this.halfMovement = false; - if (!serverOnGround) { + if (!this.onGround) { this.groundTicks = 0; this.airTicks++; } else { @@ -71,14 +93,6 @@ public class MovementManager { this.groundTicks++; } - if (to.getBlock().getType().name().endsWith("SIGN") || to.getBlock().getType().name().endsWith("POST") - || from.getBlock().getType().name().endsWith("SIGN") - || from.getBlock().getType().name().endsWith("POST")) - this.signInfluenceTicks = 3; - else - if (this.signInfluenceTicks > 0) - this.signInfluenceTicks--; - if (Utilities.couldBeOnIce(to)) { this.iceTicks++; this.iceInfluenceTicks = 60; @@ -97,12 +111,20 @@ public class MovementManager { this.slimeInfluenceTicks--; } + if (VersionUtil.isGliding(player)) { + this.elytraEffectTicks = 30; + } else { + if (this.elytraEffectTicks > 0) + this.elytraEffectTicks--; + } + double lastDistanceSq = Math.sqrt(this.lastDistance.getXDifference() * this.lastDistance.getXDifference() + this.lastDistance.getZDifference() * this.lastDistance.getZDifference()); double currentDistanceSq = Math.sqrt(distance.getXDifference() * distance.getXDifference() + distance.getZDifference() * distance.getZDifference()); this.acceleration = currentDistanceSq - lastDistanceSq; + this.lastMotionY = this.motionY; this.motionY = to.getY() - from.getY(); Location top = to.clone().add(0, 2, 0); @@ -118,5 +140,4 @@ public class MovementManager { this.halfMovementHistoryCounter--; } } - } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/util/Utilities.java b/src/main/java/com/rammelkast/anticheatreloaded/util/Utilities.java index 8c46391..82a326d 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/util/Utilities.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/util/Utilities.java @@ -19,6 +19,8 @@ package com.rammelkast.anticheatreloaded.util; +import java.math.BigDecimal; +import java.math.RoundingMode; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -120,7 +122,11 @@ public final class Utilities { } public static boolean couldBeOnBoat(Player player) { - for (Entity entity : player.getNearbyEntities(0.3, 0.3, 0.3)) { + return couldBeOnBoat(player, 0.35); + } + + public static boolean couldBeOnBoat(Player player, double range) { + for (Entity entity : player.getNearbyEntities(range, range, range)) { if (entity instanceof Boat) return true; } @@ -135,7 +141,8 @@ public final class Utilities { */ public static boolean couldBeOnIce(Location location) { return isNearIce(new Location(location.getWorld(), fixXAxis(location.getX()), location.getY() - 0.01D, - location.getBlockZ())); + location.getBlockZ())) || isNearIce(new Location(location.getWorld(), fixXAxis(location.getX()), location.getY() - 0.26D, + location.getBlockZ())); } @@ -187,7 +194,7 @@ public final class Utilities { } public static boolean isHalfblock(Block block) { - return isSlab(block) || isStair(block); + return isSlab(block) || isStair(block) || isWall(block); } @@ -359,6 +366,17 @@ public final class Utilities { Material type = block.getType(); return type.name().endsWith("STAIRS"); } + + /** + * Determine whether a block is a wall + * + * @param block block to check + * @return true if wall + */ + public static boolean isWall(Block block) { + Material type = block.getType(); + return type.name().endsWith("WALL"); + } /** * Determine whether a player is sprinting or flying @@ -415,8 +433,8 @@ public final class Utilities { */ public static boolean isNearWater(Player player) { return player.getLocation().getBlock().isLiquid() - || player.getLocation().getBlock().getRelative(BlockFace.DOWN).isLiquid() || player.getLocation().getBlock().getRelative(BlockFace.UP).isLiquid() + || player.getLocation().getBlock().getRelative(BlockFace.DOWN).isLiquid() || player.getLocation().getBlock().getRelative(BlockFace.NORTH).isLiquid() || player.getLocation().getBlock().getRelative(BlockFace.SOUTH).isLiquid() || player.getLocation().getBlock().getRelative(BlockFace.EAST).isLiquid() @@ -679,52 +697,30 @@ public final class Utilities { } /** - * Code by Hawk Anticheat - * (https://github.com/HawkAnticheat/Hawk/blob/master/src/me/islandscout/hawk/util/MathPlus.java) - * - * @param a - * @param b - * @return the greatest common divisor between two floats + * Rounds a float value to a scale + * @param value Value to round + * @param scale Scale + * @return rounded value */ - public static float gcdRational(float a, float b) { - if (a == 0) { - return b; - } - int quotient = getIntQuotient(b, a); - float remainder = ((b / a) - quotient) * a; - if (Math.abs(remainder) < Math.max(a, b) * 1E-3F) - remainder = 0; - return gcdRational(remainder, a); + public static float roundFloat(float value, int scale) { + return new BigDecimal(value).setScale(scale, RoundingMode.HALF_UP).floatValue(); } - + /** - * Code by Hawk Anticheat - * (https://github.com/HawkAnticheat/Hawk/blob/master/src/me/islandscout/hawk/util/MathPlus.java) - * - * @param numbers - * @return the greatest common divisor between a list of floats + * Rounds a double value to a scale + * @param value Value to round + * @param scale Scale + * @return rounded value */ - public static float gcdRational(List numbers) { - float result = numbers.get(0); - for (int i = 1; i < numbers.size(); i++) { - result = gcdRational(numbers.get(i), result); - } - return result; - } - - /** - * Code by Hawk Anticheat - * (https://github.com/HawkAnticheat/Hawk/blob/master/src/me/islandscout/hawk/util/MathPlus.java) - * - * @param dividend - * @param divisor - */ - public static int getIntQuotient(float dividend, float divisor) { - float ans = dividend / divisor; - float error = Math.max(dividend, divisor) * 1E-3F; - return (int) (ans + error); + public static double roundDouble(double value, int scale) { + return new BigDecimal(value).setScale(scale, RoundingMode.HALF_UP).doubleValue(); } + public static int floor(double value) { + int rounded = (int) value; + return value < rounded ? rounded - 1 : rounded; + } + public static boolean isHoneyBlock(Block block) { if (!VersionUtil.isOfVersion("v1_15")) { return false; @@ -867,13 +863,13 @@ public final class Utilities { INSTANT_BREAK.add(Material.TALL_SEAGRASS); INSTANT_BREAK.add(Material.WHEAT); // Start 1.14 objects - if (VersionUtil.isOfVersion("v1_14") || VersionUtil.isOfVersion("v1_15")) { + if (VersionUtil.isOfVersion("v1_14") || VersionUtil.isOfVersion("v1_15") || VersionUtil.isOfVersion("v1_16")) { INSTANT_BREAK.add(Material.BAMBOO_SAPLING); INSTANT_BREAK.add(Material.CORNFLOWER); } // End 1.14 objects // Start 1.15 objects - if (VersionUtil.isOfVersion("v1_15")) { + if (VersionUtil.isOfVersion("v1_15") || VersionUtil.isOfVersion("v1_16")) { INSTANT_BREAK.add(Material.HONEY_BLOCK); } // End 1.15 objects @@ -918,13 +914,13 @@ public final class Utilities { FOOD.add(Material.SPIDER_EYE); FOOD.add(Material.TROPICAL_FISH); // Start 1.14 objects - if (VersionUtil.isOfVersion("v1_14") || VersionUtil.isOfVersion("v1_15")) { + if (VersionUtil.isOfVersion("v1_14") || VersionUtil.isOfVersion("v1_15") || VersionUtil.isOfVersion("v1_16")) { FOOD.add(Material.SUSPICIOUS_STEW); FOOD.add(Material.SWEET_BERRIES); } // End 1.14 objects // Start 1.15 objects - if (VersionUtil.isOfVersion("v1_15")) { + if (VersionUtil.isOfVersion("v1_15") || VersionUtil.isOfVersion("v1_16")) { FOOD.add(Material.HONEY_BOTTLE); } // End 1.15 objects @@ -960,10 +956,19 @@ public final class Utilities { CLIMBABLE.add(Material.LADDER); CLIMBABLE.add(Material.WATER); // Start 1.14 objects - if (VersionUtil.isOfVersion("v1_14") || VersionUtil.isOfVersion("v1_15")) { + if (VersionUtil.isOfVersion("v1_14") || VersionUtil.isOfVersion("v1_15") || VersionUtil.isOfVersion("v1_16")) { CLIMBABLE.add(Material.SCAFFOLDING); } // End 1.14 objects + + // Start 1.16 objects + if (VersionUtil.isOfVersion("v1_16")) { + CLIMBABLE.add(XMaterial.TWISTING_VINES.parseMaterial()); + CLIMBABLE.add(XMaterial.TWISTING_VINES_PLANT.parseMaterial()); + CLIMBABLE.add(XMaterial.WEEPING_VINES.parseMaterial()); + CLIMBABLE.add(XMaterial.TWISTING_VINES_PLANT.parseMaterial()); + } + // End 1.16 objects // End climbable } // End other versions diff --git a/src/main/java/com/rammelkast/anticheatreloaded/util/VersionUtil.java b/src/main/java/com/rammelkast/anticheatreloaded/util/VersionUtil.java index fd86507..adf179a 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/util/VersionUtil.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/util/VersionUtil.java @@ -29,12 +29,15 @@ import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import com.rammelkast.anticheatreloaded.AntiCheatReloaded; + public class VersionUtil { private static final List SUPPORTED_VERSIONS = Arrays - .asList(new String[] { "v1_15", "v1_14", "v1_13", "v1_8_R3" }); + .asList(new String[] { "v1_16", "v1_15", "v1_14", "v1_13", "v1_8_R3" }); public static String getVersion() { return Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3]; @@ -62,14 +65,15 @@ public class VersionUtil { public static boolean isBountifulUpdate() { return isOfVersion("v1_8"); } - - public static boolean isFlying(Player p) { + + public static boolean isFlying(Player player) { if (isBountifulUpdate()) { - return p.isFlying(); + return player.isFlying(); } - return p.isFlying() || p.isGliding() || p.hasPotionEffect(PotionEffectType.LEVITATION); + return player.isFlying() || player.isGliding() || player.hasPotionEffect(PotionEffectType.LEVITATION) + || AntiCheatReloaded.getManager().getBackend().justLevitated(player); } - + public static boolean isRiptiding(Player player) { if (isBountifulUpdate()) { return false; @@ -83,7 +87,7 @@ public class VersionUtil { } return player.hasPotionEffect(PotionEffectType.SLOW_FALLING); } - + public static boolean isFrostWalk(Player player) { if (player.getInventory().getBoots() == null || isBountifulUpdate()) { return false; @@ -98,7 +102,7 @@ public class VersionUtil { } return player.getInventory().getItemInMainHand(); } - + public static int getPlayerPing(Player player) { try { Object entityPlayer = player.getClass().getMethod("getHandle").invoke(player); @@ -116,4 +120,18 @@ public class VersionUtil { return player.getTargetBlockExact(distance); } + public static boolean isGliding(Player player) { + if (isBountifulUpdate()) { + return false; + } + return player.isGliding(); + } + + public static boolean isLevitationEffect(PotionEffect effect) { + if (isBountifulUpdate()) { + return false; + } + return effect.getType().equals(PotionEffectType.LEVITATION); + } + } diff --git a/src/main/java/com/rammelkast/anticheatreloaded/util/XMaterial.java b/src/main/java/com/rammelkast/anticheatreloaded/util/XMaterial.java index 017e0fc..12e074d 100644 --- a/src/main/java/com/rammelkast/anticheatreloaded/util/XMaterial.java +++ b/src/main/java/com/rammelkast/anticheatreloaded/util/XMaterial.java @@ -43,7 +43,6 @@ import java.util.regex.Pattern; /** * XMaterial - Data Values/Pre-flattening
- * Supports 1.8-1.15
* 1.13 and above as priority. *

* This class is mainly designed to support ItemStacks. @@ -58,14 +57,14 @@ import java.util.regex.Pattern; * XMaterial v1: https://www.spigotmc.org/threads/329630/ * * @author Crypto Morin - * @version 4.0.0 + * @version 5.0.1 * @see Material * @see ItemStack */ public enum XMaterial { ACACIA_BOAT("BOAT_ACACIA"), ACACIA_BUTTON("WOOD_BUTTON"), - ACACIA_DOOR("ACACIA_DOOR_ITEM"), + ACACIA_DOOR("ACACIA_DOOR_ITEM", "ACACIA_DOOR"), ACACIA_FENCE, ACACIA_FENCE_GATE, ACACIA_LEAVES("LEAVES_2"), @@ -89,6 +88,7 @@ public enum XMaterial { */ AIR, ALLIUM(2, "RED_ROSE"), + ANCIENT_DEBRIS("1.16"), ANDESITE(5, "STONE"), ANDESITE_SLAB, ANDESITE_STAIRS, @@ -105,6 +105,7 @@ public enum XMaterial { BAMBOO_SAPLING("1.14"), BARREL("1.14", "CHEST", ""), BARRIER, + BASALT("1.16"), BAT_SPAWN_EGG(65, "MONSTER_EGG"), BEACON, BEDROCK, @@ -123,7 +124,7 @@ public enum XMaterial { BELL("1.14"), BIRCH_BOAT("BOAT_BIRCH"), BIRCH_BUTTON("WOOD_BUTTON"), - BIRCH_DOOR("BIRCH_DOOR_ITEM"), + BIRCH_DOOR("BIRCH_DOOR_ITEM", "BIRCH_DOOR"), BIRCH_FENCE, BIRCH_FENCE_GATE, BIRCH_LEAVES(2, "LEAVES"), @@ -137,8 +138,12 @@ public enum XMaterial { BIRCH_TRAPDOOR("TRAP_DOOR"), BIRCH_WALL_SIGN("SIGN_POST", "WALL_SIGN"), BIRCH_WOOD(2, "LOG"), + BLACKSTONE("1.16"), + BLACKSTONE_SLAB("1.16"), + BLACKSTONE_STAIRS("1.16"), + BLACKSTONE_WALL("1.16"), BLACK_BANNER("BANNER", "STANDING_BANNER"), - BLACK_BED(15, "BED", "BED_BLOCK"), + BLACK_BED(15, "BED_BLOCK", "BED"), BLACK_CARPET(15, "CARPET"), BLACK_CONCRETE(15, "CONCRETE"), BLACK_CONCRETE_POWDER(15, "CONCRETE_POWDER"), @@ -154,8 +159,8 @@ public enum XMaterial { BLAZE_POWDER, BLAZE_ROD, BLAZE_SPAWN_EGG(61, "MONSTER_EGG"), - BLUE_BANNER(11, "BANNER", "STANDING_BANNER"), - BLUE_BED(4, "BED", "BED_BLOCK"), + BLUE_BANNER(4, "BANNER", "STANDING_BANNER"), + BLUE_BED(11, "BED_BLOCK", "BED"), BLUE_CARPET(11, "CARPET"), BLUE_CONCRETE(11, "CONCRETE"), BLUE_CONCRETE_POWDER(11, "CONCRETE_POWDER"), @@ -166,8 +171,8 @@ public enum XMaterial { BLUE_SHULKER_BOX, BLUE_STAINED_GLASS(11, "STAINED_GLASS"), BLUE_STAINED_GLASS_PANE(11, "THIN_GLASS", "STAINED_GLASS_PANE"), - BLUE_TERRACOTTA(11, "STAINED_CLAY"), - BLUE_WALL_BANNER(11, "WALL_BANNER"), + BLUE_TERRACOTTA(11, "HARD_CLAY", "STAINED_CLAY"), + BLUE_WALL_BANNER(4, "WALL_BANNER"), BLUE_WOOL(11, "WOOL"), BONE, BONE_BLOCK, @@ -188,7 +193,7 @@ public enum XMaterial { BRICK_STAIRS, BRICK_WALL, BROWN_BANNER(3, "BANNER", "STANDING_BANNER"), - BROWN_BED(12, "BED", "BED_BLOCK"), + BROWN_BED(12, "BED_BLOCK", "BED"), BROWN_CARPET(12, "CARPET"), BROWN_CONCRETE(12, "CONCRETE"), BROWN_CONCRETE_POWDER(12, "CONCRETE_POWDER"), @@ -225,6 +230,7 @@ public enum XMaterial { */ CAVE_AIR("AIR"), CAVE_SPIDER_SPAWN_EGG(59, "MONSTER_EGG"), + CHAIN("1.16"), CHAINMAIL_BOOTS, CHAINMAIL_CHESTPLATE, CHAINMAIL_HELMET, @@ -236,6 +242,8 @@ public enum XMaterial { CHICKEN("RAW_CHICKEN"), CHICKEN_SPAWN_EGG(93, "MONSTER_EGG"), CHIPPED_ANVIL(1, "ANVIL"), + CHISELED_NETHER_BRICKS(1, "NETHER_BRICKS"), + CHISELED_POLISHED_BLACKSTONE("1.16", "POLISHED_BLACKSTONE"), CHISELED_QUARTZ_BLOCK(1, "QUARTZ_BLOCK"), CHISELED_RED_SANDSTONE(1, "RED_SANDSTONE"), CHISELED_SANDSTONE(1, "SANDSTONE"), @@ -262,7 +270,14 @@ public enum XMaterial { COD_SPAWN_EGG("1.13", "MONSTER_EGG", ""), COMMAND_BLOCK("COMMAND"), COMMAND_BLOCK_MINECART("COMMAND_MINECART"), - COMPARATOR("REDSTONE_COMPARATOR", "REDSTONE_COMPARATOR_ON", "REDSTONE_COMPARATOR_OFF"), + /** + * Unlike redstone torch and redstone lamp... neither REDTONE_COMPARATOR_OFF nor REDSTONE_COMPARATOR_ON + * are items. REDSTONE_COMPARATOR is. + * + * @see #REDSTONE_TORCH + * @see #REDSTONE_LAMP + */ + COMPARATOR("REDSTONE_COMPARATOR_OFF", "REDSTONE_COMPARATOR_ON", "REDSTONE_COMPARATOR"), COMPASS, COMPOSTER("1.14", "CAULDRON", ""), CONDUIT("1.13", "BEACON"), @@ -276,19 +291,38 @@ public enum XMaterial { COOKIE, CORNFLOWER(4, "1.14", "BLUE_DYE", ""), COW_SPAWN_EGG(92, "MONSTER_EGG"), + CRACKED_NETHER_BRICKS(2, "NETHER_BRICKS"), + CRACKED_POLISHED_BLACKSTONE_BRICKS("1.16", "POLISHED_BLACKSTONE_BRICKS"), CRACKED_STONE_BRICKS(2, "SMOOTH_BRICK"), CRAFTING_TABLE("WORKBENCH"), CREEPER_BANNER_PATTERN, CREEPER_HEAD(4, "SKULL", "SKULL_ITEM"), CREEPER_SPAWN_EGG(50, "MONSTER_EGG"), CREEPER_WALL_HEAD(4, "SKULL", "SKULL_ITEM"), + CRIMSON_BUTTON("1.16"), + CRIMSON_DOOR("1.16"), + CRIMSON_FENCE("1.16"), + CRIMSON_FENCE_GATE("1.16"), + CRIMSON_FUNGUS("1.16"), + CRIMSON_HYPHAE("1.16"), + CRIMSON_NYLIUM("1.16"), + CRIMSON_PLANKS("1.16"), + CRIMSON_PRESSURE_PLATE("1.16"), + CRIMSON_ROOTS("1.16"), + CRIMSON_SIGN("1.16"), + CRIMSON_SLAB("1.16"), + CRIMSON_STAIRS("1.16"), + CRIMSON_STEM("1.16"), + CRIMSON_TRAPDOOR("1.16"), + CRIMSON_WALL_SIGN("1.16"), CROSSBOW, + CRYING_OBSIDIAN("1.16"), CUT_RED_SANDSTONE("1.13"), CUT_RED_SANDSTONE_SLAB("STONE_SLAB2"), CUT_SANDSTONE("1.13"), CUT_SANDSTONE_SLAB("STEP"), CYAN_BANNER(6, "BANNER", "STANDING_BANNER"), - CYAN_BED(9, "BED", "BED_BLOCK"), + CYAN_BED(9, "BED_BLOCK", "BED"), CYAN_CARPET(9, "CARPET"), CYAN_CONCRETE(9, "CONCRETE"), CYAN_CONCRETE_POWDER(9, "CONCRETE_POWDER"), @@ -304,16 +338,16 @@ public enum XMaterial { DANDELION("YELLOW_FLOWER"), DARK_OAK_BOAT("BOAT_DARK_OAK"), DARK_OAK_BUTTON("WOOD_BUTTON"), - DARK_OAK_DOOR("DARK_OAK_DOOR_ITEM"), + DARK_OAK_DOOR("DARK_OAK_DOOR_ITEM", "DARK_OAK_DOOR"), DARK_OAK_FENCE, DARK_OAK_FENCE_GATE, - DARK_OAK_LEAVES(1, "LEAVES", "LEAVES_2"), + DARK_OAK_LEAVES(4, "LEAVES", "LEAVES_2"), DARK_OAK_LOG(1, "LOG", "LOG_2"), DARK_OAK_PLANKS(5, "WOOD"), DARK_OAK_PRESSURE_PLATE("WOOD_PLATE"), DARK_OAK_SAPLING(5, "SAPLING"), DARK_OAK_SIGN("SIGN"), - DARK_OAK_SLAB("WOOD_STEP", "WOODEN_SLAB", "WOOD_DOUBLE_STEP"), + DARK_OAK_SLAB(5, "WOOD_STEP", "WOODEN_SLAB", "WOOD_DOUBLE_STEP"), DARK_OAK_STAIRS, DARK_OAK_TRAPDOOR("TRAP_DOOR"), DARK_OAK_WALL_SIGN("SIGN_POST", "WALL_SIGN"), @@ -395,7 +429,7 @@ public enum XMaterial { END_ROD("1.9", "BLAZE_ROD", ""), END_STONE("ENDER_STONE"), END_STONE_BRICKS("END_BRICKS"), - END_STONE_BRICK_SLAB(4, "STEP"), + END_STONE_BRICK_SLAB(6, "STEP"), END_STONE_BRICK_STAIRS("SMOOTH_STAIRS"), END_STONE_BRICK_WALL, EVOKER_SPAWN_EGG(34, "MONSTER_EGG"), @@ -403,7 +437,12 @@ public enum XMaterial { FARMLAND("SOIL"), FEATHER, FERMENTED_SPIDER_EYE, - FERN(2, "LONG_GRASS"), + FERN(1, "LONG_GRASS"), + /** + * For some reasons filled map items are really special. + * Their data value starts from 0 and every time a player + * creates a new map that maps data value increases. + */ FILLED_MAP("MAP"), FIRE, FIREWORK_ROCKET("FIREWORK"), @@ -460,7 +499,7 @@ public enum XMaterial { GRASS_PATH, GRAVEL, GRAY_BANNER(8, "BANNER", "STANDING_BANNER"), - GRAY_BED(7, "BED", "BED_BLOCK"), + GRAY_BED(7, "BED_BLOCK", "BED"), GRAY_CARPET(7, "CARPET"), GRAY_CONCRETE(7, "CONCRETE"), GRAY_CONCRETE_POWDER(7, "CONCRETE_POWDER"), @@ -473,7 +512,7 @@ public enum XMaterial { GRAY_WALL_BANNER(8, "WALL_BANNER"), GRAY_WOOL(7, "WOOL"), GREEN_BANNER(2, "BANNER", "STANDING_BANNER"), - GREEN_BED(13, "BED", "BED_BLOCK"), + GREEN_BED(13, "BED_BLOCK", "BED"), GREEN_CARPET(13, "CARPET"), GREEN_CONCRETE(13, "CONCRETE"), GREEN_CONCRETE_POWDER(13, "CONCRETE_POWDER"), @@ -491,6 +530,7 @@ public enum XMaterial { HAY_BLOCK, HEART_OF_THE_SEA("1.13"), HEAVY_WEIGHTED_PRESSURE_PLATE("IRON_PLATE"), + HOGLIN_SPAWN_EGG("1.16", "MONSTER_EGG"), HONEYCOMB("1.15"), HONEYCOMB_BLOCK("1.15"), HONEY_BLOCK("1.15", "SLIME_BLOCK", ""), @@ -534,7 +574,7 @@ public enum XMaterial { JUKEBOX, JUNGLE_BOAT("BOAT_JUNGLE"), JUNGLE_BUTTON("WOOD_BUTTON"), - JUNGLE_DOOR("JUNGLE_DOOR_ITEM"), + JUNGLE_DOOR("JUNGLE_DOOR_ITEM", "JUNGLE_DOOR"), JUNGLE_FENCE, JUNGLE_FENCE_GATE, JUNGLE_LEAVES(3, "LEAVES"), @@ -568,8 +608,8 @@ public enum XMaterial { LEATHER_LEGGINGS, LECTERN("1.14", "BOOKSHELF", ""), LEVER, - LIGHT_BLUE_BANNER(3, "BANNER", "STANDING_BANNER"), - LIGHT_BLUE_BED(3, "BED", "BED_BLOCK"), + LIGHT_BLUE_BANNER(12, "BANNER", "STANDING_BANNER"), + LIGHT_BLUE_BED(3, "BED_BLOCK", "BED"), LIGHT_BLUE_CARPET(3, "CARPET"), LIGHT_BLUE_CONCRETE(3, "CONCRETE"), LIGHT_BLUE_CONCRETE_POWDER(3, "CONCRETE_POWDER"), @@ -582,16 +622,16 @@ public enum XMaterial { LIGHT_BLUE_WALL_BANNER(12, "WALL_BANNER", "BANNER", "STANDING_BANNER"), LIGHT_BLUE_WOOL(3, "WOOL"), LIGHT_GRAY_BANNER(7, "BANNER", "STANDING_BANNER"), - LIGHT_GRAY_BED(8, "BED", "BED_BLOCK"), + LIGHT_GRAY_BED(8, "BED_BLOCK", "BED"), LIGHT_GRAY_CARPET(8, "CARPET"), LIGHT_GRAY_CONCRETE(8, "CONCRETE"), LIGHT_GRAY_CONCRETE_POWDER(8, "CONCRETE_POWDER"), LIGHT_GRAY_DYE(7, "INK_SACK"), /** - * Renamed to SILVER_GLAZED_TERRACOTTA in 1.13 + * Renamed to SILVER_GLAZED_TERRACOTTA in 1.12 * Renamed to LIGHT_GRAY_GLAZED_TERRACOTTA in 1.14 */ - LIGHT_GRAY_GLAZED_TERRACOTTA(8, "1.12", "HARD_CLAY", "STAINED_CLAY", "LIGHT_GRAY_TERRACOTTA", "SILVER_GLAZED_TERRACOTTA"), + LIGHT_GRAY_GLAZED_TERRACOTTA("1.12", "HARD_CLAY", "STAINED_CLAY", "LIGHT_GRAY_TERRACOTTA", "SILVER_GLAZED_TERRACOTTA"), LIGHT_GRAY_SHULKER_BOX("SILVER_SHULKER_BOX"), LIGHT_GRAY_STAINED_GLASS(8, "STAINED_GLASS"), LIGHT_GRAY_STAINED_GLASS_PANE(8, "THIN_GLASS", "STAINED_GLASS_PANE"), @@ -603,7 +643,7 @@ public enum XMaterial { LILY_OF_THE_VALLEY(15, "1.14", "WHITE_DYE", ""), LILY_PAD("WATER_LILY"), LIME_BANNER(10, "BANNER", "STANDING_BANNER"), - LIME_BED(5, "BED", "BED_BLOCK"), + LIME_BED(5, "BED_BLOCK", "BED"), LIME_CARPET(5, "CARPET"), LIME_CONCRETE(5, "CONCRETE"), LIME_CONCRETE_POWDER(5, "CONCRETE_POWDER"), @@ -617,9 +657,10 @@ public enum XMaterial { LIME_WOOL(5, "WOOL"), LINGERING_POTION, LLAMA_SPAWN_EGG(103, "MONSTER_EGG"), + LODESTONE("1.16"), LOOM("1.14"), MAGENTA_BANNER(13, "BANNER", "STANDING_BANNER"), - MAGENTA_BED(2, "BED", "BED_BLOCK"), + MAGENTA_BED(2, "BED_BLOCK", "BED"), MAGENTA_CARPET(2, "CARPET"), MAGENTA_CONCRETE(2, "CONCRETE"), MAGENTA_CONCRETE_POWDER(2, "CONCRETE_POWDER"), @@ -634,6 +675,13 @@ public enum XMaterial { MAGMA_BLOCK("1.10", "MAGMA"), MAGMA_CREAM, MAGMA_CUBE_SPAWN_EGG(62, "MONSTER_EGG"), + /** + * Adding this to the duplicated list will give you a filled map + * for 1.13+ versions and removing it from duplicated list will + * still give you a filled map in -1.12 versions. + * Since higher versions are our priority I'll keep 1.13+ support + * until I can come up with something to fix it. + */ MAP("EMPTY_MAP"), MELON("MELON_BLOCK"), MELON_SEEDS, @@ -648,7 +696,7 @@ public enum XMaterial { MOSSY_COBBLESTONE_STAIRS, MOSSY_COBBLESTONE_WALL(1, "COBBLE_WALL", "COBBLESTONE_WALL"), MOSSY_STONE_BRICKS(1, "SMOOTH_BRICK"), - MOSSY_STONE_BRICK_SLAB(4, "STEP"), + MOSSY_STONE_BRICK_SLAB(5, "STEP"), MOSSY_STONE_BRICK_STAIRS("SMOOTH_STAIRS"), MOSSY_STONE_BRICK_WALL, MOVING_PISTON("PISTON_BASE", "PISTON_MOVING_PIECE"), @@ -671,15 +719,29 @@ public enum XMaterial { MYCELIUM("MYCEL"), NAME_TAG, NAUTILUS_SHELL("1.13"), + NETHERITE_AXE("1.16"), + NETHERITE_BLOCK("1.16"), + NETHERITE_BOOTS("1.16"), + NETHERITE_CHESTPLATE("1.16"), + NETHERITE_HELMET("1.16"), + NETHERITE_HOE("1.16"), + NETHERITE_INGOT("1.16"), + NETHERITE_LEGGINGS("1.16"), + NETHERITE_PICKAXE("1.16"), + NETHERITE_SCRAP("1.16"), + NETHERITE_SHOVEL("1.16"), + NETHERITE_SWORD("1.16"), NETHERRACK, NETHER_BRICK("NETHER_BRICK_ITEM"), NETHER_BRICKS("NETHER_BRICK"), NETHER_BRICK_FENCE("NETHER_FENCE"), - NETHER_BRICK_SLAB(4, "STEP"), + NETHER_BRICK_SLAB(6, "STEP"), NETHER_BRICK_STAIRS, NETHER_BRICK_WALL, + NETHER_GOLD_ORE("1.16"), NETHER_PORTAL("PORTAL"), NETHER_QUARTZ_ORE("QUARTZ_ORE"), + NETHER_SPROUTS("1.16"), NETHER_STAR, /** * Just like mentioned in https://minecraft.gamepedia.com/Nether_Wart @@ -709,7 +771,7 @@ public enum XMaterial { OBSIDIAN, OCELOT_SPAWN_EGG(98, "MONSTER_EGG"), ORANGE_BANNER(14, "BANNER", "STANDING_BANNER"), - ORANGE_BED(1, "BED", "BED_BLOCK"), + ORANGE_BED(1, "BED_BLOCK", "BED"), ORANGE_CARPET(1, "CARPET"), ORANGE_CONCRETE(1, "CONCRETE"), ORANGE_CONCRETE_POWDER(1, "CONCRETE_POWDER"), @@ -735,7 +797,7 @@ public enum XMaterial { PIG_SPAWN_EGG(90, "MONSTER_EGG"), PILLAGER_SPAWN_EGG("1.14"), PINK_BANNER(9, "BANNER", "STANDING_BANNER"), - PINK_BED(6, "BED", "BED_BLOCK"), + PINK_BED(6, "BED_BLOCK", "BED"), PINK_CARPET(6, "CARPET"), PINK_CONCRETE(6, "CONCRETE"), PINK_CONCRETE_POWDER(6, "CONCRETE_POWDER"), @@ -746,7 +808,7 @@ public enum XMaterial { PINK_STAINED_GLASS_PANE(6, "THIN_GLASS", "STAINED_GLASS_PANE"), PINK_TERRACOTTA(6, "HARD_CLAY", "STAINED_CLAY"), PINK_TULIP(7, "RED_ROSE"), - PINK_WALL_BANNER(14, "WALL_BANNER"), + PINK_WALL_BANNER(9, "WALL_BANNER"), PINK_WOOL(6, "WOOL"), PISTON("PISTON_BASE"), PISTON_HEAD("PISTON_EXTENSION"), @@ -758,6 +820,17 @@ public enum XMaterial { POLISHED_ANDESITE(6, "STONE"), POLISHED_ANDESITE_SLAB, POLISHED_ANDESITE_STAIRS, + POLISHED_BASALT("1.16"), + POLISHED_BLACKSTONE("1.16"), + POLISHED_BLACKSTONE_BRICKS("1.16"), + POLISHED_BLACKSTONE_BRICK_SLAB("1.16"), + POLISHED_BLACKSTONE_BRICK_STAIRS("1.16"), + POLISHED_BLACKSTONE_BRICK_WALL("1.16"), + POLISHED_BLACKSTONE_BUTTON("1.16"), + POLISHED_BLACKSTONE_PRESSURE_PLATE("1.16"), + POLISHED_BLACKSTONE_SLAB("1.16"), + POLISHED_BLACKSTONE_STAIRS("1.16"), + POLISHED_BLACKSTONE_WALL("1.16"), POLISHED_DIORITE(4, "STONE"), POLISHED_DIORITE_SLAB, POLISHED_DIORITE_STAIRS, @@ -813,7 +886,7 @@ public enum XMaterial { PUMPKIN_SEEDS, PUMPKIN_STEM, PURPLE_BANNER(5, "BANNER", "STANDING_BANNER"), - PURPLE_BED(10, "BED", "BED_BLOCK"), + PURPLE_BED(10, "BED_BLOCK", "BED"), PURPLE_CARPET(10, "CARPET"), PURPLE_CONCRETE(10, "CONCRETE"), PURPLE_CONCRETE_POWDER(10, "CONCRETE_POWDER"), @@ -843,17 +916,34 @@ public enum XMaterial { RAVAGER_SPAWN_EGG("1.14"), REDSTONE, REDSTONE_BLOCK, - REDSTONE_LAMP("REDSTONE_LAMP_OFF", "REDSTONE_LAMP_ON"), + /** + * Unlike redstone torch, REDSTONE_LAMP_ON isn't an item. + * The name is just here on the list for matching. + * + * @see #REDSTONE_TORCH + */ + REDSTONE_LAMP("REDSTONE_LAMP_ON", "REDSTONE_LAMP_OFF"), REDSTONE_ORE("GLOWING_REDSTONE_ORE"), - REDSTONE_TORCH("REDSTONE_TORCH_ON", "REDSTONE_TORCH_OFF"), - REDSTONE_WALL_TORCH(1, "REDSTONE_TORCH_ON", "REDSTONE_TORCH_OFF"), + /** + * REDSTONE_TORCH_OFF isn't an item, but a block. + * But REDSTONE_TORCH_ON is the item. + * The name is just here on the list for matching. + */ + REDSTONE_TORCH("REDSTONE_TORCH_OFF", "REDSTONE_TORCH_ON"), + REDSTONE_WALL_TORCH, REDSTONE_WIRE, RED_BANNER(1, "BANNER", "STANDING_BANNER"), - RED_BED(14, "BED", "BED_BLOCK"), + /** + * Data value 14 or 0 + */ + RED_BED(0, "BED_BLOCK", "BED"), RED_CARPET(14, "CARPET"), RED_CONCRETE(14, "CONCRETE"), RED_CONCRETE_POWDER(14, "CONCRETE_POWDER"), - RED_DYE(1, "ROSE_RED"), + /** + * Data value 0 or 1? + */ + RED_DYE(0, "INK_SACK", "ROSE_RED"), RED_GLAZED_TERRACOTTA(14, "1.12", "HARD_CLAY", "STAINED_CLAY", "RED_TERRACOTTA"), RED_MUSHROOM, RED_MUSHROOM_BLOCK("RED_MUSHROOM", "HUGE_MUSHROOM_2"), @@ -875,6 +965,7 @@ public enum XMaterial { RED_WOOL(14, "WOOL"), REPEATER("DIODE", "DIODE_BLOCK_ON", "DIODE_BLOCK_OFF"), REPEATING_COMMAND_BLOCK("COMMAND", "COMMAND_REPEATING"), + RESPAWN_ANCHOR("1.16"), ROSE_BUSH(4, "DOUBLE_PLANT"), ROTTEN_FLESH, SADDLE, @@ -894,6 +985,7 @@ public enum XMaterial { SHEARS, SHEEP_SPAWN_EGG(91, "MONSTER_EGG"), SHIELD, + SHROOMLIGHT("1.16"), SHULKER_BOX("PURPLE_SHULKER_BOX"), SHULKER_SHELL, SHULKER_SPAWN_EGG(69, "MONSTER_EGG"), @@ -922,7 +1014,13 @@ public enum XMaterial { SNOW, SNOWBALL("SNOW_BALL"), SNOW_BLOCK, + SOUL_CAMPFIRE("1.16"), + SOUL_FIRE("1.16"), + SOUL_LANTERN("1.16"), SOUL_SAND, + SOUL_SOIL("1.16"), + SOUL_TORCH("1.16"), + SOUL_WALL_TORCH("1.16"), SPAWNER("MOB_SPAWNER"), SPECTRAL_ARROW("1.9", "ARROW", ""), SPIDER_EYE, @@ -931,7 +1029,7 @@ public enum XMaterial { SPONGE, SPRUCE_BOAT("BOAT_SPRUCE"), SPRUCE_BUTTON("WOOD_BUTTON"), - SPRUCE_DOOR("SPRUCE_DOOR_ITEM"), + SPRUCE_DOOR("SPRUCE_DOOR_ITEM", "SPRUCE_DOOR"), SPRUCE_FENCE, SPRUCE_FENCE_GATE, SPRUCE_LEAVES(1, "LEAVES"), @@ -969,6 +1067,8 @@ public enum XMaterial { STRIPPED_ACACIA_WOOD("LOG_2"), STRIPPED_BIRCH_LOG(2, "LOG"), STRIPPED_BIRCH_WOOD(2, "LOG"), + STRIPPED_CRIMSON_HYPHAE("1.16"), + STRIPPED_CRIMSON_STEM("1.16"), STRIPPED_DARK_OAK_LOG("LOG"), STRIPPED_DARK_OAK_WOOD("LOG"), STRIPPED_JUNGLE_LOG(3, "LOG"), @@ -977,6 +1077,8 @@ public enum XMaterial { STRIPPED_OAK_WOOD("LOG"), STRIPPED_SPRUCE_LOG(1, "LOG"), STRIPPED_SPRUCE_WOOD(1, "LOG"), + STRIPPED_WARPED_HYPHAE("1.16"), + STRIPPED_WARPED_STEM("1.16"), STRUCTURE_BLOCK, /** * Originally developers used barrier blocks for its purpose. @@ -995,6 +1097,7 @@ public enum XMaterial { SWEET_BERRY_BUSH("1.14", "GRASS", ""), TALL_GRASS(2, "DOUBLE_PLANT"), TALL_SEAGRASS(2, "1.13", "TALL_GRASS", ""), + TARGET("1.16"), TERRACOTTA("HARD_CLAY"), TIPPED_ARROW("1.9", "ARROW", ""), TNT, @@ -1016,6 +1119,8 @@ public enum XMaterial { TURTLE_EGG("1.13", "EGG", ""), TURTLE_HELMET("1.13", "IRON_HELMET", ""), TURTLE_SPAWN_EGG("1.13", "CHICKEN_SPAWN_EGG", ""), + TWISTING_VINES("1.16"), + TWISTING_VINES_PLANT("1.16"), VEX_SPAWN_EGG(35, "MONSTER_EGG"), VILLAGER_SPAWN_EGG(120, "MONSTER_EGG"), VINDICATOR_SPAWN_EGG(36, "MONSTER_EGG"), @@ -1028,6 +1133,24 @@ public enum XMaterial { VOID_AIR("AIR"), WALL_TORCH("TORCH"), WANDERING_TRADER_SPAWN_EGG("1.14", "VILLAGER_SPAWN_EGG", ""), + WARPED_BUTTON("1.16"), + WARPED_DOOR("1.16"), + WARPED_FENCE("1.16"), + WARPED_FENCE_GATE("1.16"), + WARPED_FUNGUS("1.16"), + WARPED_FUNGUS_ON_A_STICK("1.16"), + WARPED_HYPHAE("1.16"), + WARPED_NYLIUM("1.16"), + WARPED_PLANKS("1.16"), + WARPED_PRESSURE_PLATE("1.16"), + WARPED_ROOTS("1.16"), + WARPED_SIGN("1.16"), + WARPED_SLAB("1.16"), + WARPED_STAIRS("1.16"), + WARPED_STEM("1.16"), + WARPED_TRAPDOOR("1.16"), + WARPED_WALL_SIGN("1.16"), + WARPED_WART_BLOCK("1.16"), /** * This is used for blocks only. * In 1.13- WATER will turn into STATIONARY_WATER after it finished spreading. @@ -1037,6 +1160,8 @@ public enum XMaterial { */ WATER("STATIONARY_WATER"), WATER_BUCKET, + WEEPING_VINES("1.16"), + WEEPING_VINES_PLANT("1.16"), WET_SPONGE(1, "SPONGE"), /** * Wheat is a known material in pre-1.13 @@ -1045,16 +1170,16 @@ public enum XMaterial { WHEAT("CROPS"), WHEAT_SEEDS("SEEDS"), WHITE_BANNER(15, "BANNER", "STANDING_BANNER"), - WHITE_BED("BED", "BED_BLOCK"), + WHITE_BED("BED_BLOCK", "BED"), WHITE_CARPET("CARPET"), WHITE_CONCRETE("CONCRETE"), WHITE_CONCRETE_POWDER("CONCRETE_POWDER"), WHITE_DYE(15, "1.14", "INK_SACK", "BONE_MEAL"), - WHITE_GLAZED_TERRACOTTA("1.12", "HARD_CLAY", "STAINED_CLAY", "WHITE_TERRACOTTA"), + WHITE_GLAZED_TERRACOTTA("1.12", "HARD_CLAY", "STAINED_CLAY"), WHITE_SHULKER_BOX, WHITE_STAINED_GLASS("STAINED_GLASS"), WHITE_STAINED_GLASS_PANE("THIN_GLASS", "STAINED_GLASS_PANE"), - WHITE_TERRACOTTA("HARD_CLAY", "TERRACOTTA"), + WHITE_TERRACOTTA("HARD_CLAY", "STAINED_CLAY", "TERRACOTTA"), WHITE_TULIP(6, "RED_ROSE"), WHITE_WALL_BANNER(15, "WALL_BANNER"), WHITE_WOOL("WOOL"), @@ -1072,7 +1197,7 @@ public enum XMaterial { WRITABLE_BOOK("BOOK_AND_QUILL"), WRITTEN_BOOK, YELLOW_BANNER(11, "BANNER", "STANDING_BANNER"), - YELLOW_BED(4, "BED", "BED_BLOCK"), + YELLOW_BED(4, "BED_BLOCK", "BED"), YELLOW_CARPET(4, "CARPET"), YELLOW_CONCRETE(4, "CONCRETE"), YELLOW_CONCRETE_POWDER(4, "CONCRETE_POWDER"), @@ -1086,10 +1211,11 @@ public enum XMaterial { YELLOW_WOOL(4, "WOOL"), ZOMBIE_HEAD(2, "SKULL", "SKULL_ITEM"), ZOMBIE_HORSE_SPAWN_EGG(29, "MONSTER_EGG"), - ZOMBIE_PIGMAN_SPAWN_EGG(57, "MONSTER_EGG"), ZOMBIE_SPAWN_EGG(54, "MONSTER_EGG"), ZOMBIE_VILLAGER_SPAWN_EGG(27, "MONSTER_EGG"), - ZOMBIE_WALL_HEAD(2, "SKULL", "SKULL_ITEM"); + ZOMBIE_WALL_HEAD(2, "SKULL", "SKULL_ITEM"), + PIGLIN_SPAWN_EGG(57, "MONSTER_EGG"), + ZOMBIFIED_PIGLIN_SPAWN_EGG(57, "MONSTER_EGG", "ZOMBIE_PIGMAN_SPAWN_EGG"); /** @@ -1124,16 +1250,28 @@ public enum XMaterial { * * @since 3.0.0 */ - private static final ImmutableMap DUPLICATED = Maps.immutableEnumMap(ImmutableMap.builder() + @SuppressWarnings("UnstableApiUsage") + private static final ImmutableMap duplicated = Maps.immutableEnumMap(ImmutableMap.builder() .put(MELON, MELON_SLICE) .put(CARROT, CARROTS) .put(POTATO, POTATOES) .put(BEETROOT, BEETROOTS) .put(BROWN_MUSHROOM, BROWN_MUSHROOM_BLOCK) .put(BRICK, BRICKS) - .put(RED_MUSHROOM, RED_MUSHROOM_BLOCK) - .put(MAP, FILLED_MAP) .put(NETHER_BRICK, NETHER_BRICKS) + + // Illegal Elements + // Since both 1.12 and 1.13 have _DOOR XMaterial will use it + // for 1.12 to parse the material, but it needs _DOOR_ITEM. + // We'll trick XMaterial into thinking this needs to be parsed + // using the old methods. + // These materials have their enum name added to the legacy list as well. + .put(DARK_OAK_DOOR, DARK_OAK_DOOR) + .put(ACACIA_DOOR, ACACIA_DOOR) + .put(BIRCH_DOOR, BIRCH_DOOR) + .put(JUNGLE_DOOR, JUNGLE_DOOR) + .put(SPRUCE_DOOR, SPRUCE_DOOR) + .build() ); /* @@ -1275,13 +1413,14 @@ public enum XMaterial { @Nullable private static XMaterial requestOldXMaterial(@Nonnull String name, byte data) { String holder = name + data; - XMaterial material = NAME_CACHE.getIfPresent(holder); - if (material != null) return material; + XMaterial cache = NAME_CACHE.getIfPresent(holder); + if (cache != null) return cache; - for (XMaterial materials : VALUES) { - if ((data == -1 || data == materials.data) && materials.anyMatchLegacy(name)) { - NAME_CACHE.put(holder, materials); - return materials; + for (XMaterial material : VALUES) { + // Not using material.name().equals(name) check is intended. + if ((data == -1 || data == material.data) && material.anyMatchLegacy(name)) { + NAME_CACHE.put(holder, material); + return material; } } @@ -1312,37 +1451,15 @@ public enum XMaterial { /** * Parses the given material name as an XMaterial with unspecified data value. * - * @see #matchXMaterial(String, byte) + * @see #matchXMaterialWithData(String) * @since 2.0.0 */ @Nonnull public static Optional matchXMaterial(@Nonnull String name) { - return matchXMaterial(name, (byte) -1); - } - - /** - * Parses the given material name as an XMaterial. - * Can also be used like: MATERIAL:DATA - *

- * Examples - *

-     *     {@code INK_SACK:1 -> RED_DYE}
-     *     {@code WOOL, 14  -> RED_WOOL}
-     * 
- * - * @see #matchDefinedXMaterial(String, byte) - * @see #matchXMaterial(ItemStack) - * @since 2.0.0 - */ - @Nonnull - public static Optional matchXMaterial(@Nonnull String name, byte data) { Validate.notEmpty(name, "Cannot match a material with null or empty material name"); Optional oldMatch = matchXMaterialWithData(name); if (oldMatch.isPresent()) return oldMatch; - - // -1 Determines whether the item's data value is unknown and only the name is given. - // Checking if the item is damageable won't do anything as the data is not going to be checked in requestOldMaterial anyway. - return matchDefinedXMaterial(format(name), data); + return matchDefinedXMaterial(format(name), (byte) -1); } /** @@ -1386,7 +1503,7 @@ public enum XMaterial { public static XMaterial matchXMaterial(@Nonnull Material material) { Objects.requireNonNull(material, "Cannot match null material"); return matchDefinedXMaterial(material.name(), (byte) -1) - .orElseThrow(() -> new IllegalArgumentException("Unsupported Material: " + material)); + .orElseThrow(() -> new IllegalArgumentException("Unsupported Material With No Bytes: " + material.name())); } /** @@ -1403,9 +1520,10 @@ public enum XMaterial { public static XMaterial matchXMaterial(@Nonnull ItemStack item) { Objects.requireNonNull(item, "Cannot match null ItemStack"); String material = item.getType().name(); - return matchDefinedXMaterial(material, - isDamageable(material) ? (byte) 0 : (byte) item.getDurability()) - .orElseThrow(() -> new IllegalArgumentException("Unsupported Material: " + material)); + byte data = (byte) (ISFLAT || isDamageable(material) ? 0 : item.getDurability()); + + return matchDefinedXMaterial(material, data) + .orElseThrow(() -> new IllegalArgumentException("Unsupported Material: " + material + " (" + data + ')')); } /** @@ -1415,7 +1533,6 @@ public enum XMaterial { * @param name the formatted name of the material. * @param data the data value of the material. * @return an XMaterial (with the same data value if specified) - * @see #matchXMaterial(String, byte) * @see #matchXMaterial(Material) * @see #matchXMaterial(int, byte) * @see #matchXMaterial(ItemStack) @@ -1428,7 +1545,7 @@ public enum XMaterial { // Do basic number and boolean checks before accessing more complex enum stuff. // Maybe we can simplify (ISFLAT || !duplicated) with the (!ISFLAT && duplicated) under it to save a few nanoseconds? // if (!Boolean.valueOf(Boolean.getBoolean(Boolean.TRUE.toString())).equals(Boolean.FALSE.booleanValue())) return null; - if (data <= 0 && (ISFLAT || !duplicated)) { + if (data <= 0 && !duplicated) { // Apparently the transform method is more efficient than toJavaUtil() // toJavaUtil isn't even supported in older versions. Optional xMat = Enums.getIfPresent(XMaterial.class, name).transform(Optional::of).or(Optional.empty()); @@ -1439,8 +1556,20 @@ public enum XMaterial { // I've concluded that this is just an infinite loop that keeps // going around the Singular Form and the Plural Form materials. A waste of brain cells and a waste of time. // This solution works just fine anyway. - if (!ISFLAT && duplicated) return Optional.ofNullable(requestDuplicatedXMaterial(name, data)); - return Optional.ofNullable(requestOldXMaterial(name, data)); + XMaterial xMat = requestOldXMaterial(name, data); + if (xMat == null) { + // Special case. Refer to FILLED_MAP for more info. + if (data > 0 && name.endsWith("MAP")) return Optional.of(FILLED_MAP); + return Optional.empty(); + } + + if (!ISFLAT && duplicated && xMat.name().charAt(xMat.name().length() - 1) == 'S') { + // A solution for XMaterial Paradox. + // Manually parses the duplicated materials to find the exact material based on the server version. + // If ends with "S" -> Plural Form Material + return Enums.getIfPresent(XMaterial.class, name).transform(Optional::of).or(Optional.empty()); + } + return Optional.ofNullable(xMat); } /** @@ -1455,13 +1584,12 @@ public enum XMaterial { * @see #isDuplicated() * @since 2.0.0 */ - public static boolean isDuplicated(@Nonnull String name) { - Validate.notEmpty(name, "Cannot check duplication for null or empty material name"); - name = format(name); - + private static boolean isDuplicated(@Nonnull String name) { // Don't use matchXMaterial() since this method is being called from matchXMaterial() itself and will cause a StackOverflowError. - for (Map.Entry duplicated : DUPLICATED.entrySet()) - if (duplicated.getKey().name().equals(name) || duplicated.getKey().anyMatchLegacy(name)) return true; + for (Map.Entry duplicated : duplicated.entrySet()) { + XMaterial material = duplicated.getKey(); + if (material.name().equals(name) || material.anyMatchLegacy(name)) return true; + } return false; } @@ -1485,60 +1613,6 @@ public enum XMaterial { return Optional.empty(); } - /** - * A solution for XMaterial Paradox. - * Manually parses the duplicated materials to find the exact material based on the server version. - * - * @param name the name of the material. - * @return the duplicated XMaterial based on the version. - * @throws IllegalArgumentException may be thrown. If thrown, it's a bug. - * @since 2.0.0 - */ - @Nullable - private static XMaterial requestDuplicatedXMaterial(@Nonnull String name, byte data) { - XMaterial mat = requestOldXMaterial(name, data); - // If ends with "S" -> Plural Form Material - return mat.name().charAt(mat.name().length() - 1) == 'S' ? Enums.getIfPresent(XMaterial.class, name).orNull() : mat; - } - - /** - * Always returns the value with the given duplicated material key name. - * - * @param name the name of the material. - * @return the new XMaterial of this duplicated material. - * @see #getXMaterialIfDuplicated(String) - * @since 2.0.0 - */ - @Nonnull - public static Optional getNewXMaterialIfDuplicated(@Nonnull String name) { - Validate.notEmpty(name, "Cannot get new duplicated material for null or empty material name"); - name = format(name); - - for (Map.Entry duplicated : DUPLICATED.entrySet()) - if (duplicated.getKey().name().equals(name)) return Optional.of(duplicated.getKey()); - return Optional.empty(); - } - - /** - * Checks if the item is duplicated for a different purpose in new versions from {@link #DUPLICATED}. - * - * @param name the name of the material. - * @return the other XMaterial (key or value) of the XMaterial (key or value). - * @see #matchXMaterial(String, byte) - * @since 2.0.0 - */ - @Nullable - public static XMaterial getXMaterialIfDuplicated(@Nonnull String name) { - Validate.notEmpty(name, "Cannot get duplicated material for null or empty material name"); - name = format(name); - - for (Map.Entry duplicated : DUPLICATED.entrySet()) - if (duplicated.getKey().name().equals(name)) return duplicated.getValue(); - else if (duplicated.getValue().name().equals(name)) return duplicated.getKey(); - - return null; - } - /** * Attempts to build the string like an enum name. * Removes all the spaces, numbers and extra non-English characters. Also removes some config/in-game based strings. @@ -1804,25 +1878,11 @@ public enum XMaterial { * Checks if the material has any duplicates. * * @return true if there is a duplicated name for this material, otherwise false. - * @see #getXMaterialIfDuplicated() * @see #isDuplicated(String) * @since 2.0.0 */ public boolean isDuplicated() { - return DUPLICATED.containsKey(this); - } - - /** - * Checks if the item is duplicated for a different purpose in new versions. - * - * @return true if the item's name is duplicated, otherwise false. - * @see #isDuplicated() - * @see #getNewXMaterialIfDuplicated(String) - * @since 2.0.0 - */ - @Nullable - public XMaterial getXMaterialIfDuplicated() { - return DUPLICATED.get(this); + return duplicated.containsKey(this); } /** @@ -1846,6 +1906,7 @@ public enum XMaterial { * @return data of this material, or 0 if none. * @since 1.0.0 */ + @SuppressWarnings("deprecation") public byte getData() { return data; } @@ -1911,9 +1972,9 @@ public enum XMaterial { * * @param suggest use a suggested material (from older materials) if the material is added in a later version of Minecraft. * @return the material related to this XMaterial based on the server version. - * @see #matchXMaterial(String, byte) * @since 2.0.0 */ + @SuppressWarnings("OptionalAssignedToNull") @Nullable public Material parseMaterial(boolean suggest) { Optional cache = PARSED_CACHE.getIfPresent(this); @@ -2024,4 +2085,4 @@ public enum XMaterial { public boolean isFromNewSystem() { return this.legacy.length != 0 && Integer.parseInt(this.legacy[0].substring(2)) > 13; } -} +} \ No newline at end of file diff --git a/src/main/resources/checks.yml b/src/main/resources/checks.yml new file mode 100644 index 0000000..bc096d2 --- /dev/null +++ b/src/main/resources/checks.yml @@ -0,0 +1,192 @@ +# AntiCheatReloaded checks configuration file +# Speed check settings +speed: + # Checks movement speed in the air + # Debugs as 'moved too fast in air' + airSpeed: + # Should this part of the check be enabled? + enabled: true + # Base unadjusted air speed limit + baseLimit: 0.03125 + # Prediction multiplier for custom walk speeds + walkSpeedMultiplier: 1.4 + + # Checks movement acceleration in the air + # Debugs as 'exceeded acceleration limits' + airAcceleration: + # Should this part of the check be enabled? + enabled: true + # Base unadjusted air acceleration limit + baseLimit: 0.3725 + # Limit multiplier for custom walk speeds + walkSpeedMultiplier: 1.4 + + # Checks movement acceleration in the air + # Debugs as 'had unexpected jumping behaviour' + jumpBehaviour: + # Should this part of the check be enabled? + enabled: true + # Minimum movement distance needed to flag + minimumDistXZ: 0.42 + + # Checks movement speed on the ground + # Debugs as 'moved too fast on ground' + groundSpeed: + # Should this part of the check be enabled? + enabled: true + # Initial speed limit value + initialLimit: 0.34 + + # Checks movement acceleration in the air + # Debugs as 'exceeded vertical speed limit' + verticalSpeed: + # Should this part of the check be enabled? + enabled: true + # Extra compensation when moving off a ladder up a slab + climbableCompensation: 0.04 + +# Flight check settings +flight: + # Checks for gliding behaviour + # Debugs as 'had gliding behaviour' + glide: + # Should this part of the check be enabled? + enabled: true + # Amount of glide-like moves before flagging + vlBeforeFlag: 3 + # Checks for prolonged air movement + # Debugs as 'tried to fly on the Y-axis' or 'had too little Y dropoff' + airFlight: + # Should this part of the check be enabled? + enabled: true + # How many milliseconds to account for block placement + # Increase this if you get false positives when building a tower + accountForBlockPlacement: 1200 + # How many milliseconds to account for TPS drops + # Increase this if you get false positives when building a tower during TPS drops + accountForTpsDrops: 250 + # How many milliseconds to account for teleports + # Increase this is you debug 'had too little Y dropoff' after teleports + accountForTeleports: 50 + # Checks for climbing behaviour in air + # Debugs as 'tried to climb air' + airClimb: + # Should this part of the check be enabled? + enabled: true + # How many milliseconds to account for teleports + # Increase this is you debug 'tried to climb air' after teleports + accountForTeleports: 50 + # Checks if a player is faking it's ground status to fly + # Debugs as 'faked ground to fly' + groundFlight: + # Should this part of the check be enabled? + enabled: true + +# FastLadder check settings +fastladder: + # Should this check be enabled? + enabled: true + # Maximum speed a player on a ladder can travel + speedMax: 0.11761 + # Minimum speed a player on a ladder will travel + speedMin: 0.11759 + # Maximum speed a player on a ladder can travel downwards + speedDownMax: 0.15 + # Amount of illegal ladder moves before flagging + vlBeforeFlag: 3 + +# KillAura check settings +killaura: + # Checks reach distance in fights + # Debugs as 'reached too far' + reach: + # Should this part of the check be enabled? + enabled: true + # Maximum base reach distances + baseMaxValue: + # Maximum base reach value + normal: 3.6 + # Maximum base reach value when a player has velocity + velocitized: 4.0 + # Settings for lag compensation + lagCompensation: + # Basic extra allowed reach when a player is lagging + lagExtraReach: 0.2 + # Extra allowed reach distance per millisecond of ping + pingCompensation: 0.0025 + # The multiplier of extra compensation for velocity + velocityMultiplier: 1.2 + + # Checks if the target it within a players viewing angle + # Debugs as 'tried to attack from an illegal angle' + angle: + # Should this part of the check be enabled? + enabled: true + # Maximum difference in angle from the players view + maxDifference: 50 + # Amount of illegally angled hits before flagging + vlBeforeFlag: 3 + +# Aimbot check settings +aimbot: + # Should this check be enabled? + enabled: true + # Minimum yaw difference when repeated + minYaw: 30 + # Maximum yaw difference when repeated + maxYaw: 355 + +# Criticals check settings +criticals: + # Should this check be enabled? + enabled: true + +# Velocity check settings +velocity: + # Should this check be enabled? + enabled: true + # Minimum distance a player has to move after taking velocity + minVelocitizedDistance: 0.125 + # Amount of zero-velocity moments before flagging + vlBeforeFlag: 3 + +# IllegalInteract check settings +illegalinteract: + # Maximum difference in angle from the players view + maxAngleDifference: 80 + # Checks angle when breaking a block + # Debugs as 'tried to break a block which was out of view' + break: + # Should this part of the check be enabled? + enabled: true + # Checks angle when placing a block + # Debugs as 'tried to place a block which was out of view' + place: + # Should this part of the check be enabled? + enabled: true + +# BadPackets check settings +badpackets: + # Should this check be enabled? + enabled: true + # Minimum server TPS needed for BadPackets to be active + minimumTps: 17.5 + # Maximum distance a player can move between packets + maxDistance: 25.0 + +# MorePackets check settings +morepackets: + # Should this check be enabled? + enabled: true + # Minimum server TPS needed for MorePackets to be active + minimumTps: 17.5 + # Maximum amount of lag compensation a player can acquire (50ms = 1 tick) + minimumClamp: 500 + # The amount of milliseconds offset between packets before flagging (50ms = 1 tick) + triggerBalance: 100 + # Should MorePackets be disabled for 'lagging' players? + # This can easily be spoofed by clients! + disableForLagging: false + # Maximum ping value before MorePackets stops checking a player (-1 to disable) + # This can easily be spoofed by clients! + maxPing: -1 \ No newline at end of file diff --git a/src/main/resources/enterprise.yml b/src/main/resources/enterprise.yml index 1a9c809..bce2aa0 100644 --- a/src/main/resources/enterprise.yml +++ b/src/main/resources/enterprise.yml @@ -42,4 +42,4 @@ config: # Load magic configuration from the database? magic: false # Load language configuration from the database? - lang: false + lang: false \ No newline at end of file diff --git a/src/main/resources/groups.yml b/src/main/resources/groups.yml index f29a0e4..2e22ffb 100644 --- a/src/main/resources/groups.yml +++ b/src/main/resources/groups.yml @@ -1,5 +1,7 @@ # AntiCheatReloaded configuration file +# Options; WARN, KICK, COMMAND[your command here] or NONE +# To disable warnings or kicking, change WARN and/or KICK to NONE groups: - - 'Medium : 50 : YELLOW : WARN' - - 'High : 100 : RED : KICK' + - 'Medium : 75 : YELLOW : WARN' + - 'High : 150 : RED : KICK' - 'Custom : -1 : GREEN : COMMAND[ban %player%;]' diff --git a/src/main/resources/magic.yml b/src/main/resources/magic.yml index dbe1e56..500a1fa 100644 --- a/src/main/resources/magic.yml +++ b/src/main/resources/magic.yml @@ -4,12 +4,12 @@ ANIMATION_INTERACT_MAX: 3 # Minimum time between animations # Changing this value is almost never required ANIMATION_MIN: 200 -# Number of times a player can fail the ascension check before being considered a cheater -# Increase in case of false positives -ASCENSION_COUNT_MAX: 8 # Minimum time in between block breaks # Decrease in case of false positives BLOCK_BREAK_MIN: 0.1 +# Maximum speed a player can travel forwards or backwards while sneaking +# This is a set value and shouldn't be changed unless you know what you're doing +XZ_SPEED_MAX_SNEAK: 0.15 # Maximum distance a player can break a block from # Changing this value is almost never required BLOCK_MAX_DISTANCE: 5.5 @@ -154,9 +154,6 @@ PROJECTILE_TIME_MIN: 1500 # Time to exempt a player from moving because of entering/exiting sneak mode # Increase in case of false positives, shouldn't be necessary SNEAK_TIME: 250 -# Maximum times a player can fail the speed check before being considered a cheater -# Increase in case of false positives -SPEED_MAX: 3 # Number of times a player can sprint without proper food level before being considered a cheater # Can either be increased or decreased to your liking. Shouldn't make a massive difference. SPRINT_FOOD_MIN: 6 @@ -180,64 +177,9 @@ VELOCITY_PREVENT: 5000 VELOCITY_SCHETIME: 2 # This is a set value and shouldn't be changed unless you know what you're doing VELOCITY_TIME: 3 -# Number of times a player can fail the ascension check while in water before being considered a cheater -# Increase in case of false positives -WATER_ASCENSION_VIOLATION_MAX: 8 # Maximum speed that a player can climb a waterfall # Can be increased in case of false positives, shouldn't be necesary WATER_CLIMB_MAX: 0.15 -# Number of times a player can be caught speeding in water before being considered a cheater -# Increase in case of false positives -WATER_SPEED_VIOLATION_MAX: 6 -# Maximum speed a player can travel forwards or backwards -# This is a set value and shouldn't be changed unless you know what you're doing -XZ_SPEED_MAX: 0.25 -# aximum speed a player can travel forwards or backwards while flying -# This is a set value and shouldn't be changed unless you know what you're doing -XZ_SPEED_MAX_FLY: 0.56 -# Maximum speed a player can travel forwards or backwards while under the influence -# This is a set value and shouldn't be changed unless you know what you're doing -XZ_SPEED_MAX_POTION: 0.7 -# Maximum speed a player can travel forwards or backwards while sprinting while under the influence -# This is a set value and shouldn't be changed unless you know what you're doing -XZ_SPEED_MAX_POTION_SPRINT: 0.95 -# Maximum speed a player can travel forwards or backwards while sneaking -# This is a set value and shouldn't be changed unless you know what you're doing -XZ_SPEED_MAX_SNEAK: 0.15 -# Maximum speed a player can travel forwards or backwards on soul sand -# This is a set value and shouldn't be changed unless you know what you're doing -XZ_SPEED_MAX_SOULSAND: 0.13 -# Maximum speed a player can travel forwards or backwards on soul sand while under the influenc -# This is a set value and shouldn't be changed unless you know what you're doing -XZ_SPEED_MAX_SOULSAND_POTION: 0.16 -# Maximum speed a player can travel forwards or backwards on soul sand while sprintin -# This is a set value and shouldn't be changed unless you know what you're doing -XZ_SPEED_MAX_SOULSAND_SPRINT: 0.2 -# Maximum speed a player can travel forwards or backwards while sprinting -# This is a set value and shouldn't be changed unless you know what you're doing -XZ_SPEED_MAX_SPRINT: 0.65 -# Maximum speed a player can travel forwards or backwards in water -# This is a set value and shouldn't be changed unless you know what you're doing -XZ_SPEED_MAX_WATER: 0.19 -# Maximum speed a player can travel forwards or backwards in water while sprinting -# This is a set value and shouldn't be changed unless you know what you're doing -XZ_SPEED_MAX_WATER_SPRINT: 0.3 -# Maximum difference between the player's last two Y values when traveling up -# Can be decreased slightly to improve detection with the risk of false positives -# Increase in case of false positives -Y_MAXDIFF: 5.0 -# Number of times a player can fly on the y-axis before being considered a cheater -# Increase in case of false positives -Y_MAXVIOLATIONS: 1 -# Time a player is forced to wait after flyhacking on the y-axis -# Should be changed to personal preference -Y_MAXVIOTIME: 5500 -# Maximum speed a player can travel up -# This is a set value and shouldn't be changed unless you know what you're doing -Y_SPEED_MAX: 0.5175 -# Time in between Y difference measures -# This is a set value and shouldn't be changed unless you know what you're doing -Y_TIME: 800 # Amount of suspicious mid-air movements before a player is suspected of glide # Increase this in case of false positives GLIDE_LIMIT: 5 @@ -248,11 +190,11 @@ MOREPACKETS_TELEPORT_COMPENSATION: 150 # The amount of milliseconds that were offset to flag for MorePackets (50ms = 1 tick) # Increase this in case of false positives # Can be decreased in to tighten check -MOREPACKETS_TRIGGER_BALANCE: 50 +MOREPACKETS_TRIGGER_BALANCE: 100 # The maximum amount of overall lag compensating in milliseconds (50ms = 1 tick) # Increase this in case of false positives # Can be decreased in to tighten check -MOREPACKETS_MINIMUM_CLAMP: 200 +MOREPACKETS_MINIMUM_CLAMP: 500 # Maximum amount zero-velocity moments before a player is suspected # Increase this in case of false positives VELOCITY_MAX_FLAGS: 3 @@ -264,7 +206,7 @@ KILLAURA_MAX_ANGLE_DIFFERENCE: 50 KILLAURA_MAX_ANGLE_VIOLATIONS: 3 # The maximum angle difference allowed when placing or breaking a block # Increase this in case of false positives, can be slightly decreased to tighten check -ILLEGALINTERACT_MAX_ANGLE_DIFFERENCE: 75 +ILLEGALINTERACT_MAX_ANGLE_DIFFERENCE: 80 # The minimum time it takes to regenerate health # Decrease this in case of false positives MIN_HEAL_TIME: 490