From 43aa37a9ec6caec7de3b10f931cc762187fb46af Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Mon, 7 Jun 2021 20:00:05 +1200 Subject: [PATCH] Fix some disguise methods not working --- .../utilities/parser/WatcherMethod.java | 6 ++++++ .../utilities/watchers/DisguiseMethods.java | 21 ++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/utilities/parser/WatcherMethod.java b/src/main/java/me/libraryaddict/disguise/utilities/parser/WatcherMethod.java index 6db52170..4c68393e 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/parser/WatcherMethod.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/parser/WatcherMethod.java @@ -18,4 +18,10 @@ public class WatcherMethod { private final Class returnType; private final Class param; private final boolean randomDefault; + + @Override + public String toString() { + return "WatcherMethod{" + "watcherClass=" + watcherClass + ", method=" + method + ", name='" + name + '\'' + ", returnType=" + returnType + ", param=" + + param + ", randomDefault=" + randomDefault + '}'; + } } diff --git a/src/main/java/me/libraryaddict/disguise/utilities/watchers/DisguiseMethods.java b/src/main/java/me/libraryaddict/disguise/utilities/watchers/DisguiseMethods.java index 80d7d5c8..7d7aa50a 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/watchers/DisguiseMethods.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/watchers/DisguiseMethods.java @@ -8,6 +8,7 @@ import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.PlayerDisguise; +import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher; import me.libraryaddict.disguise.utilities.params.ParamInfoManager; import me.libraryaddict.disguise.utilities.parser.WatcherMethod; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; @@ -106,7 +107,8 @@ public class DisguiseMethods { methods.add(m); - if (m.getName().startsWith("get") || m.getName().startsWith("has") || param == null || param == Void.TYPE || ParamInfoManager.getParamInfo(m) == null) { + if (m.getName().startsWith("get") || m.getName().startsWith("has") || param == null || param == Void.TYPE || + ParamInfoManager.getParamInfo(m) == null) { continue; } @@ -122,6 +124,7 @@ public class DisguiseMethods { try { Class cl = boolean.class; Class disguiseClass = Disguise.class; + boolean randomDefault = false; switch (methodName) { case "setExpires": @@ -136,8 +139,9 @@ public class DisguiseMethods { case "setBossBarStyle": cl = BarStyle.class; break; - case "setSoundGroup": case "setDisguiseName": + randomDefault = true; + case "setSoundGroup": cl = String.class; break; case "setDeadmau5Ears": @@ -151,9 +155,20 @@ public class DisguiseMethods { try { WatcherMethod method = new WatcherMethod(disguiseClass, MethodHandles.publicLookup().findVirtual(disguiseClass, methodName, MethodType.methodType(returnType, cl)), methodName, - null, cl, false); + null, cl, randomDefault); methods.add(method); + + watcherMethods.computeIfAbsent(disguiseClass == Disguise.class ? FlagWatcher.class : PlayerWatcher.class, (a) -> new ArrayList<>()) + .add(method); + + String getName = (cl == boolean.class ? "is" : "get") + methodName.substring(3); + + WatcherMethod getMethod = new WatcherMethod(disguiseClass, + MethodHandles.publicLookup().findVirtual(disguiseClass, getName, MethodType.methodType(cl)), getName, cl, null, + randomDefault); + + methods.add(getMethod); break; } catch (NoSuchMethodException ex) { if (returnType == disguiseClass) {