added files.

This commit is contained in:
nitrogenoliquido committed 2026-11-21 21:15:24 -05:00
commit 5c944d5935
213 files changed
+63425

No files matched your search

+201
View File
@@ -0,0 +1,201 @@
package me.konsolas.aac;
import com.comphenix.protocol.ProtocolLibrary;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import me.konsolas.aac.api.AACAPI;
import me.konsolas.aac.checks.CheckManager;
import me.konsolas.aac.checks.EnablePluginTask;
import me.konsolas.aac.checks.combat.RecentCombatTracker;
import me.konsolas.aac.checks.movement.PlayerEventStateTracker;
import me.konsolas.aac.checks.movement.SetbackManager;
import me.konsolas.aac.command.CommandController;
import me.konsolas.aac.command.CommandRegistrar;
import me.konsolas.aac.compat.CollisionAccess;
import me.konsolas.aac.compat.ServerVersionAccess;
import me.konsolas.aac.gui.InventoryMenu;
import me.konsolas.aac.hooks.McMmoHook;
import me.konsolas.aac.metrics.MetricsLite;
import me.konsolas.aac.punishment.LogManager;
import me.konsolas.aac.punishment.PunishmentManager;
import me.konsolas.aac.util.LanguageConfig;
import me.konsolas.aac.util.TickRateManager;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
public class AAC
extends JavaPlugin
implements Listener {
public static volatile AACAPI api = null;
public static String messagePrefix = "\u00a76[AAC] \u00a7r> \u00a76";
public static final Random random = new Random();
public static ServerVersionAccess serverVersion;
private static AAC instance;
private final AAC plugin = this;
public LogManager logManager;
public LanguageConfig messages;
public TickRateManager tickRateManager;
public PlayerEventStateTracker playerState;
public SetbackManager setbackManager;
public CheckManager checkManager;
public RecentCombatTracker combatTracker;
public PunishmentManager punishmentManager;
public CommandController commandController;
private final SimpleDateFormat logFilenameDateFormat = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
private final SimpleDateFormat logTimestampFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss.SSS");
private FileWriter logFileWriter;
private PrintWriter logWriter;
public static AAC getInstance() {
return instance;
}
public void onEnable() {
instance = this;
Server server = this.getServer();
for (World world : server.getWorlds()) {
Entity entity = world.spawnEntity(new Location(world, 0.0, 0.0, 0.0), EntityType.ARMOR_STAND);
entity.remove();
}
new MetricsLite(this);
serverVersion = new ServerVersionAccess(Bukkit.getVersion());
CollisionAccess.isValidLocation((Location)null);
CommandController commandController = new CommandController(this);
this.commandController = commandController;
PluginManager pluginManager = server.getPluginManager();
pluginManager.registerEvents((Listener)this, (Plugin)this);
pluginManager.registerEvents((Listener)commandController, (Plugin)this);
this.checkManager = new CheckManager(this);
this.setbackManager = new SetbackManager(this);
pluginManager.registerEvents((Listener)this.setbackManager, (Plugin)this);
if (this.getConfig().getBoolean("usetps")) {
this.tickRateManager = new TickRateManager(this);
}
this.logManager = new LogManager(this);
this.saveDefaultConfig();
this.openLog();
this.reloadConfig();
CommandRegistrar.registerCommands(this, commandController);
server.getScheduler().scheduleSyncDelayedTask((Plugin)this, (Runnable)new EnablePluginTask(this), 10L);
}
@EventHandler
public void onPlayerLogin(PlayerLoginEvent playerLoginEvent) {
if (api == null) {
playerLoginEvent.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server still starting up");
}
}
private void initializeHooks() {
Server server = Bukkit.getServer();
String str = "mcMMO";
PluginManager pluginManager = server.getPluginManager();
if (pluginManager.getPlugin(str) != null) {
Bukkit.getLogger().info("[AAC] Detected mcMMO, setting up hooks...");
Server server2 = Bukkit.getServer();
AAC aAC = this;
AAC aAC2 = this;
McMmoHook mcMmoHook = new McMmoHook(aAC);
PluginManager pluginManager2 = server2.getPluginManager();
pluginManager2.registerEvents((Listener)mcMmoHook, (Plugin)aAC2);
}
}
public void onDisable() {
try {
api = null;
Bukkit.getLogger().info("[AAC] Disabling checks...");
this.playerState.cleanup();
this.punishmentManager.saveBannedPlayers();
InventoryMenu.resetClickListener();
HandlerList.unregisterAll((Listener)this);
Server server = Bukkit.getServer();
server.getScheduler().cancelTasks((Plugin)this);
ProtocolLibrary.getProtocolManager().removePacketListeners((Plugin)this);
this.checkManager = null;
this.closeLog();
}
catch (NullPointerException nullPointerException) {}
}
public void openLog() {
try {
if (!this.getConfig().getBoolean("log_file", true)) {
Bukkit.getLogger().warning("[AAC] Logger functionality has been disabled in the configuration file.");
return;
}
File file = new File(this.getDataFolder(), "logs");
if (!file.exists() && !file.mkdir()) {
throw new IOException("Failed to create data dir");
}
Date date = new Date();
File file2 = new File(this.getDataFolder(), "logs/aac_" + this.logFilenameDateFormat.format(date) + ".log");
if (!file2.exists() && !file2.createNewFile()) {
throw new IOException("Failed to create new file");
}
this.logFileWriter = new FileWriter(file2, true);
this.logWriter = new PrintWriter(this.logFileWriter);
}
catch (IOException iOException) {
Bukkit.getLogger().severe("[AAC] Error: Could not setup log file for writing");
Bukkit.getLogger().severe("[AAC] " + iOException.getMessage());
Bukkit.getLogger().severe("[AAC] Logger functionality has been disabled.");
}
}
private void closeLog() {
try {
Bukkit.getLogger().info("[AAC] Saving log file...");
this.logWriter.close();
}
catch (NullPointerException nullPointerException) {
Bukkit.getLogger().warning("[AAC] Could not save log file as none was created.");
}
}
public void writeLog(String str) {
if (this.logWriter != null) {
Date date = new Date();
this.logWriter.println("[" + this.logTimestampFormat.format(date) + "] " + str);
this.logWriter.flush();
}
}
public void reloadPlugin() {
Bukkit.getLogger().info("[AAC] Beginning disable...");
Server server = Bukkit.getServer();
AAC aAC = this;
PluginManager pluginManager = server.getPluginManager();
pluginManager.disablePlugin((Plugin)aAC);
ProtocolLibrary.getProtocolManager().removePacketListeners((Plugin)this);
Server server2 = Bukkit.getServer();
AAC aAC2 = this;
PluginManager pluginManager2 = server2.getPluginManager();
pluginManager2.enablePlugin((Plugin)aAC2);
}
public static AAC getPlugin(AAC aAC) {
return aAC.plugin;
}
public static void initializeHooks(AAC aAC) {
aAC.initializeHooks();
}
}
@@ -0,0 +1,29 @@
package me.konsolas.aac.api;
import me.konsolas.aac.api.HackType;
import org.bukkit.entity.Player;
public interface AACAPI {
public void reloadAAC();
public void reloadPermissionCache();
public void enableCheck(HackType hackType);
public void disableCheck(HackType hackType);
public boolean isEnabled(HackType hackType);
public boolean isBypassed(Player player);
public double getTPS();
public int getPing(Player player);
public int getViolationLevel(Player player, HackType hackType);
public void setViolationLevel(Player player, HackType hackType, int i);
public boolean isPlayerOnGround(Player player);
}
@@ -0,0 +1,31 @@
package me.konsolas.aac.api;
import me.konsolas.aac.api.AACAPI;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
public class AACAPILoadedEvent
extends Event {
private final AACAPI api;
public AACAPILoadedEvent(AACAPI aACAPI) {
this.api = aACAPI;
}
public static HandlerList getHandlerList() {
return null;
}
public HandlerList getHandlers() {
return null;
}
public AACAPI getAPI() {
return this.api;
}
static {
new HandlerList();
}
}
@@ -0,0 +1,19 @@
package me.konsolas.aac.api;
import me.konsolas.aac.AAC;
import me.konsolas.aac.api.AACAPI;
public final class AACAPIProvider {
private AACAPIProvider() {
throw new AssertionError();
}
public static AACAPI getAPI() {
return AAC.api;
}
public static boolean isAPILoaded() {
return AAC.api != null;
}
}
@@ -0,0 +1,51 @@
package me.konsolas.aac.api;
public enum HackType {
SPAM("chat.Spam", "spam"),
HITBOX("combat.Hitbox", "hitbox"),
FASTBOW("combat.Fastbow", "fastbow"),
FIGHTSPEED("combat.FightSpeed", "fightspeed"),
KNOCKBACK("combat.Knockback", "knockback"),
REGEN("combat.Regen", "regen"),
FASTUSE("combat.FastUse", "fastuse"),
KILLAURA("combat.Killaura", "killaura"),
SPEED("movement.Speed", "speed"),
PHASE("movement.Phase", "phase"),
FLY("movement.Fly", "fly"),
VEHICLES("movement.Vehicles", "vehicles"),
ELYTRA("movement.Elytra", "elytra"),
NOFALL("movement.NoFall", "nofall"),
JESUS("movement.Jesus", "jesus"),
DERP("movement.Derp", "derp"),
CRITICALS("combat.Criticals", "criticals"),
FASTBREAK("world.FastBreak", "fastbreak"),
FASTPLACE("world.FastPlace", "fastplace"),
NUKER("world.Nuker", "nuker"),
NOSWING("world.NoSwing", "noswing"),
INTERACT("world.Interact", "interact"),
VELOCITY("world.Velocity", "velocity"),
MOVE("MovementManager", "move");
private final String configPath;
private final String displayName;
private final int id;
HackType(String str, String str2) {
this.configPath = str;
this.displayName = str2;
this.id = this.ordinal();
}
@Override
public String toString() {
return this.configPath;
}
public String getName() {
return this.displayName;
}
public int getId() {
return this.id;
}
}
@@ -0,0 +1,50 @@
package me.konsolas.aac.api;
import me.konsolas.aac.api.HackType;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
public final class PlayerViolationCommandEvent
extends PlayerEvent
implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private final HackType hackType;
private String command;
public PlayerViolationCommandEvent(Player player, HackType hackType, String str) {
super(player);
this.hackType = hackType;
this.command = str;
}
public static HandlerList getHandlerList() {
return handlers;
}
public String getCommand() {
return this.command;
}
public void setCommand(String str) {
this.command = str;
}
public HackType getHackType() {
return this.hackType;
}
public boolean isCancelled() {
return this.cancelled;
}
public void setCancelled(boolean flag) {
this.cancelled = flag;
}
public HandlerList getHandlers() {
return handlers;
}
}
@@ -0,0 +1,56 @@
package me.konsolas.aac.api;
import me.konsolas.aac.api.HackType;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
public final class PlayerViolationEvent
extends PlayerEvent
implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
private final HackType hackType;
private int violations;
private final String message;
public PlayerViolationEvent(Player player, HackType hackType, int i, String str) {
super(player);
this.hackType = hackType;
this.violations = i;
this.message = str;
}
public static HandlerList getHandlerList() {
return handlers;
}
public int getViolations() {
return this.violations;
}
public void setViolations(int i) {
this.violations = i;
}
public HackType getHackType() {
return this.hackType;
}
public String getMessage() {
return this.message;
}
public boolean isCancelled() {
return this.cancelled;
}
public void setCancelled(boolean flag) {
this.cancelled = flag;
}
public HandlerList getHandlers() {
return handlers;
}
}
@@ -0,0 +1,124 @@
package me.konsolas.aac.api.internal;
import me.konsolas.aac.AAC;
import me.konsolas.aac.checks.CheckManager;
import me.konsolas.aac.compat.CollisionAccess;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.util.GroundCollisionState;
import me.konsolas.aac.compat.PlayerPingAccess;
import me.konsolas.aac.util.TickRateMonitor;
import me.konsolas.aac.api.AACAPI;
import me.konsolas.aac.api.HackType;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
public final class AACAPIImplementation
implements AACAPI {
private final AAC plugin;
public static AACAPIImplementation create(AAC aAC) {
return new AACAPIImplementation(aAC);
}
private AACAPIImplementation(AAC aAC) {
this.plugin = aAC;
}
@Override
public void reloadAAC() {
AACAPIImplementation aACAPIImplementation = this;
AAC aAC = aACAPIImplementation.plugin;
aAC.reloadPlugin();
}
@Override
public void reloadPermissionCache() {
AACAPIImplementation aACAPIImplementation = this;
CheckManager checkManager = aACAPIImplementation.plugin.checkManager;
checkManager.clearBypassCache();
}
@Override
public void enableCheck(HackType hackType) {
AACAPIImplementation aACAPIImplementation = this;
boolean flag = false;
HackType hackType2 = hackType;
CheckManager checkManager = aACAPIImplementation.plugin.checkManager;
boolean flag2 = flag;
HackType hackType3 = hackType2;
checkManager.enableCheck(hackType3, flag2);
}
@Override
public void disableCheck(HackType hackType) {
AACAPIImplementation aACAPIImplementation = this;
boolean flag = false;
HackType hackType2 = hackType;
CheckManager checkManager = aACAPIImplementation.plugin.checkManager;
boolean flag2 = flag;
HackType hackType3 = hackType2;
checkManager.disableCheck(hackType3, flag2);
}
@Override
public boolean isEnabled(HackType hackType) {
AACAPIImplementation aACAPIImplementation = this;
HackType hackType2 = hackType;
CheckManager checkManager = aACAPIImplementation.plugin.checkManager;
return checkManager.isCheckEnabled(hackType2);
}
@Override
public boolean isBypassed(Player player) {
AACAPIImplementation aACAPIImplementation = this;
Player player2 = player;
CheckManager checkManager = aACAPIImplementation.plugin.checkManager;
Player player3 = player2;
return checkManager.isPlayerExempt(player3);
}
@Override
public double getTPS() {
return TickRateMonitor.getTps();
}
@Override
public int getPing(Player player) {
long ticks = 103276215108508L;
long ticks2 = ticks;
Player player2 = player;
return PlayerPingAccess.getPing(player2, ticks2);
}
@Override
public int getViolationLevel(Player player, HackType hackType) {
AACAPIImplementation aACAPIImplementation = this;
HackType hackType2 = hackType;
CheckManager checkManager = aACAPIImplementation.plugin.checkManager;
Player player2 = player;
Detector detector = checkManager.getDetector(hackType2);
return detector.getViolationLevel(player2);
}
@Override
public void setViolationLevel(Player player, HackType hackType, int i) {
AACAPIImplementation aACAPIImplementation = this;
HackType hackType2 = hackType;
CheckManager checkManager = aACAPIImplementation.plugin.checkManager;
int value = i;
Player player2 = player;
Detector detector = checkManager.getDetector(hackType2);
detector.setViolationLevel(player2, value);
}
@Override
public boolean isPlayerOnGround(Player player) {
Player player2 = player;
Player player3 = player;
GroundCollisionState groundCollisionState = GroundCollisionState.TRUE_NORMAL;
PlayerMoveEvent playerMoveEvent = new PlayerMoveEvent(player, player2.getLocation(), player3.getLocation());
GroundCollisionState groundCollisionState2 = CollisionAccess.getGroundCollisionState(playerMoveEvent, groundCollisionState);
return groundCollisionState2.isOnGround();
}
}
@@ -0,0 +1,326 @@
package me.konsolas.aac.checks;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketListener;
import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.UUID;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.BlockPositionView;
import me.konsolas.aac.compat.CollisionAccess;
import me.konsolas.aac.checks.combat.CombatCheckListener;
import me.konsolas.aac.util.GroundCollisionState;
import me.konsolas.aac.util.MathUtilities;
import me.konsolas.aac.checks.movement.MovementBoundsPacketListener;
import me.konsolas.aac.checks.movement.MovementCheckListener;
import me.konsolas.aac.util.TickRateMonitor;
import me.konsolas.aac.api.HackType;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
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.PlayerTeleportEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
public class CheckManager
implements Listener {
public static final Set identityLookupState = new HashSet();
private final EnumMap<HackType, Detector> detectors = new EnumMap<>(HackType.class);
private final List<HackType> disabledChecks = new ArrayList<>();
private final Set<UUID> bypassPlayers = new HashSet<>();
private final Map<UUID, Long> bypassRefreshTimes = new HashMap<>();
private final Map<UUID, GroundCollisionState> teleportTimes = new HashMap<>();
private final AAC plugin;
public final Consumer<PlayerMoveEvent> movementCallback = this::onPlayerMove;
private long tickCounter = 0L;
public CheckManager(AAC aAC) {
this.plugin = aAC;
for (HackType hackType : HackType.values()) {
this.detectors.put(hackType, null);
}
Server server = Bukkit.getServer();
server.getScheduler().scheduleSyncRepeatingTask((Plugin)this.plugin, this::tickDetectors, 1L, 1L);
ProtocolLibrary.getProtocolManager().addPacketListener((PacketListener)new MovementBoundsPacketListener(this, (Plugin)aAC, ListenerPriority.LOWEST, new PacketType[]{PacketType.Play.Client.POSITION_LOOK, PacketType.Play.Client.POSITION}));
}
private boolean isOutOfBounds(double d, double d2) {
return !(d >= -3.0E7 && d2 >= -3.0E7 && d < 3.0E7 && d2 < 3.0E7);
}
public boolean enableCheck(HackType hackType, boolean flag) {
Class<?> clazz;
if (this.detectors.get(hackType) != null) {
return false;
}
if (flag) {
if (this.disabledChecks.contains(hackType)) {
return false;
}
} else {
this.disabledChecks.remove(hackType);
}
try {
String className = hackType == HackType.MOVE
? "me.konsolas.aac.checks.movement.MovementManager"
: "me.konsolas.aac.checks." + hackType;
clazz = Class.forName(className);
}
catch (ClassNotFoundException classNotFoundException) {
String str = "Failed to initialize " + hackType.getName() + " (class not found)";
this.plugin.logManager.logViolation(str);
return false;
}
Constructor<?>[] constructors = clazz.getDeclaredConstructors();
Constructor<?> constructor = null;
for (Constructor<?> candidate : constructors) {
if (candidate.getParameterTypes().length == 1) {
constructor = candidate;
break;
}
}
if (constructor == null) {
throw new RuntimeException("Could not get valid constuctor");
}
Detector detector;
try {
constructor.setAccessible(true);
detector = (Detector)constructor.newInstance(new Object[]{this.plugin});
}
catch (Exception exception) {
exception.printStackTrace();
String str2 = "Failed to initialize " + hackType.getName() + " (instance creation failed)";
this.plugin.logManager.logViolation(str2);
return false;
}
this.detectors.put(hackType, detector);
Server server = Bukkit.getServer();
PluginManager pluginManager = server.getPluginManager();
pluginManager.registerEvents(detector, this.plugin);
String str3 = "(CheckManager) Enabled check " + (Object)((Object)hackType);
this.plugin.logManager.logViolation(str3);
return true;
}
public boolean disableCheck(HackType hackType, boolean flag) {
if (!this.isCheckEnabled(hackType)) {
return false;
}
if (!flag) {
this.disabledChecks.add(hackType);
}
((Detector)this.detectors.get((Object)hackType)).cleanup();
HandlerList.unregisterAll((Listener)((Listener)this.detectors.get((Object)hackType)));
this.detectors.put(hackType, null);
String str = "(CheckManager) Disabled check " + (Object)((Object)hackType);
this.plugin.logManager.logViolation(str);
return true;
}
public void disableAllChecks() {
HackType[] hackTypeArray = HackType.values();
int value = hackTypeArray.length;
for (int i = 0; i < value; ++i) {
HackType hackType = hackTypeArray[i];
if (this.isCheckEnabled(hackType)) {
this.plugin.getLogger().info("(CheckManager) Disabling check " + (Object)((Object)hackType));
boolean flag = false;
HackType hackType2 = hackType;
this.disableCheck(hackType2, flag);
continue;
}
this.plugin.getLogger().info("(CheckManager) Check " + (Object)((Object)hackType) + " is not enabled");
}
}
public void enableConfiguredChecks() {
HackType[] hackTypeArray = HackType.values();
for (HackType hackType : hackTypeArray) {
boolean flag = true;
HackType hackType2 = hackType;
this.enableCheck(hackType2, flag);
}
}
public Detector getDetector(HackType hackType) {
return (Detector)this.detectors.get((Object)hackType);
}
public boolean isCheckEnabled(HackType hackType) {
return this.detectors.get((Object)hackType) != null;
}
@EventHandler(priority=EventPriority.MONITOR)
public void onPlayerKick(PlayerKickEvent playerKickEvent) {
HackType[] hackTypeArray = HackType.values();
int value = hackTypeArray.length;
for (int i = 0; i < value; ++i) {
HackType hackType = hackTypeArray[i];
if (!this.isCheckEnabled(hackType)) continue;
this.getDetector(hackType).onPlayerKick(playerKickEvent);
}
}
@EventHandler(priority=EventPriority.MONITOR)
public void onPlayerJoin(PlayerJoinEvent playerJoinEvent) {
HackType[] hackTypeArray = HackType.values();
int value = hackTypeArray.length;
for (int i = 0; i < value; ++i) {
HackType hackType = hackTypeArray[i];
if (!this.isCheckEnabled(hackType)) continue;
this.getDetector(hackType).onPlayerJoin(playerJoinEvent);
}
if (this.plugin.logManager.isDebugEnabled()) {
this.plugin.logManager.logPlayerDebug(null, " -> JOIN " + playerJoinEvent.getPlayer().getName() + " / " + playerJoinEvent.getPlayer().getUniqueId());
}
}
@EventHandler(priority=EventPriority.MONITOR)
public void onPlayerQuit(PlayerQuitEvent playerQuitEvent) {
HackType[] hackTypeArray = HackType.values();
int value = hackTypeArray.length;
for (int i = 0; i < value; ++i) {
HackType hackType = hackTypeArray[i];
if (!this.isCheckEnabled(hackType)) continue;
this.getDetector(hackType).onPlayerQuit(playerQuitEvent);
}
if (this.plugin.logManager.isDebugEnabled()) {
this.plugin.logManager.logPlayerDebug(null, " <- QUIT " + playerQuitEvent.getPlayer().getName() + " / " + playerQuitEvent.getPlayer().getUniqueId());
}
}
@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent playerTeleportEvent) {
this.teleportTimes.put(playerTeleportEvent.getPlayer().getUniqueId(), CollisionAccess.getGroundCollisionState(new PlayerMoveEvent(playerTeleportEvent.getPlayer(), playerTeleportEvent.getTo(), playerTeleportEvent.getTo()), this.teleportTimes.getOrDefault(playerTeleportEvent.getPlayer().getUniqueId(), GroundCollisionState.TRUE_NORMAL)));
}
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
GroundCollisionState groundCollisionState;
GroundCollisionState groundCollisionState2;
long ticks = 6629313046314L;
long ticks2 = 6629313046314L;
Player player = playerMoveEvent.getPlayer();
boolean flag = this.isPlayerExempt(player);
BlockPositionView blockPositionView = new BlockPositionView(playerMoveEvent.getFrom());
BlockPositionView blockPositionView2 = new BlockPositionView(playerMoveEvent.getTo());
if (playerMoveEvent.getTo().distanceSquared(playerMoveEvent.getFrom()) < 625.0) {
groundCollisionState2 = this.teleportTimes.getOrDefault(playerMoveEvent.getPlayer().getUniqueId(), GroundCollisionState.TRUE_NORMAL);
groundCollisionState = playerMoveEvent.getTo().getY() < 258.0 && playerMoveEvent.getTo().getY() > -2.0 ? CollisionAccess.getGroundCollisionState(playerMoveEvent, groundCollisionState2) : GroundCollisionState.FALSE_NORMAL;
} else {
groundCollisionState2 = this.teleportTimes.getOrDefault(playerMoveEvent.getPlayer().getUniqueId(), GroundCollisionState.TRUE_NORMAL);
groundCollisionState = GroundCollisionState.FALSE_NORMAL;
}
boolean flag2 = groundCollisionState.isOnGround();
boolean flag3 = groundCollisionState2.isOnGround();
PlayerMoveEvent playerMoveEvent2 = playerMoveEvent;
this.plugin.playerState.updateMovementState(playerMoveEvent2, flag3, flag2);
Location location = playerMoveEvent.getTo();
for (HackType hackType : HackType.values()) {
PlayerMoveEvent playerMoveEvent3;
MovementCheckListener movementCheckListener;
Detector detector;
if (!this.isCheckEnabled(hackType) || !((detector = this.getDetector(hackType)) instanceof MovementCheckListener) || !(movementCheckListener = (MovementCheckListener)((Object)detector)).shouldProcessMovement(playerMoveEvent3 = playerMoveEvent) || flag) continue;
movementCheckListener.onMovement(playerMoveEvent, groundCollisionState2, groundCollisionState, blockPositionView, blockPositionView2, ticks2);
if (playerMoveEvent.getTo().equals((Object)location)) continue;
groundCollisionState = CollisionAccess.getGroundCollisionState(playerMoveEvent, groundCollisionState2);
break;
}
this.teleportTimes.put(playerMoveEvent.getPlayer().getUniqueId(), groundCollisionState);
PlayerMoveEvent playerMoveEvent4 = playerMoveEvent;
if (this.plugin.setbackManager.shouldProcessMovement(playerMoveEvent4) && !flag) {
this.plugin.setbackManager.onMovement(playerMoveEvent, groundCollisionState2, groundCollisionState, blockPositionView, blockPositionView2, ticks);
}
}
@EventHandler(ignoreCancelled=true, priority=EventPriority.HIGHEST)
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
long ticks = 32485288229805L;
boolean flag = entityDamageByEntityEvent.getDamager().hasPermission("AAC.bypass") || entityDamageByEntityEvent.getEntity().hasPermission("AAC.bypass");
for (HackType hackType : HackType.values()) {
CombatCheckListener combatCheckListener;
Detector detector;
if (!this.isCheckEnabled(hackType) || !((detector = this.getDetector(hackType)) instanceof CombatCheckListener) || !(combatCheckListener = (CombatCheckListener)((Object)detector)).shouldProcessCombat(entityDamageByEntityEvent) || flag) continue;
combatCheckListener.onCombat(entityDamageByEntityEvent, ticks);
}
}
public boolean isPlayerExempt(Player player) {
boolean flag;
if (player == null) {
return true;
}
if (!this.bypassRefreshTimes.containsKey(player.getUniqueId())) {
this.bypassRefreshTimes.put(player.getUniqueId(), 0L);
}
if (this.bypassPlayers.contains(player.getUniqueId())) {
if (System.currentTimeMillis() < (Long)this.bypassRefreshTimes.get(player.getUniqueId())) {
flag = true;
} else {
flag = player.hasPermission("AAC.bypass");
if (flag) {
this.bypassPlayers.add(player.getUniqueId());
} else {
this.bypassPlayers.remove(player.getUniqueId());
}
this.bypassRefreshTimes.put(player.getUniqueId(), System.currentTimeMillis() + (long)AAC.random.nextInt(20000) + 20000L);
}
} else if (System.currentTimeMillis() < (Long)this.bypassRefreshTimes.get(player.getUniqueId())) {
flag = false;
} else {
flag = player.hasPermission("AAC.bypass");
if (flag) {
this.bypassPlayers.add(player.getUniqueId());
} else {
this.bypassPlayers.remove(player.getUniqueId());
}
this.bypassRefreshTimes.put(player.getUniqueId(), System.currentTimeMillis() + (long)AAC.random.nextInt(20000) + 20000L);
}
return flag;
}
public void clearBypassCache() {
this.bypassRefreshTimes.clear();
this.bypassPlayers.clear();
}
private void tickDetectors() {
long ticks = 47357059873379L;
++this.tickCounter;
HackType[] hackTypeArray = HackType.values();
int value = hackTypeArray.length;
for (int i = 0; i < value; ++i) {
HackType hackType = hackTypeArray[i];
if (!this.isCheckEnabled(hackType)) continue;
this.getDetector(hackType).onTick(this.tickCounter, ticks);
}
if (this.plugin.logManager != null && this.plugin.logManager.isDebugEnabled()) {
double d;
double d2 = d = TickRateMonitor.getTps();
this.plugin.logManager.logPlayerDebug(null, " -> tick " + this.tickCounter + " tps: " + MathUtilities.formatNumber(d2));
}
}
public static boolean isOutOfBounds(CheckManager checkManager, double d, double d2) {
return checkManager.isOutOfBounds(d, d2);
}
}
@@ -0,0 +1,6 @@
package me.konsolas.aac.checks;
public interface CleanupHandler {
public void cleanup();
}
@@ -0,0 +1,132 @@
package me.konsolas.aac.checks;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import me.konsolas.aac.AAC;
import me.konsolas.aac.compat.PlayerPingAccess;
import me.konsolas.aac.util.TickRateMonitor;
import me.konsolas.aac.api.HackType;
import me.konsolas.aac.api.PlayerViolationEvent;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public abstract class Detector
implements Listener,
CleanupHandler {
protected final AAC plugin;
protected final Map<UUID, Integer> violationLevels = new HashMap<>();
protected final List<Integer> scheduledTaskIds = new ArrayList<>();
protected final List<PacketListener> packetListeners = new ArrayList<>();
public Detector(AAC aAC) {
this.initializeOnlinePlayers();
this.plugin = aAC;
}
public AAC getPlugin() {
return this.plugin;
}
public int getViolationLevel(Player player) {
if (player == null) {
return 0;
}
if (this.violationLevels.get(player.getUniqueId()) != null) {
return (Integer)this.violationLevels.get(player.getUniqueId());
}
return 0;
}
private void initializeOnlinePlayers() {
Server server = Bukkit.getServer();
Iterator iterator = server.getOnlinePlayers().iterator();
while (iterator.hasNext()) {
Player player = (Player)iterator.next();
this.violationLevels.put(player.getUniqueId(), 0);
}
}
@Override
public void cleanup() {
Iterator iterator = this.scheduledTaskIds.iterator();
while (iterator.hasNext()) {
int value = (Integer)iterator.next();
Server server = Bukkit.getServer();
server.getScheduler().cancelTask(value);
}
for (PacketListener packetListener : this.packetListeners) {
ProtocolLibrary.getProtocolManager().removePacketListener(packetListener);
}
}
public boolean recordViolation(UUID uUID, int i, HackType hackType, String str, long ticks) {
long ticks2 = ticks ^ 0x3B1510A8CDF8L;
Player player = Bukkit.getPlayer((UUID)uUID);
PlayerViolationEvent playerViolationEvent = new PlayerViolationEvent(player, hackType, i, str);
if (this.getViolationLevel(player) + i == 0) {
if (this.plugin.logManager.isDebugEnabled()) {
long ticks3 = ticks2;
Player player2 = player;
this.plugin.logManager.logPlayerDebug(player, "(VL0)" + str + " [ping:" + PlayerPingAccess.getPing(player2, ticks3) + " tps:" + (double)Math.round(TickRateMonitor.getTps() * 100.0) / 100.0 + "] VL:" + this.violationLevels.get(uUID));
}
return true;
}
Bukkit.getServer().getPluginManager().callEvent(playerViolationEvent);
if (!playerViolationEvent.isCancelled()) {
if (!this.violationLevels.containsKey(uUID)) {
this.violationLevels.put(uUID, 1);
}
this.violationLevels.put(uUID, (Integer)this.violationLevels.get(uUID) + playerViolationEvent.getViolations());
if (playerViolationEvent.getViolations() != i) {
String str2 = "(PlayerViolationEvent) modified " + i + " -> " + playerViolationEvent.getViolations() + " by other plugin";
this.plugin.logManager.logViolation(str2);
}
long ticks4 = ticks2;
Player player3 = player;
String str3 = str + " [ping:" + PlayerPingAccess.getPing(player3, ticks4) + " tps:" + (double)Math.round(TickRateMonitor.getTps() * 100.0) / 100.0 + "] VL:" + this.violationLevels.get(uUID);
this.plugin.logManager.logViolation(str3);
return true;
}
return false;
}
public void decreaseViolationLevel(UUID uUID, int i) {
if (this.violationLevels.containsKey(uUID)) {
this.violationLevels.put(uUID, (Integer)this.violationLevels.get(uUID) - i < 0 ? 0 : (Integer)this.violationLevels.get(uUID) - i);
} else {
this.violationLevels.put(uUID, 0);
}
}
public void setViolationLevel(Player player, int i) {
this.violationLevels.put(player.getUniqueId(), i);
}
public void onPlayerJoin(PlayerJoinEvent playerJoinEvent) {
this.violationLevels.put(playerJoinEvent.getPlayer().getUniqueId(), 0);
}
public void onPlayerQuit(PlayerQuitEvent playerQuitEvent) {
this.violationLevels.remove(playerQuitEvent.getPlayer().getUniqueId());
}
public void onPlayerKick(PlayerKickEvent playerKickEvent) {
this.violationLevels.remove(playerKickEvent.getPlayer().getUniqueId());
}
public void onTick(long ticks, long ticks2) {
}
}
@@ -0,0 +1,71 @@
package me.konsolas.aac.checks;
import me.konsolas.aac.AAC;
import me.konsolas.aac.api.internal.AACAPIImplementation;
import me.konsolas.aac.util.LanguageConfig;
import me.konsolas.aac.checks.movement.PlayerEventStateTracker;
import me.konsolas.aac.punishment.PunishmentManager;
import me.konsolas.aac.checks.combat.RecentCombatTracker;
import me.konsolas.aac.util.TickRateMonitor;
import me.konsolas.aac.api.AACAPILoadedEvent;
import me.konsolas.aac.api.HackType;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.event.Event;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
public class EnablePluginTask
implements Runnable {
final AAC plugin;
public EnablePluginTask(AAC aAC) {
this.plugin = aAC;
}
@Override
public void run() {
AAC plugin = AAC.getPlugin(this.plugin);
plugin.getLogger().info("Beginning Enable...");
plugin.punishmentManager = new PunishmentManager(plugin);
AAC.initializeHooks(this.plugin);
Server server = Bukkit.getServer();
CheckManager checkManager = this.plugin.checkManager;
PluginManager pluginManager = server.getPluginManager();
pluginManager.registerEvents((Listener)checkManager, (Plugin)plugin);
plugin.getLogger().info("Checking config file...");
for (HackType hackType : HackType.values()) {
if (this.plugin.getConfig().getBoolean(hackType.getName() + ".enabled")) {
plugin.getLogger().info("(CheckManager) Enabling check " + hackType);
this.plugin.checkManager.enableCheck(hackType, false);
continue;
}
plugin.getLogger().info("(CheckManager) Check " + hackType + " is disabled");
}
plugin.getLogger().info("Starting API...");
AAC.api = AACAPIImplementation.create(plugin);
Server server2 = Bukkit.getServer();
AACAPILoadedEvent aACAPILoadedEvent = new AACAPILoadedEvent(AAC.api);
PluginManager pluginManager2 = server2.getPluginManager();
pluginManager2.callEvent((Event)aACAPILoadedEvent);
this.plugin.combatTracker = new RecentCombatTracker(plugin);
this.plugin.playerState = new PlayerEventStateTracker(plugin);
this.plugin.messages = new LanguageConfig(plugin);
Server server3 = Bukkit.getServer();
PluginManager pluginManager3 = server3.getPluginManager();
pluginManager3.registerEvents((Listener)this.plugin.combatTracker, (Plugin)plugin);
Server server4 = Bukkit.getServer();
PluginManager pluginManager4 = server4.getPluginManager();
pluginManager4.registerEvents((Listener)this.plugin.playerState, (Plugin)plugin);
Server server5 = Bukkit.getServer();
PluginManager pluginManager5 = server5.getPluginManager();
pluginManager5.registerEvents((Listener)this.plugin.punishmentManager, (Plugin)plugin);
this.plugin.logManager.logViolation("AAC has been enabled");
plugin.getLogger().info("AAC has been enabled.");
AAC.messagePrefix = ChatColor.translateAlternateColorCodes('&', this.plugin.messages.getMessage("prefix"));
TickRateMonitor.start((Plugin)plugin);
}
}
@@ -0,0 +1,16 @@
package me.konsolas.aac.checks.chat;
public class ChatSimilarity {
public static boolean isSimilar(String str, String str2) {
if (str.equalsIgnoreCase(str2)) {
return true;
}
if (str.length() < 3 || str2.length() < 3) {
return false;
}
if (str.toLowerCase().replaceAll("[^a-z]", "").equals("") || str2.toLowerCase().replaceAll("[^a-z]", "").equals("")) {
return false;
}
return str.toLowerCase().replaceAll("[^a-z]", "").equals(str2.toLowerCase().replaceAll("[^a-z]", ""));
}
}
@@ -0,0 +1,225 @@
package me.konsolas.aac.checks.chat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import me.konsolas.aac.AAC;
import me.konsolas.aac.checks.Detector;
import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;
import me.konsolas.aac.api.HackType;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.plugin.Plugin;
public final class Spam
extends Detector {
private final ConcurrentMap messageCounts;
private final ExpiringMap lastMessages;
private final ExpiringMap flaggedMessages;
private final ExpiringMap recentSpammers;
private final ExpiringMap chatCooldowns;
private volatile List<String> whitelistedMessages;
private int messageLimit;
private int chatSpeedTicks;
public Spam(AAC aAC) { super(aAC);
this.messageCounts = new ConcurrentHashMap();
ArrayList arrayList = new ArrayList();
Spam spam = this;
spam.whitelistedMessages = arrayList;
int value = 5;
Spam spam2 = this;
spam2.messageLimit = value;
int value2 = 10;
Spam spam3 = this;
spam3.chatSpeedTicks = value2;
Spam spam4 = this;
int value3 = spam4.plugin.getConfig().getInt("spam.message_limit");
Spam spam5 = this;
spam5.messageLimit = value3;
Spam spam6 = this;
List list = spam6.plugin.getConfig().getStringList("spam.whitelist");
Spam spam7 = this;
spam7.whitelistedMessages = list;
Spam spam8 = this;
int value4 = spam8.plugin.getConfig().getInt("spam.chat_speed");
Spam spam9 = this;
spam9.chatSpeedTicks = value4;
Server server = Bukkit.getServer();
Spam spam10 = this;
server.getScheduler().scheduleSyncRepeatingTask((Plugin)spam10.plugin, this::resetChatCounts, 200L, 200L);
Server server2 = Bukkit.getServer();
Spam spam11 = this;
server2.getScheduler().scheduleSyncRepeatingTask((Plugin)spam11.plugin, this::decaySpamViolations, 200L, 300L);
ExpirationPolicy expirationPolicy = ExpirationPolicy.CREATED;
TimeUnit timeUnit = TimeUnit.SECONDS;
long ticks = 10L;
this.lastMessages = ExpiringMap.builder().expirationPolicy(expirationPolicy).expiration(ticks, timeUnit).build();
ExpirationPolicy expirationPolicy2 = ExpirationPolicy.CREATED;
TimeUnit timeUnit2 = TimeUnit.SECONDS;
long ticks2 = 5L;
this.flaggedMessages = ExpiringMap.builder().expirationPolicy(expirationPolicy2).expiration(ticks2, timeUnit2).build();
ExpirationPolicy expirationPolicy3 = ExpirationPolicy.CREATED;
TimeUnit timeUnit3 = TimeUnit.SECONDS;
long ticks3 = 10L;
this.recentSpammers = ExpiringMap.builder().expirationPolicy(expirationPolicy3).expiration(ticks3, timeUnit3).build();
ExpirationPolicy expirationPolicy4 = ExpirationPolicy.CREATED;
Spam spam12 = this;
TimeUnit timeUnit4 = TimeUnit.MILLISECONDS;
long ticks4 = spam12.chatSpeedTicks * 50;
this.chatCooldowns = ExpiringMap.builder().expirationPolicy(expirationPolicy4).expiration(ticks4, timeUnit4).build();
}
@EventHandler
public void onAsyncPlayerChat(AsyncPlayerChatEvent asyncPlayerChatEvent) {
long ticks = 113218805911140L;
Spam spam = this;
AAC aAC = spam.plugin;
Player player = asyncPlayerChatEvent.getPlayer();
if (aAC.checkManager.isPlayerExempt(player)) {
return;
}
Player player2 = asyncPlayerChatEvent.getPlayer();
Spam spam2 = this;
if (spam2.chatCooldowns.containsKey(player2.getUniqueId())) {
if (this.recordViolation(player2.getUniqueId(), 5, HackType.SPAM, player2.getName() + " failed Spam: tried to chat too quickly", ticks)) {
asyncPlayerChatEvent.setCancelled(true);
Spam spam3 = this;
AAC aAC2 = spam3.plugin;
player2.sendMessage(AAC.messagePrefix + aAC2.messages.getMessage("spam_too_fast"));
}
return;
}
Spam spam4 = this;
if (spam4.messageCounts.containsKey(player2.getUniqueId())) {
Spam spam5 = this;
Spam spam6 = this;
spam5.messageCounts.put(player2.getUniqueId(), (Integer)spam6.messageCounts.get(player2.getUniqueId()) + 1);
Spam spam7 = this;
Spam spam8 = this;
if ((Integer)spam7.messageCounts.get(player2.getUniqueId()) == spam8.messageLimit) {
Spam spam9 = this;
if (spam9.recentSpammers.containsKey(player2.getUniqueId())) {
if (this.recordViolation(player2.getUniqueId(), 6, HackType.SPAM, player2.getName() + " failed Spam: sent too many messages", ticks)) {
Spam spam10 = this;
AAC aAC3 = spam10.plugin;
player2.sendMessage(AAC.messagePrefix + aAC3.messages.getMessage("spam_slow_chat"));
}
} else if (this.recordViolation(player2.getUniqueId(), 4, HackType.SPAM, player2.getName() + " failed Spam: sent too many messages", ticks)) {
Spam spam11 = this;
spam11.recentSpammers.put(player2.getUniqueId(), (Object)true);
Spam spam12 = this;
AAC aAC4 = spam12.plugin;
player2.sendMessage(AAC.messagePrefix + aAC4.messages.getMessage("spam_slow_chat"));
}
return;
}
}
String str = asyncPlayerChatEvent.getMessage();
Spam spam13 = this;
for (String str2 : spam13.whitelistedMessages) {
String str3;
String str4 = str2;
if (!ChatSimilarity.isSimilar(str4, str3 = str)) continue;
return;
}
Spam spam14 = this;
if (spam14.lastMessages.containsKey(player2.getUniqueId())) {
Spam spam15 = this;
String str5 = str;
String str6 = (String)spam15.lastMessages.get(player2.getUniqueId());
if (ChatSimilarity.isSimilar(str5, str6)) {
Spam spam16 = this;
if (spam16.recentSpammers.containsKey(player2.getUniqueId())) {
if (this.recordViolation(player2.getUniqueId(), 4, HackType.SPAM, player2.getName() + " failed Spam: repeated last message", ticks)) {
Spam spam17 = this;
AAC aAC5 = spam17.plugin;
player2.sendMessage(AAC.messagePrefix + aAC5.messages.getMessage("spam_repeat"));
}
} else if (this.recordViolation(player2.getUniqueId(), 2, HackType.SPAM, player2.getName() + " failed Spam: repeated last message", ticks)) {
Spam spam18 = this;
spam18.recentSpammers.put(player2.getUniqueId(), (Object)true);
Spam spam19 = this;
AAC aAC6 = spam19.plugin;
player2.sendMessage(AAC.messagePrefix + aAC6.messages.getMessage("spam_repeat"));
}
return;
}
}
Spam spam20 = this;
Iterator iterator = spam20.flaggedMessages.keySet().iterator();
String str7;
while (iterator.hasNext()) {
String str8 = str;
str7 = (String)iterator.next();
String str9 = str7;
if (!ChatSimilarity.isSimilar(str8, str9)) continue;
Spam spam21 = this;
spam21.flaggedMessages.put(str, (Object)true);
Spam spam22 = this;
if (spam22.recentSpammers.containsKey(player2.getUniqueId())) {
if (this.recordViolation(player2.getUniqueId(), 3, HackType.SPAM, player2.getName() + " failed Spam: tried to repeat a suspicious message (" + str + ")", ticks)) {
Spam spam23 = this;
AAC aAC7 = spam23.plugin;
player2.sendMessage(AAC.messagePrefix + aAC7.messages.getMessage("spam_repeat_other"));
asyncPlayerChatEvent.setCancelled(true);
}
} else if (this.recordViolation(player2.getUniqueId(), 2, HackType.SPAM, player2.getName() + " failed Spam: tried to repeat a suspicious message (" + str + ")", ticks)) {
Spam spam24 = this;
AAC aAC8 = spam24.plugin;
player2.sendMessage(AAC.messagePrefix + aAC8.messages.getMessage("spam_repeat_other"));
asyncPlayerChatEvent.setCancelled(true);
Spam spam25 = this;
spam25.recentSpammers.put(player2.getUniqueId(), (Object)true);
}
return;
}
Spam spam26 = this;
iterator = spam26.lastMessages.values().iterator();
while (iterator.hasNext()) {
String str10 = str;
str7 = (String)iterator.next();
String str11 = str7;
if (!ChatSimilarity.isSimilar(str10, str11)) continue;
Spam spam27 = this;
spam27.flaggedMessages.put(str, (Object)true);
}
Spam spam28 = this;
spam28.lastMessages.put(player2.getUniqueId(), str);
Spam spam29 = this;
spam29.chatCooldowns.put(player2.getUniqueId(), (Object)true);
}
private void decaySpamViolations() {
Server server = Bukkit.getServer();
Iterator iterator = server.getOnlinePlayers().iterator();
while (iterator.hasNext()) {
Player player = (Player)iterator.next();
this.decreaseViolationLevel(player.getUniqueId(), 1);
}
}
private void resetChatCounts() {
Server server = Bukkit.getServer();
Iterator iterator = server.getOnlinePlayers().iterator();
while (iterator.hasNext()) {
Player player = (Player)iterator.next();
Spam spam = this;
if (!spam.messageCounts.containsKey(player.getUniqueId())) {
Spam spam2 = this;
spam2.messageCounts.put(player.getUniqueId(), 0);
}
Spam spam3 = this;
spam3.messageCounts.put(player.getUniqueId(), 0);
}
}
}
@@ -0,0 +1,18 @@
package me.konsolas.aac.checks.combat;
public class AccuracyState {
int checkCount;
int swingCount;
int accurateHitCount;
final KillauraAccuracyModule module;
private AccuracyState(KillauraAccuracyModule killauraAccuracyModule) {
this.module = killauraAccuracyModule;
}
public AccuracyState(KillauraAccuracyModule killauraAccuracyModule, AccuracyStateAccess accuracyStateAccess) {
this(killauraAccuracyModule);
}
}
@@ -0,0 +1,5 @@
package me.konsolas.aac.checks.combat;
public class AccuracyStateAccess {
}
@@ -0,0 +1,20 @@
package me.konsolas.aac.checks.combat;
import org.bukkit.Location;
public class AimRotationBounds {
double minimumYaw;
double maximumYaw;
double minimumPitch;
double maximumPitch;
final KillauraSwitchModule module;
public AimRotationBounds(KillauraSwitchModule killauraSwitchModule, Location location, Location location2) {
this.module = killauraSwitchModule;
this.minimumYaw = location2.getYaw() > location.getYaw() ? (double)location.getYaw() + 5.0 : (double)location2.getYaw() + 5.0;
this.maximumYaw = location.getYaw() > location2.getYaw() ? (double)location.getYaw() - 5.0 : (double)location2.getYaw() - 5.0;
this.minimumPitch = location2.getPitch() > location.getPitch() ? (double)location.getPitch() + 5.0 : (double)location2.getPitch() + 5.0;
this.maximumPitch = location.getPitch() > location2.getPitch() ? (double)location.getPitch() - 5.0 : (double)location2.getPitch() - 5.0;
}
}
@@ -0,0 +1,39 @@
package me.konsolas.aac.checks.combat;
import me.konsolas.aac.util.MathUtilities;
import org.bukkit.Location;
public class AimRotationDelta {
private final float pitchDelta;
private final float yawDelta;
final KillauraAccelerationModule module;
public AimRotationDelta(KillauraAccelerationModule killauraAccelerationModule, Location location, Location location2) {
double d;
this.module = killauraAccelerationModule;
double yaw = d = (double)(location2.getYaw() - location.getYaw());
this.yawDelta = (float)MathUtilities.wrapDegrees(yaw);
this.pitchDelta = location2.getPitch() - location.getPitch();
}
public AimRotationDelta(KillauraAccelerationModule killauraAccelerationModule, AimRotationDelta aimRotationDelta, AimRotationDelta aimRotationDelta2) {
double d;
this.module = killauraAccelerationModule;
double d2 = d = (double)(aimRotationDelta2.yawDelta - aimRotationDelta.yawDelta);
this.yawDelta = (float)MathUtilities.wrapDegrees(d2);
this.pitchDelta = aimRotationDelta2.pitchDelta - aimRotationDelta.pitchDelta;
}
public String toString() {
return "{" + this.pitchDelta + ", " + this.yawDelta + "}";
}
static float getYawDelta(AimRotationDelta aimRotationDelta) {
return aimRotationDelta.yawDelta;
}
static float getPitchDelta(AimRotationDelta aimRotationDelta) {
return aimRotationDelta.pitchDelta;
}
}
@@ -0,0 +1,95 @@
package me.konsolas.aac.checks.combat;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.entity.Entity;
import org.bukkit.util.Vector;
public class AttackContext {
private final Location attackerOrigin;
private final Vector defenderVelocity;
private final double initialDistance;
private double lastDistance;
private double maxDistance;
private int awayTickCount;
private boolean movingAway;
private boolean approachedDefender;
private boolean inWater;
private int taskId;
public AttackContext(Entity entity, Entity entity2, boolean flag) {
if (!entity.getWorld().equals(entity2.getWorld())) {
throw new IllegalStateException("Attacker and defender are in different worlds");
}
this.attackerOrigin = entity.getLocation();
this.initialDistance = Math.sqrt(Math.pow(entity.getLocation().getX() - entity2.getLocation().getX(), 2.0) + Math.pow(entity.getLocation().getZ() - entity2.getLocation().getZ(), 2.0));
this.defenderVelocity = entity2.getVelocity();
this.maxDistance = this.initialDistance;
this.awayTickCount = 0;
this.movingAway = false;
this.inWater = flag;
}
public Location getAttackerOrigin() {
return this.attackerOrigin;
}
public double getMaxDistance() {
return this.maxDistance;
}
public void setTaskId(int i) {
this.taskId = i;
}
public void cancelTask() {
Server server = Bukkit.getServer();
server.getScheduler().cancelTask(this.taskId);
}
public void updateDistance(Location location) {
double x = Math.sqrt(Math.pow(this.attackerOrigin.getX() - location.getX(), 2.0) + Math.pow(this.attackerOrigin.getZ() - location.getZ(), 2.0));
if (x > this.maxDistance) {
this.maxDistance = x;
}
if (x < this.lastDistance && x < 1.2) {
this.approachedDefender = true;
}
boolean flag = x < this.lastDistance;
this.updateDirection(flag);
this.lastDistance = x;
}
private void updateDirection(boolean flag) {
if (this.approachedDefender) {
return;
}
if (flag) {
if (this.movingAway) {
this.approachedDefender = true;
}
} else if (this.movingAway) {
++this.awayTickCount;
} else {
this.movingAway = true;
}
}
public int getAwayTickCount() {
return this.awayTickCount;
}
public double getInitialDistance() {
return this.initialDistance;
}
public Vector getDefenderVelocity() {
return this.defenderVelocity;
}
public boolean isInWater() {
return this.inWater;
}
}
@@ -0,0 +1,36 @@
package me.konsolas.aac.checks.combat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ClickIntervalHistory {
private final List<Long> intervals;
private long lastClickTime;
final FightSpeed detector;
private ClickIntervalHistory(FightSpeed fightSpeed) {
this.detector = fightSpeed;
this.intervals = Collections.synchronizedList(new ArrayList<>());
this.lastClickTime = System.currentTimeMillis();
}
private void recordClick() {
long now = System.currentTimeMillis();
this.intervals.add(now - this.lastClickTime);
this.lastClickTime = now;
}
static void recordClick(ClickIntervalHistory clickIntervalHistory) {
clickIntervalHistory.recordClick();
}
public ClickIntervalHistory(FightSpeed fightSpeed, FightSpeedPacketListener fightSpeedPacketListener) {
this(fightSpeed);
}
static List<Long> getIntervals(ClickIntervalHistory clickIntervalHistory) {
return clickIntervalHistory.intervals;
}
}
@@ -0,0 +1,10 @@
package me.konsolas.aac.checks.combat;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
public interface CombatCheckListener {
public void onCombat(EntityDamageByEntityEvent event, long ticks);
public boolean shouldProcessCombat(EntityDamageByEntityEvent event);
}
@@ -0,0 +1,113 @@
package me.konsolas.aac.checks.combat;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.BlockPositionView;
import me.konsolas.aac.compat.CollisionVectorAdjuster;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.compat.EnvironmentBlockChecks;
import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;
import me.konsolas.aac.util.GroundCollisionState;
import me.konsolas.aac.checks.movement.MovementCheckListener;
import me.konsolas.aac.api.HackType;
import org.bukkit.GameMode;
import org.bukkit.entity.Boat;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public final class Criticals
extends Detector
implements CombatCheckListener,
MovementCheckListener {
private final ExpiringMap jumpCooldowns;
private boolean cancelFalseHit;
private int jumpDelay;
public Criticals(AAC aAC) {
super(aAC);
this.cancelFalseHit = false;
this.jumpDelay = 5;
this.cancelFalseHit = this.plugin.getConfig().getBoolean("criticals.cancel_false_hit", this.cancelFalseHit);
this.jumpDelay = this.plugin.getConfig().getInt("criticals.jump_delay", this.jumpDelay);
TimeUnit timeUnit = TimeUnit.MILLISECONDS;
long ticks = 50 * this.jumpDelay;
ExpirationPolicy expirationPolicy = ExpirationPolicy.CREATED;
this.jumpCooldowns = ExpiringMap.builder().expiration(ticks, timeUnit).expirationPolicy(expirationPolicy).build();
}
@Override
public boolean shouldProcessCombat(EntityDamageByEntityEvent entityDamageByEntityEvent) {
return entityDamageByEntityEvent.getDamager().getType() == EntityType.PLAYER && !((Player)entityDamageByEntityEvent.getDamager()).isFlying();
}
@Override
public void onCombat(EntityDamageByEntityEvent entityDamageByEntityEvent, long ticks) {
long ticks2 = ticks ^ 0x7B735CA5F5C9L;
Player player = (Player)entityDamageByEntityEvent.getDamager();
if (this.isCriticalCandidate(player)) {
Player player2;
if (this.plugin.logManager.isDebugEnabled()) {
this.plugin.logManager.logPlayerDebug(player, "(Criticals) EntityDamageByEntityEvent critical location[r:" + player.getLocation() + "] velocity[r:" + player.getVelocity() + "] blockOn[r:" + player.getLocation().subtract(0.0, 1.0, 0.0).getBlock().getType() + "]");
}
if ((player.getLocation().getY() % 1.0 == 0.0 && EnvironmentBlockChecks.isUseMaterial(player.getLocation().subtract(0.0, 1.0, 0.0).getBlock()) || player.getLocation().getY() % 0.5 == 0.0 && EnvironmentBlockChecks.isHalfBlock(player.getLocation().getBlock().getType()) && !this.plugin.checkManager.isPlayerExempt(player2 = player)) && this.recordViolation(player.getUniqueId(), 2, HackType.CRITICALS, player.getName() + " failed Criticals: tried to perform a critical hit whilst on the ground", ticks2) && this.cancelFalseHit) {
entityDamageByEntityEvent.setCancelled(true);
}
} else {
if (this.plugin.logManager.isDebugEnabled()) {
this.plugin.logManager.logPlayerDebug(player, "(Criticals) EntityDamageByEntityEvent !critical location[r:" + player.getLocation() + "] velocity[r:" + player.getVelocity() + "] blockOn[r:" + player.getLocation().subtract(0.0, 1.0, 0.0).getBlock().getType() + "]");
}
if (player.getLocation().getY() % 1.0 == 0.0 && EnvironmentBlockChecks.isUseMaterial(player.getLocation().subtract(0.0, 1.0, 0.0).getBlock())) {
this.decreaseViolationLevel(player.getUniqueId(), 1);
}
}
}
private boolean isCriticalCandidate(Player player) {
return player.getFallDistance() > 0.0f && !player.isOnGround() && !player.isInsideVehicle() && !player.hasPotionEffect(PotionEffectType.BLINDNESS) && !EnvironmentBlockChecks.isOnLadderOrVine(new BlockPositionView(player.getLocation())) && !EnvironmentBlockChecks.isInLiquid(new BlockPositionView(player.getLocation()));
}
@Override
public boolean shouldProcessMovement(PlayerMoveEvent playerMoveEvent) {
Player player;
Iterator iterator = playerMoveEvent.getPlayer().getActivePotionEffects().iterator();
while (iterator.hasNext()) {
PotionEffect potionEffect = (PotionEffect)iterator.next();
if (!potionEffect.getType().equals((Object)PotionEffectType.JUMP)) continue;
return false;
}
return !playerMoveEvent.getPlayer().getAllowFlight() && playerMoveEvent.getPlayer().getGameMode() != GameMode.CREATIVE && playerMoveEvent.getPlayer().getGameMode() != GameMode.SPECTATOR && !AAC.serverVersion.isElytraGliding(player = playerMoveEvent.getPlayer()) && !this.plugin.playerState.hasActiveVelocity(playerMoveEvent.getPlayer());
}
@Override
public void onMovement(PlayerMoveEvent playerMoveEvent, GroundCollisionState groundCollisionState, GroundCollisionState groundCollisionState2, BlockPositionView blockPositionView, BlockPositionView blockPositionView2, long ticks) {
double d;
long ticks2 = ticks ^ 0x60FF4F6C294EL;
if (EnvironmentBlockChecks.isNearSnowColumn(blockPositionView) || EnvironmentBlockChecks.isNearLiquid(blockPositionView) || !CollisionVectorAdjuster.isPassableColumn(blockPositionView) || EnvironmentBlockChecks.isInLiquid(blockPositionView) || EnvironmentBlockChecks.isOnCarpet(blockPositionView) || EnvironmentBlockChecks.isPlayerInCobweb(blockPositionView)) {
return;
}
for (Entity entity : playerMoveEvent.getPlayer().getNearbyEntities(2.0, 2.0, 2.0)) {
if (!(entity instanceof Boat)) continue;
return;
}
if (groundCollisionState.isOnGround() && EnvironmentBlockChecks.isOnEdgeOfHalfBlock(blockPositionView) && EnvironmentBlockChecks.isOnEdgeOfHalfBlock(blockPositionView2) && !EnvironmentBlockChecks.isNearLiquid(blockPositionView2) && (d = playerMoveEvent.getTo().getY() - playerMoveEvent.getFrom().getY()) > 0.0 && d < 0.2) {
Double doubleVal = (Double)this.jumpCooldowns.get(playerMoveEvent.getPlayer());
if (doubleVal != null && doubleVal > 0.0 && doubleVal < 0.2 && this.recordViolation(playerMoveEvent.getPlayer().getUniqueId(), 2, HackType.CRITICALS, playerMoveEvent.getPlayer().getName() + " failed Criticals: tried to do a mini-jump", ticks2) && this.cancelFalseHit) {
boolean flag = false;
boolean flag2 = true;
double y = playerMoveEvent.getPlayer().getVelocity().getY();
PlayerMoveEvent playerMoveEvent2 = playerMoveEvent;
Player player = playerMoveEvent.getPlayer();
this.plugin.setbackManager.applySetback(player, playerMoveEvent2, y, flag2, flag);
}
this.jumpCooldowns.put(playerMoveEvent.getPlayer(), (Object)(playerMoveEvent.getTo().getY() - playerMoveEvent.getFrom().getY()));
}
}
}
@@ -0,0 +1,36 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.events.PacketContainer;
import me.konsolas.aac.AAC;
import me.konsolas.aac.compat.ServerVersion;
import org.bukkit.util.Vector;
public class EntityMovementDirection {
private final Vector direction;
public EntityMovementDirection(PacketContainer packetContainer) {
double d;
double d2;
double d3;
if (AAC.serverVersion.getVersion() == ServerVersion.VER_1_8) {
d3 = ((Byte)packetContainer.getBytes().read(0)).byteValue();
d2 = ((Byte)packetContainer.getBytes().read(1)).byteValue();
d = ((Byte)packetContainer.getBytes().read(2)).byteValue();
} else {
d3 = ((Integer)packetContainer.getIntegers().read(1)).intValue();
d2 = ((Integer)packetContainer.getIntegers().read(2)).intValue();
d = ((Integer)packetContainer.getIntegers().read(3)).intValue();
}
this.direction = new Vector(d3, d2, d).normalize();
}
public Vector getDirection() {
return this.direction;
}
static {
if (null != null) {
}
}
}
@@ -0,0 +1,40 @@
package me.konsolas.aac.checks.combat;
import me.konsolas.aac.AAC;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.api.HackType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerItemConsumeEvent;
public final class FastUse
extends Detector {
private int msToUse;
public FastUse(AAC aAC) { super(aAC);
this.msToUse = 1200;
this.msToUse = this.plugin.getConfig().getInt("fastuse.ms_to_use");
}
@EventHandler
public void onPlayerItemConsume(PlayerItemConsumeEvent playerItemConsumeEvent) {
Player player;
long ticks = 113218805911140L;
Player player2 = playerItemConsumeEvent.getPlayer();
if (this.plugin.checkManager.isPlayerExempt(player2) || AAC.serverVersion.isElytraGliding(player = playerItemConsumeEvent.getPlayer())) {
return;
}
long now = System.currentTimeMillis();
long ticks2 = now - this.plugin.playerState.getLastInteractionTime(playerItemConsumeEvent.getPlayer());
if (ticks2 < (long)this.msToUse) {
if (this.recordViolation(playerItemConsumeEvent.getPlayer().getUniqueId(), 1, HackType.FASTUSE, playerItemConsumeEvent.getPlayer().getName() + " failed FastUse: Tried to consume an item too quickly (" + ticks2 + "ms)", ticks)) {
playerItemConsumeEvent.setCancelled(true);
playerItemConsumeEvent.getPlayer().getInventory().setHeldItemSlot((playerItemConsumeEvent.getPlayer().getInventory().getHeldItemSlot() + 1) % 9);
}
} else {
this.decreaseViolationLevel(playerItemConsumeEvent.getPlayer().getUniqueId(), 1);
}
}
}
@@ -0,0 +1,98 @@
package me.konsolas.aac.checks.combat;
import java.util.WeakHashMap;
import java.util.concurrent.TimeUnit;
import me.konsolas.aac.AAC;
import me.konsolas.aac.checks.Detector;
import net.jodah.expiringmap.ExpirationListener;
import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;
import me.konsolas.aac.api.HackType;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
public final class Fastbow
extends Detector {
private final WeakHashMap drawStartTimes;
private final ExpiringMap<Player, Boolean> bowCooldowns;
private long lenienceMs;
private long blockTicks;
private int minVl;
public Fastbow(AAC aAC) { super(aAC);
this.drawStartTimes = new WeakHashMap();
this.lenienceMs = 130L;
this.blockTicks = 100L;
this.minVl = 5;
this.lenienceMs = this.plugin.getConfig().getLong("fastbow.lenience_ms", this.lenienceMs);
this.blockTicks = this.plugin.getConfig().getLong("fastbow.block_ticks", this.blockTicks);
this.minVl = this.plugin.getConfig().getInt("fastbow.min_vl", this.minVl);
ExpirationPolicy expirationPolicy = ExpirationPolicy.CREATED;
TimeUnit timeUnit = TimeUnit.MILLISECONDS;
long ticks = 50L * this.blockTicks;
ExpirationListener<Player, Boolean> expirationListener = this::notifyBowCooldownExpired;
this.bowCooldowns = ExpiringMap.builder().expirationPolicy(expirationPolicy).expiration(ticks, timeUnit).expirationListener(expirationListener).build();
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent playerInteractEvent) {
if (playerInteractEvent.hasItem() && playerInteractEvent.getItem().getType() == Material.BOW) {
long now = System.currentTimeMillis();
this.drawStartTimes.put(playerInteractEvent.getPlayer(), now);
}
}
@EventHandler
public void onEntityShootBow(EntityShootBowEvent entityShootBowEvent) {
long ticks = 113218805911140L;
if (entityShootBowEvent.getEntity() instanceof Player) {
Player player = (Player)entityShootBowEvent.getEntity();
if (this.plugin.checkManager.isPlayerExempt(player)) {
return;
}
if (this.bowCooldowns.containsKey(entityShootBowEvent.getEntity())) {
entityShootBowEvent.setCancelled(true);
return;
}
double d = entityShootBowEvent.getForce();
long ticks2 = this.getExpectedDrawMs(d) - this.lenienceMs;
if (this.drawStartTimes.containsKey(entityShootBowEvent.getEntity())) {
long now = System.currentTimeMillis() - (Long)this.drawStartTimes.get(entityShootBowEvent.getEntity());
if (now >= ticks2) {
this.drawStartTimes.put((Player)entityShootBowEvent.getEntity(), System.currentTimeMillis());
this.decreaseViolationLevel(entityShootBowEvent.getEntity().getUniqueId(), 1);
} else if (ticks2 > 150L && this.recordViolation(entityShootBowEvent.getEntity().getUniqueId(), (int)(1L + Math.abs((now - ticks2) / 90L)), HackType.FASTBOW, entityShootBowEvent.getEntity().getName() + " failed Fastbow: drew back bow too quickly (" + now + "/" + ticks2 + " ms)", ticks) && this.blockTicks > 0L && this.getViolationLevel((Player)entityShootBowEvent.getEntity()) > this.minVl) {
entityShootBowEvent.setCancelled(true);
this.bowCooldowns.put((Player)entityShootBowEvent.getEntity(), false);
entityShootBowEvent.getEntity().sendMessage(AAC.messagePrefix + this.plugin.messages.getMessage("too_many_shots"));
}
}
}
}
private long getExpectedDrawMs(double d) {
return (long)(100.0 + 950.0 * d);
}
@EventHandler(priority=EventPriority.MONITOR)
public void onFastbowPlayerJoin(PlayerJoinEvent playerJoinEvent) {
super.onPlayerJoin(playerJoinEvent);
}
@EventHandler(priority=EventPriority.MONITOR)
public void onFastbowPlayerQuit(PlayerQuitEvent playerQuitEvent) {
super.onPlayerQuit(playerQuitEvent);
}
private void notifyBowCooldownExpired(Player player, Boolean boolValue) {
player.sendMessage(AAC.messagePrefix + this.plugin.messages.getMessage("allow_bow"));
}
}
@@ -0,0 +1,95 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketListener;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.OptionalLong;
import java.util.WeakHashMap;
import me.konsolas.aac.AAC;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.api.HackType;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public final class FightSpeed
extends Detector {
private int maxHit;
private int maxSwing;
private long consistentThreshold;
private boolean consistentCheck;
private final Map<Player, ClickIntervalHistory> attackHistories;
private final Map<Player, ClickIntervalHistory> swingHistories;
public FightSpeed(AAC aAC) {
super(aAC);
this.maxHit = 15;
this.maxSwing = 19;
this.consistentThreshold = 25L;
this.consistentCheck = true;
this.attackHistories = Collections.synchronizedMap(new WeakHashMap<>());
this.swingHistories = Collections.synchronizedMap(new WeakHashMap<>());
this.maxHit = this.plugin.getConfig().getInt("fightspeed.max_hit", this.maxHit);
this.maxSwing = this.plugin.getConfig().getInt("fightspeed.max_swing", this.maxSwing);
this.consistentCheck = this.plugin.getConfig().getBoolean("fightspeed.consistent_check", this.consistentCheck);
this.consistentThreshold = this.plugin.getConfig().getLong("fightspeed.consistent_threshold", this.consistentThreshold);
FightSpeedPacketListener fightSpeedPacketListener = new FightSpeedPacketListener(this, (Plugin)this.plugin, new PacketType[]{PacketType.Play.Client.USE_ENTITY, PacketType.Play.Client.ARM_ANIMATION});
this.packetListeners.add(fightSpeedPacketListener);
ProtocolLibrary.getProtocolManager().addPacketListener((PacketListener)fightSpeedPacketListener);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@Override
public void onTick(long ticks, long ticks2) {
long ticks3 = ticks2;
long ticks4 = ticks3 ^ 0L;
long ticks5 = ticks3 ^ 0x4DEAE20E7407L;
super.onTick(ticks, ticks4);
if (ticks % 20L == 0L) {
for (Player player : Bukkit.getOnlinePlayers()) {
OptionalLong optionalLong;
OptionalLong optionalLong2;
ClickIntervalHistory clickIntervalHistory = this.attackHistories.put(player, new ClickIntervalHistory(this, null));
ClickIntervalHistory clickIntervalHistory2 = this.swingHistories.put(player, new ClickIntervalHistory(this, null));
if (clickIntervalHistory != null) {
if (ClickIntervalHistory.getIntervals(clickIntervalHistory).size() > this.maxHit) {
this.recordViolation(player.getUniqueId(), ClickIntervalHistory.getIntervals(clickIntervalHistory).size() - this.maxHit + 2, HackType.FIGHTSPEED, player.getName() + " failed FightSpeed: hit target " + ClickIntervalHistory.getIntervals(clickIntervalHistory).size() + " times in one second", ticks5);
} else {
this.decreaseViolationLevel(player.getUniqueId(), 1);
}
}
if (clickIntervalHistory2 != null) {
if (ClickIntervalHistory.getIntervals(clickIntervalHistory2).size() > this.maxSwing) {
this.recordViolation(player.getUniqueId(), ClickIntervalHistory.getIntervals(clickIntervalHistory2).size() - this.maxHit, HackType.FIGHTSPEED, player.getName() + " failed FightSpeed: clicking with a CPS of " + ClickIntervalHistory.getIntervals(clickIntervalHistory2).size(), ticks5);
} else {
this.decreaseViolationLevel(player.getUniqueId(), 1);
}
}
if (!this.consistentCheck || clickIntervalHistory == null) continue;
List<Long> list = ClickIntervalHistory.getIntervals(clickIntervalHistory);
synchronized (list) {
optionalLong2 = ClickIntervalHistory.getIntervals(clickIntervalHistory).stream().mapToLong(Long::longValue).min();
optionalLong = ClickIntervalHistory.getIntervals(clickIntervalHistory).stream().mapToLong(Long::longValue).max();
}
if (!optionalLong2.isPresent()) continue;
long ticks6 = optionalLong.getAsLong() - optionalLong2.getAsLong();
if (ClickIntervalHistory.getIntervals(clickIntervalHistory).size() <= 5 || ticks6 >= this.consistentThreshold) continue;
this.recordViolation(player.getUniqueId(), ClickIntervalHistory.getIntervals(clickIntervalHistory).size() - 4, HackType.FIGHTSPEED, player.getName() + " failed FightSpeed: attacking consistently at a rate of " + ClickIntervalHistory.getIntervals(clickIntervalHistory).size() + "/sec", ticks5);
}
}
}
static Map getAttackHistories(FightSpeed fightSpeed) {
return fightSpeed.attackHistories;
}
static Map getSwingHistories(FightSpeed fightSpeed) {
return fightSpeed.swingHistories;
}
}
@@ -0,0 +1,43 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.EnumWrappers;
import java.util.Optional;
import me.konsolas.aac.AAC;
import me.konsolas.aac.compat.UseEntityPacket;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class FightSpeedPacketListener
extends PacketAdapter {
final FightSpeed detector;
public FightSpeedPacketListener(FightSpeed fightSpeed, Plugin plugin, PacketType[] packetTypeArray) {
super(plugin, packetTypeArray);
this.detector = fightSpeed;
}
public void onPacketReceiving(PacketEvent packetEvent) {
Player player = packetEvent.getPlayer();
if (!((AAC)this.plugin).checkManager.isPlayerExempt(player)) {
PacketContainer packetContainer;
if (packetEvent.getPacketType() == PacketType.Play.Client.USE_ENTITY && new UseEntityPacket(packetContainer = packetEvent.getPacket()).getAction() == EnumWrappers.EntityUseAction.ATTACK) {
Optional.ofNullable(FightSpeed.getAttackHistories(this.detector).get(packetEvent.getPlayer())).ifPresent(FightSpeedPacketListener::recordSwingInterval);
} else if (((AAC)this.plugin).combatTracker.hasRecentCombat(packetEvent.getPlayer())) {
Optional.ofNullable(FightSpeed.getSwingHistories(this.detector).get(packetEvent.getPlayer())).ifPresent(FightSpeedPacketListener::recordClickSample);
}
}
}
private static void recordClickSample(Object obj) {
ClickIntervalHistory.recordClick((ClickIntervalHistory)obj);
}
private static void recordSwingInterval(Object obj) {
ClickIntervalHistory.recordClick((ClickIntervalHistory)obj);
}
}
@@ -0,0 +1,140 @@
package me.konsolas.aac.checks.combat;
import java.util.Iterator;
import java.util.Locale;
import java.util.WeakHashMap;
import java.util.stream.Collectors;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.AxisAlignedBoundingBox;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.util.EntityDimensions;
import me.konsolas.aac.compat.ServerVersion;
import me.konsolas.aac.api.HackType;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.util.Vector;
public final class Hitbox
extends Detector
implements CombatCheckListener {
private final WeakHashMap previousTargets;
private final WeakHashMap currentTargets;
private final WeakHashMap<Entity, Long> lastViolationTimes;
private double maxReach;
private double lenience;
private boolean cancel;
private double moveCompensation;
private int minVl;
private int reduceDelay;
static final boolean assertionsDisabled = !Hitbox.class.desiredAssertionStatus();
public Hitbox(AAC aAC) { super(aAC);
this.previousTargets = new WeakHashMap();
this.currentTargets = new WeakHashMap();
this.lastViolationTimes = new WeakHashMap<>();
this.maxReach = 3.5;
this.lenience = 0.6;
this.cancel = true;
this.moveCompensation = 5.0;
this.minVl = 1;
this.reduceDelay = 60;
this.lenience = this.plugin.getConfig().getDouble("hitbox.lenience", this.lenience);
this.cancel = this.plugin.getConfig().getBoolean("hitbox.cancel", this.cancel);
this.maxReach = this.plugin.getConfig().getDouble("hitbox.max_reach", this.maxReach);
this.minVl = this.plugin.getConfig().getInt("hitbox.min_vl", this.minVl);
this.moveCompensation = this.plugin.getConfig().getDouble("hitbox.move_compensation", this.moveCompensation);
this.reduceDelay = this.plugin.getConfig().getInt("hitbox.reduce_delay", this.reduceDelay);
}
@Override
public boolean shouldProcessCombat(EntityDamageByEntityEvent entityDamageByEntityEvent) {
return entityDamageByEntityEvent.getDamager().getType() == EntityType.PLAYER && ((Player)entityDamageByEntityEvent.getDamager()).getGameMode() != GameMode.CREATIVE && entityDamageByEntityEvent.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK;
}
@Override
public void onCombat(EntityDamageByEntityEvent entityDamageByEntityEvent, long ticks) {
double d;
double d2;
Vector vector;
long ticks2 = ticks ^ 0x7B735CA5F5C9L;
if (entityDamageByEntityEvent.getEntity().getType() == EntityType.SLIME || entityDamageByEntityEvent.getEntity().getType() == EntityType.MAGMA_CUBE) {
return;
}
if (AAC.serverVersion.getVersion() == ServerVersion.VER_1_12 && entityDamageByEntityEvent.getCause() == EntityDamageEvent.DamageCause.ENTITY_SWEEP_ATTACK) {
return;
}
if (!assertionsDisabled && !(entityDamageByEntityEvent.getDamager() instanceof Player)) {
throw new AssertionError();
}
Location location = entityDamageByEntityEvent.getDamager().getLocation();
Entity entity = entityDamageByEntityEvent.getEntity();
EntityDimensions entityDimensions = EntityDimensions.forEntity(entity);
Location location2 = entityDamageByEntityEvent.getDamager().getLocation();
Location location3 = location.clone();
Location location4 = location3.distanceSquared(location2) < 1.0 ? location3.add(0.0, ((Player)entityDamageByEntityEvent.getDamager()).getEyeHeight(), 0.0) : location2.add(0.0, ((Player)entityDamageByEntityEvent.getDamager()).getEyeHeight(), 0.0);
Location location5 = entityDamageByEntityEvent.getEntity().getLocation();
double d3 = 0.0;
if (this.previousTargets.containsKey(entityDamageByEntityEvent.getDamager()) && (vector = (Vector)((HitboxTargetCache)this.previousTargets.get((Object)entityDamageByEntityEvent.getDamager())).targets.get(entityDamageByEntityEvent.getEntity().getEntityId())) != null) {
d3 = Math.max(location5.distance(location) - vector.distance(location.toVector()), 0.0) * this.moveCompensation;
}
if ((d2 = Math.min(location4.distance(location5), location4.distance(location5.clone().add(0.0, entityDimensions.getHeight(), 0.0)))) > (d = this.maxReach + entityDimensions.getWidth() / 2.0 + d3) && this.recordViolation(entityDamageByEntityEvent.getDamager().getUniqueId(), 2, HackType.HITBOX, String.format(Locale.UK, entityDamageByEntityEvent.getDamager().getName() + " failed Hitbox: attacked an entity too far away (%.3f blocks, expected %.2f + %.2f + %.2f)", d2, this.maxReach, entityDimensions.getWidth() / 2.0, d3), ticks2)) {
this.lastViolationTimes.put((Player)entityDamageByEntityEvent.getDamager(), System.currentTimeMillis());
if (this.cancel && this.getViolationLevel((Player)entityDamageByEntityEvent.getDamager()) > this.minVl) {
entityDamageByEntityEvent.setCancelled(true);
}
return;
}
Entity entity2 = entityDamageByEntityEvent.getEntity();
AxisAlignedBoundingBox axisAlignedBoundingBox = new AxisAlignedBoundingBox(entityDamageByEntityEvent.getEntity().getLocation().toVector(), EntityDimensions.forEntity(entity2)).expand(new Vector(this.lenience, this.lenience, this.lenience));
if (entityDamageByEntityEvent.getDamager().getVehicle() != null) {
axisAlignedBoundingBox.expand(new Vector(0.3, 0.3, 0.3));
}
Vector vector2 = location4.getDirection();
boolean flag = axisAlignedBoundingBox.intersectsRay(location4.toVector(), vector2);
if (!flag && this.recordViolation(entityDamageByEntityEvent.getDamager().getUniqueId(), 1, HackType.HITBOX, String.format(Locale.UK, entityDamageByEntityEvent.getDamager().getName() + " failed Hitbox: attacked an entity out of their line of sight (reach: %.3f blocks)", d2), ticks2)) {
this.lastViolationTimes.put((Player)entityDamageByEntityEvent.getDamager(), System.currentTimeMillis());
if (this.cancel && this.getViolationLevel((Player)entityDamageByEntityEvent.getDamager()) > this.minVl) {
entityDamageByEntityEvent.setCancelled(true);
}
return;
}
if (System.currentTimeMillis() - this.lastViolationTimes.getOrDefault(entityDamageByEntityEvent.getDamager(), 0L) > (long)(this.reduceDelay * 50)) {
this.decreaseViolationLevel(entityDamageByEntityEvent.getDamager().getUniqueId(), 1);
}
}
@Override
public void onTick(long ticks, long ticks2) {
Iterator iterator = Bukkit.getOnlinePlayers().iterator();
while (iterator.hasNext()) {
Player player = (Player)iterator.next();
if (this.currentTargets.containsKey(player)) {
this.previousTargets.put(player, this.currentTargets.get(player));
}
HitboxTargetCache hitboxTargetCache = new HitboxTargetCache(this, player.getNearbyEntities(6.0, 6.0, 6.0).stream().filter(Hitbox::isLivingEntity).distinct().collect(Collectors.toMap(Entity::getEntityId, Hitbox::getEntityPosition, this::warnDuplicateEntityId)));
this.currentTargets.put(player, hitboxTargetCache);
}
}
private Vector warnDuplicateEntityId(Vector vector, Vector vector2) {
this.plugin.getLogger().warning("Duplicate entity ID returned from #getNearbyEntities (" + vector + " / " + vector2 + ")");
return vector;
}
private static Vector getEntityPosition(Entity entity) {
return entity.getLocation().toVector();
}
private static boolean isLivingEntity(Entity entity) {
return entity instanceof LivingEntity;
}
}
@@ -0,0 +1,14 @@
package me.konsolas.aac.checks.combat;
import java.util.Map;
public class HitboxTargetCache {
final Map targets;
final Hitbox detector;
public HitboxTargetCache(Hitbox hitbox, Map map) {
this.detector = hitbox;
this.targets = map;
}
}
@@ -0,0 +1,137 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketListener;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.BlockPositionView;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.util.GroundCollisionState;
import me.konsolas.aac.checks.movement.MovementCheckListener;
import me.konsolas.aac.api.HackType;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.plugin.Plugin;
public final class Killaura
extends Detector
implements MovementCheckListener,
CombatCheckListener {
private boolean cancelHit;
private int minVl;
private final Map<String, Integer> moduleWeights;
private final Map<String, KillauraModule> modules;
public Killaura(AAC aAC) { super(aAC);
this.cancelHit = true;
this.minVl = 6;
this.moduleWeights = new HashMap();
Killaura killaura = this;
this.modules = new KillauraModuleRegistry(killaura);
this.cancelHit = this.plugin.getConfig().getBoolean("killaura.cancel_hit", this.cancelHit);
this.minVl = this.plugin.getConfig().getInt("killaura.min_vl", this.minVl);
HashSet<String> hashSet = new HashSet<String>();
for (String str : this.modules.keySet()) {
this.moduleWeights.put(str, this.plugin.getConfig().getInt("killaura.modules." + str, 1));
if ((Integer)this.moduleWeights.get(str) >= 0) continue;
hashSet.add(str);
}
for (String str2 : hashSet) {
this.modules.remove(str2);
}
PacketListener packetListener = new KillauraPacketListener(this, (Plugin)this.plugin, new PacketType[]{PacketType.Play.Server.ENTITY_DESTROY, PacketType.Play.Server.ENTITY, PacketType.Play.Server.ENTITY_HEAD_ROTATION, PacketType.Play.Server.REL_ENTITY_MOVE, PacketType.Play.Server.REL_ENTITY_MOVE_LOOK, PacketType.Play.Server.ENTITY_TELEPORT, PacketType.Play.Client.USE_ENTITY, PacketType.Play.Client.ARM_ANIMATION, PacketType.Play.Client.FLYING, PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK, PacketType.Play.Client.LOOK});
this.packetListeners.add(packetListener);
ProtocolLibrary.getProtocolManager().addPacketListener(packetListener);
Server server = Bukkit.getServer();
this.scheduledTaskIds.add(server.getScheduler().scheduleSyncRepeatingTask((Plugin)this.plugin, this::decayKillauraViolations, 35L, 23L));
}
@Override
public void onTick(long ticks, long ticks2) {
this.modules.values().forEach(arg_0 -> Killaura.dispatchModuleTick(ticks, arg_0));
}
private void reportModuleViolation(KillauraViolation killauraViolation, long ticks) {
long ticks2 = (ticks = 0x410E426F8C36L ^ ticks) ^ 0x14745BB2CF6AL;
this.recordViolation(killauraViolation.getPlayer().getUniqueId(), (Integer)this.moduleWeights.get(killauraViolation.getModuleName()), HackType.KILLAURA, killauraViolation.getPlayer().getName() + " failed Killaura: (" + killauraViolation.getModuleName() + ") " + killauraViolation.getMessage(), ticks2);
}
@Override
public void onCombat(EntityDamageByEntityEvent entityDamageByEntityEvent, long ticks) {
this.modules.values().forEach(arg_0 -> Killaura.dispatchModuleEntityDamage(entityDamageByEntityEvent, arg_0));
if (this.cancelHit && this.getViolationLevel((Player)entityDamageByEntityEvent.getDamager()) > this.minVl) {
entityDamageByEntityEvent.setCancelled(true);
}
}
@Override
public boolean shouldProcessCombat(EntityDamageByEntityEvent entityDamageByEntityEvent) {
return entityDamageByEntityEvent.getDamager() instanceof Player;
}
@Override
public void onMovement(PlayerMoveEvent playerMoveEvent, GroundCollisionState groundCollisionState, GroundCollisionState groundCollisionState2, BlockPositionView blockPositionView, BlockPositionView blockPositionView2, long ticks) {
this.modules.values().forEach(arg_0 -> Killaura.dispatchModulePlayerMove(playerMoveEvent, arg_0));
}
@Override
public boolean shouldProcessMovement(PlayerMoveEvent playerMoveEvent) {
return this.plugin.combatTracker.hasRecentCombat(playerMoveEvent.getPlayer());
}
private static void dispatchModulePlayerMove(PlayerMoveEvent playerMoveEvent, KillauraModule killauraModule) {
PlayerMoveEvent playerMoveEvent2 = playerMoveEvent;
killauraModule.onPlayerMove(playerMoveEvent2);
}
private static void dispatchModuleEntityDamage(EntityDamageByEntityEvent entityDamageByEntityEvent, KillauraModule killauraModule) {
EntityDamageByEntityEvent entityDamageByEntityEvent2 = entityDamageByEntityEvent;
killauraModule.onEntityDamageByEntity(entityDamageByEntityEvent2);
}
private static void dispatchModuleTick(long ticks, KillauraModule killauraModule) {
killauraModule.onTick();
}
private void decayKillauraViolations() {
Bukkit.getOnlinePlayers().forEach(this::decayPlayerViolation);
}
private void decayPlayerViolation(Player player) {
this.decreaseViolationLevel(player.getUniqueId(), 1);
}
static void dispatchModuleViolation(Killaura killaura, KillauraViolation killauraViolation, long ticks) {
long ticks2 = (ticks = 0x410E426F8C36L ^ ticks) ^ 0x18DD464A0375L;
killaura.reportModuleViolation(killauraViolation, ticks2);
}
static Map<String, KillauraModule> getModules(Killaura killaura) {
return killaura.modules;
}
}
@@ -0,0 +1,117 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.events.PacketEvent;
import java.util.DoubleSummaryStatistics;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
public class KillauraAccelerationModule
extends KillauraModule {
private final Map<Player, AimRotationDelta> lastRotationDeltas = new WeakHashMap<>();
private final Map<Player, Long> lastAttackTimes = new WeakHashMap<>();
private final PlayerSampleData yawSamples = new PlayerSampleData(100);
private final PlayerSampleData pitchSamples = new PlayerSampleData(100);
private final Map<Player, Integer> rotationStepCounts = new WeakHashMap<>();
public KillauraAccelerationModule(AAC aAC, Consumer<KillauraViolation> consumer) {
super(aAC, consumer);
}
@Override
public void onTick() {
}
@Override
public void onPacket(PacketEvent packetEvent) {
}
@Override
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
Location location = playerMoveEvent.getTo();
Location location2 = playerMoveEvent.getFrom();
KillauraAccelerationModule killauraAccelerationModule = this;
AimRotationDelta aimRotationDelta = new AimRotationDelta(killauraAccelerationModule, location2, location);
if (!this.lastRotationDeltas.containsKey(playerMoveEvent.getPlayer())) {
this.lastRotationDeltas.put(playerMoveEvent.getPlayer(), aimRotationDelta);
return;
}
if (System.currentTimeMillis() - this.lastAttackTimes.getOrDefault(playerMoveEvent.getPlayer(), 0L) < 550L) {
double d;
DoubleSummaryStatistics doubleSummaryStatistics;
AimRotationDelta aimRotationDelta2 = aimRotationDelta;
AimRotationDelta aimRotationDelta3 = (AimRotationDelta)this.lastRotationDeltas.get(playerMoveEvent.getPlayer());
KillauraAccelerationModule killauraAccelerationModule2 = this;
AimRotationDelta aimRotationDelta4 = new AimRotationDelta(killauraAccelerationModule2, aimRotationDelta3, aimRotationDelta2);
this.yawSamples.addSample(playerMoveEvent.getPlayer(), AimRotationDelta.getYawDelta(aimRotationDelta4));
this.pitchSamples.addSample(playerMoveEvent.getPlayer(), AimRotationDelta.getPitchDelta(aimRotationDelta4));
this.lastRotationDeltas.put(playerMoveEvent.getPlayer(), aimRotationDelta);
int value = 0;
if (this.pitchSamples.hasFullSampleData(playerMoveEvent.getPlayer())) {
doubleSummaryStatistics = this.pitchSamples.getSampleData(playerMoveEvent.getPlayer()).getSamples().stream().mapToDouble(Math::abs).summaryStatistics();
d = this.pitchSamples.getSampleData(playerMoveEvent.getPlayer()).getSamples().stream().mapToDouble(Math::abs).sorted().skip(this.pitchSamples.getSampleCapacity() / 2).findFirst().orElseThrow(AssertionError::new);
if (doubleSummaryStatistics.getMax() > 25.0) {
value += 20;
}
if (d > 0.8 && doubleSummaryStatistics.getAverage() > d + 1.5) {
value += 10;
}
}
if (this.yawSamples.hasFullSampleData(playerMoveEvent.getPlayer())) {
doubleSummaryStatistics = this.yawSamples.getSampleData(playerMoveEvent.getPlayer()).getSamples().stream().mapToDouble(Math::abs).summaryStatistics();
d = this.yawSamples.getSampleData(playerMoveEvent.getPlayer()).getSamples().stream().mapToDouble(Math::abs).sorted().skip(this.yawSamples.getSampleCapacity() / 2).findFirst().orElseThrow(AssertionError::new);
if (doubleSummaryStatistics.getMax() > 45.0) {
value += 10;
}
if (d > 0.8 && doubleSummaryStatistics.getAverage() > d * 2.0) {
value += 35;
}
}
int value2 = value;
this.rotationStepCounts.compute(playerMoveEvent.getPlayer(), (arg_0, arg_1) -> KillauraAccelerationModule.incrementRotationStepCount(value2, arg_0, arg_1));
} else {
this.lastRotationDeltas.remove(playerMoveEvent.getPlayer());
}
}
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
block2: {
Player player;
block4: {
block3: {
if (!(entityDamageByEntityEvent.getDamager() instanceof Player) || !(entityDamageByEntityEvent.getEntity() instanceof LivingEntity)) break block2;
if (((Player)entityDamageByEntityEvent.getDamager()).getAllowFlight()) {
return;
}
player = (Player)entityDamageByEntityEvent.getDamager();
if (System.currentTimeMillis() - this.lastAttackTimes.getOrDefault(player, 0L) >= 550L) break block3;
if (this.rotationStepCounts.getOrDefault(player, 0) <= 100) break block4;
this.addPlayerScore(player, (double)((Integer)this.rotationStepCounts.get(player)).intValue() / 10.0);
if (!(this.getPlayerScore(player) > 5.0)) break block4;
this.reportViolation(player, "accel", "abnormal aiming patterns");
this.setPlayerScore(player, this.getPlayerScore(player) * 0.6);
break block4;
}
this.setPlayerScore(player, this.getPlayerScore(player) * 0.95);
for (int i = 0; i < 75; ++i) {
this.yawSamples.getSampleData(player).getSamples().pollLast();
this.pitchSamples.getSampleData(player).getSamples().pollLast();
}
}
this.rotationStepCounts.remove(player);
this.lastAttackTimes.put((Player)entityDamageByEntityEvent.getDamager(), System.currentTimeMillis());
}
}
private static Integer incrementRotationStepCount(int i2, Player player, Integer intVal) {
return intVal == null ? i2 : intVal + i2;
}
}
@@ -0,0 +1,132 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.EnumWrappers;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import net.jodah.expiringmap.ExpirationListener;
import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.plugin.Plugin;
public class KillauraAccuracyModule
extends KillauraModule {
private final ExpiringMap<UUID, AccuracyState> accuracyStates;
private final TargetRotationTracker targetRotationTracker = new TargetRotationTracker();
public KillauraAccuracyModule(AAC aAC, Consumer<KillauraViolation> consumer) {
super(aAC, consumer);
ExpirationPolicy expirationPolicy = ExpirationPolicy.CREATED;
TimeUnit timeUnit = TimeUnit.MILLISECONDS;
long ticks = 500L;
ExpirationListener<UUID, AccuracyState> expirationListener = this::evaluateAccuracyWindow;
this.accuracyStates = ExpiringMap.builder().expirationPolicy(expirationPolicy).expiration(ticks, timeUnit).expirationListener(expirationListener).build();
}
@Override
public void onTick() {
}
@Override
public void onPacket(PacketEvent packetEvent) {
if (packetEvent.getPacketType() == PacketType.Play.Client.ARM_ANIMATION) {
Optional.ofNullable(this.accuracyStates.get(packetEvent.getPlayer().getUniqueId())).ifPresent(KillauraAccuracyModule::incrementAttemptCount);
} else if (this.isAttackPacket(packetEvent.getPacket())) {
Server server = Bukkit.getServer();
server.getScheduler().scheduleSyncDelayedTask((Plugin)this.getPlugin(), () -> this.checkAimDeviationViolation(packetEvent));
}
}
@Override
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
}
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
}
private void checkAimDeviationViolation(PacketEvent packetEvent) {
if (packetEvent.getPacket().getEntityUseActions().read(0) == EnumWrappers.EntityUseAction.ATTACK) {
LivingEntity livingEntity = null;
int value = 0;
try {
for (Entity entity : packetEvent.getPlayer().getNearbyEntities(7.0, 7.0, 7.0)) {
if (entity.getEntityId() == ((Integer)packetEvent.getPacket().getIntegers().read(0)).intValue()) {
if (entity instanceof LivingEntity) {
livingEntity = (LivingEntity)entity;
}
break;
}
++value;
}
}
catch (NullPointerException nullPointerException) {
return;
}
if (value > 5) {
return;
}
if (livingEntity != null) {
AccuracyState accuracyState = (AccuracyState)this.accuracyStates.get(packetEvent.getPlayer().getUniqueId());
if (accuracyState != null) {
++accuracyState.checkCount;
if (this.targetRotationTracker.hasTargetChangedAndMoved(packetEvent.getPlayer(), livingEntity)) {
++accuracyState.accurateHitCount;
}
if (accuracyState.checkCount < 20) {
this.accuracyStates.resetExpiration(packetEvent.getPlayer().getUniqueId());
}
} else {
this.accuracyStates.put(packetEvent.getPlayer().getUniqueId(), new AccuracyState(this, null));
}
}
}
}
private static void incrementAttemptCount(AccuracyState accuracyState) {
++accuracyState.swingCount;
}
private void evaluateAccuracyWindow(UUID uUID, AccuracyState accuracyState) {
Player player = Bukkit.getPlayer((UUID)uUID);
if (player == null) {
return;
}
if (accuracyState.accurateHitCount < accuracyState.checkCount / 10 + 1) {
this.setPlayerScore(player, this.getPlayerScore(player) * 0.95);
return;
}
if (accuracyState.checkCount < 10) {
this.setPlayerScore(player, this.getPlayerScore(player) * 0.975);
return;
}
double d = (double)accuracyState.checkCount / (double)accuracyState.swingCount;
if (Double.isNaN(d)) {
this.addPlayerScore(player, 5 * accuracyState.checkCount);
return;
}
if (d >= 1.0) {
this.addPlayerScore(player, 1.0 * (double)accuracyState.checkCount);
} else if (d > 0.9) {
this.addPlayerScore(player, d * (double)accuracyState.checkCount);
} else {
this.setPlayerScore(player, this.getPlayerScore(player) * 0.9);
}
if (this.getPlayerScore(player) > 5.0) {
this.reportViolation(player, "accuracy", "attacking with high accuracy (r=" + String.format("%.3f", d) + "/" + accuracyState.checkCount + ")");
this.setPlayerScore(player, this.getPlayerScore(player) * 0.6);
}
}
}
@@ -0,0 +1,75 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.events.PacketEvent;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.MathUtilities;
import org.bukkit.Location;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.util.Vector;
public class KillauraAngleModule
extends KillauraModule {
private final PlayerSampleData angleSamples = new PlayerSampleData(4);
public KillauraAngleModule(AAC aAC, Consumer<KillauraViolation> consumer) {
super(aAC, consumer);
}
@Override
public void onTick() {
}
private static Vector directionToTarget(Location location, Location location2) {
double x = location2.getX() - location.getX();
double y = location2.getY() - location.getY();
double z = location2.getZ() - location.getZ();
double d = Math.sqrt(x * x + z * z);
float f = (float)(Math.atan2(z, x) * 180.0 / Math.PI) - 90.0f;
float f2 = (float)(-(Math.atan2(y, d) * 180.0 / Math.PI));
return new Vector(f, f2, 0.0f);
}
@Override
public void onPacket(PacketEvent packetEvent) {
}
@Override
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
}
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
if (entityDamageByEntityEvent.getEntity().getNearbyEntities(1.0, 3.0, 1.0).size() <= 2 && entityDamageByEntityEvent.getDamager().getType() == EntityType.PLAYER && entityDamageByEntityEvent.getEntity() instanceof LivingEntity && entityDamageByEntityEvent.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK) {
double d;
double d2;
Player player = (Player)entityDamageByEntityEvent.getDamager();
if (player.getAllowFlight()) {
return;
}
LivingEntity livingEntity = (LivingEntity)entityDamageByEntityEvent.getEntity();
Location location = livingEntity.getLocation().add(0.0, livingEntity.getEyeHeight(), 0.0);
Location location2 = player.getLocation().add(0.0, player.getEyeHeight(), 0.0);
Vector vector = new Vector(location2.getYaw(), location2.getPitch(), 0.0f);
Vector vector2 = KillauraAngleModule.directionToTarget(location2, location);
double x = d2 = vector.getX() - vector2.getX();
double d3 = MathUtilities.wrapDegrees(x);
double y = d = vector.getY() - vector2.getY();
double d4 = MathUtilities.wrapDegrees(y);
double x2 = Math.sqrt(Math.pow(player.getLocation().getX() - livingEntity.getLocation().getX(), 2.0) + Math.pow(player.getLocation().getZ() - livingEntity.getLocation().getZ(), 2.0));
double d5 = location2.distance(location);
double y2 = Math.abs(d3 * x2 * d5) + Math.abs(d4 * Math.abs(location.getY() - location2.getY()) * d5);
this.angleSamples.addSample(player, y2);
if (this.angleSamples.hasFullSampleData(player) && this.angleSamples.getMean(player) / 20.0 > 5.0) {
this.reportViolation(player, "angle", "not aiming on target (s=" + this.angleSamples.getMean(player) + ")");
this.angleSamples.getSampleData(player).clear();
}
}
}
}
@@ -0,0 +1,56 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketEvent;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
public class KillauraClickModule
extends KillauraModule {
private final Map<Player, Long> lastMovePacketTimes = new WeakHashMap<>();
private final Set<Player> fastClickPlayers = Collections.newSetFromMap(new WeakHashMap<>());
public KillauraClickModule(AAC aAC, Consumer<KillauraViolation> consumer) {
super(aAC, consumer);
}
@Override
public void onTick() {
}
@Override
public void onPacket(PacketEvent packetEvent) {
if (packetEvent.getPacketType() == PacketType.Play.Client.ARM_ANIMATION) {
if (System.currentTimeMillis() - this.lastMovePacketTimes.getOrDefault(packetEvent.getPlayer(), Long.MAX_VALUE) < 40L) {
if (this.fastClickPlayers.contains(packetEvent.getPlayer())) {
this.addPlayerScore(packetEvent.getPlayer(), 1.25);
if (this.getPlayerScore(packetEvent.getPlayer()) > 5.0) {
this.reportViolation(packetEvent.getPlayer(), "click", "attacking too quickly");
}
} else {
this.fastClickPlayers.add(packetEvent.getPlayer());
}
this.setPlayerScore(packetEvent.getPlayer(), this.getPlayerScore(packetEvent.getPlayer()) * 0.9);
}
} else if (this.isMovementPacket(packetEvent.getPacketType())) {
this.fastClickPlayers.remove(packetEvent.getPlayer());
this.lastMovePacketTimes.put(packetEvent.getPlayer(), System.currentTimeMillis());
}
}
@Override
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
}
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
}
}
@@ -0,0 +1,63 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketEvent;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
public class KillauraLookModule
extends KillauraModule {
private final Set lookPlayers = new HashSet();
private final Set positionLookPlayers = new HashSet();
private final Set attackingPlayers = new HashSet();
public KillauraLookModule(AAC aAC, Consumer<KillauraViolation> consumer) {
super(aAC, consumer);
}
@Override
public void onTick() {
Iterator iterator = Bukkit.getOnlinePlayers().iterator();
while (iterator.hasNext()) {
Player player = (Player)iterator.next();
if (this.lookPlayers.contains(player) && this.positionLookPlayers.contains(player) && this.attackingPlayers.contains(player)) {
this.addPlayerScore(player, 1.0);
if (!(this.getPlayerScore(player) > 5.0)) continue;
this.reportViolation(player, "look", "unexpected flying packet without position");
this.setPlayerScore(player, this.getPlayerScore(player) * 0.6);
continue;
}
this.setPlayerScore(player, this.getPlayerScore(player) * 0.9);
}
this.lookPlayers.clear();
this.positionLookPlayers.clear();
this.attackingPlayers.clear();
}
@Override
public void onPacket(PacketEvent packetEvent) {
if (packetEvent.getPacketType() == PacketType.Play.Client.POSITION_LOOK) {
this.positionLookPlayers.add(packetEvent.getPlayer());
} else if (packetEvent.getPacketType() == PacketType.Play.Client.LOOK) {
this.lookPlayers.add(packetEvent.getPlayer());
} else if (this.isAttackPacket(packetEvent.getPacket())) {
this.attackingPlayers.add(packetEvent.getPlayer());
}
}
@Override
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
}
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
}
}
@@ -0,0 +1,129 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.EnumWrappers;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.AxisAlignedBoundingBox;
import me.konsolas.aac.util.EntityDimensions;
import me.konsolas.aac.util.EntityTypeChecks;
import net.jodah.expiringmap.ExpirationListener;
import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector;
public class KillauraMissModule
extends KillauraModule {
private final ExpiringMap<UUID, Boolean> pendingMissChecks;
private final ExpiringMap<UUID, Boolean> attackedThisTick;
private final ExpiringMap<UUID, Entity> recentTargets;
public KillauraMissModule(AAC aAC, Consumer<KillauraViolation> consumer) {
super(aAC, consumer);
TimeUnit timeUnit = TimeUnit.MILLISECONDS;
long ticks = 1000L;
ExpirationPolicy expirationPolicy = ExpirationPolicy.CREATED;
this.recentTargets = ExpiringMap.builder().expiration(ticks, timeUnit).expirationPolicy(expirationPolicy).build();
TimeUnit timeUnit2 = TimeUnit.MILLISECONDS;
long ticks2 = 15L;
ExpirationPolicy expirationPolicy2 = ExpirationPolicy.CREATED;
ExpirationListener<UUID, Boolean> expirationListener = this::scheduleMissCheck;
this.pendingMissChecks = ExpiringMap.builder().expiration(ticks2, timeUnit2).expirationPolicy(expirationPolicy2).expirationListener(expirationListener).build();
TimeUnit timeUnit3 = TimeUnit.MILLISECONDS;
long ticks3 = 15L;
ExpirationPolicy expirationPolicy3 = ExpirationPolicy.CREATED;
this.attackedThisTick = ExpiringMap.builder().expiration(ticks3, timeUnit3).expirationPolicy(expirationPolicy3).build();
}
@Override
public void onTick() {
}
@Override
public void onPacket(PacketEvent packetEvent) {
if (!packetEvent.isServerPacket()) {
if (packetEvent.getPacketType() == PacketType.Play.Client.USE_ENTITY) {
if (packetEvent.getPacket().getEntityUseActions().read(0) == EnumWrappers.EntityUseAction.ATTACK) {
int i;
this.pendingMissChecks.remove(packetEvent.getPlayer().getUniqueId());
this.attackedThisTick.put(packetEvent.getPlayer().getUniqueId(), false);
try {
i = ((Entity)this.recentTargets.get(packetEvent.getPlayer().getUniqueId())).getEntityId();
}
catch (NullPointerException nullPointerException) {
return;
}
if (i == (Integer)packetEvent.getPacket().getIntegers().read(0)) {
this.recentTargets.resetExpiration(packetEvent.getPlayer().getUniqueId());
}
}
} else if (packetEvent.getPacketType() == PacketType.Play.Client.ARM_ANIMATION && !this.pendingMissChecks.containsKey(packetEvent.getPlayer().getUniqueId()) && !this.attackedThisTick.containsKey(packetEvent.getPlayer().getUniqueId())) {
Vector vector = packetEvent.getPlayer().getEyeLocation().toVector();
Vector vector2 = packetEvent.getPlayer().getLocation().getDirection();
boolean flag = false;
Entity entity = (Entity)this.recentTargets.get(packetEvent.getPlayer().getUniqueId());
if (entity != null && EntityTypeChecks.isCommonCombatTarget(entity.getType())) {
double d;
try {
d = packetEvent.getPlayer().getEyeLocation().distance(entity.getLocation());
}
catch (IllegalArgumentException illegalArgumentException) {
return;
}
if (d < 1.5 || d > 3.5) {
return;
}
Entity entity2 = entity;
AxisAlignedBoundingBox axisAlignedBoundingBox = new AxisAlignedBoundingBox(entity.getLocation().toVector(), EntityDimensions.forEntity(entity2)).expand(new Vector(-0.05, -0.2, -0.05));
if (axisAlignedBoundingBox.intersectsRay(vector, vector2)) {
flag = true;
}
this.pendingMissChecks.put(packetEvent.getPlayer().getUniqueId(), flag);
}
}
}
}
@Override
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
}
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
this.recentTargets.put(entityDamageByEntityEvent.getDamager().getUniqueId(), entityDamageByEntityEvent.getEntity());
}
private void scheduleMissCheck(UUID uUID, Boolean boolValue) {
Server server = Bukkit.getServer();
server.getScheduler().scheduleSyncDelayedTask((Plugin)this.getPlugin(), () -> this.verifyMissedSwing(uUID, boolValue));
}
private void verifyMissedSwing(UUID uUID, Boolean boolValue) {
Player player = Bukkit.getPlayer((UUID)uUID);
try {
Block block = player.getTargetBlock((Set)null, 5);
if (block != null && block.getType() != Material.AIR) {
return;
}
}
catch (Exception exception) {
}
if (player != null && boolValue.booleanValue() && this.recentTargets.containsKey(uUID)) {
this.reportViolation(player, "miss", "attack packets not correlating with swings");
}
}
}
@@ -0,0 +1,67 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.EnumWrappers;
import java.util.WeakHashMap;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import me.konsolas.aac.compat.UseEntityPacket;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
public abstract class KillauraModule {
private final AAC plugin;
private final Consumer<KillauraViolation> violationConsumer;
private final WeakHashMap<Player, Double> playerScores = new WeakHashMap<>();
public KillauraModule(AAC aAC, Consumer<KillauraViolation> consumer) {
this.plugin = aAC;
this.violationConsumer = consumer;
}
public AAC getPlugin() {
return this.plugin;
}
protected boolean isAttackPacket(PacketContainer packetContainer) {
if (packetContainer.getType() != PacketType.Play.Client.USE_ENTITY) {
return false;
}
PacketContainer packetContainer2 = packetContainer;
UseEntityPacket useEntityPacket = new UseEntityPacket(packetContainer2);
return useEntityPacket.getAction() == EnumWrappers.EntityUseAction.ATTACK;
}
protected boolean isMovementPacket(PacketType packetType) {
return packetType == PacketType.Play.Client.FLYING || packetType == PacketType.Play.Client.POSITION || packetType == PacketType.Play.Client.POSITION_LOOK || packetType == PacketType.Play.Client.LOOK;
}
protected void reportViolation(Player player, String str, String str2) {
this.violationConsumer.accept(new KillauraViolation(this, player, str, str2, null));
}
protected void setPlayerScore(Player player, double d) {
this.playerScores.put(player, d);
}
protected double getPlayerScore(Player player) {
return this.playerScores.getOrDefault(player, 0.0);
}
protected void addPlayerScore(Player player, double d) {
this.playerScores.put(player, this.getPlayerScore(player) + d);
}
public abstract void onTick();
public abstract void onPacket(PacketEvent event);
public abstract void onPlayerMove(PlayerMoveEvent event);
public abstract void onEntityDamageByEntity(EntityDamageByEntityEvent event);
}
@@ -0,0 +1,62 @@
package me.konsolas.aac.checks.combat;
import java.util.HashMap;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
public class KillauraModuleRegistry
extends HashMap<String, KillauraModule> {
final Killaura detector;
public KillauraModuleRegistry(Killaura killaura) {
this.detector = killaura;
Consumer<KillauraViolation> consumer = arg_0 -> KillauraModuleRegistry.reportModuleViolation(this.detector, arg_0);
AAC aAC = this.detector.getPlugin();
this.put("natural", new KillauraNaturalModule(aAC, consumer));
this.put("round", new KillauraRoundingModule(this.detector.getPlugin(), arg_0 -> KillauraModuleRegistry.reportModuleViolation(this.detector, arg_0)));
this.put("split", new KillauraSplitModule(this.detector.getPlugin(), arg_0 -> KillauraModuleRegistry.reportModuleViolation(this.detector, arg_0)));
this.put("sporadic", new KillauraSporadicModule(this.detector.getPlugin(), arg_0 -> KillauraModuleRegistry.reportModuleViolation(this.detector, arg_0)));
this.put("stable", new KillauraStableModule(this.detector.getPlugin(), arg_0 -> KillauraModuleRegistry.reportModuleViolation(this.detector, arg_0)));
Consumer<KillauraViolation> consumer2 = arg_0 -> KillauraModuleRegistry.reportModuleViolation(this.detector, arg_0);
AAC aAC2 = this.detector.getPlugin();
this.put("switch", new KillauraSwitchModule(aAC2, consumer2));
this.put("angle", new KillauraAngleModule(this.detector.getPlugin(), arg_0 -> KillauraModuleRegistry.reportModuleViolation(this.detector, arg_0)));
this.put("click", new KillauraClickModule(this.detector.getPlugin(), arg_0 -> KillauraModuleRegistry.reportModuleViolation(this.detector, arg_0)));
Consumer<KillauraViolation> consumer3 = arg_0 -> KillauraModuleRegistry.reportModuleViolation(this.detector, arg_0);
AAC aAC3 = this.detector.getPlugin();
this.put("miss", new KillauraMissModule(aAC3, consumer3));
this.put("tick", new KillauraTickModule(this.detector.getPlugin(), arg_0 -> KillauraModuleRegistry.reportModuleViolation(this.detector, arg_0)));
this.put("yaw", new KillauraYawModule(this.detector.getPlugin(), arg_0 -> KillauraModuleRegistry.reportModuleViolation(this.detector, arg_0)));
this.put("normal", new KillauraNormalModule(this.detector.getPlugin(), arg_0 -> KillauraModuleRegistry.reportModuleViolation(this.detector, arg_0)));
this.put("look", new KillauraLookModule(this.detector.getPlugin(), arg_0 -> KillauraModuleRegistry.reportModuleViolation(this.detector, arg_0)));
Consumer<KillauraViolation> consumer4 = arg_0 -> KillauraModuleRegistry.reportModuleViolation(this.detector, arg_0);
AAC aAC4 = this.detector.getPlugin();
this.put("timing", new KillauraTimingModule(aAC4, consumer4));
this.put("accel", new KillauraAccelerationModule(this.detector.getPlugin(), arg_0 -> KillauraModuleRegistry.reportModuleViolation(this.detector, arg_0)));
Consumer<KillauraViolation> consumer5 = arg_0 -> KillauraModuleRegistry.reportModuleViolation(this.detector, arg_0);
AAC aAC5 = this.detector.getPlugin();
this.put("accuracy", new KillauraAccuracyModule(aAC5, consumer5));
this.put("pattern", new KillauraPatternModule(this.detector.getPlugin(), arg_0 -> KillauraModuleRegistry.reportModuleViolation(this.detector, arg_0)));
}
private static void reportModuleViolation(Killaura killaura, KillauraViolation killauraViolation) {
Killaura.dispatchModuleViolation(killaura, killauraViolation, 116899669967483L);
}
}
@@ -0,0 +1,146 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.events.PacketEvent;
import java.util.Optional;
import java.util.UUID;
import java.util.WeakHashMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;
import me.konsolas.aac.util.MathUtilities;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.util.Vector;
public class KillauraNaturalModule
extends KillauraModule {
private final WeakHashMap<Player, NaturalAimState> aimStates = new WeakHashMap<>();
private final ExpiringMap<UUID, Boolean> recentCombatPlayers;
private final TargetRotationTracker targetRotationTracker = new TargetRotationTracker();
public KillauraNaturalModule(AAC aAC, Consumer<KillauraViolation> consumer) {
super(aAC, consumer);
ExpirationPolicy expirationPolicy = ExpirationPolicy.CREATED;
TimeUnit timeUnit = TimeUnit.MILLISECONDS;
long ticks = 750L;
this.recentCombatPlayers = ExpiringMap.builder().expirationPolicy(expirationPolicy).expiration(ticks, timeUnit).build();
}
@Override
public void onTick() {
}
@Override
public void onPacket(PacketEvent packetEvent) {
}
@Override
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
if (!this.recentCombatPlayers.containsKey(playerMoveEvent.getPlayer().getUniqueId())) {
this.aimStates.remove(playerMoveEvent.getPlayer());
}
this.aimStates.putIfAbsent(playerMoveEvent.getPlayer(), new NaturalAimState(this, null));
NaturalAimState naturalAimState = (NaturalAimState)this.aimStates.get(playerMoveEvent.getPlayer());
Vector vector = playerMoveEvent.getFrom().getDirection().normalize();
LivingEntity livingEntity = this.findTargetInView(playerMoveEvent.getPlayer(), vector);
if (livingEntity != null) {
boolean flag;
double d;
double d2 = d = this.vectorToYaw(this.vectorBetween(playerMoveEvent.getPlayer().getLocation(), livingEntity.getLocation()));
double yaw = playerMoveEvent.getFrom().getYaw();
double d3 = d2;
double d4 = yaw;
double d5 = MathUtilities.angleDifferenceAbs(d4, d3);
double d6 = d;
double yaw2 = playerMoveEvent.getTo().getYaw();
double d7 = d6;
double d8 = yaw2;
double d9 = MathUtilities.angleDifferenceAbs(d8, d7);
double yaw3 = playerMoveEvent.getFrom().getYaw();
double yaw4 = playerMoveEvent.getTo().getYaw();
double d10 = yaw3;
double d11 = yaw4;
double pitch = playerMoveEvent.getFrom().getPitch();
double pitch2 = playerMoveEvent.getTo().getPitch();
double d12 = pitch;
double d13 = pitch2;
double d14 = Math.sqrt(Math.pow(MathUtilities.angleDifferenceAbs(d11, d10), 2.0) + Math.pow(MathUtilities.angleDifferenceAbs(d13, d12), 2.0));
boolean flag2 = flag = d5 > d9;
if (naturalAimState.switchedOffTarget) {
if (flag) {
if (naturalAimState.hitSampleCount <= 5 && naturalAimState.hitDeltaAvg < (double)naturalAimState.hitSampleCount / 2.0) {
this.setPlayerScore(playerMoveEvent.getPlayer(), this.getPlayerScore(playerMoveEvent.getPlayer()) * 0.8 - 1.0);
} else if (naturalAimState.hitSampleCount > 10 && naturalAimState.missedSampleCount < naturalAimState.hitSampleCount - 6 && naturalAimState.hitDeltaAvg > 1.8 && naturalAimState.streakCount > 0) {
this.addPlayerScore(playerMoveEvent.getPlayer(), 2 + (naturalAimState.hitSampleCount - naturalAimState.missedSampleCount));
} else if (d5 < 17.5 && naturalAimState.hitSampleCount > 6 && naturalAimState.streakCount > 0) {
this.addPlayerScore(playerMoveEvent.getPlayer(), (double)(naturalAimState.hitSampleCount * naturalAimState.hitSampleCount) / 4.0);
} else {
this.setPlayerScore(playerMoveEvent.getPlayer(), this.getPlayerScore(playerMoveEvent.getPlayer()) * 0.9 - 0.5);
}
if (this.getPlayerScore(playerMoveEvent.getPlayer()) > 20.0) {
this.reportViolation(playerMoveEvent.getPlayer(), "natural", "unnatural aiming patterns (" + naturalAimState + ")");
this.setPlayerScore(playerMoveEvent.getPlayer(), this.getPlayerScore(playerMoveEvent.getPlayer()) * 0.5);
}
this.aimStates.put(playerMoveEvent.getPlayer(), new NaturalAimState(this, null));
} else {
naturalAimState.missedDeltaAvg = naturalAimState.missedDeltaAvg != 0.0 ? (naturalAimState.missedDeltaAvg + d14) / 2.0 : d14;
++naturalAimState.missedSampleCount;
}
} else if (flag) {
naturalAimState.hitDeltaAvg = naturalAimState.hitDeltaAvg != 0.0 ? (naturalAimState.hitDeltaAvg + d14) / 2.0 : d14;
++naturalAimState.hitSampleCount;
} else {
naturalAimState.switchedOffTarget = true;
}
}
}
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
if (entityDamageByEntityEvent.getDamager() instanceof Player && entityDamageByEntityEvent.getEntity() instanceof LivingEntity) {
Player player = (Player)entityDamageByEntityEvent.getDamager();
this.recentCombatPlayers.put(player.getUniqueId(), Boolean.TRUE);
this.recentCombatPlayers.resetExpiration(player.getUniqueId());
if (this.targetRotationTracker.hasTargetChangedAndMoved(player, (LivingEntity)entityDamageByEntityEvent.getEntity())) {
Optional.ofNullable(this.aimStates.get(player)).ifPresent(KillauraNaturalModule::markAttackSampled);
}
}
}
private LivingEntity findTargetInView(Player player, Vector vector) {
LivingEntity livingEntity = null;
double d = Double.MAX_VALUE;
for (Entity entity : player.getNearbyEntities(5.0, 5.0, 5.0)) {
if (!(entity instanceof LivingEntity)) continue;
LivingEntity livingEntity2 = (LivingEntity)entity;
if (livingEntity == null) {
livingEntity = (LivingEntity)entity;
continue;
}
double d2 = this.vectorBetween(player.getLocation(), livingEntity2.getLocation()).distanceSquared(vector);
if (!(d2 < d)) continue;
d = d2;
livingEntity = livingEntity2;
}
return livingEntity;
}
private Vector vectorBetween(Location location, Location location2) {
return location2.toVector().subtract(location.toVector());
}
private double vectorToYaw(Vector vector) {
return -Math.toDegrees(Math.atan2(vector.getX(), vector.getZ()));
}
private static void markAttackSampled(NaturalAimState naturalAimState) {
++naturalAimState.streakCount;
}
}
@@ -0,0 +1,149 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.EnumWrappers;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import me.konsolas.aac.compat.EntityDestroyPacket;
import me.konsolas.aac.compat.EntityTeleportPacket;
import me.konsolas.aac.compat.FakeEntityGroup;
import me.konsolas.aac.compat.UseEntityPacket;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
public class KillauraNormalModule
extends KillauraModule {
private final Map<Player, Map<Integer, FakeEntityGroup>> playerBotGroups = Collections.synchronizedMap(new WeakHashMap<>());
public KillauraNormalModule(AAC aAC, Consumer<KillauraViolation> consumer) {
super(aAC, consumer);
}
@Override
public void onTick() {
}
/*
* Enabled force condition propagation
* Lifted jumps to return sites
*/
@Override
public void onPacket(PacketEvent packetEvent) {
if (packetEvent.isServerPacket()) {
this.playerBotGroups.putIfAbsent(packetEvent.getPlayer(), new ConcurrentHashMap());
try {
Player player = packetEvent.getPlayer();
if (this.getPlugin().checkManager.isPlayerExempt(player)) return;
if (packetEvent.getPacketType() == PacketType.Play.Server.ENTITY_DESTROY) {
PacketContainer packetContainer = packetEvent.getPacket();
EntityDestroyPacket entityDestroyPacket = new EntityDestroyPacket(packetContainer);
for (int i : entityDestroyPacket.getEntityIds()) {
if (!((Map)this.playerBotGroups.get(packetEvent.getPlayer())).containsKey(i)) continue;
for (PacketContainer packetContainer2 : FakeEntityGroup.getDestroyPackets((FakeEntityGroup)((Map)this.playerBotGroups.get(packetEvent.getPlayer())).get(i))) {
ProtocolLibrary.getProtocolManager().sendServerPacket(packetEvent.getPlayer(), packetContainer2, false);
}
((Map)this.playerBotGroups.get(packetEvent.getPlayer())).remove(i);
}
return;
}
if (packetEvent.getPacketType() != PacketType.Play.Server.ENTITY_TELEPORT && packetEvent.getPacketType() != PacketType.Play.Server.REL_ENTITY_MOVE && packetEvent.getPacketType() != PacketType.Play.Server.REL_ENTITY_MOVE_LOOK) return;
int value = (Integer)packetEvent.getPacket().getIntegers().read(0);
if (!((Map)this.playerBotGroups.get(packetEvent.getPlayer())).containsKey(value)) {
return;
}
FakeEntityGroup fakeEntityGroup = (FakeEntityGroup)((Map)this.playerBotGroups.get(packetEvent.getPlayer())).get(value);
if (FakeEntityGroup.isExpired(fakeEntityGroup)) {
for (PacketContainer packetContainer : FakeEntityGroup.getDestroyPackets((FakeEntityGroup)((Map)this.playerBotGroups.get(packetEvent.getPlayer())).get(value))) {
ProtocolLibrary.getProtocolManager().sendServerPacket(packetEvent.getPlayer(), packetContainer, false);
}
((Map)this.playerBotGroups.get(packetEvent.getPlayer())).remove(value);
return;
}
if (packetEvent.getPacketType().equals((Object)PacketType.Play.Server.ENTITY_TELEPORT)) {
PacketContainer packetContainer = packetEvent.getPacket();
EntityTeleportPacket entityTeleportPacket = new EntityTeleportPacket(packetContainer);
Location location = new Location(packetEvent.getPlayer().getWorld(), entityTeleportPacket.getX(), entityTeleportPacket.getY(), entityTeleportPacket.getZ(), entityTeleportPacket.getYaw(), entityTeleportPacket.getPitch());
for (PacketContainer packetContainer3 : FakeEntityGroup.getTeleportPackets((FakeEntityGroup)((Map)this.playerBotGroups.get(packetEvent.getPlayer())).get(value), location)) {
ProtocolLibrary.getProtocolManager().sendServerPacket(packetEvent.getPlayer(), packetContainer3, false);
}
return;
}
for (PacketContainer packetContainer : FakeEntityGroup.clonePackets((FakeEntityGroup)((Map)this.playerBotGroups.get(packetEvent.getPlayer())).get(value), packetEvent.getPacket())) {
ProtocolLibrary.getProtocolManager().sendServerPacket(packetEvent.getPlayer(), packetContainer, false);
}
return;
}
catch (InvocationTargetException invocationTargetException) {
throw new RuntimeException(invocationTargetException);
}
catch (NullPointerException nullPointerException) {
this.getPlugin().getLogger().warning("Failed to manipulate killaura packets: " + packetEvent.getPacket());
throw new RuntimeException(nullPointerException);
}
} else {
PacketContainer packetContainer;
UseEntityPacket useEntityPacket;
this.playerBotGroups.putIfAbsent(packetEvent.getPlayer(), new ConcurrentHashMap());
if (packetEvent.getPacketType() != PacketType.Play.Client.USE_ENTITY || (useEntityPacket = new UseEntityPacket(packetContainer = packetEvent.getPacket())).getAction() != EnumWrappers.EntityUseAction.ATTACK) return;
if (((Map)this.playerBotGroups.get(packetEvent.getPlayer())).containsKey(useEntityPacket.getTargetEntityId()) && FakeEntityGroup.isSettled((FakeEntityGroup)((Map)this.playerBotGroups.get(packetEvent.getPlayer())).get(useEntityPacket.getTargetEntityId()))) {
this.reportViolation(packetEvent.getPlayer(), "normal", "unexpected id in attack packet");
}
for (Map.Entry<Integer, FakeEntityGroup> entry : this.playerBotGroups.get(packetEvent.getPlayer()).entrySet()) {
Optional optional = FakeEntityGroup.getOffsetForEntityId((FakeEntityGroup)entry.getValue(), useEntityPacket.getTargetEntityId());
if (!optional.isPresent() || packetEvent.getPlayer().getEntityId() == ((Integer)entry.getKey()).intValue()) continue;
useEntityPacket.setTargetEntityId((Integer)entry.getKey());
FakeEntityGroup.updateLastAttack((FakeEntityGroup)entry.getValue());
return;
}
}
}
@Override
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
}
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
if (entityDamageByEntityEvent.getEntity() instanceof Player) {
Player player = (Player)entityDamageByEntityEvent.getDamager();
LivingEntity livingEntity = (LivingEntity)entityDamageByEntityEvent.getEntity();
this.playerBotGroups.putIfAbsent(player, new ConcurrentHashMap());
if (livingEntity.getVehicle() != null || ((Map)this.playerBotGroups.get(player)).containsKey(livingEntity.getEntityId())) {
return;
}
FakeEntityGroup fakeEntityGroup = new FakeEntityGroup(this, null);
try {
for (PacketContainer packetContainer : FakeEntityGroup.getSpawnPackets(fakeEntityGroup, (Entity)livingEntity)) {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetContainer, false);
}
for (PacketContainer packetContainer : FakeEntityGroup.getTeleportPackets(fakeEntityGroup, livingEntity.getLocation())) {
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetContainer, false);
}
((Map)this.playerBotGroups.get(player)).put(livingEntity.getEntityId(), fakeEntityGroup);
}
catch (InvocationTargetException invocationTargetException) {
this.getPlugin().getLogger().warning("Failed to spawn killaura entities");
}
}
}
static {
if (null != null) {
// empty if block
}
}
}
@@ -0,0 +1,25 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import org.bukkit.plugin.Plugin;
public class KillauraPacketListener
extends PacketAdapter {
final Killaura detector;
public KillauraPacketListener(Killaura killaura, Plugin plugin, PacketType[] packetTypeArray) {
super(plugin, packetTypeArray);
this.detector = killaura;
}
public void onPacketReceiving(PacketEvent packetEvent) {
Killaura.getModules(this.detector).values().forEach(module -> module.onPacket(packetEvent));
}
public void onPacketSending(PacketEvent packetEvent) {
Killaura.getModules(this.detector).values().forEach(module -> module.onPacket(packetEvent));
}
}
@@ -0,0 +1,148 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.events.PacketEvent;
import java.util.AbstractMap;
import java.util.Iterator;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.MathUtilities;
import me.konsolas.aac.compat.NearbyTargetLookup;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.plugin.Plugin;
public class KillauraPatternModule
extends KillauraModule {
private static final int[] NETWORK_TOPOLOGY = new int[]{2, 2, 1};
private final Map<Player, TrainingSet> trainingSets = new WeakHashMap<>();
private final Map<Player, Long> lastAttackTimes = new WeakHashMap<>();
private final TargetRotationTracker targetRotationTracker = new TargetRotationTracker(false);
private final Map<Player, Integer> validHitCounts = new WeakHashMap<>();
private final Map<Player, Map.Entry<NeuralNetwork, TrainingSet>> trainedModels = new WeakHashMap<>();
public KillauraPatternModule(AAC aAC, Consumer<KillauraViolation> consumer) {
super(aAC, consumer);
}
@Override
public void onTick() {
}
private static double evaluateMeanError(NeuralNetwork neuralNetwork, TrainingSet trainingSet) {
double d = 0.0;
Iterator iterator = trainingSet.iterator();
while (iterator.hasNext()) {
TrainingSample trainingSample = (TrainingSample)iterator.next();
double[] dArray = trainingSample.getInputs();
double d2 = trainingSample.getExpectedOutputs()[0];
double d3 = neuralNetwork.evaluate(dArray)[0];
double d4 = Math.abs(d2 - d3);
d += d4;
}
d /= (double)trainingSet.size();
return d *= 180.0;
}
@Override
public void onPacket(PacketEvent packetEvent) {
}
@Override
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
double d;
long ticks;
Player player;
Player player2;
Player player3 = player2 = (player = playerMoveEvent.getPlayer());
LivingEntity livingEntity = NearbyTargetLookup.findClosestLivingEntity(player3);
if (livingEntity == null) {
this.trainingSets.remove(player);
this.trainedModels.remove(player);
this.validHitCounts.remove(player);
return;
}
long ticks2 = ticks = this.lastAttackTimes.containsKey(player) ? (Long)this.lastAttackTimes.get(player) : 0L;
if (System.currentTimeMillis() - ticks > 1250L) {
this.trainingSets.remove(player);
this.trainedModels.remove(player);
this.validHitCounts.remove(player);
return;
}
LivingEntity livingEntity2 = livingEntity;
Player player4 = player;
LivingEntity livingEntity3 = livingEntity2;
Player player5 = player4;
double d2 = NearbyTargetLookup.getYawDifferenceToTarget(player5, (Entity)livingEntity3) / 180.0;
double d3 = player.getLocation().distance(livingEntity.getLocation()) / 6.0;
double yaw = d = (double)(playerMoveEvent.getTo().getYaw() - playerMoveEvent.getFrom().getYaw());
double d4 = Math.abs(MathUtilities.wrapDegrees(yaw));
double d5 = d4 / 180.0;
if (!this.trainingSets.containsKey(player) && !this.trainedModels.containsKey(player)) {
this.trainingSets.put(player, new TrainingSet());
this.validHitCounts.remove(player);
}
if (this.trainingSets.containsKey(player)) {
TrainingSet trainingSet = (TrainingSet)this.trainingSets.get(player);
trainingSet.addSample(new TrainingSample(new double[]{d2, d3}, new double[]{d5}));
if (trainingSet.size() == 5) {
Server server = Bukkit.getServer();
server.getScheduler().runTaskAsynchronously((Plugin)this.getPlugin(), () -> this.trainPatternNetwork(trainingSet, player));
}
} else if (this.trainedModels.containsKey(player)) {
Map.Entry entry = (Map.Entry)this.trainedModels.get(player);
((TrainingSet)entry.getValue()).addSample(new TrainingSample(new double[]{d2, d3}, new double[]{d5}));
if (((TrainingSet)entry.getValue()).size() == 20) {
this.trainedModels.remove(player);
if (this.validHitCounts.getOrDefault(player, 0) < 1) {
return;
}
double d6 = KillauraPatternModule.evaluateMeanError((NeuralNetwork)entry.getKey(), (TrainingSet)entry.getValue());
if (d6 <= 2.5) {
this.addPlayerScore(player, 1.0 + (2.5 - d6));
if (this.getPlayerScore(player) > 3.0) {
this.reportViolation(player, "pattern", "computer-like aiming patterns (d=" + d6 + ")");
this.setPlayerScore(player, this.getPlayerScore(player) - 1.0);
}
} else {
this.setPlayerScore(player, this.getPlayerScore(playerMoveEvent.getPlayer()) * 0.95);
}
}
}
}
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
if (entityDamageByEntityEvent.getDamager().getType() == EntityType.PLAYER) {
if (((Player)entityDamageByEntityEvent.getDamager()).getAllowFlight()) {
return;
}
if (entityDamageByEntityEvent.getEntity() instanceof LivingEntity) {
this.lastAttackTimes.put((Player)entityDamageByEntityEvent.getDamager(), System.currentTimeMillis());
if (this.targetRotationTracker.hasTargetChangedAndMoved((Player)entityDamageByEntityEvent.getDamager(), (LivingEntity)entityDamageByEntityEvent.getEntity())) {
this.validHitCounts.merge((Player)entityDamageByEntityEvent.getDamager(), 1, Integer::sum);
}
}
}
}
private void trainPatternNetwork(TrainingSet trainingSet, Player player) {
NeuralNetwork neuralNetwork = new NeuralNetwork(2, NETWORK_TOPOLOGY);
for (int i = 0; i < 10000; ++i) {
for (int j = 0; j < trainingSet.size(); ++j) {
TrainingSample trainingSample = trainingSet.getRandomSample();
neuralNetwork.train(trainingSample.getInputs(), trainingSample.getExpectedOutputs(), 0.01, 0.1);
}
}
this.trainedModels.put(player, new AbstractMap.SimpleImmutableEntry<NeuralNetwork, TrainingSet>(neuralNetwork, new TrainingSet()));
this.trainingSets.remove(player);
}
}
@@ -0,0 +1,43 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.events.PacketEvent;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
public class KillauraRoundingModule
extends KillauraModule {
private final Map lastRoundedYaws = new HashMap();
public KillauraRoundingModule(AAC aAC, Consumer<KillauraViolation> consumer) {
super(aAC, consumer);
}
@Override
public void onTick() {
}
@Override
public void onPacket(PacketEvent packetEvent) {
}
@Override
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
double yaw = Math.abs(playerMoveEvent.getTo().getYaw() - playerMoveEvent.getFrom().getYaw()) % 360.0f;
if (yaw > 1.0 && (double)Math.round(yaw) == yaw) {
if (this.lastRoundedYaws.containsKey(playerMoveEvent.getPlayer()) && (double)((Float)this.lastRoundedYaws.get(playerMoveEvent.getPlayer())).floatValue() == yaw) {
this.reportViolation(playerMoveEvent.getPlayer(), "round", "rounded aiming values (y=" + yaw + ")");
}
} else {
this.lastRoundedYaws.remove(playerMoveEvent.getPlayer());
}
}
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
}
}
@@ -0,0 +1,75 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.events.PacketEvent;
import java.util.Iterator;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.AxisAlignedBoundingBox;
import me.konsolas.aac.util.EntityDimensions;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.util.Vector;
public class KillauraSplitModule
extends KillauraModule {
private final PlayerSampleData normalPitchSamples = new PlayerSampleData(100);
private final PlayerSampleData combatPitchSamples = new PlayerSampleData(100);
public KillauraSplitModule(AAC aAC, Consumer<KillauraViolation> consumer) {
super(aAC, consumer);
}
@Override
public void onTick() {
}
@Override
public void onPacket(PacketEvent packetEvent) {
}
@Override
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
if (playerMoveEvent.getFrom().getYaw() != playerMoveEvent.getTo().getYaw()) {
double yaw = Math.hypot(playerMoveEvent.getFrom().getYaw(), playerMoveEvent.getTo().getYaw());
Player player = playerMoveEvent.getPlayer();
if (this.hasNearbyTarget(player)) {
this.combatPitchSamples.addSample(playerMoveEvent.getPlayer(), yaw);
} else {
this.normalPitchSamples.addSample(playerMoveEvent.getPlayer(), yaw);
}
if (this.normalPitchSamples.hasFullSampleData(playerMoveEvent.getPlayer()) && this.combatPitchSamples.hasFullSampleData(playerMoveEvent.getPlayer())) {
if (this.normalPitchSamples.getMean(playerMoveEvent.getPlayer()) > this.combatPitchSamples.getMean(playerMoveEvent.getPlayer())) {
this.addPlayerScore(playerMoveEvent.getPlayer(), 4.0);
if (this.getPlayerScore(playerMoveEvent.getPlayer()) > 5.0) {
this.reportViolation(playerMoveEvent.getPlayer(), "split", String.format("sharp changes in aiming speed (%.3f/%.3f)", this.normalPitchSamples.getMean(playerMoveEvent.getPlayer()), this.combatPitchSamples.getMean(playerMoveEvent.getPlayer())));
}
this.combatPitchSamples.clearSamples(playerMoveEvent.getPlayer());
this.normalPitchSamples.clearSamples(playerMoveEvent.getPlayer());
} else {
this.setPlayerScore(playerMoveEvent.getPlayer(), this.getPlayerScore(playerMoveEvent.getPlayer()) * 0.8);
}
}
}
}
private boolean hasNearbyTarget(Player player) {
Iterator iterator = player.getNearbyEntities(6.0, 6.0, 6.0).iterator();
while (iterator.hasNext()) {
Entity entity = (Entity)iterator.next();
if (!(entity instanceof LivingEntity)) continue;
Entity entity2 = entity;
AxisAlignedBoundingBox axisAlignedBoundingBox = new AxisAlignedBoundingBox(entity.getLocation().toVector(), EntityDimensions.forEntity(entity2)).expand(new Vector(0.1, 0.1, 0.1));
if (!axisAlignedBoundingBox.intersectsRay(player.getEyeLocation().toVector(), player.getLocation().getDirection())) continue;
return true;
}
return false;
}
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
}
}
@@ -0,0 +1,80 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.events.PacketEvent;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import me.konsolas.aac.compat.NearbyTargetLookup;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
public class KillauraSporadicModule
extends KillauraModule {
private final PlayerSampleData angleSamples = new PlayerSampleData(35);
private final Map lastAttackTimes = new HashMap();
private final Map lastTargetIds = new HashMap();
public KillauraSporadicModule(AAC aAC, Consumer<KillauraViolation> consumer) {
super(aAC, consumer);
}
@Override
public void onTick() {
}
@Override
public void onPacket(PacketEvent packetEvent) {
}
@Override
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
LivingEntity livingEntity;
long ticks;
Player player;
Player player2 = player = playerMoveEvent.getPlayer();
LivingEntity livingEntity2 = NearbyTargetLookup.findClosestLivingEntity(player2);
long ticks2 = ticks = this.lastAttackTimes.containsKey(playerMoveEvent.getPlayer().getUniqueId()) ? (Long)this.lastAttackTimes.get(playerMoveEvent.getPlayer().getUniqueId()) : 0L;
if (livingEntity2 == null || System.currentTimeMillis() - ticks > 520L) {
this.lastAttackTimes.remove(playerMoveEvent.getPlayer().getUniqueId());
this.angleSamples.clearSamples(playerMoveEvent.getPlayer());
return;
}
LivingEntity livingEntity3 = livingEntity2;
Player player3 = playerMoveEvent.getPlayer();
Player player4 = player3;
double d = NearbyTargetLookup.getYawDifferenceToTarget(player4, (Entity)(livingEntity = livingEntity3));
if (d > 20.0) {
this.angleSamples.addSample(playerMoveEvent.getPlayer(), d);
if (this.angleSamples.hasFullSampleData(playerMoveEvent.getPlayer())) {
this.addPlayerScore(playerMoveEvent.getPlayer(), this.angleSamples.getMean(playerMoveEvent.getPlayer()) / 10.0 + 3.0);
if (this.getPlayerScore(playerMoveEvent.getPlayer()) > 3.0) {
this.reportViolation(playerMoveEvent.getPlayer(), "sporadic", "sporadic aiming patterns (y=" + this.angleSamples.getMean(playerMoveEvent.getPlayer()) + ")");
}
this.angleSamples.clearSamples(playerMoveEvent.getPlayer());
}
}
}
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
if (entityDamageByEntityEvent.getDamager().getType() == EntityType.PLAYER) {
if (((Player)entityDamageByEntityEvent.getDamager()).getAllowFlight()) {
return;
}
if (this.lastTargetIds.containsKey(entityDamageByEntityEvent.getDamager().getUniqueId()) && ((Integer)this.lastTargetIds.get(entityDamageByEntityEvent.getDamager().getUniqueId())).intValue() != entityDamageByEntityEvent.getEntity().getEntityId()) {
this.lastAttackTimes.remove(entityDamageByEntityEvent.getDamager().getUniqueId());
this.lastTargetIds.remove(entityDamageByEntityEvent.getDamager().getUniqueId());
return;
}
this.lastAttackTimes.put(entityDamageByEntityEvent.getDamager().getUniqueId(), System.currentTimeMillis());
this.lastTargetIds.put(entityDamageByEntityEvent.getDamager().getUniqueId(), entityDamageByEntityEvent.getEntity().getEntityId());
this.setPlayerScore((Player)entityDamageByEntityEvent.getDamager(), this.getPlayerScore((Player)entityDamageByEntityEvent.getDamager()) * 0.95);
}
}
}
@@ -0,0 +1,54 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.events.PacketEvent;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.MathUtilities;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
public class KillauraStableModule
extends KillauraModule {
public KillauraStableModule(AAC aAC, Consumer<KillauraViolation> consumer) {
super(aAC, consumer);
}
@Override
public void onTick() {
}
@Override
public void onPacket(PacketEvent packetEvent) {
}
/*
* Enabled aggressive block sorting
*/
@Override
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
double yaw = playerMoveEvent.getTo().getYaw();
double yaw2 = playerMoveEvent.getFrom().getYaw();
double d = yaw;
double d2 = yaw2;
double d3 = MathUtilities.angleDifferenceAbs(d2, d);
if (playerMoveEvent.getFrom().getPitch() == playerMoveEvent.getTo().getPitch()) {
double d4;
double yaw3 = playerMoveEvent.getTo().getYaw();
double yaw4 = playerMoveEvent.getFrom().getYaw();
double d5 = yaw4;
if (MathUtilities.angleDifferenceAbs(d5, d4 = yaw3) > 3.0 && playerMoveEvent.getFrom().getPitch() != 90.0f && playerMoveEvent.getFrom().getPitch() != -90.0f) {
this.addPlayerScore(playerMoveEvent.getPlayer(), 0.9);
if (!(this.getPlayerScore(playerMoveEvent.getPlayer()) > 4.0)) return;
this.reportViolation(playerMoveEvent.getPlayer(), "stable", "ununsually stable aiming (" + playerMoveEvent.getTo().getPitch() + "/" + d3 + ")");
this.setPlayerScore(playerMoveEvent.getPlayer(), this.getPlayerScore(playerMoveEvent.getPlayer()) * 0.4);
return;
}
}
this.setPlayerScore(playerMoveEvent.getPlayer(), this.getPlayerScore(playerMoveEvent.getPlayer()) * 0.65);
}
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
}
}
@@ -0,0 +1,62 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.events.PacketEvent;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;
import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
public class KillauraSwitchModule
extends KillauraModule {
private final Map previousRotationBounds = new WeakHashMap();
private final ExpiringMap recentTargets;
private final TargetRotationTracker targetRotationTracker = new TargetRotationTracker();
public KillauraSwitchModule(AAC aAC, Consumer<KillauraViolation> consumer) {
super(aAC, consumer);
TimeUnit timeUnit = TimeUnit.MILLISECONDS;
long ticks = 500L;
ExpirationPolicy expirationPolicy = ExpirationPolicy.CREATED;
this.recentTargets = ExpiringMap.builder().expiration(ticks, timeUnit).expirationPolicy(expirationPolicy).build();
}
@Override
public void onTick() {
}
@Override
public void onPacket(PacketEvent packetEvent) {
}
@Override
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
AimRotationBounds aimRotationBounds = (AimRotationBounds)this.previousRotationBounds.get(playerMoveEvent.getPlayer());
Entity entity = (Entity)this.recentTargets.get(playerMoveEvent.getPlayer());
if (aimRotationBounds != null && entity != null && playerMoveEvent.getFrom().getWorld().equals(entity.getWorld()) && playerMoveEvent.getFrom().distance(entity.getLocation()) < 6.0) {
if (playerMoveEvent.getTo().getYaw() != playerMoveEvent.getFrom().getYaw() && aimRotationBounds.minimumYaw < (double)playerMoveEvent.getTo().getYaw() && (double)playerMoveEvent.getTo().getYaw() < aimRotationBounds.maximumYaw) {
this.reportViolation(playerMoveEvent.getPlayer(), "switch", "aimbot-like yaw patterns");
} else if (playerMoveEvent.getTo().getPitch() != playerMoveEvent.getFrom().getPitch() && aimRotationBounds.minimumPitch < (double)playerMoveEvent.getTo().getPitch() && (double)playerMoveEvent.getTo().getPitch() < aimRotationBounds.maximumPitch) {
this.reportViolation(playerMoveEvent.getPlayer(), "switch", "aimbot-like pitch patterns");
} else {
this.setPlayerScore(playerMoveEvent.getPlayer(), this.getPlayerScore(playerMoveEvent.getPlayer()) * 0.975);
}
}
this.previousRotationBounds.put(playerMoveEvent.getPlayer(), new AimRotationBounds(this, playerMoveEvent.getFrom(), playerMoveEvent.getTo()));
}
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
if (entityDamageByEntityEvent.getDamager() instanceof Player && entityDamageByEntityEvent.getEntity() instanceof LivingEntity && this.targetRotationTracker.hasTargetChangedAndMoved((Player)entityDamageByEntityEvent.getDamager(), (LivingEntity)entityDamageByEntityEvent.getEntity())) {
this.recentTargets.put((Player)entityDamageByEntityEvent.getDamager(), entityDamageByEntityEvent.getEntity());
}
}
}
@@ -0,0 +1,54 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketEvent;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
public class KillauraTickModule
extends KillauraModule {
private final PlayerSampleData yawDeltaSamples = new PlayerSampleData(8);
public KillauraTickModule(AAC aAC, Consumer<KillauraViolation> consumer) {
super(aAC, consumer);
}
@Override
public void onTick() {
}
@Override
public void onPacket(PacketEvent packetEvent) {
if (packetEvent.getPacketType() == PacketType.Play.Client.USE_ENTITY) {
long ticks = this.getPlugin().playerState.getLastArmSwingTime(packetEvent.getPlayer());
long now = System.currentTimeMillis();
float f = now - ticks;
double d = f - 50.0f * AAC.serverVersion.getAttackCooldownTicks(packetEvent.getPlayer());
if (d < 2500.0) {
this.yawDeltaSamples.addSample(packetEvent.getPlayer(), Math.abs(d));
if (this.yawDeltaSamples.hasFullSampleData(packetEvent.getPlayer())) {
double d2 = this.yawDeltaSamples.getMean(packetEvent.getPlayer());
if (d2 < (double)AAC.serverVersion.getAttackCooldownTicks(packetEvent.getPlayer()) * 1.5) {
this.addPlayerScore(packetEvent.getPlayer(), 1.0);
if (this.getPlayerScore(packetEvent.getPlayer()) > 5.0) {
this.reportViolation(packetEvent.getPlayer(), "tick", "attacking with cooldowns (e=" + d2 + ")");
}
} else {
this.setPlayerScore(packetEvent.getPlayer(), this.getPlayerScore(packetEvent.getPlayer()) * 0.8);
}
}
}
}
}
@Override
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
}
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
}
}
@@ -0,0 +1,65 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.EnumWrappers;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;
import me.konsolas.aac.compat.UseEntityPacket;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerMoveEvent;
public class KillauraTimingModule
extends KillauraModule {
private final ExpiringMap lastAttackTimestamps;
public KillauraTimingModule(AAC aAC, Consumer<KillauraViolation> consumer) {
super(aAC, consumer);
TimeUnit timeUnit = TimeUnit.MILLISECONDS;
long ticks = 3L;
ExpirationPolicy expirationPolicy = ExpirationPolicy.CREATED;
this.lastAttackTimestamps = ExpiringMap.builder().expiration(ticks, timeUnit).expirationPolicy(expirationPolicy).build();
}
@Override
public void onTick() {
}
@Override
public void onPacket(PacketEvent packetEvent) {
if (!packetEvent.isServerPacket()) {
if (packetEvent.getPacketType() == PacketType.Play.Client.USE_ENTITY) {
PacketContainer packetContainer = packetEvent.getPacket();
UseEntityPacket useEntityPacket = new UseEntityPacket(packetContainer);
if (useEntityPacket.getAction() == EnumWrappers.EntityUseAction.ATTACK) {
if (this.lastAttackTimestamps.containsKey(packetEvent.getPlayer().getUniqueId())) {
this.addPlayerScore(packetEvent.getPlayer(), 1.0);
} else {
this.setPlayerScore(packetEvent.getPlayer(), this.getPlayerScore(packetEvent.getPlayer()) * 0.95);
}
}
} else if (this.isMovementPacket(packetEvent.getPacketType())) {
this.lastAttackTimestamps.put(packetEvent.getPlayer().getUniqueId(), (Object)false);
}
}
}
@Override
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
this.setPlayerScore(playerMoveEvent.getPlayer(), this.getPlayerScore(playerMoveEvent.getPlayer()) * 0.99);
}
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
if (this.getPlayerScore((Player)entityDamageByEntityEvent.getDamager()) > 5.0) {
this.reportViolation((Player)entityDamageByEntityEvent.getDamager(), "timing", "unusual attack patterns");
this.setPlayerScore((Player)entityDamageByEntityEvent.getDamager(), this.getPlayerScore((Player)entityDamageByEntityEvent.getDamager()) * 0.2);
}
}
}
@@ -0,0 +1,40 @@
package me.konsolas.aac.checks.combat;
import org.bukkit.entity.Player;
public class KillauraViolation {
private final Player player;
private final String moduleName;
private final String message;
final KillauraModule module;
private KillauraViolation(KillauraModule killauraModule, Player player, String str, String str2) {
this.module = killauraModule;
this.player = player;
this.moduleName = str;
this.message = str2;
}
public Player getPlayer() {
return this.player;
}
public String getModuleName() {
return this.moduleName;
}
public String getMessage() {
return this.message;
}
public KillauraViolation(KillauraModule killauraModule, Player player, String str, String str2, KillauraViolationAccess killauraViolationAccess) {
this(killauraModule, player, str, str2);
}
static {
if (null == null) {
// empty if block
}
}
}
@@ -0,0 +1,5 @@
package me.konsolas.aac.checks.combat;
public class KillauraViolationAccess {
}
@@ -0,0 +1,77 @@
package me.konsolas.aac.checks.combat;
import com.comphenix.protocol.events.PacketEvent;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.function.Consumer;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.MathUtilities;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerMoveEvent;
public class KillauraYawModule
extends KillauraModule {
private final PlayerSampleData yawSamples = new PlayerSampleData(8);
private final Map lastMoveYaws = new HashMap();
private final Map lastAttackTimes = new HashMap();
public KillauraYawModule(AAC aAC, Consumer<KillauraViolation> consumer) {
super(aAC, consumer);
}
@Override
public void onTick() {
}
@Override
public void onPacket(PacketEvent packetEvent) {
}
@Override
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
double d;
double yaw = d = (double)(playerMoveEvent.getTo().getYaw() - playerMoveEvent.getFrom().getYaw());
double d2 = Math.abs(MathUtilities.wrapDegrees(yaw));
this.lastMoveYaws.put(playerMoveEvent.getPlayer().getUniqueId(), d2);
}
@Override
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
if (entityDamageByEntityEvent.getDamager().getType() == EntityType.PLAYER && entityDamageByEntityEvent.getEntity() instanceof LivingEntity && entityDamageByEntityEvent.getCause() == EntityDamageEvent.DamageCause.ENTITY_ATTACK) {
Player player = (Player)entityDamageByEntityEvent.getDamager();
if (player.getAllowFlight()) {
return;
}
this.lastAttackTimes.put(entityDamageByEntityEvent.getDamager().getUniqueId(), System.currentTimeMillis());
if (!this.lastMoveYaws.containsKey(player.getUniqueId())) {
return;
}
double d = (Double)this.lastMoveYaws.get(player.getUniqueId());
this.yawSamples.addSample(player, d);
if (this.yawSamples.hasFullSampleData(player)) {
double d2 = 0.0;
Iterator iterator = this.yawSamples.getSampleData(player).getSamples().iterator();
while (iterator.hasNext()) {
double d3 = (Double)iterator.next();
if (!(d3 >= 27.0)) continue;
d2 += d3;
}
if (d2 > 60.0) {
this.addPlayerScore(player, d2 / 10.0);
if (this.getPlayerScore(player) > 10.0) {
this.reportViolation(player, "yaw", "snapping to attack targets (t=" + d2 + ")");
}
} else {
this.setPlayerScore(player, this.getPlayerScore(player) * 0.75);
}
this.yawSamples.clearSamples(player);
}
}
}
}
@@ -0,0 +1,140 @@
package me.konsolas.aac.checks.combat;
import java.util.concurrent.ConcurrentHashMap;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.BlockPositionView;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.util.EntityTypeChecks;
import me.konsolas.aac.util.GroundCollisionState;
import me.konsolas.aac.checks.movement.MovementCheckListener;
import me.konsolas.aac.compat.PlayerPingAccess;
import me.konsolas.aac.compat.ServerVersion;
import me.konsolas.aac.api.HackType;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
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.player.PlayerMoveEvent;
import org.bukkit.plugin.Plugin;
public final class Knockback
extends Detector
implements MovementCheckListener {
private int tickDelay;
private boolean addPing;
private int maxPing;
private double minKnockbackDist;
private final ConcurrentHashMap activeContexts;
public Knockback(AAC aAC) { super(aAC);
this.tickDelay = 7;
this.addPing = true;
this.maxPing = 500;
this.minKnockbackDist = 0.1;
this.activeContexts = new ConcurrentHashMap();
this.tickDelay = this.plugin.getConfig().getInt("knockback.tick_delay", this.tickDelay);
this.addPing = this.plugin.getConfig().getBoolean("knockback.add_ping", this.addPing);
this.maxPing = this.plugin.getConfig().getInt("knockback.max_ping", this.maxPing);
this.minKnockbackDist = this.plugin.getConfig().getDouble("knockback.min_knockback_dist", this.minKnockbackDist);
}
@EventHandler(ignoreCancelled=true, priority=EventPriority.MONITOR)
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
AttackContext attackContext;
BlockPositionView blockPositionView;
Player player;
long ticks = 103276215108508L;
if (entityDamageByEntityEvent.getEntity().getType() != EntityType.PLAYER || entityDamageByEntityEvent.getEntity().getVehicle() != null || this.plugin.checkManager.isPlayerExempt(player = (Player)entityDamageByEntityEvent.getEntity()) || entityDamageByEntityEvent.getCause() == EntityDamageEvent.DamageCause.THORNS) {
return;
}
if (this.activeContexts.containsKey(entityDamageByEntityEvent.getEntity().getUniqueId())) {
((AttackContext)this.activeContexts.get(entityDamageByEntityEvent.getEntity().getUniqueId())).cancelTask();
this.activeContexts.remove(entityDamageByEntityEvent.getEntity().getUniqueId());
}
if (!EntityTypeChecks.isKnockbackTarget(entityDamageByEntityEvent.getDamager().getType())) {
return;
}
double d = entityDamageByEntityEvent.getDamager().getLocation().distance(entityDamageByEntityEvent.getEntity().getLocation());
if (d < 1.2) {
return;
}
Player player2 = (Player)entityDamageByEntityEvent.getEntity();
if (entityDamageByEntityEvent.getDamager().getType() == EntityType.ARROW) {
if ((AAC.serverVersion.getVersion() == ServerVersion.VER_1_9 || AAC.serverVersion.getVersion() == ServerVersion.VER_1_10) && player2.isBlocking()) {
return;
}
Arrow arrow = (Arrow)entityDamageByEntityEvent.getDamager();
if (arrow.getShooter() instanceof LivingEntity) {
LivingEntity livingEntity = (LivingEntity)arrow.getShooter();
if (entityDamageByEntityEvent.getEntity().getEntityId() == livingEntity.getEntityId()) {
return;
}
}
}
if (this.isBlockingEnvironmentMaterial((blockPositionView = new BlockPositionView(player2.getLocation())).getMaterialAtOffset(0.6, 0.0, 0.0)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(-0.6, 0.0, 0.0)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(0.0, 0.0, 0.6)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(0.0, 0.0, -0.6)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(0.6, 0.0, 0.6)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(-0.6, 0.0, 0.6)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(0.6, 0.0, -0.6)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(-0.6, 0.0, -0.6)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(0.6, 1.1, 0.0)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(-0.6, 1.1, 0.0)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(0.0, 1.1, 0.6)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(0.0, 1.1, -0.6)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(0.6, 1.1, 0.6)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(-0.6, 1.1, 0.6)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(0.6, 1.1, -0.6)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(-0.6, 1.1, -0.6)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(0.6, 2.1, 0.0)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(-0.6, 2.1, 0.0)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(0.0, 2.1, 0.6)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(0.0, 2.1, -0.6)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(0.6, 2.1, 0.6)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(-0.6, 2.1, 0.6)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(0.6, 2.1, -0.6)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(-0.6, 2.1, -0.6)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(0.0, 1.1, 0.0)) || this.isBlockingEnvironmentMaterial(blockPositionView.getMaterialAtOffset(0.0, 2.1, 0.0)) || this.isBlockingEnvironmentMaterial(blockPositionView.getBlock().getType())) {
return;
}
int value = this.tickDelay;
long ticks2 = ticks;
Player player3 = player2;
int value2 = PlayerPingAccess.getPing(player3, ticks2);
if (this.addPing) {
value += value2 < this.maxPing ? value2 / 100 : this.maxPing / 100;
}
try {
boolean flag = false;
Entity entity = entityDamageByEntityEvent.getEntity();
Entity entity2 = entityDamageByEntityEvent.getDamager();
attackContext = new AttackContext(entity2, entity, flag);
}
catch (IllegalStateException illegalStateException) {
return;
}
this.activeContexts.put(player2.getUniqueId(), attackContext);
Server server = Bukkit.getServer();
long delayCheckKey = 113218805911140L;
attackContext.setTaskId(server.getScheduler().scheduleSyncDelayedTask((Plugin)this.plugin, () -> {
AttackContext trackedAttack = (AttackContext)this.activeContexts.get(player2.getUniqueId());
this.activeContexts.remove(player2.getUniqueId());
if (player2.isDead()) {
return;
}
double distanceMoved = trackedAttack.getMaxDistance() - trackedAttack.getInitialDistance();
trackedAttack.getAwayTickCount();
if (distanceMoved == 0.0) {
this.recordViolation(player2.getUniqueId(), 2, HackType.KNOCKBACK, player2.getName() + " failed Knockback: didn't move away from his attacker when hit", delayCheckKey);
} else if (distanceMoved < this.minKnockbackDist) {
this.recordViolation(player2.getUniqueId(), 2, HackType.KNOCKBACK, player2.getName() + " failed Knockback: didn't move far enough when hit (" + distanceMoved + " blocks" + (trackedAttack.isInWater() ? ", inWater)" : ")"), delayCheckKey);
} else {
this.decreaseViolationLevel(player2.getUniqueId(), 1);
}
}, (long)value));
}
@Override
public boolean shouldProcessMovement(PlayerMoveEvent playerMoveEvent) {
return true;
}
@Override
public void onMovement(PlayerMoveEvent playerMoveEvent, GroundCollisionState groundCollisionState, GroundCollisionState groundCollisionState2, BlockPositionView blockPositionView, BlockPositionView blockPositionView2, long ticks) {
if (this.activeContexts.containsKey(playerMoveEvent.getPlayer().getUniqueId())) {
AttackContext attackContext = (AttackContext)this.activeContexts.get(playerMoveEvent.getPlayer().getUniqueId());
attackContext.updateDistance(playerMoveEvent.getPlayer().getLocation());
}
}
private boolean isBlockingEnvironmentMaterial(Material material) {
return material == Material.WEB || material == Material.WATER || material == Material.STATIONARY_WATER || material == Material.LAVA || material == Material.STATIONARY_LAVA || material.isSolid() || material.equals((Object)Material.SKULL) || material == Material.FLOWER_POT;
}
}
@@ -0,0 +1,25 @@
package me.konsolas.aac.checks.combat;
public class NaturalAimState {
int streakCount;
boolean switchedOffTarget;
double missedDeltaAvg;
int missedSampleCount;
double hitDeltaAvg;
int hitSampleCount;
final KillauraNaturalModule module;
private NaturalAimState(KillauraNaturalModule killauraNaturalModule) {
this.module = killauraNaturalModule;
}
public String toString() {
return this.streakCount + "/" + this.hitSampleCount + "/" + String.format("%.3f", this.hitDeltaAvg) + "/" + this.missedSampleCount;
}
public NaturalAimState(KillauraNaturalModule killauraNaturalModule, NaturalAimStateAccess naturalAimStateAccess) {
this(killauraNaturalModule);
}
}
@@ -0,0 +1,5 @@
package me.konsolas.aac.checks.combat;
public class NaturalAimStateAccess {
}
@@ -0,0 +1,87 @@
package me.konsolas.aac.checks.combat;
import java.util.Arrays;
import java.util.Random;
public class NeuralLayer {
private final double[] outputs;
private final double[] inputs;
private final double[] weights;
private final double[] previousWeightChanges;
private boolean sigmoidEnabled;
final NeuralNetwork network;
private NeuralLayer(NeuralNetwork neuralNetwork, int i2, int i3, Random random) {
this.network = neuralNetwork;
this.sigmoidEnabled = true;
this.outputs = new double[i3];
this.inputs = new double[i2 + 1];
this.weights = new double[(1 + i2) * i3];
this.previousWeightChanges = new double[this.weights.length];
this.randomizeWeights(random);
}
private void randomizeWeights(Random random) {
for (int i = 0; i < this.weights.length; ++i) {
this.weights[i] = (random.nextDouble() - 0.5) * 4.0;
}
}
private double[] evaluate(double[] dArray) {
System.arraycopy(dArray, 0, this.inputs, 0, dArray.length);
this.inputs[this.inputs.length - 1] = 1.0;
int value = 0;
Arrays.fill(this.outputs, 0.0);
for (int i = 0; i < this.outputs.length; ++i) {
for (int j = 0; j < this.inputs.length; ++j) {
int value2 = i;
this.outputs[value2] = this.outputs[value2] + this.weights[value + j] * this.inputs[j];
}
if (this.sigmoidEnabled) {
this.outputs[i] = 1.0 / (1.0 + Math.exp(-this.outputs[i]));
}
value += this.inputs.length;
}
return Arrays.copyOf(this.outputs, this.outputs.length);
}
private double[] backpropagate(double[] dArray, double d, double d2) {
int value = 0;
double[] dArray2 = new double[this.inputs.length];
for (int i = 0; i < this.outputs.length; ++i) {
double d3 = dArray[i];
if (this.sigmoidEnabled) {
d3 *= this.outputs[i] * (1.0 - this.outputs[i]);
}
for (int j = 0; j < this.inputs.length; ++j) {
int value2 = value + j;
int value3 = j;
dArray2[value3] = dArray2[value3] + this.weights[value2] * d3;
double d4 = this.inputs[j] * d3 * d;
int value4 = value2;
this.weights[value4] = this.weights[value4] + (this.previousWeightChanges[value2] * d2 + d4);
this.previousWeightChanges[value2] = d4;
}
value += this.inputs.length;
}
return dArray2;
}
public NeuralLayer(NeuralNetwork neuralNetwork, int i2, int i3, Random random, NeuralLayerAccess neuralLayerAccess) {
this(neuralNetwork, i2, i3, random);
}
static boolean setSigmoidEnabled(NeuralLayer neuralLayer, boolean flag) {
neuralLayer.sigmoidEnabled = flag;
return neuralLayer.sigmoidEnabled;
}
static double[] forwardPass(NeuralLayer neuralLayer, double[] dArray) {
return neuralLayer.evaluate(dArray);
}
static double[] backwardPass(NeuralLayer neuralLayer, double[] dArray, double d, double d2) {
return neuralLayer.backpropagate(dArray, d, d2);
}
}
@@ -0,0 +1,5 @@
package me.konsolas.aac.checks.combat;
public class NeuralLayerAccess {
}
@@ -0,0 +1,43 @@
package me.konsolas.aac.checks.combat;
import java.util.Random;
public class NeuralNetwork {
private final NeuralLayer[] layers;
private final int inputSize;
public NeuralNetwork(int i2, int[] nArray) {
this.inputSize = i2;
this.layers = new NeuralLayer[nArray.length];
Random random = new Random(1L);
for (int i = 0; i < nArray.length; ++i) {
int value = i == 0 ? i2 : nArray[i - 1];
this.layers[i] = new NeuralLayer(this, value, nArray[i], random, null);
}
NeuralLayer.setSigmoidEnabled(this.layers[nArray.length - 1], false);
}
public double[] evaluate(double[] dArray) {
if (dArray.length != this.inputSize) {
throw new IllegalArgumentException();
}
double[] dArray2 = dArray;
for (NeuralLayer neuralLayer : this.layers) {
dArray2 = NeuralLayer.forwardPass(neuralLayer, dArray2);
}
return dArray2;
}
public void train(double[] dArray, double[] dArray2, double d, double d2) {
int i2;
double[] dArray3 = this.evaluate(dArray);
double[] dArray4 = new double[dArray3.length];
for (i2 = 0; i2 < dArray4.length; ++i2) {
dArray4[i2] = dArray2[i2] - dArray3[i2];
}
for (i2 = this.layers.length - 1; i2 >= 0; --i2) {
dArray4 = NeuralLayer.backwardPass(this.layers[i2], dArray4, d, d2);
}
}
}
@@ -0,0 +1,22 @@
package me.konsolas.aac.checks.combat;
import java.util.UUID;
public class PlayerIdentity {
private final UUID uuid;
private final String name;
public PlayerIdentity(UUID uUID, String str) {
this.uuid = uUID;
this.name = str;
}
public UUID getUuid() {
return this.uuid;
}
public String getName() {
return this.name;
}
}
@@ -0,0 +1,88 @@
package me.konsolas.aac.checks.combat;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.RandomPlayerName;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.entity.Player;
public class PlayerIdentityPool {
private static final PlayerIdentityPool instance;
private final List identities = new ArrayList();
private PlayerIdentityPool() {
int value = 0;
Server server = Bukkit.getServer();
for (OfflinePlayer offlinePlayer : server.getOfflinePlayers()) {
this.identities.add(new PlayerIdentity(offlinePlayer.getUniqueId(), offlinePlayer.getName()));
if (value++ > 500) break;
}
}
private static UUID parseUndashedUuid(String str) {
String str2 = str.replaceFirst("([0-9a-fA-F]{8})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]{4})([0-9a-fA-F]+)", "$1-$2-$3-$4-$5");
return UUID.fromString(str2);
}
public static PlayerIdentityPool getInstance() {
return instance;
}
public PlayerIdentity getRandomIdentity() {
if (this.identities.size() > 0) {
return (PlayerIdentity)this.identities.get(AAC.random.nextInt(this.identities.size()));
}
return new PlayerIdentity(UUID.randomUUID(), RandomPlayerName.generateName());
}
public PlayerIdentity getDifferentRandomIdentity(UUID uUID) {
if (this.identities.size() > 0) {
boolean flag = true;
for (int i = 0; i < 5; ++i) {
PlayerIdentity playerIdentity = (PlayerIdentity)this.identities.get(AAC.random.nextInt(this.identities.size()));
Server server = Bukkit.getServer();
for (Player player : server.getOnlinePlayers()) {
if (!player.getUniqueId().equals(playerIdentity.getUuid())) continue;
flag = false;
}
if (flag) {
return playerIdentity;
}
flag = true;
}
}
return new PlayerIdentity(UUID.randomUUID(), RandomPlayerName.generateName());
}
public PlayerIdentity getOnlineOrRandomIdentity(UUID uUID) {
for (int i = 0; i < 5; ++i) {
Server server = Bukkit.getServer();
int value = AAC.random.nextInt(server.getOnlinePlayers().size());
Player player = Bukkit.getPlayer((UUID)uUID);
int value2 = 0;
Server server2 = Bukkit.getServer();
for (Player player2 : server2.getOnlinePlayers()) {
if (value2 == value) {
player = player2;
}
++value2;
}
if (player.getUniqueId().equals(uUID)) continue;
return new PlayerIdentity(player.getUniqueId(), player.getName());
}
return null;
}
public PlayerIdentity generateRandomIdentity() {
return new PlayerIdentity(UUID.randomUUID(), RandomPlayerName.generateName());
}
static {
instance = new PlayerIdentityPool();
}
}
@@ -0,0 +1,45 @@
package me.konsolas.aac.checks.combat;
import java.util.Map;
import java.util.WeakHashMap;
import org.bukkit.entity.Player;
public class PlayerSampleData {
private final int sampleCapacity;
private final Map<Player, SampleData> playerSamples = new WeakHashMap<>();
public PlayerSampleData(int i) {
this.sampleCapacity = i;
}
public SampleData getSampleData(Player player) {
if (!this.playerSamples.containsKey(player)) {
this.playerSamples.put(player, new SampleData(this.sampleCapacity));
}
return (SampleData)this.playerSamples.get(player);
}
public boolean hasFullSampleData(Player player) {
return this.getSampleData(player).isFull();
}
public double getMean(Player player) {
if (!this.hasFullSampleData(player)) {
throw new IllegalStateException();
}
return this.getSampleData(player).getMean();
}
public int getSampleCapacity() {
return this.sampleCapacity;
}
public void addSample(Player player, double d) {
this.getSampleData(player).addSample(d);
}
public void clearSamples(Player player) {
this.playerSamples.remove(player);
}
}
@@ -0,0 +1,60 @@
package me.konsolas.aac.checks.combat;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.plugin.java.JavaPlugin;
public class RecentCombatTracker
implements Listener {
private final ExpiringMap<UUID, UUID> recentCombat;
private final ExpiringMap<UUID, Boolean> recentDamage;
public RecentCombatTracker(JavaPlugin javaPlugin) {
ExpirationPolicy expirationPolicy = ExpirationPolicy.CREATED;
TimeUnit timeUnit = TimeUnit.MILLISECONDS;
long ticks = 2000L;
this.recentCombat = ExpiringMap.builder().expirationPolicy(expirationPolicy).expiration(ticks, timeUnit).build();
ExpirationPolicy expirationPolicy2 = ExpirationPolicy.CREATED;
TimeUnit timeUnit2 = TimeUnit.MILLISECONDS;
long ticks2 = 3000L;
this.recentDamage = ExpiringMap.builder().expirationPolicy(expirationPolicy2).expiration(ticks2, timeUnit2).build();
}
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onEntityDamageByEntity(EntityDamageByEntityEvent entityDamageByEntityEvent) {
if (entityDamageByEntityEvent.getDamager().getType() == EntityType.PLAYER) {
this.recentCombat.put(entityDamageByEntityEvent.getDamager().getUniqueId(), entityDamageByEntityEvent.getEntity().getUniqueId());
this.recentCombat.resetExpiration(entityDamageByEntityEvent.getDamager().getUniqueId());
}
if (entityDamageByEntityEvent.getEntity().getType() == EntityType.PLAYER) {
this.recentCombat.put(entityDamageByEntityEvent.getEntity().getUniqueId(), entityDamageByEntityEvent.getDamager().getUniqueId());
this.recentCombat.resetExpiration(entityDamageByEntityEvent.getEntity().getUniqueId());
}
}
@EventHandler
public synchronized void onEntityDamage(EntityDamageEvent entityDamageEvent) {
if (entityDamageEvent.getEntity().getType() == EntityType.PLAYER) {
this.recentDamage.put(entityDamageEvent.getEntity().getUniqueId(), true);
this.recentDamage.resetExpiration(entityDamageEvent.getEntity().getUniqueId());
}
}
public boolean hasRecentCombat(Player player) {
return this.recentCombat.containsKey(player.getUniqueId());
}
public synchronized boolean hasRecentDamage(Player player) {
return this.recentDamage.containsKey(player.getUniqueId());
}
}
@@ -0,0 +1,62 @@
package me.konsolas.aac.checks.combat;
import me.konsolas.aac.AAC;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.compat.ServerVersion;
import me.konsolas.aac.api.HackType;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityRegainHealthEvent;
public final class Regen
extends Detector {
private long minRegenDelay;
private long minSatiatedDelay;
private boolean cancelRegen;
public Regen(AAC aAC) { super(aAC);
this.minRegenDelay = 3850L;
this.minSatiatedDelay = 450L;
this.cancelRegen = true;
this.cancelRegen = this.plugin.getConfig().getBoolean("regen.cancel_regen", this.cancelRegen);
this.minRegenDelay = this.plugin.getConfig().getLong("regen.min_regen_delay", this.minRegenDelay);
this.minSatiatedDelay = this.plugin.getConfig().getLong("regen.min_satiated_delay", this.minSatiatedDelay);
}
@EventHandler
public void onEntityRegainHealth(EntityRegainHealthEvent entityRegainHealthEvent) {
Player player;
long ticks = 113218805911140L;
if (entityRegainHealthEvent.getEntity().getType() != EntityType.PLAYER || this.plugin.checkManager.isPlayerExempt(player = (Player)entityRegainHealthEvent.getEntity())) {
return;
}
Player player2 = (Player)entityRegainHealthEvent.getEntity();
long ticks2 = this.plugin.playerState.getLastRegenerationTime(player2);
EntityRegainHealthEvent.RegainReason regainReason = this.plugin.playerState.getLastRegenerationReason(player2);
long now = System.currentTimeMillis() - ticks2;
if (regainReason == EntityRegainHealthEvent.RegainReason.SATIATED && entityRegainHealthEvent.getRegainReason() == EntityRegainHealthEvent.RegainReason.SATIATED) {
if (AAC.serverVersion.getVersion() == ServerVersion.VER_1_8) {
if (now < this.minRegenDelay) {
if (this.recordViolation(player2.getUniqueId(), 2, HackType.REGEN, player2.getName() + " failed Regen: tried to regenerate health faster than normal", ticks) && this.cancelRegen) {
entityRegainHealthEvent.setCancelled(true);
}
} else {
this.decreaseViolationLevel(player2.getUniqueId(), 1);
}
} else if (now < this.minSatiatedDelay) {
if (this.recordViolation(player2.getUniqueId(), 1, HackType.REGEN, player2.getName() + " failed Regen: regenerated health too quickly (" + now + "ms)", ticks) && this.cancelRegen) {
entityRegainHealthEvent.setCancelled(true);
}
} else if (player2.getFoodLevel() < 20) {
if (now < this.minRegenDelay && this.recordViolation(player2.getUniqueId(), 1, HackType.REGEN, player2.getName() + " failed Regen: regenerated health too quickly (" + now + "ms)", ticks) && this.cancelRegen) {
entityRegainHealthEvent.setCancelled(true);
}
} else {
this.decreaseViolationLevel(player2.getUniqueId(), 1);
}
}
}
}
@@ -0,0 +1,51 @@
package me.konsolas.aac.checks.combat;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Iterator;
public class SampleData {
private final Deque<Double> samples;
private final int capacity;
public SampleData(int i) {
this.capacity = i;
this.samples = new ArrayDeque<>();
}
public void addSample(double d) {
if (this.samples.size() >= this.capacity) {
this.samples.poll();
this.samples.add(d);
} else {
this.samples.add(d);
}
}
public Deque<Double> getSamples() {
return this.samples;
}
public double getMean() {
double d = 0.0;
Iterator<Double> iterator = this.samples.iterator();
while (iterator.hasNext()) {
double d2 = iterator.next();
d += d2;
}
return d / (double)this.samples.size();
}
public void clear() {
this.samples.clear();
}
public boolean isFull() {
return this.samples.size() == this.capacity;
}
public String toString() {
return "SampleData:" + this.samples.toString();
}
}
@@ -0,0 +1,47 @@
package me.konsolas.aac.checks.combat;
import java.util.HashMap;
import java.util.UUID;
import java.util.Map;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
public class TargetRotationTracker {
private final Map<UUID, Float> previousYaw = new HashMap<>();
private final Map<UUID, Vector> previousTargetPosition = new HashMap<>();
private final Map<UUID, Integer> previousTargetId = new HashMap<>();
private final boolean requireTargetDistance;
public TargetRotationTracker(boolean flag) {
this.requireTargetDistance = flag;
}
public TargetRotationTracker() {
this(true);
}
public boolean hasTargetChangedAndMoved(Player player, LivingEntity livingEntity) {
this.previousYaw.putIfAbsent(player.getUniqueId(), Float.valueOf(player.getLocation().getYaw()));
this.previousTargetPosition.putIfAbsent(player.getUniqueId(), livingEntity.getLocation().toVector());
this.previousTargetId.putIfAbsent(player.getUniqueId(), livingEntity.getEntityId());
double yaw = player.getLocation().getYaw() - ((Float)this.previousYaw.get(player.getUniqueId())).floatValue();
if (Math.abs(yaw) < 70.0) {
return false;
}
if (((Vector)this.previousTargetPosition.get(player.getUniqueId())).distance(livingEntity.getLocation().toVector()) < 0.6) {
return false;
}
if (livingEntity.getEntityId() != ((Integer)this.previousTargetId.get(player.getUniqueId())).intValue() && (!this.requireTargetDistance || livingEntity.getLocation().toVector().distance((Vector)this.previousTargetPosition.get(player.getUniqueId())) < 2.5)) {
this.previousTargetId.put(player.getUniqueId(), livingEntity.getEntityId());
this.previousTargetPosition.put(player.getUniqueId(), livingEntity.getLocation().toVector());
this.previousYaw.put(player.getUniqueId(), Float.valueOf(player.getLocation().getYaw()));
return false;
}
this.previousTargetId.put(player.getUniqueId(), livingEntity.getEntityId());
this.previousTargetPosition.put(player.getUniqueId(), livingEntity.getLocation().toVector());
this.previousYaw.put(player.getUniqueId(), Float.valueOf(player.getLocation().getYaw()));
return true;
}
}
@@ -0,0 +1,20 @@
package me.konsolas.aac.checks.combat;
public class TrainingSample {
private final double[] inputs;
private final double[] expectedOutputs;
public TrainingSample(double[] dArray, double[] dArray2) {
this.inputs = dArray;
this.expectedOutputs = dArray2;
}
public double[] getInputs() {
return this.inputs;
}
public double[] getExpectedOutputs() {
return this.expectedOutputs;
}
}
@@ -0,0 +1,30 @@
package me.konsolas.aac.checks.combat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
public class TrainingSet
implements Iterable {
private final List samples = new ArrayList();
public synchronized void addSample(TrainingSample trainingSample) {
this.samples.add(trainingSample);
}
public synchronized int size() {
return this.samples.size();
}
public synchronized TrainingSample getRandomSample() {
int value = ThreadLocalRandom.current().nextInt(this.samples.size());
return (TrainingSample)this.samples.get(value);
}
public Iterator iterator() {
return Collections.unmodifiableList(this.samples).iterator();
}
}
@@ -0,0 +1,19 @@
package me.konsolas.aac.checks.movement;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketListener;
import me.konsolas.aac.AAC;
import me.konsolas.aac.checks.Detector;
import org.bukkit.plugin.Plugin;
public final class Derp
extends Detector {
public Derp(AAC aAC) {
super(aAC);
HeadRollPacketListener headRollPacketListener = new HeadRollPacketListener(this, (Plugin)this.plugin, new PacketType[]{PacketType.Play.Client.LOOK, PacketType.Play.Client.POSITION_LOOK});
this.packetListeners.add(headRollPacketListener);
ProtocolLibrary.getProtocolManager().addPacketListener((PacketListener)headRollPacketListener);
}
}
@@ -0,0 +1,127 @@
package me.konsolas.aac.checks.movement;
import java.util.Locale;
import java.util.WeakHashMap;
import java.util.concurrent.TimeUnit;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.BlockPositionView;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.compat.EnvironmentBlockChecks;
import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;
import me.konsolas.aac.util.GroundCollisionState;
import me.konsolas.aac.util.MathUtilities;
import me.konsolas.aac.compat.ServerVersion;
import me.konsolas.aac.api.HackType;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.util.Vector;
public class Elytra
extends Detector
implements MovementCheckListener {
private final WeakHashMap lastMotionVectors;
private final ExpiringMap<Player, Boolean> fireworkBoostCooldowns;
private double tolerance;
private boolean teleport;
private int minVl;
private double rocketTolerance;
public Elytra(AAC aAC) {
super(aAC);
this.lastMotionVectors = new WeakHashMap();
this.tolerance = 0.2;
this.teleport = true;
this.minVl = 12;
this.rocketTolerance = 3.0;
this.tolerance = this.plugin.getConfig().getDouble("elytra.tolerance", this.tolerance);
this.rocketTolerance = this.plugin.getConfig().getDouble("elytra.rocket_tolerance", this.tolerance);
this.teleport = this.plugin.getConfig().getBoolean("elytra.teleport", this.teleport);
this.minVl = this.plugin.getConfig().getInt("elytra.min_vl", this.minVl);
ExpirationPolicy expirationPolicy = ExpirationPolicy.CREATED;
TimeUnit timeUnit = TimeUnit.MILLISECONDS;
long ticks = 3000L;
this.fireworkBoostCooldowns = ExpiringMap.builder().expirationPolicy(expirationPolicy).expiration(ticks, timeUnit).build();
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent playerInteractEvent) {
Player player;
if (playerInteractEvent.getItem() != null && playerInteractEvent.getItem().getType() == Material.FIREWORK && (AAC.serverVersion.getVersion() == ServerVersion.VER_1_11 || AAC.serverVersion.getVersion() == ServerVersion.VER_1_12) && AAC.serverVersion.isElytraGliding(player = playerInteractEvent.getPlayer()) && playerInteractEvent.getAction() == Action.RIGHT_CLICK_AIR) {
this.fireworkBoostCooldowns.put(playerInteractEvent.getPlayer(), false);
this.fireworkBoostCooldowns.resetExpiration(playerInteractEvent.getPlayer());
}
}
@Override
public void onTick(long ticks, long ticks2) {
if (ticks % 50L == 0L) {
for (Player player : Bukkit.getOnlinePlayers()) {
this.decreaseViolationLevel(player.getUniqueId(), 1);
}
}
}
@Override
public void onMovement(PlayerMoveEvent playerMoveEvent, GroundCollisionState groundCollisionState, GroundCollisionState groundCollisionState2, BlockPositionView blockPositionView, BlockPositionView blockPositionView2, long ticks) {
long ticks2 = ticks ^ 0x60FF4F6C294EL;
Vector vector = new Vector(playerMoveEvent.getTo().getX() - playerMoveEvent.getFrom().getX(), playerMoveEvent.getTo().getY() - playerMoveEvent.getFrom().getY(), playerMoveEvent.getTo().getZ() - playerMoveEvent.getFrom().getZ());
Vector vector2 = (Vector)this.lastMotionVectors.get(playerMoveEvent.getPlayer());
this.lastMotionVectors.put(playerMoveEvent.getPlayer(), vector);
if (vector2 == null) {
if ((Math.abs(vector.getX()) > 0.6 || Math.abs(vector.getZ()) > 0.6 || Math.abs(vector.getY()) > 0.6) && this.recordViolation(playerMoveEvent.getPlayer().getUniqueId(), 5 + (int)(vector.length() * 5.0), HackType.FLY, String.format(Locale.UK, playerMoveEvent.getPlayer().getName() + " failed Elytra: Initiated flight too quickly: %.3f,%.3f,%.3f", vector.getX(), vector.getY(), vector.getZ()), ticks2) && this.teleport && this.getViolationLevel(playerMoveEvent.getPlayer()) > this.minVl && playerMoveEvent.getPlayer().getLocation().subtract(0.0, 1.0, 0.0).getBlock().isEmpty()) {
playerMoveEvent.setTo(playerMoveEvent.getPlayer().getLocation().subtract(0.0, 1.0, 0.0));
}
return;
}
double x = Math.sqrt(vector.getX() * vector.getX() + vector.getZ() * vector.getZ());
double y = vector.getY();
double x2 = Math.sqrt(vector2.getX() * vector2.getX() + vector2.getZ() * vector2.getZ());
double y2 = vector2.getY();
boolean flag = this.fireworkBoostCooldowns.containsKey(playerMoveEvent.getPlayer());
if (flag && Math.abs(x) < this.rocketTolerance && Math.abs(y) < this.rocketTolerance) {
return;
}
if (EnvironmentBlockChecks.isInLiquid(blockPositionView2) || blockPositionView.getBlock().getType() == Material.WEB) {
double y3 = Math.abs(vector.getY());
double d = Jesus.isAboveLiquidSurface(blockPositionView) ? 0.42 : 0.2;
if ((y3 > d || Math.abs(vector.getX()) > 0.5 || Math.abs(vector.getZ()) > 0.5) && x > x2 && this.recordViolation(playerMoveEvent.getPlayer().getUniqueId(), 2 + (int)(vector.length() * 2.0), HackType.FLY, String.format(Locale.UK, playerMoveEvent.getPlayer().getName() + " failed Elytra: Moved too quickly in water %.3f,%.3f,%.3f", vector.getX(), vector.getY(), vector.getZ()), ticks2) && this.teleport && this.getViolationLevel(playerMoveEvent.getPlayer()) > this.minVl && playerMoveEvent.getPlayer().getLocation().subtract(0.0, 1.0, 0.0).getBlock().isEmpty()) {
playerMoveEvent.setTo(playerMoveEvent.getPlayer().getLocation().subtract(0.0, 1.0, 0.0));
}
return;
}
double d2 = EntityPushCalculator.calculatePush(playerMoveEvent.getPlayer()).getLength();
if (d2 > 0.0 && x < d2 + this.tolerance && y < y2 + d2) {
return;
}
Vector vector3 = ElytraPhysics.predictVelocity(vector2, playerMoveEvent.getFrom().getPitch(), playerMoveEvent.getFrom().getYaw());
Vector vector4 = ElytraPhysics.predictVelocity(vector2, playerMoveEvent.getTo().getPitch(), playerMoveEvent.getTo().getYaw());
double x3 = vector.getX() * vector.getX() + vector.getZ() * vector.getZ() <= vector3.getX() * vector3.getX() + vector3.getZ() * vector3.getZ() + this.tolerance && (Math.abs(vector.getY()) <= Math.abs(vector3.getY() + this.tolerance) || vector.getY() < vector3.getY() && vector.getY() > vector3.getY() - this.tolerance - this.tolerance) ? 0.0 : Math.min(vector3.distance(vector), vector4.distance(vector));
if (x3 > this.tolerance) {
Vector vector5;
Object[] objectArray = new Object[2];
Vector vector6 = vector5 = vector;
objectArray[0] = MathUtilities.formatVector(vector6);
objectArray[1] = x3;
if (this.recordViolation(playerMoveEvent.getPlayer().getUniqueId(), (int)(2.0 + x3 * 10.0), HackType.FLY, String.format(Locale.UK, playerMoveEvent.getPlayer().getName() + " failed Fly: (Elytra) unexpected movement: %s (%.3f)", objectArray), ticks2) && this.teleport && this.getViolationLevel(playerMoveEvent.getPlayer()) > this.minVl && playerMoveEvent.getPlayer().getLocation().subtract(0.0, 1.0, 0.0).getBlock().isEmpty()) {
playerMoveEvent.setTo(playerMoveEvent.getPlayer().getLocation().subtract(0.0, 1.0, 0.0));
}
}
}
@Override
public boolean shouldProcessMovement(PlayerMoveEvent playerMoveEvent) {
Player player;
if (playerMoveEvent.isCancelled()) {
return false;
}
return playerMoveEvent.getPlayer().getGameMode() != GameMode.SPECTATOR && playerMoveEvent.getPlayer().getVehicle() == null && !playerMoveEvent.getPlayer().isFlying() && !playerMoveEvent.getPlayer().isDead() && playerMoveEvent.getPlayer().getLocation().getY() > -1024.0 && !playerMoveEvent.getPlayer().getAllowFlight() && !playerMoveEvent.getPlayer().isSleeping() && AAC.serverVersion.isElytraGliding(player = playerMoveEvent.getPlayer());
}
}
@@ -0,0 +1,82 @@
package me.konsolas.aac.checks.movement;
import me.konsolas.aac.util.MathUtilities;
import org.bukkit.util.Vector;
public class ElytraPhysics {
public static Vector predictVelocity(Vector vector, float f, float f2) {
double d;
f = Math.min(Math.max(f, -90.0f), 90.0f);
Vector vector2 = vector.clone();
Vector vector3 = ElytraPhysics.direction(f, f2);
float f3 = f * ((float)Math.PI / 180);
double x = Math.sqrt(vector3.getX() * vector3.getX() + vector3.getZ() * vector3.getZ());
double x2 = Math.sqrt(vector2.getX() * vector2.getX() + vector2.getZ() * vector2.getZ());
double d2 = vector3.length();
float f4 = (float)Math.cos(f3);
f4 = (float)((double)f4 * (double)f4 * Math.min(1.0, d2 / 0.4));
vector2.setY(vector2.getY() + -0.08 + (double)f4 * 0.06);
if (vector2.getY() < 0.0 && x > Vector.getEpsilon()) {
d = vector2.getY() * -0.1 * (double)f4;
vector2.setY(vector2.getY() + d);
vector2.setX(vector2.getX() + vector3.getX() * d / x);
vector2.setZ(vector2.getZ() + vector3.getZ() * d / x);
}
if ((double)f3 < 0.0) {
d = x2 * -Math.sin(f3) * 0.04;
vector2.setY(vector2.getY() + d * 3.2);
vector2.setX(vector2.getX() - vector3.getX() * d / x);
vector2.setZ(vector2.getZ() - vector3.getZ() * d / x);
}
if (x > Vector.getEpsilon()) {
vector2.setX(vector2.getX() + (vector3.getX() / x * x2 - vector2.getX()) * 0.1);
vector2.setZ(vector2.getZ() + (vector3.getZ() / x * x2 - vector2.getZ()) * 0.1);
}
vector2.setX(vector2.getX() * 0.99);
vector2.setY(vector2.getY() * 0.98);
vector2.setZ(vector2.getZ() * 0.99);
return vector2;
}
private static Vector direction(float f, float f2) {
double d = Math.cos((double)(-f2 * ((float)Math.PI / 180)) - Math.PI);
double d2 = Math.sin((double)(-f2 * ((float)Math.PI / 180)) - Math.PI);
double d3 = -Math.cos(-f * ((float)Math.PI / 180));
double d4 = Math.sin(-f * ((float)Math.PI / 180));
return new Vector(d2 * d3, d4, d * d3);
}
private static float[] angles(Vector vector) {
double d;
double d2;
float[] fArray = new float[2];
double x = vector.getX();
double z = vector.getZ();
if (x == 0.0 && z == 0.0) {
fArray[0] = vector.getY() > 0.0 ? -90.0f : 90.0f;
return fArray;
}
double d3 = Math.atan2(-x, z);
double d4 = d2 = Math.toDegrees((d3 + Math.PI * 2) % (Math.PI * 2));
fArray[1] = (float)MathUtilities.wrapDegrees(d4);
double d5 = x * x;
double d6 = z * z;
double d7 = Math.sqrt(d5 + d6);
double y = d = Math.toDegrees(Math.atan(-vector.getY() / d7));
fArray[0] = (float)MathUtilities.wrapDegrees(y);
return fArray;
}
public static Vector predictFromObservedVelocity(Vector vector, Vector vector2) {
Vector vector3 = vector2.clone();
vector3.setX(vector3.getX() / 0.99);
vector3.setY(vector3.getY() / 0.98);
vector3.setZ(vector3.getZ() / 0.99);
vector3.setY(vector3.getY() + 0.08);
vector3.subtract(vector).normalize();
Vector vector4 = vector3;
float[] fArray = ElytraPhysics.angles(vector4);
return ElytraPhysics.predictVelocity(vector, fArray[0], fArray[1]);
}
}
@@ -0,0 +1,32 @@
package me.konsolas.aac.checks.movement;
import java.util.Iterator;
import me.konsolas.aac.util.HorizontalVector;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
public class EntityPushCalculator {
public static HorizontalVector calculatePush(Player player) {
HorizontalVector horizontalVector = HorizontalVector.ZERO;
Iterator iterator = player.getNearbyEntities(2.0, 1.8, 2.0).iterator();
while (iterator.hasNext()) {
Entity entity = (Entity)iterator.next();
if (entity.equals(player.getVehicle())) continue;
double x = player.getLocation().getX() - entity.getLocation().getX();
double z = player.getLocation().getZ() - entity.getLocation().getZ();
double d = Math.max(Math.abs(x), Math.abs(z));
if (!(d > 0.01)) continue;
d = Math.sqrt(d);
x /= d;
z /= d;
double d2 = Math.min(1.0, 1.0 / d);
x *= d2;
z *= d2;
x *= 0.05;
z *= 0.05;
horizontalVector = horizontalVector.add(new HorizontalVector(x *= 1.0, z *= 1.0));
}
return horizontalVector;
}
}
@@ -0,0 +1,49 @@
package me.konsolas.aac.checks.movement;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class FallDamageContext {
private final Location location;
private final boolean onGround;
private final double currentY;
private final double verticalVelocity;
private final Player player;
private final Double lastGroundY;
final NoFall detector;
public FallDamageContext(NoFall noFall, Location location, boolean flag, double d, double d2, Player player, Double doubleVal) {
this.detector = noFall;
this.location = location;
this.onGround = flag;
this.currentY = d;
this.verticalVelocity = d2;
this.player = player;
this.lastGroundY = doubleVal;
}
static Location getLocation(FallDamageContext fallDamageContext) {
return fallDamageContext.location;
}
static Player getPlayer(FallDamageContext fallDamageContext) {
return fallDamageContext.player;
}
static boolean isOnGround(FallDamageContext fallDamageContext) {
return fallDamageContext.onGround;
}
static double getVerticalVelocity(FallDamageContext fallDamageContext) {
return fallDamageContext.verticalVelocity;
}
static double getCurrentY(FallDamageContext fallDamageContext) {
return fallDamageContext.currentY;
}
static Double getLastGroundY(FallDamageContext fallDamageContext) {
return fallDamageContext.lastGroundY;
}
}
@@ -0,0 +1,347 @@
package me.konsolas.aac.checks.movement;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketListener;
import java.util.Collections;
import java.util.Iterator;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.WeakHashMap;
import java.util.concurrent.TimeUnit;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.BlockPositionView;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.compat.EnvironmentBlockChecks;
import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;
import me.konsolas.aac.util.GroundCollisionState;
import me.konsolas.aac.util.MathUtilities;
import me.konsolas.aac.api.HackType;
import org.bukkit.GameMode;
import org.bukkit.entity.Boat;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import org.bukkit.event.vehicle.VehicleEnterEvent;
import org.bukkit.event.vehicle.VehicleExitEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
public final class Fly
extends Detector
implements MovementCheckListener {
private final ExpiringMap<UUID, Integer> recentViolationPlayers;
private final ExpiringMap<Player, Double> expectedVelocityY;
private final WeakHashMap<Player, Double> lastVerticalDeltas;
private final WeakHashMap<Player, VerticalMovementState> lastVerticalStates;
private double tolerance;
private double eTolerance;
private boolean teleport;
private double vlMultiplier;
private int minVl;
private int velTicks;
private boolean abilities;
private boolean resetPitch;
private int reduceDelay;
private final Set levitatingPlayers;
private final Set exemptNextMovePlayers;
public Fly(AAC aAC) { super(aAC);
this.lastVerticalDeltas = new WeakHashMap();
this.lastVerticalStates = new WeakHashMap();
this.tolerance = 0.06;
this.eTolerance = 0.2;
this.teleport = true;
this.vlMultiplier = 6.0;
this.minVl = 12;
this.velTicks = 12;
this.abilities = true;
this.resetPitch = true;
this.reduceDelay = 20;
this.levitatingPlayers = Collections.newSetFromMap(new WeakHashMap());
this.exemptNextMovePlayers = Collections.newSetFromMap(new WeakHashMap());
this.tolerance = this.plugin.getConfig().getDouble("fly.tolerance", this.tolerance);
this.eTolerance = this.plugin.getConfig().getDouble("fly.e_tolerance", this.eTolerance);
this.teleport = this.plugin.getConfig().getBoolean("fly.teleport", this.teleport);
this.vlMultiplier = this.plugin.getConfig().getDouble("fly.vl_multiplier", this.vlMultiplier);
this.minVl = this.plugin.getConfig().getInt("fly.min_vl", this.minVl);
this.velTicks = this.plugin.getConfig().getInt("fly.vel_ticks", this.velTicks);
this.abilities = this.plugin.getConfig().getBoolean("fly.abilities", this.abilities);
this.resetPitch = this.plugin.getConfig().getBoolean("fly.reset_pitch", this.resetPitch);
this.reduceDelay = this.plugin.getConfig().getInt("fly.reduce_delay", this.reduceDelay);
TimeUnit timeUnit = TimeUnit.MILLISECONDS;
long ticks = this.velTicks * 50;
ExpirationPolicy expirationPolicy = ExpirationPolicy.CREATED;
this.expectedVelocityY = ExpiringMap.builder().expiration(ticks, timeUnit).expirationPolicy(expirationPolicy).build();
ExpirationPolicy expirationPolicy2 = ExpirationPolicy.CREATED;
TimeUnit timeUnit2 = TimeUnit.MILLISECONDS;
long ticks2 = this.reduceDelay * 50;
this.recentViolationPlayers = ExpiringMap.builder().expirationPolicy(expirationPolicy2).expiration(ticks2, timeUnit2).build();
PacketAdapter packetAdapter = new FlyVelocityPacketListener(this, (Plugin)this.plugin, new PacketType[]{PacketType.Play.Server.ENTITY_VELOCITY, PacketType.Play.Server.EXPLOSION});
this.packetListeners.add(packetAdapter);
ProtocolLibrary.getProtocolManager().addPacketListener((PacketListener)packetAdapter);
if (this.abilities) {
packetAdapter = new FlyAbilitiesPacketListener(this, (Plugin)this.plugin, new PacketType[]{PacketType.Play.Client.ABILITIES});
this.packetListeners.add(packetAdapter);
ProtocolLibrary.getProtocolManager().addPacketListener((PacketListener)packetAdapter);
}
}
@Override
public boolean shouldProcessMovement(PlayerMoveEvent playerMoveEvent) {
Player player;
if (playerMoveEvent.isCancelled()) {
return false;
}
if (!(playerMoveEvent.getPlayer().getGameMode() == GameMode.SPECTATOR || playerMoveEvent.getPlayer().getVehicle() != null || AAC.serverVersion.isElytraGliding(player = playerMoveEvent.getPlayer()) || playerMoveEvent.getPlayer().isFlying() || playerMoveEvent.getPlayer().isDead() || !(playerMoveEvent.getPlayer().getLocation().getY() > -1024.0) || playerMoveEvent.getPlayer().getAllowFlight() || playerMoveEvent.getPlayer().isSleeping())) {
return true;
}
this.exemptNextMovePlayers.add(playerMoveEvent.getPlayer());
this.lastVerticalDeltas.remove(playerMoveEvent.getPlayer());
return false;
}
@Override
public void onMovement(PlayerMoveEvent playerMoveEvent, GroundCollisionState groundCollisionState, GroundCollisionState groundCollisionState2, BlockPositionView blockPositionView, BlockPositionView blockPositionView2, long ticks) {
double d;
double d2;
double d3;
long ticks2 = ticks ^ 0x60FF4F6C294EL;
if (!this.recentViolationPlayers.containsKey(playerMoveEvent.getPlayer().getUniqueId())) {
this.decreaseViolationLevel(playerMoveEvent.getPlayer().getUniqueId(), 1);
}
if (this.exemptNextMovePlayers.contains(playerMoveEvent.getPlayer())) {
this.lastVerticalDeltas.remove(playerMoveEvent.getPlayer());
this.exemptNextMovePlayers.remove(playerMoveEvent.getPlayer());
return;
}
double y = playerMoveEvent.getTo().getY() - playerMoveEvent.getFrom().getY();
double x = Math.sqrt(Math.pow(playerMoveEvent.getTo().getX() - playerMoveEvent.getFrom().getX(), 2.0) + Math.pow(playerMoveEvent.getTo().getZ() - playerMoveEvent.getFrom().getZ(), 2.0));
if (y == 0.0 && x == 0.0 && this.lastVerticalStates.containsKey(playerMoveEvent.getPlayer()) && ((VerticalMovementState)this.lastVerticalStates.get((Object)playerMoveEvent.getPlayer())).timestamp > System.currentTimeMillis() - 250L) {
return;
}
int value = 0;
for (PotionEffect potionEffect : playerMoveEvent.getPlayer().getActivePotionEffects()) {
if (!potionEffect.getType().equals((Object)PotionEffectType.JUMP)) continue;
value = potionEffect.getAmplifier() + 1;
}
boolean flag = EnvironmentBlockChecks.isInLiquid(blockPositionView);
boolean flag2 = EnvironmentBlockChecks.isInLiquid(blockPositionView2);
if (!this.lastVerticalDeltas.containsKey(playerMoveEvent.getPlayer())) {
this.lastVerticalDeltas.put(playerMoveEvent.getPlayer(), y);
return;
}
int value2 = 0;
boolean flag3 = this.levitatingPlayers.contains(playerMoveEvent.getPlayer());
if (AAC.serverVersion.hasLevitation(playerMoveEvent.getPlayer())) {
this.levitatingPlayers.add(playerMoveEvent.getPlayer());
for (PotionEffect effect : playerMoveEvent.getPlayer().getActivePotionEffects()) {
if (!effect.getType().equals((Object)PotionEffectType.LEVITATION)) continue;
value2 = effect.getAmplifier() + 1;
}
} else {
this.levitatingPlayers.remove(playerMoveEvent.getPlayer());
}
VerticalMovementState verticalMovementState = new VerticalMovementState();
verticalMovementState.timestamp = System.currentTimeMillis();
verticalMovementState.lastSafeLocation = playerMoveEvent.getFrom().clone();
VerticalMovementState verticalMovementState3 = this.lastVerticalStates.get(playerMoveEvent.getPlayer()) == null ? new VerticalMovementState() : this.lastVerticalStates.get(playerMoveEvent.getPlayer());
this.lastVerticalStates.put(playerMoveEvent.getPlayer(), verticalMovementState);
boolean flag4 = false;
for (Entity entity : playerMoveEvent.getPlayer().getNearbyEntities(1.5, 1.0, 1.5)) {
if (!(entity instanceof Boat)) continue;
flag4 = true;
}
if (!flag4 && EnvironmentBlockChecks.isOnWaterLily(blockPositionView)) {
flag4 = true;
}
if (groundCollisionState.isCollided()) {
groundCollisionState = groundCollisionState.isAirStep() ? GroundCollisionState.TRUE_AIRSTEP_COLLIDED : GroundCollisionState.TRUE_NORMAL_COLLIDED;
}
boolean flag5 = blockPositionView.getBlock().isLiquid();
boolean flag6 = EnvironmentBlockChecks.isInFlowingLiquid(blockPositionView);
boolean flag7 = EnvironmentBlockChecks.isInSnow(blockPositionView);
boolean flag8 = EnvironmentBlockChecks.isNearPiston(blockPositionView);
boolean flag9 = EnvironmentBlockChecks.isPlayerInCobweb(blockPositionView);
boolean flag10 = EnvironmentBlockChecks.isOnLadderOrVine(blockPositionView);
boolean flag11 = EnvironmentBlockChecks.isNearSnowColumn(blockPositionView) || EnvironmentBlockChecks.isNearSnowColumn(blockPositionView2);
boolean flag12 = EnvironmentBlockChecks.isClimbingWithLowCeiling(blockPositionView, 0.8);
boolean flag13 = EnvironmentBlockChecks.isClimbingWithLowCeiling(blockPositionView2, 0.3);
VerticalMovementState verticalMovementState2 = verticalMovementState;
Object obj = verticalMovementState3;
int value3 = value2;
int value4 = value;
double d4 = this.tolerance;
double d5 = x;
boolean flag14 = flag10;
boolean flag15 = flag8;
boolean flag16 = flag9;
boolean flag17 = flag11;
boolean flag18 = flag2;
boolean flag19 = flag;
boolean flag20 = flag12;
boolean flag21 = flag13;
boolean flag22 = flag6;
boolean flag23 = flag5;
double y2 = playerMoveEvent.getPlayer().getVelocity().getY();
boolean flag24 = flag4;
boolean flag25 = flag7;
boolean flag26 = EnvironmentBlockChecks.isAboveOrOnSlimeBlock(blockPositionView);
GroundCollisionState groundCollisionState3 = groundCollisionState2;
GroundCollisionState groundCollisionState4 = groundCollisionState;
boolean flag27 = EnvironmentBlockChecks.isOnEdgeOfHalfBlock(blockPositionView);
double d6 = (Double)this.lastVerticalDeltas.get(playerMoveEvent.getPlayer());
double d7 = y;
boolean flag28 = VerticalMovementPredictor.isValidVerticalMovement(d7, d6, flag27, groundCollisionState4, groundCollisionState3, flag26, flag25, flag24, y2, flag23, flag22, flag21, flag20, flag19, flag18, flag17, flag16, flag15, flag14, d5, d4, value4, value3, (VerticalMovementState)obj, verticalMovementState2);
if (value2 == 0 || !flag3) {
if (groundCollisionState.isOnGround() && groundCollisionState2.isOnGround() && y <= 0.6 && y > 0.0) {
flag28 = true;
}
} else {
flag28 = true;
}
if (EnvironmentBlockChecks.isNearShulkerBox(blockPositionView) && MathUtilities.approximatelyEquals(d3 = y, d2 = 0.05, d = this.tolerance)) {
flag28 = true;
}
int value5 = 0;
boolean flag29 = false;
if (value2 == 0 && flag3 && Math.abs(y) < 1.0) {
flag28 = true;
}
if (verticalMovementState3.lastSafeLocation != null && playerMoveEvent.getFrom().distanceSquared(playerMoveEvent.getTo()) < 5.0 && playerMoveEvent.getFrom().getWorld().equals(verticalMovementState3.lastSafeLocation.getWorld()) && playerMoveEvent.getFrom().distanceSquared(verticalMovementState3.lastSafeLocation) < 5.0 && verticalMovementState3.lastSafeLocation.getY() <= playerMoveEvent.getFrom().getY() && !groundCollisionState.isOnGround() && !flag28) {
value5 = 5;
flag29 = true;
}
if (!flag28 && this.expectedVelocityY.containsKey(playerMoveEvent.getPlayer())) {
double d8 = (Double)this.expectedVelocityY.get(playerMoveEvent.getPlayer());
double d9 = flag ? 0.2 : 0.0;
if (y < d8 + this.tolerance + d9 || y < 0.0 && groundCollisionState2.isOnGround()) {
if (y > d8 - this.tolerance) {
flag28 = true;
} else if (Math.abs(y) > 1.0 && y > d8 * 0.5 - 0.1 - this.tolerance || y > d8 / 0.5 - 0.1 - this.tolerance) {
flag28 = true;
}
}
this.expectedVelocityY.remove(playerMoveEvent.getPlayer());
} else if (groundCollisionState.isOnGround()) {
value5 = 5;
}
if (this.plugin.logManager.isDebugEnabled()) {
double d10;
double d11;
double d12;
double d13 = d12 = y;
double d14 = d11 = verticalMovementState.lastDeltaY;
double d15 = d10 = verticalMovementState.expectedDeltaY;
this.plugin.logManager.logPlayerDebug(playerMoveEvent.getPlayer(), "(Fly) fullmove [dy r:" + MathUtilities.formatNumber(d13) + " u:" + MathUtilities.formatNumber(d14) + " e:" + MathUtilities.formatNumber(d15) + " fs u:" + verticalMovementState.fallStage + " uml u:" + flag29 + " g " + (Object)((Object)groundCollisionState) + (Object)((Object)groundCollisionState2) + "]");
}
if (!flag28) {
int value6 = 100;
long ticks3 = value5 + 5 + (int)(Math.abs(y - VerticalMovementPredictor.predictNextGravityMotion((Double)this.lastVerticalDeltas.get(playerMoveEvent.getPlayer()))) * this.vlMultiplier);
int value7 = MathUtilities.clampToInt(ticks3, value6);
if (this.recordViolation(playerMoveEvent.getPlayer().getUniqueId(), value7, HackType.FLY, String.format(Locale.UK, playerMoveEvent.getPlayer().getName() + " failed Fly: moved unexpectedly: %.4f (%.4f->%.4f / %s%s%d)", new Object[]{y, verticalMovementState3.lastDeltaY, verticalMovementState.expectedDeltaY, groundCollisionState, groundCollisionState2, verticalMovementState.fallStage}), ticks2) && this.teleport && (this.getViolationLevel(playerMoveEvent.getPlayer()) > this.minVl || Math.abs(y) > 1.0) && !playerMoveEvent.isCancelled()) {
if (flag29) {
PlayerMoveEvent playerMoveEvent2 = new PlayerMoveEvent(playerMoveEvent.getPlayer(), verticalMovementState3.lastSafeLocation, verticalMovementState3.lastSafeLocation);
boolean flag30 = this.resetPitch;
boolean flag31 = false;
double y3 = Math.min(-0.1, playerMoveEvent.getPlayer().getVelocity().getY());
PlayerMoveEvent playerMoveEvent3 = playerMoveEvent2;
Player player = playerMoveEvent.getPlayer();
this.plugin.setbackManager.applySetback(player, playerMoveEvent3, y3, flag31, flag30);
playerMoveEvent.setTo(playerMoveEvent2.getTo());
} else {
boolean flag32 = this.resetPitch;
boolean flag33 = true;
double y4 = playerMoveEvent.getPlayer().getVelocity().getY();
PlayerMoveEvent playerMoveEvent4 = playerMoveEvent;
Player player = playerMoveEvent.getPlayer();
this.plugin.setbackManager.applySetback(player, playerMoveEvent4, y4, flag33, flag32);
}
}
((VerticalMovementState)this.lastVerticalStates.get((Object)playerMoveEvent.getPlayer())).lastDeltaY = 0.0;
this.lastVerticalDeltas.put(playerMoveEvent.getPlayer(), 0.0);
} else {
this.lastVerticalDeltas.put(playerMoveEvent.getPlayer(), y);
}
}
@EventHandler
public void onPlayerToggleFlight(PlayerToggleFlightEvent playerToggleFlightEvent) {
this.lastVerticalDeltas.remove(playerToggleFlightEvent.getPlayer());
}
@EventHandler
public void onVehicleEnter(VehicleEnterEvent vehicleEnterEvent) {
if (vehicleEnterEvent.getEntered() instanceof Player) {
this.lastVerticalDeltas.remove(vehicleEnterEvent.getEntered());
}
}
@EventHandler
public void onVehicleExit(VehicleExitEvent vehicleExitEvent) {
if (vehicleExitEvent.getExited() instanceof Player) {
this.lastVerticalDeltas.remove(vehicleExitEvent.getExited());
}
}
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onBlockBreak(BlockBreakEvent blockBreakEvent) {
Iterator iterator = blockBreakEvent.getPlayer().getWorld().getNearbyEntities(blockBreakEvent.getBlock().getLocation(), 1.0, 3.0, 1.0).iterator();
while (iterator.hasNext()) {
Entity entity = (Entity)iterator.next();
if (!(entity instanceof Player)) continue;
this.lastVerticalStates.getOrDefault((Object)blockBreakEvent.getPlayer(), VerticalMovementPredictor.DEFAULT_STATE).brokeBlockNearby = true;
}
}
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onBlockPlace(BlockPlaceEvent blockPlaceEvent) {
Iterator iterator = blockPlaceEvent.getPlayer().getWorld().getNearbyEntities(blockPlaceEvent.getBlockPlaced().getLocation(), 1.0, 3.0, 1.0).iterator();
while (iterator.hasNext()) {
Entity entity = (Entity)iterator.next();
if (!(entity instanceof Player)) continue;
this.lastVerticalStates.getOrDefault((Object)blockPlaceEvent.getPlayer(), VerticalMovementPredictor.DEFAULT_STATE).placedBlockNearby = true;
}
}
@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent playerTeleportEvent) {
this.lastVerticalDeltas.put(playerTeleportEvent.getPlayer(), 0.0);
Optional.ofNullable(this.lastVerticalStates.get(playerTeleportEvent.getPlayer())).ifPresent(Fly::clearLastLocation);
}
@EventHandler
public void onPlayerRespawn(PlayerRespawnEvent playerRespawnEvent) {
this.lastVerticalDeltas.remove(playerRespawnEvent.getPlayer());
}
@Override
public boolean recordViolation(UUID uUID, int i, HackType hackType, String str, long ticks) {
long ticks2 = ticks ^ 0L;
this.recentViolationPlayers.put(uUID, 0);
this.recentViolationPlayers.resetExpiration(uUID);
return super.recordViolation(uUID, i, hackType, str, ticks2);
}
private static void clearLastLocation(VerticalMovementState verticalMovementState) {
verticalMovementState.lastSafeLocation = null;
}
static ExpiringMap<Player, Double> getExpectedVelocityMap(Fly fly) {
return fly.expectedVelocityY;
}
}
@@ -0,0 +1,29 @@
package me.konsolas.aac.checks.movement;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import me.konsolas.aac.AAC;
import me.konsolas.aac.api.HackType;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class FlyAbilitiesPacketListener
extends PacketAdapter {
final Fly detector;
public FlyAbilitiesPacketListener(Fly fly, Plugin plugin, PacketType[] packetTypeArray) { super(plugin, packetTypeArray);
this.detector = fly;
}
public void onPacketReceiving(PacketEvent packetEvent) {
Player player;
long ticks = 113218805911140L;
if (!packetEvent.getPlayer().getAllowFlight() && packetEvent.getPlayer().getGameMode() != GameMode.CREATIVE && packetEvent.getPlayer().getGameMode() != GameMode.SPECTATOR && !((AAC)this.plugin).checkManager.isPlayerExempt(player = packetEvent.getPlayer())) {
this.detector.recordViolation(packetEvent.getPlayer().getUniqueId(), 1000, HackType.FLY, packetEvent.getPlayer().getName() + " failed Fly: sent invalid ability packets", ticks);
}
}
}
@@ -0,0 +1,39 @@
package me.konsolas.aac.checks.movement;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import me.konsolas.aac.AAC;
import me.konsolas.aac.compat.EntityVelocityPacket;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class FlyVelocityPacketListener
extends PacketAdapter {
final Fly detector;
public FlyVelocityPacketListener(Fly fly, Plugin plugin, PacketType[] packetTypeArray) { super(plugin, packetTypeArray);
this.detector = fly;
}
public void onPacketSending(PacketEvent packetEvent) {
if (packetEvent.getPacketType() == PacketType.Play.Server.ENTITY_VELOCITY) {
PacketContainer packetContainer = packetEvent.getPacket();
EntityVelocityPacket entityVelocityPacket = new EntityVelocityPacket(packetContainer);
try {
if (entityVelocityPacket.getEntityId() == packetEvent.getPlayer().getEntityId() && ((AAC)this.plugin).setbackManager.getSetbackCheck(packetEvent.getPlayer()) == null) {
Fly.getExpectedVelocityMap(this.detector).remove(packetEvent.getPlayer());
Fly.getExpectedVelocityMap(this.detector).put(packetEvent.getPlayer(), entityVelocityPacket.getVelocityY());
Player player = packetEvent.getPlayer();
Fly.getExpectedVelocityMap(this.detector).resetExpiration(player);
}
}
catch (UnsupportedOperationException unsupportedOperationException) {
this.plugin.getLogger().warning("(Fly) Velocity packet was sent to a temporary player (" + packetEvent.getPlayer().getName() + "/" + packetEvent.getPlayer().getUniqueId() + ")");
}
}
}
}
@@ -0,0 +1,39 @@
package me.konsolas.aac.checks.movement;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import me.konsolas.aac.AAC;
import me.konsolas.aac.api.HackType;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class HeadRollPacketListener
extends PacketAdapter {
final Derp detector;
public HeadRollPacketListener(Derp derp, Plugin plugin, PacketType[] packetTypeArray) { super(plugin, packetTypeArray);
this.detector = derp;
}
public void onPacketReceiving(PacketEvent packetEvent) {
long ticks = 113218805911140L;
if (packetEvent.getPacketType() == PacketType.Play.Client.LOOK || packetEvent.getPacketType() == PacketType.Play.Client.POSITION_LOOK) {
try {
Player player = packetEvent.getPlayer();
if (((AAC)this.plugin).checkManager.isPlayerExempt(player)) {
return;
}
float f = ((Float)packetEvent.getPacket().getFloat().read(1)).floatValue();
if (f > 90.1f || f < -90.1f) {
packetEvent.setCancelled(true);
this.detector.recordViolation(packetEvent.getPlayer().getUniqueId(), 1, HackType.DERP, packetEvent.getPlayer().getName() + " failed HeadRoll: Moved with an illegal pitch (" + f + ")", ticks);
}
}
catch (NullPointerException nullPointerException) {
}
}
}
}
@@ -0,0 +1,113 @@
package me.konsolas.aac.checks.movement;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.BlockPositionView;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.util.GroundCollisionState;
import me.konsolas.aac.api.HackType;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.entity.Boat;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.plugin.Plugin;
public final class Jesus
extends Detector
implements MovementCheckListener {
private final Map liquidTicks;
private final Set enteredLiquidPlayers;
private boolean teleport;
public Jesus(AAC aAC) { super(aAC);
this.liquidTicks = new HashMap();
this.enteredLiquidPlayers = new HashSet();
this.teleport = true;
this.teleport = this.plugin.getConfig().getBoolean("jesus.teleport");
Server server = Bukkit.getServer();
this.scheduledTaskIds.add(server.getScheduler().scheduleSyncRepeatingTask((Plugin)this.plugin, this::decayJesusViolations, 20L, 100L));
}
static boolean isAboveLiquidSurface(BlockPositionView blockPositionView) {
if (Jesus.isSolidOrDry(blockPositionView.getBlockAtNegOffset(0.0, 0.5, 0.3)) || Jesus.isSolidOrDry(blockPositionView.getBlockAtNegOffset(0.3, 0.6, 0.0)) || Jesus.isSolidOrDry(blockPositionView.getBlockAtNegOffset(0.0, 0.6, -0.3)) || Jesus.isSolidOrDry(blockPositionView.getBlockAtNegOffset(-0.3, 0.6, 0.0)) || Jesus.isSolidOrDry(blockPositionView.getBlockAtNegOffset(-0.3, 0.6, -0.3)) || Jesus.isSolidOrDry(blockPositionView.getBlockAtNegOffset(-0.3, 0.6, 0.3)) || Jesus.isSolidOrDry(blockPositionView.getBlockAtNegOffset(0.3, 0.6, -0.3)) || Jesus.isSolidOrDry(blockPositionView.getBlockAtNegOffset(0.3, 0.6, 0.3)) || Jesus.isSolidOrDry(blockPositionView.getBlockAtNegOffset(0.0, 0.0, 0.3)) || Jesus.isSolidOrDry(blockPositionView.getBlockAtNegOffset(0.3, 0.0, 0.0)) || Jesus.isSolidOrDry(blockPositionView.getBlockAtNegOffset(0.0, 0.0, -0.3)) || Jesus.isSolidOrDry(blockPositionView.getBlockAtNegOffset(-0.3, 0.0, 0.0)) || Jesus.isSolidOrDry(blockPositionView.getBlockAtNegOffset(-0.3, 0.0, -0.3)) || Jesus.isSolidOrDry(blockPositionView.getBlockAtNegOffset(-0.3, 0.0, 0.3)) || Jesus.isSolidOrDry(blockPositionView.getBlockAtNegOffset(0.3, 0.0, -0.3))) {
return false;
}
return blockPositionView.getBlockAtNegOffset(0.0, 0.5, 0.0).isLiquid() || blockPositionView.getBlockAtNegOffset(0.0, 1.5, 0.0).isLiquid() || blockPositionView.getBlock().isLiquid();
}
private static boolean isSolidOrDry(Block block) {
return !block.isLiquid() && !block.isEmpty();
}
@Override
public boolean shouldProcessMovement(PlayerMoveEvent playerMoveEvent) {
if (playerMoveEvent.getPlayer().isFlying() || playerMoveEvent.getPlayer().getVehicle() != null) {
return false;
}
for (Entity entity : playerMoveEvent.getPlayer().getNearbyEntities(3.0, 3.0, 3.0)) {
if (!(entity instanceof Boat)) continue;
return false;
}
Player player = playerMoveEvent.getPlayer();
return !AAC.serverVersion.isElytraGliding(player);
}
@Override
public void onMovement(PlayerMoveEvent playerMoveEvent, GroundCollisionState groundCollisionState, GroundCollisionState groundCollisionState2, BlockPositionView blockPositionView, BlockPositionView blockPositionView2, long ticks) {
long ticks2 = ticks ^ 0x60FF4F6C294EL;
if (Jesus.isAboveLiquidSurface(blockPositionView) && playerMoveEvent.getPlayer().getLocation().add(0.0, 0.5, 0.0).getBlock().isEmpty() && (playerMoveEvent.getPlayer().getLocation().subtract(0.0, 1.5, 0.0).getBlock().isLiquid() || playerMoveEvent.getPlayer().getLocation().subtract(0.0, 0.5, 0.0).getBlock().isLiquid()) && !this.plugin.combatTracker.hasRecentDamage(playerMoveEvent.getPlayer())) {
if (playerMoveEvent.getPlayer().getLocation().subtract(0.0, 0.2, 0.0).getBlock().isLiquid()) {
if (!this.liquidTicks.containsKey(playerMoveEvent.getPlayer().getUniqueId())) {
this.liquidTicks.put(playerMoveEvent.getPlayer().getUniqueId(), 0);
}
this.enteredLiquidPlayers.add(playerMoveEvent.getPlayer().getUniqueId());
}
if (this.enteredLiquidPlayers.contains(playerMoveEvent.getPlayer().getUniqueId())) {
if (!this.liquidTicks.containsKey(playerMoveEvent.getPlayer().getUniqueId())) {
this.liquidTicks.put(playerMoveEvent.getPlayer().getUniqueId(), 0);
}
this.liquidTicks.put(playerMoveEvent.getPlayer().getUniqueId(), (Integer)this.liquidTicks.get(playerMoveEvent.getPlayer().getUniqueId()) + 1);
if ((Integer)this.liquidTicks.get(playerMoveEvent.getPlayer().getUniqueId()) > 20 && this.recordViolation(playerMoveEvent.getPlayer().getUniqueId(), 1, HackType.JESUS, playerMoveEvent.getPlayer().getName() + " failed Jesus: tried to float above water", ticks2) && this.teleport) {
playerMoveEvent.setTo(playerMoveEvent.getFrom().subtract(0.0, 0.1, 0.0));
}
}
} else {
this.liquidTicks.remove(playerMoveEvent.getPlayer().getUniqueId());
}
}
private double findWaterSurfaceY(Location location, int i) {
if (this.withY(location, location.getY() + 1.5).getBlock().isLiquid()) {
return 256.0;
}
for (double y = location.getY() + 1.0; y > location.getY() - (double)i; y -= 1.0) {
if (!this.withY(location, y).getBlock().isLiquid()) continue;
return this.withY(location, y).getBlock().getY() + 1;
}
return 256.0;
}
private Location withY(Location location, double d) {
location.setY(d);
return location;
}
private void decayJesusViolations() {
Server server = Bukkit.getServer();
Iterator iterator = server.getOnlinePlayers().iterator();
while (iterator.hasNext()) {
Player player = (Player)iterator.next();
this.decreaseViolationLevel(player.getUniqueId(), 1);
}
}
}
@@ -0,0 +1,42 @@
package me.konsolas.aac.checks.movement;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import java.util.Locale;
import me.konsolas.aac.checks.CheckManager;
import me.konsolas.aac.api.HackType;
import org.bukkit.plugin.Plugin;
public class MovementBoundsPacketListener
extends PacketAdapter {
final CheckManager checkManager;
public MovementBoundsPacketListener(CheckManager checkManager, Plugin plugin, ListenerPriority listenerPriority, PacketType[] packetTypeArray) { super(plugin, listenerPriority, packetTypeArray);
this.checkManager = checkManager;
}
public void onPacketReceiving(PacketEvent packetEvent) {
long ticks = 113218805911140L;
double d = (Double)packetEvent.getPacket().getDoubles().readSafely(0);
double d2 = (Double)packetEvent.getPacket().getDoubles().readSafely(2);
if (CheckManager.isOutOfBounds(this.checkManager, d, d2)) {
try {
this.checkManager.getDetector(HackType.SPEED).recordViolation(packetEvent.getPlayer().getUniqueId(), 100, HackType.SPEED, String.format(Locale.UK, packetEvent.getPlayer().getName() + " failed Speed: moved out of bounds (%.2f,%.2f)", d, d2), ticks);
}
catch (NullPointerException nullPointerException) {
return;
}
PacketContainer packetContainer = packetEvent.getPacket().deepClone();
packetContainer.getDoubles().writeSafely(0, packetEvent.getPlayer().getLocation().getX());
packetContainer.getDoubles().writeSafely(1, packetEvent.getPlayer().getLocation().getY());
packetContainer.getDoubles().writeSafely(2, packetEvent.getPlayer().getLocation().getZ());
packetEvent.setCancelled(true);
packetEvent.setPacket(packetContainer);
}
}
}
@@ -0,0 +1,12 @@
package me.konsolas.aac.checks.movement;
import me.konsolas.aac.util.BlockPositionView;
import me.konsolas.aac.util.GroundCollisionState;
import org.bukkit.event.player.PlayerMoveEvent;
public interface MovementCheckListener {
public void onMovement(PlayerMoveEvent event, GroundCollisionState groundCollisionState, GroundCollisionState groundCollisionState2, BlockPositionView blockPositionView, BlockPositionView blockPositionView2, long ticks);
public boolean shouldProcessMovement(PlayerMoveEvent event);
}
@@ -0,0 +1,358 @@
package me.konsolas.aac.checks.movement;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketListener;
import java.util.Collections;
import java.util.Deque;
import java.util.Map;
import java.util.Queue;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ConcurrentMap;
import me.konsolas.aac.AAC;
import me.konsolas.aac.checks.CleanupHandler;
import me.konsolas.aac.compat.CollisionAccess;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.util.MathUtilities;
import me.konsolas.aac.api.HackType;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector;
public class MovementManager
extends Detector
implements Listener,
CleanupHandler {
public static final ServerTeleportCallContext TELEPORT_CONTEXT = new ServerTeleportCallContext();
private final PacketListener packetListener;
private final int minBalance;
private final int cancelThreshold;
private final int resetLevel;
private final int balanceCap;
private final boolean dealFall;
private final double tpAcceptThreshold;
private final Object balanceLock;
private final Map<Player, Location> lastValidLocations;
private final Map<Player, Deque<Location>> queuedLocations;
private final Map<Player, Double> packetBalances;
private final Map<Player, Long> lastPacketTimestamps;
private final ConcurrentMap<Player, PendingTeleport> pendingTeleports;
public MovementManager(AAC aAC) { super(aAC);
this.balanceLock = new Object();
this.lastValidLocations = Collections.synchronizedMap(new WeakHashMap());
this.queuedLocations = Collections.synchronizedMap(new WeakHashMap());
this.packetBalances = Collections.synchronizedMap(new WeakHashMap());
this.lastPacketTimestamps = Collections.synchronizedMap(new WeakHashMap());
this.pendingTeleports = new ConcurrentHashMap();
this.minBalance = aAC.getConfig().getInt("move.min_balance", -80);
this.cancelThreshold = aAC.getConfig().getInt("move.cancel_threshold", 10);
this.resetLevel = aAC.getConfig().getInt("move.reset_level", -1);
this.balanceCap = aAC.getConfig().getInt("move.balance_cap", 15);
this.dealFall = aAC.getConfig().getBoolean("move.deal_fall", true);
this.tpAcceptThreshold = aAC.getConfig().getDouble("move.tp_accept_threshold", 0.0);
Server server = aAC.getServer();
this.scheduledTaskIds.add(server.getScheduler().scheduleSyncRepeatingTask((Plugin)aAC, this::decayMoveViolations, 1L, (long)aAC.getConfig().getInt("move.decay")));
Server server2 = aAC.getServer();
this.scheduledTaskIds.add(server2.getScheduler().scheduleSyncRepeatingTask((Plugin)aAC, this::flushStaleMoveQueues, 15L, 15L));
this.packetListener = new MovementPacketListener(this, (Plugin)aAC, ListenerPriority.LOW, new PacketType[]{PacketType.Play.Client.FLYING, PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK, PacketType.Play.Client.LOOK, PacketType.Play.Server.POSITION});
ProtocolLibrary.getProtocolManager().addPacketListener(this.packetListener);
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
private void processQueuedMoves(Player player, long ticks) {
long ticks2 = (ticks = 0x269727F98245L ^ ticks) ^ 0x7F1E5BD63D22L;
if (player.getVehicle() != null) {
this.queuedLocations.remove(player);
this.lastValidLocations.remove(player);
return;
}
this.lastValidLocations.putIfAbsent(player, player.getLocation());
this.packetBalances.putIfAbsent(player, Double.valueOf(this.minBalance));
this.queuedLocations.putIfAbsent(player, new ConcurrentLinkedDeque());
Deque deque = (Deque)this.queuedLocations.get(player);
synchronized (deque) {
Location location;
if (this.plugin.logManager.isDebugEnabled()) {
this.plugin.logManager.logPlayerDebug(player, "checking packets [size r:" + ((Deque)this.queuedLocations.get(player)).size() + "]");
}
if (((Deque)this.queuedLocations.get(player)).size() == 1) {
this.packetBalances.put(player, Math.max((Double)this.packetBalances.get(player), (double)this.resetLevel));
}
Location location2 = (Location)this.lastValidLocations.get(player);
while ((location = (Location)((Deque)this.queuedLocations.get(player)).poll()) != null) {
if (location.getWorld() == null) {
location2 = location;
location.setWorld(player.getWorld());
}
PlayerMoveEvent playerMoveEvent = new PlayerMoveEvent(player, location2, location);
Location location3 = playerMoveEvent.getTo().clone();
if (this.plugin.logManager.isDebugEnabled()) {
Vector vector;
Vector vector2;
Vector vector3 = vector2 = playerMoveEvent.getFrom().toVector();
Vector vector4 = vector = playerMoveEvent.getTo().toVector();
this.plugin.logManager.logPlayerDebug(player, "move [from r:" + MathUtilities.formatVector(vector3) + " to r:" + MathUtilities.formatVector(vector4) + " eq u:" + playerMoveEvent.getFrom().equals((Object)playerMoveEvent.getTo()) + "]");
}
boolean flag = true;
if (!playerMoveEvent.getTo().equals((Object)playerMoveEvent.getFrom())) {
if (!CollisionAccess.isValidLocation(playerMoveEvent.getTo()) || Math.abs(location2.getX() - playerMoveEvent.getTo().getX()) + Math.abs(location2.getY() - playerMoveEvent.getTo().getY()) + Math.abs(location2.getZ() - playerMoveEvent.getTo().getZ()) > 50.0) {
Vector vector;
Vector vector5 = vector = location2.toVector();
if (this.recordViolation(playerMoveEvent.getPlayer().getUniqueId(), 100, HackType.MOVE, playerMoveEvent.getPlayer().getName() + " failed Move: (movement validation) sent unsafe movement " + MathUtilities.formatVector(vector5) + " -> " + location.toVector(), ticks2)) {
boolean flag2 = false;
boolean flag3 = false;
double y = player.getVelocity().getY();
PlayerMoveEvent playerMoveEvent2 = playerMoveEvent;
Player player2 = player;
this.plugin.setbackManager.applySetback(player2, playerMoveEvent2, y, flag3, flag2);
flag = this.dealFall;
}
} else {
this.plugin.checkManager.movementCallback.accept(playerMoveEvent);
}
}
if (!location3.equals((Object)playerMoveEvent.getTo())) {
double y2 = Math.min(player.getVelocity().getY(), -0.2);
float y3 = player.getFallDistance() + (float)Math.max(location2.getY() - location3.getY(), location2.getY() - playerMoveEvent.getTo().getY());
if (this.plugin.logManager.isDebugEnabled()) {
Vector vector;
Vector vector6;
Vector vector7;
Vector vector8 = vector7 = playerMoveEvent.getFrom().toVector();
Vector vector9 = vector6 = location3.toVector();
Vector vector10 = vector = playerMoveEvent.getTo().toVector();
this.plugin.logManager.logPlayerDebug(player, "setback [move from: " + MathUtilities.formatVector(vector8) + " to: " + MathUtilities.formatVector(vector9) + "] [setback to: " + MathUtilities.formatVector(vector10) + " velY: " + y2 + " fallD: " + y3 + "]");
}
this.plugin.setbackManager.setSetbackCheck(this, player);
player.teleport(playerMoveEvent.getTo(), PlayerTeleportEvent.TeleportCause.UNKNOWN);
player.setVelocity(new Vector(0.0, y2, 0.0));
if (flag) {
player.setFallDistance(y3);
}
this.plugin.setbackManager.clearSetbackCheck(player);
((Deque)this.queuedLocations.get(playerMoveEvent.getPlayer())).clear();
break;
}
location2 = playerMoveEvent.getTo();
}
this.lastValidLocations.put(player, location2);
}
}
private static Location extractLocationFromPacket(PacketContainer packetContainer, Location location, World world) {
if (packetContainer.getType() == PacketType.Play.Client.FLYING) {
return location.clone();
}
if (packetContainer.getType() == PacketType.Play.Client.POSITION_LOOK) {
double d = (Double)packetContainer.getDoubles().read(0);
double d2 = (Double)packetContainer.getDoubles().read(1);
double d3 = (Double)packetContainer.getDoubles().read(2);
float f = ((Float)packetContainer.getFloat().read(0)).floatValue();
float f2 = ((Float)packetContainer.getFloat().read(1)).floatValue();
return new Location(world, d, d2, d3, f, f2);
}
if (packetContainer.getType() == PacketType.Play.Client.POSITION) {
double d4 = (Double)packetContainer.getDoubles().read(0);
double d5 = (Double)packetContainer.getDoubles().read(1);
double d6 = (Double)packetContainer.getDoubles().read(2);
float yaw = location.getYaw();
float pitch = location.getPitch();
return new Location(world, d4, d5, d6, yaw, pitch);
}
if (packetContainer.getType() == PacketType.Play.Client.LOOK) {
double x = location.getX();
double y = location.getY();
double z = location.getZ();
float f3 = ((Float)packetContainer.getFloat().read(0)).floatValue();
float f4 = ((Float)packetContainer.getFloat().read(1)).floatValue();
return new Location(world, x, y, z, f3, f4);
}
throw new IllegalArgumentException("Can't accept packet of type " + packetContainer.getType());
}
private Location getLastValidLocation(Player player) {
if (this.lastValidLocations.containsKey(player)) {
return ((Location)this.lastValidLocations.get(player)).clone();
}
return player.getLocation();
}
@EventHandler
public void onPlayerMove(PlayerMoveEvent playerMoveEvent) {
long ticks = 69757560353027L;
if (playerMoveEvent.getPlayer().getVehicle() != null && playerMoveEvent.getFrom().getWorld().equals(playerMoveEvent.getTo().getWorld())) {
this.plugin.checkManager.movementCallback.accept(playerMoveEvent);
this.lastValidLocations.put(playerMoveEvent.getPlayer(), playerMoveEvent.getPlayer().getLocation());
this.queuedLocations.remove(playerMoveEvent.getPlayer());
} else {
this.processQueuedMoves(playerMoveEvent.getPlayer(), ticks);
}
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@EventHandler
public void onPlayerChangedWorld(PlayerChangedWorldEvent playerChangedWorldEvent) {
Queue queue;
Queue queue2 = queue = (Queue)this.queuedLocations.computeIfAbsent(playerChangedWorldEvent.getPlayer(), MovementManager::createQueueOnWorldChange);
synchronized (queue2) {
queue.clear();
}
this.lastValidLocations.remove(playerChangedWorldEvent.getPlayer());
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
@EventHandler(priority=EventPriority.MONITOR, ignoreCancelled=true)
public void onPlayerTeleport(PlayerTeleportEvent playerTeleportEvent) {
if (playerTeleportEvent.getCause() != PlayerTeleportEvent.TeleportCause.UNKNOWN || !TELEPORT_CONTEXT.isCalledFromBukkit() || playerTeleportEvent.getPlayer().getVehicle() != null) {
Queue queue;
Queue queue2 = queue = (Queue)this.queuedLocations.computeIfAbsent(playerTeleportEvent.getPlayer(), MovementManager::createQueueOnTeleport);
synchronized (queue2) {
queue.clear();
}
this.lastValidLocations.remove(playerTeleportEvent.getPlayer());
}
}
@EventHandler
public void onPlayerRespawn(PlayerRespawnEvent playerRespawnEvent) {
this.lastValidLocations.remove(playerRespawnEvent.getPlayer());
this.queuedLocations.putIfAbsent(playerRespawnEvent.getPlayer(), new ConcurrentLinkedDeque());
((Deque)this.queuedLocations.get(playerRespawnEvent.getPlayer())).clear();
if (this.plugin.logManager.isDebugEnabled()) {
Vector vector;
Vector vector2 = vector = playerRespawnEvent.getRespawnLocation().toVector();
this.plugin.logManager.logPlayerDebug(playerRespawnEvent.getPlayer(), "respawned -> " + MathUtilities.formatVector(vector2));
}
}
@EventHandler
public void onPlayerDeath(PlayerDeathEvent playerDeathEvent) {
this.queuedLocations.putIfAbsent(playerDeathEvent.getEntity(), new ConcurrentLinkedDeque());
((Deque)this.queuedLocations.get(playerDeathEvent.getEntity())).clear();
if (this.plugin.logManager.isDebugEnabled()) {
this.plugin.logManager.logPlayerDebug(playerDeathEvent.getEntity(), "died");
}
}
@Override
public void cleanup() {
super.cleanup();
ProtocolLibrary.getProtocolManager().removePacketListener(this.packetListener);
HandlerList.unregisterAll((Listener)this);
}
private static Deque createQueueOnTeleport(Player player) {
return new ConcurrentLinkedDeque();
}
private static Deque createQueueOnWorldChange(Player player) {
return new ConcurrentLinkedDeque();
}
private void flushStaleMoveQueues() {
Bukkit.getOnlinePlayers().stream().filter(this::hasStaleMoveQueue).forEach(this::processPlayerMoveQueue);
}
private void processPlayerMoveQueue(Player player) {
long ticks = 69757560353027L;
this.queuedLocations.computeIfAbsent(player, MovementManager::createQueueOnFlush).add(player.getLocation());
this.processQueuedMoves(player, ticks);
}
private static Deque createQueueOnFlush(Player player) {
return new ConcurrentLinkedDeque();
}
private boolean hasStaleMoveQueue(Player player) {
return System.nanoTime() - this.lastPacketTimestamps.getOrDefault(player, System.nanoTime()) > 500000000L;
}
private void decayMoveViolations() {
Bukkit.getOnlinePlayers().forEach(this::decayPlayerMoveViolation);
}
private void decayPlayerMoveViolation(Player player) {
this.decreaseViolationLevel(player.getUniqueId(), 1);
}
static Map<Player, Deque<Location>> getQueuedLocations(MovementManager movementManager) {
return movementManager.queuedLocations;
}
static int getMinBalance(MovementManager movementManager) {
return movementManager.minBalance;
}
static Map<Player, Double> getPacketBalances(MovementManager movementManager) {
return movementManager.packetBalances;
}
static Location parsePacketLocation(PacketContainer packetContainer, Location location, World world) {
World world2 = world;
Location location2 = location;
PacketContainer packetContainer2 = packetContainer;
return MovementManager.extractLocationFromPacket(packetContainer2, location2, world2);
}
static Object getBalanceLock(MovementManager movementManager) {
return movementManager.balanceLock;
}
static Map<Player, Long> getLastPacketTimestamps(MovementManager movementManager) {
return movementManager.lastPacketTimestamps;
}
static int getBalanceCap(MovementManager movementManager) {
return movementManager.balanceCap;
}
static ConcurrentMap<Player, PendingTeleport> getPendingTeleports(MovementManager movementManager) {
return movementManager.pendingTeleports;
}
static Location getLastLocationForPlayer(MovementManager movementManager, Player player) {
return movementManager.getLastValidLocation(player);
}
static int getCancelThreshold(MovementManager movementManager) {
return movementManager.cancelThreshold;
}
static Map<Player, Location> getLastValidLocations(MovementManager movementManager) {
return movementManager.lastValidLocations;
}
static int getResetLevel(MovementManager movementManager) {
return movementManager.resetLevel;
}
static double getTpAcceptThreshold(MovementManager movementManager) {
return movementManager.tpAcceptThreshold;
}
}
@@ -0,0 +1,153 @@
package me.konsolas.aac.checks.movement;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import java.util.Deque;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedDeque;
import me.konsolas.aac.AAC;
import me.konsolas.aac.compat.CollisionAccess;
import me.konsolas.aac.util.MathUtilities;
import me.konsolas.aac.compat.PlayerPositionPacket;
import me.konsolas.aac.compat.RelativePositionFlag;
import me.konsolas.aac.api.HackType;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector;
public class MovementPacketListener
extends PacketAdapter {
final MovementManager movementManager;
public MovementPacketListener(MovementManager movementManager, Plugin plugin, ListenerPriority listenerPriority, PacketType[] packetTypeArray) { super(plugin, listenerPriority, packetTypeArray);
this.movementManager = movementManager;
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
public void onPacketReceiving(PacketEvent packetEvent) {
Location location;
long ticks = 113218805911140L;
try {
if (packetEvent.isCancelled()) {
return;
}
packetEvent.getPlayer().getUniqueId();
}
catch (NullPointerException nullPointerException) {
return;
}
Deque<Location> deque = MovementManager.getQueuedLocations(this.movementManager).computeIfAbsent(packetEvent.getPlayer(), MovementPacketListener::createPositionQueue);
MovementManager.getPacketBalances(this.movementManager).putIfAbsent(packetEvent.getPlayer(), Double.valueOf(MovementManager.getMinBalance(this.movementManager)));
double d = (Double)MovementManager.getPacketBalances(this.movementManager).get(packetEvent.getPlayer());
Deque<Location> deque2 = deque;
synchronized (deque2) {
location = Optional.<Location>ofNullable(deque.peekLast()).orElseGet(() -> this.fallbackPlayerLocation(packetEvent));
}
World world = packetEvent.getPlayer().getWorld();
Location location2 = location;
PacketContainer packetContainer = packetEvent.getPacket();
Location targetLoc = MovementManager.parsePacketLocation(packetContainer, location2, world);
if (!CollisionAccess.isValidLocation(targetLoc) || Math.abs(location.getX() - targetLoc.getX()) + Math.abs(location.getY() - targetLoc.getY()) + Math.abs(location.getZ() - targetLoc.getZ()) > 50.0) {
packetEvent.setCancelled(true);
}
Object obj = MovementManager.getBalanceLock(this.movementManager);
synchronized (obj) {
long now = System.nanoTime();
MovementManager.getLastPacketTimestamps(this.movementManager).computeIfAbsent(packetEvent.getPlayer(), arg_0 -> MovementPacketListener.initialPacketTimestamp(now, arg_0));
long ticks2 = now - (Long)MovementManager.getLastPacketTimestamps(this.movementManager).get(packetEvent.getPlayer());
MovementManager.getLastPacketTimestamps(this.movementManager).put(packetEvent.getPlayer(), now);
double d2 = (double)ticks2 / 5.0E7;
MovementManager.getPacketBalances(this.movementManager).put(packetEvent.getPlayer(), Math.max(Math.min((Double)MovementManager.getPacketBalances(this.movementManager).get(packetEvent.getPlayer()) + 1.0 - d2, (double)MovementManager.getBalanceCap(this.movementManager)), (double)MovementManager.getMinBalance(this.movementManager)));
}
if (MovementManager.getPendingTeleports(this.movementManager).containsKey(packetEvent.getPlayer())) {
Location deque3 = targetLoc;
Location location3 = MovementManager.getLastLocationForPlayer(this.movementManager, packetEvent.getPlayer());
if (!((PendingTeleport)MovementManager.getPendingTeleports(this.movementManager).get(packetEvent.getPlayer())).matches(location3, deque3)) {
if (((AAC)this.plugin).logManager.isDebugEnabled()) {
Vector vector;
Vector vector2 = vector = targetLoc.toVector();
((AAC)this.plugin).logManager.logPlayerDebug(packetEvent.getPlayer(), "waiting for tp reply: " + MathUtilities.formatVector(vector2) + ", for " + MovementManager.getPendingTeleports(this.movementManager).get(packetEvent.getPlayer()));
}
packetEvent.setCancelled(true);
return;
}
}
if ((obj = (PendingTeleport)MovementManager.getPendingTeleports(this.movementManager).remove(packetEvent.getPlayer())) != null) {
if (((AAC)this.plugin).logManager.isDebugEnabled()) {
Vector vector;
Vector vector3 = vector = targetLoc.toVector();
((AAC)this.plugin).logManager.logPlayerDebug(packetEvent.getPlayer(), "answered tp: " + MathUtilities.formatVector(vector3) + ", for " + obj);
}
Deque deque4 = deque;
synchronized (deque4) {
Location location4 = targetLoc.clone();
location4.setWorld(null);
deque.add(location4);
}
}
if (d < (double)MovementManager.getCancelThreshold(this.movementManager)) {
obj = deque;
synchronized (obj) {
deque.add(targetLoc);
}
} else {
MovementManager.getPacketBalances(this.movementManager).put(packetEvent.getPlayer(), (Double)MovementManager.getPacketBalances(this.movementManager).get(packetEvent.getPlayer()) - 1.0);
if (packetEvent.getPlayer().getGameMode() != GameMode.SPECTATOR) {
packetEvent.setCancelled(true);
this.movementManager.recordViolation(packetEvent.getPlayer().getUniqueId(), 1, HackType.MOVE, String.format(Locale.UK, packetEvent.getPlayer().getName() + " failed Move: (movement validation) too many packets (balance %.2f)", d), ticks);
}
}
}
public void onPacketSending(PacketEvent packetEvent) {
PacketContainer packetContainer = packetEvent.getPacket();
PlayerPositionPacket playerPositionPacket = new PlayerPositionPacket(packetContainer);
Vector vector = new Vector(playerPositionPacket.getX(), playerPositionPacket.getY(), playerPositionPacket.getZ());
Set set = playerPositionPacket.getTeleportFlags();
PendingTeleport pendingTeleport = new PendingTeleport(this.movementManager, set, vector);
MovementManager.getPacketBalances(this.movementManager).compute(packetEvent.getPlayer(), this::adjustBalanceOnTeleport);
if (playerPositionPacket.getX() == 0.0 && playerPositionPacket.getY() == 0.0 && playerPositionPacket.getZ() == 0.0 && set.contains((Object)RelativePositionFlag.X) && set.contains((Object)RelativePositionFlag.Y) && set.contains((Object)RelativePositionFlag.Z)) {
return;
}
if (!MovementManager.getLastValidLocations(this.movementManager).containsKey(packetEvent.getPlayer())) {
if (((AAC)this.plugin).logManager.isDebugEnabled()) {
((AAC)this.plugin).logManager.logPlayerDebug(packetEvent.getPlayer(), "important tp: ? -> " + pendingTeleport.toString());
}
MovementManager.getPendingTeleports(this.movementManager).put(packetEvent.getPlayer(), pendingTeleport);
MovementManager.getQueuedLocations(this.movementManager).putIfAbsent(packetEvent.getPlayer(), new ConcurrentLinkedDeque());
((Deque)MovementManager.getQueuedLocations(this.movementManager).get(packetEvent.getPlayer())).clear();
} else if (((AAC)this.plugin).logManager.isDebugEnabled()) {
Vector vector2;
Vector vector3 = vector2 = ((Location)MovementManager.getLastValidLocations(this.movementManager).get(packetEvent.getPlayer())).toVector();
((AAC)this.plugin).logManager.logPlayerDebug(packetEvent.getPlayer(), "(bukkit) tp: " + MathUtilities.formatVector(vector3) + " -> " + pendingTeleport.toString());
}
}
private Double adjustBalanceOnTeleport(Player player, Double doubleVal) {
return doubleVal == null ? (double)(MovementManager.getResetLevel(this.movementManager) - 1) : doubleVal - 1.0;
}
private static Long initialPacketTimestamp(long ticks, Player player) {
return ticks - 50000000L;
}
private Location fallbackPlayerLocation(PacketEvent packetEvent) {
return MovementManager.getLastValidLocations(this.movementManager).getOrDefault(packetEvent.getPlayer(), packetEvent.getPlayer().getLocation());
}
private static Deque createPositionQueue(Player player) {
return new ConcurrentLinkedDeque();
}
}
@@ -0,0 +1,155 @@
package me.konsolas.aac.checks.movement;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketListener;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.BlockPositionView;
import me.konsolas.aac.compat.CollisionAccess;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.compat.EnvironmentBlockChecks;
import me.konsolas.aac.util.GroundCollisionState;
import me.konsolas.aac.api.HackType;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.plugin.Plugin;
public final class NoFall
extends Detector
implements MovementCheckListener {
private double requiredVelocity;
private boolean dealDamage;
private boolean checkReduceAttempts;
private final Map<Player, Double> highestAirY;
private final Set<Player> groundedPlayers;
private final Queue<FallDamageContext> pendingFallChecks;
public NoFall(AAC aAC) { super(aAC);
this.requiredVelocity = -0.2;
this.dealDamage = true;
this.checkReduceAttempts = true;
this.highestAirY = Collections.synchronizedMap(new WeakHashMap());
this.groundedPlayers = Collections.newSetFromMap(new WeakHashMap());
this.pendingFallChecks = new ConcurrentLinkedQueue();
this.requiredVelocity = this.plugin.getConfig().getDouble("nofall.required_velocity", this.requiredVelocity);
this.dealDamage = this.plugin.getConfig().getBoolean("nofall.deal_damage", this.dealDamage);
this.checkReduceAttempts = this.plugin.getConfig().getBoolean("nofall.check_reduce_attempts", this.checkReduceAttempts);
NoFallMovementPacketListener noFallMovementPacketListener = new NoFallMovementPacketListener(this, (Plugin)this.plugin, new PacketType[]{PacketType.Play.Client.POSITION, PacketType.Play.Client.POSITION_LOOK, PacketType.Play.Client.FLYING, PacketType.Play.Client.LOOK});
this.packetListeners.add(noFallMovementPacketListener);
ProtocolLibrary.getProtocolManager().addPacketListener((PacketListener)noFallMovementPacketListener);
}
@Override
public boolean shouldProcessMovement(PlayerMoveEvent playerMoveEvent) {
return playerMoveEvent.getPlayer().getGameMode() != GameMode.CREATIVE && playerMoveEvent.getPlayer().getGameMode() != GameMode.SPECTATOR && !playerMoveEvent.getPlayer().getAllowFlight() && playerMoveEvent.getPlayer().getVehicle() == null;
}
@Override
public void onTick(long ticks, long ticks2) {
long ticks3 = ticks2 ^ 0x4DEAE20E7407L;
while (!this.pendingFallChecks.isEmpty()) {
double d;
FallDamageContext fallDamageContext = (FallDamageContext)this.pendingFallChecks.remove();
BlockPositionView blockPositionView = new BlockPositionView(FallDamageContext.getLocation(fallDamageContext));
if (!CollisionAccess.isValidLocation(new Location(blockPositionView.getWorld(), blockPositionView.getX(), blockPositionView.getY(), blockPositionView.getZ()))) continue;
boolean flag = CollisionAccess.getGroundCollisionState(new PlayerMoveEvent(FallDamageContext.getPlayer(fallDamageContext), FallDamageContext.getLocation(fallDamageContext), FallDamageContext.getLocation(fallDamageContext)), GroundCollisionState.FALSE_NORMAL).isOnGround() || EnvironmentBlockChecks.isNearSlabOrStair(blockPositionView);
boolean flag2 = FallDamageContext.isOnGround(fallDamageContext);
double d2 = FallDamageContext.getVerticalVelocity(fallDamageContext);
double d3 = FallDamageContext.getCurrentY(fallDamageContext);
if (flag || FallDamageContext.getLastGroundY(fallDamageContext) == null || !((d = FallDamageContext.getLastGroundY(fallDamageContext).doubleValue()) - d3 > 3.0) || !(d2 <= this.requiredVelocity) || !flag2 || !this.recordViolation(FallDamageContext.getPlayer(fallDamageContext).getUniqueId(), 1, HackType.NOFALL, FallDamageContext.getPlayer(fallDamageContext).getName() + " failed NoFall: invalid midair ground packet", ticks3) || !this.dealDamage) continue;
FallDamageContext.getPlayer(fallDamageContext).setFallDistance((float)(FallDamageContext.getLastGroundY(fallDamageContext) - FallDamageContext.getPlayer(fallDamageContext).getLocation().getY()));
}
}
@Override
public void onMovement(PlayerMoveEvent playerMoveEvent, GroundCollisionState groundCollisionState, GroundCollisionState groundCollisionState2, BlockPositionView blockPositionView, BlockPositionView blockPositionView2, long ticks) {
long ticks2 = ticks ^ 0x60FF4F6C294EL;
double y = playerMoveEvent.getTo().getY();
double y2 = y - playerMoveEvent.getFrom().getY();
if (groundCollisionState2.isOnGround()) {
if (this.plugin.logManager.isDebugEnabled()) {
this.plugin.logManager.logPlayerDebug(playerMoveEvent.getPlayer(), "(NoFall) " + playerMoveEvent.getPlayer().getName() + " landed");
}
this.groundedPlayers.add(playerMoveEvent.getPlayer());
double d = this.highestAirY.getOrDefault(playerMoveEvent.getPlayer(), 0.0) - y;
if (d >= 3.5 && (double)playerMoveEvent.getPlayer().getFallDistance() - y2 < d - 1.0) {
if ((double)playerMoveEvent.getPlayer().getFallDistance() <= 3.5 && d > 3.5 + (double)(playerMoveEvent.getPlayer().getFallDistance() * 2.0f)) {
if (this.recordViolation(playerMoveEvent.getPlayer().getUniqueId(), 2, HackType.NOFALL, String.format(playerMoveEvent.getPlayer().getName() + " failed NoFall: tried to avoid fall damage (%.2f/%.2f blocks)", Float.valueOf(playerMoveEvent.getPlayer().getFallDistance()), d), ticks2) && this.dealDamage) {
playerMoveEvent.getPlayer().setFallDistance((float)d);
}
} else if (this.checkReduceAttempts && this.recordViolation(playerMoveEvent.getPlayer().getUniqueId(), 1, HackType.NOFALL, String.format(playerMoveEvent.getPlayer().getName() + " failed NoFall: tried to reduce fall damage (%.2f/%.2f blocks)", Float.valueOf(playerMoveEvent.getPlayer().getFallDistance()), d), ticks2) && this.dealDamage) {
playerMoveEvent.getPlayer().setFallDistance((float)d);
}
}
} else {
this.groundedPlayers.remove(playerMoveEvent.getPlayer());
}
if (!(groundCollisionState.isOnGround() || groundCollisionState2.isOnGround() || EnvironmentBlockChecks.isOnLadderOrVine(blockPositionView) || EnvironmentBlockChecks.isOnLadderOrVine(blockPositionView2) || EnvironmentBlockChecks.isInLiquid(blockPositionView) || EnvironmentBlockChecks.isInLiquid(blockPositionView2))) {
if (this.highestAirY.containsKey(playerMoveEvent.getPlayer())) {
if (y > (Double)this.highestAirY.get(playerMoveEvent.getPlayer())) {
this.highestAirY.put(playerMoveEvent.getPlayer(), y);
}
} else {
this.highestAirY.put(playerMoveEvent.getPlayer(), y);
}
} else {
this.highestAirY.remove(playerMoveEvent.getPlayer());
}
}
@EventHandler
public void onBlockBreak(BlockBreakEvent blockBreakEvent) {
Server server = Bukkit.getServer();
Iterator iterator = server.getOnlinePlayers().iterator();
while (iterator.hasNext()) {
Player player = (Player)iterator.next();
BlockPositionView blockPositionView = new BlockPositionView(player.getLocation());
try {
if (!blockPositionView.getBlockAtNegOffset(0.0, 0.2, 0.3).equals(blockBreakEvent.getBlock()) && !blockPositionView.getBlockAtNegOffset(0.3, 0.2, 0.0).equals(blockBreakEvent.getBlock()) && !blockPositionView.getBlockAtNegOffset(0.0, 0.2, -0.3).equals(blockBreakEvent.getBlock()) && !blockPositionView.getBlockAtNegOffset(-0.3, 0.2, 0.0).equals(blockBreakEvent.getBlock()) && !blockPositionView.getBlockAtNegOffset(-0.3, 0.2, -0.3).equals(blockBreakEvent.getBlock()) && !blockPositionView.getBlockAtNegOffset(-0.3, 0.2, 0.3).equals(blockBreakEvent.getBlock()) && !blockPositionView.getBlockAtNegOffset(0.3, 0.2, -0.3).equals(blockBreakEvent.getBlock()) && !blockPositionView.getBlockAtNegOffset(0.3, 0.2, 0.3).equals(blockBreakEvent.getBlock())) continue;
this.highestAirY.put(player, player.getLocation().getY());
}
catch (NullPointerException nullPointerException) {}
}
}
@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent playerTeleportEvent) {
if (!(playerTeleportEvent.getCause() == PlayerTeleportEvent.TeleportCause.UNKNOWN && MovementManager.TELEPORT_CONTEXT.isCalledFromBukkit() || this.plugin.setbackManager.getSetbackCheck(playerTeleportEvent.getPlayer()) != null)) {
this.highestAirY.put(playerTeleportEvent.getPlayer(), playerTeleportEvent.getTo().getY());
}
}
@EventHandler
public void onPlayerRespawn(PlayerRespawnEvent playerRespawnEvent) {
this.highestAirY.remove(playerRespawnEvent.getPlayer());
}
static Map getHighestAirYMap(NoFall noFall) {
return noFall.highestAirY;
}
static Queue getPendingFallChecks(NoFall noFall) {
return noFall.pendingFallChecks;
}
static Set getGroundedPlayers(NoFall noFall) {
return noFall.groundedPlayers;
}
}
@@ -0,0 +1,48 @@
package me.konsolas.aac.checks.movement;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import me.konsolas.aac.AAC;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class NoFallMovementPacketListener
extends PacketAdapter {
final NoFall detector;
public NoFallMovementPacketListener(NoFall noFall, Plugin plugin, PacketType[] packetTypeArray) { super(plugin, packetTypeArray);
this.detector = noFall;
}
public void onPacketReceiving(PacketEvent packetEvent) {
if (packetEvent.isCancelled()) {
return;
}
try {
if (packetEvent.getPlayer().getGameMode() == GameMode.CREATIVE || packetEvent.getPlayer().getGameMode() == GameMode.SPECTATOR || packetEvent.getPlayer().getAllowFlight() || packetEvent.getPlayer().getVehicle() != null) {
return;
}
Player player = packetEvent.getPlayer();
if (((AAC)this.plugin).checkManager.isPlayerExempt(player)) {
return;
}
PacketContainer packetContainer = packetEvent.getPacket();
Location location = packetEvent.getPlayer().getLocation();
if (packetEvent.getPacketType() == PacketType.Play.Client.POSITION_LOOK || packetEvent.getPacketType() == PacketType.Play.Client.POSITION) {
location = new Location(packetEvent.getPlayer().getWorld(), ((Double)packetContainer.getDoubles().read(0)).doubleValue(), ((Double)packetContainer.getDoubles().read(1)).doubleValue(), ((Double)packetContainer.getDoubles().read(2)).doubleValue());
}
NoFall.getPendingFallChecks(this.detector).add(new FallDamageContext(this.detector, location, (Boolean)packetContainer.getBooleans().read(0), packetEvent.getPlayer().getLocation().getY(), packetEvent.getPlayer().getVelocity().getY(), packetEvent.getPlayer(), (Double)NoFall.getHighestAirYMap(this.detector).get(packetEvent.getPlayer())));
if (NoFall.getGroundedPlayers(this.detector).contains(packetEvent.getPlayer())) {
packetContainer.getBooleans().write(0, true);
}
}
catch (NullPointerException nullPointerException) {
}
}
}
@@ -0,0 +1,138 @@
package me.konsolas.aac.checks.movement;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.util.Vector;
import me.konsolas.aac.compat.RelativePositionFlag;
import me.konsolas.aac.util.MathUtilities;
public class PendingTeleport {
final boolean relativeX;
final boolean relativeY;
final boolean relativeZ;
final Vector target;
final MovementManager movementManager;
PendingTeleport(MovementManager movementManager, Set set, Vector vector) {
this.movementManager = movementManager;
this.relativeX = set.contains(RelativePositionFlag.X);
this.relativeY = set.contains(RelativePositionFlag.Y);
this.relativeZ = set.contains(RelativePositionFlag.Z);
this.target = vector;
}
boolean matches(Location location, Location location2) {
boolean flag;
label62: {
label65: {
if (this.relativeX) {
double x = location2.getX() - location.getX();
double x2 = this.target.getX();
double d = 0.1;
double d2 = x2;
double d3 = x;
if (MathUtilities.approximatelyEquals(d3, d2, d)) {
break label65;
}
}
if (!this.relativeX) {
double x3 = location2.getX();
double x4 = this.target.getX();
double d4 = MovementManager.getTpAcceptThreshold(this.movementManager);
double d5 = x4;
double d6 = x3;
if (MathUtilities.approximatelyEquals(d6, d5, d4)) {
break label65;
}
}
flag = false;
break label62;
}
flag = true;
}
boolean flag2;
label52: {
label66: {
flag2 = flag;
if (this.relativeY) {
double y = location2.getY() - location.getY();
double y2 = this.target.getY();
double d7 = 0.1;
double d8 = y2;
double d9 = y;
if (MathUtilities.approximatelyEquals(d9, d8, d7)) {
break label66;
}
}
if (!this.relativeY) {
double y3 = location2.getY();
double y4 = this.target.getY();
double d10 = MovementManager.getTpAcceptThreshold(this.movementManager);
double d11 = y4;
double d12 = y3;
if (MathUtilities.approximatelyEquals(d12, d11, d10)) {
break label66;
}
}
flag = false;
break label52;
}
flag = true;
}
boolean flag3;
label42: {
label67: {
flag3 = flag;
if (this.relativeZ) {
double z = location2.getZ() - location.getZ();
double z2 = this.target.getZ();
double d13 = 0.1;
double d14 = z2;
double d15 = z;
if (MathUtilities.approximatelyEquals(d15, d14, d13)) {
break label67;
}
}
if (!this.relativeZ) {
double z3 = location2.getZ();
double z4 = this.target.getZ();
double d16 = MovementManager.getTpAcceptThreshold(this.movementManager);
double d17 = z4;
double d18 = z3;
if (MathUtilities.approximatelyEquals(d18, d17, d16)) {
break label67;
}
}
flag = false;
break label42;
}
flag = true;
}
boolean flag4 = flag;
return flag2 && flag3 && flag4;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder()
.append(this.relativeX ? "dX" : "")
.append(this.relativeY ? "dY" : "")
.append(this.relativeZ ? "dZ" : "")
.append("[");
Vector vector = this.target;
Vector vector2 = vector;
return sb.append(MathUtilities.formatVector(vector2)).append("]").toString();
}
}
@@ -0,0 +1,198 @@
package me.konsolas.aac.checks.movement;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.AxisAlignedBoundingBox;
import me.konsolas.aac.util.BlockPositionView;
import me.konsolas.aac.compat.CollisionAccess;
import me.konsolas.aac.compat.CollisionQueryResult;
import me.konsolas.aac.compat.CollisionVectorAdjuster;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.util.EntityDimensions;
import me.konsolas.aac.util.GroundCollisionState;
import me.konsolas.aac.util.MathUtilities;
import me.konsolas.aac.compat.ServerVersion;
import me.konsolas.aac.api.HackType;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector;
public final class Phase
extends Detector
implements MovementCheckListener {
private final List excludedMaterials;
public Phase(AAC aAC) { super(aAC);
this.excludedMaterials = new ArrayList();
for (String str : this.plugin.getConfig().getStringList("phase.exclude")) {
this.excludedMaterials.add(Material.getMaterial((String)str));
}
Server server = Bukkit.getServer();
this.scheduledTaskIds.add(server.getScheduler().scheduleSyncRepeatingTask((Plugin)this.plugin, this::decayPhaseViolations, 69L, 13L));
}
@Override
public boolean shouldProcessMovement(PlayerMoveEvent playerMoveEvent) {
Player player;
return playerMoveEvent.getPlayer().getGameMode() != GameMode.SPECTATOR && playerMoveEvent.getPlayer().getGameMode() != GameMode.CREATIVE && !AAC.serverVersion.isElytraGliding(player = playerMoveEvent.getPlayer()) && playerMoveEvent.getPlayer().getVehicle() == null;
}
@Override
public void onMovement(PlayerMoveEvent playerMoveEvent, GroundCollisionState groundCollisionState, GroundCollisionState groundCollisionState2, BlockPositionView blockPositionView, BlockPositionView blockPositionView2, long ticks) {
AxisAlignedBoundingBox axisAlignedBoundingBox;
AxisAlignedBoundingBox axisAlignedBoundingBox2;
long ticks2 = ticks ^ 0x60FF4F6C294EL;
double d = playerMoveEvent.getTo().distance(playerMoveEvent.getFrom());
if (d > 10.0) {
Vector vector;
Vector vector2;
Object[] objectArray = new Object[3];
Vector vector3 = vector2 = playerMoveEvent.getFrom().toVector();
objectArray[0] = MathUtilities.formatVector(vector3);
Vector vector4 = vector = playerMoveEvent.getTo().toVector();
objectArray[1] = MathUtilities.formatVector(vector4);
objectArray[2] = d;
if (this.recordViolation(playerMoveEvent.getPlayer().getUniqueId(), 1, HackType.PHASE, String.format(Locale.UK, playerMoveEvent.getPlayer().getName() + " failed Phase: moved too far away from safe location %s -> %s (%.2f)", objectArray), ticks2)) {
boolean flag = false;
boolean flag2 = false;
double y = playerMoveEvent.getPlayer().getVelocity().getY();
PlayerMoveEvent playerMoveEvent2 = playerMoveEvent;
Player player = playerMoveEvent.getPlayer();
this.plugin.setbackManager.applySetback(player, playerMoveEvent2, y, flag2, flag);
}
}
if (AAC.serverVersion.getVersion() == ServerVersion.VER_1_8) {
Player player = playerMoveEvent.getPlayer();
axisAlignedBoundingBox2 = new AxisAlignedBoundingBox(playerMoveEvent.getFrom().toVector(), EntityDimensions.forEntity((Entity)player));
Player player2 = playerMoveEvent.getPlayer();
axisAlignedBoundingBox = new AxisAlignedBoundingBox(playerMoveEvent.getTo().toVector(), EntityDimensions.forEntity((Entity)player2));
} else {
Player player = playerMoveEvent.getPlayer();
axisAlignedBoundingBox2 = new AxisAlignedBoundingBox(playerMoveEvent.getFrom().toVector(), EntityDimensions.forEntity((Entity)player).expand(0.0, -0.2));
Player player3 = playerMoveEvent.getPlayer();
axisAlignedBoundingBox = new AxisAlignedBoundingBox(playerMoveEvent.getTo().toVector(), EntityDimensions.forEntity((Entity)player3).expand(0.0, -0.2));
}
if (axisAlignedBoundingBox2.intersects(axisAlignedBoundingBox) && !groundCollisionState.isCollided() && !groundCollisionState2.isCollided()) {
return;
}
AxisAlignedBoundingBox axisAlignedBoundingBox3 = axisAlignedBoundingBox2.union(axisAlignedBoundingBox);
Player player = playerMoveEvent.getPlayer();
if (CollisionAccess.getCollidingBoxes((Entity)player, axisAlignedBoundingBox3).size() == 0) {
return;
}
AxisAlignedBoundingBox axisAlignedBoundingBox4 = axisAlignedBoundingBox2;
Player player4 = playerMoveEvent.getPlayer();
List<AxisAlignedBoundingBox> list2 = CollisionAccess.getCollidingBoxes((Entity)player4, axisAlignedBoundingBox4);
AxisAlignedBoundingBox axisAlignedBoundingBox5 = axisAlignedBoundingBox;
Player player5 = playerMoveEvent.getPlayer();
List<AxisAlignedBoundingBox> list = CollisionAccess.getCollidingBoxes((Entity)player5, axisAlignedBoundingBox5);
if (!this.excludedMaterials.isEmpty()) {
list2.removeIf(arg_0 -> this.isExcludedFromBlock(playerMoveEvent, arg_0));
list.removeIf(arg_0 -> this.isExcludedToBlock(playerMoveEvent, arg_0));
}
if (list2.isEmpty() && !list.isEmpty()) {
AxisAlignedBoundingBox axisAlignedBoundingBox6 = list.get(0);
Block block = axisAlignedBoundingBox6.getMinimum().toLocation(playerMoveEvent.getPlayer().getWorld()).getBlock();
if (this.recordViolation(playerMoveEvent.getPlayer().getUniqueId(), 1, HackType.PHASE, String.format(Locale.UK, playerMoveEvent.getPlayer().getName() + " failed Phase: moved into a block (%s at %d,%d,%d)", block.getType().toString(), block.getLocation().getBlockX(), block.getLocation().getBlockY(), block.getLocation().getBlockZ()), ticks2)) {
boolean flag3 = false;
boolean flag4 = false;
double y2 = playerMoveEvent.getPlayer().getVelocity().getY();
PlayerMoveEvent playerMoveEvent3 = playerMoveEvent;
Player player6 = playerMoveEvent.getPlayer();
this.plugin.setbackManager.applySetback(player6, playerMoveEvent3, y2, flag4, flag3);
}
return;
}
if (!list2.isEmpty()) {
if ((d >= 1.0 || list.size() >= list2.size() && !list2.containsAll(list)) && this.recordViolation(playerMoveEvent.getPlayer().getUniqueId(), 1, HackType.PHASE, String.format(Locale.UK, playerMoveEvent.getPlayer().getName() + " failed Phase: moved inside blocks (%d,%d,%d to %d,%d,%d)", playerMoveEvent.getFrom().getBlockX(), playerMoveEvent.getFrom().getBlockY(), playerMoveEvent.getFrom().getBlockZ(), playerMoveEvent.getTo().getBlockX(), playerMoveEvent.getTo().getBlockY(), playerMoveEvent.getTo().getBlockZ()), ticks2)) {
boolean flag5 = false;
boolean flag6 = false;
double y3 = playerMoveEvent.getPlayer().getVelocity().getY();
PlayerMoveEvent playerMoveEvent4 = playerMoveEvent;
Player player7 = playerMoveEvent.getPlayer();
this.plugin.setbackManager.applySetback(player7, playerMoveEvent4, y3, flag6, flag5);
}
return;
}
if (axisAlignedBoundingBox2.intersects(axisAlignedBoundingBox)) {
if (!(list2.isEmpty() && list.isEmpty() || !this.recordViolation(playerMoveEvent.getPlayer().getUniqueId(), 1, HackType.PHASE, String.format(Locale.UK, playerMoveEvent.getPlayer().getName() + " failed Phase: moved through a block (%d,%d,%d to %d,%d,%d)", playerMoveEvent.getFrom().getBlockX(), playerMoveEvent.getFrom().getBlockY(), playerMoveEvent.getFrom().getBlockZ(), playerMoveEvent.getTo().getBlockX(), playerMoveEvent.getTo().getBlockY(), playerMoveEvent.getTo().getBlockZ()), ticks2))) {
boolean flag7 = false;
boolean flag8 = false;
double y4 = playerMoveEvent.getPlayer().getVelocity().getY();
PlayerMoveEvent playerMoveEvent5 = playerMoveEvent;
Player player8 = playerMoveEvent.getPlayer();
this.plugin.setbackManager.applySetback(player8, playerMoveEvent5, y4, flag8, flag7);
}
} else {
Vector vector;
Vector vector5 = playerMoveEvent.getTo().clone().subtract(playerMoveEvent.getFrom()).toVector();
Vector vector6 = vector = vector5.clone();
Location location = playerMoveEvent.getFrom();
Player player9 = playerMoveEvent.getPlayer();
CollisionQueryResult collisionQueryResult = CollisionVectorAdjuster.adjustVectorForCollisions((Entity)player9, location, vector6);
if (!vector.equals((Object)vector5)) {
if (collisionQueryResult.getAdjustment() < 0.6) {
Location location2 = playerMoveEvent.getFrom().clone().add(0.0, collisionQueryResult.getAdjustment() + 0.01, 0.0);
vector5 = playerMoveEvent.getTo().clone().subtract(location2).toVector();
Vector vector7 = vector = vector5.clone();
Location location3 = location2;
Player player10 = playerMoveEvent.getPlayer();
collisionQueryResult = CollisionVectorAdjuster.adjustVectorForCollisions((Entity)player10, location3, vector7);
if (!vector.equals((Object)vector5)) {
AxisAlignedBoundingBox axisAlignedBoundingBox7 = (AxisAlignedBoundingBox)collisionQueryResult.getCollisions().get(0);
Block block = axisAlignedBoundingBox7.getMinimum().toLocation(playerMoveEvent.getPlayer().getWorld()).getBlock();
if (this.recordViolation(playerMoveEvent.getPlayer().getUniqueId(), 1, HackType.PHASE, String.format(Locale.UK, playerMoveEvent.getPlayer().getName() + " failed Phase: stepped through a block (%s at %d,%d,%d)", block.getType().toString(), block.getLocation().getBlockX(), block.getLocation().getBlockY(), block.getLocation().getBlockZ()), ticks2)) {
boolean flag9 = false;
boolean flag10 = false;
double y5 = playerMoveEvent.getPlayer().getVelocity().getY();
PlayerMoveEvent playerMoveEvent6 = playerMoveEvent;
Player player11 = playerMoveEvent.getPlayer();
this.plugin.setbackManager.applySetback(player11, playerMoveEvent6, y5, flag10, flag9);
}
}
} else {
AxisAlignedBoundingBox axisAlignedBoundingBox8 = (AxisAlignedBoundingBox)collisionQueryResult.getCollisions().get(0);
Block block = axisAlignedBoundingBox8.getMinimum().toLocation(playerMoveEvent.getPlayer().getWorld()).getBlock();
if (this.recordViolation(playerMoveEvent.getPlayer().getUniqueId(), 1, HackType.PHASE, String.format(Locale.UK, playerMoveEvent.getPlayer().getName() + " failed Phase: moved through a block (%s at %d,%d,%d)", block.getType().toString(), block.getLocation().getBlockX(), block.getLocation().getBlockY(), block.getLocation().getBlockZ()), ticks2)) {
boolean flag11 = false;
boolean flag12 = false;
double y6 = playerMoveEvent.getPlayer().getVelocity().getY();
PlayerMoveEvent playerMoveEvent7 = playerMoveEvent;
Player player12 = playerMoveEvent.getPlayer();
this.plugin.setbackManager.applySetback(player12, playerMoveEvent7, y6, flag12, flag11);
}
}
}
}
}
private boolean isExcludedToBlock(PlayerMoveEvent playerMoveEvent, AxisAlignedBoundingBox axisAlignedBoundingBox) {
return this.excludedMaterials.contains(axisAlignedBoundingBox.getMinimum().toLocation(playerMoveEvent.getPlayer().getWorld()).getBlock().getType());
}
private boolean isExcludedFromBlock(PlayerMoveEvent playerMoveEvent, AxisAlignedBoundingBox axisAlignedBoundingBox) {
return this.excludedMaterials.contains(axisAlignedBoundingBox.getMinimum().toLocation(playerMoveEvent.getPlayer().getWorld()).getBlock().getType());
}
private void decayPhaseViolations() {
Server server = Bukkit.getServer();
Iterator iterator = server.getOnlinePlayers().iterator();
while (iterator.hasNext()) {
Player player = (Player)iterator.next();
this.decreaseViolationLevel(player.getUniqueId(), 1);
}
}
}
@@ -0,0 +1,163 @@
package me.konsolas.aac.checks.movement;
import java.util.HashMap;
import java.util.UUID;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import me.konsolas.aac.AAC;
import me.konsolas.aac.checks.CleanupHandler;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerAnimationType;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerVelocityEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.plugin.Plugin;
public class PlayerEventStateTracker
implements Listener,
CleanupHandler {
private final AAC plugin;
private final HashSet recentLandings = new HashSet();
private final HashSet recentTakeoffs = new HashSet();
private final Map lastArmSwingTimes = new HashMap();
private final Map lastRegenerationTimes = new HashMap();
private final Map lastRegenerationReasons = new HashMap();
private final Map lastInteractionTimes = new HashMap();
private final ConcurrentMap activeVelocities = new ConcurrentHashMap(32, 0.9f, 1);
private final ConcurrentMap lastVelocityTimes = new ConcurrentHashMap(32, 0.9f, 1);
private final Map<UUID, Location> previousLocations = new HashMap<>();
public PlayerEventStateTracker(AAC aAC) {
this.plugin = aAC;
}
public void updateMovementState(PlayerMoveEvent playerMoveEvent, boolean flag, boolean flag2) {
if (flag && !flag2) {
this.recentTakeoffs.add(playerMoveEvent.getPlayer().getUniqueId());
Server server = Bukkit.getServer();
server.getScheduler().scheduleSyncDelayedTask((Plugin)this.plugin, () -> this.clearTakeoffState(playerMoveEvent), 3L);
} else if (!flag && flag2) {
this.recentLandings.add(playerMoveEvent.getPlayer().getUniqueId());
Server server = Bukkit.getServer();
server.getScheduler().scheduleSyncDelayedTask((Plugin)this.plugin, () -> this.clearLadderState(playerMoveEvent), 3L);
}
if (this.activeVelocities.containsKey(playerMoveEvent.getPlayer().getUniqueId()) && System.currentTimeMillis() - this.getLastVelocityTime(playerMoveEvent.getPlayer()) > 90L) {
if (flag2 && flag) {
this.activeVelocities.remove(playerMoveEvent.getPlayer().getUniqueId());
} else if (playerMoveEvent.getPlayer().getVelocity().getY() == 0.0 && playerMoveEvent.getPlayer().getVelocity().getX() == 0.0 && playerMoveEvent.getPlayer().getVelocity().getZ() == 0.0) {
this.activeVelocities.remove(playerMoveEvent.getPlayer().getUniqueId());
}
}
this.previousLocations.put(playerMoveEvent.getPlayer().getUniqueId(), playerMoveEvent.getFrom());
}
@EventHandler
public void onPlayerVelocity(PlayerVelocityEvent playerVelocityEvent) {
if (this.plugin.setbackManager.getSetbackCheck(playerVelocityEvent.getPlayer()) == null) {
this.activeVelocities.put(playerVelocityEvent.getPlayer().getUniqueId(), playerVelocityEvent.getVelocity());
this.lastVelocityTimes.put(playerVelocityEvent.getPlayer().getUniqueId(), System.currentTimeMillis());
}
}
@EventHandler
public void onPlayerAnimation(PlayerAnimationEvent playerAnimationEvent) {
if (playerAnimationEvent.getAnimationType() == PlayerAnimationType.ARM_SWING) {
this.lastArmSwingTimes.put(playerAnimationEvent.getPlayer().getUniqueId(), System.currentTimeMillis());
}
}
@EventHandler(priority=EventPriority.MONITOR)
public void onEntityRegainHealth(EntityRegainHealthEvent entityRegainHealthEvent) {
if (entityRegainHealthEvent.getEntity().getType() == EntityType.PLAYER) {
this.lastRegenerationTimes.put(entityRegainHealthEvent.getEntity().getUniqueId(), System.currentTimeMillis());
this.lastRegenerationReasons.put(entityRegainHealthEvent.getEntity().getUniqueId(), entityRegainHealthEvent.getRegainReason());
}
}
@EventHandler(priority=EventPriority.MONITOR)
public void onPlayerInteract(PlayerInteractEvent playerInteractEvent) {
this.lastInteractionTimes.put(playerInteractEvent.getPlayer().getUniqueId(), System.currentTimeMillis());
}
@EventHandler(priority=EventPriority.MONITOR)
public void onWorldUnload(WorldUnloadEvent worldUnloadEvent) {
Set<UUID> hashSet = new HashSet<>();
for (Map.Entry<UUID, Location> entry : this.previousLocations.entrySet()) {
if (!((Location)entry.getValue()).getWorld().equals(worldUnloadEvent.getWorld())) continue;
hashSet.add(entry.getKey());
}
for (UUID uUID : hashSet) {
this.previousLocations.remove(uUID);
}
}
public synchronized boolean hasActiveVelocity(Player player) {
return this.activeVelocities.containsKey(player.getUniqueId());
}
public synchronized long getLastVelocityTime(Player player) {
return this.lastVelocityTimes.get(player.getUniqueId()) != null ? (Long)this.lastVelocityTimes.get(player.getUniqueId()) : 0L;
}
public long getLastArmSwingTime(Player player) {
try {
return (Long)this.lastArmSwingTimes.get(player.getUniqueId());
}
catch (NullPointerException nullPointerException) {
return 0L;
}
}
public long getLastRegenerationTime(Player player) {
try {
return (Long)this.lastRegenerationTimes.get(player.getUniqueId());
}
catch (NullPointerException nullPointerException) {
return 0L;
}
}
public EntityRegainHealthEvent.RegainReason getLastRegenerationReason(Player player) {
try {
return (EntityRegainHealthEvent.RegainReason)this.lastRegenerationReasons.get(player.getUniqueId());
}
catch (NullPointerException nullPointerException) {
return EntityRegainHealthEvent.RegainReason.CUSTOM;
}
}
public long getLastInteractionTime(Player player) {
try {
return (Long)this.lastInteractionTimes.get(player.getUniqueId());
}
catch (NullPointerException nullPointerException) {
return 0L;
}
}
@Override
public void cleanup() {
}
private void clearLadderState(PlayerMoveEvent playerMoveEvent) {
this.recentLandings.remove(playerMoveEvent.getPlayer().getUniqueId());
}
private void clearTakeoffState(PlayerMoveEvent playerMoveEvent) {
this.recentTakeoffs.remove(playerMoveEvent.getPlayer().getUniqueId());
}
}
@@ -0,0 +1,16 @@
package me.konsolas.aac.checks.movement;
public class ServerTeleportCallContext
extends SecurityManager {
public boolean isCalledFromBukkit() {
Class<?>[] classArray = this.getClassContext();
int value = classArray.length;
for (int i = 0; i < value; ++i) {
Class<?> clazz = classArray[i];
if (!(clazz.getName().startsWith("net.minecraft.server") ? clazz.getSimpleName().equals("EntityPlayer") || clazz.getSimpleName().equals("World") || clazz.getSimpleName().equals("LoginListener") || clazz.getSimpleName().equals("CommandTp") : clazz.getName().startsWith("org.bukkit.craftbukkit") && clazz.getSimpleName().equals("CraftPlayer"))) continue;
return false;
}
return true;
}
}
@@ -0,0 +1,172 @@
package me.konsolas.aac.checks.movement;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.AxisAlignedBoundingBox;
import me.konsolas.aac.util.BlockPositionView;
import me.konsolas.aac.compat.CollisionAccess;
import me.konsolas.aac.compat.CollisionVectorAdjuster;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.util.GroundCollisionState;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import org.bukkit.event.world.WorldUnloadEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector;
public class SetbackManager
implements Listener,
MovementCheckListener {
private final Map<Player, Location> safeLocations = Collections.synchronizedMap(new WeakHashMap<>());
private final Map<Player, Detector> setbackChecks = Collections.synchronizedMap(new WeakHashMap<>());
private final AAC plugin;
public SetbackManager(AAC aAC) {
this.plugin = aAC;
}
public void setSetbackCheck(Detector detector, Player player) {
this.setbackChecks.put(player, detector);
}
public void clearSetbackCheck(Player player) {
this.setbackChecks.remove(player);
}
@EventHandler(priority=EventPriority.HIGHEST)
public void onPlayerTeleport(PlayerTeleportEvent playerTeleportEvent) {
if (this.setbackChecks.containsKey(playerTeleportEvent.getPlayer()) && playerTeleportEvent.getCause() == PlayerTeleportEvent.TeleportCause.UNKNOWN) {
if (this.setbackChecks.get(playerTeleportEvent.getPlayer()) instanceof Speed || this.setbackChecks.get(playerTeleportEvent.getPlayer()) instanceof Fly) {
this.safeLocations.remove(playerTeleportEvent.getPlayer());
}
} else {
if (playerTeleportEvent.getTo().equals((Object)playerTeleportEvent.getFrom()) && playerTeleportEvent.getCause() == PlayerTeleportEvent.TeleportCause.UNKNOWN) {
return;
}
this.safeLocations.put(playerTeleportEvent.getPlayer(), playerTeleportEvent.getTo().clone());
}
}
@EventHandler(priority=EventPriority.MONITOR)
public void onPlayerRespawn(PlayerRespawnEvent playerRespawnEvent) {
this.safeLocations.remove(playerRespawnEvent.getPlayer());
}
@EventHandler(priority=EventPriority.MONITOR)
public void resetSafeLocationOnWorldChange(PlayerChangedWorldEvent playerChangedWorldEvent) {
this.safeLocations.remove(playerChangedWorldEvent.getPlayer());
}
@EventHandler
public void onPlayerToggleFlight(PlayerToggleFlightEvent playerToggleFlightEvent) {
Bukkit.getScheduler().scheduleSyncDelayedTask((Plugin)this.plugin, () -> this.updateSafeLocationDelayed(playerToggleFlightEvent), 40L);
}
public Detector getSetbackCheck(Player player) {
return (Detector)this.setbackChecks.get(player);
}
private void recordSafeLocation(PlayerMoveEvent playerMoveEvent, BlockPositionView blockPositionView) {
if (CollisionVectorAdjuster.isClearColumn(blockPositionView)) {
if (this.safeLocations.containsKey(playerMoveEvent.getPlayer())) {
if (playerMoveEvent.getFrom().getWorld() != ((Location)this.safeLocations.get(playerMoveEvent.getPlayer())).getWorld() || playerMoveEvent.getFrom().distanceSquared((Location)this.safeLocations.get(playerMoveEvent.getPlayer())) > 3.0 || playerMoveEvent.getFrom().getY() - ((Location)this.safeLocations.get(playerMoveEvent.getPlayer())).getY() > 0.2) {
this.safeLocations.put(playerMoveEvent.getPlayer(), playerMoveEvent.getFrom().clone());
} else if (CollisionVectorAdjuster.isPassableColumn(blockPositionView)) {
this.safeLocations.put(playerMoveEvent.getPlayer(), playerMoveEvent.getFrom().clone());
}
} else {
this.safeLocations.put(playerMoveEvent.getPlayer(), playerMoveEvent.getFrom().clone());
}
}
}
@Override
public void onMovement(PlayerMoveEvent playerMoveEvent, GroundCollisionState groundCollisionState, GroundCollisionState groundCollisionState2, BlockPositionView blockPositionView, BlockPositionView blockPositionView2, long ticks) {
if (groundCollisionState.isOnGround() && groundCollisionState2.isOnGround()) {
this.recordSafeLocation(playerMoveEvent, blockPositionView);
}
}
@Override
public boolean shouldProcessMovement(PlayerMoveEvent playerMoveEvent) {
if (playerMoveEvent.getPlayer().isFlying()) {
this.safeLocations.put(playerMoveEvent.getPlayer(), playerMoveEvent.getPlayer().getLocation());
}
return true;
}
@EventHandler
public void onWorldUnload(WorldUnloadEvent worldUnloadEvent) {
this.safeLocations.values().removeIf(arg_0 -> SetbackManager.matchesWorld(worldUnloadEvent, arg_0));
}
@EventHandler
public void resetChecksOnWorldChange(PlayerChangedWorldEvent playerChangedWorldEvent) {
this.safeLocations.remove(playerChangedWorldEvent.getPlayer());
this.setbackChecks.remove(playerChangedWorldEvent.getPlayer());
}
public void applySetback(Player player, PlayerMoveEvent playerMoveEvent, double d, boolean flag, boolean flag2) {
Location location;
double d2;
Location location2;
if (d > -0.1) {
d = -0.1;
}
if ((location2 = this.safeLocations.getOrDefault(player, playerMoveEvent.getFrom())) != null && flag && location2.getWorld().equals(player.getWorld())) {
double x = Math.abs(playerMoveEvent.getFrom().getX() - location2.getX());
double z = Math.abs(playerMoveEvent.getFrom().getZ() - location2.getZ());
d2 = Math.sqrt(Math.pow(x, 2.0) + Math.pow(z, 2.0));
if (d2 < 3.0 && playerMoveEvent.getFrom().getY() > location2.getY()) {
playerMoveEvent.setTo(location2);
return;
}
}
Location location3 = playerMoveEvent.getFrom();
AxisAlignedBoundingBox axisAlignedBoundingBox = new AxisAlignedBoundingBox(location3.toVector(), 0.6, 1.65);
Player player2 = player;
AxisAlignedBoundingBox axisAlignedBoundingBox2 = axisAlignedBoundingBox = axisAlignedBoundingBox.expandTowards(new Vector(0.0, d, 0.0));
List<AxisAlignedBoundingBox> list = CollisionAccess.getCollidingBoxes((Entity)player2, axisAlignedBoundingBox2);
if (list.isEmpty()) {
location = location3.clone().add(0.0, d, 0.0);
} else {
d2 = axisAlignedBoundingBox.getMinimum().getY();
for (AxisAlignedBoundingBox axisAlignedBoundingBox3 : list) {
if (!(axisAlignedBoundingBox3.getMaximum().getY() > d2) || !(axisAlignedBoundingBox3.getMaximum().getY() <= location3.getY() + 0.6)) continue;
d2 = axisAlignedBoundingBox3.getMaximum().getY();
}
if (d2 == axisAlignedBoundingBox.getMinimum().getY()) {
location = location3;
} else {
location = location3;
location.setY(d2);
}
}
if (flag2) {
location.setPitch(0.0f);
}
playerMoveEvent.setTo(location);
}
private static boolean matchesWorld(WorldUnloadEvent worldUnloadEvent, Location location) {
return location.getWorld().equals(worldUnloadEvent.getWorld());
}
private void updateSafeLocationDelayed(PlayerToggleFlightEvent playerToggleFlightEvent) {
this.safeLocations.put(playerToggleFlightEvent.getPlayer(), playerToggleFlightEvent.getPlayer().getLocation());
}
}
@@ -0,0 +1,523 @@
package me.konsolas.aac.checks.movement;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketListener;
import java.util.Collections;
import java.util.Iterator;
import java.util.Locale;
import java.util.Set;
import java.util.UUID;
import java.util.WeakHashMap;
import java.util.concurrent.TimeUnit;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.BlockPositionView;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.compat.EnvironmentBlockChecks;
import net.jodah.expiringmap.ExpirationPolicy;
import net.jodah.expiringmap.ExpiringMap;
import me.konsolas.aac.util.GroundCollisionState;
import me.konsolas.aac.util.HorizontalVector;
import me.konsolas.aac.compat.ItemUseAccess;
import me.konsolas.aac.util.MathUtilities;
import me.konsolas.aac.api.HackType;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.util.Vector;
public final class Speed
extends Detector
implements MovementCheckListener {
private final WeakHashMap sneakToggleCounts;
private final WeakHashMap itemUseToggleCounts;
private final ExpiringMap<Player, HorizontalVector> velocityBoosts;
private final WeakHashMap lastMoveVectors;
private final WeakHashMap lastAllowedSpeeds;
private final Set airbornePlayers;
private final WeakHashMap offGroundTicks;
private final ExpiringMap<Player, Boolean> cobwebBoostUsed;
private final ExpiringMap<Player, Boolean> iceBoostPlayers;
private final ExpiringMap<UUID, Integer> vlDecayCooldowns;
private final ExpiringMap<Player, Integer> cachedSpeedLevels;
private final ExpiringMap<Player, Boolean> itemUseGracePlayers;
private int maxSneakToggles;
private int maxUseToggles;
private int velTicks;
private double threshold;
private double vlMultiplier;
private int minVl;
private int reduceDelay;
private double itemScalar;
private double sneakScalar;
private double soulSandScalar;
private boolean checkSprintDirection;
private boolean checkSlownessEffect;
private boolean checkCobwebs;
private boolean strictVelocityChecking;
public Speed(AAC aAC) { super(aAC);
this.sneakToggleCounts = new WeakHashMap();
this.itemUseToggleCounts = new WeakHashMap();
this.lastMoveVectors = new WeakHashMap();
this.lastAllowedSpeeds = new WeakHashMap();
this.airbornePlayers = Collections.newSetFromMap(new WeakHashMap());
this.offGroundTicks = new WeakHashMap();
this.maxSneakToggles = 15;
this.maxUseToggles = 35;
this.velTicks = 12;
this.threshold = 0.01;
this.vlMultiplier = 5.0;
this.minVl = 20;
this.reduceDelay = 20;
this.itemScalar = 0.5;
this.sneakScalar = 0.63;
this.soulSandScalar = 0.7;
this.checkSprintDirection = true;
this.checkSlownessEffect = true;
this.checkCobwebs = true;
this.strictVelocityChecking = true;
this.maxSneakToggles = this.plugin.getConfig().getInt("speed.max_sneak_toggles", this.maxSneakToggles);
this.maxUseToggles = this.plugin.getConfig().getInt("speed.max_use_toggles", this.maxUseToggles);
this.velTicks = this.plugin.getConfig().getInt("speed.vel_ticks", this.velTicks);
this.threshold = this.plugin.getConfig().getDouble("speed.threshold", this.threshold);
this.vlMultiplier = this.plugin.getConfig().getDouble("speed.vl_multiplier", this.vlMultiplier);
this.minVl = this.plugin.getConfig().getInt("speed.min_vl", this.minVl);
this.reduceDelay = this.plugin.getConfig().getInt("speed.reduce_delay", this.reduceDelay);
this.itemScalar = this.plugin.getConfig().getDouble("speed.item_scalar", this.itemScalar);
this.sneakScalar = this.plugin.getConfig().getDouble("speed.sneak_scalar", this.sneakScalar);
this.soulSandScalar = this.plugin.getConfig().getDouble("speed.soul_sand_scalar", this.soulSandScalar);
this.checkSprintDirection = this.plugin.getConfig().getBoolean("speed.check_sprint_direction", this.checkSprintDirection);
this.checkSlownessEffect = this.plugin.getConfig().getBoolean("speed.check_slowness_effect", this.checkSlownessEffect);
this.checkCobwebs = this.plugin.getConfig().getBoolean("speed.check_cobwebs", this.checkCobwebs);
this.strictVelocityChecking = this.plugin.getConfig().getBoolean("speed.strict_velocity_checking", this.strictVelocityChecking);
ExpirationPolicy expirationPolicy = ExpirationPolicy.CREATED;
TimeUnit timeUnit = TimeUnit.MILLISECONDS;
long ticks = 200L;
this.cobwebBoostUsed = ExpiringMap.builder().expirationPolicy(expirationPolicy).expiration(ticks, timeUnit).build();
ExpirationPolicy expirationPolicy2 = ExpirationPolicy.CREATED;
TimeUnit timeUnit2 = TimeUnit.MILLISECONDS;
long ticks2 = this.reduceDelay * 50;
this.vlDecayCooldowns = ExpiringMap.builder().expirationPolicy(expirationPolicy2).expiration(ticks2, timeUnit2).build();
ExpirationPolicy expirationPolicy3 = ExpirationPolicy.CREATED;
TimeUnit timeUnit3 = TimeUnit.MILLISECONDS;
long ticks3 = 100L;
this.iceBoostPlayers = ExpiringMap.builder().expirationPolicy(expirationPolicy3).expiration(ticks3, timeUnit3).build();
ExpirationPolicy expirationPolicy4 = ExpirationPolicy.CREATED;
TimeUnit timeUnit4 = TimeUnit.MILLISECONDS;
long ticks4 = 100L;
this.cachedSpeedLevels = ExpiringMap.builder().expirationPolicy(expirationPolicy4).expiration(ticks4, timeUnit4).build();
ExpirationPolicy expirationPolicy5 = ExpirationPolicy.CREATED;
TimeUnit timeUnit5 = TimeUnit.MILLISECONDS;
long ticks5 = 200L;
this.itemUseGracePlayers = ExpiringMap.builder().expirationPolicy(expirationPolicy5).expiration(ticks5, timeUnit5).build();
Server server = Bukkit.getServer();
this.scheduledTaskIds.add(server.getScheduler().scheduleSyncRepeatingTask((Plugin)this.plugin, this::decaySpeedViolations, 20L, 53L));
Server server2 = Bukkit.getServer();
this.scheduledTaskIds.add(server2.getScheduler().scheduleSyncRepeatingTask((Plugin)this.plugin, this::resetToggleCounters, 6L, 20L));
PacketAdapter packetAdapter = new SpeedItemUsePacketListener(this, (Plugin)this.plugin, new PacketType[]{PacketType.Play.Client.BLOCK_PLACE, PacketType.Play.Client.BLOCK_DIG});
this.packetListeners.add(packetAdapter);
ProtocolLibrary.getProtocolManager().addPacketListener((PacketListener)packetAdapter);
TimeUnit timeUnit6 = TimeUnit.MILLISECONDS;
long ticks6 = this.velTicks * 50;
ExpirationPolicy expirationPolicy6 = ExpirationPolicy.CREATED;
this.velocityBoosts = ExpiringMap.builder().expiration(ticks6, timeUnit6).expirationPolicy(expirationPolicy6).build();
packetAdapter = new SpeedVelocityPacketListener(this, (Plugin)this.plugin, new PacketType[]{PacketType.Play.Server.ENTITY_VELOCITY});
this.packetListeners.add(packetAdapter);
ProtocolLibrary.getProtocolManager().addPacketListener((PacketListener)packetAdapter);
}
@EventHandler
public void onPlayerFish(PlayerFishEvent playerFishEvent) {
if (playerFishEvent.getCaught() instanceof Player && !playerFishEvent.getPlayer().equals(playerFishEvent.getCaught())) {
Player player = (Player)playerFishEvent.getCaught();
this.velocityBoosts.put(player, HorizontalVector.ONE);
}
}
@EventHandler
public void onPlayerToggleSneak(PlayerToggleSneakEvent playerToggleSneakEvent) {
long ticks = 113218805911140L;
Player player = playerToggleSneakEvent.getPlayer();
if (this.plugin.checkManager.isPlayerExempt(player)) {
return;
}
if (!this.sneakToggleCounts.containsKey(playerToggleSneakEvent.getPlayer())) {
this.sneakToggleCounts.put(playerToggleSneakEvent.getPlayer(), 1);
} else {
this.sneakToggleCounts.put(playerToggleSneakEvent.getPlayer(), (Integer)this.sneakToggleCounts.get(playerToggleSneakEvent.getPlayer()) + 1);
if ((Integer)this.sneakToggleCounts.get(playerToggleSneakEvent.getPlayer()) > this.maxSneakToggles) {
this.recordViolation(playerToggleSneakEvent.getPlayer().getUniqueId(), 50, HackType.SPEED, playerToggleSneakEvent.getPlayer().getName() + " failed Speed: tried to toggle sneak too quickly (" + this.sneakToggleCounts.get(playerToggleSneakEvent.getPlayer()) + " toggles/second)", ticks);
return;
}
}
if (this.plugin.logManager.isDebugEnabled()) {
this.plugin.logManager.logPlayerDebug(playerToggleSneakEvent.getPlayer(), "(Speed) PlayerToggleSneakEvent sneaks[m:" + this.maxSneakToggles + ",r:" + this.sneakToggleCounts.get(playerToggleSneakEvent.getPlayer()) + "]");
}
}
@Override
public boolean shouldProcessMovement(PlayerMoveEvent playerMoveEvent) {
if (playerMoveEvent.getPlayer().isDead() || playerMoveEvent.getPlayer().isFlying() || playerMoveEvent.getPlayer().getGameMode().equals((Object)GameMode.SPECTATOR) || playerMoveEvent.getPlayer().getAllowFlight()) {
this.lastMoveVectors.put(playerMoveEvent.getPlayer(), new HorizontalVector(Math.abs(playerMoveEvent.getTo().getX() - playerMoveEvent.getFrom().getX()) * 1.2, Math.abs(playerMoveEvent.getTo().getZ() - playerMoveEvent.getFrom().getZ()) * 1.2));
return false;
}
if (playerMoveEvent.getPlayer().getVehicle() != null) {
this.lastMoveVectors.remove(playerMoveEvent.getPlayer());
return false;
}
return true;
}
@Override
public void onMovement(PlayerMoveEvent playerMoveEvent, GroundCollisionState groundCollisionState, GroundCollisionState groundCollisionState2, BlockPositionView blockPositionView, BlockPositionView blockPositionView2, long ticks) {
int i;
HorizontalVector horizontalVector;
long ticks2 = ticks ^ 0x60FF4F6C294EL;
double x = playerMoveEvent.getTo().getX() - playerMoveEvent.getFrom().getX();
double z = playerMoveEvent.getTo().getZ() - playerMoveEvent.getFrom().getZ();
if (Math.abs(x) + Math.abs(z) < 0.001) {
return;
}
HorizontalVector horizontalVector2 = new HorizontalVector(Math.abs(x), Math.abs(z));
Player player = playerMoveEvent.getPlayer();
if (AAC.serverVersion.isElytraGliding(player)) {
this.lastMoveVectors.put(playerMoveEvent.getPlayer(), horizontalVector2.multiply(2.0));
this.iceBoostPlayers.put(playerMoveEvent.getPlayer(), false);
return;
}
int value = -1;
int value2 = -1;
int value3 = -1;
if (playerMoveEvent.getPlayer().hasPotionEffect(PotionEffectType.SPEED) || playerMoveEvent.getPlayer().hasPotionEffect(PotionEffectType.SLOW)) {
for (PotionEffect potionEffect : playerMoveEvent.getPlayer().getActivePotionEffects()) {
if (potionEffect.getType().equals((Object)PotionEffectType.SPEED)) {
value = potionEffect.getAmplifier();
continue;
}
if (potionEffect.getType().equals((Object)PotionEffectType.SLOW)) {
value2 = potionEffect.getAmplifier();
continue;
}
if (!potionEffect.getType().equals((Object)PotionEffectType.JUMP)) continue;
value3 = potionEffect.getAmplifier();
}
}
if (groundCollisionState.isCollided()) {
groundCollisionState = groundCollisionState.isAirStep() ? GroundCollisionState.TRUE_AIRSTEP_COLLIDED : GroundCollisionState.TRUE_NORMAL_COLLIDED;
}
double d = playerMoveEvent.getPlayer().getWalkSpeed();
Block block = playerMoveEvent.getPlayer().getLocation().getBlock();
boolean flag = blockPositionView.getMaterialAtNegOffset(0.0, 0.1, 0.0) == Material.PACKED_ICE || blockPositionView.getMaterialAtNegOffset(0.0, 0.1, 0.0) == Material.ICE || blockPositionView.getMaterialAtNegOffset(0.0, 0.9, 0.0) == Material.PACKED_ICE || blockPositionView.getMaterialAtNegOffset(0.0, 0.9, 0.0) == Material.ICE;
boolean flag2 = EnvironmentBlockChecks.isNearSlabOrStair(blockPositionView2);
double y = playerMoveEvent.getTo().getY() - playerMoveEvent.getFrom().getY();
HorizontalVector horizontalVector3 = new HorizontalVector(d, d);
Player player2 = playerMoveEvent.getPlayer();
if (!this.lastMoveVectors.containsKey(player2)) {
this.lastMoveVectors.put(player2, horizontalVector2);
return;
}
HorizontalVector horizontalVector4 = (HorizontalVector)this.lastMoveVectors.get(player2);
int value4 = 4;
if (this.checkCobwebs && EnvironmentBlockChecks.isInCobweb(blockPositionView)) {
horizontalVector = HorizontalVector.BASE_AIR;
double y2 = Math.abs(playerMoveEvent.getTo().getY() - playerMoveEvent.getFrom().getY());
double d2 = 0.05;
if (blockPositionView.getMaterialAtNegOffset(0.0, 0.1, 0.0) != Material.WEB) {
d2 = 0.15;
if (!this.cobwebBoostUsed.containsKey(player2) && horizontalVector2.getLength() > horizontalVector.getLength()) {
horizontalVector = horizontalVector.multiply(3.0);
this.cobwebBoostUsed.put(player2, false);
}
}
if (!flag2 && (y2 < -d2 || y2 > d2)) {
int value5 = 100;
long ticks3 = (int)(Math.abs(horizontalVector2.getLength() - horizontalVector.getLength()) * this.vlMultiplier + 20.0);
int value6 = MathUtilities.clampToInt(ticks3, value5);
if (this.recordViolation(player2.getUniqueId(), value6, HackType.SPEED, String.format(Locale.UK, playerMoveEvent.getPlayer().getName() + " failed Speed: (WEB/VERTICAL) moved too quickly: %.3f blocks/tick (%.3f)", y2, 0.05), ticks2) && (this.getViolationLevel(playerMoveEvent.getPlayer()) > this.minVl || value6 > this.minVl)) {
playerMoveEvent.setTo(playerMoveEvent.getFrom());
}
return;
}
} else if (EnvironmentBlockChecks.isInLiquid(blockPositionView)) {
int value7 = playerMoveEvent.getPlayer().getInventory().getBoots() != null ? playerMoveEvent.getPlayer().getInventory().getBoots().getEnchantmentLevel(Enchantment.DEPTH_STRIDER) : 0;
boolean blToWater = EnvironmentBlockChecks.isInLiquid(blockPositionView2);
boolean flag3 = EnvironmentBlockChecks.isNotSurroundedByLiquid(blockPositionView2);
boolean flag4 = EnvironmentBlockChecks.isNotSurroundedByLiquid(blockPositionView.offset(0.0, 0.5, 0.0));
boolean flag5 = EnvironmentBlockChecks.isNotSurroundedByLiquid(blockPositionView2.offset(0.0, 0.5, 0.0));
this.airbornePlayers.remove(player2);
double d3 = 0.92;
double d4 = 0.02;
double d5 = value7;
d5 *= 1.1;
if (d5 > 3.0) {
d5 = 3.0;
}
if (!groundCollisionState.isOnGround()) {
d5 *= 0.6;
}
if (d5 > 0.0) {
d4 += 0.08 * d5 / 3.0;
}
if (!blToWater) {
d3 = 1.1;
}
horizontalVector = horizontalVector4.multiply(d3).maxLength((HorizontalVector)this.velocityBoosts.get(player2)).increaseLength(d4);
if (EnvironmentBlockChecks.isInFlowingLiquid(blockPositionView)) {
horizontalVector = horizontalVector.increaseLength(0.1);
}
if (flag3) {
horizontalVector = horizontalVector.increaseLength(0.25);
}
if (flag4 && !flag5) {
horizontalVector = horizontalVector.increaseLength(0.025);
}
horizontalVector = horizontalVector.maxLength(new HorizontalVector(0.05, 0.05)).increaseLength((double)value7 * 0.01);
if (value != -1) {
horizontalVector = horizontalVector.applySpeedEffect(value);
this.cachedSpeedLevels.put(player2, value);
this.cachedSpeedLevels.resetExpiration(player2);
} else if (this.cachedSpeedLevels.containsKey(player2)) {
horizontalVector = horizontalVector.applySpeedEffect((Integer)this.cachedSpeedLevels.get(player2));
}
} else if (groundCollisionState.isOnGround()) {
boolean flag6 = EnvironmentBlockChecks.isStandingOnSoulSand(blockPositionView);
boolean blOnIceOrSlab = EnvironmentBlockChecks.isNearSnowColumn(blockPositionView);
boolean flag7 = EnvironmentBlockChecks.isInSnow(blockPositionView);
Player player4 = playerMoveEvent.getPlayer();
boolean flag8 = ItemUseAccess.isUsingItem(player4);
boolean flag9 = playerMoveEvent.getPlayer().isSneaking();
horizontalVector = horizontalVector3;
horizontalVector = horizontalVector.increaseLength(0.01);
if (value != -1) {
horizontalVector = horizontalVector.applySpeedEffect(value);
this.cachedSpeedLevels.put(player2, value);
this.cachedSpeedLevels.resetExpiration(player2);
} else {
Integer intVal = (Integer)this.cachedSpeedLevels.get(player2);
if (intVal != null) {
horizontalVector = horizontalVector.applySpeedEffect(intVal);
}
}
if (this.checkSlownessEffect && value2 != -1) {
horizontalVector = horizontalVector.applySlownessEffect(value2).maxLength(new HorizontalVector(0.05, 0.05));
}
horizontalVector = horizontalVector.clampNonNegative();
if (flag8) {
horizontalVector = horizontalVector.multiply(this.itemScalar);
if (horizontalVector2.getLength() > horizontalVector.getLength() && horizontalVector2.getLength() < d && !this.itemUseGracePlayers.containsKey(player2)) {
horizontalVector = horizontalVector2;
this.itemUseGracePlayers.put(player2, false);
}
} else if (flag9) {
horizontalVector = horizontalVector.multiply(this.sneakScalar);
} else if (flag6) {
horizontalVector = horizontalVector.multiply(this.soulSandScalar);
}
boolean flag10 = false;
if (this.checkSprintDirection) {
double d6;
double d7;
Location location = playerMoveEvent.getPlayer().getLocation();
location.setDirection(new Vector(x, 0.0, z).normalize());
double yaw = d7 = (double)location.getYaw();
double d8 = MathUtilities.wrapDegrees(yaw);
double yaw2 = d6 = d8 - (double)playerMoveEvent.getPlayer().getLocation().getYaw();
if (Math.abs(MathUtilities.wrapDegrees(yaw2)) >= 65.0) {
flag10 = true;
}
}
if (flag10 || playerMoveEvent.getPlayer().getFoodLevel() <= 6 || playerMoveEvent.getPlayer().hasPotionEffect(PotionEffectType.BLINDNESS)) {
horizontalVector = horizontalVector.applySlowMovement();
}
if (flag) {
this.iceBoostPlayers.put(player2, false);
this.iceBoostPlayers.resetExpiration(player2);
} else if (this.iceBoostPlayers.containsKey(player2) && horizontalVector.getLength() < 0.6) {
horizontalVector = horizontalVector.applyJumpMovementModifiers(value, value2, playerMoveEvent.getPlayer().getWalkSpeed());
}
if (groundCollisionState2.isOnGround()) {
if (flag) {
if (horizontalVector4.getLength() > horizontalVector.getLength()) {
horizontalVector = horizontalVector4;
}
} else if (horizontalVector4.decayGroundFriction().getLength() > horizontalVector.getLength()) {
horizontalVector = horizontalVector4.decayGroundFriction();
}
} else if (horizontalVector4.decayAirFriction().getLength() > horizontalVector.getLength()) {
horizontalVector = horizontalVector4.decayAirFriction();
}
if (!flag9 && !flag8 && !flag && this.airbornePlayers.contains(player2) && y >= 0.0) {
horizontalVector = horizontalVector.maxLength(horizontalVector4).clampMinWalkSpeed().applyJumpMovementModifiers(value, value2, d);
this.airbornePlayers.remove(player2);
}
if (!(groundCollisionState2.isOnGround() || flag8 || flag9)) {
if (this.plugin.logManager.isDebugEnabled()) {
this.plugin.logManager.logPlayerDebug(playerMoveEvent.getPlayer(), "(Speed) takeoff [dy r:" + y + "]");
}
if (!groundCollisionState.isAirStep() && !groundCollisionState2.isAirStep()) {
value4 += 20;
}
horizontalVector = horizontalVector.addJumpBoost();
if (groundCollisionState2.isAirStep()) {
horizontalVector = horizontalVector.applyJumpMovementModifiers(value, value2, d);
}
if (flag) {
horizontalVector = horizontalVector.maxLength(new HorizontalVector(0.42));
}
if (!(flag || blOnIceOrSlab || groundCollisionState2.isAirStep() || groundCollisionState.isAirStep())) {
this.offGroundTicks.put(player2, 0);
}
} else if (value3 != -1 && (value3 < 0 || value3 > 127 && value3 < 253)) {
horizontalVector = horizontalVector.addJumpBoost();
} else if (groundCollisionState2.isOnGround() && (groundCollisionState.isAirStep() || groundCollisionState2.isAirStep()) || flag7 || flag2 && y > 0.105) {
if (groundCollisionState2.isAirStep()) {
horizontalVector = horizontalVector.addJumpBoost();
}
if (groundCollisionState.isAirStep()) {
this.airbornePlayers.add(player2);
}
}
if (this.velocityBoosts.containsKey(player2)) {
if (this.strictVelocityChecking) {
if (horizontalVector2.getLength() > horizontalVector.getLength() + this.threshold && horizontalVector.getLength() < this.velocityBoosts.getOrDefault(player2, horizontalVector).addLength(horizontalVector).getLength()) {
horizontalVector = this.velocityBoosts.getOrDefault(player2, horizontalVector).addJumpBoost().addLength(horizontalVector);
this.velocityBoosts.remove(player2);
this.offGroundTicks.remove(player2);
}
} else if (horizontalVector2.getLength() > horizontalVector.getLength() + this.threshold) {
horizontalVector = ((HorizontalVector)this.velocityBoosts.get(player2)).addJumpBoost().addLength(horizontalVector).boostSprint().maxLength(horizontalVector);
this.offGroundTicks.remove(player2);
}
}
if ((block.getType() == Material.PISTON_BASE || block.getType() == Material.PISTON_STICKY_BASE || block.getType() == Material.PISTON_MOVING_PIECE || block.getType() == Material.PISTON_EXTENSION) && horizontalVector.getLength() < HorizontalVector.ONE.getLength()) {
horizontalVector = HorizontalVector.ONE;
}
} else {
boolean flag11 = EnvironmentBlockChecks.isNearStairs(blockPositionView2);
if (!(groundCollisionState2.isOnGround() || groundCollisionState.isOnGround() || groundCollisionState2.isAirStep() || groundCollisionState.isAirStep())) {
value4 += 10;
}
if (this.offGroundTicks.containsKey(player2)) {
this.offGroundTicks.put(player2, (Integer)this.offGroundTicks.get(playerMoveEvent.getPlayer()) + 1);
if ((Integer)this.offGroundTicks.get(player2) == 1) {
horizontalVector = !flag && !flag2 && horizontalVector4.getLength() > horizontalVector3.getLength() + this.threshold ? horizontalVector4.applyAirDrag().clampMinWalkSpeed() : horizontalVector4.decayAirFriction().clampMinWalkSpeed();
this.offGroundTicks.remove(player2);
} else {
horizontalVector = (HorizontalVector)this.lastAllowedSpeeds.get(player2);
}
} else {
horizontalVector = horizontalVector4.decayAirFriction().clampMinWalkSpeed();
}
if (this.velocityBoosts.containsKey(player2)) {
if (this.strictVelocityChecking) {
if (horizontalVector2.getLength() > horizontalVector.getLength() + this.threshold && horizontalVector.getLength() < this.velocityBoosts.getOrDefault(player2, horizontalVector).addLength(horizontalVector).getLength()) {
horizontalVector = this.velocityBoosts.getOrDefault(player2, horizontalVector).addLength(horizontalVector);
this.velocityBoosts.remove(player2);
}
} else if (horizontalVector2.getLength() > horizontalVector.getLength() + this.threshold) {
horizontalVector = ((HorizontalVector)this.velocityBoosts.get(player2)).addLength(horizontalVector).boostSprint().maxLength(horizontalVector);
}
}
if (flag11) {
if (horizontalVector.getLength() < horizontalVector3.getLength()) {
horizontalVector = horizontalVector3;
}
horizontalVector.addJumpBoost().clampMinWalkSpeed();
}
this.airbornePlayers.add(playerMoveEvent.getPlayer());
}
if (value2 > 1) {
horizontalVector = horizontalVector.increaseLength(0.01);
}
if (groundCollisionState.isOnGround() && groundCollisionState2.isOnGround() && !groundCollisionState.isAirStep() && !groundCollisionState2.isAirStep() && !flag2) {
value4 += 10;
}
HorizontalVector horizontalVector5 = EntityPushCalculator.calculatePush(playerMoveEvent.getPlayer());
horizontalVector = horizontalVector.increaseLength(horizontalVector5.getLength());
this.lastAllowedSpeeds.put(player2, horizontalVector);
if (this.plugin.logManager.isDebugEnabled()) {
double d9;
double d10;
double d11;
double d12 = d11 = y;
double d13 = d10 = horizontalVector2.getLength();
double d14 = d9 = horizontalVector.getLength();
this.plugin.logManager.logPlayerDebug(playerMoveEvent.getPlayer(), "(Speed) fullmove [dy r:" + MathUtilities.formatNumber(d12) + " dxz r: " + MathUtilities.formatNumber(d13) + " l:" + MathUtilities.formatNumber(d14) + " g " + (Object)((Object)groundCollisionState) + (Object)((Object)groundCollisionState2) + "]");
}
if (horizontalVector.getLength() + this.threshold < horizontalVector2.getLength()) {
int value8 = 100;
long ticks4 = (int)(Math.abs(Math.pow(horizontalVector2.getLength() - horizontalVector.getLength(), 2.0)) * this.vlMultiplier) + value4;
i = MathUtilities.clampToInt(ticks4, value8);
if (this.recordViolation(player2.getUniqueId(), i, HackType.SPEED, String.format(Locale.UK, playerMoveEvent.getPlayer().getName() + " failed Speed: moved too quickly: %.3f blocks/tick (%.3f/%.3f) g:" + (Object)((Object)groundCollisionState) + (Object)((Object)groundCollisionState2), horizontalVector2.getLength(), horizontalVector.getLength(), y), ticks2) && (this.getViolationLevel(playerMoveEvent.getPlayer()) > this.minVl || i > this.minVl)) {
boolean flag12 = false;
boolean flag13 = false;
double y3 = playerMoveEvent.getPlayer().getVelocity().getY();
PlayerMoveEvent playerMoveEvent2 = playerMoveEvent;
Player player7 = playerMoveEvent.getPlayer();
this.plugin.setbackManager.applySetback(player7, playerMoveEvent2, y3, flag13, flag12);
}
this.lastMoveVectors.put(playerMoveEvent.getPlayer(), HorizontalVector.ZERO);
} else {
if (!this.vlDecayCooldowns.containsKey(player2.getUniqueId())) {
this.decreaseViolationLevel(player2.getUniqueId(), 1);
}
this.lastMoveVectors.put(playerMoveEvent.getPlayer(), horizontalVector2);
}
}
@Override
public boolean recordViolation(UUID uUID, int i, HackType hackType, String str, long ticks) {
long ticks2 = ticks ^ 0L;
this.vlDecayCooldowns.put(uUID, 0);
this.vlDecayCooldowns.resetExpiration(uUID);
return super.recordViolation(uUID, i, hackType, str, ticks2);
}
private void resetToggleCounters() {
Server server = Bukkit.getServer();
Iterator iterator = server.getOnlinePlayers().iterator();
while (iterator.hasNext()) {
Player player = (Player)iterator.next();
this.sneakToggleCounts.put(player, 0);
this.itemUseToggleCounts.put(player, 0);
this.decreaseViolationLevel(player.getUniqueId(), 1);
}
}
private void decaySpeedViolations() {
Server server = Bukkit.getServer();
Iterator iterator = server.getOnlinePlayers().iterator();
while (iterator.hasNext()) {
Player player = (Player)iterator.next();
this.decreaseViolationLevel(player.getUniqueId(), 1);
}
}
static WeakHashMap getItemUseToggleCounts(Speed speed) {
return speed.itemUseToggleCounts;
}
static int getMaxUseToggles(Speed speed) {
return speed.maxUseToggles;
}
static ExpiringMap<Player, HorizontalVector> getVelocityBoosts(Speed speed) {
return speed.velocityBoosts;
}
}
@@ -0,0 +1,40 @@
package me.konsolas.aac.checks.movement;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import me.konsolas.aac.AAC;
import me.konsolas.aac.api.HackType;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class SpeedItemUsePacketListener
extends PacketAdapter {
final Speed detector;
public SpeedItemUsePacketListener(Speed speed, Plugin plugin, PacketType[] packetTypeArray) { super(plugin, packetTypeArray);
this.detector = speed;
}
public void onPacketReceiving(PacketEvent packetEvent) {
long ticks = 113218805911140L;
AAC aAC = (AAC)this.plugin;
Player player = packetEvent.getPlayer();
if (aAC.checkManager.isPlayerExempt(player)) {
return;
}
if (!AAC.serverVersion.hasConsumableOrWeapon(AAC.serverVersion.getHeldItems(packetEvent.getPlayer()))) {
return;
}
if (!Speed.getItemUseToggleCounts(this.detector).containsKey(packetEvent.getPlayer())) {
Speed.getItemUseToggleCounts(this.detector).put(packetEvent.getPlayer(), 1);
} else {
Speed.getItemUseToggleCounts(this.detector).put(packetEvent.getPlayer(), (Integer)Speed.getItemUseToggleCounts(this.detector).get(packetEvent.getPlayer()) + 1);
if ((Integer)Speed.getItemUseToggleCounts(this.detector).get(packetEvent.getPlayer()) > Speed.getMaxUseToggles(this.detector)) {
this.detector.recordViolation(packetEvent.getPlayer().getUniqueId(), 50, HackType.SPEED, packetEvent.getPlayer().getName() + " failed Speed: tried to toggle use too quickly (" + Speed.getItemUseToggleCounts(this.detector).get(packetEvent.getPlayer()) + " toggles/second)", ticks);
}
}
}
}
@@ -0,0 +1,37 @@
package me.konsolas.aac.checks.movement;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import me.konsolas.aac.compat.EntityVelocityPacket;
import me.konsolas.aac.util.HorizontalVector;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
public class SpeedVelocityPacketListener
extends PacketAdapter {
final Speed detector;
public SpeedVelocityPacketListener(Speed speed, Plugin plugin, PacketType[] packetTypeArray) { super(plugin, packetTypeArray);
this.detector = speed;
}
public void onPacketSending(PacketEvent packetEvent) {
PacketContainer packetContainer = packetEvent.getPacket();
EntityVelocityPacket entityVelocityPacket = new EntityVelocityPacket(packetContainer);
try {
if (entityVelocityPacket.getEntityId() == packetEvent.getPlayer().getEntityId()) {
HorizontalVector horizontalVector = new HorizontalVector(Math.abs(entityVelocityPacket.getVelocityX()), Math.abs(entityVelocityPacket.getVelocityZ()));
Speed.getVelocityBoosts(this.detector).put(packetEvent.getPlayer(), horizontalVector);
Player player = packetEvent.getPlayer();
Speed.getVelocityBoosts(this.detector).resetExpiration(player);
}
}
catch (UnsupportedOperationException unsupportedOperationException) {
this.plugin.getLogger().warning("(Speed) Velocity packet was sent to a temporary player (" + packetEvent.getPlayer().getName() + "/" + packetEvent.getPlayer().getUniqueId() + ")");
}
}
}
@@ -0,0 +1,23 @@
package me.konsolas.aac.checks.movement;
import org.bukkit.entity.EntityType;
public class VehicleTypeSwitch {
static final int[] ENTITY_ORDINALS = new int[EntityType.values().length];
static {
try {
VehicleTypeSwitch.ENTITY_ORDINALS[EntityType.BOAT.ordinal()] = 1;
}
catch (NoSuchFieldError noSuchFieldError) {}
try {
VehicleTypeSwitch.ENTITY_ORDINALS[EntityType.HORSE.ordinal()] = 2;
}
catch (NoSuchFieldError noSuchFieldError) {}
try {
VehicleTypeSwitch.ENTITY_ORDINALS[EntityType.PIG.ordinal()] = 3;
}
catch (NoSuchFieldError noSuchFieldError) {}
}
}
@@ -0,0 +1,174 @@
package me.konsolas.aac.checks.movement;
import java.util.Collections;
import java.util.Locale;
import java.util.Set;
import java.util.WeakHashMap;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.BlockPositionView;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.compat.EnvironmentBlockChecks;
import me.konsolas.aac.util.GroundCollisionState;
import me.konsolas.aac.util.MathUtilities;
import me.konsolas.aac.compat.ServerVersion;
import me.konsolas.aac.api.HackType;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.Boat;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
public class Vehicles
extends Detector
implements MovementCheckListener {
private final WeakHashMap lastVerticalDeltas;
private final Set nonGroundPlayers;
private double tolerance;
private boolean teleport;
private int minVl;
private double vlMultiplier;
public Vehicles(AAC aAC) { super(aAC);
this.lastVerticalDeltas = new WeakHashMap();
this.nonGroundPlayers = Collections.newSetFromMap(new WeakHashMap());
this.tolerance = 0.015;
this.teleport = true;
this.minVl = 12;
this.vlMultiplier = 6.0;
this.tolerance = this.plugin.getConfig().getDouble("vehicles.tolerance", this.tolerance);
this.teleport = this.plugin.getConfig().getBoolean("vehicles.teleport", this.teleport);
this.minVl = this.plugin.getConfig().getInt("vehicles.min_vl", this.minVl);
this.vlMultiplier = this.plugin.getConfig().getDouble("vehicles.vl_multiplier", this.vlMultiplier);
if (AAC.serverVersion.getVersion() == ServerVersion.VER_1_8) {
this.plugin.getLogger().info("Disabling check movement.Vehicles as server is 1.8.8");
boolean flag = false;
HackType hackType = HackType.VEHICLES;
this.plugin.checkManager.disableCheck(hackType, flag);
}
}
@Override
public void onTick(long ticks, long ticks2) {
if (ticks % 50L == 0L) {
for (Player player : Bukkit.getOnlinePlayers()) {
this.decreaseViolationLevel(player.getUniqueId(), 1);
}
}
}
@Override
public void onMovement(PlayerMoveEvent playerMoveEvent, GroundCollisionState groundCollisionState, GroundCollisionState groundCollisionState2, BlockPositionView blockPositionView, BlockPositionView blockPositionView2, long ticks) {
long ticks2 = ticks ^ 0x60FF4F6C294EL;
Player player = playerMoveEvent.getPlayer();
double y = playerMoveEvent.getTo().getY() - playerMoveEvent.getFrom().getY();
if (!this.lastVerticalDeltas.containsKey(playerMoveEvent.getPlayer())) {
this.lastVerticalDeltas.put(playerMoveEvent.getPlayer(), 0.0);
}
EntityType entityType = player.getVehicle().getType();
boolean flag = !this.nonGroundPlayers.contains(playerMoveEvent.getPlayer());
boolean flag2 = EnvironmentBlockChecks.isVehicleOnGround(player.getVehicle());
if (flag2) {
this.nonGroundPlayers.remove(playerMoveEvent.getPlayer());
} else {
this.nonGroundPlayers.add(playerMoveEvent.getPlayer());
}
double d = (Double)this.lastVerticalDeltas.get(player);
double x = Math.sqrt(Math.pow(playerMoveEvent.getTo().getX() - playerMoveEvent.getFrom().getX(), 2.0) + Math.pow(playerMoveEvent.getTo().getZ() - playerMoveEvent.getFrom().getZ(), 2.0));
switch (VehicleTypeSwitch.ENTITY_ORDINALS[entityType.ordinal()]) {
case 1: {
if (this.isBoatAirborne((Boat)player.getVehicle()) && y > 0.0) {
int value = 100;
long ticks3 = 6 + (int)(Math.abs(y) * this.vlMultiplier);
int value2 = MathUtilities.clampToInt(ticks3, value);
if (!this.recordViolation(player.getUniqueId(), value2, HackType.FLY, String.format(Locale.UK, player.getName() + " failed Vehicles: (BOAT) moved unexpectedly: %.3f (ABOVE WATER)", y), ticks2) || !this.teleport || this.getViolationLevel(player) <= this.minVl && !(Math.abs(y) > 1.0)) break;
this.plugin.setbackManager.setSetbackCheck(this, player);
player.teleport(playerMoveEvent.getFrom());
this.lastVerticalDeltas.put(player, player.getVelocity().getY());
break;
}
double d2 = VerticalMovementPredictor.predictNextGravityMotion(d);
if (!(Math.abs(y) > Math.abs(d2) + this.tolerance) && (flag2 || !(y > d2 + this.tolerance))) break;
int value3 = 100;
long ticks4 = 6 + (int)(Math.abs(y) * this.vlMultiplier);
int value4 = MathUtilities.clampToInt(ticks4, value3);
if (!this.recordViolation(player.getUniqueId(), value4, HackType.FLY, String.format(Locale.UK, player.getName() + " failed Vehicles: (BOAT) moved unexpectedly: %.3f (%.3f)", y, d2), ticks2) || !this.teleport || this.getViolationLevel(player) <= this.minVl && !(Math.abs(y) > 1.0)) break;
this.plugin.setbackManager.setSetbackCheck(this, player);
player.teleport(playerMoveEvent.getFrom());
this.lastVerticalDeltas.put(player, player.getVelocity().getY());
break;
}
case 2: {
if (flag) {
if (!(y > 2.0)) break;
int value5 = 100;
long ticks5 = 5 + (int)(Math.abs(y) * this.vlMultiplier);
int value6 = MathUtilities.clampToInt(ticks5, value5);
if (!this.recordViolation(player.getUniqueId(), value6, HackType.FLY, String.format(Locale.UK, player.getName() + " failed Vehicles: (HORSE) jumped unexpectedly: %.3f (JUMP)", y), ticks2) || !this.teleport || this.getViolationLevel(player) <= this.minVl && !(Math.abs(y) > 1.0)) break;
this.plugin.setbackManager.setSetbackCheck(this, player);
player.teleport(playerMoveEvent.getFrom());
this.lastVerticalDeltas.put(player, player.getVelocity().getY());
break;
}
double d3 = VerticalMovementPredictor.predictNextGravityMotion(d);
if (!(Math.abs(y) > Math.abs(d3) + this.tolerance) && (flag2 || !(y > d3 + this.tolerance))) break;
int value7 = 100;
long ticks6 = (int)(Math.abs(y) * this.vlMultiplier);
int value8 = MathUtilities.clampToInt(ticks6, value7);
if (!this.recordViolation(player.getUniqueId(), value8, HackType.FLY, String.format(Locale.UK, player.getName() + " failed Vehicles: (HORSE) moved unexpectedly: %.3f (%.3f)", y, d), ticks2) || !this.teleport || this.getViolationLevel(player) <= this.minVl && !(Math.abs(y) > 1.0)) break;
this.plugin.setbackManager.setSetbackCheck(this, player);
player.teleport(playerMoveEvent.getFrom());
this.lastVerticalDeltas.put(player, player.getVelocity().getY());
break;
}
case 3: {
if (flag) {
if (y > 1.0) {
int value9 = 100;
long ticks7 = 5 + (int)(Math.abs(y) * this.vlMultiplier);
int value10 = MathUtilities.clampToInt(ticks7, value9);
if (this.recordViolation(player.getUniqueId(), value10, HackType.FLY, String.format(Locale.UK, player.getName() + " failed Vehicles: (PIG) moved unexpectedly: %.3f (JUMP)", y), ticks2) && this.teleport && (this.getViolationLevel(player) > this.minVl || Math.abs(y) > 1.0)) {
this.plugin.setbackManager.setSetbackCheck(this, player);
player.teleport(playerMoveEvent.getFrom());
this.lastVerticalDeltas.put(player, player.getVelocity().getY());
}
}
} else {
double d4 = VerticalMovementPredictor.predictNextGravityMotion(d);
if (Math.abs(y) > Math.abs(d4) + this.tolerance || !flag2 && y > d4 + this.tolerance) {
int value11 = 100;
long ticks8 = 5 + (int)(Math.abs(y) * this.vlMultiplier);
int value12 = MathUtilities.clampToInt(ticks8, value11);
if (this.recordViolation(player.getUniqueId(), value12, HackType.FLY, String.format(Locale.UK, player.getName() + " failed Vehicles: (PIG) moved unexpectedly: %.3f (%.3f)", y, d4), ticks2) && this.teleport && (this.getViolationLevel(player) > this.minVl || Math.abs(y) > 1.0)) {
this.plugin.setbackManager.setSetbackCheck(this, player);
player.teleport(playerMoveEvent.getFrom());
this.lastVerticalDeltas.put(player, player.getVelocity().getY());
}
}
}
if (!(x > 0.412) || !this.recordViolation(player.getUniqueId(), 5 + (int)(Math.abs(x) * this.vlMultiplier), HackType.FLY, String.format(Locale.UK, player.getName() + " failed Vehicles: (PIG) moved too quickly (%.3f)", x), ticks2) || !this.teleport || this.getViolationLevel(player) <= this.minVl && !(Math.abs(y) > 1.0)) break;
this.plugin.setbackManager.setSetbackCheck(this, player);
player.teleport(playerMoveEvent.getFrom());
this.lastVerticalDeltas.put(player, player.getVelocity().getY());
}
}
this.lastVerticalDeltas.put(player, y);
}
@Override
public boolean shouldProcessMovement(PlayerMoveEvent playerMoveEvent) {
Player player;
if (playerMoveEvent.isCancelled()) {
return false;
}
return playerMoveEvent.getPlayer().getGameMode() != GameMode.SPECTATOR && !AAC.serverVersion.isElytraGliding(player = playerMoveEvent.getPlayer()) && !playerMoveEvent.getPlayer().isFlying() && !playerMoveEvent.getPlayer().isDead() && playerMoveEvent.getPlayer().getLocation().getY() > -1024.0 && !playerMoveEvent.getPlayer().getAllowFlight() && !playerMoveEvent.getPlayer().isSleeping() && playerMoveEvent.getPlayer().getVehicle() != null;
}
private boolean isBoatAirborne(Boat boat) {
Material material = boat.getLocation().getBlock().getType();
return material != Material.STATIONARY_WATER && material != Material.WATER && !boat.isOnGround();
}
}
@@ -0,0 +1,80 @@
package me.konsolas.aac.checks.movement;
import me.konsolas.aac.checks.world.VelocityPacketListener;
import org.bukkit.Location;
import org.bukkit.util.Vector;
public class VelocityResponseState {
private final Vector expectedVelocity;
private final Location origin;
private double responseDistance;
private Vector observedVelocity;
private double horizontalResponse;
private boolean responded;
private boolean attackObserved = false;
private VelocityResponseState(Location location, Vector vector) {
this.origin = location;
this.expectedVelocity = vector;
this.responseDistance = 2.147483647E9;
this.observedVelocity = new Vector(0, 0, 0);
}
public VelocityResponseState(Location location, Vector vector, VelocityPacketListener velocityPacketListener) {
this(location, vector);
}
public static boolean setAttackObserved(VelocityResponseState velocityResponseState, boolean flag) {
velocityResponseState.attackObserved = flag;
return velocityResponseState.attackObserved;
}
public static boolean setResponded(VelocityResponseState velocityResponseState, boolean flag) {
velocityResponseState.responded = flag;
return velocityResponseState.responded;
}
public static Vector getExpectedVelocity(VelocityResponseState velocityResponseState) {
return velocityResponseState.expectedVelocity;
}
public static boolean isResponded(VelocityResponseState velocityResponseState) {
return velocityResponseState.responded;
}
public static double getResponseDistance(VelocityResponseState velocityResponseState) {
return velocityResponseState.responseDistance;
}
public static Vector setObservedVelocity(VelocityResponseState velocityResponseState, Vector vector) {
velocityResponseState.observedVelocity = vector;
return velocityResponseState.observedVelocity;
}
public static double setResponseDistance(VelocityResponseState velocityResponseState, double d) {
velocityResponseState.responseDistance = d;
return velocityResponseState.responseDistance;
}
public static double setHorizontalResponse(VelocityResponseState velocityResponseState, double d) {
velocityResponseState.horizontalResponse = d;
return velocityResponseState.horizontalResponse;
}
public static boolean isAttackObserved(VelocityResponseState velocityResponseState) {
return velocityResponseState.attackObserved;
}
public static Vector getObservedVelocity(VelocityResponseState velocityResponseState) {
return velocityResponseState.observedVelocity;
}
public static double getHorizontalResponse(VelocityResponseState velocityResponseState) {
return velocityResponseState.horizontalResponse;
}
public static Location getOrigin(VelocityResponseState velocityResponseState) {
return velocityResponseState.origin;
}
}
@@ -0,0 +1,268 @@
package me.konsolas.aac.checks.movement;
import me.konsolas.aac.util.GroundCollisionState;
import me.konsolas.aac.util.HorizontalVector;
import me.konsolas.aac.util.MathUtilities;
public class VerticalMovementPredictor {
public static final VerticalMovementState DEFAULT_STATE = new VerticalMovementState();
private static boolean isLessThanLimit(double d, double d2, double d3) {
return d < d2 + d3;
}
private static boolean isGreaterThanMin(double d, double d2, double d3) {
return d > d2 - d3;
}
private static boolean isApproximatelyEqual(double d, double d2, double d3) {
double d4 = d3;
double d5 = d2;
double d6 = d;
return MathUtilities.approximatelyEquals(d6, d5, d4);
}
public static double predictNextGravityMotion(double d) {
d -= 0.08;
if (Math.abs(d *= 0.98) < 0.005) {
d = 0.0;
}
return d;
}
private static double predictLevitationMotion(double d, int i) {
if (i > 127) {
d = (d -= (double)(255 - i) * 0.005) < -((double)(255 - i) * 0.05) ? -((double)(255 - i) * 0.05) : d;
d *= 0.98;
} else {
d = (d += (double)i * 0.005) > (double)i * 0.05 ? (double)i * 0.05 : d;
d *= 0.98;
}
return d;
}
private static double scaleJumpBoost(double d) {
return d * 1.5;
}
public static boolean isValidVerticalMovement(double d, double d2, boolean flag, GroundCollisionState groundCollisionState, GroundCollisionState groundCollisionState2, boolean flag2, boolean flag3, boolean flag4, double d3, boolean flag5, boolean flag6, boolean flag7, boolean flag8, boolean flag9, boolean flag10, boolean flag11, boolean flag12, boolean flag13, boolean flag14, double d4, double d5, int i, int i2, VerticalMovementState verticalMovementState, VerticalMovementState verticalMovementState2) {
double d6;
double d7;
double d8;
double d9;
double d10;
double d11;
double d12;
block40: {
block39: {
double d13 = verticalMovementState.lastDeltaY;
verticalMovementState2.lastDeltaY = d;
d12 = VerticalMovementPredictor.predictNextGravityMotion(d13);
double d14 = Math.max(i > 0 ? (double)i / 10.0 + 0.42 : 0.42, flag4 ? 0.65 : 0.0);
if (i2 > 0) {
if (groundCollisionState.isOnGround() && d > 0.0 && d < 1.0) {
verticalMovementState2.fallStage = 0;
verticalMovementState2.expectedDeltaY = 1.0;
return true;
}
double d15 = VerticalMovementPredictor.predictLevitationMotion(d13, i2);
verticalMovementState2.fallStage = 1;
verticalMovementState2.expectedDeltaY = d15;
double d16 = d5;
double d17 = d15;
double d18 = d;
return VerticalMovementPredictor.isApproximatelyEqual(d18, d17, d16);
}
if (d13 < -0.1 && verticalMovementState.placedBlockNearby && d > 0.2) {
groundCollisionState = GroundCollisionState.TRUE_NORMAL;
}
if (verticalMovementState.brokeBlockNearby && d <= 0.0) {
return true;
}
if (flag6) {
d5 += 0.2;
}
if (flag11) {
if (d13 <= 0.0 && d > 0.0) {
double d19;
verticalMovementState2.fallStage = 3;
verticalMovementState2.expectedDeltaY = d19 = Math.max(Math.max(VerticalMovementPredictor.scaleJumpBoost(d3), d14), Math.max(VerticalMovementPredictor.scaleJumpBoost(-d13), 1.51));
return VerticalMovementPredictor.isLessThanLimit(d, d19, d5);
}
if (d < -d5 && d < d13 - 0.05 && VerticalMovementPredictor.isGreaterThanMin(d, -0.5, d5)) {
verticalMovementState2.fallStage = 4;
return true;
}
if (groundCollisionState.isOnGround() && Math.abs(d) < 0.1) {
verticalMovementState2.fallStage = 5;
return true;
}
if (d > 0.0 && d < 0.3 && VerticalMovementPredictor.isLessThanLimit(d, d12 * 1.2, d5)) {
verticalMovementState2.fallStage = 6;
return true;
}
}
if (flag3) {
if (d > d14) {
verticalMovementState2.fallStage = 7;
verticalMovementState2.lastDeltaY = d14;
} else {
verticalMovementState2.fallStage = 8;
}
return VerticalMovementPredictor.isLessThanLimit(d, d14 + 0.2, d5);
}
if (flag13) {
verticalMovementState2.fallStage = 9;
return VerticalMovementPredictor.isLessThanLimit(d, 1.125, d5);
}
if (flag12) {
verticalMovementState2.fallStage = 10;
return groundCollisionState.isOnGround() ? VerticalMovementPredictor.isLessThanLimit(d, 0.6, 0.0) : VerticalMovementPredictor.isLessThanLimit(d, 0.0, d5);
}
if (flag14) {
boolean flag15 = VerticalMovementPredictor.isLessThanLimit(d, Math.max(d12, 0.155), d5) && VerticalMovementPredictor.isGreaterThanMin(d, Math.min(d12, -0.2), d5);
verticalMovementState2.fallStage = 11;
if (!groundCollisionState.isOnGround()) {
return flag15;
}
if (flag15) {
return true;
}
}
if (groundCollisionState.isOnGround() || flag4) {
verticalMovementState2.expectedDeltaY = d14;
if (!(groundCollisionState2.isOnGround() || flag4 || flag7 || flag9)) {
double d20;
double d21;
double d22;
double d23;
double d24;
double d25;
double d26;
double d27;
double d28;
double d29 = d;
double d30 = d14;
double d31 = d5;
if (VerticalMovementPredictor.isApproximatelyEqual(d29, d30, d31)) {
verticalMovementState2.fallStage = 12;
return true;
}
if (VerticalMovementPredictor.isLessThanLimit(d, d14, d5) && VerticalMovementPredictor.isGreaterThanMin(d, d14 - 0.02, d5) && d4 <= 0.2) {
verticalMovementState2.lastDeltaY = 0.42;
verticalMovementState2.fallStage = 13;
return true;
}
if (d4 <= 0.1 && groundCollisionState.isAirStep() && groundCollisionState2.isAirStep()) {
verticalMovementState2.fallStage = 14;
double d32 = d;
double d33 = 0.333;
double d34 = d5;
if (VerticalMovementPredictor.isApproximatelyEqual(d32, d33, d34)) {
return true;
}
}
verticalMovementState2.fallStage = 15;
double d35 = d;
double d36 = 0.0;
double d37 = d5;
return VerticalMovementPredictor.isApproximatelyEqual(d35, d36, d37) || VerticalMovementPredictor.isApproximatelyEqual(d28 = d, d27 = -0.08, d26 = d5) || VerticalMovementPredictor.isApproximatelyEqual(d25 = d, d24 = -0.16, d23 = d5 + HorizontalVector.ROUNDING_EPSILON.getLength()) || VerticalMovementPredictor.isApproximatelyEqual(d22 = d, d21 = d12, d20 = d5) || flag8 && VerticalMovementPredictor.isLessThanLimit(d, d14, d5);
}
if (Math.abs(d + d13) < HorizontalVector.ROUNDING_EPSILON.getLength()) {
verticalMovementState2.fallStage = 16;
verticalMovementState2.lastDeltaY = 0.42;
} else {
verticalMovementState2.fallStage = 17;
}
return VerticalMovementPredictor.isLessThanLimit(d, d14, d5) && VerticalMovementPredictor.isGreaterThanMin(d, Math.min(d12, -0.2), d5);
}
if (flag9) {
double d38;
double d39;
double d40;
double d41;
double d42;
double d43;
double d44;
double d45;
double d46;
double d47;
double d48;
double d49;
double d50;
double d51;
double d52;
verticalMovementState2.wasOnGround = true;
if (!flag10 && !flag6) {
verticalMovementState2.fallStage = 18;
verticalMovementState2.expectedDeltaY = flag2 ? Math.max(d12, d14) : Math.max(flag5 ? 0.0 : 0.2, d12);
return VerticalMovementPredictor.isLessThanLimit(d, verticalMovementState2.expectedDeltaY, d5);
}
verticalMovementState2.fallStage = 19;
verticalMovementState2.expectedDeltaY = Math.max(d12, 0.2);
if (flag2) {
verticalMovementState2.fallStage = 20;
verticalMovementState2.expectedDeltaY = Math.max(Math.max(d14, d14 + d2), 0.1);
return VerticalMovementPredictor.isLessThanLimit(d, verticalMovementState2.expectedDeltaY, d5) && VerticalMovementPredictor.isGreaterThanMin(d, Math.min(d12, -0.6), d5);
}
if (groundCollisionState2.isOnGround() || d4 < 0.05 || flag8 || flag7) {
verticalMovementState2.fallStage = 22;
return VerticalMovementPredictor.isLessThanLimit(d, Math.max(d13 * 0.8 + 0.02, 0.34), d5) && VerticalMovementPredictor.isGreaterThanMin(d, Math.min(d13 * 0.8 - 0.8, -0.16), d5);
}
verticalMovementState2.fallStage = 23;
double d53 = d;
double d54 = d13 * 0.8 + 0.02;
double d55 = d5;
return VerticalMovementPredictor.isApproximatelyEqual(d53, d54, d55) || VerticalMovementPredictor.isApproximatelyEqual(d52 = d, d51 = d13 * 0.8 - 0.02, d50 = d5) || VerticalMovementPredictor.isApproximatelyEqual(d49 = d, d48 = d12, d47 = d5) || VerticalMovementPredictor.isApproximatelyEqual(d46 = d, d45 = d12 * 0.8, d44 = d5) || VerticalMovementPredictor.isApproximatelyEqual(d43 = d, d42 = d12 + 0.04, d41 = d5) || VerticalMovementPredictor.isApproximatelyEqual(d40 = d, d39 = -0.0376, d38 = d5);
}
if (verticalMovementState.wasOnGround) {
d5 += 0.3;
}
if (groundCollisionState2.isOnGround()) {
verticalMovementState2.expectedDeltaY = d12;
if (flag8 || flag7) {
verticalMovementState2.fallStage = 24;
return VerticalMovementPredictor.isGreaterThanMin(d, Math.min(VerticalMovementPredictor.predictNextGravityMotion(d12), -0.2), d5) && VerticalMovementPredictor.isLessThanLimit(d, Math.max(d12, d12 < -0.1 ? 0.4 : 0.0), d5);
}
verticalMovementState2.fallStage = 25;
return VerticalMovementPredictor.isGreaterThanMin(d, Math.min(VerticalMovementPredictor.predictNextGravityMotion(d12), 0.0), d5) && VerticalMovementPredictor.isLessThanLimit(d, Math.max(d12, d12 < -0.1 ? 0.4 : 0.0), d5);
}
verticalMovementState2.expectedDeltaY = d12;
double d56 = d;
double d57 = d12;
double d58 = d5;
if (VerticalMovementPredictor.isApproximatelyEqual(d56, d57, d58)) break block39;
double d59 = d5;
double d60 = d;
double d61 = VerticalMovementPredictor.predictNextGravityMotion(d2);
if (!VerticalMovementPredictor.isApproximatelyEqual(d60, d61, d59)) break block40;
}
verticalMovementState2.fallStage = 26;
return true;
}
if (flag8) {
verticalMovementState2.fallStage = 27;
verticalMovementState2.expectedDeltaY = d12;
return VerticalMovementPredictor.isLessThanLimit(d, Math.max(d12, -0.2), d5) && VerticalMovementPredictor.isGreaterThanMin(d, -0.5, d5);
}
double d62 = d12;
double d63 = 0.0;
double d64 = 0.05 + d5;
if (MathUtilities.approximatelyEquals(d62, d63, d64)) {
verticalMovementState2.fallStage = 29;
verticalMovementState2.lastDeltaY = verticalMovementState2.expectedDeltaY = VerticalMovementPredictor.predictNextGravityMotion(verticalMovementState2.expectedDeltaY);
double d65 = d5;
double d66 = verticalMovementState2.expectedDeltaY + d12;
double d67 = d;
return VerticalMovementPredictor.isApproximatelyEqual(d67, d66, d65);
}
verticalMovementState2.fallStage = 30;
if (flag && MathUtilities.approximatelyEquals(d11 = d, d10 = 0.404, d9 = d5) && MathUtilities.approximatelyEquals(d8 = d12, d7 = -0.2305, d6 = d5)) {
verticalMovementState2.fallStage = 31;
verticalMovementState2.lastDeltaY = 0.42;
return true;
}
return false;
}
}
@@ -0,0 +1,16 @@
package me.konsolas.aac.checks.movement;
import org.bukkit.Location;
public class VerticalMovementState {
public Location lastSafeLocation = null;
public double expectedDeltaY = 0.0;
public double lastDeltaY = 0.0;
public boolean wasOnGround = false;
public int fallStage = 0;
public boolean placedBlockNearby;
public boolean brokeBlockNearby;
public long timestamp;
}
@@ -0,0 +1,96 @@
package me.konsolas.aac.checks.world;
import java.util.WeakHashMap;
import me.konsolas.aac.AAC;
import me.konsolas.aac.compat.BlockBreakSpeedAccess;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.api.HackType;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.player.PlayerInteractEvent;
public final class FastBreak
extends Detector {
private int letTicks;
private boolean cancelBreak;
private boolean checkDelay;
private int cancelVl;
private final WeakHashMap breakStartTimes;
private final WeakHashMap targetBlockLocations;
private final WeakHashMap lastBlockBreakTimes;
public FastBreak(AAC aAC) { super(aAC);
this.letTicks = 2;
this.cancelBreak = true;
this.checkDelay = true;
this.cancelVl = 1;
this.breakStartTimes = new WeakHashMap();
this.targetBlockLocations = new WeakHashMap();
this.lastBlockBreakTimes = new WeakHashMap();
this.letTicks = this.plugin.getConfig().getInt("fastbreak.let_ticks", this.letTicks);
this.cancelBreak = this.plugin.getConfig().getBoolean("fastbreak.cancel_break", this.cancelBreak);
this.checkDelay = this.plugin.getConfig().getBoolean("fastbreak.check_delay", this.checkDelay);
this.cancelVl = this.plugin.getConfig().getInt("fastbreak.cancel_vl", this.cancelVl);
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent playerInteractEvent) {
long ticks = 113218805911140L;
if (playerInteractEvent.getAction() == Action.LEFT_CLICK_BLOCK) {
long ticks2;
long ticks3;
if (playerInteractEvent.getClickedBlock().getLocation().toVector().equals(this.targetBlockLocations.get(playerInteractEvent.getPlayer()))) {
ticks3 = System.currentTimeMillis();
long ticks4 = ticks3 - (ticks2 = ((Long)this.breakStartTimes.get(playerInteractEvent.getPlayer())).longValue()) / 50L;
if (ticks4 >= BlockBreakSpeedAccess.getBreakTicks(playerInteractEvent.getClickedBlock(), playerInteractEvent.getPlayer())) {
this.breakStartTimes.put(playerInteractEvent.getPlayer(), System.currentTimeMillis());
}
} else {
this.targetBlockLocations.put(playerInteractEvent.getPlayer(), playerInteractEvent.getClickedBlock().getLocation().toVector());
this.breakStartTimes.put(playerInteractEvent.getPlayer(), System.currentTimeMillis());
}
if (this.checkDelay && this.lastBlockBreakTimes.containsKey(playerInteractEvent.getPlayer()) && BlockBreakSpeedAccess.getHasteLevel(playerInteractEvent.getPlayer()) == 0) {
ticks3 = (Long)this.lastBlockBreakTimes.get(playerInteractEvent.getPlayer());
ticks2 = System.currentTimeMillis();
if (ticks2 - ticks3 < 100L && playerInteractEvent.getClickedBlock() != null && BlockBreakSpeedAccess.getBreakTicks(playerInteractEvent.getClickedBlock(), playerInteractEvent.getPlayer()) > 1L && this.recordViolation(playerInteractEvent.getPlayer().getUniqueId(), 2, HackType.FASTBREAK, playerInteractEvent.getPlayer().getName() + " failed FastBreak: interacted too quickly after breaking a block", ticks) && this.cancelBreak && this.getViolationLevel(playerInteractEvent.getPlayer()) > this.cancelVl) {
playerInteractEvent.setCancelled(true);
}
}
}
}
@EventHandler(priority=EventPriority.LOWEST, ignoreCancelled=true)
public void onBlockBreak(BlockBreakEvent blockBreakEvent) {
Player player;
long ticks = 113218805911140L;
if (blockBreakEvent.getPlayer().getGameMode() == GameMode.CREATIVE || this.plugin.checkManager.isPlayerExempt(player = blockBreakEvent.getPlayer())) {
return;
}
if (!blockBreakEvent.getBlock().getLocation().toVector().equals(this.targetBlockLocations.get(blockBreakEvent.getPlayer())) && this.recordViolation(blockBreakEvent.getPlayer().getUniqueId(), 1, HackType.FASTBREAK, blockBreakEvent.getPlayer().getName() + " failed FastBreak: broke the wrong block", ticks) && this.cancelBreak) {
blockBreakEvent.setCancelled(true);
}
if (this.breakStartTimes.containsKey(blockBreakEvent.getPlayer())) {
long now = System.currentTimeMillis();
long ticks2 = (Long)this.breakStartTimes.get(blockBreakEvent.getPlayer());
long ticks3 = (now - ticks2) / 50L;
long ticks4 = BlockBreakSpeedAccess.getBreakTicks(blockBreakEvent.getBlock(), blockBreakEvent.getPlayer());
if (ticks4 == 0L) {
return;
}
if (ticks3 + (long)this.letTicks < ticks4) {
if (this.recordViolation(blockBreakEvent.getPlayer().getUniqueId(), 1, HackType.FASTBREAK, blockBreakEvent.getPlayer().getName() + " failed FastBreak: tried to break blocks too quickly (" + ticks3 + ", expected " + ticks4 + ")", ticks) && this.cancelBreak && this.getViolationLevel(blockBreakEvent.getPlayer()) > this.cancelVl) {
blockBreakEvent.setCancelled(true);
}
} else {
this.decreaseViolationLevel(blockBreakEvent.getPlayer().getUniqueId(), 1);
}
}
this.lastBlockBreakTimes.put(blockBreakEvent.getPlayer(), System.currentTimeMillis());
}
}
@@ -0,0 +1,67 @@
package me.konsolas.aac.checks.world;
import java.util.WeakHashMap;
import me.konsolas.aac.AAC;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.api.HackType;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
public final class FastPlace
extends Detector {
private static final ItemStack BONE_MEAL_ITEM = new ItemStack(Material.INK_SACK, 1, (short)15);
private int maxPlacePerSecond;
private boolean cancelPlace;
private int cancelVl;
private final WeakHashMap placeCounts;
public FastPlace(AAC aAC) { super(aAC);
this.maxPlacePerSecond = 10;
this.cancelPlace = true;
this.cancelVl = 2;
this.placeCounts = new WeakHashMap();
this.maxPlacePerSecond = this.plugin.getConfig().getInt("fastplace.max_place_per_second", this.maxPlacePerSecond);
this.cancelPlace = this.plugin.getConfig().getBoolean("fastplace.cancel_place", this.cancelPlace);
this.cancelVl = this.plugin.getConfig().getInt("fastplace.cancel_vl", this.cancelVl);
Server server = this.plugin.getServer();
this.scheduledTaskIds.add(server.getScheduler().scheduleSyncRepeatingTask((Plugin)this.plugin, this::resetPlaceCounts, 20L, 20L));
}
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true)
public void onBlockPlace(BlockPlaceEvent blockPlaceEvent) {
Player player;
long ticks = 113218805911140L;
if (blockPlaceEvent.getPlayer().getGameMode() == GameMode.CREATIVE || this.plugin.checkManager.isPlayerExempt(player = blockPlaceEvent.getPlayer())) {
return;
}
for (ItemStack itemStack : AAC.serverVersion.getHeldItems(blockPlaceEvent.getPlayer())) {
if (itemStack != null && itemStack.getType() != Material.FLINT_AND_STEEL && !itemStack.isSimilar(BONE_MEAL_ITEM)) continue;
return;
}
if (!this.placeCounts.containsKey(blockPlaceEvent.getPlayer())) {
this.placeCounts.put(blockPlaceEvent.getPlayer(), 1);
} else {
this.placeCounts.put(blockPlaceEvent.getPlayer(), (Integer)this.placeCounts.get(blockPlaceEvent.getPlayer()) + 1);
}
if ((Integer)this.placeCounts.get(blockPlaceEvent.getPlayer()) > this.maxPlacePerSecond && this.recordViolation(blockPlaceEvent.getPlayer().getUniqueId(), (Integer)this.placeCounts.get(blockPlaceEvent.getPlayer()) - this.maxPlacePerSecond, HackType.FASTBREAK, blockPlaceEvent.getPlayer().getName() + " failed FastPlace: placed " + this.placeCounts.get(blockPlaceEvent.getPlayer()) + " blocks in 1 second", ticks) && this.cancelPlace && this.getViolationLevel(blockPlaceEvent.getPlayer()) > this.cancelVl) {
blockPlaceEvent.setCancelled(true);
}
}
private void resetPlaceCounts() {
this.placeCounts.clear();
for (Player player : Bukkit.getOnlinePlayers()) {
this.decreaseViolationLevel(player.getUniqueId(), 1);
}
}
}
@@ -0,0 +1,298 @@
package me.konsolas.aac.checks.world;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import me.konsolas.aac.AAC;
import me.konsolas.aac.util.AxisAlignedBoundingBox;
import me.konsolas.aac.compat.BlockBreakSpeedAccess;
import me.konsolas.aac.compat.CollisionAccess;
import me.konsolas.aac.checks.combat.CombatCheckListener;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.util.EntityDimensions;
import me.konsolas.aac.util.EntityTypeChecks;
import me.konsolas.aac.compat.ItemUseAccess;
import me.konsolas.aac.api.HackType;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.BlockState;
import org.bukkit.block.DoubleChest;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector;
public class Interact
extends Detector
implements CombatCheckListener {
private boolean cancelLiquids;
private boolean cancelGhostBlock;
private boolean cancelDead;
private boolean cancelItemAttack;
private boolean cancelGhostAttack;
private int cancelVlInteract;
private int cancelVlPlace;
private int cancelVlBreak;
public Interact(AAC aAC) { super(aAC);
this.cancelLiquids = true;
this.cancelGhostBlock = true;
this.cancelDead = true;
this.cancelItemAttack = true;
this.cancelGhostAttack = true;
this.cancelVlInteract = 5;
this.cancelVlPlace = 5;
this.cancelVlBreak = 0;
this.cancelLiquids = this.plugin.getConfig().getBoolean("interact.cancel_liquids", this.cancelLiquids);
this.cancelGhostBlock = this.plugin.getConfig().getBoolean("interact.cancel_ghost_block", this.cancelGhostBlock);
this.cancelDead = this.plugin.getConfig().getBoolean("interact.cancel_dead", this.cancelDead);
this.cancelItemAttack = this.plugin.getConfig().getBoolean("interact.cancel_item_attack", this.cancelItemAttack);
this.cancelGhostAttack = this.plugin.getConfig().getBoolean("interact.cancel_ghost_attack", this.cancelGhostAttack);
this.cancelVlInteract = this.plugin.getConfig().getInt("interact.cancel_vl_interact", this.cancelVlInteract);
this.cancelVlPlace = this.plugin.getConfig().getInt("interact.cancel_vl_place", this.cancelVlPlace);
this.cancelVlBreak = this.plugin.getConfig().getInt("interact.cancel_vl_break", this.cancelVlBreak);
Server server = this.plugin.getServer();
this.scheduledTaskIds.add(server.getScheduler().scheduleSyncRepeatingTask((Plugin)this.plugin, this::decayInteractViolations, 19L, 43L));
}
@Override
public boolean shouldProcessCombat(EntityDamageByEntityEvent entityDamageByEntityEvent) {
return entityDamageByEntityEvent.getDamager().getType() == EntityType.PLAYER;
}
@Override
public void onCombat(EntityDamageByEntityEvent entityDamageByEntityEvent, long ticks) {
long ticks2 = ticks ^ 0x7B735CA5F5C9L;
Player player = (Player)entityDamageByEntityEvent.getDamager();
Player player2 = player;
if (this.plugin.checkManager.isPlayerExempt(player2)) {
return;
}
if (player.isDead() && this.cancelDead) {
if (this.recordViolation(player.getUniqueId(), 1, HackType.INTERACT, player.getName() + " failed Interact: attacked whilst dead", ticks2)) {
entityDamageByEntityEvent.setCancelled(true);
}
} else {
Player player3 = player;
if (ItemUseAccess.isUsingItem(player3) && this.cancelItemAttack) {
if (this.recordViolation(player.getUniqueId(), 1, HackType.INTERACT, player.getName() + " failed Interact: attacked whilst using an item", ticks2)) {
entityDamageByEntityEvent.setCancelled(true);
}
} else if (this.cancelGhostAttack) {
if (!EntityTypeChecks.isCommonCombatTarget(entityDamageByEntityEvent.getEntityType()) && !EntityTypeChecks.isStandardMob(entityDamageByEntityEvent.getEntityType())) {
return;
}
Vector vector = ((Player)entityDamageByEntityEvent.getDamager()).getEyeLocation().toVector();
Vector vector2 = entityDamageByEntityEvent.getDamager().getLocation().getDirection();
Entity entity = entityDamageByEntityEvent.getEntity();
AxisAlignedBoundingBox axisAlignedBoundingBox = new AxisAlignedBoundingBox(entityDamageByEntityEvent.getEntity().getLocation().toVector(), EntityDimensions.forEntity(entity).scale(2.0));
Entity entity2 = entityDamageByEntityEvent.getDamager();
AxisAlignedBoundingBox axisAlignedBoundingBox2 = new AxisAlignedBoundingBox(vector, EntityDimensions.forEntity(entity2)).union(axisAlignedBoundingBox);
Entity entity3 = entityDamageByEntityEvent.getDamager();
AxisAlignedBoundingBox axisAlignedBoundingBox3 = this.findClosestHitBox(vector, vector2, CollisionAccess.getCollidingBoxes(entity3, axisAlignedBoundingBox2));
if (axisAlignedBoundingBox3 != null && axisAlignedBoundingBox3.rayTraceDistance(vector, vector2) < axisAlignedBoundingBox.rayTraceDistance(vector, vector2) && this.recordViolation(player.getUniqueId(), 2, HackType.INTERACT, player.getName() + " failed Interact: attacked a player-like entity through a solid wall", ticks2)) {
entityDamageByEntityEvent.setCancelled(true);
}
}
}
}
@EventHandler
public void onPlayerInteract(PlayerInteractEvent playerInteractEvent) {
long ticks = 113218805911140L;
if (playerInteractEvent.getClickedBlock() == null || playerInteractEvent.getClickedBlock().getType() == Material.AIR) {
return;
}
if ((playerInteractEvent.getAction() == Action.LEFT_CLICK_BLOCK || playerInteractEvent.getAction() == Action.RIGHT_CLICK_BLOCK) && this.cancelGhostBlock) {
Block block = null;
Block block2 = playerInteractEvent.getClickedBlock();
Player player = playerInteractEvent.getPlayer();
if (this.checkLineOfSight(player, block2, block) && this.recordViolation(playerInteractEvent.getPlayer().getUniqueId(), playerInteractEvent.getItem() != null && playerInteractEvent.getItem().getType() == Material.MONSTER_EGG ? 2 : 0, HackType.INTERACT, playerInteractEvent.getPlayer().getName() + " failed Interact: interacted with a block out of his line of sight", ticks) && this.getViolationLevel(playerInteractEvent.getPlayer()) >= this.cancelVlInteract) {
playerInteractEvent.setCancelled(true);
}
}
if (playerInteractEvent.getPlayer().isDead() && this.cancelDead && this.recordViolation(playerInteractEvent.getPlayer().getUniqueId(), 1, HackType.INTERACT, playerInteractEvent.getPlayer().getName() + " failed Interact: interacted whilst dead", ticks)) {
playerInteractEvent.setCancelled(true);
}
}
@EventHandler
public void onBlockBreak(BlockBreakEvent blockBreakEvent) {
Player player;
long ticks = 113218805911140L;
if (blockBreakEvent.getBlock() == null || this.plugin.checkManager.isPlayerExempt(player = blockBreakEvent.getPlayer())) {
return;
}
if (BlockBreakSpeedAccess.getBreakTicks(blockBreakEvent.getBlock(), blockBreakEvent.getPlayer()) <= 0L || blockBreakEvent.getPlayer().getGameMode() == GameMode.CREATIVE) {
return;
}
if (this.cancelGhostBlock) {
Block block = blockBreakEvent.getBlock();
Block block2 = null;
Block block3 = block;
Player player2 = blockBreakEvent.getPlayer();
if (this.checkLineOfSight(player2, block3, block2) && this.recordViolation(blockBreakEvent.getPlayer().getUniqueId(), 2, HackType.INTERACT, blockBreakEvent.getPlayer().getName() + " failed Interact: broke a block out of line of sight", ticks) && this.getViolationLevel(blockBreakEvent.getPlayer()) > this.cancelVlBreak) {
blockBreakEvent.setCancelled(true);
}
}
this.decreaseViolationLevel(blockBreakEvent.getPlayer().getUniqueId(), 1);
}
@EventHandler
public void onBlockPlace(BlockPlaceEvent blockPlaceEvent) {
long ticks = 113218805911140L;
Player player = blockPlaceEvent.getPlayer();
if (this.plugin.checkManager.isPlayerExempt(player)) {
return;
}
Material material = blockPlaceEvent.getBlockAgainst().getType();
if ((material == Material.LAVA || material == Material.WATER || material == Material.STATIONARY_LAVA || material == Material.STATIONARY_WATER) && this.cancelLiquids && blockPlaceEvent.getPlayer().getItemInHand().getType() != Material.WATER_LILY && this.recordViolation(blockPlaceEvent.getPlayer().getUniqueId(), 2, HackType.INTERACT, blockPlaceEvent.getPlayer().getName() + " failed Interact: interacted with a liquid", ticks)) {
blockPlaceEvent.setCancelled(true);
}
if (this.cancelGhostBlock) {
Block block = blockPlaceEvent.getBlockAgainst();
Block block2 = blockPlaceEvent.getBlockPlaced();
if (blockPlaceEvent.getBlockPlaced().equals(blockPlaceEvent.getBlockAgainst())) {
block2 = null;
}
Block block3 = block2;
Block block4 = block;
Player player2 = blockPlaceEvent.getPlayer();
if (this.checkLineOfSight(player2, block4, block3) && this.recordViolation(blockPlaceEvent.getPlayer().getUniqueId(), 2, HackType.INTERACT, blockPlaceEvent.getPlayer().getName() + " failed Interact: placed a block out of line of sight", ticks) && this.getViolationLevel(blockPlaceEvent.getPlayer()) > this.cancelVlPlace) {
blockPlaceEvent.setCancelled(true);
}
}
}
@EventHandler
public void onInventoryOpen(InventoryOpenEvent inventoryOpenEvent) {
long ticks = 113218805911140L;
if (this.cancelGhostBlock) {
Block block;
Block block2;
Block block3;
Player player;
Player player2 = (Player)inventoryOpenEvent.getPlayer();
Player player3 = player2;
if (this.plugin.checkManager.isPlayerExempt(player3)) {
return;
}
try {
if (inventoryOpenEvent.getInventory() == null || inventoryOpenEvent.getInventory().getHolder() == null) {
return;
}
}
catch (Exception exception) {
Bukkit.getLogger().warning("[AAC] Failed to cast inventory holder to player: " + exception.getMessage());
return;
}
if (inventoryOpenEvent.getInventory().getHolder() instanceof Minecart || inventoryOpenEvent.getInventory().getHolder() instanceof LivingEntity) {
return;
}
if (inventoryOpenEvent.getInventory().getHolder() instanceof DoubleChest) {
DoubleChest doubleChest = (DoubleChest)inventoryOpenEvent.getInventory().getHolder();
Block block4 = null;
Player player4 = player2;
Block block5 = ((BlockState)doubleChest.getLeftSide()).getBlock();
if (this.checkLineOfSight(player4, block5, block4)) {
Block block6 = null;
Block block7 = ((BlockState)doubleChest.getRightSide()).getBlock();
Player player5 = (Player)inventoryOpenEvent.getPlayer();
if (this.checkLineOfSight(player5, block7, block6) && this.recordViolation(inventoryOpenEvent.getPlayer().getUniqueId(), 2, HackType.INTERACT, inventoryOpenEvent.getPlayer().getName() + " failed Interact: opened a container out of line of sight", ticks)) {
inventoryOpenEvent.setCancelled(true);
}
}
} else if (inventoryOpenEvent.getInventory().getHolder() instanceof BlockState && this.checkLineOfSight(player = player2, block3 = (block2 = ((BlockState)inventoryOpenEvent.getInventory().getHolder()).getBlock()), block = null) && this.recordViolation(inventoryOpenEvent.getPlayer().getUniqueId(), 2, HackType.INTERACT, inventoryOpenEvent.getPlayer().getName() + " failed Interact: opened a container out of line of sight", ticks)) {
inventoryOpenEvent.setCancelled(true);
}
}
}
private boolean checkLineOfSight(Player player, Block block, Block block2) {
Player player2 = player;
AxisAlignedBoundingBox axisAlignedBoundingBox = new AxisAlignedBoundingBox(player.getLocation().toVector(), EntityDimensions.forEntity((Entity)player2));
AxisAlignedBoundingBox axisAlignedBoundingBox2 = axisAlignedBoundingBox.union(new AxisAlignedBoundingBox(block.getLocation()));
Player player3 = player;
List list = CollisionAccess.getCollidingBoxes((Entity)player3, axisAlignedBoundingBox2);
list.add(new AxisAlignedBoundingBox(block.getLocation()));
Vector vector = player.getEyeLocation().toVector();
Vector vector2 = player.getLocation().getDirection();
if (this.isPathClearToTarget(vector, vector2, list, block, block2)) {
Vector vector3 = block.getLocation().add(0.5, 0.5, 0.5).subtract(player.getEyeLocation()).toVector().normalize();
if (vector3.distance(vector2) > 0.5) {
return true;
}
for (BlockFace blockFace : new BlockFace[]{BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST, BlockFace.UP, BlockFace.DOWN}) {
Vector vector4 = block.getLocation().add((double)blockFace.getModX() * 0.5, (double)blockFace.getModY() * 0.5, (double)blockFace.getModZ() * 0.5).add(0.5, 0.5, 0.5).subtract(player.getEyeLocation()).toVector().normalize();
if (this.isPathClearToTarget(vector, vector4, list, block, block2)) continue;
return false;
}
return true;
}
return false;
}
/*
* Enabled force condition propagation
* Lifted jumps to return sites
*/
private boolean isPathClearToTarget(Vector vector, Vector vector2, List<AxisAlignedBoundingBox> list, Block block, Block block2) {
AxisAlignedBoundingBox axisAlignedBoundingBox = this.findClosestHitBox(vector, vector2, block2 == null ? list : list.stream().filter(arg_0 -> Interact.isNotTargetBlockBox(block2, arg_0)).collect(Collectors.toList()));
if (axisAlignedBoundingBox == null) {
return true;
}
if (block2 != null && !new AxisAlignedBoundingBox(block2.getLocation()).intersectsRay(vector, vector2)) {
return true;
}
if (!axisAlignedBoundingBox.getMinimum().toLocation(block.getWorld()).getBlock().equals(block)) {
return true;
}
if (block2 == null) return false;
AxisAlignedBoundingBox axisAlignedBoundingBox2 = new AxisAlignedBoundingBox(block2.getLocation());
if (!(axisAlignedBoundingBox.rayTraceDistance(vector, vector2) < axisAlignedBoundingBox2.rayTraceDistance(vector, vector2))) return false;
return true;
}
private AxisAlignedBoundingBox findClosestHitBox(Vector vector, Vector vector2, List<AxisAlignedBoundingBox> list) {
if (list.isEmpty()) {
return null;
}
double d = Double.MAX_VALUE;
AxisAlignedBoundingBox axisAlignedBoundingBox = null;
for (AxisAlignedBoundingBox axisAlignedBoundingBox2 : list) {
double d2 = axisAlignedBoundingBox2.rayTraceDistance(vector, vector2);
if (Double.isNaN(d2) || !(d2 < d)) continue;
d = d2;
axisAlignedBoundingBox = axisAlignedBoundingBox2;
}
return axisAlignedBoundingBox;
}
private static boolean isNotTargetBlockBox(Block block, AxisAlignedBoundingBox axisAlignedBoundingBox) {
return !axisAlignedBoundingBox.getMinimum().toLocation(block.getWorld()).getBlock().equals(block);
}
private void decayInteractViolations() {
Iterator iterator = Bukkit.getOnlinePlayers().iterator();
while (iterator.hasNext()) {
Player player = (Player)iterator.next();
this.decreaseViolationLevel(player.getUniqueId(), 1);
}
}
}
@@ -0,0 +1,62 @@
package me.konsolas.aac.checks.world;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.PacketListener;
import me.konsolas.aac.AAC;
import me.konsolas.aac.checks.Detector;
import me.konsolas.aac.util.MathUtilities;
import me.konsolas.aac.compat.PlayerPingAccess;
import me.konsolas.aac.compat.UseEntityPacket;
import me.konsolas.aac.api.HackType;
import org.bukkit.GameMode;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.plugin.Plugin;
public final class NoSwing
extends Detector {
public NoSwing(AAC aAC) { super(aAC);
NoSwingPacketListener noSwingPacketListener = new NoSwingPacketListener(this, (Plugin)this.plugin, new PacketType[]{UseEntityPacket.TYPE});
this.packetListeners.add(noSwingPacketListener);
ProtocolLibrary.getProtocolManager().addPacketListener((PacketListener)noSwingPacketListener);
}
@EventHandler
public void onBlockBreak(BlockBreakEvent blockBreakEvent) {
Player player;
if (blockBreakEvent.getPlayer().getGameMode() == GameMode.CREATIVE || this.plugin.checkManager.isPlayerExempt(player = blockBreakEvent.getPlayer())) {
return;
}
long now = System.currentTimeMillis();
Player player2 = blockBreakEvent.getPlayer();
AAC aAC = this.plugin;
Server server = this.plugin.getServer();
server.getScheduler().scheduleSyncDelayedTask((Plugin)this.plugin, () -> this.verifyBlockBreakSwing(aAC, player2, now), 5L);
}
private void verifyBlockBreakSwing(AAC aAC, Player player, long ticks) {
long ticks2 = 113218805911140L;
long ticks3 = 103276215108508L;
if (aAC.logManager.isDebugEnabled()) {
aAC.logManager.logPlayerDebug(player, "(NoSwing) BlockBreakEvent lastAnimated[e:" + ticks + ",r:" + aAC.playerState.getLastArmSwingTime(player) + "]");
}
try {
long ticks4 = ticks3;
Player player2 = player;
double d = 299 + PlayerPingAccess.getPing(player2, ticks4);
double d2 = aAC.playerState.getLastArmSwingTime(player);
double d3 = ticks;
if (!MathUtilities.approximatelyEquals(d3, d2, d)) {
this.recordViolation(player.getUniqueId(), 1, HackType.NOSWING, player.getName() + " failed NoSwing: didn't swing arm (block break)", ticks2);
} else {
this.decreaseViolationLevel(player.getUniqueId(), 2);
}
}
catch (NullPointerException nullPointerException) {}
}
}
Loaded 100 of 213 files, more files were not shown because too many files have changed in this diff. Show more