Don't fatal error if someone's using a dumb jar system
This commit is contained in:
parent
1cb9c0ee4a
commit
7f3aa75c44
@ -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
|
||||||
|
@ -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;
|
||||||
|
@ -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);
|
||||||
|
PluginDescriptionFile desc = (PluginDescriptionFile) dF.get(loader);
|
||||||
|
|
||||||
for (Class c : lClasses.values()) {
|
if (hasWatcher(lClasses)) {
|
||||||
if (!c.getName().startsWith("me.libraryaddict.disguise.disguisetypes.watchers.") &&
|
|
||||||
!c.getName().equals("me.libraryaddict.disguise.disguisetypes.FlagWatcher")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
PluginDescriptionFile desc = (PluginDescriptionFile) dF.get(loader);
|
|
||||||
|
|
||||||
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() {
|
||||||
|
@ -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");
|
||||||
|
|
||||||
for (Class c : ClassGetter.getClassesForPackage("org.bukkit.entity")) {
|
try {
|
||||||
if (c != Entity.class && Entity.class.isAssignableFrom(c) && c.getAnnotation(Deprecated.class) == null) {
|
for (Class c : ClassGetter.getClassesForPackage("org.bukkit.entity")) {
|
||||||
TranslateType.DISGUISES.save(c.getSimpleName(),
|
if (c != Entity.class && Entity.class.isAssignableFrom(c) &&
|
||||||
"Name for the " + c.getSimpleName() + " EntityType, " + "this is used in radius commands");
|
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.save("EntityType", "Used for the disgiuse radius command to list all entitytypes");
|
||||||
TranslateType.DISGUISES
|
TranslateType.DISGUISES
|
||||||
|
Loading…
Reference in New Issue
Block a user