Reformatting, update to 1.17, performance and general improvements, improved WaterWalk

This commit is contained in:
Rammelkast committed 2021-06-30 19:32:37 +02:00
1 parent f637facbea
commit 7739eb9ca0
19 files changed
+676 -705

No files matched your search

@@ -14,7 +14,6 @@
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*/
package com.rammelkast.anticheatreloaded.util;
import java.io.Serializable;
@@ -37,7 +36,7 @@ import com.google.common.collect.Ordering;
*
* @author Kristian
*/
public class MinecraftVersion implements Comparable<MinecraftVersion>, Serializable {
public final class MinecraftVersion implements Comparable<MinecraftVersion>, Serializable {
private static final long serialVersionUID = 1L;
/**
@@ -25,7 +25,7 @@ import org.bukkit.potion.PotionEffectType;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
public class MovementManager {
public final class MovementManager {
// Ticks in air
public int airTicks = 0;
@@ -95,14 +95,14 @@ public class MovementManager {
public long lastUpdate;
@SuppressWarnings("deprecation")
public void handle(Player player, Location from, Location to, Distance distance) {
public void handle(final Player player, final Location from, final Location to, final Distance distance) {
// TODO as of now, we "trust" the client to send the right thing
// This is checked for spoofing by "GroundFlight"
// Also seems to make NoFall cheats flag for speed lmao
this.onGround = player.isOnGround();
double x = distance.getXDifference();
double z = distance.getZDifference();
final double x = distance.getXDifference();
final double z = distance.getZDifference();
this.lastDistanceXZ = this.distanceXZ;
this.lastDistanceX = this.distanceX;
this.lastDistanceZ = this.distanceZ;
@@ -111,8 +111,9 @@ public class MovementManager {
this.distanceZ = z;
// Account for standing on boat
if (Utilities.couldBeOnBoat(player, 0.25, true) && !Utilities.isSubmersed(player))
if (Utilities.couldBeOnBoat(player, 0.25, true) && !Utilities.isSubmersed(player)) {
this.onGround = true;
}
// Handle 1.9+ potion effects
if (MinecraftVersion.atOrAbove(MinecraftVersion.COMBAT_UPDATE)) {
@@ -123,15 +124,16 @@ public class MovementManager {
AntiCheatReloaded.getManager().getBackend().logLevitating(player, 1);
}
}
this.touchedGroundThisTick = false;
this.halfMovement = false;
if (!this.onGround) {
this.groundTicks = 0;
this.airTicks++;
} else {
if (this.airTicks > 0)
if (this.airTicks > 0) {
this.touchedGroundThisTick = true;
}
this.airTicksBeforeGrounded = this.airTicks;
this.airTicks = 0;
this.groundTicks++;
@@ -142,8 +144,9 @@ public class MovementManager {
this.iceInfluenceTicks = 60;
} else {
this.iceTicks = 0;
if (this.iceInfluenceTicks > 0)
if (this.iceInfluenceTicks > 0) {
this.iceInfluenceTicks--;
}
}
if (Utilities.couldBeOnSlime(to)) {
@@ -151,62 +154,68 @@ public class MovementManager {
this.slimeInfluenceTicks = 40;
} else {
this.slimeTicks = 0;
if (this.slimeInfluenceTicks > 0)
if (this.slimeInfluenceTicks > 0) {
this.slimeInfluenceTicks--;
}
}
if (VersionUtil.isGliding(player)) {
this.elytraEffectTicks = 30;
} else {
if (this.elytraEffectTicks > 0)
if (this.elytraEffectTicks > 0) {
this.elytraEffectTicks--;
}
}
if (player.isSneaking())
if (player.isSneaking()) {
this.sneakingTicks++;
else
} else {
this.sneakingTicks = 0;
if (player.isBlocking())
this.blockingTicks++;
else
this.blockingTicks = 0;
if (Utilities.isNearWater(player))
this.nearLiquidTicks = 8;
else {
if (this.nearLiquidTicks > 0)
this.nearLiquidTicks--;
else
this.nearLiquidTicks = 0;
}
if (player.isBlocking()) {
this.blockingTicks++;
} else {
this.blockingTicks = 0;
}
if (Utilities.isNearWater(player)) {
this.nearLiquidTicks = 8;
} else {
if (this.nearLiquidTicks > 0) {
this.nearLiquidTicks--;
} else {
this.nearLiquidTicks = 0;
}
}
if (VersionUtil.CURRENT_VERSION.isAtLeast(MinecraftVersion.AQUATIC_UPDATE)) {
if (player.isRiptiding()) {
this.riptideTicks = 30;
} else {
if (this.riptideTicks > 0)
if (this.riptideTicks > 0) {
this.riptideTicks--;
else
} else {
this.riptideTicks = 0;
}
}
}
this.hadSpeedEffect = this.hasSpeedEffect;
this.hasSpeedEffect = player.hasPotionEffect(PotionEffectType.SPEED);
double lastDistanceSq = Math.sqrt(this.lastDistance.getXDifference() * this.lastDistance.getXDifference()
final double lastDistanceSq = Math.sqrt(this.lastDistance.getXDifference() * this.lastDistance.getXDifference()
+ this.lastDistance.getZDifference() * this.lastDistance.getZDifference());
double currentDistanceSq = Math.sqrt(distance.getXDifference() * distance.getXDifference()
final 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);
final Location top = to.clone().add(0, 2, 0);
this.topSolid = top.getBlock().getType().isSolid();
Location bottom = to.clone().add(0, -1, 0);
final Location bottom = to.clone().add(0, -1, 0);
this.bottomSolid = bottom.getBlock().getType().isSolid();
if ((this.motionY > 0.42D && this.motionY <= 0.5625D)
@@ -214,8 +223,9 @@ public class MovementManager {
this.halfMovement = true;
this.halfMovementHistoryCounter = 30;
} else {
if (this.halfMovementHistoryCounter > 0)
if (this.halfMovementHistoryCounter > 0) {
this.halfMovementHistoryCounter--;
}
}
this.lastUpdate = System.currentTimeMillis();
@@ -21,6 +21,7 @@ package com.rammelkast.anticheatreloaded.util;
import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
@@ -31,67 +32,67 @@ import com.rammelkast.anticheatreloaded.check.movement.NoSlowCheck;
import com.rammelkast.anticheatreloaded.check.packet.BadPacketsCheck;
import com.rammelkast.anticheatreloaded.check.packet.MorePacketsCheck;
public class PacketListener {
public final class PacketListener {
public static void listenMovementPackets() {
AntiCheatReloaded.getProtocolManager()
.addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(), ListenerPriority.LOWEST,
new PacketType[] { PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK,
PacketType.Play.Server.POSITION }) {
@Override
public void onPacketReceiving(PacketEvent event) {
Player player = event.getPlayer();
if (player == null || !player.isOnline())
return;
public static void load(final ProtocolManager manager) {
// Used for MorePackets and BadPackets
manager.addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(), ListenerPriority.LOWEST,
new PacketType[] { PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK,
PacketType.Play.Server.POSITION }) {
@Override
public void onPacketReceiving(final PacketEvent event) {
final Player player = event.getPlayer();
if (player == null || !player.isOnline()) {
return;
}
// Run MorePackets check
MorePacketsCheck.runCheck(player, event);
// Run MorePackets check
MorePacketsCheck.runCheck(player, event);
if (!event.isCancelled()) {
// Run BadPackets check
BadPacketsCheck.runCheck(player, event);
}
}
if (!event.isCancelled()) {
// Run BadPackets check
BadPacketsCheck.runCheck(player, event);
}
}
@Override
public void onPacketSending(PacketEvent event) {
Player player = event.getPlayer();
// Check if we have an actual player object
if (player instanceof TemporaryPlayer)
return;
// Compensate for teleport
MorePacketsCheck.compensate(player);
}
});
}
@Override
public void onPacketSending(final PacketEvent event) {
final Player player = event.getPlayer();
// Check if we have an actual player object
if (player instanceof TemporaryPlayer) {
return;
}
// Compensate for teleport
MorePacketsCheck.compensate(player);
}
});
// Used for accurate ping
manager.addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(), ListenerPriority.LOWEST,
new PacketType[] { PacketType.Play.Client.KEEP_ALIVE, PacketType.Play.Server.KEEP_ALIVE }) {
@Override
public void onPacketSending(final PacketEvent event) {
final User user = AntiCheatReloaded.getManager().getUserManager()
.getUser(event.getPlayer().getUniqueId());
user.onServerPing();
}
public static void listenKeepAlivePackets() {
AntiCheatReloaded.getProtocolManager()
.addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(), ListenerPriority.LOWEST,
new PacketType[] { PacketType.Play.Client.KEEP_ALIVE, PacketType.Play.Server.KEEP_ALIVE }) {
@Override
public void onPacketSending(PacketEvent event) {
User user = AntiCheatReloaded.getManager().getUserManager()
.getUser(event.getPlayer().getUniqueId());
user.onServerPing();
}
@Override
public void onPacketReceiving(PacketEvent event) {
User user = AntiCheatReloaded.getManager().getUserManager()
.getUser(event.getPlayer().getUniqueId());
user.onClientPong();
}
});
}
public static void listenUseItemPackets() {
AntiCheatReloaded.getProtocolManager().addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(),
@Override
public void onPacketReceiving(final PacketEvent event) {
final User user = AntiCheatReloaded.getManager().getUserManager()
.getUser(event.getPlayer().getUniqueId());
user.onClientPong();
}
});
// Used for NoSlow
manager.addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(),
ListenerPriority.LOWEST, new PacketType[] { PacketType.Play.Client.BLOCK_DIG }) {
@Override
public void onPacketReceiving(PacketEvent event) {
if (event.getPacket().getPlayerDigTypes().read(0) == PlayerDigType.RELEASE_USE_ITEM)
public void onPacketReceiving(final PacketEvent event) {
if (event.getPacket().getPlayerDigTypes().read(0) == PlayerDigType.RELEASE_USE_ITEM) {
NoSlowCheck.runCheck(event.getPlayer(), event);
}
}
});
}
@@ -1,44 +0,0 @@
/*
* AntiCheatReloaded for Bukkit and Spigot.
* Copyright (c) 2012-2015 AntiCheat Team
* Copyright (c) 2016-2021 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 <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.util;
import org.bukkit.Material;
public enum ToolHardness {
// NOTHING(null, 1.5)
WOOD(0.75D), STONE(0.40D), IRON(0.25D), DIAMOND(0.20D), SHEARS(0.55D), GOLD(0.15D);
double hardness;
ToolHardness(double hard) {
hardness = hard;
}
public static double getToolHardness(Material tool) {
for (ToolHardness e : ToolHardness.values()) {
if (tool.name().contains(e.name())) {
return e.hardness;
}
}
return 1.50D;
}
}
@@ -23,7 +23,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
@@ -42,7 +42,7 @@ public class UpdateManager {
}
public void update() {
this.latestVersion = this.getOnlineData(SPIGOT_VERSION_URL);
this.latestVersion = getOnlineData(SPIGOT_VERSION_URL);
if (this.latestVersion == null) {
this.isLatest = true;
this.isAhead = false;
@@ -64,7 +64,7 @@ public class UpdateManager {
InputStream stream = null;
try {
stream = new URL(url).openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, Charset.forName("UTF-8")));
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, StandardCharsets.UTF_8));
StringBuilder builder = new StringBuilder();
int readChar;
while ((readChar = reader.read()) != -1) {
@@ -32,7 +32,7 @@ import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.util.rule.Rule;
public class User {
public final class User {
private final UUID uuid;
private final String name;
private final int id;
@@ -52,19 +52,20 @@ public class User {
private int ping = -1;
private int lastPing = -1;
private MovementManager movementManager;
private final MovementManager movementManager = new MovementManager();
/**
* Initialize an AntiCheat user
*
* @param uuid Player's UUID
*/
public User(UUID uuid) {
public User(final UUID uuid) {
this.uuid = uuid;
this.name = getPlayer() != null && getPlayer().isOnline() ? getPlayer().getName() : "";
this.id = getPlayer() != null && getPlayer().isOnline() ? getPlayer().getEntityId() : -1;
this.movementManager = new MovementManager();
this.ping = getPlayer() != null && getPlayer().isOnline() ? VersionUtil.getPlayerPing(getPlayer()) : -1;
setIsWaitingOnLevelSync(true);
config.getLevels().loadLevelToUser(this);
}
/**
@@ -118,14 +119,15 @@ public class User {
* @return group
*/
public Group getGroup() {
List<Group> groups = config.getGroups().getGroups();
final List<Group> groups = config.getGroups().getGroups();
for (int i = 0; i < groups.size(); i++) {
if (i == 0 && level < groups.get(i).getLevel())
if (i == 0 && level < groups.get(i).getLevel()) {
break;
else if (i == groups.size() - 1)
} else if (i == groups.size() - 1) {
return groups.get(i);
else if (level >= groups.get(i).getLevel() && level < groups.get(i + 1).getLevel())
} else if (level >= groups.get(i).getLevel() && level < groups.get(i + 1).getLevel()) {
return groups.get(i);
}
}
return null;
}
@@ -136,7 +138,7 @@ public class User {
* @param type The check failed
* @return true if the level was increased
*/
public boolean increaseLevel(CheckType type) {
public boolean increaseLevel(final CheckType type) {
if (getPlayer() != null && getPlayer().isOnline()) {
if (silentMode() && type.getUses(uuid) % 4 != 0) {
// Prevent silent mode from increasing the level way too fast
@@ -146,17 +148,17 @@ public class User {
level++;
// Check levels
for (Group l : getLevels()) {
if (l.getLevel() == level) {
AntiCheatReloaded.getManager().getUserManager().alert(this, l, type);
if (l.getLevel() == config.getGroups().getHighestLevel()) {
level = l.getLevel() - 10;
for (final Group group : getLevels()) {
if (group.getLevel() == level) {
AntiCheatReloaded.getManager().getUserManager().alert(this, group, type);
if (group.getLevel() == config.getGroups().getHighestLevel()) {
level = group.getLevel() - 10;
}
}
}
// Execute rules
for (Rule rule : config.getRules().getRules()) {
for (final Rule rule : config.getRules().getRules()) {
rule.check(this, type);
}
return true;
@@ -182,7 +184,7 @@ public class User {
* @param level level to set
* @return true if the level was valid and set properly
*/
public boolean setLevel(int level) {
public boolean setLevel(final int level) {
isWaitingOnLevelSync = false;
if (level >= 0) {
if (level <= config.getGroups().getHighestLevel()) {
@@ -202,7 +204,7 @@ public class User {
*/
public void resetLevel() {
level = 0;
for (CheckType type : CheckType.values()) {
for (final CheckType type : CheckType.values()) {
type.clearUse(uuid);
}
}
@@ -213,13 +215,13 @@ public class User {
* @param location default value to be returned if no known good location exists
* @return last known valid location
*/
public Location getGoodLocation(Location location) {
public Location getGoodLocation(final Location location) {
if (goodLocation == null || !location.getWorld().equals(goodLocation.getWorld())
|| location.distance(goodLocation) > config.getConfig().maxSetbackDistance.getValue()) {
return location;
}
Location moveTo = goodLocation;
final Location moveTo = goodLocation;
if (location != null) {
moveTo.setPitch(location.getPitch());
moveTo.setYaw(location.getYaw());
@@ -233,7 +235,7 @@ public class User {
* @param location location to be set
* @return true if the location was valid and set properly
*/
public boolean setGoodLocation(Location location) {
public boolean setGoodLocation(final Location location) {
if (Utilities.cantStandAtExp(location)) {
return false;
}
@@ -241,7 +243,7 @@ public class User {
goodLocation = location;
return true;
}
/**
* Set the player's to location
*
@@ -402,9 +404,9 @@ public class User {
}
public int getPing() {
int ping = this.ping;
final int ping = this.ping;
if (ping < 0) {
return VersionUtil.getPlayerPing(this.getPlayer());
return VersionUtil.getPlayerPing(getPlayer());
}
return ping;
}
@@ -51,7 +51,7 @@ public class VersionUtil {
return false;
}
public static boolean isOfVersion(String versionId) {
public static boolean isOfVersion(final String versionId) {
if (getVersion().startsWith(versionId)) {
return true;
}
@@ -65,7 +65,7 @@ public class VersionUtil {
return isOfVersion("v1_8");
}
public static boolean isFlying(Player player) {
public static boolean isFlying(final Player player) {
if (isBountifulUpdate()) {
return player.isFlying();
}
@@ -73,14 +73,14 @@ public class VersionUtil {
|| AntiCheatReloaded.getManager().getBackend().justLevitated(player);
}
public static boolean isSlowFalling(Player player) {
public static boolean isSlowFalling(final Player player) {
if (!CURRENT_VERSION.isAtLeast(MinecraftVersion.AQUATIC_UPDATE)) {
return false;
}
return player.hasPotionEffect(PotionEffectType.SLOW_FALLING);
}
public static boolean isFrostWalk(Player player) {
public static boolean isFrostWalk(final Player player) {
if (player.getInventory().getBoots() == null || isBountifulUpdate()) {
return false;
}
@@ -88,59 +88,65 @@ public class VersionUtil {
}
@SuppressWarnings("deprecation")
public static ItemStack getItemInHand(Player player) {
public static ItemStack getItemInHand(final Player player) {
if (isBountifulUpdate()) {
return player.getItemInHand();
}
return player.getInventory().getItemInMainHand();
}
public static int getPlayerPing(Player player) {
try {
Object entityPlayer = player.getClass().getMethod("getHandle").invoke(player);
int ping = (int) entityPlayer.getClass().getField("ping").get(entityPlayer);
return ping;
} catch (Exception e) {
return -1;
public static int getPlayerPing(final Player player) {
if (!CURRENT_VERSION.isAtLeast(MinecraftVersion.CAVES_CLIFFS_1)) {
try {
final Object entityPlayer = player.getClass().getMethod("getHandle").invoke(player);
final int ping = (int) entityPlayer.getClass().getField("ping").get(entityPlayer);
return ping;
} catch (Exception e) {
return -1;
}
} else {
return player.getPing();
}
}
public static Block getTargetBlock(Player player, int distance) {
public static Block getTargetBlock(final Player player, final int distance) {
if (!CURRENT_VERSION.isAtLeast(MinecraftVersion.AQUATIC_UPDATE)) {
return player.getTargetBlock((Set<Material>) null, distance);
}
return player.getTargetBlockExact(distance);
}
public static boolean isGliding(Player player) {
public static boolean isGliding(final Player player) {
if (isBountifulUpdate()) {
return false;
}
return player.isGliding();
}
public static boolean isLevitationEffect(PotionEffect effect) {
public static boolean isLevitationEffect(final PotionEffect effect) {
if (isBountifulUpdate()) {
return false;
}
return effect.getType().equals(PotionEffectType.LEVITATION);
}
public static int getPotionLevel(Player player, PotionEffectType type) {
public static int getPotionLevel(final Player player, final PotionEffectType type) {
if (isBountifulUpdate()) {
for (PotionEffect effect : player.getActivePotionEffects()) {
if (effect.getType().equals(type))
if (effect.getType().equals(type)) {
return effect.getAmplifier() + 1;
}
}
return 0;
}
if (player.hasPotionEffect(type))
if (player.hasPotionEffect(type)) {
return player.getPotionEffect(type).getAmplifier() + 1;
}
return 0;
}
public static boolean isSwimming(Player player) {
public static boolean isSwimming(final Player player) {
if (!CURRENT_VERSION.isAtLeast(MinecraftVersion.AQUATIC_UPDATE)) {
return false;
}
@@ -148,7 +154,7 @@ public class VersionUtil {
}
static {
SUPPORTED_VERSIONS = Arrays.asList(new String[] { "v1_16", "v1_15", "v1_14", "v1_13", "v1_12", "v1_8_R3" });
SUPPORTED_VERSIONS = Arrays.asList(new String[] { "v1_17_R1", "v1_16", "v1_15", "v1_14", "v1_13", "v1_12", "v1_8_R3" });
CURRENT_VERSION = MinecraftVersion.getCurrentVersion();
}
}