Make automatic loading deal properly with anonymous classes.

This commit is contained in:
ulumulu1510 2017-07-03 02:04:33 +02:00 committed by Olof Larsson
parent a077762b62
commit 334b31e060

View File

@ -949,9 +949,7 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
public void setupAddChildren()
{
String s = this.getClass().getSimpleName();
for (Field field : this.getClass().getDeclaredFields())
for (Field field : this.getClassOrEnclosing(this).getDeclaredFields())
{
ReflectionUtil.makeAccessible(field);
Class<?> fieldType = field.getType();
@ -972,13 +970,20 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
}
}
private Class<?> getClassOrEnclosing(Object object)
{
Class<?> clazz = object.getClass();
Class<?> enclosingClass = clazz.getEnclosingClass();
return enclosingClass == null ? clazz : enclosingClass;
}
protected String calcName()
{
// If this is a child command
if (this.isRoot()) return null;
// ... get name of parent ...
String parentName = this.getParent().getClass().getSimpleName();
String parentName = this.getClassOrEnclosing(this.getParent()).getSimpleName();
// ... and only try if the names match ...
String name = this.getClass().getSimpleName();
@ -1011,7 +1016,7 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
// ... split at new words and separate with underscore.
permName = Txt.implode(Txt.camelsplit(permName), "_");
// Enums are alway upper case.
// Enums are always upper case.
permName = permName.toUpperCase();
// If the name is empty it is the base command