From 8506fc087aa2d87d792bca58c8d90fc03901913c Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 25 Feb 2020 23:56:34 +1300 Subject: [PATCH] Sort flagwatchers with a more reliable method --- .../utilities/watchers/CompileMethods.java | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java b/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java index df5d788c..d050fa53 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/watchers/CompileMethods.java @@ -13,10 +13,7 @@ import org.bukkit.Sound; import java.io.File; import java.io.PrintWriter; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Random; +import java.util.*; /** * Created by libraryaddict on 13/02/2020. @@ -64,15 +61,37 @@ public class CompileMethods { } } + private static void addClass(ArrayList classes, Class c) { + if (classes.contains(c)) { + return; + } + + System.out.println("Now processing " + c.getName()); + + if (c != FlagWatcher.class) { + addClass(classes, c.getSuperclass()); + + int ind = classes.indexOf(c.getSuperclass()); + classes.add(ind + 1, c); + } else { + classes.add(0, c); + } + } + private static void doMethods() { ArrayList> classes = ClassGetter .getClassesForPackage(FlagWatcher.class, "me.libraryaddict.disguise.disguisetypes.watchers"); classes.add(FlagWatcher.class); - classes.sort((c1, c2) -> c1.isAssignableFrom(c2) ? -1 : 1); + + ArrayList sorted = new ArrayList<>(); + + for (Class c : classes) { + addClass(sorted, c); + } ArrayList methods = new ArrayList<>(); - for (Class c : classes) { + for (Class c : sorted) { for (Method method : c.getMethods()) { if (!FlagWatcher.class.isAssignableFrom(method.getDeclaringClass())) { continue;