Make it not required to put all permissions in the PERM file

This commit is contained in:
Magnus Ulf 2019-02-08 16:38:00 +01:00
parent b0086ba0f7
commit 140201478f
4 changed files with 27 additions and 23 deletions

View File

@ -9,10 +9,10 @@ public enum MassiveCorePerm implements Identified
// ENUM // ENUM
// -------------------------------------------- // // -------------------------------------------- //
BASECOMMAND, /*BASECOMMAND,
TEST, TEST,
ID, ID,
VERSION,
HEARSOUND, HEARSOUND,
STORE, STORE,
STORE_STATS, STORE_STATS,
@ -21,7 +21,7 @@ public enum MassiveCorePerm implements Identified
STORE_CLEAN, STORE_CLEAN,
USYS, USYS,
USYS_MULTIVERSE, USYS_MULTIVERSE,
USYS_MULTIVERSE_LIST,
USYS_MULTIVERSE_SHOW, USYS_MULTIVERSE_SHOW,
USYS_MULTIVERSE_NEW, USYS_MULTIVERSE_NEW,
USYS_MULTIVERSE_DEL, USYS_MULTIVERSE_DEL,
@ -31,7 +31,7 @@ public enum MassiveCorePerm implements Identified
USYS_UNIVERSE_CLEAR, USYS_UNIVERSE_CLEAR,
USYS_WORLD, USYS_WORLD,
USYS_ASPECT, USYS_ASPECT,
USYS_ASPECT_LIST,
USYS_ASPECT_SHOW, USYS_ASPECT_SHOW,
USYS_ASPECT_USE, USYS_ASPECT_USE,
BUFFER, BUFFER,
@ -41,14 +41,18 @@ public enum MassiveCorePerm implements Identified
BUFFER_ADD, BUFFER_ADD,
BUFFER_WHITESPACE, BUFFER_WHITESPACE,
CMDURL, CMDURL,
CONFIG,
SPONSOR, SPONSOR,
CLICK, CLICK,
NOTPDELAY, NOTPDELAY,*/
CONFIG,
VERSION,
USYS_MULTIVERSE_LIST,
USYS_ASPECT_LIST,
VARIABLE_BOOK, VARIABLE_BOOK,
VARIABLE_BUFFER, VARIABLE_BUFFER,
// END OF LIST // END OF LIST
; ;

View File

@ -32,7 +32,7 @@ public class CmdMassiveCore extends MassiveCoreCommand
public CmdMassiveCoreCmdurl cmdMassiveCoreCmdurl = new CmdMassiveCoreCmdurl(); public CmdMassiveCoreCmdurl cmdMassiveCoreCmdurl = new CmdMassiveCoreCmdurl();
public CommandEditAbstract<MassiveCoreMConf, MassiveCoreMConf> cmdMassiveCoreConfig = new CommandEditSingleton<>(MassiveCoreMConf.get()).addRequirements(RequirementHasPerm.get(MassiveCorePerm.CONFIG)); public CommandEditAbstract<MassiveCoreMConf, MassiveCoreMConf> cmdMassiveCoreConfig = new CommandEditSingleton<>(MassiveCoreMConf.get()).addRequirements(RequirementHasPerm.get(MassiveCorePerm.CONFIG));
public CmdMassiveCoreClick cmdMassiveCoreClick = new CmdMassiveCoreClick(); public CmdMassiveCoreClick cmdMassiveCoreClick = new CmdMassiveCoreClick();
public MassiveCommandVersion cmdMassiveCoreVersion = new MassiveCommandVersion(MassiveCore.get()).setAliases("v", "version").addRequirements(RequirementHasPerm.get(MassiveCorePerm.VERSION)); public MassiveCommandVersion cmdMassiveCoreVersion = new MassiveCommandVersion(MassiveCore.get()).addRequirements(RequirementHasPerm.get(MassiveCorePerm.VERSION));
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE

View File

@ -997,13 +997,12 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
public void setupChildren() public void setupChildren()
{ {
for (MassiveCommand child : this.getChildren()) this.getChildren().stream()
{ .filter(MassiveCommand::isSetupEnabled)
if (child.isSetupEnabled()) child.setup(); .forEach(MassiveCommand::setup);
}
} }
private Class<?> getClassOrEnclosing(Object object) private static Class<?> getClassOrEnclosing(Object object)
{ {
Class<?> clazz = object.getClass(); Class<?> clazz = object.getClass();
Class<?> enclosingClass = clazz.getEnclosingClass(); Class<?> enclosingClass = clazz.getEnclosingClass();
@ -1031,16 +1030,13 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
return ret; return ret;
} }
protected <T extends Enum<T>> T calcPerm() protected Object calcPerm()
{ {
Class<T> permClass = this.getSetupPermClass(); Class<? extends Enum<?>> permClass = this.getSetupPermClass();
String basePrefix = this.getSetupPermBaseClassName(); String basePrefix = this.getSetupPermBaseClassName();
if (permClass == null) return null;
if (basePrefix == null) return null;
// Only try if the name matches with the expected prefix ... // Only try if the name matches with the expected prefix ...
String name = getClassOrEnclosing(this).getSimpleName(); //this.getClass().getSimpleName(); String name = getClassOrEnclosing(this).getSimpleName();
if ( ! name.startsWith(basePrefix)) return null; if ( ! name.startsWith(basePrefix)) return null;
// ... and remove the prefix ... // ... and remove the prefix ...
@ -1056,7 +1052,7 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
if (permName.isEmpty()) permName = "BASECOMMAND"; if (permName.isEmpty()) permName = "BASECOMMAND";
// Create ret // Create ret
T ret = null; Object ret = null;
// Try non-lenient // Try non-lenient
ret = getPerm(permName, false, permClass); ret = getPerm(permName, false, permClass);
@ -1066,11 +1062,13 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
ret = getPerm(permName, true, permClass); ret = getPerm(permName, true, permClass);
if (ret != null) return ret; if (ret != null) return ret;
throw new RuntimeException("Could not find permission matching: " + permName); // Or calculate ourselves
return PermissionUtil.createPermissionId(this.getRoot().getPlugin(), permName);
} }
protected static <T extends Enum<T>> T getPerm(String permName, boolean lenient, Class<T> permClass) protected static <T extends Enum<T>> T getPerm(String permName, boolean lenient, Class<?> permClazz)
{ {
Class<T> permClass = (Class<T>) permClazz;
permName = getPermCompareString(permName, lenient); permName = getPermCompareString(permName, lenient);
for (T perm : TypeEnum.getEnumValues(permClass)) for (T perm : TypeEnum.getEnumValues(permClass))
{ {

View File

@ -159,7 +159,9 @@ public class DriverFlatfile extends DriverAbstract
public static JsonObject loadFileJsonObject(File file) public static JsonObject loadFileJsonObject(File file)
{ {
return loadFileJson(file).getAsJsonObject(); JsonElement ret = loadFileJson(file);
if (ret == null) return null;
return ret.getAsJsonObject();
} }
public static JsonElement loadFileJson(File file) public static JsonElement loadFileJson(File file)