diff --git a/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoColor.java b/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoColor.java index 220ea4e6..64b2522d 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoColor.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/params/types/custom/ParamInfoColor.java @@ -57,7 +57,7 @@ public class ParamInfoColor extends ParamInfoEnum { } @Override - protected Object fromString(String string) { + public Object fromString(String string) { return parseToColor(string); } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/Asm14.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/Asm14.java deleted file mode 100644 index ede3695c..00000000 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/Asm14.java +++ /dev/null @@ -1,65 +0,0 @@ -package me.libraryaddict.disguise.utilities.reflection.asm; - -import lombok.Getter; -import org.bukkit.craftbukkit.libs.org.objectweb.asm.*; - -import java.io.IOException; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Map; - -/** - * Created by libraryaddict on 17/02/2020. - */ -public class Asm14 implements IAsm { - @Getter - private Method defineMethod; - - public Asm14() throws NoSuchMethodException { - defineMethod = getDefineClassMethod(); - } - - public Class createClassWithoutMethods(String className, - ArrayList> illegalMethods) throws IOException, InvocationTargetException, - IllegalAccessException, NoSuchFieldException { - ClassReader cr = new ClassReader( - getClass().getClassLoader().getResourceAsStream(className.replace(".", "/") + ".class")); - ClassWriter writer = new ClassWriter(cr, 0); - - cr.accept(new ClassVisitor(Opcodes.ASM5, writer) { - public MethodVisitor visitMethod(int access, String name, String desc, String signature, - String[] exceptions) { - - Map.Entry entry = illegalMethods.stream() - .filter(e -> e.getKey().equals(name) && e.getValue().equals(desc)).findFirst().orElse(null); - - if (entry != null) { - return null; - } - - return super.visitMethod(access, name, desc, signature, exceptions); - } - }, 0); - - byte[] bytes = writer.toByteArray(); - - ClassLoader loader = getClass().getClassLoader(); - Field field = loader.getClass().getDeclaredField("classes"); - field.setAccessible(true); - Map> map = (Map>) field.get(loader); - Class newClass = (Class) defineMethod.invoke(getClass().getClassLoader(), className, bytes, 0, bytes.length); - - map.put(className, newClass); - return newClass; - } - - private Method getDefineClassMethod() throws NoSuchMethodException { - Method defineClass = ClassLoader.class - .getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class); - defineClass.setAccessible(true); - - return defineClass; - } -} diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/AsmDownloader.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/AsmDownloader.java index b3ad452b..0e0c41a3 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/AsmDownloader.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/AsmDownloader.java @@ -24,14 +24,10 @@ public class AsmDownloader { /** * Using maven */ - private String urlToGrab = "https://search.maven.org/remotecontent?filepath=org/ow2/asm/asm/7.3.1/asm-7.3.1.jar"; - private File filePath = new File(LibsDisguises.getInstance().getDataFolder(), "libs/org-ow2-asm-7.3.1.jar"); + private String urlToGrab = "https://search.maven.org/remotecontent?filepath=org/ow2/asm/asm/9.1/asm-9.1.jar"; + private File filePath = new File(LibsDisguises.getInstance().getDataFolder(), "libs/org-ow2-asm-9.1.jar"); public AsmDownloader() { - if (NmsVersion.v1_13.isSupported()) { - throw new IllegalStateException("Sorry, this shouldn't have been started!"); - } - try { Class.forName("org.objectweb.asm.ClassReader"); return; @@ -41,7 +37,7 @@ public class AsmDownloader { } if (!hasASM()) { - LibsDisguises.getInstance().getLogger().info("Downloading required library for 1.12 support!"); + LibsDisguises.getInstance().getLogger().info("Downloading required library for asm!"); downloadASM(); diff --git a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java index ed5a5a83..1f56fbba 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/reflection/asm/WatcherSanitizer.java @@ -35,10 +35,9 @@ public class WatcherSanitizer { PluginDescriptionFile desc = (PluginDescriptionFile) dF.get(loader); if (hasWatcher(lClasses)) { - LibsDisguises.getInstance().getLogger().severe(desc.getFullName() + - " has been a naughty plugin, they're declaring access to the disguise watchers before Lib's " + - "Disguises can properly load them! They should add 'LibsDisguises' to the 'depend' section of" + - " their plugin.yml!"); + LibsDisguises.getInstance().getLogger() + .severe(desc.getFullName() + " has been a naughty plugin, they're declaring access to the disguise watchers before Lib's " + + "Disguises can properly load them! They should add 'LibsDisguises' to the 'depend' section of" + " their plugin.yml!"); break; } } @@ -49,8 +48,7 @@ public class WatcherSanitizer { if (hasWatcher(classes)) { LibsDisguises.getInstance().getLogger() - .severe("Somehow the main server has a Watcher instance! Hopefully there was a plugin mentioned " + - "above! This is a bug!"); + .severe("Somehow the main server has a Watcher instance! Hopefully there was a plugin mentioned " + "above! This is a bug!"); } } @@ -77,17 +75,8 @@ public class WatcherSanitizer { ArrayList mapped = new ArrayList<>(); try (InputStream stream = LibsDisguises.getInstance().getResource("ANTI_PIRACY_ENCRYPTION")) { - IAsm asm; - - if (NmsVersion.v1_14.isSupported()) { - asm = new Asm14(); - } else { - if (!NmsVersion.v1_13.isSupported()) { - new AsmDownloader(); - } - - asm = new Asm13(); - } + new AsmDownloader(); + IAsm asm = new Asm13(); String[] lines = new String(ReflectionManager.readFully(stream), StandardCharsets.UTF_8).split("\n"); @@ -100,8 +89,7 @@ public class WatcherSanitizer { continue; } - String path = "me.libraryaddict.disguise.disguisetypes." + - (info.getWatcher().equals("FlagWatcher") ? "" : "watchers.") + info.getWatcher(); + String path = "me.libraryaddict.disguise.disguisetypes." + (info.getWatcher().equals("FlagWatcher") ? "" : "watchers.") + info.getWatcher(); toRemove.putIfAbsent(path, new ArrayList<>());