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

View File

@ -32,7 +32,7 @@ public class CmdMassiveCore extends MassiveCoreCommand
public CmdMassiveCoreCmdurl cmdMassiveCoreCmdurl = new CmdMassiveCoreCmdurl();
public CommandEditAbstract<MassiveCoreMConf, MassiveCoreMConf> cmdMassiveCoreConfig = new CommandEditSingleton<>(MassiveCoreMConf.get()).addRequirements(RequirementHasPerm.get(MassiveCorePerm.CONFIG));
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

View File

@ -997,13 +997,12 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
public void setupChildren()
{
for (MassiveCommand child : this.getChildren())
{
if (child.isSetupEnabled()) child.setup();
}
this.getChildren().stream()
.filter(MassiveCommand::isSetupEnabled)
.forEach(MassiveCommand::setup);
}
private Class<?> getClassOrEnclosing(Object object)
private static Class<?> getClassOrEnclosing(Object object)
{
Class<?> clazz = object.getClass();
Class<?> enclosingClass = clazz.getEnclosingClass();
@ -1031,16 +1030,13 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
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();
if (permClass == null) return null;
if (basePrefix == null) return null;
// 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;
// ... and remove the prefix ...
@ -1056,7 +1052,7 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
if (permName.isEmpty()) permName = "BASECOMMAND";
// Create ret
T ret = null;
Object ret = null;
// Try non-lenient
ret = getPerm(permName, false, permClass);
@ -1066,11 +1062,13 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
ret = getPerm(permName, true, permClass);
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);
for (T perm : TypeEnum.getEnumValues(permClass))
{

View File

@ -159,7 +159,9 @@ public class DriverFlatfile extends DriverAbstract
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)