mirror of
https://github.com/funkemunky/KauriV3.git
synced 2026-07-02 02:28:25 +00:00
New stuffs
This commit is contained in:
@@ -91,6 +91,13 @@ public class Anticheat extends JavaPlugin {
|
||||
true,
|
||||
true);
|
||||
|
||||
if(!getConfig().contains("database.username")) {
|
||||
getConfig().set("database.username", "dbuser");
|
||||
}
|
||||
if(!getConfig().contains("database.password")) {
|
||||
getConfig().set("database.password", UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
this.keepaliveProcessor = new KeepaliveProcessor();
|
||||
this.checkManager = new CheckManager();
|
||||
this.playerRegistry = new PlayerRegistry();
|
||||
|
||||
@@ -9,6 +9,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface CheckData {
|
||||
String name();
|
||||
String checkId();
|
||||
CheckType type();
|
||||
|
||||
boolean enabled() default true;
|
||||
|
||||
@@ -22,7 +22,7 @@ public class CheckStatic {
|
||||
private WrappedConstructor initConst;
|
||||
@Getter
|
||||
private final List<Tuple<WrappedField, Class<?>>> actions = new ArrayList<>(),
|
||||
timedActions = new ArrayList<>();
|
||||
timedActions = new ArrayList<>(), cancellableActions = new ArrayList<>();
|
||||
|
||||
public CheckStatic(WrappedClass checkClass) {
|
||||
this.checkClass = checkClass;
|
||||
@@ -33,7 +33,8 @@ public class CheckStatic {
|
||||
initConst = checkClass.getConstructor(APlayer.class);
|
||||
for (WrappedField field : checkClass.getFields()) {
|
||||
if(!WAction.class.isAssignableFrom(field.getType())
|
||||
&& !TimedWAction.class.isAssignableFrom(field.getType())) continue;
|
||||
&& !WCancellable.class.isAssignableFrom(field.getType())
|
||||
&& !WTimedAction.class.isAssignableFrom(field.getType())) continue;
|
||||
|
||||
Type genericType = field.getField().getGenericType();
|
||||
Type type = null;
|
||||
@@ -59,8 +60,10 @@ public class CheckStatic {
|
||||
|
||||
if(field.getType().equals(WAction.class)) {
|
||||
actions.add(new Tuple<>(field, (Class<?>)type));
|
||||
} else { //This will always be TimedAction
|
||||
} else if(field.getType().equals(WTimedAction.class)) { //This will always be TimedAction
|
||||
timedActions.add(new Tuple<>(field, (Class<?>)type));
|
||||
} else if(field.getType().equals(WCancellable.class)) {
|
||||
cancellableActions.add(new Tuple<>(field, (Class<?>)type));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package dev.brighten.ac.check;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface WCancellable<T> {
|
||||
boolean invoke(T event);
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package dev.brighten.ac.check;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface TimedWAction<T> {
|
||||
public interface WTimedAction<T> {
|
||||
void invoke(T event, long timestamp);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package dev.brighten.ac.check.impl.chat;
|
||||
|
||||
import dev.brighten.ac.api.check.CheckType;
|
||||
import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.check.CheckData;
|
||||
import dev.brighten.ac.check.WCancellable;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInChat;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@CheckData(name = "Log4J", checkId = "log4j", type = CheckType.CHAT)
|
||||
public class Log4J extends Check {
|
||||
|
||||
public Log4J(APlayer player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
private static final Pattern pattern = Pattern.compile("\\$\\{.*}");
|
||||
|
||||
WCancellable<WPacketPlayInChat> chatPacket = packet -> {
|
||||
Matcher matcher = pattern.matcher(packet.getMessage());
|
||||
if(matcher.matches()) {
|
||||
flag("Tried to use JNDI exploit");
|
||||
return true;
|
||||
}
|
||||
|
||||
debug("Sent chat message: " + packet.getMessage());
|
||||
return false;
|
||||
};
|
||||
}
|
||||
@@ -6,13 +6,14 @@ import dev.brighten.ac.check.CheckData;
|
||||
import dev.brighten.ac.api.check.CheckType;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying;
|
||||
import dev.brighten.ac.utils.Async;
|
||||
import dev.brighten.ac.utils.Color;
|
||||
import dev.brighten.ac.utils.timer.Timer;
|
||||
import dev.brighten.ac.utils.timer.impl.TickTimer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@CheckData(name = "Aim", type = CheckType.COMBAT)
|
||||
@CheckData(name = "Aim", checkId = "aima", type = CheckType.COMBAT)
|
||||
public class Aim extends Check {
|
||||
public Aim(APlayer player) {
|
||||
super(player);
|
||||
@@ -22,6 +23,7 @@ public class Aim extends Check {
|
||||
protected Timer lastGrid = new TickTimer(3);
|
||||
|
||||
|
||||
@Async
|
||||
WAction<WPacketPlayInFlying> onFlying = (packet) -> {
|
||||
if(!packet.isLooked()) return;
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.bukkit.util.Vector;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
@CheckData(name = "Hitbox", type = CheckType.COMBAT)
|
||||
@CheckData(name = "Hitbox", checkId = "hitboxa", type = CheckType.COMBAT)
|
||||
public class Hitbox extends Check {
|
||||
private float buffer;
|
||||
private int hbuffer;
|
||||
|
||||
@@ -8,8 +8,9 @@ import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.ProtocolVersion;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInArmAnimation;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying;
|
||||
import dev.brighten.ac.utils.Async;
|
||||
|
||||
@CheckData(name = "AutoClicker (A)", type = CheckType.AUTOCLICKER, maxVersion = ProtocolVersion.V1_8_9)
|
||||
@CheckData(name = "AutoClicker (A)", checkId = "autoclickera", type = CheckType.AUTOCLICKER, maxVersion = ProtocolVersion.V1_8_9)
|
||||
public class AutoclickerA extends Check {
|
||||
public AutoclickerA(APlayer player) {
|
||||
super(player);
|
||||
@@ -17,6 +18,7 @@ public class AutoclickerA extends Check {
|
||||
|
||||
private int flyingTicks, cps;
|
||||
|
||||
@Async
|
||||
WAction<WPacketPlayInFlying> flying = (packet) -> {
|
||||
flyingTicks++;
|
||||
if(flyingTicks >= 20) {
|
||||
@@ -30,6 +32,7 @@ public class AutoclickerA extends Check {
|
||||
}
|
||||
};
|
||||
|
||||
@Async
|
||||
WAction<WPacketPlayInArmAnimation> armAnimation = packet -> {
|
||||
if(!player.getInfo().breakingBlock
|
||||
&& player.getInfo().getLastBlockDig().isPassed(1)
|
||||
|
||||
@@ -3,12 +3,12 @@ package dev.brighten.ac.check.impl.combat.autoclicker;
|
||||
import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.check.CheckData;
|
||||
import dev.brighten.ac.api.check.CheckType;
|
||||
import dev.brighten.ac.check.TimedWAction;
|
||||
import dev.brighten.ac.check.WTimedAction;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInArmAnimation;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying;
|
||||
|
||||
@CheckData(name = "Autoclicker (B)", type = CheckType.AUTOCLICKER)
|
||||
@CheckData(name = "Autoclicker (B)", checkId = "autoclickerb", type = CheckType.AUTOCLICKER)
|
||||
public class AutoclickerB extends Check {
|
||||
public AutoclickerB(APlayer player) {
|
||||
super(player);
|
||||
@@ -17,12 +17,12 @@ public class AutoclickerB extends Check {
|
||||
private long lastFlying;
|
||||
private int buffer;
|
||||
|
||||
TimedWAction<WPacketPlayInFlying> flyingPacket = (packet, timestamp) -> {
|
||||
WTimedAction<WPacketPlayInFlying> flyingPacket = (packet, timestamp) -> {
|
||||
if(player.getMovement().getLastTeleport().isPassed(1))
|
||||
lastFlying = timestamp;
|
||||
};
|
||||
|
||||
TimedWAction<WPacketPlayInArmAnimation> animation = (packet, timestamp) -> {
|
||||
WTimedAction<WPacketPlayInArmAnimation> animation = (packet, timestamp) -> {
|
||||
if(timestamp - lastFlying < 10 && player.getLagInfo().getLastPacketDrop().isPassed(1)) {
|
||||
if(++buffer > 4) {
|
||||
flag("delta=%s", timestamp - lastFlying);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package dev.brighten.ac.check.impl.misc;
|
||||
|
||||
import dev.brighten.ac.api.check.CheckType;
|
||||
import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.check.CheckData;
|
||||
import dev.brighten.ac.check.WAction;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import lombok.val;
|
||||
import org.bukkit.event.player.PlayerEditBookEvent;
|
||||
|
||||
@CheckData(name = "BookOp", checkId = "bookop", type = CheckType.EXPLOIT)
|
||||
public class BookOp extends Check {
|
||||
public BookOp(APlayer player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
WAction<PlayerEditBookEvent> bookEdit = event -> {
|
||||
val optional = event.getNewBookMeta().getPages().stream()
|
||||
.filter(string -> string.toLowerCase().contains("run_command"))
|
||||
.findFirst();
|
||||
if(optional.isPresent()) {
|
||||
vl++;
|
||||
flag("line=" + optional.get());
|
||||
event.setCancelled(true);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -7,12 +7,13 @@ import dev.brighten.ac.api.check.CheckType;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.ProtocolVersion;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying;
|
||||
import dev.brighten.ac.utils.Async;
|
||||
import dev.brighten.ac.utils.MathUtils;
|
||||
import dev.brighten.ac.utils.MovementUtils;
|
||||
import dev.brighten.ac.utils.timer.Timer;
|
||||
import dev.brighten.ac.utils.timer.impl.MillisTimer;
|
||||
|
||||
@CheckData(name = "Fly (A)", type = CheckType.MOVEMENT)
|
||||
@CheckData(name = "Fly (A)", checkId = "flya", type = CheckType.MOVEMENT)
|
||||
public class FlyA extends Check {
|
||||
|
||||
public FlyA(APlayer player) {
|
||||
@@ -24,6 +25,7 @@ public class FlyA extends Check {
|
||||
private static double mult = 0.98f, previousPrediction;
|
||||
private boolean didNextPrediction = false;
|
||||
|
||||
@Async
|
||||
WAction<WPacketPlayInFlying> flying = packet -> {
|
||||
if(!packet.isMoved() || (player.getMovement().getDeltaXZ() == 0
|
||||
&& player.getMovement().getDeltaY() == 0)) {
|
||||
|
||||
@@ -6,10 +6,11 @@ import dev.brighten.ac.check.CheckData;
|
||||
import dev.brighten.ac.api.check.CheckType;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying;
|
||||
import dev.brighten.ac.utils.Async;
|
||||
import dev.brighten.ac.utils.timer.Timer;
|
||||
import dev.brighten.ac.utils.timer.impl.TickTimer;
|
||||
|
||||
@CheckData(name = "Fly (B)", type = CheckType.MOVEMENT)
|
||||
@CheckData(name = "Fly (B)", checkId = "flyb", type = CheckType.MOVEMENT)
|
||||
public class FlyB extends Check {
|
||||
public FlyB(APlayer player) {
|
||||
super(player);
|
||||
@@ -18,6 +19,7 @@ public class FlyB extends Check {
|
||||
private Timer lastNearGround = new TickTimer();
|
||||
private float buffer;
|
||||
|
||||
@Async
|
||||
WAction<WPacketPlayInFlying> flying = packet -> {
|
||||
if(player.getInfo().isNearGround()) lastNearGround.reset();
|
||||
if(!packet.isMoved() || player.getInfo().isGeneralCancel()) return;
|
||||
|
||||
@@ -1,17 +1,23 @@
|
||||
package dev.brighten.ac.check.impl.movement.fly;
|
||||
|
||||
import dev.brighten.ac.api.check.CheckType;
|
||||
import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.check.CheckData;
|
||||
import dev.brighten.ac.check.WAction;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying;
|
||||
import dev.brighten.ac.packet.wrapper.out.WPacketPlayOutEntityVelocity;
|
||||
import dev.brighten.ac.utils.Async;
|
||||
|
||||
@CheckData(name = "Fly (C)", checkId = "flyc", type = CheckType.MOVEMENT)
|
||||
public class FlyC extends Check {
|
||||
public FlyC(APlayer player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Async
|
||||
WAction<WPacketPlayInFlying> flyingAction = packet -> {
|
||||
boolean ground =
|
||||
boolean ground = player.getMovement().getTo().isOnGround(),
|
||||
fground = player.getMovement().getFrom().isOnGround();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,8 +6,9 @@ import dev.brighten.ac.check.CheckData;
|
||||
import dev.brighten.ac.api.check.CheckType;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying;
|
||||
import dev.brighten.ac.utils.Async;
|
||||
|
||||
@CheckData(name = "NoFall (A)", type = CheckType.MOVEMENT)
|
||||
@CheckData(name = "NoFall (A)", checkId = "nofalla", type = CheckType.MOVEMENT)
|
||||
public class NoFallA extends Check {
|
||||
|
||||
public NoFallA(APlayer player) {
|
||||
@@ -17,6 +18,7 @@ public class NoFallA extends Check {
|
||||
private static double divisor = 1. / 64.;
|
||||
private float buffer;
|
||||
|
||||
@Async
|
||||
WAction<WPacketPlayInFlying> flying = packet -> {
|
||||
if(player.getInfo().isGeneralCancel()
|
||||
|| (player.getMovement().getDeltaXZ() == 0 && player.getMovement().getDeltaY() == 0)
|
||||
|
||||
@@ -6,8 +6,9 @@ import dev.brighten.ac.check.CheckData;
|
||||
import dev.brighten.ac.api.check.CheckType;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying;
|
||||
import dev.brighten.ac.utils.Async;
|
||||
|
||||
@CheckData(name = "NoFall (B)", type = CheckType.MOVEMENT)
|
||||
@CheckData(name = "NoFall (B)", checkId = "nofallb", type = CheckType.MOVEMENT)
|
||||
public class NoFallB extends Check {
|
||||
|
||||
public NoFallB(APlayer player) {
|
||||
@@ -18,6 +19,7 @@ public class NoFallB extends Check {
|
||||
|
||||
private int airBuffer, groundBuffer;
|
||||
|
||||
@Async
|
||||
WAction<WPacketPlayInFlying> flying = packet -> {
|
||||
if(player.getMovement().getLastTeleport().isNotPassed(3)
|
||||
|| player.getMovement().getMoveTicks() < 2
|
||||
|
||||
@@ -7,6 +7,7 @@ import dev.brighten.ac.api.check.CheckType;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.ProtocolVersion;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying;
|
||||
import dev.brighten.ac.utils.Async;
|
||||
import dev.brighten.ac.utils.BlockUtils;
|
||||
import dev.brighten.ac.utils.MathHelper;
|
||||
import dev.brighten.ac.utils.math.IntVector;
|
||||
@@ -18,7 +19,7 @@ import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.Deque;
|
||||
|
||||
@CheckData(name = "Horizontal", type = CheckType.MOVEMENT)
|
||||
@CheckData(name = "Horizontal", checkId = "horizontala", type = CheckType.MOVEMENT)
|
||||
public class Horizontal extends Check {
|
||||
private boolean lastLastClientGround;
|
||||
private float buffer;
|
||||
@@ -33,6 +34,7 @@ public class Horizontal extends Check {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Async
|
||||
WAction<WPacketPlayInFlying> flying = packet -> {
|
||||
Block underBlock = BlockUtils.getBlock(player.getMovement().getTo().getLoc()
|
||||
.toLocation(player.getBukkitPlayer().getWorld())
|
||||
@@ -219,7 +221,7 @@ public class Horizontal extends Check {
|
||||
pmotionx = lmotionX;
|
||||
pmotionz = lmotionZ;
|
||||
|
||||
if (delta < 1E-15) {
|
||||
if (delta < 4E-17) {
|
||||
this.strafe = s * 0.98f;
|
||||
this.forward = f * 0.98f;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@CheckData(name = "Velocity (A)", type = CheckType.MOVEMENT)
|
||||
@CheckData(name = "Velocity (A)", checkId = "velocitya", type = CheckType.MOVEMENT)
|
||||
public class VelocityA extends Check {
|
||||
|
||||
private Vector currentVelocity = null;
|
||||
|
||||
@@ -134,7 +134,7 @@ public class VelocityB extends Check {
|
||||
|
||||
found = true;
|
||||
if(!velocity.isPresent()) {
|
||||
Horizontal speedCheck = (Horizontal) player.findCheck(Horizontal.class);
|
||||
Horizontal speedCheck = (Horizontal) player.getCheckHandler().findCheck(Horizontal.class);
|
||||
double s2 = speedCheck.strafe;
|
||||
double f2 = speedCheck.forward;
|
||||
|
||||
|
||||
@@ -3,12 +3,12 @@ package dev.brighten.ac.check.impl.order;
|
||||
import dev.brighten.ac.api.check.CheckType;
|
||||
import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.check.CheckData;
|
||||
import dev.brighten.ac.check.TimedWAction;
|
||||
import dev.brighten.ac.check.WTimedAction;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInBlockPlace;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying;
|
||||
|
||||
@CheckData(name = "Order (Place)", type = CheckType.ORDER, punishVl = 4)
|
||||
@CheckData(name = "Order (Place)", checkId = "order_place", type = CheckType.ORDER, punishVl = 4)
|
||||
public class Place extends Check {
|
||||
public Place(APlayer player) {
|
||||
super(player);
|
||||
@@ -17,7 +17,7 @@ public class Place extends Check {
|
||||
private long lastFlying;
|
||||
private int buffer;
|
||||
|
||||
TimedWAction<WPacketPlayInBlockPlace> placePacket = (packet, timestamp) -> {
|
||||
WTimedAction<WPacketPlayInBlockPlace> placePacket = (packet, timestamp) -> {
|
||||
if(timestamp - lastFlying < 10 && player.getLagInfo().getLastPacketDrop().isPassed(1)) {
|
||||
if(++buffer > 4) {
|
||||
buffer = 5;
|
||||
@@ -28,7 +28,7 @@ public class Place extends Check {
|
||||
debug("buffer=%s delta=%sms", buffer, timestamp - lastFlying);
|
||||
};
|
||||
|
||||
TimedWAction<WPacketPlayInFlying> flying = (packet, timestamp) -> {
|
||||
WTimedAction<WPacketPlayInFlying> flying = (packet, timestamp) -> {
|
||||
if(player.getMovement().getLastTeleport().isPassed(1))
|
||||
lastFlying = timestamp;
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.api.check.CheckType;
|
||||
import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.check.CheckData;
|
||||
import dev.brighten.ac.check.TimedWAction;
|
||||
import dev.brighten.ac.check.WTimedAction;
|
||||
import dev.brighten.ac.check.WAction;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.ProtocolVersion;
|
||||
@@ -14,7 +14,7 @@ import dev.brighten.ac.packet.wrapper.out.WPacketPlayOutPosition;
|
||||
import dev.brighten.ac.utils.timer.impl.TickTimer;
|
||||
import net.minecraft.server.v1_8_R3.PacketPlayInTransaction;
|
||||
|
||||
@CheckData(name = "Timer", type = CheckType.ORDER)
|
||||
@CheckData(name = "Timer", checkId = "timer", type = CheckType.ORDER)
|
||||
public class Timer extends Check {
|
||||
|
||||
public Timer(APlayer player) {
|
||||
@@ -38,7 +38,7 @@ public class Timer extends Check {
|
||||
/**
|
||||
* Fixing bug with 1.9 since flying packets are not always sent
|
||||
*/
|
||||
TimedWAction<PacketPlayInTransaction> transaction = (packet, timestamp) -> {
|
||||
WTimedAction<PacketPlayInTransaction> transaction = (packet, timestamp) -> {
|
||||
if(player.getPlayerVersion().isBelow(ProtocolVersion.V1_9)) return;
|
||||
|
||||
Anticheat.INSTANCE.getKeepaliveProcessor().getKeepById(packet.b()).ifPresent(ka -> {
|
||||
@@ -50,7 +50,7 @@ public class Timer extends Check {
|
||||
});
|
||||
};
|
||||
|
||||
TimedWAction<WPacketPlayInFlying> flying = (packet, timestamp) -> {
|
||||
WTimedAction<WPacketPlayInFlying> flying = (packet, timestamp) -> {
|
||||
if(totalTimer == -1) {
|
||||
totalTimer = player.getCreation().getCurrent() - 50;
|
||||
debug("set base time");
|
||||
|
||||
@@ -3,12 +3,12 @@ package dev.brighten.ac.check.impl.order;
|
||||
import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.check.CheckData;
|
||||
import dev.brighten.ac.api.check.CheckType;
|
||||
import dev.brighten.ac.check.TimedWAction;
|
||||
import dev.brighten.ac.check.WTimedAction;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInUseEntity;
|
||||
|
||||
@CheckData(name = "Order (Use)", type = CheckType.ORDER)
|
||||
@CheckData(name = "Order (Use)", checkId = "order_use", type = CheckType.ORDER)
|
||||
public class UseEntity extends Check {
|
||||
|
||||
private long lastFlying;
|
||||
@@ -18,7 +18,7 @@ public class UseEntity extends Check {
|
||||
super(player);
|
||||
}
|
||||
|
||||
TimedWAction<WPacketPlayInUseEntity> useEntity = (packet, timestamp) -> {
|
||||
WTimedAction<WPacketPlayInUseEntity> useEntity = (packet, timestamp) -> {
|
||||
if(timestamp - lastFlying < 10 && player.getLagInfo().getLastPacketDrop().isPassed(1)) {
|
||||
if(++buffer > 5) {
|
||||
buffer = 6;
|
||||
@@ -27,7 +27,7 @@ public class UseEntity extends Check {
|
||||
} else if(buffer > 0) buffer--;
|
||||
};
|
||||
|
||||
TimedWAction<WPacketPlayInFlying> flying = (packet, timestamp) -> {
|
||||
WTimedAction<WPacketPlayInFlying> flying = (packet, timestamp) -> {
|
||||
if(player.getMovement().getLastTeleport().isPassed(0))
|
||||
lastFlying = timestamp;
|
||||
};
|
||||
|
||||
@@ -8,10 +8,7 @@ import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.ProtocolVersion;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInBlockPlace;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying;
|
||||
import dev.brighten.ac.utils.BlockUtils;
|
||||
import dev.brighten.ac.utils.KLocation;
|
||||
import dev.brighten.ac.utils.MathUtils;
|
||||
import dev.brighten.ac.utils.Tuple;
|
||||
import dev.brighten.ac.utils.*;
|
||||
import dev.brighten.ac.utils.math.cond.MaxDouble;
|
||||
import dev.brighten.ac.utils.world.BlockData;
|
||||
import dev.brighten.ac.utils.world.CollisionBox;
|
||||
@@ -24,7 +21,7 @@ import java.util.Optional;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
@CheckData(name = "Block (A)", type = CheckType.INTERACT)
|
||||
@CheckData(name = "Block (A)", checkId = "blocka", type = CheckType.INTERACT)
|
||||
public class BlockA extends Check {
|
||||
public BlockA(APlayer player) {
|
||||
super(player);
|
||||
@@ -33,6 +30,7 @@ public class BlockA extends Check {
|
||||
private final MaxDouble verbose = new MaxDouble(20);
|
||||
private Queue<Tuple<Block, SimpleCollisionBox>> blockPlacements = new LinkedBlockingQueue<>();
|
||||
|
||||
@Async
|
||||
WAction<WPacketPlayInBlockPlace> blockPlace = packet -> {
|
||||
Location loc = packet.getBlockPos().toBukkitVector().toLocation(player.getBukkitPlayer().getWorld());
|
||||
Optional<Block> optionalBlock = BlockUtils.getBlockAsync(loc);
|
||||
@@ -63,6 +61,7 @@ public class BlockA extends Check {
|
||||
blockPlacements.add(new Tuple<>(block, simpleBox.expand(0.1)));
|
||||
};
|
||||
|
||||
@Async
|
||||
WAction<WPacketPlayInFlying> flying = packet -> {
|
||||
Tuple<Block, SimpleCollisionBox> tuple;
|
||||
|
||||
|
||||
@@ -5,15 +5,17 @@ import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.check.CheckData;
|
||||
import dev.brighten.ac.api.check.CheckType;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.utils.Async;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
@CheckData(name = "Block (B)", type = CheckType.INTERACT)
|
||||
@CheckData(name = "Block (B)", checkId = "blockb", type = CheckType.INTERACT)
|
||||
public class BlockB extends Check {
|
||||
public BlockB(APlayer player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Async
|
||||
WAction<BlockPlaceEvent> blockPlaceEvent = event -> {
|
||||
Block ba = event.getBlockAgainst();
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package dev.brighten.ac.check.impl.world;
|
||||
|
||||
import dev.brighten.ac.check.WAction;
|
||||
import dev.brighten.ac.api.check.CheckType;
|
||||
import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.check.CheckData;
|
||||
import dev.brighten.ac.api.check.CheckType;
|
||||
import dev.brighten.ac.check.WTimedAction;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInBlockPlace;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying;
|
||||
import dev.brighten.ac.utils.KLocation;
|
||||
|
||||
@CheckData(name = "Block (C)", type = CheckType.INTERACT)
|
||||
@CheckData(name = "Block (C)", checkId = "blockc", type = CheckType.INTERACT)
|
||||
public class BlockC extends Check {
|
||||
|
||||
private long lastPlace;
|
||||
@@ -20,9 +20,8 @@ public class BlockC extends Check {
|
||||
super(player);
|
||||
}
|
||||
|
||||
WAction<WPacketPlayInFlying> flying = packet -> {
|
||||
WTimedAction<WPacketPlayInFlying> flying = (packet, timestamp) -> {
|
||||
if(player.getInfo().isCreative() || player.getMovement().isExcuseNextFlying()) return;
|
||||
long timestamp = System.currentTimeMillis();
|
||||
if(place) {
|
||||
long delta = timestamp - lastPlace;
|
||||
if(delta >= 25) {
|
||||
@@ -34,11 +33,10 @@ public class BlockC extends Check {
|
||||
}
|
||||
};
|
||||
|
||||
WAction<WPacketPlayInBlockPlace> blockPlace = packet -> {
|
||||
WTimedAction<WPacketPlayInBlockPlace> blockPlace = (packet, timestamp) -> {
|
||||
if(player.pastLocations.isEmpty()) return;
|
||||
|
||||
KLocation lastMovePacket = player.pastLocations.getLast().one;
|
||||
long timestamp = System.currentTimeMillis();
|
||||
|
||||
if(lastMovePacket == null) return;
|
||||
|
||||
|
||||
@@ -2,14 +2,8 @@ package dev.brighten.ac.data;
|
||||
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.check.*;
|
||||
import dev.brighten.ac.data.handlers.BlockInformation;
|
||||
import dev.brighten.ac.data.handlers.GeneralInformation;
|
||||
import dev.brighten.ac.data.handlers.LagInformation;
|
||||
import dev.brighten.ac.data.handlers.MovementHandler;
|
||||
import dev.brighten.ac.data.obj.ActionStore;
|
||||
import dev.brighten.ac.data.obj.InstantAction;
|
||||
import dev.brighten.ac.data.obj.NormalAction;
|
||||
import dev.brighten.ac.data.obj.TimedActionStore;
|
||||
import dev.brighten.ac.data.handlers.*;
|
||||
import dev.brighten.ac.data.obj.*;
|
||||
import dev.brighten.ac.handler.EntityLocationHandler;
|
||||
import dev.brighten.ac.handler.PotionHandler;
|
||||
import dev.brighten.ac.handler.VelocityHandler;
|
||||
@@ -45,7 +39,6 @@ public class APlayer {
|
||||
private final Player bukkitPlayer;
|
||||
@Getter
|
||||
private final UUID uuid;
|
||||
private final List<Check> checks = new ArrayList<>();
|
||||
@Getter
|
||||
private MovementHandler movement;
|
||||
@Getter
|
||||
@@ -60,6 +53,9 @@ public class APlayer {
|
||||
@Getter
|
||||
private BlockUpdateHandler blockUpdateHandler;
|
||||
|
||||
@Getter
|
||||
private CheckHandler checkHandler;
|
||||
|
||||
@Getter
|
||||
private GeneralInformation info;
|
||||
@Getter
|
||||
@@ -89,8 +85,7 @@ public class APlayer {
|
||||
private final List<Consumer<Vector>> onVelocityTasks = new ArrayList<>();
|
||||
public final EvictingList<Tuple<KLocation, Double>> pastLocations = new EvictingList<>(20);
|
||||
|
||||
private final Map<Class<?>, ActionStore[]> events = new HashMap<>();
|
||||
private final Map<Class<?>, TimedActionStore[]> eventsWithTimestamp = new HashMap<>();
|
||||
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@@ -103,87 +98,26 @@ public class APlayer {
|
||||
load();
|
||||
}
|
||||
|
||||
private final Map<Class<? extends Check>, Check> checkCache = new HashMap<>();
|
||||
|
||||
public synchronized Check findCheck(Class<? extends Check> checkClass) {
|
||||
return checkCache.computeIfAbsent(checkClass, key -> {
|
||||
for (Check check : checks) {
|
||||
if (check.getClass().equals(key)) {
|
||||
return check;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
private void load() {
|
||||
synchronized (checks) {
|
||||
for (CheckStatic check : Anticheat.INSTANCE.getCheckManager().getCheckClasses().values()) {
|
||||
checks.add(check.playerInit(this));
|
||||
}
|
||||
}
|
||||
this.movement = new MovementHandler(this);
|
||||
this.potionHandler = new PotionHandler(this);
|
||||
this.velocityHandler = new VelocityHandler(this);
|
||||
this.entityLocationHandler = new EntityLocationHandler(this);
|
||||
this.blockUpdateHandler = new BlockUpdateHandler(this);
|
||||
this.checkHandler = new CheckHandler(this);
|
||||
this.info = new GeneralInformation();
|
||||
this.lagInfo = new LagInformation();
|
||||
this.blockInfo = new BlockInformation(this);
|
||||
|
||||
creation.reset();
|
||||
|
||||
// Grabbing the protocol version of the player.
|
||||
Anticheat.INSTANCE.getScheduler().execute(() -> {
|
||||
playerVersion = ProtocolVersion.getVersion(ProtocolAPI.INSTANCE.getPlayerVersion(getBukkitPlayer()));
|
||||
|
||||
// Enabling checks for players on join
|
||||
for (CheckStatic checkClass : Anticheat.INSTANCE.getCheckManager().getCheckClasses().values()) {
|
||||
CheckData data = checkClass.getCheckClass().getAnnotation(CheckData.class);
|
||||
|
||||
//Version checks
|
||||
if(playerVersion.isAbove(data.maxVersion()) || playerVersion.isBelow(data.minVersion())) {
|
||||
Anticheat.INSTANCE.alog("Player " + getBukkitPlayer().getName() +
|
||||
" is not on the right version for check " + data.name()
|
||||
+ " (version: " + playerVersion.name() + ")");
|
||||
continue;
|
||||
}
|
||||
|
||||
Check check = checkClass.playerInit(this);
|
||||
|
||||
synchronized (events) {
|
||||
for (Tuple<WrappedField, Class<?>> tuple : checkClass.getActions()) {
|
||||
WAction<?> action = tuple.one.get(check);
|
||||
|
||||
events.compute(tuple.two, (packetClass, array) -> {
|
||||
if (array == null) {
|
||||
return new ActionStore[] {new ActionStore(action, checkClass.getCheckClass().getParent())};
|
||||
} else {
|
||||
ActionStore[] newArray = Arrays.copyOf(array, array.length + 1);
|
||||
newArray[array.length] = new ActionStore(action, checkClass.getCheckClass().getParent());
|
||||
return newArray;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
synchronized (eventsWithTimestamp) {
|
||||
for (Tuple<WrappedField, Class<?>> tuple : checkClass.getTimedActions()) {
|
||||
TimedWAction<?> action = tuple.one.get(check);
|
||||
|
||||
eventsWithTimestamp.compute(tuple.two, (packetClass, array) -> {
|
||||
if (array == null) {
|
||||
return new TimedActionStore[] {new TimedActionStore(action, checkClass.getCheckClass().getParent())};
|
||||
} else {
|
||||
TimedActionStore[] newArray = Arrays.copyOf(array, array.length + 1);
|
||||
newArray[array.length] = new TimedActionStore(action, checkClass.getCheckClass().getParent());
|
||||
return newArray;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
checkHandler.initChecks();
|
||||
});
|
||||
|
||||
creation.reset();
|
||||
|
||||
// Enabling alerts for players on join if they have the permissions to
|
||||
if(getBukkitPlayer().hasPermission("anticheat.command.alerts")
|
||||
|| getBukkitPlayer().hasPermission("anticheat.alerts")) {
|
||||
@@ -193,45 +127,11 @@ public class APlayer {
|
||||
}
|
||||
|
||||
protected void unload() {
|
||||
checks.clear();
|
||||
this.info = null;
|
||||
this.lagInfo = null;
|
||||
this.movement = null;
|
||||
}
|
||||
|
||||
public void disableCheck(String checkName) {
|
||||
|
||||
}
|
||||
|
||||
public void callEvent(Event event) {
|
||||
if(events.containsKey(event.getClass())) {
|
||||
ActionStore<Event>[] actions = (ActionStore<Event>[]) events.get(event.getClass());
|
||||
for (ActionStore<Event> action : actions) {
|
||||
action.getAction().invoke(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO When using WPacket wrappers only, make this strictly WPacket param based only
|
||||
public void callPacket(Object packet, long timestamp) {
|
||||
if(events.containsKey(packet.getClass())) {
|
||||
synchronized (events) {
|
||||
ActionStore<Object>[] actions = events.get(packet.getClass());
|
||||
for (ActionStore<Object> action : actions) {
|
||||
action.getAction().invoke(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(eventsWithTimestamp.containsKey(packet.getClass())) {
|
||||
synchronized (events) {
|
||||
TimedActionStore<Object>[] actions = eventsWithTimestamp.get(packet.getClass());
|
||||
for (TimedActionStore<Object> action : actions) {
|
||||
action.getAction().invoke(packet, timestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int runKeepaliveAction(Consumer<KeepAlive> action) {
|
||||
return runKeepaliveAction(action, 0);
|
||||
|
||||
@@ -0,0 +1,226 @@
|
||||
package dev.brighten.ac.data.handlers;
|
||||
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.check.*;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.data.obj.ActionStore;
|
||||
import dev.brighten.ac.data.obj.CancellableActionStore;
|
||||
import dev.brighten.ac.data.obj.TimedActionStore;
|
||||
import dev.brighten.ac.handler.thread.ThreadHandler;
|
||||
import dev.brighten.ac.utils.Async;
|
||||
import dev.brighten.ac.utils.Tuple;
|
||||
import dev.brighten.ac.utils.reflections.types.WrappedField;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.event.Event;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class CheckHandler {
|
||||
private final Map<Class<?>, ActionStore[]> events = new HashMap<>();
|
||||
private final Map<Class<?>, TimedActionStore[]> eventsWithTimestamp = new HashMap<>();
|
||||
private final Map<Class<?>, CancellableActionStore[]> cancellableEvents = new HashMap<>();
|
||||
|
||||
private final Map<Class<?>, ActionStore[]> async_events = new HashMap<>();
|
||||
private final Map<Class<?>, TimedActionStore[]> async_eventsWithTimestamp = new HashMap<>();
|
||||
|
||||
private final Map<Class<? extends Check>, Check> checkCache = new HashMap<>();
|
||||
|
||||
private final List<Check> checks = new ArrayList<>();
|
||||
|
||||
private final APlayer player;
|
||||
|
||||
public synchronized Check findCheck(Class<? extends Check> checkClass) {
|
||||
return checkCache.computeIfAbsent(checkClass, key -> {
|
||||
for (Check check : checks) {
|
||||
if (check.getClass().equals(key)) {
|
||||
return check;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
public void initChecks() {
|
||||
// Enabling checks for players on join
|
||||
for (CheckStatic checkClass : Anticheat.INSTANCE.getCheckManager().getCheckClasses().values()) {
|
||||
CheckData data = checkClass.getCheckClass().getAnnotation(CheckData.class);
|
||||
|
||||
//Version checks
|
||||
if(player.getPlayerVersion().isAbove(data.maxVersion()) || player.getPlayerVersion().isBelow(data.minVersion())) {
|
||||
Anticheat.INSTANCE.alog("Player " + player.getBukkitPlayer().getName() +
|
||||
" is not on the right version for check " + data.name()
|
||||
+ " (version: " + player.getPlayerVersion().name() + ")");
|
||||
continue;
|
||||
}
|
||||
|
||||
Check check = checkClass.playerInit(player);
|
||||
|
||||
checks.add(check);
|
||||
|
||||
synchronized (events) {
|
||||
for (Tuple<WrappedField, Class<?>> tuple : checkClass.getActions()) {
|
||||
WAction<?> action = tuple.one.get(check);
|
||||
|
||||
if(!action.getClass().isAnnotationPresent(Async.class)) {
|
||||
events.compute(tuple.two, (packetClass, array) -> {
|
||||
if (array == null) {
|
||||
return new ActionStore[] {new ActionStore(action, checkClass.getCheckClass().getParent())};
|
||||
} else {
|
||||
ActionStore[] newArray = Arrays.copyOf(array, array.length + 1);
|
||||
newArray[array.length] = new ActionStore(action, checkClass.getCheckClass().getParent());
|
||||
return newArray;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
synchronized (async_events) {
|
||||
for (Tuple<WrappedField, Class<?>> tuple : checkClass.getActions()) {
|
||||
WAction<?> action = tuple.one.get(check);
|
||||
|
||||
if(action.getClass().isAnnotationPresent(Async.class)) {
|
||||
async_events.compute(tuple.two, (packetClass, array) -> {
|
||||
if (array == null) {
|
||||
return new ActionStore[] {new ActionStore(action, checkClass.getCheckClass().getParent())};
|
||||
} else {
|
||||
ActionStore[] newArray = Arrays.copyOf(array, array.length + 1);
|
||||
newArray[array.length] = new ActionStore(action, checkClass.getCheckClass().getParent());
|
||||
return newArray;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
synchronized (eventsWithTimestamp) {
|
||||
for (Tuple<WrappedField, Class<?>> tuple : checkClass.getTimedActions()) {
|
||||
WTimedAction<?> action = tuple.one.get(check);
|
||||
|
||||
if(!action.getClass().isAnnotationPresent(Async.class)) {
|
||||
eventsWithTimestamp.compute(tuple.two, (packetClass, array) -> {
|
||||
if (array == null) {
|
||||
return new TimedActionStore[] {new TimedActionStore(action, checkClass.getCheckClass().getParent())};
|
||||
} else {
|
||||
TimedActionStore[] newArray = Arrays.copyOf(array, array.length + 1);
|
||||
newArray[array.length] = new TimedActionStore(action, checkClass.getCheckClass().getParent());
|
||||
return newArray;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
synchronized (async_eventsWithTimestamp) {
|
||||
for (Tuple<WrappedField, Class<?>> tuple : checkClass.getTimedActions()) {
|
||||
WTimedAction<?> action = tuple.one.get(check);
|
||||
|
||||
if(action.getClass().isAnnotationPresent(Async.class)) {
|
||||
async_eventsWithTimestamp.compute(tuple.two, (packetClass, array) -> {
|
||||
if (array == null) {
|
||||
return new TimedActionStore[] {new TimedActionStore(action, checkClass.getCheckClass().getParent())};
|
||||
} else {
|
||||
TimedActionStore[] newArray = Arrays.copyOf(array, array.length + 1);
|
||||
newArray[array.length] = new TimedActionStore(action, checkClass.getCheckClass().getParent());
|
||||
return newArray;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
synchronized (cancellableEvents) {
|
||||
for (Tuple<WrappedField, Class<?>> tuple : checkClass.getTimedActions()) {
|
||||
WCancellable<?> action = tuple.one.get(check);
|
||||
|
||||
if(!action.getClass().isAnnotationPresent(Async.class)) {
|
||||
cancellableEvents.compute(tuple.two, (packetClass, array) -> {
|
||||
if (array == null) {
|
||||
return new CancellableActionStore[] {new CancellableActionStore(action, checkClass.getCheckClass().getParent())};
|
||||
} else {
|
||||
CancellableActionStore[] newArray = Arrays.copyOf(array, array.length + 1);
|
||||
newArray[array.length] = new CancellableActionStore(action, checkClass.getCheckClass().getParent());
|
||||
return newArray;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
Anticheat.INSTANCE.alog("WARNING: Async action " + action.getClass().getSimpleName() + " is not cancellable");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
checks.clear();
|
||||
events.clear();
|
||||
eventsWithTimestamp.clear();
|
||||
cancellableEvents.clear();
|
||||
async_events.clear();
|
||||
async_eventsWithTimestamp.clear();
|
||||
}
|
||||
|
||||
public void disableCheck(String checkName) {
|
||||
|
||||
}
|
||||
|
||||
public void callEvent(Event event) {
|
||||
if(events.containsKey(event.getClass())) {
|
||||
ActionStore<Event>[] actions = (ActionStore<Event>[]) events.get(event.getClass());
|
||||
for (ActionStore<Event> action : actions) {
|
||||
action.getAction().invoke(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//TODO When using WPacket wrappers only, make this strictly WPacket param based only
|
||||
public void callPacket(Object packet, long timestamp) {
|
||||
ThreadHandler.INSTANCE.getThread(player).getThread().execute(() -> {
|
||||
if(async_events.containsKey(packet.getClass())) {
|
||||
synchronized (events) {
|
||||
ActionStore<Object>[] actions = async_events.get(packet.getClass());
|
||||
for (ActionStore<Object> action : actions) {
|
||||
action.getAction().invoke(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(async_eventsWithTimestamp.containsKey(packet.getClass())) {
|
||||
synchronized (events) {
|
||||
TimedActionStore<Object>[] actions = async_eventsWithTimestamp.get(packet.getClass());
|
||||
for (TimedActionStore<Object> action : actions) {
|
||||
action.getAction().invoke(packet, timestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean callSyncPacket(Object packet, long timestamp) {
|
||||
if(events.containsKey(packet.getClass())) {
|
||||
synchronized (events) {
|
||||
ActionStore<Object>[] actions = events.get(packet.getClass());
|
||||
for (ActionStore<Object> action : actions) {
|
||||
action.getAction().invoke(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(eventsWithTimestamp.containsKey(packet.getClass())) {
|
||||
synchronized (events) {
|
||||
TimedActionStore<Object>[] actions = eventsWithTimestamp.get(packet.getClass());
|
||||
for (TimedActionStore<Object> action : actions) {
|
||||
action.getAction().invoke(packet, timestamp);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(cancellableEvents.containsKey(packet.getClass())) {
|
||||
boolean cancelled = false;
|
||||
synchronized (cancellableEvents) {
|
||||
CancellableActionStore<Object>[] actions = cancellableEvents.get(packet.getClass());
|
||||
for (CancellableActionStore<Object> action : actions) {
|
||||
if(action.getAction().invoke(packet)) {
|
||||
cancelled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return cancelled;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -19,4 +19,24 @@ public class CMove {
|
||||
this.box = move.getBox();
|
||||
this.onGround = move.isOnGround();
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return loc.x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return loc.y;
|
||||
}
|
||||
|
||||
public double getZ() {
|
||||
return loc.z;
|
||||
}
|
||||
|
||||
public float getYaw() {
|
||||
return loc.yaw;
|
||||
}
|
||||
|
||||
public float getPitch() {
|
||||
return loc.pitch;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package dev.brighten.ac.data.obj;
|
||||
|
||||
import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.check.WCancellable;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class CancellableActionStore<T> {
|
||||
private final WCancellable<T> action;
|
||||
private final Class<? extends Check> checkClass;
|
||||
private final UUID uuid = UUID.randomUUID();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
CancellableActionStore that = (CancellableActionStore) o;
|
||||
return uuid.equals(that.uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(uuid);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.brighten.ac.data.obj;
|
||||
|
||||
import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.check.TimedWAction;
|
||||
import dev.brighten.ac.check.WTimedAction;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.UUID;
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public class TimedActionStore<T> {
|
||||
private final TimedWAction<T> action;
|
||||
private final WTimedAction<T> action;
|
||||
private final Class<? extends Check> checkClass;
|
||||
//To ensure duplicate actions are not added to the list
|
||||
private final UUID uuid = UUID.randomUUID();
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.brighten.ac.handler;
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.data.obj.NormalAction;
|
||||
import dev.brighten.ac.handler.thread.ThreadHandler;
|
||||
import dev.brighten.ac.packet.ProtocolVersion;
|
||||
import dev.brighten.ac.packet.wrapper.PacketType;
|
||||
import dev.brighten.ac.packet.wrapper.in.*;
|
||||
@@ -25,7 +26,7 @@ import java.util.*;
|
||||
|
||||
public class PacketHandler {
|
||||
|
||||
public void process(APlayer player, PacketType type, Object packetObject) {
|
||||
public boolean process(APlayer player, PacketType type, Object packetObject) {
|
||||
long timestamp = System.currentTimeMillis();
|
||||
switch (type) {
|
||||
case CLIENT_TRANSACTION: {
|
||||
@@ -110,7 +111,7 @@ public class PacketHandler {
|
||||
|
||||
if(player.getMovement().isExcuseNextFlying()) {
|
||||
player.getMovement().setExcuseNextFlying(false);
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (timestamp - player.getLagInfo().getLastFlying() <= 15) {
|
||||
@@ -304,12 +305,16 @@ public class PacketHandler {
|
||||
"" + type.name() + ": " + packetObject.toString());
|
||||
}
|
||||
|
||||
player.callPacket(packetObject, timestamp);
|
||||
boolean cancelled = player.getCheckHandler().callSyncPacket(packetObject, timestamp);
|
||||
ThreadHandler.INSTANCE.getThread(player).getThread()
|
||||
.execute(() -> player.getCheckHandler().callPacket(packetObject, timestamp));
|
||||
|
||||
// Post flying settings
|
||||
if(type.equals(PacketType.FLYING)) {
|
||||
player.getVelocityHandler().onFlyingPost((WPacketPlayInFlying)packetObject);
|
||||
player.getInfo().lsneaking = player.getInfo().sneaking;
|
||||
}
|
||||
|
||||
return cancelled;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,14 @@ import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||
import org.bukkit.event.player.PlayerEditBookEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
|
||||
@Init
|
||||
public class GeneralListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onDamage(EntityDamageByEntityEvent event) {
|
||||
if(event.getDamager() instanceof Player) {
|
||||
APlayer player = Anticheat.INSTANCE.getPlayerRegistry().getPlayer(event.getDamager().getUniqueId()).
|
||||
@@ -38,18 +39,23 @@ public class GeneralListener implements Listener {
|
||||
});
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBookEdit(PlayerEditBookEvent event) {
|
||||
Anticheat.INSTANCE.getPlayerRegistry().getPlayer(event.getPlayer().getUniqueId())
|
||||
.ifPresent(player -> player.getCheckHandler().callEvent(event));
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onTeleport(PlayerTeleportEvent event) {
|
||||
if(event.getFrom().getWorld().equals(event.getTo().getWorld()) || event.isCancelled()) return;
|
||||
if(event.getFrom().getWorld().equals(event.getTo().getWorld())) return;
|
||||
|
||||
Anticheat.INSTANCE.getPlayerRegistry().getPlayer(event.getPlayer().getUniqueId())
|
||||
.ifPresent(player -> player.getBlockUpdateHandler().onWorldChange());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlace(BlockPlaceEvent event) {
|
||||
if(!event.isCancelled())
|
||||
Anticheat.INSTANCE.getPlayerRegistry().getPlayer(event.getPlayer().getUniqueId())
|
||||
.ifPresent(player -> player.callEvent(event));
|
||||
Anticheat.INSTANCE.getPlayerRegistry().getPlayer(event.getPlayer().getUniqueId())
|
||||
.ifPresent(player -> player.getCheckHandler().callEvent(event));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,8 +24,12 @@ public class JoinListener implements Listener {
|
||||
Optional<APlayer> aplayer = Anticheat.INSTANCE.getPlayerRegistry()
|
||||
.getPlayer(event.getPlayer().getUniqueId());
|
||||
|
||||
aplayer.ifPresent(player -> Anticheat.INSTANCE.getPacketHandler()
|
||||
.process(player, event.getType(), event.getPacket()));
|
||||
aplayer.ifPresent(player -> {
|
||||
if(Anticheat.INSTANCE.getPacketHandler()
|
||||
.process(player, event.getType(), event.getPacket())) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Anticheat.INSTANCE.getPacketProcessor().process(Anticheat.INSTANCE, EventPriority.HIGHEST, event -> {
|
||||
@@ -83,7 +87,7 @@ public class JoinListener implements Listener {
|
||||
HandlerAbstract.getHandler().add(event.getPlayer());
|
||||
}, 6);
|
||||
|
||||
player.callEvent(event);
|
||||
player.getCheckHandler().callEvent(event);
|
||||
}
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent event) {
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package dev.brighten.ac.logging;
|
||||
|
||||
import dev.brighten.ac.logging.sql.MySQL;
|
||||
|
||||
|
||||
public class LoggerManager {
|
||||
|
||||
/*
|
||||
* Structure of Log
|
||||
* UUID hashcode (INT32),
|
||||
*/
|
||||
public void init() {
|
||||
// Starting up H2
|
||||
MySQL.initH2();
|
||||
}
|
||||
|
||||
public void shutDown() {
|
||||
MySQL.shutdown();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
package dev.brighten.ac.logging.sql;
|
||||
|
||||
import dev.brighten.ac.utils.MiscUtils;
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ExecutableStatement {
|
||||
private PreparedStatement statement;
|
||||
private int pos = 1;
|
||||
|
||||
public ExecutableStatement(PreparedStatement statement) {
|
||||
this.statement = statement;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public Integer execute() {
|
||||
try {
|
||||
return statement.executeUpdate();
|
||||
} finally {
|
||||
MiscUtils.close(statement);
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void execute(ResultSetIterator iterator) {
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
rs = statement.executeQuery();
|
||||
while (rs.next()) iterator.next(rs);
|
||||
} finally {
|
||||
MiscUtils.close(statement, rs);
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public void executeSingle(ResultSetIterator iterator) {
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
rs = statement.executeQuery();
|
||||
if (rs.next()) iterator.next(rs);
|
||||
else iterator.next(null);
|
||||
} finally {
|
||||
MiscUtils.close(statement, rs);
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public ResultSet executeQuery() {
|
||||
return statement.executeQuery();
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public ExecutableStatement append(Object obj) {
|
||||
statement.setObject(pos++, obj);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public ExecutableStatement append(Object... objects) {
|
||||
for (Object obj : objects) {
|
||||
statement.setObject(pos++, obj);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public ExecutableStatement append(String obj) {
|
||||
statement.setString(pos++, obj);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public ExecutableStatement append(UUID uuid) {
|
||||
if (uuid != null) statement.setString(pos++, uuid.toString().replace("-", ""));
|
||||
else statement.setString(pos++, null);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public ExecutableStatement append(Array obj) {
|
||||
statement.setArray(pos++, obj);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public ExecutableStatement append(Integer obj) {
|
||||
statement.setInt(pos++, obj);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public ExecutableStatement append(Short obj) {
|
||||
statement.setShort(pos++, obj);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public ExecutableStatement append(Long obj) {
|
||||
statement.setLong(pos++, obj);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public ExecutableStatement append(Float obj) {
|
||||
statement.setFloat(pos++, obj);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public ExecutableStatement append(Double obj) {
|
||||
statement.setDouble(pos++, obj);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public ExecutableStatement append(Date obj) {
|
||||
statement.setDate(pos++, obj);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public ExecutableStatement append(Timestamp obj) {
|
||||
statement.setTimestamp(pos++, obj);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public ExecutableStatement append(Time obj) {
|
||||
statement.setTime(pos++, obj);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public ExecutableStatement append(Blob obj) {
|
||||
statement.setBlob(pos++, obj);
|
||||
return this;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public ExecutableStatement append(byte[] obj) {
|
||||
statement.setBytes(pos++, obj);
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package dev.brighten.ac.logging.sql;
|
||||
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import lombok.SneakyThrows;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class MySQL {
|
||||
private static Connection conn;
|
||||
|
||||
@SneakyThrows
|
||||
public static void initH2() {
|
||||
File dataFolder = new File(Anticheat.INSTANCE.getDataFolder(), "database.db");
|
||||
try {//https://nexus.funkemunky.cc/service/local/repositories/releases/content/com/h2database/h2/1.4.199/h2-1.4.199.jar
|
||||
if(dataFolder.createNewFile()) {
|
||||
Anticheat.INSTANCE.getLogger().info("Successfully created database.db in Anticheat folder!");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
Anticheat.INSTANCE.getLogger().log(Level.SEVERE, "File write error: database.db");
|
||||
}
|
||||
try {
|
||||
Class.forName("org.h2.Driver");
|
||||
conn = new NonClosableConnection(DriverManager.getConnection ("jdbc:h2:file:" +
|
||||
dataFolder.getAbsolutePath(),
|
||||
Anticheat.INSTANCE.getConfig().getString("database.username"),
|
||||
Anticheat.INSTANCE.getConfig().getString("database.password")));
|
||||
conn.setAutoCommit(true);
|
||||
Query.use(conn);
|
||||
Bukkit.getLogger().info("Connection to H2 SQlLite has been established.");
|
||||
} catch (SQLException ex) {
|
||||
Anticheat.INSTANCE.getLogger().log(Level.SEVERE,"SQLite exception on initialize", ex);
|
||||
} catch (ClassNotFoundException ex) {
|
||||
Anticheat.INSTANCE.getLogger().log(Level.SEVERE, "You need the H2 JBDC library. Google it. Put it in /lib folder.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void shutdown() {
|
||||
try {
|
||||
if(conn != null && !conn.isClosed()) {
|
||||
if(conn instanceof NonClosableConnection) {
|
||||
((NonClosableConnection)conn).shutdown();
|
||||
} else conn.close();
|
||||
conn = null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
package dev.brighten.ac.logging.sql;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
/**
|
||||
* A wrapper around a {@link Connection} which blocks usage of the default {@link #close()} method.
|
||||
*/
|
||||
public class NonClosableConnection implements Connection {
|
||||
private final Connection delegate;
|
||||
|
||||
public NonClosableConnection(Connection delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually {@link #close() closes} the underlying connection.
|
||||
*/
|
||||
public final void shutdown() throws SQLException {
|
||||
this.delegate.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void close() throws SQLException {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean isWrapperFor(Class<?> iface) throws SQLException {
|
||||
return iface.isInstance(this.delegate) || this.delegate.isWrapperFor(iface);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public final <T> T unwrap(Class<T> iface) throws SQLException {
|
||||
if (iface.isInstance(this.delegate)) {
|
||||
return (T) this.delegate;
|
||||
}
|
||||
return this.delegate.unwrap(iface);
|
||||
}
|
||||
|
||||
// Forward to the delegate connection
|
||||
@Override public Statement createStatement() throws SQLException { return this.delegate.createStatement(); }
|
||||
@Override public PreparedStatement prepareStatement(String sql) throws SQLException { return this.delegate.prepareStatement(sql); }
|
||||
@Override public CallableStatement prepareCall(String sql) throws SQLException { return this.delegate.prepareCall(sql); }
|
||||
@Override public String nativeSQL(String sql) throws SQLException { return this.delegate.nativeSQL(sql); }
|
||||
@Override public void setAutoCommit(boolean autoCommit) throws SQLException { this.delegate.setAutoCommit(autoCommit); }
|
||||
@Override public boolean getAutoCommit() throws SQLException { return this.delegate.getAutoCommit(); }
|
||||
@Override public void commit() throws SQLException { this.delegate.commit(); }
|
||||
@Override public void rollback() throws SQLException { this.delegate.rollback(); }
|
||||
@Override public boolean isClosed() throws SQLException { return this.delegate.isClosed(); }
|
||||
@Override public DatabaseMetaData getMetaData() throws SQLException { return this.delegate.getMetaData(); }
|
||||
@Override public void setReadOnly(boolean readOnly) throws SQLException { this.delegate.setReadOnly(readOnly); }
|
||||
@Override public boolean isReadOnly() throws SQLException { return this.delegate.isReadOnly(); }
|
||||
@Override public void setCatalog(String catalog) throws SQLException { this.delegate.setCatalog(catalog); }
|
||||
@Override public String getCatalog() throws SQLException { return this.delegate.getCatalog(); }
|
||||
@Override public void setTransactionIsolation(int level) throws SQLException { this.delegate.setTransactionIsolation(level); }
|
||||
@Override public int getTransactionIsolation() throws SQLException { return this.delegate.getTransactionIsolation(); }
|
||||
@Override public SQLWarning getWarnings() throws SQLException { return this.delegate.getWarnings(); }
|
||||
@Override public void clearWarnings() throws SQLException { this.delegate.clearWarnings(); }
|
||||
@Override public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { return this.delegate.createStatement(resultSetType, resultSetConcurrency); }
|
||||
@Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { return this.delegate.prepareStatement(sql, resultSetType, resultSetConcurrency); }
|
||||
@Override public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) throws SQLException { return this.delegate.prepareCall(sql, resultSetType, resultSetConcurrency); }
|
||||
@Override public Map<String, Class<?>> getTypeMap() throws SQLException { return this.delegate.getTypeMap(); }
|
||||
@Override public void setTypeMap(Map<String, Class<?>> map) throws SQLException { this.delegate.setTypeMap(map); }
|
||||
@Override public void setHoldability(int holdability) throws SQLException { this.delegate.setHoldability(holdability); }
|
||||
@Override public int getHoldability() throws SQLException { return this.delegate.getHoldability(); }
|
||||
@Override public Savepoint setSavepoint() throws SQLException { return this.delegate.setSavepoint(); }
|
||||
@Override public Savepoint setSavepoint(String name) throws SQLException { return this.delegate.setSavepoint(name); }
|
||||
@Override public void rollback(Savepoint savepoint) throws SQLException { this.delegate.rollback(savepoint); }
|
||||
@Override public void releaseSavepoint(Savepoint savepoint) throws SQLException { this.delegate.releaseSavepoint(savepoint); }
|
||||
@Override public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return this.delegate.createStatement(resultSetType, resultSetConcurrency, resultSetHoldability); }
|
||||
@Override public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return this.delegate.prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability); }
|
||||
@Override public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException { return this.delegate.prepareCall(sql, resultSetType, resultSetConcurrency, resultSetHoldability); }
|
||||
@Override public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { return this.delegate.prepareStatement(sql, autoGeneratedKeys); }
|
||||
@Override public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { return this.delegate.prepareStatement(sql, columnIndexes); }
|
||||
@Override public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { return this.delegate.prepareStatement(sql, columnNames); }
|
||||
@Override public Clob createClob() throws SQLException { return this.delegate.createClob(); }
|
||||
@Override public Blob createBlob() throws SQLException { return this.delegate.createBlob(); }
|
||||
@Override public NClob createNClob() throws SQLException { return this.delegate.createNClob(); }
|
||||
@Override public SQLXML createSQLXML() throws SQLException { return this.delegate.createSQLXML(); }
|
||||
@Override public boolean isValid(int timeout) throws SQLException { return this.delegate.isValid(timeout); }
|
||||
@Override public void setClientInfo(String name, String value) throws SQLClientInfoException { this.delegate.setClientInfo(name, value); }
|
||||
@Override public void setClientInfo(Properties properties) throws SQLClientInfoException { this.delegate.setClientInfo(properties); }
|
||||
@Override public String getClientInfo(String name) throws SQLException { return this.delegate.getClientInfo(name); }
|
||||
@Override public Properties getClientInfo() throws SQLException { return this.delegate.getClientInfo(); }
|
||||
@Override public Array createArrayOf(String typeName, Object[] elements) throws SQLException { return this.delegate.createArrayOf(typeName, elements); }
|
||||
@Override public Struct createStruct(String typeName, Object[] attributes) throws SQLException { return this.delegate.createStruct(typeName, attributes); }
|
||||
@Override public void setSchema(String schema) throws SQLException { this.delegate.setSchema(schema); }
|
||||
@Override public String getSchema() throws SQLException { return this.delegate.getSchema(); }
|
||||
@Override public void abort(Executor executor) throws SQLException { this.delegate.abort(executor); }
|
||||
@Override public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { this.delegate.setNetworkTimeout(executor, milliseconds); }
|
||||
@Override public int getNetworkTimeout() throws SQLException { return this.delegate.getNetworkTimeout(); }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package dev.brighten.ac.logging.sql;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
public class Query {
|
||||
private static Connection conn;
|
||||
|
||||
public static void use(Connection conn) {
|
||||
Query.conn = conn;
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static ExecutableStatement prepare(String query) {
|
||||
return new ExecutableStatement(conn.prepareStatement(query));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public static ExecutableStatement prepare(String query, Connection con) {
|
||||
return new ExecutableStatement(con.prepareStatement(query));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package dev.brighten.ac.logging.sql;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
||||
public interface ResultSetIterator {
|
||||
void next(ResultSet rs) throws Exception;
|
||||
}
|
||||
@@ -97,11 +97,11 @@ public class LegacyHandler extends HandlerAbstract {
|
||||
int index = name.lastIndexOf(".");
|
||||
String packetName = name.substring(index + 1);
|
||||
|
||||
boolean allowed = Anticheat.INSTANCE.getPacketProcessor().call(player, msg, PacketType
|
||||
Object packet = Anticheat.INSTANCE.getPacketProcessor().call(player, msg, PacketType
|
||||
.getByPacketId(packetName).orElse(PacketType.UNKNOWN));
|
||||
|
||||
if(allowed) {
|
||||
super.channelRead(ctx, msg);
|
||||
if(packet != null) {
|
||||
super.channelRead(ctx, packet);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,12 +110,12 @@ public class LegacyHandler extends HandlerAbstract {
|
||||
String name = msg.getClass().getName();
|
||||
int index = name.lastIndexOf(".");
|
||||
String packetName = name.substring(index + 1);
|
||||
boolean allowed = Anticheat.INSTANCE.getPacketProcessor().call(player, msg, PacketType
|
||||
Object packet = Anticheat.INSTANCE.getPacketProcessor().call(player, msg, PacketType
|
||||
.getByPacketId(packetName).orElse(PacketType.UNKNOWN));
|
||||
|
||||
if(allowed) {
|
||||
super.write(ctx, msg, promise);
|
||||
}
|
||||
if(packet != null) {
|
||||
super.write(ctx, packet, promise);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.wrapper.PacketType;
|
||||
import dev.brighten.ac.packet.wrapper.WPacket;
|
||||
import dev.brighten.ac.packet.wrapper.in.WPacketHandshakingInSetProtocol;
|
||||
import dev.brighten.ac.packet.wrapper.login.WPacketHandshakingInSetProtocol;
|
||||
import dev.brighten.ac.utils.reflections.impl.MinecraftReflection;
|
||||
import io.netty.channel.*;
|
||||
import net.minecraft.server.v1_8_R3.PacketLoginInStart;
|
||||
@@ -129,7 +129,7 @@ public class ModernHandler extends HandlerAbstract {
|
||||
}
|
||||
|
||||
private final class PacketHandler extends ChannelDuplexHandler {
|
||||
protected Player player;
|
||||
private Player player;
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
|
||||
@@ -156,11 +156,11 @@ public class ModernHandler extends HandlerAbstract {
|
||||
|
||||
if(player != null) {
|
||||
try {
|
||||
boolean allowed = Anticheat.INSTANCE.getPacketProcessor().call(player, msg,
|
||||
Object returnedObject = Anticheat.INSTANCE.getPacketProcessor().call(player, msg,
|
||||
type);
|
||||
|
||||
if (allowed) {
|
||||
super.channelRead(ctx, msg);
|
||||
if (returnedObject != null) {
|
||||
super.channelRead(ctx, returnedObject);
|
||||
}
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
@@ -177,11 +177,11 @@ public class ModernHandler extends HandlerAbstract {
|
||||
|
||||
if(player != null) {
|
||||
try {
|
||||
boolean allowed = Anticheat.INSTANCE.getPacketProcessor().call(player, msg, PacketType
|
||||
Object returnedObject = Anticheat.INSTANCE.getPacketProcessor().call(player, msg, PacketType
|
||||
.getByPacketId(packetName).orElse(PacketType.UNKNOWN));
|
||||
|
||||
if (allowed) {
|
||||
super.write(ctx, msg, promise);
|
||||
if (returnedObject != null) {
|
||||
super.write(ctx, returnedObject, promise);
|
||||
}
|
||||
} catch(Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
|
||||
@@ -10,7 +10,8 @@ import org.bukkit.entity.Player;
|
||||
public class PacketInfo {
|
||||
@Getter
|
||||
private final Player player;
|
||||
private final Object packet;
|
||||
@Setter
|
||||
private Object packet;
|
||||
@Getter
|
||||
private final PacketType type;
|
||||
@Getter
|
||||
@@ -19,6 +20,13 @@ public class PacketInfo {
|
||||
@Setter
|
||||
private boolean cancelled;
|
||||
|
||||
public PacketInfo(Player player, Object packet, PacketType type, long timestamp) {
|
||||
this.player = player;
|
||||
this.packet = packet;
|
||||
this.type = type;
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
public <T> T getPacket() {
|
||||
return (T) packet;
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ public class PacketProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean call(Player player, Object packet, PacketType type) {
|
||||
public Object call(Player player, Object packet, PacketType type) {
|
||||
if(packet == null) return false;
|
||||
PacketInfo info = new PacketInfo(player, packet, type, System.currentTimeMillis()),
|
||||
asyncInfo;
|
||||
@@ -175,7 +175,7 @@ public class PacketProcessor {
|
||||
tuple.getListener().onEvent(asyncInfo);
|
||||
}
|
||||
}
|
||||
return !cancelled;
|
||||
return cancelled ? null : info.getPacket();
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.brighten.ac.packet.wrapper;
|
||||
|
||||
import dev.brighten.ac.packet.wrapper.in.*;
|
||||
import dev.brighten.ac.packet.wrapper.login.WPacketHandshakingInSetProtocol;
|
||||
import dev.brighten.ac.packet.wrapper.out.*;
|
||||
|
||||
public interface PacketConverter {
|
||||
@@ -47,5 +48,9 @@ public interface PacketConverter {
|
||||
|
||||
Object processParticles(WPacketPlayOutWorldParticles packet);
|
||||
|
||||
WPacketPlayInChat processChat(Object object);
|
||||
|
||||
Object processChat(WPacketPlayInChat packet);
|
||||
|
||||
WPacketPlayOutPlayerInfo processInfo(Object object);
|
||||
}
|
||||
|
||||
@@ -127,6 +127,8 @@ public enum PacketType {
|
||||
return convert.processMultiBlockChange(object);
|
||||
case VELOCITY:
|
||||
return convert.processVelocity(object);
|
||||
case CHAT:
|
||||
return convert.processChat(object);
|
||||
case SERVER_ABILITIES:
|
||||
return convert.processOutAbilities(object);
|
||||
default:
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package dev.brighten.ac.packet.wrapper;
|
||||
|
||||
public interface WPacket {
|
||||
PacketType getPacketType();
|
||||
public abstract class WPacket {
|
||||
|
||||
Object getPacket();
|
||||
public abstract PacketType getPacketType();
|
||||
|
||||
public abstract Object getPacket();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package dev.brighten.ac.packet.wrapper.impl;
|
||||
|
||||
import dev.brighten.ac.packet.wrapper.PacketConverter;
|
||||
import dev.brighten.ac.packet.wrapper.in.*;
|
||||
import dev.brighten.ac.packet.wrapper.login.WPacketHandshakingInSetProtocol;
|
||||
import dev.brighten.ac.packet.wrapper.objects.EnumParticle;
|
||||
import dev.brighten.ac.packet.wrapper.objects.PlayerCapabilities;
|
||||
import dev.brighten.ac.packet.wrapper.objects.WrappedEnumDirection;
|
||||
@@ -375,6 +376,19 @@ public class Processor_18 implements PacketConverter {
|
||||
packet.getSpeed(), packet.getAmount(), packet.getData());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WPacketPlayInChat processChat(Object object) {
|
||||
PacketPlayInChat packet = (PacketPlayInChat) object;
|
||||
return WPacketPlayInChat.builder()
|
||||
.message(packet.a())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object processChat(WPacketPlayInChat packet) {
|
||||
return new PacketPlayInChat(packet.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WPacketPlayOutPlayerInfo processInfo(Object object) {
|
||||
PacketPlayOutPlayerInfo packet = (PacketPlayOutPlayerInfo) object;
|
||||
|
||||
@@ -8,7 +8,7 @@ import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class WPacketPlayInAbilities implements WPacket {
|
||||
public class WPacketPlayInAbilities extends WPacket {
|
||||
private PlayerCapabilities capabilities;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,7 +7,7 @@ import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class WPacketPlayInArmAnimation implements WPacket {
|
||||
public class WPacketPlayInArmAnimation extends WPacket {
|
||||
|
||||
private long timestamp;
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class WPacketPlayInBlockDig implements WPacket {
|
||||
public class WPacketPlayInBlockDig extends WPacket {
|
||||
|
||||
private IntVector blockPos;
|
||||
private WrappedEnumDirection direction;
|
||||
|
||||
@@ -10,7 +10,7 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class WPacketPlayInBlockPlace implements WPacket {
|
||||
public class WPacketPlayInBlockPlace extends WPacket {
|
||||
|
||||
private IntVector blockPos;
|
||||
private ItemStack itemStack;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package dev.brighten.ac.packet.wrapper.in;
|
||||
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.packet.wrapper.PacketType;
|
||||
import dev.brighten.ac.packet.wrapper.WPacket;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class WPacketPlayInChat extends WPacket {
|
||||
private String message;
|
||||
|
||||
@Override
|
||||
public PacketType getPacketType() {
|
||||
return PacketType.CHAT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getPacket() {
|
||||
return Anticheat.INSTANCE.getPacketProcessor().getPacketConverter().processChat(this);
|
||||
}
|
||||
|
||||
public BaseComponent[] getWrappedMessage() {
|
||||
return TextComponent.fromLegacyText(message);
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class WPacketPlayInCloseWindow implements WPacket {
|
||||
public class WPacketPlayInCloseWindow extends WPacket {
|
||||
|
||||
private int id;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class WPacketPlayInEntityAction implements WPacket {
|
||||
public class WPacketPlayInEntityAction extends WPacket {
|
||||
|
||||
private EnumPlayerAction action;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class WPacketPlayInFlying implements WPacket {
|
||||
public class WPacketPlayInFlying extends WPacket {
|
||||
private double x, y, z;
|
||||
private float yaw, pitch;
|
||||
private boolean looked, moved, onGround;
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.bukkit.util.Vector;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class WPacketPlayInUseEntity implements WPacket {
|
||||
public class WPacketPlayInUseEntity extends WPacket {
|
||||
private int entityId;
|
||||
private Vector vector;
|
||||
private EnumEntityUseAction action;
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package dev.brighten.ac.packet.wrapper.in;
|
||||
package dev.brighten.ac.packet.wrapper.login;
|
||||
|
||||
import dev.brighten.ac.packet.wrapper.PacketType;
|
||||
import dev.brighten.ac.packet.wrapper.WPacket;
|
||||
@@ -7,7 +7,7 @@ import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class WPacketHandshakingInSetProtocol implements WPacket {
|
||||
public class WPacketHandshakingInSetProtocol extends WPacket {
|
||||
private int versionNumber, port;
|
||||
private String hostname;
|
||||
private EnumProtocol protocol;
|
||||
@@ -9,7 +9,7 @@ import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class WPacketPlayOutAbilities implements WPacket {
|
||||
public class WPacketPlayOutAbilities extends WPacket {
|
||||
|
||||
private PlayerCapabilities capabilities;
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class WPacketPlayOutAttachEntity implements WPacket {
|
||||
public class WPacketPlayOutAttachEntity extends WPacket {
|
||||
|
||||
private int attachedEntityId, holdingEntityId;
|
||||
private boolean isLeashModifer = true;
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.bukkit.Material;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class WPacketPlayOutBlockChange implements WPacket {
|
||||
public class WPacketPlayOutBlockChange extends WPacket {
|
||||
|
||||
private IntVector blockLocation;
|
||||
private Material material;
|
||||
|
||||
@@ -7,7 +7,7 @@ import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class WPacketPlayOutEntity implements WPacket {
|
||||
public class WPacketPlayOutEntity extends WPacket {
|
||||
|
||||
private int id;
|
||||
private boolean looked, moved, onGround;
|
||||
|
||||
@@ -7,7 +7,7 @@ import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class WPacketPlayOutEntityEffect implements WPacket {
|
||||
public class WPacketPlayOutEntityEffect extends WPacket {
|
||||
|
||||
private int entityId, effectId, duration;
|
||||
private byte amplifier, flags;
|
||||
|
||||
@@ -7,7 +7,7 @@ import lombok.Getter;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class WPacketPlayOutEntityTeleport implements WPacket {
|
||||
public class WPacketPlayOutEntityTeleport extends WPacket {
|
||||
|
||||
private int entityId;
|
||||
private double x, y, z;
|
||||
|
||||
@@ -8,7 +8,7 @@ import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class WPacketPlayOutEntityVelocity implements WPacket {
|
||||
public class WPacketPlayOutEntityVelocity extends WPacket {
|
||||
private int entityId;
|
||||
private double deltaX, deltaY, deltaZ;
|
||||
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ import java.util.Arrays;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class WPacketPlayOutMultiBlockChange implements WPacket {
|
||||
public class WPacketPlayOutMultiBlockChange extends WPacket {
|
||||
private int[] chunk;
|
||||
private BlockChange[] changes;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.Set;
|
||||
|
||||
@Builder
|
||||
@Getter
|
||||
public class WPacketPlayOutPosition implements WPacket {
|
||||
public class WPacketPlayOutPosition extends WPacket {
|
||||
|
||||
private double x, y, z;
|
||||
private float yaw, pitch;
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.Arrays;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class WPacketPlayOutWorldParticles implements WPacket {
|
||||
public class WPacketPlayOutWorldParticles extends WPacket {
|
||||
private EnumParticle particle;
|
||||
private float x, y, z, offsetX, offsetY, offsetZ, speed;
|
||||
private int amount;
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package dev.brighten.ac.utils;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE})
|
||||
public @interface Async {
|
||||
}
|
||||
@@ -46,6 +46,13 @@ public class MiscUtils {
|
||||
return toCheck.toLowerCase().contains(contains.toLowerCase());
|
||||
}
|
||||
|
||||
public static void close(AutoCloseable... closeables) {
|
||||
try {
|
||||
for (AutoCloseable closeable : closeables) if (closeable != null) closeable.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
public static boolean isInMaterialBB(World world, SimpleCollisionBox entityBox, XMaterial xmaterial) {
|
||||
int startX = MathHelper.floor_double(entityBox.xMin);
|
||||
int startY = MathHelper.floor_double(entityBox.yMin);
|
||||
|
||||
Reference in New Issue
Block a user