CTZServer/src/main/java/cn/citycraft/CTZServer/commands/BaseCommand.java

180 lines
3.5 KiB
Java
Raw Normal View History

2015-10-07 16:10:34 +00:00
package cn.citycraft.CTZServer.commands;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.bukkit.command.CommandException;
/**
*
*
* @author
* 201581212:49:34
*/
public abstract class BaseCommand {
private final String[] aliases;
private String description = "无";
private int minimumArguments = 0;
private final String name;
private boolean onlyPlayerExecutable = false;
private String permission;
private String possibleArguments = "";
public BaseCommand(final String name) {
this(name, new String[0]);
}
public BaseCommand(final String name, final String... aliases) {
this.name = name;
this.aliases = aliases;
}
/**
*
*
* @param sender
* -
* @param label
* -
* @param args
* -
* @throws CommandException
* -
*/
public abstract void execute(String label, String[] args);
public List<String> getCommandList() {
final List<String> cmds = new ArrayList<String>();
cmds.add(name);
cmds.addAll(Arrays.asList(aliases));
return cmds;
}
/**
*
*
* @return
*/
public String getDescription() {
return description;
}
/**
*
*
* @return
*/
public int getMinimumArguments() {
return minimumArguments;
}
/**
*
*
* @return
*/
public String getName() {
return name;
}
/**
*
*
* @return
*/
public String getPermission() {
return permission;
}
/**
*
*
* @return
*/
public String getPossibleArguments() {
return possibleArguments;
}
/**
*
*
* @return
*/
public boolean isOnlyPlayerExecutable() {
return onlyPlayerExecutable;
}
/**
*
*
* @param name
* -
* @return
*/
public final boolean isValidTrigger(final String name) {
if (this.name.equalsIgnoreCase(name)) {
return true;
}
if (aliases != null) {
for (final String alias : aliases) {
if (alias.equalsIgnoreCase(name)) {
return true;
}
}
}
return false;
}
/**
*
*
* @param description
* -
*/
public void setDescription(final String description) {
this.description = description;
}
/**
*
*
* @param minimumArguments
* -
*/
public void setMinimumArguments(final int minimumArguments) {
this.minimumArguments = minimumArguments;
}
/**
*
*
* @param onlyPlayerExecutable
* -
*/
public void setOnlyPlayerExecutable() {
this.onlyPlayerExecutable = true;
}
/**
*
*
* @param permission
* -
*/
public void setPermission(final String permission) {
this.permission = permission;
}
/**
*
*
* @param possibleArguments
* -
*/
public void setPossibleArguments(final String possibleArguments) {
this.possibleArguments = possibleArguments;
}
}