MassiveCore - Permission System Improvements

This commit is contained in:
Olof Larsson 2016-05-26 10:18:16 +02:00
parent 47717ff70b
commit 5c26c3a503
No known key found for this signature in database
GPG Key ID: BBEF14F97DA52474
42 changed files with 123 additions and 123 deletions

View File

@ -4,7 +4,7 @@ import org.bukkit.permissions.Permissible;
import com.massivecraft.massivecore.util.PermissionUtil;
public enum MassiveCorePerm
public enum MassiveCorePerm implements Identified
{
// -------------------------------------------- //
// ENUM
@ -56,7 +56,8 @@ public enum MassiveCorePerm
// FIELDS
// -------------------------------------------- //
public final String node;
private final String id;
@Override public String getId() { return this.id; }
// -------------------------------------------- //
// CONSTRUCT
@ -64,7 +65,7 @@ public enum MassiveCorePerm
MassiveCorePerm()
{
this.node = "massivecore." + this.name().toLowerCase().replace('_', '.');
this.id = PermissionUtil.createPermissionId(MassiveCore.get(), this);
}
// -------------------------------------------- //
@ -73,7 +74,7 @@ public enum MassiveCorePerm
public boolean has(Permissible permissible, boolean informSenderIfNot)
{
return PermissionUtil.hasPermission(permissible, this.node, informSenderIfNot);
return PermissionUtil.hasPermission(permissible, this.id, informSenderIfNot);
}
public boolean has(Permissible permissible)

View File

@ -195,7 +195,8 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
// -------------------------------------------- //
public List<MassiveCommand> getChildren() { return this.children; }
public void setChildren(List<MassiveCommand> children) { this.children = children; }
@SuppressWarnings("unchecked")
public <T extends MassiveCommand> T setChildren(List<MassiveCommand> children) { this.children = children; return (T) this; }
public boolean isParent()
{
@ -324,23 +325,12 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
// CHILDREN > ADD & REMOVE
// -------------------------------------------- //
public void addChild(MassiveCommand child)
public <T extends MassiveCommand> T addChild(MassiveCommand child)
{
this.addChild(child, this.children.size());
return this.addChild(child, this.children.size());
}
public void addChild(MassiveCommand child, int index)
{
if (this.children.isEmpty() && ! (child instanceof MassiveCommandHelp))
{
this.children.add(0, new MassiveCommandHelp());
index++;
}
child.addToChain(this);
this.children.add(index, child);
}
public void addChildAfter(MassiveCommand child, MassiveCommand after)
public <T extends MassiveCommand> T addChildAfter(MassiveCommand child, MassiveCommand after)
{
int index = this.children.indexOf(after);
if (index == -1)
@ -351,7 +341,7 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
{
index++;
}
this.addChild(child, index);
return this.addChild(child, index);
}
public int removeChild(MassiveCommand child)
@ -369,17 +359,33 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
return index;
}
@SuppressWarnings("unchecked")
public <T extends MassiveCommand> T addChild(MassiveCommand child, int index)
{
if (this.children.isEmpty() && ! (child instanceof MassiveCommandHelp))
{
this.children.add(0, new MassiveCommandHelp());
index++;
}
child.addToChain(this);
this.children.add(index, child);
return (T) this;
}
// -------------------------------------------- //
// ALIASES
// -------------------------------------------- //
public List<String> getAliases() { return this.aliases; }
public void setAliases(Collection<String> aliases) { this.aliases = new MassiveList<String>(aliases); }
public void setAliases(String... aliases) { this.setAliases(Arrays.asList(aliases)); }
@SuppressWarnings("unchecked")
public <T extends MassiveCommand> T setAliases(Collection<String> aliases) { this.aliases = new MassiveList<String>(aliases); return (T) this; }
public <T extends MassiveCommand> T setAliases(String... aliases) { return this.setAliases(Arrays.asList(aliases)); }
public void addAliases(Collection<String> aliases) { this.aliases.addAll(aliases); }
public void addAliases(String... aliases) { this.addAliases(Arrays.asList(aliases)); }
@SuppressWarnings("unchecked")
public <T extends MassiveCommand> T addAliases(Collection<String> aliases) { this.aliases.addAll(aliases); return (T) this; }
public <T extends MassiveCommand> T addAliases(String... aliases) { return this.addAliases(Arrays.asList(aliases)); }
// -------------------------------------------- //
// PARAMETERS
@ -605,7 +611,6 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
return this.addParameter(new Parameter<T>(type));
}
// -------------------------------------------- //
// PREPROCESS
// -------------------------------------------- //
@ -713,9 +718,12 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
// -------------------------------------------- //
public List<Requirement> getRequirements() { return this.requirements; }
public void setRequirements(List<Requirement> requirements) { this.requirements = requirements; }
public void addRequirements(Collection<Requirement> requirements) { this.requirements.addAll(requirements); }
public void addRequirements(Requirement... requirements) { this.addRequirements(Arrays.asList(requirements)); }
@SuppressWarnings("unchecked")
public <T extends MassiveCommand> T setRequirements(List<Requirement> requirements) { this.requirements = requirements; return (T) this; }
@SuppressWarnings("unchecked")
public <T extends MassiveCommand> T addRequirements(Collection<Requirement> requirements) { this.requirements.addAll(requirements); return (T) this; }
@SuppressWarnings("unchecked")
public <T extends MassiveCommand> T addRequirements(Requirement... requirements) { this.addRequirements(Arrays.asList(requirements)); return (T) this; }
public boolean isRequirementsMet(CommandSender sender, boolean verboose)
{
@ -757,7 +765,7 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
for (Requirement requirement : this.getRequirements())
{
if ( ! (requirement instanceof RequirementHasPerm)) continue;
return ((RequirementHasPerm)requirement).getPerm();
return ((RequirementHasPerm)requirement).getPermissionId();
}
return null;
}
@ -829,6 +837,9 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
args = this.applyPuzzler(args, sender);
this.setArgs(args);
// Requirements
if ( ! this.isRequirementsMet(sender, true)) return;
// Child Execution
if (this.isParent() && args.size() > 0)
{
@ -883,12 +894,12 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
return;
}
// Self Execution (Perform)
if (this.isValidCall(this.sender, this.getArgs()))
{
// Self Execution > Arguments Valid
if ( ! this.isArgsValid(this.getArgs(), this.sender)) return;
// Self Execution > Perform
this.perform();
}
}
catch (MassiveException ex)
{
// Sometimes Types (or commands themselves) throw exceptions, to stop executing and notify the user.
@ -944,24 +955,6 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
// CALL VALIDATION
// -------------------------------------------- //
/**
* In this method we validate that all prerequisites to perform this command has been met.
*/
public boolean isValidCall(CommandSender sender, List<String> args)
{
if ( ! this.isRequirementsMet(sender, true))
{
return false;
}
if ( ! this.isArgsValid(args, sender))
{
return false;
}
return true;
}
public boolean isArgsValid(List<String> args, CommandSender sender)
{
if (args.size() < this.getParameterCountRequired(sender))
@ -990,6 +983,7 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
}
return true;
}
public boolean isArgsValid(List<String> args)
{
return this.isArgsValid(args, null);

View File

@ -1,13 +1,10 @@
package com.massivecraft.massivecore.command;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.util.Txt;
public class MassiveCommandVersion extends MassiveCommand
@ -29,22 +26,13 @@ public class MassiveCommandVersion extends MassiveCommand
// CONSTRUCT
// -------------------------------------------- //
public MassiveCommandVersion(Plugin plugin, String permissionName, String... aliases)
{
this(plugin, permissionName, Arrays.asList(aliases));
}
public MassiveCommandVersion(Plugin plugin, String permissionName, Collection<String> aliases)
public MassiveCommandVersion(Plugin plugin)
{
this.plugin = plugin;
if (permissionName != null)
{
this.addRequirements(RequirementHasPerm.get(permissionName));
}
this.setDesc("display plugin version");
this.setAliases("version");
this.addAliases(aliases);
this.setDesc("display plugin version");
}
// -------------------------------------------- //

View File

@ -1,6 +1,5 @@
package com.massivecraft.massivecore.command.editor;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.command.type.Type;
public class CommandEditProperties<O, V> extends CommandEditAbstract<O, V>
@ -9,7 +8,7 @@ public class CommandEditProperties<O, V> extends CommandEditAbstract<O, V>
// CONSTRUCT
// -------------------------------------------- //
public CommandEditProperties(EditSettings<O> settings, Property<O, V> property, String permission)
public CommandEditProperties(EditSettings<O> settings, Property<O, V> property)
{
// Super
super(settings, property, null);
@ -26,8 +25,6 @@ public class CommandEditProperties<O, V> extends CommandEditAbstract<O, V>
this.addChild(prop.createEditCommand(fieldSettings));
}
}
if (permission != null) this.addRequirements(RequirementHasPerm.get(permission));
}
}

