Add a permission arg reader and the option to turn of the cmd arg tokenizer.
This commit is contained in:
parent
31f3964cb9
commit
480fcdc8b9
@ -1,6 +1,7 @@
|
|||||||
package com.massivecraft.mcore.cmd;
|
package com.massivecraft.mcore.cmd;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
@ -28,7 +29,16 @@ public class BukkitGlueCommand extends Command
|
|||||||
public boolean execute(CommandSender sender, String commandLabel, String[] args)
|
public boolean execute(CommandSender sender, String commandLabel, String[] args)
|
||||||
{
|
{
|
||||||
if ( ! plugin.isEnabled()) return false;
|
if ( ! plugin.isEnabled()) return false;
|
||||||
this.mcommand.execute(sender, Txt.tokenizeArguments(Txt.implode(args, " ")));
|
List<String> argList;
|
||||||
|
if (this.mcommand.isUsingTokenizer())
|
||||||
|
{
|
||||||
|
argList = Txt.tokenizeArguments(Txt.implode(args, " "));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
argList = new ArrayList<String>(Arrays.asList(args));
|
||||||
|
}
|
||||||
|
this.mcommand.execute(sender, argList);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,6 +70,12 @@ public abstract class MCommand
|
|||||||
public boolean getErrorOnToManyArgs() { return this.errorOnToManyArgs; }
|
public boolean getErrorOnToManyArgs() { return this.errorOnToManyArgs; }
|
||||||
public void setErrorOnToManyArgs(boolean val) { this.errorOnToManyArgs = val; }
|
public void setErrorOnToManyArgs(boolean val) { this.errorOnToManyArgs = val; }
|
||||||
|
|
||||||
|
// FIELD: usingTokenizer
|
||||||
|
// Should the arguments be parsed considering quotes and backslashes and such?
|
||||||
|
protected boolean usingTokenizer;
|
||||||
|
public boolean isUsingTokenizer() { return this.usingTokenizer; }
|
||||||
|
public void setUsingTokenizer(boolean usingTokenizer) { this.usingTokenizer = usingTokenizer; }
|
||||||
|
|
||||||
// FIELD: requirements
|
// FIELD: requirements
|
||||||
// All these requirements must be met for the command to be executable;
|
// All these requirements must be met for the command to be executable;
|
||||||
protected List<Req> requirements;
|
protected List<Req> requirements;
|
||||||
@ -214,6 +220,7 @@ public abstract class MCommand
|
|||||||
this.requirements = new ArrayList<Req>();
|
this.requirements = new ArrayList<Req>();
|
||||||
|
|
||||||
this.errorOnToManyArgs = true;
|
this.errorOnToManyArgs = true;
|
||||||
|
this.usingTokenizer = true;
|
||||||
|
|
||||||
this.desc = null;
|
this.desc = null;
|
||||||
|
|
||||||
|
40
src/com/massivecraft/mcore/cmd/arg/ARPermission.java
Normal file
40
src/com/massivecraft/mcore/cmd/arg/ARPermission.java
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
package com.massivecraft.mcore.cmd.arg;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.permissions.Permission;
|
||||||
|
|
||||||
|
public class ARPermission extends ArgReaderAbstract<Permission>
|
||||||
|
{
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// INSTANCE & CONSTRUCT
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
private static ARPermission i = new ARPermission();
|
||||||
|
public static ARPermission get() { return i; }
|
||||||
|
|
||||||
|
// -------------------------------------------- //
|
||||||
|
// OVERRIDE
|
||||||
|
// -------------------------------------------- //
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ArgResult<Permission> read(String arg, CommandSender sender)
|
||||||
|
{
|
||||||
|
ArgResult<Permission> ret = new ArgResult<Permission>();
|
||||||
|
|
||||||
|
for (Permission permission : Bukkit.getPluginManager().getPermissions())
|
||||||
|
{
|
||||||
|
if (!permission.getName().equals(arg)) continue;
|
||||||
|
ret.setResult(permission);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!ret.hasResult())
|
||||||
|
{
|
||||||
|
ret.setErrors("<b>No permission with the name \"<h>"+arg+"<b>\" was found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user