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; import com.massivecraft.massivecore.util.PermissionUtil;
public enum MassiveCorePerm public enum MassiveCorePerm implements Identified
{ {
// -------------------------------------------- // // -------------------------------------------- //
// ENUM // ENUM
@ -56,7 +56,8 @@ public enum MassiveCorePerm
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
public final String node; private final String id;
@Override public String getId() { return this.id; }
// -------------------------------------------- // // -------------------------------------------- //
// CONSTRUCT // CONSTRUCT
@ -64,7 +65,7 @@ public enum MassiveCorePerm
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) 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) 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 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() public boolean isParent()
{ {
@ -324,23 +325,12 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
// CHILDREN > ADD & REMOVE // 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) public <T extends MassiveCommand> T addChildAfter(MassiveCommand child, MassiveCommand after)
{
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)
{ {
int index = this.children.indexOf(after); int index = this.children.indexOf(after);
if (index == -1) if (index == -1)
@ -351,7 +341,7 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
{ {
index++; index++;
} }
this.addChild(child, index); return this.addChild(child, index);
} }
public int removeChild(MassiveCommand child) public int removeChild(MassiveCommand child)
@ -369,17 +359,33 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
return index; 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 // ALIASES
// -------------------------------------------- // // -------------------------------------------- //
public List<String> getAliases() { return this.aliases; } public List<String> getAliases() { return this.aliases; }
public void setAliases(Collection<String> aliases) { this.aliases = new MassiveList<String>(aliases); } @SuppressWarnings("unchecked")
public void setAliases(String... aliases) { this.setAliases(Arrays.asList(aliases)); } 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); } @SuppressWarnings("unchecked")
public void addAliases(String... aliases) { this.addAliases(Arrays.asList(aliases)); } 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 // PARAMETERS
@ -605,7 +611,6 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
return this.addParameter(new Parameter<T>(type)); return this.addParameter(new Parameter<T>(type));
} }
// -------------------------------------------- // // -------------------------------------------- //
// PREPROCESS // PREPROCESS
// -------------------------------------------- // // -------------------------------------------- //
@ -713,9 +718,12 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
// -------------------------------------------- // // -------------------------------------------- //
public List<Requirement> getRequirements() { return this.requirements; } public List<Requirement> getRequirements() { return this.requirements; }
public void setRequirements(List<Requirement> requirements) { this.requirements = requirements; } @SuppressWarnings("unchecked")
public void addRequirements(Collection<Requirement> requirements) { this.requirements.addAll(requirements); } public <T extends MassiveCommand> T setRequirements(List<Requirement> requirements) { this.requirements = requirements; return (T) this; }
public void addRequirements(Requirement... requirements) { this.addRequirements(Arrays.asList(requirements)); } @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) public boolean isRequirementsMet(CommandSender sender, boolean verboose)
{ {
@ -757,7 +765,7 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
for (Requirement requirement : this.getRequirements()) for (Requirement requirement : this.getRequirements())
{ {
if ( ! (requirement instanceof RequirementHasPerm)) continue; if ( ! (requirement instanceof RequirementHasPerm)) continue;
return ((RequirementHasPerm)requirement).getPerm(); return ((RequirementHasPerm)requirement).getPermissionId();
} }
return null; return null;
} }
@ -829,6 +837,9 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
args = this.applyPuzzler(args, sender); args = this.applyPuzzler(args, sender);
this.setArgs(args); this.setArgs(args);
// Requirements
if ( ! this.isRequirementsMet(sender, true)) return;
// Child Execution // Child Execution
if (this.isParent() && args.size() > 0) if (this.isParent() && args.size() > 0)
{ {
@ -883,11 +894,11 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
return; return;
} }
// Self Execution (Perform) // Self Execution > Arguments Valid
if (this.isValidCall(this.sender, this.getArgs())) if ( ! this.isArgsValid(this.getArgs(), this.sender)) return;
{
this.perform(); // Self Execution > Perform
} this.perform();
} }
catch (MassiveException ex) catch (MassiveException ex)
{ {
@ -944,24 +955,6 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
// CALL VALIDATION // 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) public boolean isArgsValid(List<String> args, CommandSender sender)
{ {
if (args.size() < this.getParameterCountRequired(sender)) if (args.size() < this.getParameterCountRequired(sender))
@ -990,6 +983,7 @@ public class MassiveCommand implements Active, PluginIdentifiableCommand
} }
return true; return true;
} }
public boolean isArgsValid(List<String> args) public boolean isArgsValid(List<String> args)
{ {
return this.isArgsValid(args, null); return this.isArgsValid(args, null);

View File

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

View File

@ -1,6 +1,5 @@
package com.massivecraft.massivecore.command.editor; package com.massivecraft.massivecore.command.editor;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.command.type.Type; import com.massivecraft.massivecore.command.type.Type;
public class CommandEditProperties<O, V> extends CommandEditAbstract<O, V> public class CommandEditProperties<O, V> extends CommandEditAbstract<O, V>
@ -9,7 +8,7 @@ public class CommandEditProperties<O, V> extends CommandEditAbstract<O, V>
// CONSTRUCT // CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public CommandEditProperties(EditSettings<O> settings, Property<O, V> property, String permission) public CommandEditProperties(EditSettings<O> settings, Property<O, V> property)
{ {
// Super // Super
super(settings, property, null); super(settings, property, null);
@ -26,8 +25,6 @@ public class CommandEditProperties<O, V> extends CommandEditAbstract<O, V>
this.addChild(prop.createEditCommand(fieldSettings)); 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 // 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); String name = typeObject.getName(object);
this.setAliases(name); this.setAliases(name);
this.setDesc("edit " + name); this.setDesc("edit " + name);

View File

@ -31,10 +31,10 @@ public class CmdMassiveCore extends MassiveCommand
public CmdMassiveCoreHearsound cmdMassiveCoreHearsound = new CmdMassiveCoreHearsound(); public CmdMassiveCoreHearsound cmdMassiveCoreHearsound = new CmdMassiveCoreHearsound();
public CmdMassiveCoreBuffer cmdMassiveCoreBuffer = new CmdMassiveCoreBuffer(); public CmdMassiveCoreBuffer cmdMassiveCoreBuffer = new CmdMassiveCoreBuffer();
public CmdMassiveCoreCmdurl cmdMassiveCoreCmdurl = new CmdMassiveCoreCmdurl(); 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 CmdMassiveCoreSponsor cmdMassiveCoreSponsor = new CmdMassiveCoreSponsor();
public CmdMassiveCoreClick cmdMassiveCoreClick = new CmdMassiveCoreClick(); 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 // CONSTRUCT
@ -56,7 +56,7 @@ public class CmdMassiveCore extends MassiveCommand
this.addChild(this.cmdMassiveCoreVersion); this.addChild(this.cmdMassiveCoreVersion);
// Requirements // 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"); this.addAliases("buffer");
// Requirements // 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"); this.addParameter(TypeString.get(), "text", true).setDesc("the text to add to your buffer");
// Requirements // 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"); this.addAliases("clear");
// Requirements // 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"); this.addAliases("print");
// Requirements // 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"); this.addParameter(TypeString.get(), "text", true).setDesc("the text to set your buffer to");
// Requirements // 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"); this.addParameter(1, TypeInteger.get(), "times").setDesc("the amount of whitespace to add to your buffer");
// Requirements // 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"); this.addParameter(null, TypeStringCommand.get(), "command", "none", true).setDesc("the command to perform");
// Requirements // 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"); this.addParameter(TypeString.get(), "url").setDesc("the url to load");
// Requirements // Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.CMDURL.node)); this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.CMDURL));
this.addRequirements(RequirementIsPlayer.get()); 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"); this.addParameter(TypeList.get(TypeSoundEffect.get()), "sound(s)", true).setDesc("the sounds to hear");
// Requirements // Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.HEARSOUND.node)); this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.HEARSOUND));
this.addRequirements(RequirementIsPlayer.get()); this.addRequirements(RequirementIsPlayer.get());
} }

View File

@ -17,7 +17,7 @@ public class CmdMassiveCoreId extends MassiveCommand
this.addAliases("id"); this.addAliases("id");
// Requirements // 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"); this.addAliases("sponsor");
// Requirements // 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"); this.addAliases("store");
// Requirements // 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"); this.addParameter(TypeString.get(), "to").setDesc("the database to copy to");
// Requirements // 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"); this.addParameter(TypeString.get(), "db", ConfServer.dburi).setDesc("the database to list colls from");
// Requirements // 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"); this.addParameter(TypeColl.get(), "coll", Coll.TOTAL).setDesc("the coll to show info about");
// Requirements // 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"); this.addParameter(false, TypeBoolean.getYes(), "set", "no");
// Requirements // Requirements
this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.TEST.node)); this.addRequirements(RequirementHasPerm.get(MassiveCorePerm.TEST));
this.addRequirements(RequirementIsPlayer.get()); this.addRequirements(RequirementIsPlayer.get());
// VisibilityMode // VisibilityMode