View File

@ -10,14 +10,14 @@ public class CommandEditSingleton<O> extends CommandEditProperties<O, O>
// CONSTRUCT
// -------------------------------------------- //
public CommandEditSingleton(O object, String permission)
public CommandEditSingleton(O object)
{
this(object, getType(object), permission);
this(object, getType(object));
}
public CommandEditSingleton(O object, Type<O> typeObject, String permission)
public CommandEditSingleton(O object, Type<O> typeObject)
{
super(createEditSettings(object, typeObject), new PropertyThis<>(typeObject), permission);
super(createEditSettings(object, typeObject), new PropertyThis<>(typeObject));
String name = typeObject.getName(object);
this.setAliases(name);
this.setDesc("edit " + name);

View File

@ -31,10 +31,10 @@ public class CmdMassiveCore extends MassiveCommand
public CmdMassiveCoreHearsound cmdMassiveCoreHearsound = new CmdMassiveCoreHearsound();
public CmdMassiveCoreBuffer cmdMassiveCoreBuffer = new CmdMassiveCoreBuffer();
public CmdMassiveCoreCmdurl cmdMassiveCoreCmdurl = new CmdMassiveCoreCmdurl();
public CommandEditAbstract<MassiveCoreMConf, MassiveCoreMConf> cmdMassiveCoreConfig = new CommandEditSingleton<>(MassiveCoreMConf.get(), MassiveCorePerm.CONFIG.node);
public CommandEditAbstract<MassiveCoreMConf, MassiveCoreMConf> cmdMassiveCoreConfig = new CommandEditSingleton<>(MassiveCoreMConf.get()).addRequirements(RequirementHasPerm.get(MassiveCorePerm.CONFIG));
public CmdMassiveCoreSponsor cmdMassiveCoreSponsor = new CmdMassiveCoreSponsor();
public CmdMassiveCoreClick cmdMassiveCoreClick = new CmdMassiveCoreClick();
public MassiveCommandVersion cmdMassiveCoreVersion = new MassiveCommandVersion(MassiveCore.get(), MassiveCorePerm.VERSION.node, "v", "version");
public MassiveCommandVersion cmdMassiveCoreVersion = new MassiveCommandVersion(MassiveCore.get()).setAliases("v", "version").addRequirements(RequirementHasPerm.get(MassiveCorePerm.VERSION));
// -------------------------------------------- //
// CONSTRUCT
@ -56,7 +56,7 @@ public class CmdMassiveCore extends MassiveCommand
this.addChild(this.cmdMassiveCoreVersion);
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.BASECOMMAND.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.BASECOMMAND));
}
// -------------------------------------------- //

