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 extends Plugin> mainClass, Plugin plugin, ClassLoader loader,
- boolean loadListeners, boolean loadCommands) {
- initializeScanner(mainClass, plugin, loader, scanFile(null, mainClass), loadListeners,
- loadCommands);
+ public void initializeScanner(Class extends Plugin> mainClass, Plugin plugin, ClassLoader loader) {
+ initializeScanner(mainClass, plugin, loader, scanFile(null, mainClass));
}
- public void initializeScanner(Class extends Plugin> mainClass, Plugin plugin, ClassLoader loader, Set names,
- boolean loadListeners, boolean loadCommands) {
+ public void initializeScanner(Class extends Plugin> 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 extends Annotation> 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