Don't fatal error if someone's using a dumb jar system

This commit is contained in:
libraryaddict 2020-02-23 10:54:09 +13:00
parent 1cb9c0ee4a
commit 7f3aa75c44
No known key found for this signature in database
GPG Key ID: 052E4FBCD257AEA4
4 changed files with 43 additions and 19 deletions

View File

@ -34,13 +34,13 @@ public class LibsDisguises extends JavaPlugin {
if (!Bukkit.getServer().getWorlds().isEmpty()) { if (!Bukkit.getServer().getWorlds().isEmpty()) {
reloaded = true; reloaded = true;
getLogger()
.severe("Lib's Disguises was reloaded! Please do not report any bugs! This plugin can't handle " +
"reloads gracefully!");
return; return;
} }
WatcherSanitizer.init(); WatcherSanitizer.init();
getLogger().severe("Lib's Disguises was reloaded! Please do not report any bugs! This plugin can't handle " +
"reloads gracefully!");
} }
@Override @Override

View File

@ -31,9 +31,10 @@ public class ClassGetter {
if (src != null) { if (src != null) {
URL resource = src.getLocation(); URL resource = src.getLocation();
if (resource.getPath().endsWith(".jar")) { if (resource.getPath().toLowerCase().endsWith(".jar")) {
processJarfile(resource, pkgname, classes); processJarfile(resource, pkgname, classes);
} else { } else {
System.out.println("Not sure how you got here: " + resource.getPath());
for (File f : new File(resource.getPath() + "/" + pkgname.replace(".", "/")).listFiles()) { for (File f : new File(resource.getPath() + "/" + pkgname.replace(".", "/")).listFiles()) {
if (!f.getName().endsWith(".class")) { if (!f.getName().endsWith(".class")) {
continue; continue;

View File

@ -24,9 +24,6 @@ public class WatcherSanitizer {
public static void checkPreLoaded() throws NoSuchFieldException, IllegalAccessException { public static void checkPreLoaded() throws NoSuchFieldException, IllegalAccessException {
JavaPluginLoader javaLoader = (JavaPluginLoader) LibsDisguises.getInstance().getPluginLoader(); 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"); Field lM = JavaPluginLoader.class.getDeclaredField("loaders");
lM.setAccessible(true); lM.setAccessible(true);
List loaders = (List) lM.get(javaLoader); List loaders = (List) lM.get(javaLoader);
@ -38,15 +35,9 @@ public class WatcherSanitizer {
for (Object loader : loaders) { for (Object loader : loaders) {
Map<String, Class<?>> lClasses = (Map<String, Class<?>>) lF.get(loader); Map<String, Class<?>> lClasses = (Map<String, Class<?>>) lF.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); PluginDescriptionFile desc = (PluginDescriptionFile) dF.get(loader);
if (hasWatcher(lClasses)) {
LibsDisguises.getInstance().getLogger().severe(desc.getFullName() + LibsDisguises.getInstance().getLogger().severe(desc.getFullName() +
" has been a naughty plugin, they're declaring access to the disguise watchers before Lib's " + " 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" + "Disguises can properly load them! They should add 'LibsDisguises' to the 'depend' section of" +
@ -54,6 +45,29 @@ public class WatcherSanitizer {
break; 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() { public static void init() {

View File

@ -1,6 +1,7 @@
package me.libraryaddict.disguise.utilities.translations; package me.libraryaddict.disguise.utilities.translations;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; 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.ParamInfo;
import me.libraryaddict.disguise.utilities.params.ParamInfoManager; import me.libraryaddict.disguise.utilities.params.ParamInfoManager;
import me.libraryaddict.disguise.utilities.reflection.ClassGetter; 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("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"); TranslateType.DISGUISE_OPTIONS.save("adult", "Used as a shortcut for setBaby(false) when disguising an entity");
try {
for (Class c : ClassGetter.getClassesForPackage("org.bukkit.entity")) { for (Class c : ClassGetter.getClassesForPackage("org.bukkit.entity")) {
if (c != Entity.class && Entity.class.isAssignableFrom(c) && c.getAnnotation(Deprecated.class) == null) { if (c != Entity.class && Entity.class.isAssignableFrom(c) &&
c.getAnnotation(Deprecated.class) == null) {
TranslateType.DISGUISES.save(c.getSimpleName(), TranslateType.DISGUISES.save(c.getSimpleName(),
"Name for the " + c.getSimpleName() + " EntityType, " + "this is used in radius commands"); "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.save("EntityType", "Used for the disgiuse radius command to list all entitytypes");
TranslateType.DISGUISES TranslateType.DISGUISES