View File

@ -43,7 +43,7 @@ public class CmdMassiveCoreBuffer extends MassiveCommand
this.addAliases("buffer");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.BUFFER.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.BUFFER));
}
}

View File

@ -22,7 +22,7 @@ public class CmdMassiveCoreBufferAdd extends MassiveCommand
this.addParameter(TypeString.get(), "text", true).setDesc("the text to add to your buffer");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.BUFFER_ADD.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.BUFFER_ADD));
}
// -------------------------------------------- //

View File

@ -17,7 +17,7 @@ public class CmdMassiveCoreBufferClear extends MassiveCommand
this.addAliases("clear");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.BUFFER_CLEAR.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.BUFFER_CLEAR));
}
// -------------------------------------------- //

View File

@ -17,7 +17,7 @@ public class CmdMassiveCoreBufferPrint extends MassiveCommand
this.addAliases("print");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.BUFFER_PRINT.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.BUFFER_PRINT));
}
// -------------------------------------------- //

View File

@ -22,7 +22,7 @@ public class CmdMassiveCoreBufferSet extends MassiveCommand
this.addParameter(TypeString.get(), "text", true).setDesc("the text to set your buffer to");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.BUFFER_SET.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.BUFFER_SET));
}
// -------------------------------------------- //

View File

@ -23,7 +23,7 @@ public class CmdMassiveCoreBufferWhitespace extends MassiveCommand
this.addParameter(1, TypeInteger.get(), "times").setDesc("the amount of whitespace to add to your buffer");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.BUFFER_WHITESPACE.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.BUFFER_WHITESPACE));
}
// -------------------------------------------- //

