Added GhostHand and Unicode chat check and fixed broken fly check.

Furthermore:
+ Updated and documented magic.yml
+ Added support for missing CAVE_AIR material
+ Average ping for blink check can now be configured
+ Removed /acr update from help command
+ Added UpdateManager.java to be used in future update messages
+ Better MainHand/OffHand support

I've been busy :)
This commit is contained in:
Rammelkast committed 2020-03-24 20:15:31 +01:00
1 parent acea36929b
commit fec1286c8d
22 files changed
+596 -193

No files matched your search

@@ -41,6 +41,7 @@ import org.bukkit.potion.PotionEffectType;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.combat.VelocityCheck;
import com.rammelkast.anticheatreloaded.check.movement.BlinkCheck;
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;
@@ -173,6 +174,7 @@ public class Backend {
GlideCheck.LAST_FALL_DISTANCE.remove(pU);
GlideCheck.VIOLATIONS.remove(pU);
SpeedCheck.SPEED_VIOLATIONS.remove(player.getUniqueId());
ElytraCheck.JUMP_Y_VALUE.remove(player.getUniqueId().toString());
}
public CheckResult checkFastBow(Player player, float force) {
@@ -411,22 +413,29 @@ public class Backend {
if (player.hasPotionEffect(PotionEffectType.JUMP)) {
max += 12;
string = " with jump potion";
}
Block block = player.getLocation().getBlock();
if (!isMovingExempt(player) && !Utilities.isInWater(player) && !VersionUtil.isFlying(player) && !justBroke(player) && !Utilities.isClimbableBlock(player.getLocation().getBlock()) && !player.isInsideVehicle() && !YAxisCheck.isMoveUpBlock(player.getLocation().add(0, -1, 0).getBlock()) && !YAxisCheck.isMoveUpBlock(player.getLocation().add(0, -1.5, 0).getBlock())) {
if (y1 < y2) {
if (!block.getRelative(BlockFace.NORTH).isLiquid() && !block.getRelative(BlockFace.SOUTH).isLiquid() && !block.getRelative(BlockFace.EAST).isLiquid() && !block.getRelative(BlockFace.WEST).isLiquid()) {
increment(player, ascensionCount, max);
if (ascensionCount.get(player.getUniqueId()) >= max) {
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " ascended " + ascensionCount.get(player.getUniqueId()) + " times in a row (max = " + max + string + ")");
}
}
} else {
ascensionCount.put(player.getUniqueId(), 0);
}
}
return PASS;
}
}
Block block = player.getLocation().getBlock();
if (!isMovingExempt(player) && !Utilities.isInWater(player) && !VersionUtil.isFlying(player)
&& !justBroke(player) && !Utilities.isClimbableBlock(player.getLocation().getBlock())
&& !player.isInsideVehicle() && !YAxisCheck.isMoveUpBlock(player.getLocation().add(0, -1, 0).getBlock())
&& !YAxisCheck.isMoveUpBlock(player.getLocation().add(0, -1.5, 0).getBlock())) {
if (y1 < y2) {
if (!block.getRelative(BlockFace.NORTH).isLiquid() && !block.getRelative(BlockFace.SOUTH).isLiquid()
&& !block.getRelative(BlockFace.EAST).isLiquid()
&& !block.getRelative(BlockFace.WEST).isLiquid()) {
increment(player, ascensionCount, max);
if (ascensionCount.get(player.getUniqueId()) >= max) {
return new CheckResult(CheckResult.Result.FAILED,
player.getName() + " ascended " + ascensionCount.get(player.getUniqueId())
+ " times in a row (max = " + max + string + ")");
}
}
} else {
ascensionCount.put(player.getUniqueId(), 0);
}
}
return PASS;
}
public CheckResult checkSwing(Player player, Block block) {
UUID uuid = player.getUniqueId();
@@ -566,14 +575,14 @@ public class Backend {
}
Long l = user.getMessageTime(i);
if (System.currentTimeMillis() - l > magic.CHAT_REPEAT_MIN() * 100) {
if (System.currentTimeMillis() - l > magic.CHAT_REPEAT_MIN()) {
user.clearMessages();
break;
} else {
if (manager.getConfiguration().getConfig().blockChatSpamRepetition.getValue() && m.equalsIgnoreCase(msg) && i == 1) {
manager.getLoggingManager().logFineInfo(player.getName() + " spam-repeated \"" + msg + "\"");
return new CheckResult(CheckResult.Result.FAILED, lang.SPAM_WARNING());
} else if (manager.getConfiguration().getConfig().blockChatSpamSpeed.getValue() && System.currentTimeMillis() - user.getLastCommandTime() < magic.COMMAND_MIN() * 2) {
} else if (manager.getConfiguration().getConfig().blockChatSpamSpeed.getValue() && System.currentTimeMillis() - user.getLastCommandTime() < magic.CHAT_MIN()) {
manager.getLoggingManager().logFineInfo(player.getName() + " spammed quickly \"" + msg + "\"");
return new CheckResult(CheckResult.Result.FAILED, lang.SPAM_WARNING());
}
@@ -609,13 +618,13 @@ public class Backend {
}
Long l = user.getCommandTime(i);
if (System.currentTimeMillis() - l > magic.COMMAND_REPEAT_MIN() * 100) {
if (System.currentTimeMillis() - l > magic.COMMAND_REPEAT_MIN()) {
user.clearCommands();
break;
} else {
if (manager.getConfiguration().getConfig().blockCommandSpamRepetition.getValue() && m.equalsIgnoreCase(cmd) && i == 1) {
return new CheckResult(CheckResult.Result.FAILED, lang.SPAM_WARNING());
} else if (manager.getConfiguration().getConfig().blockCommandSpamSpeed.getValue() && System.currentTimeMillis() - user.getLastCommandTime() < magic.COMMAND_MIN() * 2) {
} else if (manager.getConfiguration().getConfig().blockCommandSpamSpeed.getValue() && System.currentTimeMillis() - user.getLastCommandTime() < magic.COMMAND_MIN()) {
return new CheckResult(CheckResult.Result.FAILED, lang.SPAM_WARNING());
}
}
@@ -656,8 +665,8 @@ public class Backend {
}
public CheckResult checkSprintDamage(Player player) {
if (isDoing(player, sprinted, magic.SPRINT_MIN())) {
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " sprinted and damaged an entity too fast (min sprint=" + magic.SPRINT_MIN() + " ms)");
if (isDoing(player, sprinted, magic.SPRINT_MAX())) {
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " sprinted and damaged an entity too fast (min sprint=" + magic.SPRINT_MAX() + " ms)");
} else {
return PASS;
}
@@ -794,6 +803,7 @@ public class Backend {
GlideCheck.LAST_FALL_DISTANCE.remove(player.getUniqueId());
GlideCheck.LAST_DIFFERENCE.remove(player.getUniqueId());
GlideCheck.VIOLATIONS.remove(player.getUniqueId());
ElytraCheck.JUMP_Y_VALUE.remove(player.getUniqueId().toString());
}
public void logExitFly(final Player player) {
@@ -36,11 +36,8 @@ import java.util.UUID;
*/
public enum CheckType {
ZOMBE_FLY(Permission.CHECK_ZOMBE_FLY),
ZOMBE_NOCLIP(Permission.CHECK_ZOMBE_NOCLIP),
ZOMBE_CHEAT(Permission.CHECK_ZOMBE_CHEAT),
FLIGHT(Permission.CHECK_FLIGHT),
ELYTRA(Permission.CHECK_FLIGHT),
ELYTRAFLY(Permission.CHECK_FLIGHT),
WATER_WALK(Permission.CHECK_WATERWALK),
NO_SWING(Permission.CHECK_NOSWING),
FAST_BREAK(Permission.CHECK_FASTBREAK),
@@ -65,8 +62,9 @@ public enum CheckType {
BLINK(Permission.CHECK_BLINK),
VELOCITY(Permission.CHECK_VELOCITY),
CRITICALS(Permission.CHECK_CRITICALS),
CHAT_UNICODE(Permission.CHECK_UNICODE);
CHAT_UNICODE(Permission.CHECK_UNICODE),
GHOSTHAND(Permission.CHECK_GHOSTHAND);
private final Permission permission;
private final Map<UUID, Integer> level = new HashMap<UUID, Integer>();
@@ -23,7 +23,6 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@@ -72,7 +71,9 @@ public class BlinkCheck {
int ping = VersionUtil.getPlayerPing(p);
int blinkMagic = AntiCheatReloaded.getManager().getBackend()
.getMagic().BLINK_PACKET();
float pingLeniency = (float) ((ping / 120));
int averagePing = AntiCheatReloaded.getManager().getBackend()
.getMagic().BLINK_AVERAGE_PING();
float pingLeniency = (float) ((ping / averagePing));
if (pingLeniency < 1) pingLeniency = 1;
if (pingLeniency > 3) pingLeniency = 3;
blinkMagic = Math.round(pingLeniency * blinkMagic);
@@ -19,39 +19,71 @@
package com.rammelkast.anticheatreloaded.check.movement;
import java.util.HashMap;
import org.bukkit.Location;
import org.bukkit.Material;
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.util.Distance;
import com.rammelkast.anticheatreloaded.util.Utilities;
/**
* TODO
*/
public class ElytraCheck {
public static final HashMap<String, Double> JUMP_Y_VALUE = new HashMap<String, Double>();
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static CheckResult runCheck(Player player, Distance distance) {
String uuid = player.getUniqueId().toString();
if (distance.getYDifference() > AntiCheatReloaded.getManager().getBackend().getMagic().TELEPORT_MIN()) {
// This was a teleport, so skip check.
JUMP_Y_VALUE.remove(uuid);
return PASS;
}
/*if (!FlightCheck.isMovingExempt(player) && !Utilities.isHoveringOverWater(player.getLocation(), 1)
&& Utilities.cantStandAtExp(player.getLocation())
&& Utilities.blockIsnt(player.getLocation().getBlock().getRelative(BlockFace.DOWN),
new Material[] { Material.FENCE, Material.FENCE_GATE, Material.COBBLE_WALL,
Material.ACACIA_FENCE, Material.ACACIA_FENCE_GATE, Material.BIRCH_FENCE,
Material.BIRCH_FENCE_GATE, Material.DARK_OAK_FENCE, Material.DARK_OAK_FENCE_GATE,
Material.IRON_FENCE, Material.JUNGLE_FENCE, Material.JUNGLE_FENCE_GATE,
Material.fence, Material.SPRUCE_FENCE, Material.SPRUCE_FENCE_GATE, Material.IRON_BARS })) {
}*/
//TODO 1.15 update
if (player.isFlying() || player.hasPotionEffect(PotionEffectType.LEVITATION) || !player.isGliding()) {
JUMP_Y_VALUE.remove(uuid);
return PASS;
}
double changeY = distance.toY() - distance.fromY();
boolean upwardMovement = changeY > 0;
if (player.getInventory().getItemInMainHand().getType() == Material.TRIDENT) {
if (upwardMovement) {
// TODO continue check here
JUMP_Y_VALUE.remove(uuid);
return PASS;
}
}
if (changeY == 0.0D) {
// Seen no false positives here yet
return new CheckResult(CheckResult.Result.FAILED,
player.getName() + " had no Y-axis dropoff when gliding with Elytra");
}
if (!JUMP_Y_VALUE.containsKey(uuid)) {
JUMP_Y_VALUE.put(uuid, distance.toY());
return PASS;
}
double lastY = JUMP_Y_VALUE.get(uuid);
if (lastY < distance.toY()) {
double diff = distance.toY() - lastY;
if (diff > 0.7675) {
if (!AntiCheatReloaded.getManager().getBackend().silentMode()) {
Location to = player.getLocation();
to.setY(to.getY() - diff);
player.teleport(to);
}
return new CheckResult(CheckResult.Result.FAILED,
player.getName() + " tried to glide above jump level");
}
}
return PASS;
}
@@ -56,11 +56,8 @@ public class FlightCheck {
&& Utilities.cantStandAtExp(player.getLocation())
&& Utilities.blockIsnt(player.getLocation().getBlock().getRelative(BlockFace.DOWN),
new Material[] { Material.IRON_BARS })
&& Utilities.blockIsnt(player.getLocation().getBlock().getRelative(BlockFace.DOWN), new String[] {
"FENCE",
"FENCE_GATE"
})) {
&& Utilities.blockIsnt(player.getLocation().getBlock().getRelative(BlockFace.DOWN),
new String[] { "FENCE", "FENCE_GATE" })) {
if (!BLOCKS_OVER_FLIGHT.containsKey(uuid)) {
BLOCKS_OVER_FLIGHT.put(uuid, 0D);
}
@@ -72,8 +69,8 @@ public class FlightCheck {
BLOCKS_OVER_FLIGHT.put(uuid, (BLOCKS_OVER_FLIGHT.get(uuid) - distance.getYDifference()));
}
if (BLOCKS_OVER_FLIGHT.get(uuid) > AntiCheatReloaded.getManager().getBackend().getMagic().FLIGHT_BLOCK_LIMIT()
&& (y1 <= y2)) {
if (BLOCKS_OVER_FLIGHT.get(uuid) > AntiCheatReloaded.getManager().getBackend().getMagic()
.FLIGHT_BLOCK_LIMIT() && (y1 <= y2)) {
return new CheckResult(CheckResult.Result.FAILED,
player.getName() + " flew over " + BLOCKS_OVER_FLIGHT.get(uuid) + " blocks (max="
+ AntiCheatReloaded.getManager().getBackend().getMagic().FLIGHT_BLOCK_LIMIT() + ")");
@@ -81,7 +78,6 @@ public class FlightCheck {
} else {
BLOCKS_OVER_FLIGHT.put(uuid, 0D);
}
return PASS;
}
@@ -67,11 +67,11 @@ public class GlideCheck {
if (VIOLATIONS.get(player.getUniqueId()) + 1 >= AntiCheatReloaded.getManager().getBackend().getMagic()
.GLIDE_LIMIT()) {
VIOLATIONS.remove(player.getUniqueId());
Location to = player.getLocation();
to.setY(to.getY() - distanceToFall(to));
player.teleport(to);
// Report glide violation to statistics, just for the lulz jk
AntiCheatReloaded.getPlugin().onGlideViolation();
if (!AntiCheatReloaded.getManager().getBackend().silentMode()) {
Location to = player.getLocation();
to.setY(to.getY() - distanceToFall(to));
player.teleport(to);
}
return new CheckResult(CheckResult.Result.FAILED,
player.getName() + " was set back for gliding (yDiff="
+ new BigDecimal(yDiff).setScale(2, RoundingMode.HALF_UP) + ")");
@@ -90,7 +90,8 @@ public class GlideCheck {
private static double distanceToFall(Location location) {
location = location.clone();
double firstY = location.getY();
while (location.clone().add(0, -0.1, 0).getBlock().getType() == Material.AIR)
Material subtractType = location.clone().add(0, -0.1, 0).getBlock().getType();
while (subtractType == Material.AIR || subtractType == Material.CAVE_AIR)
location.add(0, -0.1, 0);
return firstY - location.getY();
}
@@ -36,7 +36,8 @@ import com.rammelkast.anticheatreloaded.util.Utilities;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
/**
* This check seems to be broken/outdated
* This check should be replaced
* It works, but not great
*/
public class WaterWalkCheck {
@@ -77,7 +77,7 @@ public class YAxisCheck {
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) {
if (g.getBlock().getType() == Material.AIR || g.getBlock().getType() == Material.CAVE_AIR) {
player.teleport(g);
}
}
@@ -103,7 +103,7 @@ public class YAxisCheck {
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) {
if (g.getBlock().getType() == Material.AIR || g.getBlock().getType() == Material.CAVE_AIR) {
player.teleport(g);
}
}
@@ -19,18 +19,77 @@
package com.rammelkast.anticheatreloaded.check.player;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.List;
import org.bukkit.GameMode;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.config.providers.Magic;
import com.rammelkast.anticheatreloaded.util.Utilities;
/**
*
* @author Rammelkast
*
*/
public class GhosthandCheck {
public static final Map<UUID, Integer> FLAG_COUNT = new HashMap<UUID, Integer>();
public static final int MAX_FLAGS = 3; // TODO config?
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static CheckResult performCheck(Player player, Event event) {
if (event instanceof BlockPlaceEvent) {
return checkBlockPlace(player, (BlockPlaceEvent) event);
} else if (event instanceof BlockBreakEvent) {
return checkBlockBreak(player, (BlockBreakEvent) event);
}
return PASS;
}
private static CheckResult checkBlockBreak(Player player, BlockBreakEvent event) {
if (!isValidBreakTarget(player, event.getBlock())) {
return new CheckResult(CheckResult.Result.FAILED,
player.getName() + " tried to break a block which was out of view");
}
return PASS;
}
private static CheckResult checkBlockPlace(Player player, BlockPlaceEvent event) {
if (!isValidPlaceTarget(player, event.getBlock())) {
return new CheckResult(CheckResult.Result.FAILED,
player.getName() + " tried to place a block out of their view");
}
return PASS;
}
private static boolean isValidPlaceTarget(Player player, Block block) {
Magic magic = AntiCheatReloaded.getManager().getConfiguration().getMagic();
double distance =
player.getGameMode() == GameMode.CREATIVE ? magic.BLOCK_MAX_DISTANCE_CREATIVE()
: player.getLocation().getDirection().getY() > 0.9 ? magic.BLOCK_MAX_DISTANCE_CREATIVE()
: magic.BLOCK_MAX_DISTANCE();
Block targetBlock = player.getTargetBlockExact((int) Math.ceil(distance));
if (Utilities.isClimbableBlock(targetBlock)) {
if (targetBlock.getLocation().distance(player.getLocation()) <= distance) {
return true;
}
}
return targetBlock.equals(block) || targetBlock.getLocation().distance(block.getLocation()) <= 1.51;
}
private static boolean isValidBreakTarget(Player player, Block block) {
Magic magic = AntiCheatReloaded.getManager().getConfiguration().getMagic();
double distance =
player.getGameMode() == GameMode.CREATIVE ? magic.BLOCK_MAX_DISTANCE_CREATIVE()
: player.getLocation().getDirection().getY() > 0.9 ? magic.BLOCK_MAX_DISTANCE_CREATIVE()
: magic.BLOCK_MAX_DISTANCE();
List<Block> targetBlocks = player.getLastTwoTargetBlocks(null, (int) Math.ceil(distance));
for (Block target : targetBlocks) {
if (Utilities.isClimbableBlock(target)) {
return true;
}
}
return targetBlocks.contains(block);
}
}