mirror of
https://github.com/funkemunky/KauriV3.git
synced 2026-07-01 18:28:25 +00:00
Adding shit
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user