View File

@ -30,7 +30,7 @@ public class CmdMassiveCoreClick extends MassiveCommand
this.addParameter(null, TypeStringCommand.get(), "command", "none", true).setDesc("the command to perform");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.CLICK.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.CLICK));
}
// -------------------------------------------- //

View File

@ -40,7 +40,7 @@ public class CmdMassiveCoreCmdurl extends MassiveCommand
this.addParameter(TypeString.get(), "url").setDesc("the url to load");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.CMDURL.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.CMDURL));
this.addRequirements(RequirementIsPlayer.get());
}

View File

@ -26,7 +26,7 @@ public class CmdMassiveCoreHearsound extends MassiveCommand
this.addParameter(TypeList.get(TypeSoundEffect.get()), "sound(s)", true).setDesc("the sounds to hear");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.HEARSOUND.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.HEARSOUND));
this.addRequirements(RequirementIsPlayer.get());
}

View File

@ -17,7 +17,7 @@ public class CmdMassiveCoreId extends MassiveCommand
this.addAliases("id");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.ID.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.ID));
}
// -------------------------------------------- //

View File

@ -24,7 +24,7 @@ public class CmdMassiveCoreSponsor extends MassiveCommandToggle
this.addAliases("sponsor");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.SPONSOR.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.SPONSOR));
}
// -------------------------------------------- //

View File

@ -39,7 +39,7 @@ public class CmdMassiveCoreStore extends MassiveCommand
this.addAliases("store");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.STORE.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.STORE));
}
}

View File

@ -32,7 +32,7 @@ public class CmdMassiveCoreStoreCopydb extends MassiveCommand
this.addParameter(TypeString.get(), "to").setDesc("the database to copy to");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.STORE_COPYDB.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.STORE_COPYDB));
}
// -------------------------------------------- //

View File

@ -30,7 +30,7 @@ public class CmdMassiveCoreStoreListcolls extends MassiveCommand
this.addParameter(TypeString.get(), "db", ConfServer.dburi).setDesc("the database to list colls from");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.STORE_LISTCOLLS.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.STORE_LISTCOLLS));
}
// -------------------------------------------- //

View File

@ -26,7 +26,7 @@ public class CmdMassiveCoreStoreStats extends MassiveCommand
this.addParameter(TypeColl.get(), "coll", Coll.TOTAL).setDesc("the coll to show info about");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.STORE_STATS.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.STORE_STATS));
}
// -------------------------------------------- //

View File

@ -33,7 +33,7 @@ public class CmdMassiveCoreTest extends MassiveCommand
this.addParameter(false, TypeBoolean.getYes(), "set", "no");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.TEST.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.TEST));
this.addRequirements(RequirementIsPlayer.get());
// VisibilityMode

View File

@ -41,7 +41,7 @@ public class CmdMassiveCoreUsys extends MassiveCommand
this.addAliases("usys");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS));
}
}

View File

@ -29,7 +29,7 @@ public class CmdMassiveCoreUsysAspect extends MassiveCommand
this.addAliases("aspect");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_ASPECT.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_ASPECT));
}
}

View File

