diff --git a/Anticheat/pom.xml b/Anticheat/pom.xml index 77f9df8..4c277ef 100644 --- a/Anticheat/pom.xml +++ b/Anticheat/pom.xml @@ -19,6 +19,10 @@ + + maven-central + https://nexus.funkemunky.cc/repository/maven-central/ + viaversion-repo https://repo.viaversion.com @@ -39,6 +43,14 @@ lucko https://repo.lucko.me/ + + codemc-releases + https://repo.codemc.io/repository/maven-releases/ + + + codemc-snapshots + https://repo.codemc.io/repository/maven-snapshots/ + diff --git a/Anticheat/src/main/java/dev/brighten/ac/Anticheat.java b/Anticheat/src/main/java/dev/brighten/ac/Anticheat.java index 513ab02..236245b 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/Anticheat.java +++ b/Anticheat/src/main/java/dev/brighten/ac/Anticheat.java @@ -27,7 +27,6 @@ import dev.brighten.ac.utils.config.Configuration; import dev.brighten.ac.utils.config.ConfigurationProvider; import dev.brighten.ac.utils.config.YamlConfiguration; import dev.brighten.ac.utils.math.RollingAverageDouble; -import dev.brighten.ac.utils.reflections.types.WrappedMethod; import dev.brighten.ac.utils.timer.Timer; import dev.brighten.ac.utils.timer.impl.TickTimer; import dev.brighten.ac.utils.world.WorldInfo; @@ -58,6 +57,7 @@ import java.util.stream.Collectors; @MavenLibrary(groupId = "it.unimi.dsi", artifactId = "fastutil", version = "8.5.11", repo = @Repository(url = "https://repo1.maven.org/maven2")) @MavenLibrary(groupId = "org.ow2.asm", artifactId = "asm", version = "9.4", repo = @Repository(url = "https://repo1.maven.org/maven2")) @MavenLibrary(groupId = "org.ow2.asm", artifactId = "asm-tree", version = "9.4", repo = @Repository(url = "https://repo1.maven.org/maven2")) +@MavenLibrary(groupId = "org.dizitart", artifactId = "nitrite-jackson-mapper", version = "4.3.0", repo = @Repository(url = "https://repo1.maven.org/maven2")) public class Anticheat extends JavaPlugin { public static Anticheat INSTANCE; @@ -76,7 +76,6 @@ public class Anticheat extends JavaPlugin { private FakeEntityTracker fakeTracker; private int currentTick; private Deque onTickEnd = new LinkedList<>(); - private ServerInjector injector; //Lag Information private Timer lastTickLag; private long lastTick; @@ -87,9 +86,8 @@ public class Anticheat extends JavaPlugin { public static boolean allowDebug = true; @ConfigSetting(path = "logging", name = "verbose") - private static boolean verboseLogging = true; + private static final boolean verboseLogging = true; - private WrappedMethod findClassMethod; private Configuration anticheatConfig; public void onEnable() { @@ -155,7 +153,7 @@ public class Anticheat extends JavaPlugin { .orElse(null); } else if(!c.isOptional()) throw new InvalidCommandArgument(MessageKeys.NOT_ALLOWED_ON_CONSOLE, - false, new String[0]); + false); else return null; } }); @@ -168,9 +166,7 @@ public class Anticheat extends JavaPlugin { new AnticheatAPI(); new ClassScanner().initializeScanner(getClass(), this, - null, - true, - true); + null); if(!getAnticheatConfig().contains("database.username")) { getAnticheatConfig().set("database.username", "dbuser"); @@ -200,13 +196,6 @@ public class Anticheat extends JavaPlugin { alog(Color.Green + "Loading WorldInfo system..."); Bukkit.getWorlds().forEach(w -> worldInfoMap.put(w.getUID(), new WorldInfo(w))); - injector = new ServerInjector(); - try { - injector.inject(); - } catch (Exception e) { - e.printStackTrace(); - } - Bukkit.getOnlinePlayers().forEach(HandlerAbstract.getHandler()::add); } public void onDisable() { @@ -234,13 +223,6 @@ public class Anticheat extends JavaPlugin { CheckHandler.TO_HOOK.clear(); BBRevealHandler.INSTANCE = null; - try { - injector.eject(); - injector = null; - } catch (Exception e) { - throw new RuntimeException(e); - } - fakeTracker.despawnAll(); fakeTracker = null; @@ -255,7 +237,6 @@ public class Anticheat extends JavaPlugin { packetProcessor = null; packetHandler = null; - injector = null; onTickEnd.clear(); onTickEnd = null; diff --git a/Anticheat/src/main/java/dev/brighten/ac/check/CheckConfig.java b/Anticheat/src/main/java/dev/brighten/ac/check/CheckConfig.java index 0a3e7fb..170ecc4 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/check/CheckConfig.java +++ b/Anticheat/src/main/java/dev/brighten/ac/check/CheckConfig.java @@ -3,14 +3,13 @@ package dev.brighten.ac.check; import dev.brighten.ac.utils.annotation.ConfigSetting; import dev.brighten.ac.utils.annotation.Init; -import java.util.Arrays; import java.util.List; @Init public class CheckConfig { @ConfigSetting(name = "punishments.commands") - public static List punishmentCommands = Arrays.asList("kick %player% Unfair Advantage (%check%)"); + public static List punishmentCommands = List.of("kick %player% Unfair Advantage (%check%)"); @ConfigSetting(name = "alerts.clickCommand") public static String clickCommand = "tp %player%"; diff --git a/Anticheat/src/main/java/dev/brighten/ac/check/impl/combat/killaura/calc/impl/KAGrid.java b/Anticheat/src/main/java/dev/brighten/ac/check/impl/combat/killaura/calc/impl/KAGrid.java index 6ebebce..b18631a 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/check/impl/combat/killaura/calc/impl/KAGrid.java +++ b/Anticheat/src/main/java/dev/brighten/ac/check/impl/combat/killaura/calc/impl/KAGrid.java @@ -19,8 +19,7 @@ public class KAGrid extends Check implements RotationCheck { super(player); } - private int buffer; - private List offsetGrid = new EvictingList<>(50); + private final List offsetGrid = new EvictingList<>(50); @Override public void runCheck(Tuple locs, double[] std, double[] offset, float[] rot) { diff --git a/Anticheat/src/main/java/dev/brighten/ac/check/impl/movement/velocity/VelocityB.java b/Anticheat/src/main/java/dev/brighten/ac/check/impl/movement/velocity/VelocityB.java index 529c564..e2ea081 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/check/impl/movement/velocity/VelocityB.java +++ b/Anticheat/src/main/java/dev/brighten/ac/check/impl/movement/velocity/VelocityB.java @@ -286,11 +286,11 @@ public class VelocityB extends Check { } 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); } for (int j = 0; j < SIN_TABLE_FAST_NEW.length; ++j) { diff --git a/Anticheat/src/main/java/dev/brighten/ac/command/LogsCommand.java b/Anticheat/src/main/java/dev/brighten/ac/command/LogsCommand.java index 165ffac..0222fa1 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/command/LogsCommand.java +++ b/Anticheat/src/main/java/dev/brighten/ac/command/LogsCommand.java @@ -22,6 +22,7 @@ import java.nio.charset.StandardCharsets; import java.sql.Timestamp; import java.time.format.DateTimeFormatter; import java.util.*; +import java.util.logging.Level; @Init(priority = Priority.LOW) @CommandAlias("kauri|anticheat|ac") @@ -61,7 +62,7 @@ public class LogsCommand extends BaseCommand { + Anticheat.INSTANCE.getCheckManager().getIdToName().get(log.getCheckId()) + "(VL: " + log.getVl() + ") {" + log.getData() + "}"); }); - if(logs.size() == 0) { + if(logs.isEmpty()) { sender.sendMessage(Color.Gray + "There are no logs for player \"" + playername + "\""); } else { String url = null; @@ -83,7 +84,7 @@ public class LogsCommand extends BaseCommand { + Anticheat.INSTANCE.getCheckManager().getIdToName().get(log.getCheckId()) + "(VL: " + log.getVl() + ") {" + log.getData() + "}"); }); - if(logs.size() == 0) { + if(logs.isEmpty()) { sender.sendMessage(Color.Gray + " does not have any violations for check \"" + check + "\""); } else { String url = null; @@ -134,10 +135,10 @@ public class LogsCommand extends BaseCommand { + Anticheat.INSTANCE.getCheckManager().getIdToName().get(log.getCheckId()) + "(VL: " + log.getVl() + ") {" + log.getData() + "}"); }); - if(logs.size() == 0) { + if(logs.isEmpty()) { sender.sendMessage(Color.Gray + "There are no logs for player \"" + playername + "\""); } else { - String url = null; + String url; try { url = Pastebin.makePaste(String.join("\n", logs), playername + "'s Logs", Pastebin.Privacy.UNLISTED); @@ -159,8 +160,7 @@ public class LogsCommand extends BaseCommand { @Description("View the logs of a user") public void onLogsWeb(CommandSender sender, String[] args) { if(args.length == 0) { - if(sender instanceof Player) { - Player player = (Player) sender; + if(sender instanceof Player player) { runWebLog(sender, player); } else sender.sendMessage(Color.translate("You cannot view your own logs from console.")); } else { @@ -191,13 +191,20 @@ public class LogsCommand extends BaseCommand { } - StringBuilder url = new StringBuilder("https://funkemunky.cc/api/kauri?uuid=" + target.getUniqueId().toString().replaceAll("-", "") + (violations.keySet().size() > 0 ? "&violations=" : "")); + StringBuilder url = new StringBuilder("https://funkemunky.cc/api/kauri?uuid=" + + target.getUniqueId().toString().replaceAll("-", "") + + (!violations.isEmpty() ? "&violations=" : "")); - if (violations.keySet().size() > 0) { + if (!violations.isEmpty()) { for (String key : violations.keySet()) { if (Anticheat.INSTANCE.getCheckManager().isCheck(key)) { - CheckSettings checkData = Anticheat.INSTANCE.getCheckManager().getCheckSettings(Anticheat.INSTANCE.getCheckManager().getCheckClasses() - .get(Anticheat.INSTANCE.getCheckManager().getIdToName().get(key)).getCheckClass().getParent()); + var checkClass = Anticheat.INSTANCE.getCheckManager().getCheckClasses() + .get(Anticheat.INSTANCE.getCheckManager().getIdToName().get(key)) + .getCheckClass().getParent(); + + + CheckSettings checkData = Anticheat.INSTANCE.getCheckManager() + .getCheckSettings(checkClass); int vl = violations.get(key), maxVL = checkData.getPunishVl(); boolean developer = false; @@ -209,7 +216,7 @@ public class LogsCommand extends BaseCommand { } } - if (violations.keySet().size() > 0) { + if (!violations.isEmpty()) { url.deleteCharAt(url.length() - 1); } @@ -223,7 +230,7 @@ public class LogsCommand extends BaseCommand { finalURL = finalURL.replace("%id%", readAll(reader)); } catch (IOException e) { - e.printStackTrace(); + Anticheat.INSTANCE.getLogger().log(Level.WARNING, "Failed to get logs for " + target.getName(), e); } sender.sendMessage(Color.translate("&aView the log here&7: &f" + finalURL)); diff --git a/Anticheat/src/main/java/dev/brighten/ac/data/APlayer.java b/Anticheat/src/main/java/dev/brighten/ac/data/APlayer.java index 033af67..7c8cb40 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/data/APlayer.java +++ b/Anticheat/src/main/java/dev/brighten/ac/data/APlayer.java @@ -84,12 +84,12 @@ public class APlayer { @Getter private int playerTick; @Getter - private Timer creation = new MillisTimer(); + private final Timer creation = new MillisTimer(); @Getter //TODO Actually grab real player version once finished implementing version grabber from Atlas private ProtocolVersion playerVersion = ProtocolVersion.UNKNOWN; @Getter - private Object playerConnection; + private final Object playerConnection; public Emulator EMULATOR; @@ -323,8 +323,7 @@ public class APlayer { public void sendPacketSilently(Object packet) { if(sniffing) { - sniffedPackets.add("(Silent) [" + Anticheat.INSTANCE.getKeepaliveProcessor().tick + "] " + - "" + (packet instanceof WPacket ? ((WPacket)packet).getPacketType() + sniffedPackets.add("(Silent) [" + Anticheat.INSTANCE.getKeepaliveProcessor().tick + "] " + (packet instanceof WPacket ? ((WPacket)packet).getPacketType() : HandlerAbstract.getPacketType(packet)) + ": " + packet); } HandlerAbstract.getHandler().sendPacketSilently(this, packet); diff --git a/Anticheat/src/main/java/dev/brighten/ac/data/info/BlockInformation.java b/Anticheat/src/main/java/dev/brighten/ac/data/info/BlockInformation.java index 17046d9..55b10cb 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/data/info/BlockInformation.java +++ b/Anticheat/src/main/java/dev/brighten/ac/data/info/BlockInformation.java @@ -22,7 +22,7 @@ import org.bukkit.entity.LivingEntity; import java.util.*; public class BlockInformation { - private APlayer player; + private final APlayer player; public boolean onClimbable, onSlab, onStairs, onHalfBlock, inLiquid, inLava, inWater, inWeb, onSlime, onIce, onSoulSand, blocksAbove, collidesVertically, bedNear, collidesHorizontally, blocksNear, inBlock, miscNear, collidedWithEntity, roseBush, fenceNear, inPortal, blocksBelow, pistonNear, fenceBelow, inScaffolding, inHoney, diff --git a/Anticheat/src/main/java/dev/brighten/ac/depends/LibraryLoader.java b/Anticheat/src/main/java/dev/brighten/ac/depends/LibraryLoader.java index e6ad3b6..299112b 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/depends/LibraryLoader.java +++ b/Anticheat/src/main/java/dev/brighten/ac/depends/LibraryLoader.java @@ -104,13 +104,13 @@ public final class LibraryLoader { } if (!saveLocation.exists()) { - throw new RuntimeException("Unable to download dependency: " + d.toString()); + throw new RuntimeException("Unable to download dependency: " + d); } try { URL_INJECTOR.get().addURL(saveLocation.toURI().toURL()); } catch (Exception e) { - throw new RuntimeException("Unable to load dependency: " + saveLocation.toString(), e); + throw new RuntimeException("Unable to load dependency: " + saveLocation, e); } Anticheat.INSTANCE.info("Loaded dependency '" + name + "' successfully."); @@ -167,8 +167,7 @@ public final class LibraryLoader { @Override public boolean equals(Object o) { if (o == this) return true; - if (!(o instanceof Dependency)) return false; - final Dependency other = (Dependency) o; + if (!(o instanceof Dependency other)) return false; return this.getGroupId().equals(other.getGroupId()) && this.getArtifactId().equals(other.getArtifactId()) && this.getVersion().equals(other.getVersion()) && diff --git a/Anticheat/src/main/java/dev/brighten/ac/handler/EntityLocationHandler.java b/Anticheat/src/main/java/dev/brighten/ac/handler/EntityLocationHandler.java index 92ed150..f8ccecc 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/handler/EntityLocationHandler.java +++ b/Anticheat/src/main/java/dev/brighten/ac/handler/EntityLocationHandler.java @@ -259,7 +259,7 @@ public class EntityLocationHandler { clientHasEntity.set(false); } - private double[] offsets = new double[]{-1.25, 0, 1.25}; + private final double[] offsets = new double[]{-1.25, 0, 1.25}; private void createFakeMob(int entityId, Location location) { if(!canCreateMob.contains(entityId)) return; diff --git a/Anticheat/src/main/java/dev/brighten/ac/handler/PacketHandler.java b/Anticheat/src/main/java/dev/brighten/ac/handler/PacketHandler.java index 1490649..67ca614 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/handler/PacketHandler.java +++ b/Anticheat/src/main/java/dev/brighten/ac/handler/PacketHandler.java @@ -369,11 +369,9 @@ public class PacketHandler { if(player.sniffing) { if(type != PacketType.UNKNOWN) { - player.sniffedPackets.add("[" + Anticheat.INSTANCE.getKeepaliveProcessor().tick + "] " + - "" + type.name() + ": " + packetObject.toString()); + player.sniffedPackets.add("[" + Anticheat.INSTANCE.getKeepaliveProcessor().tick + "] " + type.name() + ": " + packetObject.toString()); } else { - player.sniffedPackets.add("[" + Anticheat.INSTANCE.getKeepaliveProcessor().tick + "] (UNKNOWN) " + - "" + packetObject.getClass().getSimpleName() + ": " + packetObject); + player.sniffedPackets.add("[" + Anticheat.INSTANCE.getKeepaliveProcessor().tick + "] (UNKNOWN) " + packetObject.getClass().getSimpleName() + ": " + packetObject); } } diff --git a/Anticheat/src/main/java/dev/brighten/ac/handler/entity/FakeMob.java b/Anticheat/src/main/java/dev/brighten/ac/handler/entity/FakeMob.java index 1df8c64..ca3e06a 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/handler/entity/FakeMob.java +++ b/Anticheat/src/main/java/dev/brighten/ac/handler/entity/FakeMob.java @@ -19,8 +19,8 @@ import java.util.concurrent.ThreadLocalRandom; @Getter public class FakeMob { - private int entityId; - private EntityType type; + private final int entityId; + private final EntityType type; private List watching = Collections.emptyList(); diff --git a/Anticheat/src/main/java/dev/brighten/ac/packet/listener/ListenerEntry.java b/Anticheat/src/main/java/dev/brighten/ac/packet/listener/ListenerEntry.java index 71a929e..e423020 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/packet/listener/ListenerEntry.java +++ b/Anticheat/src/main/java/dev/brighten/ac/packet/listener/ListenerEntry.java @@ -12,5 +12,5 @@ import java.util.UUID; class ListenerEntry { private final EventPriority priority; private final PacketListener listener; - private long id = UUID.randomUUID().getMostSignificantBits(); + private final long id = UUID.randomUUID().getMostSignificantBits(); } diff --git a/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/WObject.java b/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/WObject.java index aa2d443..8dff3e0 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/WObject.java +++ b/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/WObject.java @@ -3,10 +3,10 @@ package dev.brighten.ac.packet.wrapper; import dev.brighten.ac.utils.reflections.types.WrappedField; import lombok.Getter; +@Getter public abstract class WObject { - @Getter - private Object vanillaObject; + private final Object vanillaObject; public WObject(Object object) { this.vanillaObject = object; processVanilla(); diff --git a/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/in/WPacketPlayInBlockDig.java b/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/in/WPacketPlayInBlockDig.java index 7ec224a..c9206a3 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/in/WPacketPlayInBlockDig.java +++ b/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/in/WPacketPlayInBlockDig.java @@ -25,15 +25,6 @@ public class WPacketPlayInBlockDig extends WPacket { return null; } - public enum EnumDirection { - DOWN, - UP, - NORTH, - SOUTH, - WEST, - EAST - } - public enum EnumPlayerDigType { START_DESTROY_BLOCK, ABORT_DESTROY_BLOCK, @@ -42,7 +33,7 @@ public class WPacketPlayInBlockDig extends WPacket { DROP_ITEM, RELEASE_USE_ITEM; - private EnumPlayerDigType() { + EnumPlayerDigType() { } } diff --git a/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/in/WPacketPlayInEntityAction.java b/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/in/WPacketPlayInEntityAction.java index 5cb97ef..51c5d53 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/in/WPacketPlayInEntityAction.java +++ b/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/in/WPacketPlayInEntityAction.java @@ -21,7 +21,7 @@ public class WPacketPlayInEntityAction extends WPacket { return null; } - public static enum EnumPlayerAction { + public enum EnumPlayerAction { START_SNEAKING, STOP_SNEAKING, STOP_SLEEPING, @@ -30,7 +30,7 @@ public class WPacketPlayInEntityAction extends WPacket { RIDING_JUMP, OPEN_INVENTORY; - private EnumPlayerAction() { + EnumPlayerAction() { } } diff --git a/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/in/WPacketPlayInUseEntity.java b/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/in/WPacketPlayInUseEntity.java index cb6d6b2..471d169 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/in/WPacketPlayInUseEntity.java +++ b/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/in/WPacketPlayInUseEntity.java @@ -26,10 +26,6 @@ public class WPacketPlayInUseEntity extends WPacket { return null; } - public enum EnumHand { - MAIN_HAND, OFF_HAND; - } - public Entity getEntity(World world) { for (Entity entity : world.getEntities()) { if(entity.getEntityId() == entityId) { @@ -39,13 +35,13 @@ public class WPacketPlayInUseEntity extends WPacket { return null; } + @Getter public enum EnumEntityUseAction { INTERACT("INTERACT"), ATTACK("ATTACK"), INTERACT_AT("INTERACT_AT"); - @Getter - private String name; + private final String name; EnumEntityUseAction(String name) { this.name = name; diff --git a/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/objects/EnumParticle.java b/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/objects/EnumParticle.java index e8f6c3a..388e877 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/objects/EnumParticle.java +++ b/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/objects/EnumParticle.java @@ -57,14 +57,14 @@ public enum EnumParticle { private static final Map U = Maps.newHashMap(); private static final String[] V; - private EnumParticle(String var3, int var4, boolean var5, int var6) { + EnumParticle(String var3, int var4, boolean var5, int var6) { this.Q = var3; this.R = var4; this.S = var5; this.T = var6; } - private EnumParticle(String var3, int var4, boolean var5) { + EnumParticle(String var3, int var4, boolean var5) { this(var3, var4, var5, 0); } @@ -93,7 +93,7 @@ public enum EnumParticle { } public static EnumParticle a(int var0) { - return (EnumParticle)U.get(var0); + return U.get(var0); } static { diff --git a/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/objects/WrappedEnumDirection.java b/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/objects/WrappedEnumDirection.java index 26a93b3..b292ada 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/objects/WrappedEnumDirection.java +++ b/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/objects/WrappedEnumDirection.java @@ -47,7 +47,7 @@ public enum WrappedEnumDirection { private final IntVector m; public static WrappedClass enumDirection; - private WrappedEnumDirection(int order, int offset, String direction, WrappedEnumDirection.EnumAxisDirection axisDirection, WrappedEnumDirection.EnumAxis axis, IntVector offsetPosition) { + WrappedEnumDirection(int order, int offset, String direction, WrappedEnumDirection.EnumAxisDirection axisDirection, WrappedEnumDirection.EnumAxis axis, IntVector offsetPosition) { this.i = offset; this.h = order; this.j = direction; @@ -135,7 +135,7 @@ public enum WrappedEnumDirection { return (T) enumDirection.getEnum(name()); } - public static enum EnumDirectionLimit { + public enum EnumDirectionLimit { HORIZONTAL, VERTICAL; @@ -144,14 +144,14 @@ public enum WrappedEnumDirection { } } - public static enum EnumAxisDirection { + public enum EnumAxisDirection { POSITIVE(1, "Towards positive"), NEGATIVE(-1, "Towards negative"); private final int c; private final String d; - private EnumAxisDirection(int var3, String var4) { + EnumAxisDirection(int var3, String var4) { this.c = var3; this.d = var4; } @@ -165,7 +165,7 @@ public enum WrappedEnumDirection { } } - public static enum EnumAxis { + public enum EnumAxis { X("x", WrappedEnumDirection.EnumDirectionLimit.HORIZONTAL), Y("y", WrappedEnumDirection.EnumDirectionLimit.VERTICAL), Z("z", WrappedEnumDirection.EnumDirectionLimit.HORIZONTAL); @@ -185,7 +185,7 @@ public enum WrappedEnumDirection { private final String e; private final WrappedEnumDirection.EnumDirectionLimit f; - private EnumAxis(String var3, WrappedEnumDirection.EnumDirectionLimit var4) { + EnumAxis(String var3, WrappedEnumDirection.EnumDirectionLimit var4) { this.e = var3; this.f = var4; } diff --git a/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/out/WPacketPlayInClientCommand.java b/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/out/WPacketPlayInClientCommand.java index d638792..96dbae4 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/out/WPacketPlayInClientCommand.java +++ b/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/out/WPacketPlayInClientCommand.java @@ -24,6 +24,6 @@ public class WPacketPlayInClientCommand extends WPacket { public enum WrappedEnumClientCommand { PERFORM_RESPAWN, REQUEST_STATS, - OPEN_INVENTORY_ACHIEVEMENT; + OPEN_INVENTORY_ACHIEVEMENT } } diff --git a/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/out/WPacketPlayOutPosition.java b/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/out/WPacketPlayOutPosition.java index 7e0b712..06ebbe6 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/out/WPacketPlayOutPosition.java +++ b/Anticheat/src/main/java/dev/brighten/ac/packet/wrapper/out/WPacketPlayOutPosition.java @@ -37,9 +37,9 @@ public class WPacketPlayOutPosition extends WPacket { Y_ROT(3), X_ROT(4); - private int f; + private final int f; - private EnumPlayerTeleportFlags(int var3) { + EnumPlayerTeleportFlags(int var3) { this.f = var3; } diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/AxisAlignedBB.java b/Anticheat/src/main/java/dev/brighten/ac/utils/AxisAlignedBB.java index e23e318..06d5c6d 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/AxisAlignedBB.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/AxisAlignedBB.java @@ -24,15 +24,6 @@ public class AxisAlignedBB { this.maxZ = Math.max(d2, d5); } - public AxisAlignedBB(BoundingBox box) { - this.minX = box.minX; - this.minY = box.minY; - this.minZ = box.minZ; - this.maxX = box.maxX; - this.maxY = box.maxY; - this.maxZ = box.maxZ; - } - public AxisAlignedBB(SimpleCollisionBox box) { this.minX = box.minX; this.minY = box.minY; diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/BlockBounds.java b/Anticheat/src/main/java/dev/brighten/ac/utils/BlockBounds.java deleted file mode 100644 index 99bfee0..0000000 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/BlockBounds.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.brighten.ac.utils; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class BlockBounds { - public List bounds = new ArrayList<>(); - public int id; - - public BlockBounds(int id, BoundingBox... boxes) { - bounds.addAll(Arrays.asList(boxes)); - } -} diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/BoundingBox.java b/Anticheat/src/main/java/dev/brighten/ac/utils/BoundingBox.java deleted file mode 100644 index d6ad0f4..0000000 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/BoundingBox.java +++ /dev/null @@ -1,315 +0,0 @@ -package dev.brighten.ac.utils; - -import dev.brighten.ac.utils.world.types.SimpleCollisionBox; -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.util.Vector; - -import java.util.ArrayList; -import java.util.List; - -public class BoundingBox { - - public float minX, minY, minZ, maxX, maxY, maxZ; - - public BoundingBox(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) { - this.minX = minX; - this.minY = minY; - this.minZ = minZ; - this.maxX = maxX; - this.maxY = maxY; - this.maxZ = maxZ; - } - - public BoundingBox(Vector min, Vector max) { - this.minX = (float) Math.min(min.getX(), max.getX()); - this.minY = (float) Math.min(min.getY(), max.getY()); - this.minZ = (float) Math.min(min.getZ(), max.getZ()); - this.maxX = (float) Math.max(min.getX(), max.getX()); - this.maxY = (float) Math.max(min.getY(), max.getY()); - this.maxZ = (float) Math.max(min.getZ(), max.getZ()); - } - - public BoundingBox(BoundingBox one, BoundingBox two) { - this.minX = Math.min(one.minX, two.minX); - this.minY = Math.min(one.minY, two.minY); - this.minZ = Math.min(one.minZ, two.minZ); - this.maxX = Math.max(one.maxX, two.maxX); - this.maxY = Math.max(one.maxY, two.maxY); - this.maxZ = Math.max(one.maxZ, two.maxZ); - } - - public BoundingBox add(float x, float y, float z) { - float newMinX = minX + x; - float newMaxX = maxX + x; - float newMinY = minY + y; - float newMaxY = maxY + y; - float newMinZ = minZ + z; - float newMaxZ = maxZ + z; - - return new BoundingBox(newMinX, newMinY, newMinZ, newMaxX, newMaxY, newMaxZ); - } - - public BoundingBox add(Vector vector) { - float x = (float) vector.getX(), y = (float) vector.getY(), z = (float) vector.getZ(); - - float newMinX = minX + x; - float newMaxX = maxX + x; - float newMinY = minY + y; - float newMaxY = maxY + y; - float newMinZ = minZ + z; - float newMaxZ = maxZ + z; - - return new BoundingBox(newMinX, newMinY, newMinZ, newMaxX, newMaxY, newMaxZ); - } - - public BoundingBox grow(float x, float y, float z) { - float newMinX = minX - x; - float newMaxX = maxX + x; - float newMinY = minY - y; - float newMaxY = maxY + y; - float newMinZ = minZ - z; - float newMaxZ = maxZ + z; - - return new BoundingBox(newMinX, newMinY, newMinZ, newMaxX, newMaxY, newMaxZ); - } - - public BoundingBox shrink(float x, float y, float z) { - float newMinX = minX + x; - float newMaxX = maxX - x; - float newMinY = minY + y; - float newMaxY = maxY - y; - float newMinZ = minZ + z; - float newMaxZ = maxZ - z; - - return new BoundingBox(newMinX, newMinY, newMinZ, newMaxX, newMaxY, newMaxZ); - } - - public BoundingBox add(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) { - return new BoundingBox(this.minX + minX, this.minY + minY, this.minZ + minZ, this.maxX + maxX, this.maxY + maxY, this.maxZ + maxZ); - } - - public BoundingBox subtract(float minX, float minY, float minZ, float maxX, float maxY, float maxZ) { - return new BoundingBox(this.minX - minX, this.minY - minY, this.minZ - minZ, this.maxX - maxX, this.maxY - maxY, this.maxZ - maxZ); - } - - public boolean intersectsWithBox(Vector vector) { - return (vector.getX() > this.minX && vector.getX() < this.maxX) && ((vector.getY() > this.minY && vector.getY() < this.maxY) && (vector.getZ() > this.minZ && vector.getZ() < this.maxZ)); - } - - public Vector getMinimum() { - return new Vector(minX, minY, minZ); - } - - public Vector getMaximum() { - return new Vector(maxX, maxY, maxZ); - } - - public List getAllBlocks(Player player) { - Location min = new Location(player.getWorld(), MathUtils.floor(minX), MathUtils.floor(minY), MathUtils.floor(minZ)); - Location max = new Location(player.getWorld(), MathUtils.floor(maxX), MathUtils.floor(maxY), MathUtils.floor(maxZ)); - List all = new ArrayList<>(); - for (float x = (float) min.getX(); x < max.getX(); x++) { - for (float y = (float) min.getY(); y < max.getY(); y++) { - for (float z = (float) min.getZ(); z < max.getZ(); z++) { - Block block = BlockUtils.getBlock(new Location(player.getWorld(), x, y, z)); - if (block != null && block.getType().getId() != 0) { - all.add(block); - } - } - } - } - return all; - } - - public boolean intersectsWithBox(Object other) { - if (other instanceof BoundingBox) { - BoundingBox otherBox = (BoundingBox) other; - return otherBox.maxX > this.minX && otherBox.minX < this.maxX && otherBox.maxY > this.minY && otherBox.minY < this.maxY && otherBox.maxZ > this.minZ && otherBox.minZ < this.maxZ; - } else { - float otherMinX = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "a"), other); - float otherMinY = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "b"), other); - float otherMinZ = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "c"), other); - float otherMaxX = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "d"), other); - float otherMaxY = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "e"), other); - float otherMaxZ = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "f"), other); - return otherMaxX > minX && otherMinX < maxX && otherMaxY > minY && otherMinY < maxY && otherMaxZ > minZ && otherMinZ < maxZ; - } - } - - public boolean collides(Vector vector) { - return (vector.getX() >= this.minX && vector.getX() <= this.maxX) && ((vector.getY() >= this.minY && vector.getY() <= this.maxY) && (vector.getZ() >= this.minZ && vector.getZ() <= this.maxZ)); - } - - public boolean collides(Object other) { - if (other instanceof BoundingBox) { - BoundingBox otherBox = (BoundingBox) other; - return otherBox.maxX >= this.minX && otherBox.minX <= this.maxX && otherBox.maxY >= this.minY && otherBox.minY <= this.maxY && otherBox.maxZ >= this.minZ && otherBox.minZ <= this.maxZ; - } else { - float otherMinX = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "a"), other); - float otherMinY = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "b"), other); - float otherMinZ = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "c"), other); - float otherMaxX = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "d"), other); - float otherMaxY = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "e"), other); - float otherMaxZ = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "f"), other); - return otherMaxX >= minX && otherMinX <= maxX && otherMaxY >= minY && otherMinY <= maxY && otherMaxZ >= minZ && otherMinZ <= maxZ; - } - } - - public boolean collidesHorizontally(Vector vector) { - return (vector.getX() >= this.minX && vector.getX() <= this.maxX) && ((vector.getY() > this.minY && vector.getY() < this.maxY) && (vector.getZ() >= this.minZ && vector.getZ() <= this.maxZ)); - } - - public boolean collidesHorizontally(Object other) { - if (other instanceof BoundingBox) { - BoundingBox otherBox = (BoundingBox) other; - return otherBox.maxX >= this.minX && otherBox.minX <= this.maxX && otherBox.maxY > this.minY && otherBox.minY < this.maxY && otherBox.maxZ >= this.minZ && otherBox.minZ <= this.maxZ; - } else { - float otherMinX = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "a"), other); - float otherMinY = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "b"), other); - float otherMinZ = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "c"), other); - float otherMaxX = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "d"), other); - float otherMaxY = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "e"), other); - float otherMaxZ = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "f"), other); - return otherMaxX >= minX && otherMinX <= maxX && otherMaxY > minY && otherMinY < maxY && otherMaxZ >= minZ && otherMinZ <= maxZ; - } - } - - public boolean collidesVertically(Vector vector) { - return (vector.getX() > this.minX && vector.getX() < this.maxX) && ((vector.getY() >= this.minY && vector.getY() <= this.maxY) && (vector.getZ() > this.minZ && vector.getZ() < this.maxZ)); - } - - public boolean collidesVertically(Object other) { - if (other instanceof BoundingBox) { - BoundingBox otherBox = (BoundingBox) other; - return otherBox.maxX > this.minX && otherBox.minX < this.maxX && otherBox.maxY >= this.minY && otherBox.minY <= this.maxY && otherBox.maxZ > this.minZ && otherBox.minZ < this.maxZ; - } else { - float otherMinX = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "a"), other); - float otherMinY = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "b"), other); - float otherMinZ = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "c"), other); - float otherMaxX = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "d"), other); - float otherMaxY = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "e"), other); - float otherMaxZ = (float) (double) ReflectionsUtil.getFieldValue(ReflectionsUtil.getFieldByName(other.getClass(), "f"), other); - return otherMaxX > minX && otherMinX < maxX && otherMaxY >= minY && otherMinY <= maxY && otherMaxZ > minZ && otherMinZ < maxZ; - } - } - - /** - * if instance and the argument bounding boxes overlap in the Y and Z dimensions, calculate the offset between them - * in the X dimension. return var2 if the bounding boxes do not overlap or if var2 is closer to 0 then the - * calculated offset. Otherwise return the calculated offset. - */ - public double calculateXOffset(BoundingBox other, double offsetX) { - if (other.maxY > this.minY && other.minY < this.maxY && other.maxZ > this.minZ && other.minZ < this.maxZ) { - if (offsetX > 0.0D && other.maxX <= this.minX) { - double d1 = this.minX - other.maxX; - - if (d1 < offsetX) { - offsetX = d1; - } - } else if (offsetX < 0.0D && other.minX >= this.maxX) { - double d0 = this.maxX - other.minX; - - if (d0 > offsetX) { - offsetX = d0; - } - } - - return offsetX; - } else { - return offsetX; - } - } - - /** - * if instance and the argument bounding boxes overlap in the X and Z dimensions, calculate the offset between them - * in the Y dimension. return var2 if the bounding boxes do not overlap or if var2 is closer to 0 then the - * calculated offset. Otherwise return the calculated offset. - */ - public double calculateYOffset(BoundingBox other, double offsetY) { - if (other.maxX > this.minX && other.minX < this.maxX && other.maxZ > this.minZ && other.minZ < this.maxZ) { - if (offsetY > 0.0D && other.maxY <= this.minY) { - double d1 = this.minY - other.maxY; - - if (d1 < offsetY) { - offsetY = d1; - } - } else if (offsetY < 0.0D && other.minY >= this.maxY) { - double d0 = this.maxY - other.minY; - - if (d0 > offsetY) { - offsetY = d0; - } - } - - return offsetY; - } else { - return offsetY; - } - } - - /** - * if instance and the argument bounding boxes overlap in the Y and X dimensions, calculate the offset between them - * in the Z dimension. return var2 if the bounding boxes do not overlap or if var2 is closer to 0 then the - * calculated offset. Otherwise return the calculated offset. - */ - public double calculateZOffset(BoundingBox other, double offsetZ) { - if (other.maxX > this.minX && other.minX < this.maxX && other.maxY > this.minY && other.minY < this.maxY) { - if (offsetZ > 0.0D && other.maxZ <= this.minZ) { - double d1 = this.minZ - other.maxZ; - - if (d1 < offsetZ) { - offsetZ = d1; - } - } else if (offsetZ < 0.0D && other.minZ >= this.maxZ) { - double d0 = this.maxZ - other.minZ; - - if (d0 > offsetZ) { - offsetZ = d0; - } - } - - return offsetZ; - } else { - return offsetZ; - } - } - - public BoundingBox addCoord(float x, float y, float z) { - float d0 = this.minX; - float d1 = this.minY; - float d2 = this.minZ; - float d3 = this.maxX; - float d4 = this.maxY; - float d5 = this.maxZ; - - if (x < 0.0D) { - d0 += x; - } else if (x > 0.0D) { - d3 += x; - } - - if (y < 0.0D) { - d1 += y; - } else if (y > 0.0D) { - d4 += y; - } - - if (z < 0.0D) { - d2 += z; - } else if (z > 0.0D) { - d5 += z; - } - - return new BoundingBox(d0,d1,d2,d3,d4,d5); - } - - public SimpleCollisionBox toCollisionBox() { - return new SimpleCollisionBox(minX, minY, minZ, maxX, maxY, maxZ); - } - - public String toString() { - return "[" + minX + ", " + minY + ", " + minZ + ", " + maxX + ", " + maxY + ", " + maxZ + "]"; - } -} diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/ClassScanner.java b/Anticheat/src/main/java/dev/brighten/ac/utils/ClassScanner.java index f6c1623..0c1a774 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/ClassScanner.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/ClassScanner.java @@ -14,6 +14,7 @@ import dev.brighten.ac.utils.reflections.types.WrappedMethod; import org.bukkit.Bukkit; import org.bukkit.event.Listener; import org.bukkit.plugin.Plugin; +import org.jetbrains.annotations.NotNull; import org.objectweb.asm.ClassReader; import org.objectweb.asm.tree.AnnotationNode; import org.objectweb.asm.tree.ClassNode; @@ -27,6 +28,7 @@ import java.net.URL; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.*; +import java.util.logging.Level; import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -38,14 +40,11 @@ public class ClassScanner { private final PathMatcher CLASS_FILE = create("glob:*.class"); private final PathMatcher ARCHIVE = create("glob:*.{jar}"); - public void initializeScanner(Class mainClass, Plugin plugin, ClassLoader loader, - boolean loadListeners, boolean loadCommands) { - initializeScanner(mainClass, plugin, loader, scanFile(null, mainClass), loadListeners, - loadCommands); + public void initializeScanner(Class mainClass, Plugin plugin, ClassLoader loader) { + initializeScanner(mainClass, plugin, loader, scanFile(null, mainClass)); } - public void initializeScanner(Class mainClass, Plugin plugin, ClassLoader loader, Set names, - boolean loadListeners, boolean loadCommands) { + public void initializeScanner(Class mainClass, Plugin plugin, ClassLoader loader, Set names) { names.stream() .map(name -> { if(loader != null) { @@ -55,7 +54,7 @@ public class ClassScanner { } else return new WrappedClass(Class.forName(name, true, loader)); } catch (ClassNotFoundException e) { - e.printStackTrace(); + Anticheat.INSTANCE.getLogger().log(Level.SEVERE, "Could not initialize scanner!", e); } return null; } else { @@ -69,29 +68,16 @@ public class ClassScanner { String[] required = init.requirePlugins(); if(required.length > 0) { - if(init.requireType() == Init.RequireType.ALL) { - return Arrays.stream(required) - .allMatch(name -> { - if(name.contains("||")) { - return Arrays.stream(name.split("\\|\\|")) - .anyMatch(n2 -> Bukkit.getPluginManager().isPluginEnabled(n2)); - } else if(name.contains("&&")) { - return Arrays.stream(name.split("\\|\\|")) - .allMatch(n2 -> Bukkit.getPluginManager().isPluginEnabled(n2)); - } else return Bukkit.getPluginManager().isPluginEnabled(name); - }); - } else { - return Arrays.stream(required) - .anyMatch(name -> { - if(name.contains("||")) { - return Arrays.stream(name.split("\\|\\|")) - .anyMatch(n2 -> Bukkit.getPluginManager().isPluginEnabled(n2)); - } else if(name.contains("&&")) { - return Arrays.stream(name.split("\\|\\|")) - .allMatch(n2 -> Bukkit.getPluginManager().isPluginEnabled(n2)); - } else return Bukkit.getPluginManager().isPluginEnabled(name); - }); - } + return Arrays.stream(required) + .anyMatch(name -> { + if(name.contains("||")) { + return Arrays.stream(name.split("\\|\\|")) + .anyMatch(n2 -> Bukkit.getPluginManager().isPluginEnabled(n2)); + } else if(name.contains("&&")) { + return Arrays.stream(name.split("\\|\\|")) + .allMatch(n2 -> Bukkit.getPluginManager().isPluginEnabled(n2)); + } else return Bukkit.getPluginManager().isPluginEnabled(name); + }); } return true; }) @@ -99,7 +85,6 @@ public class ClassScanner { c.getAnnotation(Init.class).priority().getPriority(), Comparator.reverseOrder())) .forEach(c -> { Object obj = c.getParent().equals(mainClass) ? plugin : c.getConstructor().newInstance(); - Init annotation = c.getAnnotation(Init.class); if(obj instanceof Listener listener) { Bukkit.getPluginManager().registerEvents(listener, plugin); @@ -110,7 +95,7 @@ public class ClassScanner { if(obj instanceof BaseCommand command) { Anticheat.INSTANCE.alog(true,"&7Found BaseCommand for class &e" + c.getParent().getSimpleName() + "&7! Registering commands..."); - Anticheat.INSTANCE.getCommandManager().registerCommand((BaseCommand)obj); + Anticheat.INSTANCE.getCommandManager().registerCommand(command); } for (WrappedMethod method : c.getMethods()) { @@ -125,7 +110,7 @@ public class ClassScanner { if(field.isAnnotationPresent(ConfigSetting.class)) { ConfigSetting setting = field.getAnnotation(ConfigSetting.class); - String name = setting.name().length() > 0 + String name = !setting.name().isEmpty() ? setting.name() : field.getField().getName(); @@ -136,12 +121,12 @@ public class ClassScanner { Configuration config = Anticheat.INSTANCE.getAnticheatConfig(); - if(config.get((setting.path().length() > 0 ? setting.path() + "." : "") + name) == null) { + if(config.get((!setting.path().isEmpty() ? setting.path() + "." : "") + name) == null) { Anticheat.INSTANCE.alog(true,"&7Value not set in config! Setting value..."); - config.set((setting.path().length() > 0 ? setting.path() + "." : "") + name, field.get(obj)); + config.set((!setting.path().isEmpty() ? setting.path() + "." : "") + name, field.get(obj)); Anticheat.INSTANCE.saveConfig(); } else { - Object configObj = config.get((setting.path().length() > 0 ? setting.path() + "." : "") + name); + Object configObj = config.get((!setting.path().isEmpty() ? setting.path() + "." : "") + name); Anticheat.INSTANCE.alog(true, "&7Set field to value &e%s&7.", (setting.hide() ? "HIDDEN" : configObj)); field.set(obj, configObj); @@ -197,9 +182,9 @@ public class ClassScanner { private void scanDirectory(Path dir, Class annotationClass, final Set plugins) { try { Files.walkFileTree(dir, newHashSet(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, - new SimpleFileVisitor() { + new SimpleFileVisitor<>() { @Override - public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { + public @NotNull FileVisitResult visitFile(Path path, @NotNull BasicFileAttributes attrs) throws IOException { if (CLASS_FILE.matches(path.getFileName())) { try (InputStream in = Files.newInputStream(path)) { String plugin = findClass(in, annotationClass); @@ -213,7 +198,7 @@ public class ClassScanner { } }); } catch (IOException e) { - e.printStackTrace(); + Anticheat.INSTANCE.getLogger().log(Level.SEVERE, "Error scanning directory", e); } } @@ -226,15 +211,14 @@ public class ClassScanner { String className = classNode.name.replace('/', '.'); final String anName = annotationClass.getName().replace(".", "/"); if (classNode.visibleAnnotations != null) { - for (Object node : classNode.visibleAnnotations) { - AnnotationNode annotation = (AnnotationNode) node; - if (annotation.desc + for (AnnotationNode node : classNode.visibleAnnotations) { + if (node.desc .equals("L" + anName + ";")) return className; } } } catch (Exception e) { - //Bukkit.getLogger().info("Failed to scan: " + in.toString()); + Anticheat.INSTANCE.getLogger().log(Level.SEVERE, "Failed to scan: " + in.toString(), e); } return null; } @@ -260,7 +244,7 @@ public class ClassScanner { } } } catch (IOException e) { - e.printStackTrace(); + Anticheat.INSTANCE.getLogger().log(Level.SEVERE, "Failed to scan path: " + path, e); } } @@ -306,9 +290,9 @@ public class ClassScanner { private void scanDirectory(String file, Path dir, final Set plugins) { try { Files.walkFileTree(dir, newHashSet(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, - new SimpleFileVisitor() { + new SimpleFileVisitor<>() { @Override - public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException { + public @NotNull FileVisitResult visitFile(Path path, @NotNull BasicFileAttributes attrs) throws IOException { if (CLASS_FILE.matches(path.getFileName())) { try (InputStream in = Files.newInputStream(path)) { String plugin = findPlugin(file, in); @@ -322,10 +306,11 @@ public class ClassScanner { } }); } catch (IOException e) { - e.printStackTrace(); + Anticheat.INSTANCE.getLogger().log(Level.SEVERE, "Failed to scan dir: " + dir, e); } } + @SafeVarargs private HashSet newHashSet(E... elements) { HashSet set = new HashSet<>(); Collections.addAll(set, elements); @@ -354,7 +339,7 @@ public class ClassScanner { } } } catch (IOException e) { - e.printStackTrace(); + Anticheat.INSTANCE.getLogger().log(Level.SEVERE, "Failed to scan zip: " + path + "/" + file, e); } } @@ -365,18 +350,17 @@ public class ClassScanner { reader.accept(classNode, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES); String className = classNode.name.replace('/', '.'); if (classNode.visibleAnnotations != null) { - for (Object node : classNode.visibleAnnotations) { - AnnotationNode annotation = (AnnotationNode) node; - if ((file == null && annotation.desc + for (AnnotationNode node : classNode.visibleAnnotations) { + if ((file == null && node.desc .equals("L" + Init.class.getName().replace(".", "/") + ";")) - || (file != null && annotation.desc + || (file != null && node.desc .equals("L" + file.replace(".", "/") + ";"))) return className; } } if (classNode.superName != null && (classNode.superName.equals(file))) return className; } catch (Exception e) { - //System.out.println("Failed to scan: " + in.toString()); + Anticheat.INSTANCE.getLogger().log(Level.SEVERE, "Failed to find plugin: " + file, e); } return null; } diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/Helper.java b/Anticheat/src/main/java/dev/brighten/ac/utils/Helper.java index 84a90d3..55b67c3 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/Helper.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/Helper.java @@ -237,7 +237,7 @@ public class Helper { } public static SimpleCollisionBox getEntityCollision(Entity entity) { - return new SimpleCollisionBox((Object) MinecraftReflection.getEntityBoundingBox(entity)); + return new SimpleCollisionBox(MinecraftReflection.getEntityBoundingBox(entity)); } public static List getCollisions(APlayer player, SimpleCollisionBox collisionBox, int mask) { @@ -269,7 +269,7 @@ public class Helper { if (!BlockUtils.isEntityCollidable(entity)) continue; SimpleCollisionBox entityCollisionBox = - new SimpleCollisionBox((Object) MinecraftReflection.getEntityBoundingBox(entity)); + new SimpleCollisionBox(MinecraftReflection.getEntityBoundingBox(entity)); if (entityCollisionBox.isIntersected(collisionBox)) entityCollisionBox.downCast(collisionBoxes); diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/Pastebin.java b/Anticheat/src/main/java/dev/brighten/ac/utils/Pastebin.java index 469c86e..457dcad 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/Pastebin.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/Pastebin.java @@ -1,12 +1,14 @@ package dev.brighten.ac.utils; - -import org.bukkit.Bukkit; +import dev.brighten.ac.Anticheat; +import lombok.Getter; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.util.logging.Level; public class Pastebin { static String pasteURL = "https://funkemunky.cc/pastebin/make"; @@ -15,18 +17,6 @@ public class Pastebin { } - public static String nonce() { - Object player = Bukkit.getPlayer(""); - - player = new Object(); - - return "%%__NONCE__%%"; - } - - public static String userId() { - return "%%__USER__%%"; - } - static String checkResponse(String response) { if (response.startsWith("Bad API request")) { return response.substring(17); @@ -36,27 +26,14 @@ public class Pastebin { static public String makePaste(String body, String name, Privacy privacy) throws UnsupportedEncodingException { - String content = URLEncoder.encode(body, "UTF-8"); - String title = URLEncoder.encode(name + " report", "UTF-8"); + String content = URLEncoder.encode(body, StandardCharsets.UTF_8); + String title = URLEncoder.encode(name + " report", StandardCharsets.UTF_8); String data = "body=" + content + "&name=" + title + "&privacy=" + privacy.name(); String response = Pastebin.page(Pastebin.pasteURL, data); if(response == null) return ""; String check = Pastebin.checkResponse(response); - if (!check.equals("")) { - return check; - } - return response; - } - - static public String makePaste(String body, String name, Privacy privacy, String expire) - throws UnsupportedEncodingException { - String content = URLEncoder.encode(body, "UTF-8"); - String title = URLEncoder.encode(name + " report", "UTF-8"); - String data = "body=" + content + "&name=" + title + "&privacy=" + privacy.name() + "&expire=" + expire; - String response = Pastebin.page(Pastebin.pasteURL, data); - String check = Pastebin.checkResponse(response); - if (!check.equals("")) { + if (!check.isEmpty()) { return check; } return response; @@ -91,7 +68,7 @@ public class Pastebin { InputStream is = connection.getInputStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; - StringBuffer response = new StringBuffer(); + StringBuilder response = new StringBuilder(); while ((line = rd.readLine()) != null) { response.append(line); } @@ -99,7 +76,7 @@ public class Pastebin { return response.toString(); } catch (Exception e) { - e.printStackTrace(); + Anticheat.INSTANCE.getLogger().log(Level.SEVERE, "Failed to upload paste", e); return null; } finally { @@ -110,6 +87,7 @@ public class Pastebin { } } + @Getter public enum Privacy { PUBLIC(0), UNLISTED(1), PRIVATE(2); @@ -119,8 +97,5 @@ public class Pastebin { this.privacy = privacy; } - public int getPrivacy() { - return privacy; - } } } \ No newline at end of file diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/ReflectionUtil.java b/Anticheat/src/main/java/dev/brighten/ac/utils/ReflectionUtil.java deleted file mode 100644 index 2f87f72..0000000 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/ReflectionUtil.java +++ /dev/null @@ -1,100 +0,0 @@ -package dev.brighten.ac.utils; - -import dev.brighten.ac.Anticheat; -import sun.misc.Unsafe; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.Arrays; - -@SuppressWarnings({"ConstantConditions", "unchecked"}) -public final class ReflectionUtil { - private static final Unsafe UNSAFE = ReflectionUtil.getUnsafeInstance(); - - private static Unsafe getUnsafeInstance() { - try { - Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); - unsafeField.setAccessible(true); - return (Unsafe) unsafeField.get(null); - } catch (NoSuchFieldException | IllegalAccessException e) { - Anticheat.INSTANCE.getLogger().severe("Could not locate Unsafe object!"); - e.printStackTrace(); - return null; - } - } - - public static Field get(Class oClass, Class type, int index) throws NoSuchFieldException { - int i = 0; - for (Field field : oClass.getDeclaredFields()) { - if (field.getType() == type) { - if (i == index) { - field.setAccessible(true); - return field; - } - i++; - } - } - - throw new NoSuchFieldException("Could not find field of class " + type.getName() + " with index " + index); - } - - public static Field getFieldByClassNames(Class clazz, String... simpleNames) throws NoSuchFieldException { - for (Field field : clazz.getDeclaredFields()) { - String typeSimpleName = field.getType().getSimpleName(); - for (String name : simpleNames) { - if (name.equals(typeSimpleName)) { - field.setAccessible(true); - return field; - } - } - } - - throw new NoSuchFieldException("Could not find field in class " + clazz.getName() + " with names " + Arrays.toString(simpleNames)); - } - - public static Field getFieldByType(Class clazz, Class type) throws NoSuchFieldException { - for (Field field : clazz.getDeclaredFields()) { - Class foundType = field.getType(); - if (type.isAssignableFrom(foundType)) { - field.setAccessible(true); - return field; - } - } - - throw new NoSuchFieldException("Could not find field in class " + clazz.getName() + " with type " + type.getName()); - } - - public static Method getMethodByName(Class clazz, String name) throws NoSuchMethodException { - for (Method method : clazz.getDeclaredMethods()) { - if (name.equals(method.getName())) { - method.setAccessible(true); - return method; - } - } - - throw new NoSuchMethodException("Could not find method in class " + clazz.getName() + " with name " + name); - } - - public static Class getSuperClassByName(Class clazz, String simpleName) { - if (!clazz.getSimpleName().equals(simpleName)) { - Class superClazz; - while((superClazz = clazz.getSuperclass()) != null) { - if (superClazz.getSimpleName().equals(simpleName)) { - break; - } - } - - return superClazz; - } else { - return clazz; - } - } - - public static void setUnsafe(Object object, Field field, T value) { - ReflectionUtil.UNSAFE.putObject(object, ReflectionUtil.UNSAFE.objectFieldOffset(field), value); - } - - public static T instantiateUnsafe(Class clazz) throws Exception{ - return (T) ReflectionUtil.UNSAFE.allocateInstance(clazz); - } -} \ No newline at end of file diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/ReflectionsUtil.java b/Anticheat/src/main/java/dev/brighten/ac/utils/ReflectionsUtil.java deleted file mode 100644 index 98d5df0..0000000 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/ReflectionsUtil.java +++ /dev/null @@ -1,489 +0,0 @@ -package dev.brighten.ac.utils; - -import dev.brighten.ac.Anticheat; -import dev.brighten.ac.packet.ProtocolVersion; -import dev.brighten.ac.utils.reflections.Reflections; -import org.bukkit.Bukkit; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.Server; -import org.bukkit.block.Block; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.util.Vector; - -import java.io.File; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -public class ReflectionsUtil { - public static Class blockPosition = null; - 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 final Class craftServer = getCBClass("CraftServer"); - public static Class World = getNMSClass("World"); - public static Class worldServer = getNMSClass("WorldServer"); - public static Class playerConnection = getNMSClass("PlayerConnection"); - public static Class networkManager = getNMSClass("NetworkManager"); - public static Class minecraftServer = getNMSClass("MinecraftServer"), nmsItemStack = getNMSClass("ItemStack"); - public static Class packet = getNMSClass("Packet"); - public static Class iBlockData = null; - public static Class iBlockAccess = null; - 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); - } - - public static Object getEntity(org.bukkit.entity.Entity entity) { - return getMethodValue(getMethod(CraftEntity, "getHandle"), entity); - } - - public static Object getExpandedBoundingBox(Object box, double x, double y, double z) { - return getMethodValue(getMethod(box.getClass(), "grow", double.class, double.class, double.class), box, x, y, z); - } - - public static Object modifyBoundingBox(Object box, double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { - double newminX = (double) getFieldValue(getFieldByName(box.getClass(), "a"), box) - minX; - double newminY = (double) getFieldValue(getFieldByName(box.getClass(), "b"), box) - minY; - double newminZ = (double) getFieldValue(getFieldByName(box.getClass(), "c"), box) - minZ; - double newmaxX = (double) getFieldValue(getFieldByName(box.getClass(), "d"), box) + maxX; - double newmaxY = (double) getFieldValue(getFieldByName(box.getClass(), "e"), box) + maxY; - double newmaxZ = (double) getFieldValue(getFieldByName(box.getClass(), "f"), box) + maxZ; - - return newInstance(getNMSClass("AxisAlignedBB"), newminX, newminY, newminZ, newmaxX, newmaxY, newmaxZ); - } - - private static Vector getBoxMin(Object box) { - if (hasField(box.getClass(), "a")) { - double x = (double) getFieldValue(getFieldByName(box.getClass(), "a"), box); - double y = (double) getFieldValue(getFieldByName(box.getClass(), "b"), box); - double z = (double) getFieldValue(getFieldByName(box.getClass(), "c"), box); - return new Vector(x, y, z); - } else { - double x = (double) getFieldValue(getFieldByName(box.getClass(), "minX"), box); - double y = (double) getFieldValue(getFieldByName(box.getClass(), "minY"), box); - double z = (double) getFieldValue(getFieldByName(box.getClass(), "minZ"), box); - return new Vector(x, y, z); - } - } - - public static Object getMinecraftServer() { - return getMethodValue(getMethod(craftServer, "getServer"), Bukkit.getServer()); - } - - private static Vector getBoxMax(Object box) { - if (hasField(box.getClass(), "d")) { - double x = (double) getFieldValue(getFieldByName(box.getClass(), "d"), box); - double y = (double) getFieldValue(getFieldByName(box.getClass(), "e"), box); - double z = (double) getFieldValue(getFieldByName(box.getClass(), "f"), box); - return new Vector(x, y, z); - } else { - double x = (double) getFieldValue(getFieldByName(box.getClass(), "maxX"), box); - double y = (double) getFieldValue(getFieldByName(box.getClass(), "maxY"), box); - double z = (double) getFieldValue(getFieldByName(box.getClass(), "maxZ"), box); - return new Vector(x, y, z); - } - } - - public static BoundingBox toBoundingBox(Object aaBB) { - Vector min = getBoxMin(aaBB); - Vector max = getBoxMax(aaBB); - - return new BoundingBox((float) min.getX(), (float) min.getY(), (float) min.getZ(), (float) max.getX(), (float) max.getY(), (float) max.getZ()); - } - - public static float getBlockDurability(Block block) { - Object vanillaBlock = getVanillaBlock(block); - return (float) getFieldValue(getFieldByName(getNMSClass("Block"), "strength"), vanillaBlock); - } - - public static boolean canDestroyBlock(Player player, Block block) { - Object inventory = getVanillaInventory(player); - return (boolean) getMethodValue(getMethod(getNMSClass("PlayerInventory"), "b", getNMSClass("Block")), inventory, ProtocolVersion.getGameVersion().isAbove(ProtocolVersion.V1_8_9) ? getBlockData(block) : getVanillaBlock(block)); - } - - public static Object getVanillaInventory(Player player) { - return getMethodValue(getMethod(getCBClass("inventory.CraftInventoryPlayer"), "getInventory"), player.getInventory()); - } - - private static final Field frictionFactorField = getFieldByName(vanillaBlock, "frictionFactor"); - public static float getFriction(Block block) { - Object blockNMS = getVanillaBlock(block); - - return (float) getFieldValue(frictionFactorField, blockNMS); - } - - public static Object getBlockPosition(Location location) { - if (ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_8)) { - return newInstance(blockPosition, location.getBlockX(), location.getBlockY(), location.getBlockZ()); - } - return null; - } - - public static List getEntitiesInWorld(org.bukkit.World world) { - Object worldHandle = getWorldHandle(world); - List toReturn = new ArrayList<>(); - List entityList = new ArrayList<>((List) getFieldValue(getFieldByName(getNMSClass("World"), "entityList"), worldHandle)); - - Class entity = getNMSClass("Entity"); - entityList.forEach(object -> { - Object bEntity = getMethodValue(getMethod(entity, "getBukkitEntity"), object); - if(bEntity != null) { - toReturn.add((org.bukkit.entity.Entity) bEntity); - } - }); - return toReturn; - } - - public static double getTPS(Server server) { - Object handle = getMethodValue(getMethod(getCBClass("CraftServer"), "getHandle"), server); - - return (int) getFieldValue(getFieldByName(getNMSClass("MinecraftServer"), "TPS"), handle); - } - - public static float getBlockHardness(final Material material) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { - if (!material.isBlock()) - return 0; - - final int blockId = material.getId(); - final Object nmsBlock = getNMSClass("Block").getMethod("getById", Integer.TYPE).invoke(null, blockId); - - try { - final Field field = nmsBlock.getClass().getDeclaredField("strength"); - field.setAccessible(true); - return (float) field.get(nmsBlock); - } catch (final NoSuchFieldException e) { - return 0.0F; - } - } - - public static float getDestroySpeed(Block block, Player player) { - - if (ProtocolVersion.getGameVersion().isAbove(ProtocolVersion.V1_8_9)) { - Object item = getVanillaItem(player.getItemInHand()); - return (float) getMethodValue(getMethod(getNMSClass("Item"), "getDestroySpeed", nmsItemStack, getNMSClass("IBlockData")), item, getVanillaItemStack(player.getItemInHand()), getBlockData(block)); - } else { - Object item = getVanillaItem(player.getInventory().getItemInHand()); - return (float) getMethodValue(getMethod(getNMSClass("Item"), "getDestroySpeed", nmsItemStack, getNMSClass("Block")), item, getVanillaItemStack(player.getInventory().getItemInHand()), getVanillaBlock(block)); - } - } - - private static final Method getItemMethod = getMethod(nmsItemStack, "getItem"); - public static Object getVanillaItem(ItemStack itemStack) { - return getMethodValue(getMethod(nmsItemStack, "getItem"), getVanillaItemStack(itemStack)); - } - - public static Object getVanillaItemStack(ItemStack itemStack) { - return getMethodValue(getMethod(getCBClass("inventory.CraftItemStack"), "asNMSCopy", getClass("org.bukkit.inventory.ItemStack")), itemStack, itemStack); - } - - private static Method getBlockMethod = null, - getTypeMethod = null; - public static Object getVanillaBlock(Block block) { - if (!isBukkitVerison("1_7")) { - if(getBlockMethod == null) getBlockMethod = getMethod(iBlockData, "getBlock"); - Object getType = getBlockData(block); - return getMethodValue(getBlockMethod, getType); - } else { - if(getTypeMethod == null) getTypeMethod = getMethod(worldServer, "getType", int.class, int.class, int.class); - Object world = getWorldHandle(block.getWorld()); - return getMethodValue(getTypeMethod, world, block.getLocation().getBlockX(), block.getLocation().getBlockY(), block.getLocation().getBlockZ()); - } - } - - private static Constructor blockPosConstructor = null; - private static Method getTypeMethod2 = null; - public static Object getBlockData(Block block) { - try { - if (!isBukkitVerison("1_7")) { - if(blockPosConstructor == null) blockPosConstructor = blockPosition.getConstructor(int.class, int.class, int.class); - Object bPos = blockPosConstructor.newInstance(block.getX(), block.getY(), block.getZ()); - Object world = getWorldHandle(block.getWorld()); - if(getTypeMethod2 == null) getTypeMethod2 = getMethod(worldServer, "getType", blockPosition); - return getMethodValue(getTypeMethod2, world, bPos); - } else { - Object world = getWorldHandle(block.getWorld()); - if(getTypeMethod2 == null) getTypeMethod2 = getMethod(worldServer, "getType", int.class, int.class, int.class); - return getMethodValue(getTypeMethod2, world, block.getX(), block.getY(), block.getZ()); - } - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - public static Object getBelowBox(Player player, double below) { - Object box = getBoundingBox(player); - double minX = (double) getFieldValue(getFieldByName(box.getClass(), "a"), box); - double minY = (double) getFieldValue(getFieldByName(box.getClass(), "b"), box) - below; - double minZ = (double) getFieldValue(getFieldByName(box.getClass(), "c"), box); - double maxX = (double) getFieldValue(getFieldByName(box.getClass(), "d"), box); - double maxY = (double) getFieldValue(getFieldByName(box.getClass(), "e"), box); - double maxZ = (double) getFieldValue(getFieldByName(box.getClass(), "f"), box); - - try { - return getNMSClass("AxisAlignedBB").getConstructor(double.class, double.class, double.class, double.class, double.class, double.class).newInstance(minX, minY, minZ, maxX, maxY, maxZ); - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - public static Object getBoundingBox(Player player) { - return getBoundingBox((org.bukkit.entity.Entity) player); - } - - public static Object getBoundingBox(org.bukkit.entity.Entity entity) { - return isBukkitVerison("1_7") ? getFieldValue(getFieldByName(Entity, "boundingBox"), getEntity(entity)) : getMethodValue(getMethod(Entity, "getBoundingBox"), getEntity(entity)); - } - - public static boolean isBukkitVerison(String version) { - return ProtocolVersion.getGameVersion().getServerVersion().contains(version); - } - - public static File getPluginFolder() { - Object console = getMethodValue(getMethod(getCBClass("CraftServer"), "console"), Anticheat.INSTANCE.getServer()); - Object options = getFieldValue(getFieldByName(getNMSClass("MinecraftServer"), "options"), console); - return (File) getMethodValue(getMethod(getNMSClass("OptionSet"), "valueOf", String.class), options, "plugins"); - } - - public static boolean isNewVersion() { - return isBukkitVerison("1_9") || isBukkitVerison("1_1"); - } - - public static Class getCBClass(String string) { - return getClass("org.bukkit.craftbukkit." + version + "." + string); - } - - - public static Object newAxisAlignedBB(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { - try { - return isBukkitVerison("1_7") ? getMethodValue(getMethod(getNMSClass("AxisAlignedBB"), "a", double.class, double.class, double.class, double.class, double.class, double.class), null, minX, minY, minZ, maxX, maxY, maxZ) : getNMSClass("AxisAlignedBB").getConstructor(double.class, double.class, double.class, double.class, double.class, double.class).newInstance(minX, minY, minZ, maxX, maxY, maxZ); - } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { - e.printStackTrace(); - } - return null; - } - - public static Object newVoxelShape(double minX, double minY, double minZ, double maxX, double maxY, double maxZ) { - try { - return getNMSClass("AxisAlignedBB").getConstructor(double.class, double.class, double.class, double.class, double.class, double.class).newInstance(minX, minY, minZ, maxX, maxY, maxZ); - } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { - e.printStackTrace(); - } - return null; - } - - public static double getMotionY(Player player) { - double motionY = 0; - try { - motionY = (double) ReflectionsUtil.getEntityPlayer(player).getClass().getField("motY").get(ReflectionsUtil.getEntityPlayer(player)); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } catch (NoSuchFieldException e) { - e.printStackTrace(); - } - - return motionY; - } - - public static Object newAxisAlignedBB(Location from, Location to) { - double minX = Math.min(from.getX(), to.getX()); - double minY = Math.min(from.getY(), to.getY()); - double minZ = Math.min(from.getZ(), to.getZ()); - double maxX = Math.max(from.getX(), to.getX()); - double maxY = Math.max(from.getY(), to.getY()); - double maxZ = Math.max(from.getZ(), to.getZ()); - - try { - return getNMSClass("AxisAlignedBB").getConstructor(double.class, double.class, double.class, double.class, double.class, double.class).newInstance(minX, minY, minZ, maxX, maxY, maxZ); - } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { - e.printStackTrace(); - } - return null; - } - - public static Class getClass(String string) { - try { - return Class.forName(string); - } catch (ClassNotFoundException e) { - e.printStackTrace(); - } - return null; - } - - @SuppressWarnings("unchecked") - public static Enum getEnum(Class clazz, String enumName) { - return Enum.valueOf((Class) clazz, enumName); - } - - public static Field getFieldByName(Class clazz, String fieldName) { - try { - Field field = clazz.getDeclaredField(fieldName) != null ? clazz.getDeclaredField(fieldName) : clazz.getSuperclass().getDeclaredField(fieldName); - field.setAccessible(true); - - return field; - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - public static Object setFieldValue(Object object, Field field, Object value) { - try { - field.set(object, value); - } catch (IllegalAccessException e) { - e.printStackTrace(); - } - - return field.getDeclaringClass(); - } - - - public static boolean inBlock(Player player, Object axisAlignedBB) { - return getCollidingBlocks(player, axisAlignedBB).size() > 0; - } - - /** - * Method removed in 1.12 and later versions in NMS - **/ - public static Collection getCollidingBlocks(Player player, Object axisAlignedBB) { - Object world = getWorldHandle(player.getWorld()); - return (Collection) (isNewVersion() - ? getMethodValue(getCubes1_12, world, null, axisAlignedBB) - : getMethodValue(getCubes, world, axisAlignedBB)); - } - - private static final Method craftWorldHandle = getMethod(CraftWorld, "getHandle"); - public static Object getWorldHandle(org.bukkit.World world) { - return getMethodValue(craftWorldHandle, world); - } - - public static Field getFirstFieldByType(Class clazz, Class type) { - try { - for (Field field : clazz.getDeclaredFields()) { - if (field.getType().equals(type)) { - field.setAccessible(true); - return field; - } - } - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - public static Method getMethod(Class clazz, String methodName, Class... args) { - try { - Method method = clazz.getMethod(methodName, args); - method.setAccessible(true); - return method; - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - - private static Method getMethodNoST(Class clazz, String methodName, Class... args) { - try { - Method method = clazz.getMethod(methodName, args); - method.setAccessible(true); - return method; - } catch (Exception e) { - } - return null; - } - - public static boolean hasMethod(Class clazz, Method method) { - return Arrays.stream(clazz.getMethods()).anyMatch(methodLoop -> methodLoop.getName().equals(method.getName())); - } - - public static boolean hasMethod(Class clazz, String methodName) { - return Arrays.stream(clazz.getMethods()).anyMatch(methodLoop -> methodLoop.getName().equals(methodName)); - } - - public static Object getMethodValue(Method method, Object object, Object... args) { - try { - return method.invoke(object, args); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - public static boolean hasField(Class object, String fieldName) { - return Arrays.stream(object.getFields()).anyMatch(field -> field.getName().equalsIgnoreCase(fieldName)); - } - - public static Object getMethodValueNoST(Method method, Object object, Object... args) { - try { - return method.invoke(object, args); - } catch (Exception e) { - return null; - } - } - - public static Object getFieldValue(Field field, Object object) { - try { - field.setAccessible(true); - return field.get(object); - } catch (Exception e) { - e.printStackTrace(); - return null; - } - } - - public static Object getFieldValueNoST(Field field, Object object) { - try { - field.setAccessible(true); - return field.get(object); - } catch (Exception e) { - return null; - } - } - - public static Field getFieldByNameNoST(Class clazz, String fieldName) { - try { - Field field = clazz.getDeclaredField(fieldName) != null ? clazz.getDeclaredField(fieldName) : clazz.getSuperclass().getDeclaredField(fieldName); - field.setAccessible(true); - - return field; - } catch (Exception e) { - return null; - } - } - - public static Object newInstance(Class objectClass, Object... args) { - try { - return objectClass.getConstructor(args.getClass()).newInstance(args); - } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) { - e.printStackTrace(); - } - return null; - } - - public static Class getNMSClass(String string) { - return Reflections.getNMSClass(string).getParent(); - } - - static { - if (ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_8)) { - iBlockData = getNMSClass("IBlockData"); - blockPosition = getNMSClass("BlockPosition"); - iBlockAccess = getNMSClass("IBlockAccess"); - } - } -} \ No newline at end of file diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/ServerInjector.java b/Anticheat/src/main/java/dev/brighten/ac/utils/ServerInjector.java deleted file mode 100644 index 859c1a2..0000000 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/ServerInjector.java +++ /dev/null @@ -1,67 +0,0 @@ -package dev.brighten.ac.utils; - -import dev.brighten.ac.Anticheat; -import dev.brighten.ac.utils.reflections.impl.CraftReflection; -import dev.brighten.ac.utils.reflections.impl.MinecraftReflection; - -import java.lang.reflect.Field; -import java.lang.reflect.ParameterizedType; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -public class ServerInjector { - private static final Collection TICKABLE_CLASS_NAMES = Arrays.asList("IUpdatePlayerListBox", "ITickable", "Runnable"); - private Field hookedField; - - @SuppressWarnings({"unchecked", "rawtypes"}) - public void inject() throws Exception { - // Start end of tick injection - Object server = CraftReflection.getMinecraftServer(); - Class serverClass = MinecraftReflection.minecraftServer.getParent(); - - // Inject our hooked list for end of tick - for (Field field : serverClass.getDeclaredFields()) { - try { - if (field.getType().equals(List.class)) { - // Check if type parameters match one of the tickable class names used throughout different versions - Class genericType = (Class) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0]; - if (!ServerInjector.TICKABLE_CLASS_NAMES.contains(genericType.getSimpleName())) { - continue; - } - - field.setAccessible(true); - - // Use a list wrapper to check when the size method is called - HookedListWrapper wrapper = new HookedListWrapper((List) field.get(server)) { - @Override - public void onSize() { - Runnable toRun = null; - - while((toRun = Anticheat.INSTANCE.getOnTickEnd().poll()) != null) { - toRun.run(); - } - } - }; - - ReflectionUtil.setUnsafe(server, field, wrapper); - this.hookedField = field; - break; - } - } catch (Exception ignored) { - } - } - } - - public void eject() throws Exception { - // Replace hooked wrapper with original - if (this.hookedField != null) { - Object server = CraftReflection.getMinecraftServer(); - - HookedListWrapper hookedListWrapper = (HookedListWrapper) this.hookedField.get(server); - - ReflectionUtil.setUnsafe(server, this.hookedField, hookedListWrapper.getBase()); - this.hookedField = null; - } - } -} \ No newline at end of file diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONArray.java b/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONArray.java index 518b697..d0feac0 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONArray.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONArray.java @@ -86,7 +86,7 @@ public class JSONArray { /** * The arrayList where the JSONArray's properties are kept. */ - private ArrayList myArrayList; + private final ArrayList myArrayList; /** @@ -619,7 +619,7 @@ public class JSONArray { * @return this. */ public dev.brighten.ac.utils.json.JSONArray put(int value) { - put(new Integer(value)); + put(Integer.valueOf(value)); return this; } @@ -631,7 +631,7 @@ public class JSONArray { * @return this. */ public dev.brighten.ac.utils.json.JSONArray put(long value) { - put(new Long(value)); + put(Long.valueOf(value)); return this; } @@ -723,7 +723,7 @@ public class JSONArray { * @throws JSONException If the index is negative. */ public dev.brighten.ac.utils.json.JSONArray put(int index, int value) throws JSONException { - put(index, new Integer(value)); + put(index, Integer.valueOf(value)); return this; } @@ -739,7 +739,7 @@ public class JSONArray { * @throws JSONException If the index is negative. */ public dev.brighten.ac.utils.json.JSONArray put(int index, long value) throws JSONException { - put(index, new Long(value)); + put(index, Long.valueOf(value)); return this; } diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONObject.java b/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONObject.java index 67e4856..4b5ab74 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONObject.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONObject.java @@ -95,7 +95,7 @@ public class JSONObject { /** * The map where the JSONObject's properties are kept. */ - private Map map; + private final Map map; /** @@ -241,7 +241,7 @@ public class JSONObject { * @param names An array of strings, the names of the fields to be obtained * from the object. */ - public JSONObject(Object object, String names[]) { + public JSONObject(Object object, String[] names) { this(); Class c = object.getClass(); for (int i = 0; i < names.length; i += 1) { @@ -508,7 +508,7 @@ public class JSONObject { if (b == '0' && string.length() > 2 && (string.charAt(1) == 'x' || string.charAt(1) == 'X')) { try { - return new Integer(Integer.parseInt(string.substring(2), 16)); + return Integer.valueOf(Integer.parseInt(string.substring(2), 16)); } catch (Exception ignore) { } } @@ -517,9 +517,9 @@ public class JSONObject { string.indexOf('e') > -1 || string.indexOf('E') > -1) { return Double.valueOf(string); } else { - Long myLong = new Long(string); + Long myLong = Long.valueOf(string); if (myLong.longValue() == myLong.intValue()) { - return new Integer(myLong.intValue()); + return Integer.valueOf(myLong.intValue()); } else { return myLong; } @@ -1290,7 +1290,7 @@ public class JSONObject { * @throws dev.brighten.ac.utils.json.JSONException If the key is null. */ public dev.brighten.ac.utils.json.JSONObject put(String key, int value) throws dev.brighten.ac.utils.json.JSONException { - put(key, new Integer(value)); + put(key, Integer.valueOf(value)); return this; } @@ -1303,7 +1303,7 @@ public class JSONObject { * @throws dev.brighten.ac.utils.json.JSONException If the key is null. */ public dev.brighten.ac.utils.json.JSONObject put(String key, long value) throws dev.brighten.ac.utils.json.JSONException { - put(key, new Long(value)); + put(key, Long.valueOf(value)); return this; } @@ -1574,7 +1574,7 @@ public class JSONObject { * * @return NULL. */ - protected final Object clone() { + protected Object clone() { return this; } diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONString.java b/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONString.java index bc977ba..e70bc7e 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONString.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONString.java @@ -15,5 +15,5 @@ public interface JSONString { * * @return A strictly syntactically correct JSON text. */ - public String toJSONString(); + String toJSONString(); } diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONTokener.java b/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONTokener.java index 507408e..400d031 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONTokener.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONTokener.java @@ -41,7 +41,7 @@ public class JSONTokener { private int index; private int line; private char previous; - private Reader reader; + private final Reader reader; private boolean usePrevious; @@ -430,7 +430,7 @@ public class JSONTokener { * @return A JSONException object, suitable for throwing */ public JSONException syntaxError(String message) { - return new JSONException(message + toString()); + return new JSONException(message + this); } diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONWriter.java b/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONWriter.java index 03a37c9..7c90fb9 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONWriter.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/json/JSONWriter.java @@ -80,7 +80,7 @@ public class JSONWriter { /** * The object/array stack. */ - private JSONObject stack[]; + private final JSONObject[] stack; /** * The stack top index. A value of 0 indicates that the stack is empty. */ diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/json/JsonReader.java b/Anticheat/src/main/java/dev/brighten/ac/utils/json/JsonReader.java index a0b9227..e33e57a 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/json/JsonReader.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/json/JsonReader.java @@ -8,7 +8,7 @@ package dev.brighten.ac.utils.json; import java.io.*; import java.net.URL; import java.net.URLConnection; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; public class JsonReader { public JsonReader() { @@ -31,7 +31,7 @@ public class JsonReader { JSONObject var6; try { - BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8"))); + BufferedReader rd = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); String jsonText = readAll(rd); JSONObject json = new JSONObject(jsonText); var6 = json; diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/json/XML.java b/Anticheat/src/main/java/dev/brighten/ac/utils/json/XML.java index e56516f..56699c9 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/json/XML.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/json/XML.java @@ -337,7 +337,7 @@ public class XML { return JSONObject.NULL; } if (string.equals("0")) { - return new Integer(0); + return Integer.valueOf(0); } // If it might be a number, try converting it. If that doesn't work, @@ -357,9 +357,9 @@ public class XML { if (string.indexOf('.') >= 0) { return Double.valueOf(string); } else if (string.indexOf('e') < 0 && string.indexOf('E') < 0) { - Long myLong = new Long(string); + Long myLong = Long.valueOf(string); if (myLong.longValue() == myLong.intValue()) { - return new Integer(myLong.intValue()); + return Integer.valueOf(myLong.intValue()); } else { return myLong; } diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/math/FloatVector.java b/Anticheat/src/main/java/dev/brighten/ac/utils/math/FloatVector.java index ac743df..6508869 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/math/FloatVector.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/math/FloatVector.java @@ -9,19 +9,15 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.util.Vector; +import java.util.Objects; + +@Setter +@Getter @AllArgsConstructor @NoArgsConstructor public class FloatVector implements Cloneable { - @Getter - @Setter private float x, y, z; - public FloatVector(Location location) { - this.x = MathHelper.floor_double(location.getX()); - this.y = MathHelper.floor_double(location.getY()); - this.z = MathHelper.floor_double(location.getZ()); - } - public FloatVector clone() { try { return (FloatVector) super.clone(); @@ -56,18 +52,12 @@ public class FloatVector implements Cloneable { @Override public boolean equals(Object o) { - if(!(o instanceof FloatVector)) return false; - - FloatVector FloatVector = (FloatVector) o; - return x == FloatVector.x && y == FloatVector.y && z == FloatVector.z; + if (!(o instanceof FloatVector that)) return false; + return Float.compare(x, that.x) == 0 && Float.compare(y, that.y) == 0 && Float.compare(z, that.z) == 0; } @Override public int hashCode() { - int hash = 7; - hash = 79 * hash + (Float.floatToIntBits(this.x) ^ Float.floatToIntBits(this.x) >>> 16); - hash = 79 * hash + (Float.floatToIntBits(this.y) ^ Float.floatToIntBits(this.y) >>> 16); - hash = 79 * hash + (Float.floatToIntBits(this.z) ^ Float.floatToIntBits(this.z) >>> 16); - return hash; + return Objects.hash(x, y, z); } } diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/math/IntVector.java b/Anticheat/src/main/java/dev/brighten/ac/utils/math/IntVector.java index cdb3eae..2935951 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/math/IntVector.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/math/IntVector.java @@ -9,11 +9,13 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.util.Vector; +import java.util.Objects; + +@Setter +@Getter @AllArgsConstructor @NoArgsConstructor -public class IntVector { - @Getter - @Setter +public class IntVector implements Cloneable { private int x, y, z; public IntVector(Location location) { @@ -23,7 +25,15 @@ public class IntVector { } public IntVector clone() { - return new IntVector(x, y, z); + final IntVector clone; + + try { + clone = (IntVector) super.clone(); + } catch (CloneNotSupportedException ex) { + throw new RuntimeException("Failed to clone IntVector", ex); + } + + return clone; } public Vector toBukkitVector() { @@ -42,10 +52,6 @@ public class IntVector { return this; } - public Integer[] toIntArray() { - return new Integer[] {x, y, z}; - } - public IntVector add(IntVector vec) { return add(vec.getX(), vec.getY(), vec.getZ()); } @@ -56,18 +62,12 @@ public class IntVector { @Override public boolean equals(Object o) { - if(!(o instanceof IntVector)) return false; - - IntVector intVector = (IntVector) o; + if (!(o instanceof IntVector intVector)) return false; return x == intVector.x && y == intVector.y && z == intVector.z; } @Override public int hashCode() { - int hash = 7; - hash = 79 * hash + (int)(Double.doubleToLongBits(this.x) ^ Double.doubleToLongBits(this.x) >>> 32); - hash = 79 * hash + (int)(Double.doubleToLongBits(this.y) ^ Double.doubleToLongBits(this.y) >>> 32); - hash = 79 * hash + (int)(Double.doubleToLongBits(this.z) ^ Double.doubleToLongBits(this.z) >>> 32); - return hash; + return Objects.hash(x, y, z); } } diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/menu/MenuListener.java b/Anticheat/src/main/java/dev/brighten/ac/utils/menu/MenuListener.java index 641433c..c859d10 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/menu/MenuListener.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/menu/MenuListener.java @@ -99,8 +99,7 @@ public class MenuListener implements Listener { if (menu != null) { menu.handleClose((Player) event.getPlayer()); - if(menu instanceof ChestMenu) { - ChestMenu cmenu = (ChestMenu) menu; + if(menu instanceof ChestMenu cmenu) { for (int i = 0; i < cmenu.contents.length; i++) { Button button = cmenu.contents[i]; @@ -123,8 +122,7 @@ public class MenuListener implements Listener { }.runTaskTimer(Anticheat.INSTANCE, 2L, 0L)); } } - if(inventory instanceof AnvilInventory && anvils.containsKey(inventory)) { - AnvilInventory anvil = (AnvilInventory) inventory; + if(inventory instanceof AnvilInventory anvil && anvils.containsKey(inventory)) { WrappedMethod method = new WrappedClass(ProtocolVersion.getGameVersion().isOrAbove(ProtocolVersion.V1_11) ? AnvilInventory.class : Inventory.class) diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/world/EntityData.java b/Anticheat/src/main/java/dev/brighten/ac/utils/world/EntityData.java index 903365b..79a1abe 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/world/EntityData.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/world/EntityData.java @@ -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(); } diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/world/types/DynamicCollisionBox.java b/Anticheat/src/main/java/dev/brighten/ac/utils/world/types/DynamicCollisionBox.java index c214da4..e090cd8 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/world/types/DynamicCollisionBox.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/world/types/DynamicCollisionBox.java @@ -14,7 +14,7 @@ import java.util.List; public class DynamicCollisionBox implements CollisionBox { private final CollisionFactory box; - private APlayer player; + private final APlayer player; @Setter private WrappedBlock block; @Setter diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/world/types/RayCollision.java b/Anticheat/src/main/java/dev/brighten/ac/utils/world/types/RayCollision.java index 88c727c..8cf07ca 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/world/types/RayCollision.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/world/types/RayCollision.java @@ -100,8 +100,7 @@ public class RayCollision implements CollisionBox { public boolean isIntersected(CollisionBox other) { if(other instanceof RayCollision) { return false; //not supported yet - } else if(other instanceof SimpleCollisionBox) { - SimpleCollisionBox box = (SimpleCollisionBox) other; + } else if(other instanceof SimpleCollisionBox box) { return intersect(this, box); } else { diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/world/types/SimpleCollisionBox.java b/Anticheat/src/main/java/dev/brighten/ac/utils/world/types/SimpleCollisionBox.java index 6c2e623..d031d6c 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/world/types/SimpleCollisionBox.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/world/types/SimpleCollisionBox.java @@ -1,7 +1,6 @@ package dev.brighten.ac.utils.world.types; import dev.brighten.ac.packet.wrapper.objects.EnumParticle; -import dev.brighten.ac.utils.BoundingBox; import dev.brighten.ac.utils.Helper; import dev.brighten.ac.utils.KLocation; import dev.brighten.ac.utils.reflections.impl.MinecraftReflection; @@ -78,10 +77,6 @@ public class SimpleCollisionBox implements CollisionBox { maxY += height; } - public SimpleCollisionBox(BoundingBox box) { - this(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ); - } - public SimpleCollisionBox(Object aabb) { double[] box = MinecraftReflection.fromAABB(aabb); @@ -237,8 +232,7 @@ public class SimpleCollisionBox implements CollisionBox { @Override public boolean isCollided(CollisionBox other) { - if (other instanceof SimpleCollisionBox) { - SimpleCollisionBox box = ((SimpleCollisionBox) other); + if (other instanceof SimpleCollisionBox box) { box.sort(); sort(); return box.maxX >= this.minX && box.minX <= this.maxX @@ -252,8 +246,7 @@ public class SimpleCollisionBox implements CollisionBox { @Override public boolean isIntersected(CollisionBox other) { - if(other instanceof SimpleCollisionBox) { - SimpleCollisionBox box = (SimpleCollisionBox) other; + if(other instanceof SimpleCollisionBox box) { box.sort(); sort(); return box.maxX > this.minX && box.minX < this.maxX @@ -345,10 +338,6 @@ public class SimpleCollisionBox implements CollisionBox { } } - public BoundingBox toBoundingBox() { - return new BoundingBox(new Vector(minX, minY, minZ), new Vector(maxX, maxY, maxZ)); - } - public T toAxisAlignedBB() { return MinecraftReflection.toAABB(minX, minY, minZ, maxX, maxY, maxZ); } diff --git a/Anticheat/src/main/java/dev/brighten/ac/utils/wrapper/impl/Wrapper_Reflection.java b/Anticheat/src/main/java/dev/brighten/ac/utils/wrapper/impl/Wrapper_Reflection.java index adf5d41..d4b6795 100644 --- a/Anticheat/src/main/java/dev/brighten/ac/utils/wrapper/impl/Wrapper_Reflection.java +++ b/Anticheat/src/main/java/dev/brighten/ac/utils/wrapper/impl/Wrapper_Reflection.java @@ -13,9 +13,9 @@ import org.bukkit.block.Block; public class Wrapper_Reflection extends Wrapper { - private static WrappedClass blockClass = Reflections.getNMSClass("Block"); - private static WrappedMethod getById = blockClass.getMethodByType(blockClass.getParent(), 0); - private static WrappedField fieldFriction = blockClass.getFieldByType(float.class, 3); + private static final WrappedClass blockClass = Reflections.getNMSClass("Block"); + private static final WrappedMethod getById = blockClass.getMethodByType(blockClass.getParent(), 0); + private static final WrappedField fieldFriction = blockClass.getFieldByType(float.class, 3); @Override public float getFriction(Material material) {