mirror of
https://github.com/funkemunky/KauriV3.git
synced 2026-06-07 08:32:17 +00:00
New Fly D and lowering file size, new logs system
This commit is contained in:
@@ -7,12 +7,19 @@ import dev.brighten.ac.api.AnticheatAPI;
|
||||
import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.check.CheckManager;
|
||||
import dev.brighten.ac.data.PlayerRegistry;
|
||||
import dev.brighten.ac.depends.LibraryLoader;
|
||||
import dev.brighten.ac.depends.MavenLibrary;
|
||||
import dev.brighten.ac.depends.Repository;
|
||||
import dev.brighten.ac.handler.PacketHandler;
|
||||
import dev.brighten.ac.handler.keepalive.KeepaliveProcessor;
|
||||
import dev.brighten.ac.handler.protocolsupport.ProtocolAPI;
|
||||
import dev.brighten.ac.logging.LoggerManager;
|
||||
import dev.brighten.ac.packet.handler.HandlerAbstract;
|
||||
import dev.brighten.ac.packet.listener.PacketProcessor;
|
||||
import dev.brighten.ac.utils.*;
|
||||
import dev.brighten.ac.utils.annotation.ConfigSetting;
|
||||
import dev.brighten.ac.utils.annotation.Init;
|
||||
import dev.brighten.ac.utils.annotation.Invoke;
|
||||
import dev.brighten.ac.utils.math.RollingAverageDouble;
|
||||
import dev.brighten.ac.utils.objects.RemoteClassLoader;
|
||||
import dev.brighten.ac.utils.reflections.Reflections;
|
||||
@@ -40,6 +47,12 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@Getter
|
||||
@Init
|
||||
@MavenLibrary(groupId = "co.aikar", artifactId = "acf-bukkit", version = "0.5.0", repo = @Repository(url = "https://nexus.funkemunky.cc/content/repositories/releases/"))
|
||||
@MavenLibrary(groupId = "com.google.guava", artifactId = "guava", version = "21.0", repo = @Repository(url = "https://repo1.maven.org/maven2"))
|
||||
@MavenLibrary(groupId = "com.h2database", artifactId = "h2", version = "1.4.199", repo = @Repository(url = "https://repo1.maven.org/maven2"))
|
||||
@MavenLibrary(groupId = "it.unimi.dsi", artifactId = "fastutil", version = "8.5.6", repo = @Repository(url = "https://repo1.maven.org/maven2"))
|
||||
@MavenLibrary(groupId = "org.ow2.asm", artifactId = "asm", version = "9.2", repo = @Repository(url = "https://repo1.maven.org/maven2"))
|
||||
@MavenLibrary(groupId = "org.ow2.asm", artifactId = "asm-tree", version = "9.2", repo = @Repository(url = "https://repo1.maven.org/maven2"))
|
||||
public class Anticheat extends JavaPlugin {
|
||||
|
||||
public static Anticheat INSTANCE;
|
||||
@@ -51,6 +64,7 @@ public class Anticheat extends JavaPlugin {
|
||||
private PlayerRegistry playerRegistry;
|
||||
private KeepaliveProcessor keepaliveProcessor;
|
||||
private PacketHandler packetHandler;
|
||||
private LoggerManager logManager;
|
||||
private int currentTick;
|
||||
private Deque<Runnable> onTickEnd = new LinkedList<>();
|
||||
private ServerInjector injector;
|
||||
@@ -68,6 +82,7 @@ public class Anticheat extends JavaPlugin {
|
||||
|
||||
public void onEnable() {
|
||||
INSTANCE = this;
|
||||
LibraryLoader.loadAll(getClass());
|
||||
|
||||
scheduler = Executors.newScheduledThreadPool(2, new ThreadFactoryBuilder()
|
||||
.setNameFormat("Anticheat Schedular")
|
||||
@@ -98,12 +113,15 @@ public class Anticheat extends JavaPlugin {
|
||||
getConfig().set("database.password", UUID.randomUUID().toString());
|
||||
}
|
||||
|
||||
HandlerAbstract.init();
|
||||
|
||||
this.keepaliveProcessor = new KeepaliveProcessor();
|
||||
this.checkManager = new CheckManager();
|
||||
this.playerRegistry = new PlayerRegistry();
|
||||
this.packetHandler = new PacketHandler();
|
||||
logManager = new LoggerManager();
|
||||
|
||||
HandlerAbstract.init();
|
||||
logManager.init();
|
||||
|
||||
alog(Color.Green + "Loading WorldInfo system...");
|
||||
Bukkit.getWorlds().forEach(w -> worldInfoMap.put(w.getUID(), new WorldInfo(w)));
|
||||
@@ -114,6 +132,8 @@ public class Anticheat extends JavaPlugin {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(HandlerAbstract.getHandler()::add);
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
@@ -134,6 +154,8 @@ public class Anticheat extends JavaPlugin {
|
||||
ProtocolAPI.INSTANCE = null;
|
||||
tps = null;
|
||||
|
||||
logManager.shutDown();
|
||||
|
||||
Bukkit.getScheduler().cancelTasks(this);
|
||||
|
||||
|
||||
|
||||
@@ -148,6 +148,8 @@ public class Check implements ECheck {
|
||||
|
||||
if(currentResult.isCancelled()) return;
|
||||
|
||||
Anticheat.INSTANCE.getLogManager().insertLog(player, checkData, vl, System.currentTimeMillis(), info);
|
||||
|
||||
boolean dev = Anticheat.INSTANCE.getTps() < 18;
|
||||
//if(vl > 0) Anticheat.INSTANCE.loggerManager.addLog(player, this, info);
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.brighten.ac.check;
|
||||
|
||||
import dev.brighten.ac.utils.ConfigSetting;
|
||||
import dev.brighten.ac.utils.Init;
|
||||
import dev.brighten.ac.utils.annotation.ConfigSetting;
|
||||
import dev.brighten.ac.utils.annotation.Init;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -11,6 +11,7 @@ import java.util.Map;
|
||||
@Getter
|
||||
public class CheckManager {
|
||||
private final Map<String, CheckStatic> checkClasses = new HashMap<>();
|
||||
private final Map<String, String> idToName = new HashMap<>();
|
||||
|
||||
public CheckManager() {
|
||||
synchronized (checkClasses) {
|
||||
@@ -33,6 +34,7 @@ public class CheckManager {
|
||||
Anticheat.INSTANCE.alog(true, "&7Adding check to CheckManager: " + checkData.name());
|
||||
|
||||
checkClasses.put(checkData.name(), check);
|
||||
idToName.put(checkData.checkId(), checkData.name());
|
||||
}
|
||||
|
||||
public boolean isCheck(String name) {
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package dev.brighten.ac.check.impl.combat;
|
||||
|
||||
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.WAction;
|
||||
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;
|
||||
@@ -22,8 +21,6 @@ public class Aim extends Check {
|
||||
private float buffer;
|
||||
protected Timer lastGrid = new TickTimer(3);
|
||||
|
||||
|
||||
@Async
|
||||
WAction<WPacketPlayInFlying> onFlying = (packet) -> {
|
||||
if(!packet.isLooked()) return;
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ public class Hitbox extends Check {
|
||||
EntityData.getEntityBox(oldLocation.toVector(), target.one);
|
||||
|
||||
if(player.getPlayerVersion().isBelow(ProtocolVersion.V1_9)) {
|
||||
box = box.expand(0.105);
|
||||
box = box.expand(0.1325);
|
||||
} else box = box.expand(0.0325);
|
||||
boxes.add(box);
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public class Hitbox extends Check {
|
||||
EntityData.getEntityBox(oldLocation.toVector(), target.one);
|
||||
|
||||
if(player.getPlayerVersion().isBelow(ProtocolVersion.V1_9)) {
|
||||
box = box.expand(0.105);
|
||||
box = box.expand(0.1325);
|
||||
} else box = box.expand(0.0325);
|
||||
boxes.add(box);
|
||||
}
|
||||
@@ -98,7 +98,7 @@ public class Hitbox extends Check {
|
||||
EntityData.getEntityBox(oldLocation.toVector(), target.one);
|
||||
|
||||
if(player.getPlayerVersion().isBelow(ProtocolVersion.V1_9)) {
|
||||
box = box.expand(0.105);
|
||||
box = box.expand(0.1325);
|
||||
} else box = box.expand(0.0325);
|
||||
boxes.add(box);
|
||||
}
|
||||
@@ -168,7 +168,7 @@ public class Hitbox extends Check {
|
||||
|
||||
if(hbuffer > 0) hbuffer--;
|
||||
|
||||
debug("buffer: %.3f distance=%.2f hits=%s", buffer, distance, hits);
|
||||
debug("buffer: %.3f distance=%.2f hits=%s sneaking=%s", buffer, distance, hits, player.getInfo().isSneaking());
|
||||
} else if(player.getEntityLocationHandler().streak > 1) {
|
||||
if (++hbuffer > 5) {
|
||||
flag("%.1f;%.1f;%.1f", eloc.one.x, eloc.one.y, eloc.one.z);
|
||||
|
||||
@@ -8,7 +8,7 @@ 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;
|
||||
import dev.brighten.ac.utils.annotation.Async;
|
||||
|
||||
@CheckData(name = "AutoClicker (A)", checkId = "autoclickera", type = CheckType.AUTOCLICKER, maxVersion = ProtocolVersion.V1_8_9)
|
||||
public class AutoclickerA extends Check {
|
||||
|
||||
@@ -7,7 +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.annotation.Async;
|
||||
import dev.brighten.ac.utils.MathUtils;
|
||||
import dev.brighten.ac.utils.MovementUtils;
|
||||
import dev.brighten.ac.utils.timer.Timer;
|
||||
|
||||
@@ -6,7 +6,7 @@ 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.annotation.Async;
|
||||
import dev.brighten.ac.utils.timer.Timer;
|
||||
import dev.brighten.ac.utils.timer.impl.TickTimer;
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ 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.utils.Async;
|
||||
import dev.brighten.ac.utils.MathUtils;
|
||||
import dev.brighten.ac.utils.MovementUtils;
|
||||
|
||||
@@ -23,6 +22,7 @@ public class FlyC extends Check {
|
||||
|
||||
WAction<WPacketPlayInFlying> flyingAction = packet -> {
|
||||
if(player.getMovement().getLastTeleport().isNotPassed((1))
|
||||
|| player.getMovement().getMoveTicks() <= 2
|
||||
|| player.getInfo().isGeneralCancel())
|
||||
return;
|
||||
final boolean ground = player.getMovement().getTo().isOnGround(),
|
||||
@@ -44,7 +44,7 @@ public class FlyC extends Check {
|
||||
for (Double possibleHeight : possibleHeights) {
|
||||
double delta = MathUtils.getDelta(player.getMovement().getDeltaY(), possibleHeight);
|
||||
|
||||
if(delta < 1E-5) {
|
||||
if(delta < (player.getInfo().getLastBlockPlace().isNotPassed(20) ? 0.02 : 0.005)) {
|
||||
debug("Found delta: dy=%.5f, p=%.5f", player.getMovement().getDeltaY(), possibleHeight);
|
||||
break jumpCheck;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
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.utils.annotation.Async;
|
||||
|
||||
@CheckData(name = "Fly (D)", checkId = "flyd", type = CheckType.MOVEMENT)
|
||||
public class FlyD extends Check {
|
||||
public FlyD(APlayer player) {
|
||||
super(player);
|
||||
}
|
||||
|
||||
private double totalY;
|
||||
|
||||
@Async
|
||||
WAction<WPacketPlayInFlying> flyingPacket = packet -> {
|
||||
if(!packet.isMoved() || player.getMovement().getMoveTicks() <= 2) return;
|
||||
double deltaY = player.getMovement().getDeltaY();
|
||||
|
||||
if(deltaY > 0)
|
||||
totalY+= deltaY;
|
||||
else {
|
||||
if(totalY % 0.25 < 1E-6 && totalY > 0.6) {
|
||||
flag("totalY=%s gt=%s", totalY, player.getMovement().getGroundTicks());
|
||||
}
|
||||
debug("totalY=%s", totalY);
|
||||
totalY = 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -6,7 +6,7 @@ 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.annotation.Async;
|
||||
|
||||
@CheckData(name = "NoFall (A)", checkId = "nofalla", type = CheckType.MOVEMENT)
|
||||
public class NoFallA extends Check {
|
||||
|
||||
@@ -6,7 +6,7 @@ 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.annotation.Async;
|
||||
|
||||
@CheckData(name = "NoFall (B)", checkId = "nofallb", type = CheckType.MOVEMENT)
|
||||
public class NoFallB extends Check {
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package dev.brighten.ac.check.impl.movement.speed;
|
||||
|
||||
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.WAction;
|
||||
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;
|
||||
@@ -34,7 +33,6 @@ public class Horizontal extends Check {
|
||||
super(player);
|
||||
}
|
||||
|
||||
@Async
|
||||
WAction<WPacketPlayInFlying> flying = packet -> {
|
||||
Block underBlock = BlockUtils.getBlock(player.getMovement().getTo().getLoc()
|
||||
.toLocation(player.getBukkitPlayer().getWorld())
|
||||
@@ -147,6 +145,11 @@ public class Horizontal extends Check {
|
||||
if (Math.abs(lmotionZ) < 0.005)
|
||||
lmotionZ = 0;
|
||||
}
|
||||
|
||||
//Less than 0.05
|
||||
if(((lmotionX * lmotionX) + (lmotionZ * lmotionZ)) < 0.0025 && player.getMovement().getDeltaXZ() < 0.1) {
|
||||
break check;
|
||||
}
|
||||
// Attack slowdown
|
||||
if (attack) {
|
||||
lmotionX *= 0.6;
|
||||
|
||||
@@ -9,6 +9,7 @@ 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.*;
|
||||
import dev.brighten.ac.utils.annotation.Async;
|
||||
import dev.brighten.ac.utils.math.cond.MaxDouble;
|
||||
import dev.brighten.ac.utils.world.BlockData;
|
||||
import dev.brighten.ac.utils.world.CollisionBox;
|
||||
|
||||
@@ -5,7 +5,7 @@ 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 dev.brighten.ac.utils.annotation.Async;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
|
||||
|
||||
@@ -6,9 +6,11 @@ import co.aikar.commands.bukkit.contexts.OnlinePlayer;
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.check.Check;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.logging.Log;
|
||||
import dev.brighten.ac.messages.Messages;
|
||||
import dev.brighten.ac.packet.handler.HandlerAbstract;
|
||||
import dev.brighten.ac.utils.*;
|
||||
import dev.brighten.ac.utils.annotation.Init;
|
||||
import dev.brighten.ac.utils.msg.ChatBuilder;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import lombok.val;
|
||||
@@ -23,6 +25,8 @@ import org.bukkit.entity.Player;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Init(priority = Priority.LOW)
|
||||
@@ -107,6 +111,40 @@ public class AnticheatCommand extends BaseCommand {
|
||||
}
|
||||
}
|
||||
|
||||
@Subcommand("logs")
|
||||
@Syntax("[player]")
|
||||
@CommandCompletion("@players")
|
||||
@CommandPermission("anticheat.command.logs")
|
||||
@Description("Get player logs")
|
||||
public void onLogs(CommandSender sender, @Single String playername) {
|
||||
UUID uuid = Bukkit.getOfflinePlayer(playername).getUniqueId();
|
||||
|
||||
sender.sendMessage(Color.Red + "Getting logs for " + playername + "...");
|
||||
|
||||
Anticheat.INSTANCE.getScheduler().execute(() -> {
|
||||
List<String> logs = new ArrayList<>();
|
||||
Anticheat.INSTANCE.getLogManager().runQuery("select * from logs where uuid=" + uuid.hashCode(), rs -> {
|
||||
Log log = Log.builder()
|
||||
.uuid(UUID.fromString(rs.getString("uuid")))
|
||||
.checkId(rs.getString("check"))
|
||||
.data(rs.getString("data"))
|
||||
.vl(rs.getFloat("vl"))
|
||||
.time(rs.getLong("time"))
|
||||
.build();
|
||||
|
||||
logs.add("Flagged " + Anticheat.INSTANCE.getCheckManager().getIdToName().get(log.getCheckId()) + " data: " + log.getData() + " VL: " + log.getVl() + " at " + log.getTime());
|
||||
});
|
||||
String url = null;
|
||||
try {
|
||||
url = Pastebin.makePaste(String.join("\n", logs), playername + "'s Logs", Pastebin.Privacy.UNLISTED);
|
||||
|
||||
sender.sendMessage(Color.Green + "Logs for " + playername + ": " + Color.White + url);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Subcommand("title")
|
||||
@Private
|
||||
public void onTitle(CommandSender sender, OnlinePlayer target, String title) {
|
||||
|
||||
@@ -7,7 +7,7 @@ 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.annotation.Async;
|
||||
import dev.brighten.ac.utils.Tuple;
|
||||
import dev.brighten.ac.utils.reflections.types.WrappedField;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -63,7 +63,6 @@ public class CheckHandler {
|
||||
WAction<?> action = tuple.one.get(check);
|
||||
|
||||
if(!tuple.one.getField().isAnnotationPresent(Async.class)) {
|
||||
System.out.println("Adding sync event");
|
||||
events.compute(tuple.two, (packetClass, array) -> {
|
||||
if (array == null) {
|
||||
return new ActionStore[] {new ActionStore(action, checkClass.getCheckClass().getParent())};
|
||||
@@ -81,7 +80,6 @@ public class CheckHandler {
|
||||
WAction<?> action = tuple.one.get(check);
|
||||
|
||||
if(tuple.one.getField().isAnnotationPresent(Async.class)) {
|
||||
System.out.println("Adding async event");
|
||||
async_events.compute(tuple.two, (packetClass, array) -> {
|
||||
if (array == null) {
|
||||
return new ActionStore[] {new ActionStore(action, checkClass.getCheckClass().getParent())};
|
||||
@@ -99,7 +97,6 @@ public class CheckHandler {
|
||||
WTimedAction<?> action = tuple.one.get(check);
|
||||
|
||||
if(!tuple.one.getField().isAnnotationPresent(Async.class)) {
|
||||
System.out.println("Adding timed sync event");
|
||||
eventsWithTimestamp.compute(tuple.two, (packetClass, array) -> {
|
||||
if (array == null) {
|
||||
return new TimedActionStore[] {new TimedActionStore(action, checkClass.getCheckClass().getParent())};
|
||||
@@ -117,7 +114,6 @@ public class CheckHandler {
|
||||
WTimedAction<?> action = tuple.one.get(check);
|
||||
|
||||
if(tuple.one.getField().isAnnotationPresent(Async.class)) {
|
||||
System.out.println("Adding timed async event");
|
||||
async_eventsWithTimestamp.compute(tuple.two, (packetClass, array) -> {
|
||||
if (array == null) {
|
||||
return new TimedActionStore[] {new TimedActionStore(action, checkClass.getCheckClass().getParent())};
|
||||
@@ -135,7 +131,6 @@ public class CheckHandler {
|
||||
WCancellable<?> action = tuple.one.get(check);
|
||||
|
||||
if(!tuple.one.getField().isAnnotationPresent(Async.class)) {
|
||||
System.out.println("Adding cancel sync event");
|
||||
cancellableEvents.compute(tuple.two, (packetClass, array) -> {
|
||||
if (array == null) {
|
||||
return new CancellableActionStore[] {new CancellableActionStore(action, checkClass.getCheckClass().getParent())};
|
||||
@@ -177,7 +172,6 @@ public class CheckHandler {
|
||||
|
||||
//TODO When using WPacket wrappers only, make this strictly WPacket param based only
|
||||
public void callPacket(Object packet, long timestamp) {
|
||||
//System.out.println("Being called");
|
||||
ThreadHandler.INSTANCE.getThread(player).getThread().execute(() -> {
|
||||
if(async_events.containsKey(packet.getClass())) {
|
||||
synchronized (async_events) {
|
||||
|
||||
@@ -26,7 +26,8 @@ public class GeneralInformation {
|
||||
lastSneak = new TickTimer(), velocity = new TickTimer(), lastCancel = new TickTimer(),
|
||||
slimeTimer = new TickTimer(), lastElytra = new TickTimer(), blockAbove = new TickTimer(),
|
||||
lastPlace = new TickTimer(), climbTimer = new TickTimer(), lastUseItem = new TickTimer(),
|
||||
lastLiquid = new TickTimer(), lastBlockDig = new TickTimer(), lastBlockPlace = new TickTimer();
|
||||
lastLiquid = new TickTimer(), lastBlockDig = new TickTimer(), lastBlockPlace = new TickTimer(),
|
||||
lastBlockUpdate = new TickTimer();
|
||||
public LivingEntity target;
|
||||
public boolean serverGround, lastServerGround, canFly, nearGround, worldLoaded, generalCancel, inVehicle, creative,
|
||||
sneaking, lsneaking, sprinting, gliding, riptiding, wasOnSlime, onLadder, doingVelocity, breakingBlock;
|
||||
|
||||
@@ -58,7 +58,7 @@ public class MovementHandler {
|
||||
@Getter
|
||||
private float sensitivityX, sensitivityY, currentSensX, currentSensY, sensitivityMcp, yawMode, pitchMode;
|
||||
@Getter
|
||||
private int sensXPercent, sensYPercent;
|
||||
private int sensXPercent, sensYPercent, airTicks, groundTicks;
|
||||
private int ticks;
|
||||
private double lastX, lastY, lastLastY, lastYawAcelleration, lastPitchAcelleration;
|
||||
private boolean inTick;
|
||||
@@ -76,6 +76,7 @@ public class MovementHandler {
|
||||
|
||||
if (checkMovement) {
|
||||
moveTicks++;
|
||||
if(!packet.isMoved()) moveTicks = 1;
|
||||
} else moveTicks = 0;
|
||||
|
||||
updateLocations(packet);
|
||||
@@ -201,8 +202,13 @@ public class MovementHandler {
|
||||
}
|
||||
}
|
||||
|
||||
if (player.getInfo().isServerGround()) {
|
||||
if (packet.isOnGround()) {
|
||||
player.getInfo().setWasOnSlime(player.getBlockInfo().onSlime);
|
||||
groundTicks++;
|
||||
airTicks = 0;
|
||||
} else {
|
||||
airTicks++;
|
||||
groundTicks = 0;
|
||||
}
|
||||
|
||||
player.getInfo().setCreative(player.getBukkitPlayer().getGameMode() == GameMode.CREATIVE
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
/*
|
||||
* This file is part of helper, 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.depends;
|
||||
|
||||
import com.google.common.base.Supplier;
|
||||
import com.google.common.base.Suppliers;
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.utils.Log;
|
||||
import dev.brighten.ac.utils.annotation.NonnullByDefault;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Resolves {@link MavenLibrary} annotations for a class, and loads the dependency
|
||||
* into the classloader.
|
||||
*/
|
||||
@NonnullByDefault
|
||||
public final class LibraryLoader {
|
||||
|
||||
@SuppressWarnings("Guava")
|
||||
private static final Supplier<URLClassLoaderAccess> URL_INJECTOR = Suppliers.memoize(() -> URLClassLoaderAccess.create((URLClassLoader) Anticheat.INSTANCE.getClass().getClassLoader()));
|
||||
|
||||
/**
|
||||
* Resolves all {@link MavenLibrary} annotations on the given object.
|
||||
*
|
||||
* @param object the object to load libraries for.
|
||||
*/
|
||||
public static void loadAll(Object object) {
|
||||
loadAll(object.getClass());
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves all {@link MavenLibrary} annotations on the given class.
|
||||
*
|
||||
* @param clazz the class to load libraries for.
|
||||
*/
|
||||
public static void loadAll(Class<?> clazz) {
|
||||
MavenLibrary[] libs = clazz.getDeclaredAnnotationsByType(MavenLibrary.class);
|
||||
if (libs == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (MavenLibrary lib : libs) {
|
||||
load(lib.groupId(), lib.artifactId(), lib.version(), lib.repo().url());
|
||||
}
|
||||
}
|
||||
|
||||
public static void load(String groupId, String artifactId, String version) {
|
||||
load(groupId, artifactId, version, "https://repo1.maven.org/maven2");
|
||||
}
|
||||
|
||||
public static void load(String groupId, String artifactId, String version, String repoUrl) {
|
||||
load(new Dependency(groupId, artifactId, version, repoUrl));
|
||||
}
|
||||
|
||||
public static void load(Dependency d) {
|
||||
Log.info(String.format("Loading dependency %s:%s:%s from %s", d.getGroupId(), d.getArtifactId(), d.getVersion(), d.getRepoUrl()));
|
||||
String name = d.getArtifactId() + "-" + d.getVersion();
|
||||
|
||||
File saveLocation = new File(getLibFolder(), name + ".jar");
|
||||
if (!saveLocation.exists()) {
|
||||
|
||||
try {
|
||||
Log.info("Dependency '" + name + "' is not already in the libraries folder. Attempting to download...");
|
||||
URL url = d.getUrl();
|
||||
|
||||
try (InputStream is = url.openStream()) {
|
||||
Files.copy(is, saveLocation.toPath());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
Log.info("Dependency '" + name + "' successfully downloaded.");
|
||||
}
|
||||
|
||||
if (!saveLocation.exists()) {
|
||||
throw new RuntimeException("Unable to download dependency: " + d.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
URL_INJECTOR.get().addURL(saveLocation.toURI().toURL());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to load dependency: " + saveLocation.toString(), e);
|
||||
}
|
||||
|
||||
Log.info("Loaded dependency '" + name + "' successfully.");
|
||||
}
|
||||
|
||||
private static File getLibFolder() {
|
||||
File pluginDataFolder = Anticheat.INSTANCE.getDataFolder();
|
||||
File libs = new File(pluginDataFolder, "libraries");
|
||||
libs.mkdirs();
|
||||
return libs;
|
||||
}
|
||||
|
||||
@NonnullByDefault
|
||||
public static final class Dependency {
|
||||
private final String groupId;
|
||||
private final String artifactId;
|
||||
private final String version;
|
||||
private final String repoUrl;
|
||||
|
||||
public Dependency(String groupId, String artifactId, String version, String repoUrl) {
|
||||
this.groupId = Objects.requireNonNull(groupId, "groupId");
|
||||
this.artifactId = Objects.requireNonNull(artifactId, "artifactId");
|
||||
this.version = Objects.requireNonNull(version, "version");
|
||||
this.repoUrl = Objects.requireNonNull(repoUrl, "repoUrl");
|
||||
}
|
||||
|
||||
public String getGroupId() {
|
||||
return this.groupId;
|
||||
}
|
||||
|
||||
public String getArtifactId() {
|
||||
return this.artifactId;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return this.version;
|
||||
}
|
||||
|
||||
public String getRepoUrl() {
|
||||
return this.repoUrl;
|
||||
}
|
||||
|
||||
public URL getUrl() throws MalformedURLException {
|
||||
String repo = this.repoUrl;
|
||||
if (!repo.endsWith("/")) {
|
||||
repo += "/";
|
||||
}
|
||||
repo += "%s/%s/%s/%s-%s.jar";
|
||||
|
||||
String url = String.format(repo, this.groupId.replace(".", "/"), this.artifactId, this.version, this.artifactId, this.version);
|
||||
return new URL(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == this) return true;
|
||||
if (!(o instanceof Dependency)) return false;
|
||||
final Dependency other = (Dependency) o;
|
||||
return this.getGroupId().equals(other.getGroupId()) &&
|
||||
this.getArtifactId().equals(other.getArtifactId()) &&
|
||||
this.getVersion().equals(other.getVersion()) &&
|
||||
this.getRepoUrl().equals(other.getRepoUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int PRIME = 59;
|
||||
int result = 1;
|
||||
result = result * PRIME + this.getGroupId().hashCode();
|
||||
result = result * PRIME + this.getArtifactId().hashCode();
|
||||
result = result * PRIME + this.getVersion().hashCode();
|
||||
result = result * PRIME + this.getRepoUrl().hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "LibraryLoader.Dependency(" +
|
||||
"groupId=" + this.getGroupId() + ", " +
|
||||
"artifactId=" + this.getArtifactId() + ", " +
|
||||
"version=" + this.getVersion() + ", " +
|
||||
"repoUrl=" + this.getRepoUrl() + ")";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* This file is part of helper, 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.depends;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Annotation to indicate the required libraries for a class.
|
||||
*/
|
||||
@Documented
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MavenLibraries {
|
||||
|
||||
@Nonnull
|
||||
MavenLibrary[] value() default {};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* This file is part of helper, 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.depends;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Annotation to indicate a required library for a class.
|
||||
*/
|
||||
@Documented
|
||||
@Repeatable(MavenLibraries.class)
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface MavenLibrary {
|
||||
|
||||
/**
|
||||
* The group id of the library
|
||||
*
|
||||
* @return the group id of the library
|
||||
*/
|
||||
@Nonnull
|
||||
String groupId();
|
||||
|
||||
/**
|
||||
* The artifact id of the library
|
||||
*
|
||||
* @return the artifact id of the library
|
||||
*/
|
||||
@Nonnull
|
||||
String artifactId();
|
||||
|
||||
/**
|
||||
* The version of the library
|
||||
*
|
||||
* @return the version of the library
|
||||
*/
|
||||
@Nonnull
|
||||
String version();
|
||||
|
||||
/**
|
||||
* The repo where the library can be obtained from
|
||||
*
|
||||
* @return the repo where the library can be obtained from
|
||||
*/
|
||||
@Nonnull
|
||||
Repository repo() default @Repository(url = "https://repo1.maven.org/maven2");
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This file is part of helper, 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.depends;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* Represents a maven repository.
|
||||
*/
|
||||
@Documented
|
||||
@Target(ElementType.LOCAL_VARIABLE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Repository {
|
||||
|
||||
/**
|
||||
* Gets the base url of the repository.
|
||||
*
|
||||
* @return the base url of the repository
|
||||
*/
|
||||
@Nonnull
|
||||
String url();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* This file is part of helper, 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.depends;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Provides access to {@link URLClassLoader}#addURL.
|
||||
*/
|
||||
public abstract class URLClassLoaderAccess {
|
||||
|
||||
/**
|
||||
* Creates a {@link URLClassLoaderAccess} for the given class loader.
|
||||
*
|
||||
* @param classLoader the class loader
|
||||
* @return the access object
|
||||
*/
|
||||
static URLClassLoaderAccess create(URLClassLoader classLoader) {
|
||||
if (Reflection.isSupported()) {
|
||||
return new Reflection(classLoader);
|
||||
} else if (Unsafe.isSupported()) {
|
||||
return new Unsafe(classLoader);
|
||||
} else {
|
||||
return Noop.INSTANCE;
|
||||
}
|
||||
}
|
||||
|
||||
private final URLClassLoader classLoader;
|
||||
|
||||
protected URLClassLoaderAccess(URLClassLoader classLoader) {
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds the given URL to the class loader.
|
||||
*
|
||||
* @param url the URL to add
|
||||
*/
|
||||
public abstract void addURL(@Nonnull URL url);
|
||||
|
||||
/**
|
||||
* Accesses using reflection, not supported on Java 9+.
|
||||
*/
|
||||
private static class Reflection extends URLClassLoaderAccess {
|
||||
private static final Method ADD_URL_METHOD;
|
||||
|
||||
static {
|
||||
Method addUrlMethod;
|
||||
try {
|
||||
addUrlMethod = URLClassLoader.class.getDeclaredMethod("addURL", URL.class);
|
||||
addUrlMethod.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
addUrlMethod = null;
|
||||
}
|
||||
ADD_URL_METHOD = addUrlMethod;
|
||||
}
|
||||
|
||||
private static boolean isSupported() {
|
||||
return ADD_URL_METHOD != null;
|
||||
}
|
||||
|
||||
Reflection(URLClassLoader classLoader) {
|
||||
super(classLoader);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addURL(@Nonnull URL url) {
|
||||
try {
|
||||
ADD_URL_METHOD.invoke(super.classLoader, url);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Accesses using sun.misc.Unsafe, supported on Java 9+.
|
||||
*
|
||||
* @author Vaishnav Anil (https://github.com/slimjar/slimjar)
|
||||
*/
|
||||
private static class Unsafe extends URLClassLoaderAccess {
|
||||
private static final sun.misc.Unsafe UNSAFE;
|
||||
|
||||
static {
|
||||
sun.misc.Unsafe unsafe;
|
||||
try {
|
||||
Field unsafeField = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
|
||||
unsafeField.setAccessible(true);
|
||||
unsafe = (sun.misc.Unsafe) unsafeField.get(null);
|
||||
} catch (Throwable t) {
|
||||
unsafe = null;
|
||||
}
|
||||
UNSAFE = unsafe;
|
||||
}
|
||||
|
||||
private static boolean isSupported() {
|
||||
return UNSAFE != null;
|
||||
}
|
||||
|
||||
private final Collection<URL> unopenedURLs;
|
||||
private final Collection<URL> pathURLs;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Unsafe(URLClassLoader classLoader) {
|
||||
super(classLoader);
|
||||
|
||||
Collection<URL> unopenedURLs;
|
||||
Collection<URL> pathURLs;
|
||||
try {
|
||||
Object ucp = fetchField(URLClassLoader.class, classLoader, "ucp");
|
||||
unopenedURLs = (Collection<URL>) fetchField(ucp.getClass(), ucp, "unopenedUrls");
|
||||
pathURLs = (Collection<URL>) fetchField(ucp.getClass(), ucp, "path");
|
||||
} catch (Throwable e) {
|
||||
unopenedURLs = null;
|
||||
pathURLs = null;
|
||||
}
|
||||
this.unopenedURLs = unopenedURLs;
|
||||
this.pathURLs = pathURLs;
|
||||
}
|
||||
|
||||
private static Object fetchField(final Class<?> clazz, final Object object, final String name) throws NoSuchFieldException {
|
||||
Field field = clazz.getDeclaredField(name);
|
||||
long offset = UNSAFE.objectFieldOffset(field);
|
||||
return UNSAFE.getObject(object, offset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addURL(@Nonnull URL url) {
|
||||
this.unopenedURLs.add(url);
|
||||
this.pathURLs.add(url);
|
||||
}
|
||||
}
|
||||
|
||||
private static class Noop extends URLClassLoaderAccess {
|
||||
private static final Noop INSTANCE = new Noop();
|
||||
|
||||
private Noop() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addURL(@Nonnull URL url) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,10 +5,13 @@ import dev.brighten.ac.packet.wrapper.in.WPacketPlayInFlying;
|
||||
import dev.brighten.ac.packet.wrapper.out.WPacketPlayOutEntityVelocity;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.val;
|
||||
import org.bukkit.util.Consumer;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
public class VelocityHandler {
|
||||
|
||||
@@ -34,6 +34,7 @@ public class BlockUpdateHandler {
|
||||
* @param place
|
||||
*/
|
||||
public void onPlace(WPacketPlayInBlockPlace place) {
|
||||
player.getInfo().lastBlockUpdate.reset();
|
||||
// Could not possibly be a block placement as it's not a block a player is holding.
|
||||
IntVector pos = place.getBlockPos().clone();
|
||||
|
||||
@@ -68,6 +69,7 @@ public class BlockUpdateHandler {
|
||||
* @param dig
|
||||
*/
|
||||
public void onDig(WPacketPlayInBlockDig dig) {
|
||||
player.getInfo().lastBlockUpdate.reset();
|
||||
if(dig.getDigType() == WPacketPlayInBlockDig.EnumPlayerDigType.STOP_DESTROY_BLOCK) {
|
||||
Deque<Material> possible = getPossibleMaterials(dig.getBlockPos());
|
||||
possible.clear();
|
||||
@@ -76,6 +78,7 @@ public class BlockUpdateHandler {
|
||||
}
|
||||
|
||||
public void runUpdate(WPacketPlayOutBlockChange packet) {
|
||||
player.getInfo().lastBlockUpdate.reset();
|
||||
Deque<Material> blockInfo = blockInformation.compute(packet.getBlockLocation(), (blockLoc, blockI) -> {
|
||||
if(blockI == null) {
|
||||
blockI = new LinkedList<>();
|
||||
@@ -105,6 +108,7 @@ public class BlockUpdateHandler {
|
||||
}
|
||||
|
||||
public void runUpdate(WPacketPlayOutMultiBlockChange packet) {
|
||||
player.getInfo().lastBlockUpdate.reset();
|
||||
List<Tuple<Deque<Material>, Material>> changes = new ArrayList<>();
|
||||
for (WPacketPlayOutMultiBlockChange.BlockChange change : packet.getChanges()) {
|
||||
Deque<Material> blockInfo = blockInformation.compute(change.getLocation(), (blockLoc, blockI) -> {
|
||||
@@ -144,7 +148,7 @@ public class BlockUpdateHandler {
|
||||
}
|
||||
|
||||
public Deque<Material> getPossibleMaterials(IntVector loc) {
|
||||
return blockInformation.compute(loc, (blockLoc, blockI) -> {
|
||||
return new LinkedList<>(blockInformation.compute(loc, (blockLoc, blockI) -> {
|
||||
if(blockI == null) {
|
||||
blockI = new LinkedList<>();
|
||||
|
||||
@@ -160,6 +164,6 @@ public class BlockUpdateHandler {
|
||||
}
|
||||
|
||||
return blockI;
|
||||
});
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ public class KeepaliveProcessor implements Runnable {
|
||||
|
||||
currentKeepalive.startStamp = System.currentTimeMillis();
|
||||
totalPlayers = laggyPlayers = 0;
|
||||
if(Anticheat.INSTANCE.getPlayerRegistry() == null) return; //Temp fix for startup errors on plugman reload
|
||||
for (APlayer value : Anticheat.INSTANCE.getPlayerRegistry().aplayerMap.values()) {
|
||||
totalPlayers++;
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.handler.protocolsupport.impl.NoAPI;
|
||||
import dev.brighten.ac.handler.protocolsupport.impl.ProtocolSupport;
|
||||
import dev.brighten.ac.handler.protocolsupport.impl.ViaVersionAPI;
|
||||
import dev.brighten.ac.utils.Init;
|
||||
import dev.brighten.ac.utils.Instance;
|
||||
import dev.brighten.ac.utils.annotation.Init;
|
||||
import dev.brighten.ac.utils.annotation.Instance;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@@ -3,7 +3,7 @@ package dev.brighten.ac.handler.thread;
|
||||
import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.utils.Init;
|
||||
import dev.brighten.ac.utils.annotation.Init;
|
||||
import dev.brighten.ac.utils.MiscUtils;
|
||||
import dev.brighten.ac.utils.RunUtils;
|
||||
import lombok.Getter;
|
||||
|
||||
@@ -2,7 +2,7 @@ package dev.brighten.ac.listener;
|
||||
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.utils.Init;
|
||||
import dev.brighten.ac.utils.annotation.Init;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
||||
@@ -4,7 +4,7 @@ import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.packet.handler.HandlerAbstract;
|
||||
import dev.brighten.ac.packet.wrapper.PacketType;
|
||||
import dev.brighten.ac.utils.Init;
|
||||
import dev.brighten.ac.utils.annotation.Init;
|
||||
import dev.brighten.ac.utils.RunUtils;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package dev.brighten.ac.logging;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class Log {
|
||||
public UUID uuid;
|
||||
private float vl;
|
||||
private long time;
|
||||
private String data;
|
||||
private String checkId;
|
||||
}
|
||||
@@ -1,10 +1,25 @@
|
||||
package dev.brighten.ac.logging;
|
||||
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.check.CheckData;
|
||||
import dev.brighten.ac.data.APlayer;
|
||||
import dev.brighten.ac.logging.sql.ExecutableStatement;
|
||||
import dev.brighten.ac.logging.sql.MySQL;
|
||||
import dev.brighten.ac.logging.sql.Query;
|
||||
import dev.brighten.ac.logging.sql.ResultSetIterator;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Deque;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
|
||||
public class LoggerManager {
|
||||
|
||||
private final Deque<Log> logList = new LinkedList<>();
|
||||
|
||||
/*
|
||||
* Structure of Log
|
||||
* UUID hashcode (INT32),
|
||||
@@ -12,6 +27,63 @@ public class LoggerManager {
|
||||
public void init() {
|
||||
// Starting up H2
|
||||
MySQL.initH2();
|
||||
|
||||
Query.prepare("CREATE TABLE IF NOT EXISTS `logs` (" +
|
||||
"`id` INT NOT NULL AUTO_INCREMENT," +
|
||||
"`uuid` INT NOT NULL," +
|
||||
"`check` VARCHAR(32) NOT NULL," +
|
||||
"`vl` FLOAT NOT NULL," +
|
||||
"`data` MEDIUMTEXT NOT NULL," +
|
||||
"`time` TIMESTAMP NOT NULL," +
|
||||
"PRIMARY KEY (`id`)" +
|
||||
");").execute();
|
||||
|
||||
Anticheat.INSTANCE.getScheduler().scheduleAtFixedRate(() -> {
|
||||
if(logList.size() > 0) {
|
||||
synchronized (logList) {
|
||||
final StringBuilder values = new StringBuilder();
|
||||
|
||||
List<Object> objectsToInsert = new ArrayList<>();
|
||||
Log log = null;
|
||||
int amount = 0;
|
||||
while((log = logList.poll()) != null) {
|
||||
objectsToInsert.add(log.getUuid().toString());
|
||||
objectsToInsert.add(log.getCheckId());
|
||||
objectsToInsert.add(log.getVl());
|
||||
objectsToInsert.add(log.getData());
|
||||
objectsToInsert.add(new Timestamp(log.getTime()));
|
||||
|
||||
if(++amount >= 150) break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < amount; i++) {
|
||||
values.append(i > 0 ? "," : "").append("(?, ?, ?, ?, ?)");
|
||||
}
|
||||
|
||||
ExecutableStatement statement = Query.prepare("INSERT INTO `logs` " +
|
||||
"(`uuid`,`check`,`vl`,`data`,`time`) VALUES" + values.toString())
|
||||
.append(objectsToInsert.toArray());
|
||||
|
||||
statement.execute();
|
||||
|
||||
objectsToInsert.clear();
|
||||
}
|
||||
}
|
||||
}, 5, 10, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public void insertLog(APlayer player, CheckData checkData, float vl, long time, String data) {
|
||||
logList.add(Log.builder()
|
||||
.uuid(player.getUuid())
|
||||
.checkId(checkData.checkId())
|
||||
.vl(vl)
|
||||
.data(data)
|
||||
.time(time)
|
||||
.build());
|
||||
}
|
||||
|
||||
public void runQuery(String query, ResultSetIterator iterator) {
|
||||
Query.prepare(query).execute(iterator);
|
||||
}
|
||||
|
||||
public void shutDown() {
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package dev.brighten.ac.logging.sql;
|
||||
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.utils.reflections.Reflections;
|
||||
import dev.brighten.ac.utils.reflections.types.WrappedConstructor;
|
||||
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.Properties;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class MySQL {
|
||||
@@ -26,10 +28,11 @@ public class MySQL {
|
||||
}
|
||||
try {
|
||||
Class.forName("org.h2.Driver");
|
||||
conn = new NonClosableConnection(DriverManager.getConnection ("jdbc:h2:file:" +
|
||||
WrappedConstructor jdbcConnection = Reflections.getClass("org.h2.jdbc.JdbcConnection")
|
||||
.getConstructor(String.class, Properties.class);
|
||||
conn = new NonClosableConnection(jdbcConnection.newInstance("jdbc:h2:file:" +
|
||||
dataFolder.getAbsolutePath(),
|
||||
Anticheat.INSTANCE.getConfig().getString("database.username"),
|
||||
Anticheat.INSTANCE.getConfig().getString("database.password")));
|
||||
new Properties()));
|
||||
conn.setAutoCommit(true);
|
||||
Query.use(conn);
|
||||
Bukkit.getLogger().info("Connection to H2 SQlLite has been established.");
|
||||
|
||||
@@ -24,8 +24,6 @@ public abstract class HandlerAbstract{
|
||||
if(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_8)) {
|
||||
handler = new ModernHandler();
|
||||
} else handler = new LegacyHandler();
|
||||
|
||||
Bukkit.getOnlinePlayers().forEach(handler::add);
|
||||
}
|
||||
|
||||
public static void shutdown() {
|
||||
|
||||
@@ -43,12 +43,12 @@ public class AxisAlignedBB {
|
||||
}
|
||||
|
||||
public AxisAlignedBB(Location blockposition, Location blockposition1) {
|
||||
this.minX = (double) blockposition.getBlockX();
|
||||
this.minY = (double) blockposition.getBlockY();
|
||||
this.minZ = (double) blockposition.getBlockZ();
|
||||
this.maxX = (double) blockposition1.getBlockX();
|
||||
this.maxY = (double) blockposition1.getBlockY();
|
||||
this.maxZ = (double) blockposition1.getBlockZ();
|
||||
this.minX = blockposition.getBlockX();
|
||||
this.minY = blockposition.getBlockY();
|
||||
this.minZ = blockposition.getBlockZ();
|
||||
this.maxX = blockposition1.getBlockX();
|
||||
this.maxY = blockposition1.getBlockY();
|
||||
this.maxZ = blockposition1.getBlockZ();
|
||||
}
|
||||
|
||||
public AxisAlignedBB a(double d0, double d1, double d2) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.brighten.ac.utils;
|
||||
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.utils.annotation.Init;
|
||||
import dev.brighten.ac.utils.reflections.Reflections;
|
||||
import dev.brighten.ac.utils.reflections.types.WrappedClass;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
@@ -20,12 +20,12 @@ import java.util.function.Consumer;
|
||||
@Getter
|
||||
public class
|
||||
CollisionHandler {
|
||||
private List<Block> blocks;
|
||||
private List<Entity> entities;
|
||||
private APlayer data;
|
||||
private KLocation location;
|
||||
private List<Triad<Double[], Integer, Consumer<Boolean>>> intersects = new ArrayList<>(),
|
||||
collides = new ArrayList<>();
|
||||
private final List<Block> blocks;
|
||||
private final List<Entity> entities;
|
||||
private final APlayer data;
|
||||
private final KLocation location;
|
||||
private final List<Triad<Double[], Integer, Consumer<Boolean>>> intersects = new ArrayList<>();
|
||||
private final List<Triad<Double[], Integer, Consumer<Boolean>>> collides = new ArrayList<>();
|
||||
|
||||
private double width, height;
|
||||
private double shift;
|
||||
@@ -62,7 +62,7 @@ CollisionHandler {
|
||||
}
|
||||
|
||||
public void intersectsWithFuture(int bitMask, Consumer<Boolean> intersects) {
|
||||
String bitMaskString = String.valueOf(bitMask) + "%%__NONCE__%%";
|
||||
String bitMaskString = bitMask + "%%__NONCE__%%";
|
||||
this.intersects.add(new Triad<>(new Double[] {width, height, shift}, bitMask, intersects));
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ public class ExpTimer {
|
||||
public final long extense;
|
||||
public final Runnable onComplete;
|
||||
public BukkitTask levelTask, expTask;
|
||||
private int previousLevel;
|
||||
private float previousExp;
|
||||
private final int previousLevel;
|
||||
private final float previousExp;
|
||||
|
||||
public ExpTimer(Player player, long time, TimeUnit unit, Runnable onComplete) {
|
||||
this.player = player;
|
||||
|
||||
@@ -4,7 +4,6 @@ import dev.brighten.ac.packet.ProtocolVersion;
|
||||
import dev.brighten.ac.packet.handler.HandlerAbstract;
|
||||
import dev.brighten.ac.packet.wrapper.objects.EnumParticle;
|
||||
import dev.brighten.ac.packet.wrapper.out.WPacketPlayOutWorldParticles;
|
||||
import dev.brighten.ac.utils.handlers.PlayerSizeHandler;
|
||||
import dev.brighten.ac.utils.world.BlockData;
|
||||
import dev.brighten.ac.utils.world.CollisionBox;
|
||||
import dev.brighten.ac.utils.world.types.RayCollision;
|
||||
@@ -36,10 +35,6 @@ public class Helper {
|
||||
return vector;
|
||||
}
|
||||
|
||||
public static SimpleCollisionBox getMovementHitbox(Player player, double x, double y, double z) {
|
||||
return PlayerSizeHandler.instance.bounds(player, x, y, z);
|
||||
}
|
||||
|
||||
public static void drawRay(RayCollision collision, double distance, EnumParticle particle, Collection<? extends Player> players) {
|
||||
for (double i = 0; i < 3; i += 0.2) {
|
||||
float fx = (float) (collision.originX + (collision.directionX * i));
|
||||
@@ -148,16 +143,6 @@ public class Helper {
|
||||
|
||||
}
|
||||
|
||||
public static SimpleCollisionBox getMovementHitbox(Player player) {
|
||||
return PlayerSizeHandler.instance.bounds(player);
|
||||
}
|
||||
|
||||
public static SimpleCollisionBox getCombatHitbox(Player player, ProtocolVersion version) {
|
||||
return version.isBelow(ProtocolVersion.V1_9)
|
||||
? PlayerSizeHandler.instance.bounds(player).expand(.1, 0, .1)
|
||||
: PlayerSizeHandler.instance.bounds(player);
|
||||
}
|
||||
|
||||
public static Block getBlockAt(World world, int x, int y, int z) {
|
||||
return world.isChunkLoaded(x >> 4, z >> 4)
|
||||
? world.getChunkAt(x >> 4, z >> 4).getBlock(x & 15, y, z & 15)
|
||||
|
||||
@@ -25,7 +25,7 @@ import java.util.stream.Collectors;
|
||||
* @version 1.3
|
||||
*/
|
||||
public class ItemBuilder {
|
||||
private ItemStack is;
|
||||
private final ItemStack is;
|
||||
/**
|
||||
* Inits the builder with the given {@link Material}
|
||||
*
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This file is part of helper, 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.utils;
|
||||
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Utility for quickly accessing a logger instance without using {@link Bukkit#getLogger()}
|
||||
*/
|
||||
public final class Log {
|
||||
|
||||
public static void info(@Nonnull String s) {
|
||||
Anticheat.INSTANCE.getLogger().info(s);
|
||||
}
|
||||
|
||||
public static void warn(@Nonnull String s) {
|
||||
Anticheat.INSTANCE.getLogger().warning(s);
|
||||
}
|
||||
|
||||
public static void severe(@Nonnull String s) {
|
||||
Anticheat.INSTANCE.getLogger().severe(s);
|
||||
}
|
||||
|
||||
public static void warn(@Nonnull String s, Throwable t) {
|
||||
Anticheat.INSTANCE.getLogger().log(Level.WARNING, s, t);
|
||||
}
|
||||
|
||||
public static void severe(@Nonnull String s, Throwable t) {
|
||||
Anticheat.INSTANCE.getLogger().log(Level.SEVERE, s, t);
|
||||
}
|
||||
|
||||
private Log() {
|
||||
throw new UnsupportedOperationException("This class cannot be instantiated");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,11 +42,11 @@ public class MathHelper {
|
||||
}
|
||||
|
||||
for (int j = 0; j < 4096; ++j) {
|
||||
SIN_TABLE_FAST[j] = (float) Math.sin((double) (((float) j + 0.5F) / 4096.0F * ((float) Math.PI * 2F)));
|
||||
SIN_TABLE_FAST[j] = (float) Math.sin(((float) j + 0.5F) / 4096.0F * ((float) Math.PI * 2F));
|
||||
}
|
||||
|
||||
for (int l = 0; l < 360; l += 90) {
|
||||
SIN_TABLE_FAST[(int) ((float) l * 11.377778F) & 4095] = (float) Math.sin((double) ((float) l * 0.017453292F));
|
||||
SIN_TABLE_FAST[(int) ((float) l * 11.377778F) & 4095] = (float) Math.sin((float) l * 0.017453292F);
|
||||
}
|
||||
|
||||
multiplyDeBruijnBitPosition = new int[]{0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8, 31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9};
|
||||
@@ -77,7 +77,7 @@ public class MathHelper {
|
||||
}
|
||||
|
||||
public static float sqrt_float(float value) {
|
||||
return (float) Math.sqrt((double) value);
|
||||
return (float) Math.sqrt(value);
|
||||
}
|
||||
|
||||
public static float sqrt_double(double value) {
|
||||
@@ -364,7 +364,7 @@ public class MathHelper {
|
||||
}
|
||||
|
||||
public static long getCoordinateRandom(int x, int y, int z) {
|
||||
long i = (long) (x * 3129871) ^ (long) z * 116129781L ^ (long) y;
|
||||
long i = (long) (x * 3129871L) ^ (long) z * 116129781L ^ (long) y;
|
||||
i = i * i * 42317861L + i * 11L;
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -706,7 +706,7 @@ public class MathUtils {
|
||||
public static double trim(int degree, double d) {
|
||||
String format = "#.#";
|
||||
for (int i = 1; i < degree; ++i) {
|
||||
format = String.valueOf(format) + "#";
|
||||
format = format + "#";
|
||||
}
|
||||
DecimalFormat twoDForm = new DecimalFormat(format);
|
||||
return Double.parseDouble(twoDForm.format(d).replaceAll(",", "."));
|
||||
@@ -715,7 +715,7 @@ public class MathUtils {
|
||||
public static float trimFloat(int degree, float d) {
|
||||
String format = "#.#";
|
||||
for (int i = 1; i < degree; ++i) {
|
||||
format = String.valueOf(format) + "#";
|
||||
format = format + "#";
|
||||
}
|
||||
DecimalFormat twoDForm = new DecimalFormat(format);
|
||||
return Float.parseFloat(twoDForm.format(d).replaceAll(",", "."));
|
||||
@@ -749,7 +749,7 @@ public class MathUtils {
|
||||
});
|
||||
|
||||
//Calculating the largest value to the key, which would be the mode.
|
||||
return (T) repeated.keySet().stream()
|
||||
return repeated.keySet().stream()
|
||||
.map(key -> new Tuple<>(key, repeated.get(key))) //We map it into a Tuple for easier sorting.
|
||||
.max(Comparator.comparing(tup -> tup.two, Comparator.naturalOrder()))
|
||||
.orElseThrow(NullPointerException::new).one;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class MiscUtils {
|
||||
.filter(mat -> mat.name().contains("LEGACY"))
|
||||
.toArray(Material[]::new);
|
||||
|
||||
public static Map<EntityType, Vector> entityDimensions = new HashMap<>();;
|
||||
public static Map<EntityType, Vector> entityDimensions = new HashMap<>();
|
||||
|
||||
public static boolean containsIgnoreCase(String toCheck, String contains) {
|
||||
return toCheck.toLowerCase().contains(contains.toLowerCase());
|
||||
@@ -256,7 +256,7 @@ public class MiscUtils {
|
||||
return total;
|
||||
}
|
||||
|
||||
private static WrappedClass materialClass = new WrappedClass(Material.class);
|
||||
private static final WrappedClass materialClass = new WrappedClass(Material.class);
|
||||
public static Material match(String material) {
|
||||
if(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_13)) {
|
||||
return materialClass
|
||||
@@ -372,11 +372,11 @@ public class MiscUtils {
|
||||
if(p.getDescription().getName().equalsIgnoreCase(pl)) {
|
||||
pm.disablePlugin(p);
|
||||
var21 = var21 + p.getName() + " ";
|
||||
if(plugins != null && plugins.contains(p)) {
|
||||
if(plugins != null) {
|
||||
plugins.remove(p);
|
||||
}
|
||||
|
||||
if(names != null && names.containsKey(pl)) {
|
||||
if(names != null) {
|
||||
names.remove(pl);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Pastebin {
|
||||
}
|
||||
|
||||
static String checkResponse(String response) {
|
||||
if (response.substring(0, 15).equals("Bad API request")) {
|
||||
if (response.startsWith("Bad API request")) {
|
||||
return response.substring(17);
|
||||
}
|
||||
return "";
|
||||
@@ -74,7 +74,7 @@ public class Pastebin {
|
||||
"application/x-www-form-urlencoded");
|
||||
|
||||
connection.setRequestProperty("Content-Length",
|
||||
"" + Integer.toString(urlParameters.getBytes().length));
|
||||
"" + urlParameters.getBytes().length);
|
||||
connection.setRequestProperty("Content-Language", "en-US");
|
||||
|
||||
connection.setDoInput(true);
|
||||
@@ -110,10 +110,10 @@ public class Pastebin {
|
||||
}
|
||||
}
|
||||
|
||||
public static enum Privacy {
|
||||
public enum Privacy {
|
||||
PUBLIC(0), UNLISTED(1), PRIVATE(2);
|
||||
|
||||
private int privacy;
|
||||
private final int privacy;
|
||||
|
||||
Privacy(int privacy) {
|
||||
this.privacy = privacy;
|
||||
|
||||
@@ -27,13 +27,13 @@ import java.util.logging.Level;
|
||||
|
||||
public class ReflectionsUtil {
|
||||
public static Class<?> blockPosition = null;
|
||||
private static String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||
private static final String version = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
|
||||
public static Class<?> EntityPlayer = getNMSClass("EntityPlayer");
|
||||
public static Class<?> Entity = getNMSClass("Entity");
|
||||
public static Class<?> CraftPlayer = getCBClass("entity.CraftPlayer");
|
||||
public static Class<?> CraftEntity = getCBClass("entity.CraftEntity");
|
||||
public static Class<?> CraftWorld = getCBClass("CraftWorld");
|
||||
private static Class<?> craftServer = getCBClass("CraftServer");
|
||||
private static final Class<?> craftServer = getCBClass("CraftServer");
|
||||
public static Class<?> World = getNMSClass("World");
|
||||
public static Class<?> worldServer = getNMSClass("WorldServer");
|
||||
public static Class<?> playerConnection = getNMSClass("PlayerConnection");
|
||||
@@ -42,9 +42,9 @@ public class ReflectionsUtil {
|
||||
public static Class<?> packet = getNMSClass("Packet");
|
||||
public static Class<?> iBlockData = null;
|
||||
public static Class<?> iBlockAccess = null;
|
||||
private static Class<?> vanillaBlock = getNMSClass("Block");
|
||||
private static Method getCubes = getMethod(World, "a", getNMSClass("AxisAlignedBB"));
|
||||
private static Method getCubes1_12 = getMethod(World, "getCubes", getNMSClass("Entity"), getNMSClass("AxisAlignedBB"));
|
||||
private static final Class<?> vanillaBlock = getNMSClass("Block");
|
||||
private static final Method getCubes = getMethod(World, "a", getNMSClass("AxisAlignedBB"));
|
||||
private static final Method getCubes1_12 = getMethod(World, "getCubes", getNMSClass("Entity"), getNMSClass("AxisAlignedBB"));
|
||||
|
||||
public static Object getEntityPlayer(Player player) {
|
||||
return getMethodValue(getMethod(CraftPlayer, "getHandle"), player);
|
||||
@@ -122,7 +122,7 @@ public class ReflectionsUtil {
|
||||
return getMethodValue(getMethod(getCBClass("inventory.CraftInventoryPlayer"), "getInventory"), player.getInventory());
|
||||
}
|
||||
|
||||
private static Field frictionFactorField = getFieldByName(vanillaBlock, "frictionFactor");
|
||||
private static final Field frictionFactorField = getFieldByName(vanillaBlock, "frictionFactor");
|
||||
public static float getFriction(Block block) {
|
||||
Object blockNMS = getVanillaBlock(block);
|
||||
|
||||
@@ -287,7 +287,7 @@ public class ReflectionsUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static Method getItemMethod = getMethod(nmsItemStack, "getItem");
|
||||
private static final Method getItemMethod = getMethod(nmsItemStack, "getItem");
|
||||
public static Object getVanillaItem(ItemStack itemStack) {
|
||||
return getMethodValue(getMethod(nmsItemStack, "getItem"), getVanillaItemStack(itemStack));
|
||||
}
|
||||
@@ -473,7 +473,7 @@ public class ReflectionsUtil {
|
||||
: getMethodValue(getCubes, world, axisAlignedBB));
|
||||
}
|
||||
|
||||
private static Method craftWorldHandle = getMethod(CraftWorld, "getHandle");
|
||||
private static final Method craftWorldHandle = getMethod(CraftWorld, "getHandle");
|
||||
public static Object getWorldHandle(org.bukkit.World world) {
|
||||
return getMethodValue(craftWorldHandle, world);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class Step {
|
||||
|
||||
public static class GenericStepper<T> implements Iterator<T>, Iterable<T> {
|
||||
|
||||
private Link<T> first;
|
||||
private final Link<T> first;
|
||||
private Link<T> link;
|
||||
|
||||
public GenericStepper(Link<T> link) {
|
||||
|
||||
@@ -35,7 +35,7 @@ public class Vec3D {
|
||||
}
|
||||
|
||||
public Vec3D(Location var1) {
|
||||
this((double)var1.getX(), (double)var1.getY(), (double)var1.getZ());
|
||||
this(var1.getX(), var1.getY(), var1.getZ());
|
||||
}
|
||||
|
||||
public Vec3D a(Vec3D var1) {
|
||||
@@ -43,7 +43,7 @@ public class Vec3D {
|
||||
}
|
||||
|
||||
public Vec3D a() {
|
||||
double var1 = (double) MathHelper.sqrt_double(this.x * this.x + this.y * this.y + this.z * this.z);
|
||||
double var1 = MathHelper.sqrt_double(this.x * this.x + this.y * this.y + this.z * this.z);
|
||||
return var1 < 1.0E-4D ? a : new Vec3D(this.x / var1, this.y / var1, this.z / var1);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ public class Vec3D {
|
||||
double var2 = var1.x - this.x;
|
||||
double var4 = var1.y - this.y;
|
||||
double var6 = var1.z - this.z;
|
||||
return (double)MathHelper.sqrt_double(var2 * var2 + var4 * var4 + var6 * var6);
|
||||
return MathHelper.sqrt_double(var2 * var2 + var4 * var4 + var6 * var6);
|
||||
}
|
||||
|
||||
public double distanceSquared(Vec3D var1) {
|
||||
@@ -97,7 +97,7 @@ public class Vec3D {
|
||||
}
|
||||
|
||||
public double b() {
|
||||
return (double)MathHelper.sqrt_double(this.x * this.x + this.y * this.y + this.z * this.z);
|
||||
return MathHelper.sqrt_double(this.x * this.x + this.y * this.y + this.z * this.z);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -1788,7 +1788,7 @@ public enum XMaterial {
|
||||
* @since 3.0.0
|
||||
*/
|
||||
@Nonnull
|
||||
protected static Optional<XMaterial> matchDefinedXMaterial(@Nonnull String name, byte data) {
|
||||
private static Optional<XMaterial> matchDefinedXMaterial(@Nonnull String name, byte data) {
|
||||
// if (!Boolean.valueOf(Boolean.getBoolean(Boolean.TRUE.toString())).equals(Boolean.FALSE.booleanValue())) return null;
|
||||
Boolean duplicated = null;
|
||||
boolean isAMap = name.equalsIgnoreCase("MAP");
|
||||
@@ -1863,7 +1863,7 @@ public enum XMaterial {
|
||||
* @since 2.0.0
|
||||
*/
|
||||
@Nonnull
|
||||
protected static String format(@Nonnull String name) {
|
||||
private static String format(@Nonnull String name) {
|
||||
int len = name.length();
|
||||
char[] chs = new char[len];
|
||||
int count = 0;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package dev.brighten.ac.utils;
|
||||
package dev.brighten.ac.utils.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package dev.brighten.ac.utils;
|
||||
package dev.brighten.ac.utils.annotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package dev.brighten.ac.utils;
|
||||
package dev.brighten.ac.utils.annotation;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package dev.brighten.ac.utils;
|
||||
package dev.brighten.ac.utils.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
+3
-1
@@ -1,4 +1,6 @@
|
||||
package dev.brighten.ac.utils;
|
||||
package dev.brighten.ac.utils.annotation;
|
||||
|
||||
import dev.brighten.ac.utils.Priority;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package dev.brighten.ac.utils;
|
||||
package dev.brighten.ac.utils.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package dev.brighten.ac.utils;
|
||||
package dev.brighten.ac.utils.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* This file is part of helper, 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.utils.annotation;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
@Nonnull
|
||||
@Documented
|
||||
@TypeQualifierDefault({
|
||||
ElementType.FIELD,
|
||||
ElementType.METHOD,
|
||||
ElementType.PARAMETER
|
||||
})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface NonnullByDefault {
|
||||
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public class JsonConfiguration extends ConfigurationProvider
|
||||
@Override
|
||||
public JsonElement serialize(Configuration src, Type typeOfSrc, JsonSerializationContext context)
|
||||
{
|
||||
return context.serialize( ( (Configuration) src ).self );
|
||||
return context.serialize( src.self );
|
||||
}
|
||||
} ).create();
|
||||
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
package dev.brighten.ac.utils.handlers;
|
||||
|
||||
import dev.brighten.ac.packet.ProtocolVersion;
|
||||
import dev.brighten.ac.utils.world.types.SimpleCollisionBox;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public interface PlayerSizeHandler {
|
||||
|
||||
PlayerSizeHandler instance = getInstance();
|
||||
|
||||
double height(Player player);
|
||||
double width(Player player);
|
||||
|
||||
default SimpleCollisionBox bounds(Player player) {
|
||||
Location l = player.getLocation();
|
||||
return bounds(player,l.getX(),l.getY(),l.getZ());
|
||||
}
|
||||
|
||||
default SimpleCollisionBox bounds(Player player, double x, double y, double z) {
|
||||
double width = width(player);
|
||||
return new SimpleCollisionBox().offset(x,y,z).expand(width,0,width).expandMax(0,height(player),0);
|
||||
}
|
||||
|
||||
static PlayerSizeHandler getInstance() {
|
||||
if (instance!=null)
|
||||
return instance;
|
||||
|
||||
try {
|
||||
return ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_12)
|
||||
? new PlayerSizeHandlerModern()
|
||||
: new PlayerSizeHandlerLegacy();
|
||||
} catch(Exception e) {
|
||||
return new PlayerSizeHandlerLegacy();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package dev.brighten.ac.utils.handlers;
|
||||
|
||||
import dev.brighten.ac.utils.world.types.SimpleCollisionBox;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerSizeHandlerLegacy implements PlayerSizeHandler {
|
||||
|
||||
@Override
|
||||
public double height(Player player) {
|
||||
return 1.8;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double width(Player player) {
|
||||
return 0.6;
|
||||
}
|
||||
|
||||
public SimpleCollisionBox bounds(Player player) {
|
||||
Location l = player.getLocation();
|
||||
return new SimpleCollisionBox().offset(l.getX(), l.getY(), l.getZ()).expand(.3,0,.3).expandMax(0,1.8,0);
|
||||
}
|
||||
public SimpleCollisionBox bounds(Player player, double x, double y, double z) {
|
||||
return new SimpleCollisionBox().offset(x,y,z).expand(.3,0,.3).expandMax(0,1.8,0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package dev.brighten.ac.utils.handlers;
|
||||
|
||||
import dev.brighten.ac.utils.reflections.types.WrappedClass;
|
||||
import dev.brighten.ac.utils.reflections.types.WrappedMethod;
|
||||
import dev.brighten.ac.utils.world.types.SimpleCollisionBox;
|
||||
import lombok.SneakyThrows;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerSizeHandlerModern implements PlayerSizeHandler {
|
||||
|
||||
private final WrappedMethod width;
|
||||
private final WrappedMethod height;
|
||||
private final WrappedMethod gliding;
|
||||
private static WrappedClass entityClass = new WrappedClass(Entity.class);
|
||||
|
||||
public PlayerSizeHandlerModern() {
|
||||
width = entityClass.getMethod("getWidth");
|
||||
height = entityClass.getMethod("getHeight");
|
||||
gliding = entityClass.getMethod("isGliding");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public double height(Player player) {
|
||||
return (double) height.invoke(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public double width(Player player) {
|
||||
return (double) width.invoke(player);
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
public SimpleCollisionBox bounds(Player player) {
|
||||
Location l = player.getLocation();
|
||||
double width = (double) this.width.invoke(player)/2;
|
||||
double height = this.height.invoke(player);
|
||||
return new SimpleCollisionBox().offset(l.getX(), l.getY(), l.getZ()).expand(width,0,width).expandMax(0,height,0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SneakyThrows
|
||||
public SimpleCollisionBox bounds(Player player, double x, double y, double z) {
|
||||
double width = (double) this.width.invoke(player)/2;
|
||||
double height = this.height.invoke(player);
|
||||
return new SimpleCollisionBox().offset(x,y,z).expand(width,0,width).expandMax(0,height,0);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,10 +27,7 @@ public class RayTrace {
|
||||
return false;
|
||||
} else if (position.getY() < min.getY() || position.getY() > max.getY()) {
|
||||
return false;
|
||||
} else if (position.getZ() < min.getZ() || position.getZ() > max.getZ()) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} else return !(position.getZ() < min.getZ()) && !(position.getZ() > max.getZ());
|
||||
}
|
||||
|
||||
//get a point on the raytrace at X blocks away
|
||||
@@ -41,11 +38,7 @@ public class RayTrace {
|
||||
//checks if a position is on contained within the position
|
||||
public boolean isOnLine(Vector position) {
|
||||
double t = (position.getX() - origin.getX()) / direction.getX();
|
||||
;
|
||||
if (position.getBlockY() == origin.getY() + (t * direction.getY()) && position.getBlockZ() == origin.getZ() + (t * direction.getZ())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return position.getBlockY() == origin.getY() + (t * direction.getY()) && position.getBlockZ() == origin.getZ() + (t * direction.getZ());
|
||||
}
|
||||
|
||||
//get all postions on a raytrace
|
||||
|
||||
@@ -79,7 +79,7 @@ public interface Menu extends Iterable<Button> {
|
||||
* @throws IndexOutOfBoundsException If the index is out of bounds this is thrown
|
||||
*/
|
||||
|
||||
public void checkBounds(int index) throws IndexOutOfBoundsException;
|
||||
void checkBounds(int index) throws IndexOutOfBoundsException;
|
||||
|
||||
/**
|
||||
* Gets the {@link Button} at the specified index
|
||||
|
||||
@@ -3,7 +3,7 @@ package dev.brighten.ac.utils.menu;
|
||||
import dev.brighten.ac.Anticheat;
|
||||
import dev.brighten.ac.packet.ProtocolVersion;
|
||||
import dev.brighten.ac.utils.Color;
|
||||
import dev.brighten.ac.utils.Init;
|
||||
import dev.brighten.ac.utils.annotation.Init;
|
||||
import dev.brighten.ac.utils.XMaterial;
|
||||
import dev.brighten.ac.utils.menu.button.Button;
|
||||
import dev.brighten.ac.utils.menu.button.ClickAction;
|
||||
|
||||
@@ -13,7 +13,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class SettingButton extends Button {
|
||||
|
||||
private Setting<?> setting;
|
||||
private final Setting<?> setting;
|
||||
private AtomicInteger current;
|
||||
|
||||
public SettingButton(Player player, String name, String description, Setting<?> setting) {
|
||||
|
||||
@@ -120,11 +120,7 @@ public class ChestMenu implements Menu {
|
||||
|
||||
@Override
|
||||
public void showMenu(Player player) {
|
||||
if (holder == null) {
|
||||
buildInventory(true);
|
||||
} else {
|
||||
buildInventory(false);
|
||||
}
|
||||
buildInventory(holder == null);
|
||||
player.openInventory(holder.getInventory());
|
||||
}
|
||||
|
||||
|
||||
@@ -126,11 +126,7 @@ public class PagedMenu implements Menu {
|
||||
|
||||
@Override
|
||||
public void showMenu(Player player) {
|
||||
if (holder == null) {
|
||||
buildInventory(true);
|
||||
} else {
|
||||
buildInventory(false);
|
||||
}
|
||||
buildInventory(holder == null);
|
||||
player.openInventory(holder.getInventory());
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import net.md_5.bungee.api.chat.ComponentBuilder.FormatRetention;
|
||||
import net.md_5.bungee.api.chat.HoverEvent.Action;
|
||||
|
||||
public class ChatBuilder {
|
||||
private ComponentBuilder componentBuilder;
|
||||
private final ComponentBuilder componentBuilder;
|
||||
|
||||
public ChatBuilder(String text, Object... objects) {
|
||||
this.componentBuilder = new ComponentBuilder(String.format(Color.translate(text), objects));
|
||||
@@ -67,7 +67,7 @@ public class ChatBuilder {
|
||||
}
|
||||
|
||||
public ChatBuilder event(Action action, TextComponent component) {
|
||||
return this.event(action, TextComponent.fromLegacyText(TextComponent.toLegacyText(new BaseComponent[]{component})));
|
||||
return this.event(action, TextComponent.fromLegacyText(TextComponent.toLegacyText(component)));
|
||||
}
|
||||
|
||||
public ChatBuilder event(Action action, String string) {
|
||||
@@ -89,7 +89,7 @@ public class ChatBuilder {
|
||||
}
|
||||
|
||||
public static ChatBuilder create() {
|
||||
return new ChatBuilder("", new Object[0]);
|
||||
return new ChatBuilder("");
|
||||
}
|
||||
|
||||
public static ChatBuilder create(String text, Object... objects) {
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.util.stream.Stream;
|
||||
|
||||
public class Interval extends LinkedList<Double> {
|
||||
|
||||
private long max;
|
||||
private final long max;
|
||||
|
||||
public Interval(long max) {
|
||||
this.max = max;
|
||||
|
||||
@@ -12,7 +12,7 @@ public class MethodFunction {
|
||||
private BiFunction biFunc;
|
||||
private TriFunction triFunc;
|
||||
private QuadFunction quadFunc;
|
||||
private Method method;
|
||||
private final Method method;
|
||||
|
||||
public MethodFunction(Method method, Function function) {
|
||||
this.function = function;
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ConcurrentEvictingList<T> extends ConcurrentLinkedDeque<T> {
|
||||
private int maxSize;
|
||||
private final int maxSize;
|
||||
|
||||
public ConcurrentEvictingList(int maxSize) {
|
||||
this.maxSize = maxSize;
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class EvictingList<T> extends LinkedList<T> {
|
||||
private int maxSize;
|
||||
private final int maxSize;
|
||||
|
||||
public EvictingList(int maxSize) {
|
||||
this.maxSize = maxSize;
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class ConcurrentFilteredList<T> extends CopyOnWriteArrayList<T> {
|
||||
|
||||
private Predicate<T> predicate;
|
||||
private final Predicate<T> predicate;
|
||||
|
||||
public ConcurrentFilteredList(Predicate<T> predicate) {
|
||||
this.predicate = predicate;
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class ConcurrentFilteredSet<T> extends ConcurrentSkipListSet<T> {
|
||||
|
||||
private Predicate<T> predicate;
|
||||
private final Predicate<T> predicate;
|
||||
|
||||
public ConcurrentFilteredSet(Predicate<T> predicate) {
|
||||
this.predicate = predicate;
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class FilteredList<T> extends ArrayList<T> {
|
||||
|
||||
private Predicate<T> predicate;
|
||||
private final Predicate<T> predicate;
|
||||
|
||||
public FilteredList(Predicate<T> predicate) {
|
||||
this.predicate = predicate;
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class FilteredSet<T> extends HashSet<T> {
|
||||
|
||||
private Predicate<T> predicate;
|
||||
private final Predicate<T> predicate;
|
||||
|
||||
public FilteredSet(Predicate<T> predicate) {
|
||||
this.predicate = predicate;
|
||||
|
||||
@@ -26,8 +26,8 @@ public interface ListMap<K, V> {
|
||||
|
||||
@Getter
|
||||
class ContainsResult {
|
||||
private boolean result;
|
||||
private Object key;
|
||||
private final boolean result;
|
||||
private final Object key;
|
||||
protected ContainsResult(Object key, boolean result) {
|
||||
this.key = key;
|
||||
this.result = result;
|
||||
|
||||
@@ -28,7 +28,7 @@ import java.util.function.Function;
|
||||
public class Reflections {
|
||||
private static final String craftBukkitString;
|
||||
private static final String netMinecraftServerString;
|
||||
private static MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
private static final MethodHandles.Lookup lookup = MethodHandles.lookup();
|
||||
public static String OBC_PREFIX = Bukkit.getServer().getClass().getPackage().getName();
|
||||
public static String VERSION = OBC_PREFIX.replace("org.bukkit.craftbukkit", "")
|
||||
.replace(".", "");
|
||||
|
||||
@@ -28,18 +28,18 @@ public class CraftReflection {
|
||||
public static WrappedClass craftChatMessage = Reflections.getCBClass("util.CraftChatMessage");
|
||||
|
||||
//Vanilla Instances
|
||||
private static WrappedMethod itemStackInstance = craftItemStack.getMethod("asNMSCopy", ItemStack.class); //1.7-1.14
|
||||
private static WrappedMethod humanEntityInstance = craftHumanEntity.getMethod("getHandle"); //1.7-1.14
|
||||
private static WrappedMethod entityInstance = craftEntity.getMethod("getHandle"); //1.7-1.14
|
||||
private static WrappedMethod blockInstance = craftBlock.getMethod(ProtocolVersion.getGameVersion()
|
||||
private static final WrappedMethod itemStackInstance = craftItemStack.getMethod("asNMSCopy", ItemStack.class); //1.7-1.14
|
||||
private static final WrappedMethod humanEntityInstance = craftHumanEntity.getMethod("getHandle"); //1.7-1.14
|
||||
private static final WrappedMethod entityInstance = craftEntity.getMethod("getHandle"); //1.7-1.14
|
||||
private static final WrappedMethod blockInstance = craftBlock.getMethod(ProtocolVersion.getGameVersion()
|
||||
.isOrAbove(ProtocolVersion.V1_17_1) ? "getNMS" : "getNMSBlock"); //1.7-1.14
|
||||
private static WrappedMethod worldInstance = craftWorld.getMethod("getHandle"); //1.7-1.14
|
||||
private static WrappedMethod bukkitEntity = MinecraftReflection.entity.getMethod("getBukkitEntity"); //1.7-1.14
|
||||
private static WrappedMethod getInventory = craftInventoryPlayer.getMethod("getInventory"); //1.7-1.14
|
||||
private static WrappedMethod mcServerInstance = craftServer.getMethod("getServer"); //1.7-1.14
|
||||
private static WrappedMethod entityPlayerInstance = craftPlayer.getMethod("getHandle");
|
||||
private static WrappedMethod chunkInstance = craftChunk.getMethod("getHandle");
|
||||
private static WrappedMethod methodGetBlockFromMaterial = ProtocolVersion.getGameVersion()
|
||||
private static final WrappedMethod worldInstance = craftWorld.getMethod("getHandle"); //1.7-1.14
|
||||
private static final WrappedMethod bukkitEntity = MinecraftReflection.entity.getMethod("getBukkitEntity"); //1.7-1.14
|
||||
private static final WrappedMethod getInventory = craftInventoryPlayer.getMethod("getInventory"); //1.7-1.14
|
||||
private static final WrappedMethod mcServerInstance = craftServer.getMethod("getServer"); //1.7-1.14
|
||||
private static final WrappedMethod entityPlayerInstance = craftPlayer.getMethod("getHandle");
|
||||
private static final WrappedMethod chunkInstance = craftChunk.getMethod("getHandle");
|
||||
private static final WrappedMethod methodGetBlockFromMaterial = ProtocolVersion.getGameVersion()
|
||||
.isOrAbove(ProtocolVersion.V1_13) ? craftMagicNumbers.getMethod("getBlock", Material.class)
|
||||
: craftMagicNumbers.getMethod("getBlock", int.class);
|
||||
private static WrappedMethod fromComponent;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class MinecraftReflection {
|
||||
public static WrappedClass iBlockData, blockBase,
|
||||
chunkProviderServer = Reflections.getNMSClass("ChunkProviderServer");
|
||||
public static WrappedClass itemClass = Reflections.getNMSClass("Item"),
|
||||
enumChatFormat = Reflections.getNMSClass("EnumChatFormat");;
|
||||
enumChatFormat = Reflections.getNMSClass("EnumChatFormat");
|
||||
public static WrappedClass world = Reflections.getNMSClass("World");
|
||||
public static WrappedClass worldServer = Reflections.getNMSClass("WorldServer");
|
||||
public static WrappedClass playerInventory = Reflections.getNMSClass("PlayerInventory");
|
||||
@@ -222,7 +222,8 @@ public class MinecraftReflection {
|
||||
new WrappedClass(channel.getClass()).getMethod("close").invoke(channel);
|
||||
}
|
||||
|
||||
private static WrappedMethod fluidMethod, getFlowMethod;
|
||||
private static WrappedMethod fluidMethod;
|
||||
private static final WrappedMethod getFlowMethod;
|
||||
|
||||
public static ItemStack toBukkitItemStack(Object vanillaItemStack) {
|
||||
return itemStackAsBukkitCopy.invoke(null, vanillaItemStack);
|
||||
|
||||
@@ -25,11 +25,11 @@ import java.util.function.Function;
|
||||
@Getter
|
||||
public class WrappedMethod {
|
||||
private final WrappedClass parent;
|
||||
private Method method;
|
||||
private final Method method;
|
||||
private final String name;
|
||||
private MethodFunction mfunc;
|
||||
private final List<Class<?>> parameters;
|
||||
private boolean isVoid;
|
||||
private final boolean isVoid;
|
||||
|
||||
public WrappedMethod(WrappedClass parent, Method method) {
|
||||
this.name = method.getName();
|
||||
|
||||
@@ -419,7 +419,7 @@ public enum BlockData {
|
||||
|
||||
private CollisionBox box;
|
||||
private CollisionFactory dynamic;
|
||||
private Material[] materials;
|
||||
private final Material[] materials;
|
||||
|
||||
BlockData(CollisionBox box, Material... materials) {
|
||||
this.box = box;
|
||||
@@ -451,7 +451,7 @@ public enum BlockData {
|
||||
.offset(block.getX(), block.getY(), block.getZ());
|
||||
}
|
||||
|
||||
private static BlockData[] lookup = new BlockData[Material.values().length];
|
||||
private static final BlockData[] lookup = new BlockData[Material.values().length];
|
||||
|
||||
static {
|
||||
for (BlockData data : values()) {
|
||||
|
||||
@@ -27,8 +27,8 @@ public class EntityData {
|
||||
|
||||
//We cast this as a float since the fields are floats.
|
||||
|
||||
return new SimpleCollisionBox(new Vector(), (float)fieldWidth.get(ventity),
|
||||
(float)fieldLength.get(ventity));
|
||||
return new SimpleCollisionBox(new Vector(), fieldWidth.get(ventity),
|
||||
fieldLength.get(ventity));
|
||||
}).copy();
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ public class DoorHandler implements CollisionFactory {
|
||||
} else {
|
||||
Block blockTwo;
|
||||
Door door = (Door) b.getType().getNewData(b.getData());
|
||||
if ((boolean) door.isTopHalf()) {
|
||||
if (door.isTopHalf()) {
|
||||
Optional<Block> rel = BlockUtils.getRelativeAsync(b, BlockFace.DOWN);
|
||||
|
||||
if (!rel.isPresent()) return NoCollisionBox.INSTANCE;
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ComplexCollisionBox implements CollisionBox {
|
||||
private List<CollisionBox> boxes = new ArrayList<>();
|
||||
private final List<CollisionBox> boxes = new ArrayList<>();
|
||||
|
||||
public ComplexCollisionBox(CollisionBox... boxes) {
|
||||
Collections.addAll(this.boxes, boxes);
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
|
||||
public class DynamicCollisionBox implements CollisionBox {
|
||||
|
||||
private CollisionFactory box;
|
||||
private final CollisionFactory box;
|
||||
@Setter
|
||||
private Block block;
|
||||
@Setter
|
||||
|
||||
@@ -279,13 +279,9 @@ public class RayCollision implements CollisionBox {
|
||||
tFar = tymax >= tFar && !Double.isNaN(tFar) ? tFar : tymax;
|
||||
tNear = tzmin > tNear ? tzmin : tNear;
|
||||
tFar = tzmax < tFar ? tzmax : tFar;
|
||||
if (tNear < tFar && tFar >= 0.0D) {
|
||||
// result.x = tNear;
|
||||
// result.y = tFar;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
// result.x = tNear;
|
||||
// result.y = tFar;
|
||||
return tNear < tFar && tFar >= 0.0D;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user