@ -26,7 +26,7 @@ public class CmdMassiveCoreUsysAspectList extends MassiveCommand
this.addParameter(Parameter.getPage()).setDesc("the page in the aspect list");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_ASPECT_LIST.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_ASPECT_LIST));
}
// -------------------------------------------- //

View File

@ -23,7 +23,7 @@ public class CmdMassiveCoreUsysAspectShow extends MassiveCommand
this.addParameter(TypeAspect.get(), "aspect").setDesc("the aspect to show info about");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_ASPECT_SHOW.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_ASPECT_SHOW));
}
// -------------------------------------------- //

View File

@ -25,7 +25,7 @@ public class CmdMassiveCoreUsysAspectUse extends MassiveCommand
this.addParameter(TypeMultiverse.get(), "multiverse").setDesc("the multiverse which the aspect should use");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_ASPECT_USE.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_ASPECT_USE));
}
// -------------------------------------------- //

View File

@ -31,7 +31,7 @@ public class CmdMassiveCoreUsysMultiverse extends MassiveCommand
this.addAliases("multiverse");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_MULTIVERSE.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_MULTIVERSE));
}
}

View File

@ -23,7 +23,7 @@ public class CmdMassiveCoreUsysMultiverseDel extends MassiveCommand
this.addParameter(TypeMultiverse.get(), "multiverse").setDesc("the multiverse to delete");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_MULTIVERSE_DEL.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_MULTIVERSE_DEL));
}
// -------------------------------------------- //

View File

@ -26,7 +26,7 @@ public class CmdMassiveCoreUsysMultiverseList extends MassiveCommand
this.addParameter(Parameter.getPage());
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_MULTIVERSE_LIST.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_MULTIVERSE_LIST));
}
// -------------------------------------------- //

View File

@ -22,7 +22,7 @@ public class CmdMassiveCoreUsysMultiverseNew extends MassiveCommand
this.addParameter(TypeString.get(), "multiverse").setDesc("name of multiverse to create");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_MULTIVERSE_NEW.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_MULTIVERSE_NEW));
}
// -------------------------------------------- //

View File

@ -28,7 +28,7 @@ public class CmdMassiveCoreUsysMultiverseShow extends MassiveCommand
this.addParameter(TypeMultiverse.get(), "multiverse").setDesc("the multiverse to show info about");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_MULTIVERSE_SHOW.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_MULTIVERSE_SHOW));
}
// -------------------------------------------- //

View File

@ -29,7 +29,7 @@ public class CmdMassiveCoreUsysUniverse extends MassiveCommand
this.addAliases("universe");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_UNIVERSE.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_UNIVERSE));
}
}

View File

@ -25,7 +25,7 @@ public class CmdMassiveCoreUsysUniverseClear extends MassiveCommand
this.addParameter(TypeMultiverse.get(), "multiverse").setDesc("the multiverse of the universe to clear");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_UNIVERSE_CLEAR.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_UNIVERSE_CLEAR));
}
// -------------------------------------------- //

View File

@ -25,7 +25,7 @@ public class CmdMassiveCoreUsysUniverseDel extends MassiveCommand
this.addParameter(TypeMultiverse.get(), "multiverse").setDesc("the multiverse of the universe to delete");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_MULTIVERSE_DEL.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_MULTIVERSE_DEL));
}
// -------------------------------------------- //

View File

@ -24,7 +24,7 @@ public class CmdMassiveCoreUsysUniverseNew extends MassiveCommand
this.addParameter(TypeMultiverse.get(), "multiverse").setDesc("the multiverse of the universe to create");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_UNIVERSE_NEW.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_UNIVERSE_NEW));
}
// -------------------------------------------- //

View File

@ -25,7 +25,7 @@ public class CmdMassiveCoreUsysWorld extends MassiveCommand
this.addParameter(TypeMultiverse.get(), "multiverse").setDesc("the multiverse of the universe to move the world to");
// Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_WORLD.node));
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.USYS_WORLD));
}
// -------------------------------------------- //

View File