View File

@ -41,7 +41,7 @@ public class CmdMassiveCoreUsys extends MassiveCommand
this.addAliases("usys"); this.addAliases("usys");
// Requirements // 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"); this.addAliases("aspect");
// Requirements // 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"); this.addParameter(Parameter.getPage()).setDesc("the page in the aspect list");
// Requirements // 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"); this.addParameter(TypeAspect.get(), "aspect").setDesc("the aspect to show info about");
// Requirements // 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"); this.addParameter(TypeMultiverse.get(), "multiverse").setDesc("the multiverse which the aspect should use");
// Requirements // 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"); this.addAliases("multiverse");
// Requirements // 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"); this.addParameter(TypeMultiverse.get(), "multiverse").setDesc("the multiverse to delete");
// Requirements // 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()); this.addParameter(Parameter.getPage());
// Requirements // 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"); this.addParameter(TypeString.get(), "multiverse").setDesc("name of multiverse to create");
// Requirements // 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"); this.addParameter(TypeMultiverse.get(), "multiverse").setDesc("the multiverse to show info about");
// Requirements // 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"); this.addAliases("universe");
// Requirements // 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"); this.addParameter(TypeMultiverse.get(), "multiverse").setDesc("the multiverse of the universe to clear");
// Requirements // 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"); this.addParameter(TypeMultiverse.get(), "multiverse").setDesc("the multiverse of the universe to delete");
// Requirements // 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"); this.addParameter(TypeMultiverse.get(), "multiverse").setDesc("the multiverse of the universe to create");
// Requirements // 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"); this.addParameter(TypeMultiverse.get(), "multiverse").setDesc("the multiverse of the universe to move the world to");
// Requirements // 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 org.bukkit.command.CommandSender;
import com.massivecraft.massivecore.Identified;
import com.massivecraft.massivecore.command.MassiveCommand; import com.massivecraft.massivecore.command.MassiveCommand;
import com.massivecraft.massivecore.util.PermissionUtil; import com.massivecraft.massivecore.util.PermissionUtil;
@ -13,15 +14,29 @@ public class RequirementHasPerm extends RequirementAbstract
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
// -------------------------------------------- // // -------------------------------------------- //
public static RequirementHasPerm get(String perm) { return new RequirementHasPerm(perm); } public static RequirementHasPerm get(String permissionId) { return new RequirementHasPerm(permissionId); }
public RequirementHasPerm(String perm) { this.perm = perm; } 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 // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
private final String perm; private final String permissionId;
public String getPerm() { return this.perm; } public String getPermissionId() { return this.permissionId; }
// -------------------------------------------- // // -------------------------------------------- //
// OVERRIDE // OVERRIDE
@ -30,13 +45,13 @@ public class RequirementHasPerm extends RequirementAbstract
@Override @Override
public boolean apply(CommandSender sender, MassiveCommand command) public boolean apply(CommandSender sender, MassiveCommand command)
{ {
return sender.hasPermission(this.perm); return sender.hasPermission(this.permissionId);
} }
@Override @Override
public String createErrorMessage(CommandSender sender, MassiveCommand command) 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()) if (this.hasInnerProperties())
{ {
return new CommandEditProperties<O, T>(settings, property, null); return new CommandEditProperties<O, T>(settings, property);
} }
else else
{ {

View File

@ -69,22 +69,22 @@ public abstract class SenderEntity<E extends SenderEntity<E>> extends Entity<E>
// -------------------------------------------- // // -------------------------------------------- //
// GENERIC // GENERIC
public <T> T convertGet(T value, T defaultValue, String permission) public <T> T convertGet(T value, T defaultValue, String permissionId)
{ {
// Create // Create
T ret = super.convertGet(value, defaultValue); T ret = super.convertGet(value, defaultValue);
// Permission Requirement // 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
return ret; return ret;
} }
// BOOLEAN // 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; return ret;
} }
public static String createPermissionId(Plugin plugin, Enum<?> e)
{
return plugin.getName().toLowerCase() + "." + e.name().toLowerCase().replace('_', '.');
}
// -------------------------------------------- // // -------------------------------------------- //
// ENSURE HAS // 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. // 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 (event == null) throw new NullPointerException("event");
if (title == null) throw new NullPointerException("title"); 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 ... // If a player is changing a sign ...
final Player player = event.getPlayer(); final Player player = event.getPlayer();
@ -126,7 +126,7 @@ public class SignUtil
if ( ! title.equalsIgnoreCase(lenientTitle)) return false; if ( ! title.equalsIgnoreCase(lenientTitle)) return false;
// ... verify that the player has permission to create that type of sign ... // ... 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); event.setCancelled(true);
return false; return false;