Fixed YAxis false positive, added BadPackets check and cleaned up code and README .

This commit is contained in:
Rammelkast committed 2020-04-23 16:47:25 +02:00
1 parent 76c595e255
commit 9771387909
20 files changed
+600 -323

No files matched your search

@@ -30,10 +30,11 @@ import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.rammelkast.anticheatreloaded.check.movement.MorePacketsCheck;
import com.rammelkast.anticheatreloaded.check.packet.MorePacketsCheck;
import com.rammelkast.anticheatreloaded.command.CommandHandler;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.event.BlockListener;
@@ -43,6 +44,7 @@ import com.rammelkast.anticheatreloaded.event.PlayerListener;
import com.rammelkast.anticheatreloaded.event.VehicleListener;
import com.rammelkast.anticheatreloaded.manage.AntiCheatManager;
import com.rammelkast.anticheatreloaded.metrics.Metrics;
import com.rammelkast.anticheatreloaded.util.PacketListener;
import com.rammelkast.anticheatreloaded.util.UpdateManager;
import com.rammelkast.anticheatreloaded.util.User;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
@@ -59,6 +61,9 @@ public class AntiCheatReloaded extends JavaPlugin {
private static SecureRandom random;
private static Long loadTime;
private static UpdateManager updateManager;
private double tps = -1;
private int currentTick;
@Override
public void onEnable() {
@@ -90,13 +95,13 @@ public class AntiCheatReloaded extends JavaPlugin {
getLogger().info("NMS version is " + VersionUtil.getVersion());
if (!VersionUtil.isSupported()) {
Bukkit.getConsoleSender().sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.RED + "The version of this server is NOT supported by ACR! The plugin will be buggy!");
Bukkit.getConsoleSender().sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.RED
+ "The version of this server is NOT supported by ACR! The plugin will not work as expected!");
}
getLogger().info("Enabling checks that use ProtcolLib");
// Enable packetlisteners
MorePacketsCheck.startTimer();
MorePacketsCheck.listenPackets();
getLogger().info("Enabling packet listeners");
PacketListener.listenKeepAlivePackets();
PacketListener.listenMovementPackets();
updateManager = new UpdateManager();
@@ -130,6 +135,27 @@ public class AntiCheatReloaded extends JavaPlugin {
} catch (Exception e) {
e.printStackTrace();
}
// Launch TPS check
new BukkitRunnable() {
long sec;
long currentSec;
int ticks;
public void run() {
sec = (System.currentTimeMillis() / 1000L);
if (currentSec == sec) {
ticks += 1;
} else {
currentSec = sec;
tps = (tps == 0.0D ? ticks : (tps + ticks) / 2.0D);
ticks = 1;
}
currentTick++;
}
}.runTaskTimer(this, 40L, 1L);
// Launch MorePackets timer
MorePacketsCheck.startTimer();
}
@Override
@@ -264,4 +290,11 @@ public class AntiCheatReloaded extends JavaPlugin {
return updateManager;
}
public double getTPS() {
if (this.tps < 0) {
return 20;
}
return this.tps;
}
}
@@ -39,13 +39,13 @@ import org.bukkit.potion.PotionEffectType;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.combat.KillAuraCheck;
import com.rammelkast.anticheatreloaded.check.combat.VelocityCheck;
import com.rammelkast.anticheatreloaded.check.movement.MorePacketsCheck;
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;
import com.rammelkast.anticheatreloaded.config.providers.Magic;
@@ -56,6 +56,7 @@ import com.rammelkast.anticheatreloaded.util.Utilities;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
public class Backend {
public Map<UUID, Long> velocitized = new HashMap<UUID, Long>();
private List<UUID> isAscending = new ArrayList<UUID>();
private Map<UUID, Integer> ascensionCount = new HashMap<UUID, Integer>();
private Map<UUID, Integer> chatLevel = new HashMap<UUID, Integer>();
@@ -70,7 +71,6 @@ public class Backend {
private Map<UUID, Long> lastBlockPlaceTime = new HashMap<UUID, Long>();
private Map<UUID, Integer> blockPunches = new HashMap<UUID, Integer>();
private Map<UUID, Integer> projectilesShot = new HashMap<UUID, Integer>();
private Map<UUID, Long> velocitized = new HashMap<UUID, Long>();
private Map<UUID, Integer> velocitytrack = new HashMap<UUID, Integer>();
private Map<UUID, Long> startEat = new HashMap<UUID, Long>();
private Map<UUID, Long> lastHeal = new HashMap<UUID, Long>();
@@ -171,7 +171,7 @@ public class Backend {
inventoryClicks.remove(pU);
lastFallPacket.remove(pU);
fastSneakViolations.remove(player.getUniqueId().toString());
GlideCheck.LAST_DIFFERENCE.remove(pU);
GlideCheck.LAST_MOTION_Y.remove(pU);
GlideCheck.LAST_FALL_DISTANCE.remove(pU);
GlideCheck.VIOLATIONS.remove(pU);
SpeedCheck.SPEED_VIOLATIONS.remove(player.getUniqueId());
@@ -392,7 +392,7 @@ public class Backend {
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())) {
&& !YAxisCheck.isMoveUpBlock(player.getLocation().add(0, -0.5, 0).getBlock())) {
// TODO isMoveUpBlock does not seem to be a success with stairs
if (y1 < y2) {
if (!block.getRelative(BlockFace.NORTH).isLiquid() && !block.getRelative(BlockFace.SOUTH).isLiquid()
@@ -803,7 +803,7 @@ public class Backend {
YAxisCheck.LAST_Y_COORD_CACHE.remove(player.getUniqueId());
YAxisCheck.LAST_Y_TIME.remove(player.getUniqueId());
GlideCheck.LAST_FALL_DISTANCE.remove(player.getUniqueId());
GlideCheck.LAST_DIFFERENCE.remove(player.getUniqueId());
GlideCheck.LAST_MOTION_Y.remove(player.getUniqueId());
GlideCheck.VIOLATIONS.remove(player.getUniqueId());
ElytraCheck.JUMP_Y_VALUE.remove(player.getUniqueId().toString());
}
@@ -824,7 +824,7 @@ public class Backend {
return isAscending.contains(player.getUniqueId());
}
private boolean isDoing(Player player, Map<UUID, Long> map, double max) {
public boolean isDoing(Player player, Map<UUID, Long> map, double max) {
if (map.containsKey(player.getUniqueId())) {
if (max != -1) {
if (((System.currentTimeMillis() - map.get(player.getUniqueId())) / 1000) > max) {
@@ -60,6 +60,7 @@ public enum CheckType {
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),
@@ -32,63 +32,92 @@ 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 {
public static final Map<UUID, Double> LAST_DIFFERENCE = new HashMap<UUID, Double>();
public static final Map<UUID, Double> LAST_MOTION_Y = new HashMap<UUID, Double>();
public static final Map<UUID, Float> LAST_FALL_DISTANCE = new HashMap<UUID, Float>();
public static final Map<UUID, Integer> VIOLATIONS = new HashMap<UUID, Integer>();
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static CheckResult runCheck(Player player, Distance distance) {
if (VersionUtil.isFlying(player)) {
if (distance.getYDifference() > AntiCheatReloaded.getManager().getBackend().getMagic().TELEPORT_MIN()
|| VersionUtil.isFlying(player) || FlightCheck.isMovingExempt(player)) {
VIOLATIONS.put(player.getUniqueId(), 0);
return PASS;
}
if (player.getLocation().getBlock().getType() == Material.LADDER
|| player.getLocation().getBlock().getRelative(0, 1, 0).getType() == Material.LADDER) {
return PASS;
}
if (!LAST_DIFFERENCE.containsKey(player.getUniqueId())) {
LAST_DIFFERENCE.put(player.getUniqueId(), distance.getYDifference());
if (!LAST_MOTION_Y.containsKey(player.getUniqueId())) {
LAST_MOTION_Y.put(player.getUniqueId(), distance.getYDifference());
return PASS;
}
if (!LAST_FALL_DISTANCE.containsKey(player.getUniqueId())) {
LAST_FALL_DISTANCE.put(player.getUniqueId(), player.getFallDistance());
return PASS;
}
double yDiff = distance.getYDifference();
int violations = VIOLATIONS.getOrDefault(player.getUniqueId(), 0);
double motionY = distance.getYDifference();
float fallDistance = player.getFallDistance();
if (yDiff == LAST_DIFFERENCE.get(player.getUniqueId())
if (motionY == LAST_MOTION_Y.get(player.getUniqueId())
&& fallDistance > LAST_FALL_DISTANCE.get(player.getUniqueId())) {
if (!VIOLATIONS.containsKey(player.getUniqueId())) {
VIOLATIONS.put(player.getUniqueId(), 1);
} else {
if (VIOLATIONS.get(player.getUniqueId()) + 1 >= AntiCheatReloaded.getManager().getBackend().getMagic()
.GLIDE_LIMIT()) {
VIOLATIONS.remove(player.getUniqueId());
if (!AntiCheatReloaded.getManager().getBackend().silentMode()) {
Location prev = player.getLocation();
prev.setY(prev.getY() - distanceToFall(prev));
player.teleport(AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId())
.getGoodLocation(prev));
}
return new CheckResult(CheckResult.Result.FAILED,
"type=glide, desc_amount=" + new BigDecimal(yDiff).setScale(2, RoundingMode.HALF_UP) + ")");
} else {
VIOLATIONS.put(player.getUniqueId(), VIOLATIONS.get(player.getUniqueId()) + 1);
if (violations + 1 >= AntiCheatReloaded.getManager().getBackend().getMagic().GLIDE_LIMIT()) {
VIOLATIONS.put(player.getUniqueId(), 0);
if (!AntiCheatReloaded.getManager().getBackend().silentMode()) {
Location prev = player.getLocation().clone();
prev.setY(prev.getY() - distanceToFall(prev));
player.teleport(AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId())
.getGoodLocation(prev));
}
return new CheckResult(CheckResult.Result.FAILED,
"type=glide, desc_amount=" + new BigDecimal(motionY).setScale(2, RoundingMode.HALF_UP) + ")");
} else {
VIOLATIONS.put(player.getUniqueId(), violations + 1);
return PASS;
}
} else {
if (fallDistance > LAST_FALL_DISTANCE.get(player.getUniqueId()) && !player.isOnGround()) {
// TODO check gravity
if (fallDistance > LAST_FALL_DISTANCE.get(player.getUniqueId()) && !player.isOnGround()
&& Utilities.isNotNearSlime(distance.getTo().getBlock()) && fallDistance < 1.5) {
// TODO that fallDistance check is a horrible way to prevent a certain false positive
// Needs to be fixed since this only works for slight above ground movements
float predicted = calculateNextMotionY(LAST_MOTION_Y.get(player.getUniqueId()).floatValue());
float actual = Double.valueOf(motionY).floatValue();
float scaledDifference = Math.abs((predicted - actual) + 0.1568f);
if (scaledDifference > 3E-8) {
if (violations + 1 >= AntiCheatReloaded.getManager().getBackend().getMagic().GLIDE_LIMIT()
&& !Utilities.canStand(distance.getTo().getBlock())) {
VIOLATIONS.put(player.getUniqueId(), 1);
if (!AntiCheatReloaded.getManager().getBackend().silentMode()) {
Location prev = player.getLocation().clone();
prev.setY(prev.getY() - distanceToFall(prev));
player.teleport(AntiCheatReloaded.getManager().getUserManager()
.getUser(player.getUniqueId()).getGoodLocation(prev));
}
return new CheckResult(CheckResult.Result.FAILED, "type=gravity, offset="
+ new BigDecimal(scaledDifference).setScale(2, RoundingMode.HALF_UP) + ")");
} else {
VIOLATIONS.put(player.getUniqueId(), violations + 1);
return PASS;
}
}
}
}
LAST_DIFFERENCE.put(player.getUniqueId(), distance.getYDifference());
LAST_MOTION_Y.put(player.getUniqueId(), distance.getYDifference());
LAST_FALL_DISTANCE.put(player.getUniqueId(), player.getFallDistance());
if (violations > Math.round(AntiCheatReloaded.getManager().getBackend().getMagic().GLIDE_LIMIT() / 2)) {
VIOLATIONS.put(player.getUniqueId(), violations - 1);
}
return PASS;
}
private static float calculateNextMotionY(float motionY) {
return (motionY - 0.08f) * 0.98f;
}
private static double distanceToFall(Location location) {
location = location.clone();
double highestY = location.getWorld().getHighestBlockYAt(location) + 1.02D;
@@ -1,111 +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 <http://www.gnu.org/licenses/>.
*/
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.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.event.EventListener;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
/**
* @author Rammelkast
*/
public class MorePacketsCheck {
public static final Map<UUID, Integer> MOVE_COUNT = new HashMap<UUID, Integer>();
public static void startTimer() {
new BukkitRunnable() {
@Override
public void run() {
MOVE_COUNT.clear();
}
}.runTaskTimer(AntiCheatReloaded.getPlugin(), 20, 20);
}
public static void listenPackets() {
AntiCheatReloaded.getProtocolManager()
.addPacketListener(new PacketAdapter(AntiCheatReloaded.getPlugin(), ListenerPriority.LOWEST,
new PacketType[] { PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK }) {
@Override
public void onPacketReceiving(PacketEvent e) {
Player player = e.getPlayer();
if (!AntiCheatReloaded.getManager().getCheckManager().willCheck(player,
CheckType.MOREPACKETS)) {
return;
}
Location cur = e.getPlayer().getLocation();
if (!MOVE_COUNT.containsKey(player.getUniqueId())) {
MOVE_COUNT.put(player.getUniqueId(), 1);
} else {
MOVE_COUNT.put(player.getUniqueId(), MOVE_COUNT.get(player.getUniqueId()) + 1);
int ping = VersionUtil.getPlayerPing(player);
int limit = AntiCheatReloaded.getManager().getBackend().getMagic().MOREPACKETS_LIMIT();
int averagePing = AntiCheatReloaded.getManager().getBackend().getMagic()
.MOREPACKETS_AVERAGE_PING();
float pingLeniency = (float) ((ping / averagePing));
if (pingLeniency < 1)
pingLeniency = 1;
if (pingLeniency > 2.5F)
pingLeniency = 2.5F;
limit = Math.round(pingLeniency * limit);
final float finalPingLeniency = pingLeniency;
try {
if (MOVE_COUNT.get(player.getUniqueId()) > limit) {
final int packets = MOVE_COUNT.get(player.getUniqueId());
MOVE_COUNT.remove(player.getUniqueId());
AntiCheatReloaded.sendToMainThread(new Runnable() {
@Override
public void run() {
EventListener.log(
new CheckResult(CheckResult.Result.FAILED,
"sent " + packets + " packets in one second (max="
+ AntiCheatReloaded.getManager().getBackend()
.getMagic().MOREPACKETS_LIMIT()
+ ", leniency=" + finalPingLeniency + ", ping="
+ ping + ")").getMessage(),
player, CheckType.MOREPACKETS);
e.setCancelled(true);
e.getPlayer().teleport(cur);
}
});
}
} catch (NullPointerException nullPointer) {
// TODO this is thrown sometimes, might have something to do with line 83
}
}
}
});
}
}
@@ -28,7 +28,9 @@ import org.bukkit.entity.Player;
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.util.Utilities;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
/**
@@ -39,36 +41,36 @@ public class SpeedCheck {
public static final Map<UUID, Integer> SPEED_VIOLATIONS = new HashMap<UUID, Integer>();
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static boolean isSpeedExempt(Player player) {
return AntiCheatReloaded.getManager().getBackend().isMovingExempt(player)
|| AntiCheatReloaded.getManager().getBackend().justVelocity(player) || VersionUtil.isFlying(player);
public static boolean isSpeedExempt(Player player, Backend backend) {
return backend.isMovingExempt(player) || backend.justVelocity(player) || VersionUtil.isFlying(player);
}
public static CheckResult checkXZSpeed(Player player, double x, double z) {
if (!isSpeedExempt(player) && player.getVehicle() == null) {
Backend backend = AntiCheatReloaded.getManager().getBackend();
if (!isSpeedExempt(player, backend) && player.getVehicle() == null) {
String reason = "";
double max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX();
double max = backend.getMagic().XZ_SPEED_MAX();
if (player.getLocation().getBlock().getType() == Material.SOUL_SAND) {
if (player.isSprinting()) {
reason = "on soulsand while sprinting ";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_SOULSAND_SPRINT();
max = backend.getMagic().XZ_SPEED_MAX_SOULSAND_SPRINT();
} else if (player.hasPotionEffect(PotionEffectType.SPEED)) {
reason = "on soulsand with speed potion ";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_SOULSAND_POTION();
max = backend.getMagic().XZ_SPEED_MAX_SOULSAND_POTION();
} else {
reason = "on soulsand ";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_SOULSAND();
max = backend.getMagic().XZ_SPEED_MAX_SOULSAND();
}
} else if (VersionUtil.isFlying(player)) {
reason = "while flying ";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_FLY();
max = backend.getMagic().XZ_SPEED_MAX_FLY();
} else if (player.hasPotionEffect(PotionEffectType.SPEED)) {
if (player.isSprinting()) {
reason = "with speed potion while sprinting ";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_POTION_SPRINT();
max = backend.getMagic().XZ_SPEED_MAX_POTION_SPRINT();
} else {
reason = "with speed potion ";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_POTION();
max = backend.getMagic().XZ_SPEED_MAX_POTION();
}
} else if (player.isSprinting()) {
String blockDownName = player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType().name();
@@ -77,16 +79,16 @@ public class SpeedCheck {
if (player.getLocation().getBlock().getType().name().endsWith("TRAPDOOR")) {
reason = "while boosting on " + blockDownName.toLowerCase().replaceAll("_", " ")
+ " and trapdoor";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_SPRINT()
max = backend.getMagic().XZ_SPEED_MAX_SPRINT()
+ (blockDownName.equals("BLUE_ICE") ? 0.35925D : 0.35D);
} else {
reason = "while boosting on " + blockDownName.toLowerCase().replaceAll("_", " ") + " ";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_SPRINT()
max = backend.getMagic().XZ_SPEED_MAX_SPRINT()
+ (blockDownName.equals("BLUE_ICE") ? 0.20925D : 0.2D);
}
} else {
reason = "while sprinting ";
max = AntiCheatReloaded.getManager().getBackend().getMagic().XZ_SPEED_MAX_SPRINT();
max = backend.getMagic().XZ_SPEED_MAX_SPRINT();
}
}
@@ -94,13 +96,12 @@ public class SpeedCheck {
max += speed > 0 ? player.getWalkSpeed() - 0.2f : 0;
if (x > max || z > max) {
int num = AntiCheatReloaded.getManager().getBackend().increment(player, SPEED_VIOLATIONS,
AntiCheatReloaded.getManager().getBackend().getMagic().SPEED_MAX());
if (num >= AntiCheatReloaded.getManager().getBackend().getMagic().SPEED_MAX()) {
int num = backend.increment(player, SPEED_VIOLATIONS, backend.getMagic().SPEED_MAX());
if (num >= backend.getMagic().SPEED_MAX()) {
return new CheckResult(CheckResult.Result.FAILED,
"speed was too high " + reason + num + " times in a row (max="
+ AntiCheatReloaded.getManager().getBackend().getMagic().SPEED_MAX() + ", speed="
+ (x > z ? x : z) + ", max speed=" + max + ")");
+ backend.getMagic().SPEED_MAX() + ", speed=" + (x > z ? x : z) + ", max speed="
+ max + ")");
} else {
return PASS;
}
@@ -113,4 +114,19 @@ public class SpeedCheck {
}
}
public CheckResult checkYSpeed(Player player, double y) {
Backend backend = AntiCheatReloaded.getManager().getBackend();
if (!backend.isMovingExempt(player) && !player.isInsideVehicle() && !player.isSleeping()
&& (y > backend.getMagic().Y_SPEED_MAX())
&& !backend.isDoing(player, backend.velocitized, backend.getMagic().VELOCITY_TIME())
&& !player.hasPotionEffect(PotionEffectType.JUMP) && !VersionUtil.isFlying(player)
&& !Utilities.isSlime(AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId())
.getGoodLocation(player.getLocation()).getBlock())) {
return new CheckResult(CheckResult.Result.FAILED,
"y speed was too high (speed=" + y + ", max=" + backend.getMagic().Y_SPEED_MAX() + ")");
} else {
return PASS;
}
}
}
@@ -30,6 +30,7 @@ import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.Backend;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.util.Utilities;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
@@ -46,6 +47,7 @@ public class WaterWalkCheck {
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static CheckResult runCheck(Player player, double x, double y, double z) {
Backend backend = AntiCheatReloaded.getManager().getBackend();
Block block = player.getLocation().getBlock();
UUID uuid = player.getUniqueId();
@@ -56,15 +58,11 @@ public class WaterWalkCheck {
if (player.getNearbyEntities(1, 1, 1).isEmpty()) {
boolean violation;
if (!Utilities.sprintFly(player)) {
violation = x > AntiCheatReloaded.getManager().getBackend().getMagic()
.XZ_SPEED_MAX_WATER()
|| z > AntiCheatReloaded.getManager().getBackend().getMagic()
.XZ_SPEED_MAX_WATER();
violation = x > backend.getMagic().XZ_SPEED_MAX_WATER()
|| z > backend.getMagic().XZ_SPEED_MAX_WATER();
} else {
violation = x > AntiCheatReloaded.getManager().getBackend().getMagic()
.XZ_SPEED_MAX_WATER_SPRINT()
|| z > AntiCheatReloaded.getManager().getBackend().getMagic()
.XZ_SPEED_MAX_WATER_SPRINT();
violation = x > backend.getMagic().XZ_SPEED_MAX_WATER_SPRINT()
|| z > backend.getMagic().XZ_SPEED_MAX_WATER_SPRINT();
}
if (!violation && !Utilities.isFullyInWater(player.getLocation())
&& Utilities.isHoveringOverWater(player.getLocation(), 1) && y == 0D
@@ -74,8 +72,7 @@ public class WaterWalkCheck {
if (violation) {
if (WATER_SPEED_VIOLATIONS.containsKey(uuid)) {
int v = WATER_SPEED_VIOLATIONS.get(uuid);
if (v >= AntiCheatReloaded.getManager().getBackend().getMagic()
.WATER_SPEED_VIOLATION_MAX()) {
if (v >= backend.getMagic().WATER_SPEED_VIOLATION_MAX()) {
WATER_SPEED_VIOLATIONS.put(uuid, 0);
return new CheckResult(CheckResult.Result.FAILED,
"stood on water " + v + " times (can't stand on " + block.getType()
@@ -96,13 +93,13 @@ public class WaterWalkCheck {
IS_IN_WATER.add(uuid);
return PASS;
}
} else if (block.getRelative(BlockFace.DOWN).isLiquid()
&& !AntiCheatReloaded.getManager().getBackend().isAscending(player) && Utilities.cantStandAt(block)
&& Utilities.cantStandAt(block.getRelative(BlockFace.DOWN)) && (y < 0.025
|| y == 0.09999999999999964 || y == 0.14999999999999947 || y == 0.04999999999999982)) {
} else if (block.getRelative(BlockFace.DOWN).isLiquid() && !backend.isAscending(player)
&& Utilities.cantStandAt(block) && Utilities.cantStandAt(block.getRelative(BlockFace.DOWN))
&& (y < 0.025 || y == 0.09999999999999964 || y == 0.14999999999999947
|| y == 0.04999999999999982)) {
if (WATER_ASCENSION_VIOLATIONS.containsKey(uuid)) {
int v = WATER_ASCENSION_VIOLATIONS.get(uuid);
if (v >= AntiCheatReloaded.getManager().getBackend().getMagic().WATER_ASCENSION_VIOLATION_MAX()) {
if (v >= backend.getMagic().WATER_ASCENSION_VIOLATION_MAX()) {
WATER_ASCENSION_VIOLATIONS.put(uuid, 0);
return new CheckResult(CheckResult.Result.FAILED,
"stood on water " + v + " times (can't stand on " + block.getType() + " or "
@@ -77,12 +77,12 @@ 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 || g.getBlock().getType() == Material.CAVE_AIR) {
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 ="
"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()
@@ -95,7 +95,7 @@ public class YAxisCheck {
}
long i = System.currentTimeMillis() - LAST_Y_TIME.get(uuid);
double diff = AntiCheatReloaded.getManager().getBackend().getMagic().Y_MAXDIFF()
+ (Utilities.isStair(player.getLocation().add(0, -1, 0).getBlock()) ? 0.5 : 0.0);
+ ((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();
@@ -103,11 +103,11 @@ 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 || g.getBlock().getType() == Material.CAVE_AIR) {
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 ="
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()
@@ -125,8 +125,7 @@ public class YAxisCheck {
}
public static boolean isMoveUpBlock(Block block) {
Material type = block.getType();
return type.name().endsWith("STAIRS"); // TODO slabs/others?
return Utilities.isStair(block);
}
}
@@ -0,0 +1,80 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.check.packet;
import java.math.BigDecimal;
import java.math.RoundingMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
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.event.EventListener;
public class BadPacketsCheck {
public static void runCheck(Player player, PacketEvent event) {
Backend backend = AntiCheatReloaded.getManager().getBackend();
if (!AntiCheatReloaded.getManager().getCheckManager().willCheck(player, CheckType.BADPACKETS)
|| backend.isMovingExempt(player)) {
return;
}
PacketContainer packet = event.getPacket();
float pitch = packet.getFloat().read(1);
// Check for derp
if (Math.abs(pitch) > 90) {
flag(player, event, "had an illegal pitch");
return;
}
double x = packet.getDoubles().read(0);
double y = packet.getDoubles().read(1);
double z = packet.getDoubles().read(2);
float yaw = packet.getFloat().read(0);
// Create location from new data
Location previous = player.getLocation();
Location current = new Location(previous.getWorld(), x, y, z, yaw, pitch);
double distance = previous.distanceSquared(current);
double maxDistance = backend.getMagic().BADPACKETS_MAX_DISTANCE();
if (distance > maxDistance) {
flag(player, event, "moved too far between packets (distance=" + new BigDecimal(distance).setScale(1, RoundingMode.HALF_UP) + ", max=" + maxDistance + ")");
return;
}
}
private static void flag(Player player, PacketEvent event, String message) {
event.setCancelled(true);
// We are currently not in the main server thread, so switch
AntiCheatReloaded.sendToMainThread(new Runnable() {
@Override
public void run() {
EventListener.log(new CheckResult(CheckResult.Result.FAILED, message).getMessage(), player,
CheckType.MOREPACKETS);
player.teleport(player.getLocation());
}
});
}
}
@@ -0,0 +1,105 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.check.packet;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import com.comphenix.protocol.events.PacketEvent;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.CheckResult;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.event.EventListener;
/**
* @author Rammelkast
*/
public class MorePacketsCheck {
public static final Map<UUID, Integer> MOVE_COUNT = new HashMap<UUID, Integer>();
public static void startTimer() {
new BukkitRunnable() {
@Override
public void run() {
MOVE_COUNT.clear();
}
}.runTaskTimer(AntiCheatReloaded.getPlugin(), 20, 20);
}
public static void runCheck(Player player, PacketEvent event) {
// Confirm if we should even check for MorePackets
// If your TPS is lower than 15 you are running a shitshow
double tps = AntiCheatReloaded.getPlugin().getTPS();
if (!AntiCheatReloaded.getManager().getCheckManager().willCheck(player, CheckType.MOREPACKETS) || tps < 15) {
return;
}
Location currentLocation = event.getPlayer().getLocation();
if (!MOVE_COUNT.containsKey(player.getUniqueId())) {
MOVE_COUNT.put(player.getUniqueId(), 1);
} else {
MOVE_COUNT.put(player.getUniqueId(), MOVE_COUNT.get(player.getUniqueId()) + 1);
int ping = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId()).getPing();
int limit = AntiCheatReloaded.getManager().getBackend().getMagic().MOREPACKETS_LIMIT();
int averagePing = AntiCheatReloaded.getManager().getBackend().getMagic().MOREPACKETS_AVERAGE_PING();
float pingLeniency = (float) ((ping / averagePing));
if (pingLeniency < 1)
pingLeniency = 1;
if (pingLeniency > 2)
pingLeniency = 2;
float tpsLeniency = (float) ((19 / tps));
if (tps > 19) {
tpsLeniency = 1;
}
float leniency = pingLeniency * tpsLeniency;
limit = Math.round(leniency * limit);
final float finalLeniency = leniency;
try {
if (MOVE_COUNT.get(player.getUniqueId()) > limit) {
final int packets = MOVE_COUNT.get(player.getUniqueId());
MOVE_COUNT.remove(player.getUniqueId());
event.setCancelled(true);
// We are currently not in the main server thread, so switch
AntiCheatReloaded.sendToMainThread(new Runnable() {
@Override
public void run() {
EventListener
.log(new CheckResult(CheckResult.Result.FAILED,
"sent " + packets + " packets in one second (max="
+ AntiCheatReloaded.getManager().getBackend().getMagic()
.MOREPACKETS_LIMIT()
+ ", leniency=" + finalLeniency + ")").getMessage(),
player, CheckType.MOREPACKETS);
player.teleport(currentLocation);
}
});
}
} catch (NullPointerException nullPointer) {
// TODO this is thrown sometimes, might have something to do with line 83
}
}
}
}
@@ -386,4 +386,8 @@ public interface Magic {
* The minimum time it takes to regenerate health; TYPE=INTEGER, Leniency=DECREASE
*/
public int MIN_HEAL_TIME();
/**
* Maximum distance allowed between two movement packets; Type=DOUBLE, Leniency=INCREASE.
*/
public double BADPACKETS_MAX_DISTANCE();
}
@@ -19,6 +19,12 @@
package com.rammelkast.anticheatreloaded.event;
import java.text.DecimalFormat;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
@@ -27,129 +33,131 @@ import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.Backend;
import com.rammelkast.anticheatreloaded.check.CheckType;
import com.rammelkast.anticheatreloaded.config.Configuration;
import com.rammelkast.anticheatreloaded.manage.*;
import com.rammelkast.anticheatreloaded.manage.AntiCheatManager;
import com.rammelkast.anticheatreloaded.manage.CheckManager;
import com.rammelkast.anticheatreloaded.manage.UserManager;
import com.rammelkast.anticheatreloaded.util.User;
import com.rammelkast.anticheatreloaded.util.VersionUtil;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class EventListener implements Listener {
private static final Map<CheckType, Integer> USAGE_LIST = new EnumMap<CheckType, Integer>(CheckType.class);
private static final Map<UUID, Integer> DECREASE_LIST = new HashMap<UUID, Integer>();
private static final CheckManager CHECK_MANAGER = AntiCheatReloaded.getManager().getCheckManager();
private static final Backend BACKEND = AntiCheatReloaded.getManager().getBackend();
private static final AntiCheatReloaded PLUGIN = AntiCheatReloaded.getManager().getPlugin();
private static final UserManager USER_MANAGER = AntiCheatReloaded.getManager().getUserManager();
private static final Configuration CONFIG = AntiCheatReloaded.getManager().getConfiguration();
private static final Map<CheckType, Integer> USAGE_LIST = new EnumMap<CheckType, Integer>(CheckType.class);
private static final Map<UUID, Integer> DECREASE_LIST = new HashMap<UUID, Integer>();
private static final CheckManager CHECK_MANAGER = AntiCheatReloaded.getManager().getCheckManager();
private static final Backend BACKEND = AntiCheatReloaded.getManager().getBackend();
private static final AntiCheatReloaded PLUGIN = AntiCheatReloaded.getManager().getPlugin();
private static final UserManager USER_MANAGER = AntiCheatReloaded.getManager().getUserManager();
private static final Configuration CONFIG = AntiCheatReloaded.getManager().getConfiguration();
private static final DecimalFormat TPS_FORMAT = new DecimalFormat("##.##");
public static void log(String message, Player player, CheckType type) {
User user = getUserManager().getUser(player.getUniqueId());
if (message == null || message.equals("")) {
message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.GRAY + player.getName() + " failed "
+ CheckType.getName(type);
} else {
message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.GRAY + player.getName() + " failed "
+ CheckType.getName(type) + ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + message
+ ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + "ping: " + user.getPing() + "ms"
+ ", tps: " + TPS_FORMAT.format(AntiCheatReloaded.getPlugin().getTPS());
}
if (user != null) { // npc
logCheat(type, user);
if (user.increaseLevel(type)) {
AntiCheatReloaded.getManager().log(message);
}
removeDecrease(user);
}
public static void log(String message, Player player, CheckType type) {
User user = getUserManager().getUser(player.getUniqueId());
if (message == null || message.equals("")) {
message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.GRAY + player.getName() + " failed " + CheckType.getName(type);
} else {
message = ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.GRAY + player.getName() + " failed " + CheckType.getName(type) + ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + message + ChatColor.DARK_GRAY + " | " + ChatColor.GRAY + "ping: " + VersionUtil.getPlayerPing(player) + "ms";
}
if (user != null) { // npc
logCheat(type, user);
if (user.increaseLevel(type)) {
AntiCheatReloaded.getManager().log(message);
}
removeDecrease(user);
}
if (CONFIG.getConfig().debugMode.getValue()) {
player.sendMessage(message);
} else {
AntiCheatReloaded.getPlugin().sendToStaff(message);
}
}
if (CONFIG.getConfig().debugMode.getValue()) {
player.sendMessage(message);
} else {
AntiCheatReloaded.getPlugin().sendToStaff(message);
}
}
private static void logCheat(CheckType type, User user) {
USAGE_LIST.put(type, getCheats(type) + 1);
// Ignore plugins that are creating NPCs with no names (why the hell)
if (user != null && user.getUUID() != null) {
type.logUse(user);
if (CONFIG.getConfig().enterprise.getValue() && CONFIG.getEnterprise().loggingEnabled.getValue()) {
CONFIG.getEnterprise().database.logEvent(user, type);
}
}
}
private static void logCheat(CheckType type, User user) {
USAGE_LIST.put(type, getCheats(type) + 1);
// Ignore plugins that are creating NPCs with no names (why the hell)
if (user != null && user.getUUID() != null) {
type.logUse(user);
if (CONFIG.getConfig().enterprise.getValue() && CONFIG.getEnterprise().loggingEnabled.getValue()) {
CONFIG.getEnterprise().database.logEvent(user, type);
}
}
}
public void resetCheck(CheckType type) {
USAGE_LIST.put(type, 0);
}
public void resetCheck(CheckType type) {
USAGE_LIST.put(type, 0);
}
public static int getCheats(CheckType type) {
int x = 0;
if (USAGE_LIST.get(type) != null) {
x = USAGE_LIST.get(type);
}
return x;
}
public static int getCheats(CheckType type) {
int x = 0;
if (USAGE_LIST.get(type) != null) {
x = USAGE_LIST.get(type);
}
return x;
}
private static void removeDecrease(User user) {
int x = 0;
// Ignore plugins that are creating NPCs with no names
if (user.getUUID() != null) {
if (DECREASE_LIST.get(user.getUUID()) != null) {
x = DECREASE_LIST.get(user.getUUID());
x -= 2;
if (x < 0) {
x = 0;
}
}
DECREASE_LIST.put(user.getUUID(), x);
}
}
private static void removeDecrease(User user) {
int x = 0;
// Ignore plugins that are creating NPCs with no names
if (user.getUUID() != null) {
if (DECREASE_LIST.get(user.getUUID()) != null) {
x = DECREASE_LIST.get(user.getUUID());
x -= 2;
if (x < 0) {
x = 0;
}
}
DECREASE_LIST.put(user.getUUID(), x);
}
}
public static void decrease(Player player) {
User user = getUserManager().getUser(player.getUniqueId());
// Ignore plugins that are creating NPCs with no names
if (user.getUUID() != null) {
int x = 0;
public static void decrease(Player player) {
User user = getUserManager().getUser(player.getUniqueId());
// Ignore plugins that are creating NPCs with no names
if (user.getUUID() != null) {
int x = 0;
if (DECREASE_LIST.get(user.getUUID()) != null) {
x = DECREASE_LIST.get(user.getUUID());
}
if (DECREASE_LIST.get(user.getUUID()) != null) {
x = DECREASE_LIST.get(user.getUUID());
}
x += 1;
DECREASE_LIST.put(user.getUUID(), x);
x += 1;
DECREASE_LIST.put(user.getUUID(), x);
if (x >= 10) {
user.decreaseLevel();
DECREASE_LIST.put(user.getUUID(), 0);
}
}
}
if (x >= 10) {
user.decreaseLevel();
DECREASE_LIST.put(user.getUUID(), 0);
}
}
}
public static CheckManager getCheckManager() {
return CHECK_MANAGER;
}
public static CheckManager getCheckManager() {
return CHECK_MANAGER;
}
public static AntiCheatManager getManager() {
return AntiCheatReloaded.getManager();
}
public static AntiCheatManager getManager() {
return AntiCheatReloaded.getManager();
}
public static Backend getBackend() {
return BACKEND;
}
public static Backend getBackend() {
return BACKEND;
}
public static UserManager getUserManager() {
return USER_MANAGER;
}
public static UserManager getUserManager() {
return USER_MANAGER;
}
public static AntiCheatReloaded getPlugin() {
return PLUGIN;
}
public static AntiCheatReloaded getPlugin() {
return PLUGIN;
}
public static Configuration getConfig() {
return CONFIG;
}
public static Configuration getConfig() {
return CONFIG;
}
public static boolean silentMode() {
return CONFIG.getConfig().silentMode.getValue();
}
public static boolean silentMode() {
return CONFIG.getConfig().silentMode.getValue();
}
}
@@ -44,6 +44,7 @@ import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.event.player.PlayerToggleFlightEvent;
@@ -465,9 +466,8 @@ public class PlayerListener extends EventListener {
}
@EventHandler(priority=EventPriority.HIGHEST)
public void onDeath(PlayerDeathEvent e) {
//KillAuraCheck.cleanPlayer(e.getEntity()); // Remove bots on death to reduce lag
//TODO
public void onRespawn(PlayerRespawnEvent event) {
getBackend().logTeleport(event.getPlayer());
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@@ -30,6 +30,7 @@ public class Distance {
private final double ZDiff;
private final Location from;
private final Location to;
public Distance(Location from, Location to) {
l1Y = to.getY();
@@ -40,6 +41,7 @@ public class Distance {
YDiff = Math.abs(l1Y - l2Y);
this.from = from;
this.to = to;
}
public double fromY() {
@@ -65,4 +67,8 @@ public class Distance {
public Location getFrom() {
return this.from;
}
public Location getTo() {
return this.to;
}
}
@@ -0,0 +1,70 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
package com.rammelkast.anticheatreloaded.util;
import org.bukkit.entity.Player;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
import com.rammelkast.anticheatreloaded.check.packet.BadPacketsCheck;
import com.rammelkast.anticheatreloaded.check.packet.MorePacketsCheck;
public 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 }) {
@Override
public void onPacketReceiving(PacketEvent event) {
Player player = event.getPlayer();
// Run MorePackets check
MorePacketsCheck.runCheck(player, event);
if (!event.isCancelled()) {
// Run BadPackets check
BadPacketsCheck.runCheck(player, event);
}
}
});
}
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();
}
});
}
}
@@ -26,7 +26,7 @@ public enum Permission {
CHECK_FLIGHT, CHECK_ELYTRA, CHECK_WATERWALK, CHECK_NOSWING, CHECK_FASTBREAK,
CHECK_FASTPLACE, CHECK_CHATSPAM, CHECK_COMMANDSPAM, CHECK_SPRINT, CHECK_SNEAK, CHECK_SPEED, CHECK_VCLIP,
CHECK_SPIDER, CHECK_NOFALL, CHECK_FASTBOW, CHECK_FASTEAT, CHECK_FASTHEAL, CHECK_KILLAURA, CHECK_LONGREACH, CHECK_UNICODE,
CHECK_FASTPROJECTILE, CHECK_ITEMSPAM, CHECK_VISUAL, CHECK_FASTINVENTORY, CHECK_AUTOTOOL, CHECK_MOREPACKETS, CHECK_VELOCITY, CHECK_CRITICALS, CHECK_ILLEGAL_INTERACT,
CHECK_FASTPROJECTILE, CHECK_ITEMSPAM, CHECK_VISUAL, CHECK_FASTINVENTORY, CHECK_AUTOTOOL, CHECK_MOREPACKETS, CHECK_BADPACKETS, CHECK_VELOCITY, CHECK_CRITICALS, CHECK_ILLEGAL_INTERACT,
/* System Nodes */
SYSTEM_LOG, SYSTEM_RESET, SYSTEM_HELP, SYSTEM_VERSION, SYSTEM_REPORT, SYSTEM_ALERT, SYSTEM_NOTICE,
@@ -52,6 +52,10 @@ public class User {
private boolean isWaitingOnLevelSync;
private Timestamp levelSyncTimestamp;
private long lastServerPing, lastClientPong;
private int ping = -1;
private int lastPing = -1;
/**
* Initialize an AntiCheat user
*
@@ -63,16 +67,6 @@ public class User {
this.id = getPlayer() != null && getPlayer().isOnline() ? getPlayer().getEntityId() : -1;
}
/**
* Initialize an AntiCheat user
*
* @param name Player's name
*/
/*
* public User(String name) { this.uuid = Bukkit.getPlayer(name).getUniqueId();
* this.name = name; this.id = getPlayer() != null && getPlayer().isOnline() ?
* getPlayer().getEntityId() : -1; }
*/
/**
* Get the player's UUID
*
@@ -429,6 +423,36 @@ public class User {
return levelSyncTimestamp;
}
public void onServerPing() {
this.lastServerPing = System.currentTimeMillis();
}
public void onClientPong() {
this.lastClientPong = System.currentTimeMillis();
this.lastPing = this.ping;
this.ping = (int) (this.lastClientPong - this.lastServerPing);
}
public int getPing() {
int ping = this.ping;
if (ping < 0) {
return VersionUtil.getPlayerPing(this.getPlayer());
}
return ping;
}
public int getLastPing() {
int lastPing = this.lastPing;
if (lastPing < 0) {
return this.getPing();
}
return lastPing;
}
public boolean isLagging() {
return Math.abs(this.ping - this.lastPing) > 50;
}
@Override
public String toString() {
return "User {name = " + getName() + ", level = " + level + "}";
@@ -112,6 +112,15 @@ public final class Utilities {
return !(block.isLiquid() || block.getType() == Material.AIR);
}
public static boolean isSlime(Block block) {
return block.getType() == Material.SLIME_BLOCK;
}
public static boolean isNotNearSlime(Block block) {
return !isSlime(block.getRelative(BlockFace.NORTH)) && !isSlime(block.getRelative(BlockFace.EAST))
&& !isSlime(block.getRelative(BlockFace.SOUTH)) && !isSlime(block.getRelative(BlockFace.WEST));
}
/**
* Determine whether a player is fully submerged in water
*
@@ -551,6 +560,13 @@ public final class Utilities {
float error = Math.max(dividend, divisor) * 1E-3F;
return (int) (ans + error);
}
public static boolean isHoneyBlock(Block block) {
if (!VersionUtil.isOfVersion("v1_15")) {
return false;
}
return block.getType() == Material.HONEY_BLOCK;
}
static {
// Start 1.8.8