@ -2,6 +2,7 @@ package com.massivecraft.massivecore.command.requirement;
import org.bukkit.command.CommandSender;
import com.massivecraft.massivecore.Identified;
import com.massivecraft.massivecore.command.MassiveCommand;
import com.massivecraft.massivecore.util.PermissionUtil;
@ -13,15 +14,29 @@ public class RequirementHasPerm extends RequirementAbstract
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
public static RequirementHasPerm get(String perm) { return new RequirementHasPerm(perm); }
public RequirementHasPerm(String perm) { this.perm = perm; }
public static RequirementHasPerm get(String permissionId) { return new RequirementHasPerm(permissionId); }
public static RequirementHasPerm get(Identified identified) { return new RequirementHasPerm(identified); }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public RequirementHasPerm(String permissionId)
{
this.permissionId = permissionId;
}
public RequirementHasPerm(Identified identified)
{
this(identified.getId());
}
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private final String perm;
public String getPerm() { return this.perm; }
private final String permissionId;
public String getPermissionId() { return this.permissionId; }
// -------------------------------------------- //
// OVERRIDE
@ -30,13 +45,13 @@ public class RequirementHasPerm extends RequirementAbstract
@Override
public boolean apply(CommandSender sender, MassiveCommand command)
{
return sender.hasPermission(this.perm);
return sender.hasPermission(this.permissionId);
}
@Override
public String createErrorMessage(CommandSender sender, MassiveCommand command)
{
return PermissionUtil.getPermissionDeniedMessage(this.perm);
return PermissionUtil.getPermissionDeniedMessage(this.permissionId);
}
}

View File

@ -654,7 +654,7 @@ public abstract class TypeAbstract<T> implements Type<T>
{
if (this.hasInnerProperties())
{
return new CommandEditProperties<O, T>(settings, property, null);
return new CommandEditProperties<O, T>(settings, property);
}
else
{

View File

@ -69,22 +69,22 @@ public abstract class SenderEntity<E extends SenderEntity<E>> extends Entity<E>
// -------------------------------------------- //
// GENERIC
public <T> T convertGet(T value, T defaultValue, String permission)
public <T> T convertGet(T value, T defaultValue, String permissionId)
{
// Create
T ret = super.convertGet(value, defaultValue);
// Permission Requirement
if ( ! Objects.equal(value, defaultValue) && ! PermissionUtil.hasPermission(this.getSender(), permission)) return defaultValue;
if ( ! Objects.equal(value, defaultValue) && ! PermissionUtil.hasPermission(this.getSender(), permissionId)) return defaultValue;
// Return
return ret;
}
// BOOLEAN
public boolean convertGet(Boolean value, String permission)
public boolean convertGet(Boolean value, String permissionId)
{
return this.convertGet(value, false, permission);
return this.convertGet(value, false, permissionId);
}
// -------------------------------------------- //

View File

@ -41,6 +41,11 @@ public class PermissionUtil
return ret;
}
public static String createPermissionId(Plugin plugin, Enum<?> e)
{
return plugin.getName().toLowerCase() + "." + e.name().toLowerCase().replace('_', '.');
}
// -------------------------------------------- //
// ENSURE HAS
// -------------------------------------------- //

View File

@ -109,11 +109,11 @@ public class SignUtil
// -------------------------------------------- //
// Returns true if the result is a special sign of with the specified title.
public static boolean handleSpecialPermissionFix(SignChangeEvent event, String title, String permissionNode)
public static boolean handleSpecialPermissionFix(SignChangeEvent event, String title, String permissionId)
{
if (event == null) throw new NullPointerException("event");
if (title == null) throw new NullPointerException("title");
if (permissionNode == null) throw new NullPointerException("permissionNode");
if (permissionId == null) throw new NullPointerException("permissionId");
// If a player is changing a sign ...
final Player player = event.getPlayer();
@ -126,7 +126,7 @@ public class SignUtil
if ( ! title.equalsIgnoreCase(lenientTitle)) return false;
// ... verify that the player has permission to create that type of sign ...
if ( ! PermissionUtil.hasPermission(player, permissionNode, true))
if ( ! PermissionUtil.hasPermission(player, permissionId, true))
{
event.setCancelled(true);
return false;