This commit is contained in:
Dawson
2022-09-03 11:51:22 -04:00
7 changed files with 217 additions and 397 deletions
+3
View File
@@ -61,6 +61,9 @@
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>false</minimizeJar>
</configuration>
</execution>
</executions>
</plugin>
+4 -121
View File
@@ -1,12 +1,10 @@
package dev.brighten.ac;
import co.aikar.commands.BaseCommand;
import co.aikar.commands.BukkitCommandManager;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import dev.brighten.ac.api.AnticheatAPI;
import dev.brighten.ac.check.Check;
import dev.brighten.ac.check.CheckManager;
import dev.brighten.ac.command.AnticheatCommand;
import dev.brighten.ac.data.PlayerRegistry;
import dev.brighten.ac.depends.LibraryLoader;
import dev.brighten.ac.depends.MavenLibrary;
@@ -20,13 +18,10 @@ import dev.brighten.ac.packet.listener.PacketProcessor;
import dev.brighten.ac.utils.*;
import dev.brighten.ac.utils.annotation.ConfigSetting;
import dev.brighten.ac.utils.annotation.Init;
import dev.brighten.ac.utils.annotation.Invoke;
import dev.brighten.ac.utils.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.WrappedClass;
import dev.brighten.ac.utils.reflections.types.WrappedField;
import dev.brighten.ac.utils.reflections.types.WrappedMethod;
import dev.brighten.ac.utils.timer.Timer;
import dev.brighten.ac.utils.timer.impl.TickTimer;
@@ -37,8 +32,6 @@ import me.mat1337.loader.plugin.LoaderPlugin;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import java.io.File;
import java.io.IOException;
@@ -90,8 +83,6 @@ public class Anticheat extends LoaderPlugin {
INSTANCE = this;
LibraryLoader.loadAll(getClass());
findClassMethod = new WrappedClass(getClassLoader2().getClass()).getMethod("findClass", String.class);
scheduler = Executors.newScheduledThreadPool(2, new ThreadFactoryBuilder()
.setNameFormat("Anticheat Schedular")
.setUncaughtExceptionHandler((t, e) -> RunUtils.task(e::printStackTrace))
@@ -99,11 +90,11 @@ public class Anticheat extends LoaderPlugin {
loadConfig();
IntegrityCheck.checkIntegrity();
commandManager = new BukkitCommandManager(getPluginInstance());
commandManager.enableUnstableAPI("help");
commandManager.registerCommand(new AnticheatCommand());
new CommandPropertiesManager(commandManager, getDataFolder(),
getResource2("command-messages.properties"));
@@ -111,10 +102,8 @@ public class Anticheat extends LoaderPlugin {
new AnticheatAPI();
initializeScanner(getPluginInstance().getClass(), getPluginInstance(),
null,
true,
true);
ClassScanner.initializeScanner(getPluginInstance().getClass(), getPluginInstance(),
ClassScanner.getNames());
if(!getAnticheatConfig().contains("database.username")) {
getAnticheatConfig().set("database.username", "dbuser");
@@ -225,116 +214,10 @@ public class Anticheat extends LoaderPlugin {
}
}
public void initializeScanner(Class<?> mainClass, Plugin plugin, ClassLoader loader,
boolean loadListeners, boolean loadCommands) {
initializeScanner(mainClass, plugin, loader, ClassScanner.getNames(), loadListeners,
loadCommands);
}
public WorldInfo getWorldInfo(World world) {
return worldInfoMap.computeIfAbsent(world.getUID(), key -> new WorldInfo(world));
}
public void initializeScanner(Class<?> mainClass, Plugin plugin, ClassLoader loader, Set<String> names,
boolean loadListeners, boolean loadCommands) {
names.stream()
.map(name -> {
return new WrappedClass(findClassMethod.invoke(getClassLoader2(), name));
})
.filter(c -> {
if(c.getParent() == null) {
return false;
}
Init init = c.getAnnotation(Init.class);
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 true;
})
.sorted(Comparator.comparing(c ->
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(loadListeners) {
if(obj instanceof Listener) {
Bukkit.getPluginManager().registerEvents((Listener)obj, plugin);
alog(true,"&7Registered Bukkit listener &e"
+ c.getParent().getSimpleName() + "&7.");
}
}
if(obj instanceof BaseCommand) {
alog(true,"&7Found BaseCommand for class &e"
+ c.getParent().getSimpleName() + "&7! Registering commands...");
commandManager.registerCommand((BaseCommand)obj);
}
for (WrappedMethod method : c.getMethods()) {
if(method.getMethod().isAnnotationPresent(Invoke.class)) {
alog(true,"&7Invoking method &e" + method.getName() + " &7in &e"
+ c.getClass().getSimpleName() + "&7...");
method.invoke(obj);
}
}
for (WrappedField field : c.getFields()) {
if(field.isAnnotationPresent(ConfigSetting.class)) {
ConfigSetting setting = field.getAnnotation(ConfigSetting.class);
String name = setting.name().length() > 0
? setting.name()
: field.getField().getName();
alog(true, "&7Found ConfigSetting &e%s &7(default=&f%s&7).",
field.getField().getName(),
(setting.hide() ? "HIDDEN" : field.get(obj)));
Configuration config = getAnticheatConfig();
if(config.get((setting.path().length() > 0 ? setting.path() + "." : "") + name) == null) {
alog(true,"&7Value not set in config! Setting value...");
config.set((setting.path().length() > 0 ? setting.path() + "." : "") + name, field.get(obj));
saveConfig();
} else {
Object configObj = config.get((setting.path().length() > 0 ? setting.path() + "." : "") + name);
alog(true, "&7Set field to value &e%s&7.",
(setting.hide() ? "HIDDEN" : configObj));
field.set(obj, configObj);
}
}
}
});
}
public void alog(String log, Object... values) {
alog(false, log, values);
}
@@ -15,6 +15,7 @@ import dev.brighten.ac.utils.Color;
import dev.brighten.ac.utils.MiscUtils;
import dev.brighten.ac.utils.Pastebin;
import dev.brighten.ac.utils.Tuple;
import dev.brighten.ac.utils.annotation.Init;
import dev.brighten.ac.utils.msg.ChatBuilder;
import io.netty.buffer.Unpooled;
import lombok.val;
@@ -35,6 +36,7 @@ import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
@Init
@CommandAlias("anticheat|ac")
@CommandPermission("anticheat.command")
public class AnticheatCommand extends BaseCommand {
@@ -100,7 +102,6 @@ public class AnticheatCommand extends BaseCommand {
}
@Subcommand("alerts")
@HelpCommand
@CommandPermission("anticheat.command.alerts")
@Description("Toggle anticheat alerts")
public void onAlerts(Player pl) {
@@ -1,10 +1,9 @@
package dev.brighten.ac.logging.sql;
import dev.brighten.ac.Anticheat;
import dev.brighten.ac.utils.reflections.Reflections;
import dev.brighten.ac.utils.reflections.types.WrappedConstructor;
import lombok.SneakyThrows;
import org.bukkit.Bukkit;
import org.h2.jdbc.JdbcConnection;
import java.io.File;
import java.io.IOException;
@@ -27,9 +26,7 @@ public class MySQL {
Anticheat.INSTANCE.getLogger().log(Level.SEVERE, "File write error: database.db");
}
try {
WrappedConstructor jdbcConnection = Reflections.getClass("org.h2.jdbc.JdbcConnection")
.getConstructor(String.class, Properties.class, String.class, Object.class, boolean.class);
conn = new NonClosableConnection(jdbcConnection.newInstance("jdbc:h2:file:" +
conn = new NonClosableConnection(new JdbcConnection("jdbc:h2:file:" +
dataFolder.getAbsolutePath(),
new Properties(), "root", "erc5gmv-xvg5CZQ0nzw", false));
conn.setAutoCommit(true);
@@ -1,10 +1,18 @@
package dev.brighten.ac.utils;
import co.aikar.commands.BaseCommand;
import dev.brighten.ac.Anticheat;
import dev.brighten.ac.utils.annotation.ConfigSetting;
import dev.brighten.ac.utils.annotation.Init;
import dev.brighten.ac.utils.annotation.Invoke;
import dev.brighten.ac.utils.config.Configuration;
import dev.brighten.ac.utils.reflections.Reflections;
import dev.brighten.ac.utils.reflections.types.WrappedClass;
import dev.brighten.ac.utils.reflections.types.WrappedField;
import dev.brighten.ac.utils.reflections.types.WrappedMethod;
import org.bukkit.Bukkit;
import org.bukkit.event.Listener;
import org.bukkit.plugin.Plugin;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.ClassNode;
@@ -54,6 +62,105 @@ public class ClassScanner {
return toReturn;
}
private static WrappedMethod findClassMethod =
new WrappedClass(Anticheat.INSTANCE.getClassLoader2().getClass()).getMethod("findClass", String.class);
public static void initializeScanner(Class<?> mainClass, Plugin plugin, Set<String> names) {
names.stream()
.map(name -> {
return new WrappedClass(findClassMethod.invoke(Anticheat.INSTANCE.getClassLoader2(), name));
})
.filter(c -> {
if(c.getParent() == null) {
return false;
}
Init init = c.getAnnotation(Init.class);
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 true;
})
.sorted(Comparator.comparing(c ->
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) {
Bukkit.getPluginManager().registerEvents((Listener)obj, plugin);
Anticheat.INSTANCE.alog(true,"&7Registered Bukkit listener &e"
+ c.getParent().getSimpleName() + "&7.");
}
if(obj instanceof BaseCommand) {
Anticheat.INSTANCE.alog(true,"&7Found BaseCommand for class &e"
+ c.getParent().getSimpleName() + "&7! Registering commands...");
Anticheat.INSTANCE.getCommandManager().registerCommand((BaseCommand)obj);
}
for (WrappedMethod method : c.getMethods()) {
if(method.getMethod().isAnnotationPresent(Invoke.class)) {
Anticheat.INSTANCE.alog(true,"&7Invoking method &e" + method.getName() + " &7in &e"
+ c.getClass().getSimpleName() + "&7...");
method.invoke(obj);
}
}
for (WrappedField field : c.getFields()) {
if(field.isAnnotationPresent(ConfigSetting.class)) {
ConfigSetting setting = field.getAnnotation(ConfigSetting.class);
String name = setting.name().length() > 0
? setting.name()
: field.getField().getName();
Anticheat.INSTANCE.alog(true, "&7Found ConfigSetting &e%s &7(default=&f%s&7).",
field.getField().getName(),
(setting.hide() ? "HIDDEN" : field.get(obj)));
Configuration config = Anticheat.INSTANCE.getAnticheatConfig();
if(config.get((setting.path().length() > 0 ? 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));
Anticheat.INSTANCE.saveConfig();
} else {
Object configObj = config.get((setting.path().length() > 0 ? setting.path() + "." : "") + name);
Anticheat.INSTANCE.alog(true, "&7Set field to value &e%s&7.",
(setting.hide() ? "HIDDEN" : configObj));
field.set(obj, configObj);
}
}
}
});
}
public static Set<WrappedClass> getClasses(Class<? extends Annotation> annotationClass) {
Map<String, byte[]> map = Anticheat.INSTANCE.getStuffs();
Map<String, byte[]> loadedClasses = Anticheat.INSTANCE.getLoadedClasses();
@@ -78,7 +185,7 @@ public class ClassScanner {
}
public static Set<String> getNames() {
Map<String, byte[]> map = Anticheat.INSTANCE.getStuffs();
Map<String, byte[]> map = new HashMap<>(Anticheat.INSTANCE.getStuffs());
Set<String> nameSet = new HashSet<>();
@@ -0,0 +1,98 @@
package dev.brighten.ac.utils;
import dev.brighten.ac.Anticheat;
import dev.brighten.ac.utils.reflections.Reflections;
import dev.brighten.ac.utils.reflections.types.WrappedClass;
import dev.brighten.ac.utils.reflections.types.WrappedMethod;
import it.unimi.dsi.fastutil.longs.LongArrayList;
import it.unimi.dsi.fastutil.longs.LongList;
import lombok.SneakyThrows;
import org.bukkit.plugin.InvalidDescriptionException;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import java.io.*;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.zip.CRC32;
public class IntegrityCheck {
private static WrappedClass classSystem = Reflections.getClass("java.lang.System");
private static WrappedMethod exitMethod = classSystem.getMethod("exit", int.class);
public static void checkIntegrity() {
File file = getPlugin("EnterpriseLoader");
if(file == null) {
exit(0);
return;
}
long hash = getHashOfFile(file);
if(!acceptableHashes.contains(hash)) {
System.out.println("Bad loader file!");
exit(0);
}
}
private static void exit(int number) {
exitMethod.invoke(null, number);
}
private static byte[] getBytes(InputStream inputStream) {
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
return buffer.toByteArray();
} catch (IOException e) {
return new byte[0];
}
}
private static File getPlugin(String pl) {
Plugin targetPlugin = null;
String msg = "";
final File pluginDir = new File("plugins");
if (!pluginDir.isDirectory()) {
return null;
}
File pluginFile = new File(pluginDir, pl + ".jar");
if (!pluginFile.isFile()) {
for (final File f : pluginDir.listFiles()) {
try {
if (f.getName().endsWith(".jar")) {
final PluginDescriptionFile pdf = Anticheat.INSTANCE.getPluginInstance()
.getPluginLoader().getPluginDescription(f);
if (pdf.getName().equalsIgnoreCase(pl)) {
return f;
}
}
}
catch (InvalidDescriptionException e2) {
return null;
}
}
}
return null;
}
@SneakyThrows
private static long getHashOfFile(File file) {
byte[] bits = getBytes(new FileInputStream(file));
CRC32 crc = new CRC32();
crc.update(ByteBuffer.wrap(bits));
return crc.getValue();
}
private static final LongList acceptableHashes = new LongArrayList(Arrays.asList(3436861907L, 679626389L));
}
@@ -1,6 +1,5 @@
package dev.brighten.ac.utils;
import dev.brighten.ac.Anticheat;
import dev.brighten.ac.packet.ProtocolVersion;
import dev.brighten.ac.utils.reflections.impl.CraftReflection;
import dev.brighten.ac.utils.reflections.impl.MinecraftReflection;
@@ -15,27 +14,19 @@ import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand;
import org.bukkit.command.SimpleCommandMap;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.*;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
import java.io.*;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.Supplier;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
import java.util.zip.ZipException;
public class MiscUtils {
@@ -328,181 +319,16 @@ public class MiscUtils {
return "-----------------------------------------------------";
}
public static String unloadPlugin(String pl) {
PluginManager pm = Bukkit.getServer().getPluginManager();
SimplePluginManager spm = (SimplePluginManager)pm;
SimpleCommandMap cmdMap = null;
List plugins = null;
Map names = null;
Map commands = null;
Map listeners = null;
boolean reloadlisteners = true;
if(spm != null) {
try {
Field tp = spm.getClass().getDeclaredField("plugins");
tp.setAccessible(true);
plugins = (List)tp.get(spm);
Field arr$ = spm.getClass().getDeclaredField("lookupNames");
arr$.setAccessible(true);
names = (Map)arr$.get(spm);
Field len$;
try {
len$ = spm.getClass().getDeclaredField("listeners");
len$.setAccessible(true);
listeners = (Map)len$.get(spm);
} catch (Exception var19) {
reloadlisteners = false;
}
len$ = spm.getClass().getDeclaredField("commandMap");
len$.setAccessible(true);
cmdMap = (SimpleCommandMap)len$.get(spm);
Field i$ = cmdMap.getClass().getDeclaredField("knownCommands");
i$.setAccessible(true);
commands = (Map)i$.get(cmdMap);
} catch (IllegalAccessException | NoSuchFieldException var20) {
return "Failed to unload plugin!";
}
}
String var21 = "";
Plugin[] var22 = Bukkit.getServer().getPluginManager().getPlugins();
int var23 = var22.length;
for(int var24 = 0; var24 < var23; ++var24) {
Plugin p = var22[var24];
if(p.getDescription().getName().equalsIgnoreCase(pl)) {
pm.disablePlugin(p);
var21 = var21 + p.getName() + " ";
if(plugins != null) {
plugins.remove(p);
}
if(names != null) {
names.remove(pl);
}
Iterator it;
if(listeners != null && reloadlisteners) {
it = listeners.values().iterator();
while(it.hasNext()) {
SortedSet entry = (SortedSet)it.next();
Iterator c = entry.iterator();
while(c.hasNext()) {
RegisteredListener value = (RegisteredListener)c.next();
if(value.getPlugin() == p) {
c.remove();
}
}
}
}
if(cmdMap != null) {
it = commands.entrySet().iterator();
while(it.hasNext()) {
Map.Entry var25 = (Map.Entry) it.next();
if(var25.getValue() instanceof PluginCommand) {
PluginCommand var26 = (PluginCommand)var25.getValue();
if(var26.getPlugin() == p) {
var26.unregister(cmdMap);
it.remove();
}
}
}
}
}
}
return var21 + "has been unloaded and disabled!";
}
//Stolen from Luke
public static boolean contains(Object[] array, Object obj) {
for (Object object : array) if (object != null && object.equals(obj)) return true;
return false;
}
public static Map<String, byte[]> loadJar(File jarFile) {
try {
Map<String, byte[]> classes = new HashMap<>();
JarFile jar = new JarFile(jarFile);
Enumeration<JarEntry> enumeration = jar.entries();
while (enumeration.hasMoreElements()) {
JarEntry entry = enumeration.nextElement();
readJar(jar, entry, classes, null);
}
jar.close();
return classes;
} catch (ZipException e) {
return null;
}
catch (IOException e) {
e.printStackTrace();
}
return null;
}
private static Map<String, byte[]> readJar(JarFile jar, JarEntry en, Map<String, byte[]> classes, List<String> ignored) {
String name = en.getName();
try (InputStream jis = jar.getInputStream(en)) {
if (name.endsWith(".class")) {
if (ignored != null) {
for (String s : ignored) {
if (name.startsWith(s)) {
return classes;
}
}
}
byte[] bytes = getBytes(jis);
try {
classes.put(name, bytes);
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
return classes;
}
private static byte[] getBytes(InputStream inputStream) {
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[16384];
while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
return buffer.toByteArray();
} catch (IOException e) {
return new byte[0];
}
}
public static <T> T parseObjectFromString(String s, Class<T> clazz) throws Exception {
return clazz.getConstructor(new Class[] {String.class}).newInstance(s);
}
public static BoundingBox getEntityBoundingBox(LivingEntity entity) {
if (entityDimensions.containsKey(entity.getType())) {
Vector entityVector = entityDimensions.get(entity.getType());
float minX = (float) Math.min(-entityVector.getX() + entity.getLocation().getX(), entityVector.getX() + entity.getLocation().getX());
float minY = (float) Math.min(entity.getLocation().getY(), entityVector.getY() + entity.getLocation().getY());
float minZ = (float) Math.min(-entityVector.getZ() + entity.getLocation().getZ(), entityVector.getZ() + entity.getLocation().getZ());
float maxX = (float) Math.max(-entityVector.getX() + entity.getLocation().getX(), entityVector.getX() + entity.getLocation().getX());
float maxY = (float) Math.max(entity.getLocation().getY(), entityVector.getY() + entity.getLocation().getY());
float maxZ = (float) Math.max(-entityVector.getZ() + entity.getLocation().getZ(), entityVector.getZ() + entity.getLocation().getZ());
return new BoundingBox(minX, minY, minZ, maxX, maxY, maxZ);
}
return ReflectionsUtil.toBoundingBox(ReflectionsUtil.getBoundingBox(entity));
}
/* MAKE SURE TO ONLY RUN THIS METHOD IN onLoad() AND NO WHERE ELSE */
public static void registerCommand(String name, JavaPlugin plugin) {
plugin.getDescription().getCommands().put(name, new HashMap<>());
@@ -534,106 +360,11 @@ public class MiscUtils {
return true;
}
public static List<File> getAtlasDependingPlugins() {
List<File> plugins = new ArrayList<>();
final File pluginDir = new File("plugins");
if (!pluginDir.isDirectory()) {
return plugins;
}
for (final File f : pluginDir.listFiles()) {
try {
if (f.getName().endsWith(".jar")) {
final PluginDescriptionFile pdf = Anticheat.INSTANCE.getPluginInstance().getPluginLoader().getPluginDescription(f);
if (pdf.getDepend().contains("Atlas")) {
plugins.add(f);
}
}
}
catch (InvalidDescriptionException e2) {
//Empty catch block.
}
}
return plugins;
}
public static void loadPlugin(final String pl) {
Plugin targetPlugin = null;
String msg = "";
final File pluginDir = new File("plugins");
if (!pluginDir.isDirectory()) {
return;
}
File pluginFile = new File(pluginDir, pl + ".jar");
if (!pluginFile.isFile()) {
for (final File f : pluginDir.listFiles()) {
try {
if (f.getName().endsWith(".jar")) {
final PluginDescriptionFile pdf = Anticheat.INSTANCE.getPluginInstance().getPluginLoader().getPluginDescription(f);
if (pdf.getName().equalsIgnoreCase(pl)) {
pluginFile = f;
msg = "(via search) ";
break;
}
}
}
catch (InvalidDescriptionException e2) {
return;
}
}
}
try {
Anticheat.INSTANCE.getServer().getPluginManager().loadPlugin(pluginFile);
targetPlugin = getPlugin(pl);
Anticheat.INSTANCE.getServer().getPluginManager().enablePlugin(targetPlugin);
}
catch (UnknownDependencyException | InvalidPluginException | InvalidDescriptionException e3) {
e3.printStackTrace();
}
}
private static Plugin getPlugin(final String p) {
for (final Plugin pl : Anticheat.INSTANCE.getServer().getPluginManager().getPlugins()) {
if (pl.getDescription().getName().equalsIgnoreCase(p)) {
return pl;
}
}
return null;
}
public static <T> T getArgOrNull(T[] array, int index) {
if(array.length > index) {
return array[index];
}
return null;
}
static {
entityDimensions.put(EntityType.WOLF, new Vector(0.31, 0.8, 0.31));
entityDimensions.put(EntityType.SHEEP, new Vector(0.45, 1.3, 0.45));
entityDimensions.put(EntityType.COW, new Vector(0.45, 1.3, 0.45));
entityDimensions.put(EntityType.PIG, new Vector(0.45, 0.9, 0.45));
entityDimensions.put(EntityType.MUSHROOM_COW, new Vector(0.45, 1.3, 0.45));
entityDimensions.put(EntityType.WITCH, new Vector(0.31, 1.95, 0.31));
entityDimensions.put(EntityType.BLAZE, new Vector(0.31, 1.8, 0.31));
entityDimensions.put(EntityType.PLAYER, new Vector(0.3, 1.8, 0.3));
entityDimensions.put(EntityType.VILLAGER, new Vector(0.31, 1.8, 0.31));
entityDimensions.put(EntityType.CREEPER, new Vector(0.31, 1.8, 0.31));
entityDimensions.put(EntityType.GIANT, new Vector(1.8, 10.8, 1.8));
entityDimensions.put(EntityType.SKELETON, new Vector(0.31, 1.8, 0.31));
entityDimensions.put(EntityType.ZOMBIE, new Vector(0.31, 1.8, 0.31));
entityDimensions.put(EntityType.SNOWMAN, new Vector(0.35, 1.9, 0.35));
entityDimensions.put(EntityType.HORSE, new Vector(0.7, 1.6, 0.7));
entityDimensions.put(EntityType.ENDER_DRAGON, new Vector(1.5, 1.5, 1.5));
entityDimensions.put(EntityType.ENDERMAN, new Vector(0.31, 2.9, 0.31));
entityDimensions.put(EntityType.CHICKEN, new Vector(0.2, 0.7, 0.2));
entityDimensions.put(EntityType.OCELOT, new Vector(0.31, 0.7, 0.31));
entityDimensions.put(EntityType.SPIDER, new Vector(0.7, 0.9, 0.7));
entityDimensions.put(EntityType.WITHER, new Vector(0.45, 3.5, 0.45));
entityDimensions.put(EntityType.IRON_GOLEM, new Vector(0.7, 2.9, 0.7));
entityDimensions.put(EntityType.GHAST, new Vector(2, 4, 2));
}
}