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

@@ -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();
}
}