Don't fatal error if someone's using a dumb jar system
This commit is contained in:
		| @@ -34,13 +34,13 @@ public class LibsDisguises extends JavaPlugin { | ||||
|  | ||||
|         if (!Bukkit.getServer().getWorlds().isEmpty()) { | ||||
|             reloaded = true; | ||||
|             getLogger() | ||||
|                     .severe("Lib's Disguises was reloaded! Please do not report any bugs! This plugin can't handle " + | ||||
|                             "reloads gracefully!"); | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         WatcherSanitizer.init(); | ||||
|  | ||||
|         getLogger().severe("Lib's Disguises was reloaded! Please do not report any bugs! This plugin can't handle " + | ||||
|                 "reloads gracefully!"); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|   | ||||
| @@ -31,9 +31,10 @@ public class ClassGetter { | ||||
|         if (src != null) { | ||||
|             URL resource = src.getLocation(); | ||||
|  | ||||
|             if (resource.getPath().endsWith(".jar")) { | ||||
|             if (resource.getPath().toLowerCase().endsWith(".jar")) { | ||||
|                 processJarfile(resource, pkgname, classes); | ||||
|             } else { | ||||
|                 System.out.println("Not sure how you got here: " + resource.getPath()); | ||||
|                 for (File f : new File(resource.getPath() + "/" + pkgname.replace(".", "/")).listFiles()) { | ||||
|                     if (!f.getName().endsWith(".class")) { | ||||
|                         continue; | ||||
|   | ||||
| @@ -24,9 +24,6 @@ public class WatcherSanitizer { | ||||
|     public static void checkPreLoaded() throws NoSuchFieldException, IllegalAccessException { | ||||
|         JavaPluginLoader javaLoader = (JavaPluginLoader) LibsDisguises.getInstance().getPluginLoader(); | ||||
|  | ||||
|         Field cM = JavaPluginLoader.class.getDeclaredField("classes"); | ||||
|         cM.setAccessible(true); | ||||
|         Map<String, Class<?>> classes = (Map<String, Class<?>>) cM.get(javaLoader); | ||||
|         Field lM = JavaPluginLoader.class.getDeclaredField("loaders"); | ||||
|         lM.setAccessible(true); | ||||
|         List loaders = (List) lM.get(javaLoader); | ||||
| @@ -38,15 +35,9 @@ public class WatcherSanitizer { | ||||
|  | ||||
|         for (Object loader : loaders) { | ||||
|             Map<String, Class<?>> lClasses = (Map<String, Class<?>>) lF.get(loader); | ||||
|             PluginDescriptionFile desc = (PluginDescriptionFile) dF.get(loader); | ||||
|  | ||||
|             for (Class c : lClasses.values()) { | ||||
|                 if (!c.getName().startsWith("me.libraryaddict.disguise.disguisetypes.watchers.") && | ||||
|                         !c.getName().equals("me.libraryaddict.disguise.disguisetypes.FlagWatcher")) { | ||||
|                     continue; | ||||
|                 } | ||||
|  | ||||
|                 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" + | ||||
| @@ -54,6 +45,29 @@ public class WatcherSanitizer { | ||||
|                 break; | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         Field cM = JavaPluginLoader.class.getDeclaredField("classes"); | ||||
|         cM.setAccessible(true); | ||||
|         Map<String, Class<?>> classes = (Map<String, Class<?>>) cM.get(javaLoader); | ||||
|  | ||||
|         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!"); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private static boolean hasWatcher(Map<String, Class<?>> classes) { | ||||
|         for (Class c : classes.values()) { | ||||
|             if (!c.getName().startsWith("me.libraryaddict.disguise.disguisetypes.watchers.") && | ||||
|                     !c.getName().equals("me.libraryaddict.disguise.disguisetypes.FlagWatcher")) { | ||||
|                 continue; | ||||
|             } | ||||
|  | ||||
|             return true; | ||||
|         } | ||||
|  | ||||
|         return false; | ||||
|     } | ||||
|  | ||||
|     public static void init() { | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package me.libraryaddict.disguise.utilities.translations; | ||||
|  | ||||
| import me.libraryaddict.disguise.disguisetypes.DisguiseType; | ||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||
| import me.libraryaddict.disguise.utilities.params.ParamInfo; | ||||
| import me.libraryaddict.disguise.utilities.params.ParamInfoManager; | ||||
| import me.libraryaddict.disguise.utilities.reflection.ClassGetter; | ||||
| @@ -80,12 +81,20 @@ public class TranslateFiller { | ||||
|         TranslateType.DISGUISE_OPTIONS.save("baby", "Used as a shortcut for setBaby when disguising an entity"); | ||||
|         TranslateType.DISGUISE_OPTIONS.save("adult", "Used as a shortcut for setBaby(false) when disguising an entity"); | ||||
|  | ||||
|         for (Class c : ClassGetter.getClassesForPackage("org.bukkit.entity")) { | ||||
|             if (c != Entity.class && Entity.class.isAssignableFrom(c) && c.getAnnotation(Deprecated.class) == null) { | ||||
|                 TranslateType.DISGUISES.save(c.getSimpleName(), | ||||
|                         "Name for the " + c.getSimpleName() + " EntityType, " + "this is used in radius commands"); | ||||
|         try { | ||||
|             for (Class c : ClassGetter.getClassesForPackage("org.bukkit.entity")) { | ||||
|                 if (c != Entity.class && Entity.class.isAssignableFrom(c) && | ||||
|                         c.getAnnotation(Deprecated.class) == null) { | ||||
|                     TranslateType.DISGUISES.save(c.getSimpleName(), | ||||
|                             "Name for the " + c.getSimpleName() + " EntityType, " + "this is used in radius commands"); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|         catch (Exception ex) { | ||||
|             DisguiseUtilities.getLogger() | ||||
|                     .severe("Error while trying to read entity types, assuming you're using a weird jar loader and " + | ||||
|                             "not making this fatal.."); | ||||
|         } | ||||
|  | ||||
|         TranslateType.DISGUISES.save("EntityType", "Used for the disgiuse radius command to list all entitytypes"); | ||||
|         TranslateType.DISGUISES | ||||
|   | ||||
		Reference in New Issue
	
	Block a user