mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-29 20:24:43 +02:00
cleanup
This commit is contained in:
@ -9,7 +9,8 @@ import java.util.Set;
|
||||
import com.intellectualcrafters.plot.commands.CommandCategory;
|
||||
import com.intellectualcrafters.plot.commands.RequiredType;
|
||||
|
||||
public abstract class Command<E extends CommandCaller> extends CommandManager {
|
||||
public abstract class Command<E extends CommandCaller> extends CommandManager
|
||||
{
|
||||
|
||||
private RequiredType requiredType = RequiredType.NONE;
|
||||
private String command, usage = "", description = "", permission = "";
|
||||
@ -17,29 +18,34 @@ public abstract class Command<E extends CommandCaller> extends CommandManager {
|
||||
private CommandCategory category;
|
||||
protected Argument<?>[] requiredArguments;
|
||||
|
||||
public Command() {
|
||||
public Command()
|
||||
{
|
||||
super(null, new ArrayList<Command>());
|
||||
}
|
||||
|
||||
public Command(String command) {
|
||||
public Command(final String command)
|
||||
{
|
||||
super(null, new ArrayList<Command>());
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
public Command(String command, String usage) {
|
||||
public Command(final String command, final String usage)
|
||||
{
|
||||
super(null, new ArrayList<Command>());
|
||||
this.command = command;
|
||||
this.usage = usage;
|
||||
}
|
||||
|
||||
public Command(String command, String usage, String description) {
|
||||
public Command(final String command, final String usage, final String description)
|
||||
{
|
||||
super(null, new ArrayList<Command>());
|
||||
this.command = command;
|
||||
this.usage = usage;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public Command(String command, String usage, String description, String permission) {
|
||||
public Command(final String command, final String usage, final String description, final String permission)
|
||||
{
|
||||
super(null, new ArrayList<Command>());
|
||||
this.command = command;
|
||||
this.usage = usage;
|
||||
@ -47,20 +53,23 @@ public abstract class Command<E extends CommandCaller> extends CommandManager {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public Command(String command, String[] aliases, String usage) {
|
||||
public Command(final String command, final String[] aliases, final String usage)
|
||||
{
|
||||
super(null, new ArrayList<Command>());
|
||||
this.command = command;
|
||||
this.aliases = new HashSet<>(Arrays.asList(aliases));
|
||||
this.usage = usage;
|
||||
}
|
||||
|
||||
public Command(String command, String[] aliases) {
|
||||
public Command(final String command, final String[] aliases)
|
||||
{
|
||||
super(null, new ArrayList<Command>());
|
||||
this.command = command;
|
||||
this.aliases = new HashSet<>(Arrays.asList(aliases));
|
||||
}
|
||||
|
||||
public Command(String command, String usage, String description, String permission, String[] aliases, RequiredType requiredType) {
|
||||
public Command(final String command, final String usage, final String description, final String permission, final String[] aliases, final RequiredType requiredType)
|
||||
{
|
||||
super(null, new ArrayList<Command>());
|
||||
this.command = command;
|
||||
this.usage = usage;
|
||||
@ -70,16 +79,16 @@ public abstract class Command<E extends CommandCaller> extends CommandManager {
|
||||
this.requiredType = requiredType;
|
||||
}
|
||||
|
||||
final public RequiredType getRequiredType() {
|
||||
final public RequiredType getRequiredType()
|
||||
{
|
||||
return this.requiredType;
|
||||
}
|
||||
|
||||
final protected void create() {
|
||||
Annotation annotation = getClass().getAnnotation(CommandDeclaration.class);
|
||||
if (annotation == null) {
|
||||
throw new RuntimeException("Command does not have a CommandDeclaration");
|
||||
}
|
||||
CommandDeclaration declaration = (CommandDeclaration) annotation;
|
||||
final protected void create()
|
||||
{
|
||||
final Annotation annotation = getClass().getAnnotation(CommandDeclaration.class);
|
||||
if (annotation == null) { throw new RuntimeException("Command does not have a CommandDeclaration"); }
|
||||
final CommandDeclaration declaration = (CommandDeclaration) annotation;
|
||||
this.command = declaration.command();
|
||||
this.usage = declaration.usage();
|
||||
this.description = declaration.description();
|
||||
@ -91,87 +100,85 @@ public abstract class Command<E extends CommandCaller> extends CommandManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
final public String toString() {
|
||||
final public String toString()
|
||||
{
|
||||
return this.command;
|
||||
}
|
||||
|
||||
public abstract boolean onCommand(E plr, String[] arguments);
|
||||
public abstract boolean onCommand(final E plr, final String[] arguments);
|
||||
|
||||
final public int handle(E plr, String[] args) {
|
||||
if (args.length == 0) {
|
||||
return super.handle(plr, "");
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (String s : args) {
|
||||
final public int handle(final E plr, final String[] args)
|
||||
{
|
||||
if (args.length == 0) { return super.handle(plr, ""); }
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (final String s : args)
|
||||
{
|
||||
builder.append(s).append(" ");
|
||||
}
|
||||
String s = builder.substring(0, builder.length() - 1);
|
||||
final String s = builder.substring(0, builder.length() - 1);
|
||||
return super.handle(plr, s);
|
||||
}
|
||||
|
||||
final public String getCommand() {
|
||||
final public String getCommand()
|
||||
{
|
||||
return this.command;
|
||||
}
|
||||
|
||||
public String getUsage() {
|
||||
if (this.usage.length() == 0) {
|
||||
return "/{label} " + command;
|
||||
}
|
||||
public String getUsage()
|
||||
{
|
||||
if (this.usage.length() == 0) { return "/{label} " + command; }
|
||||
return this.usage;
|
||||
}
|
||||
|
||||
final public String getPermission() {
|
||||
if (this.permission == null || this.permission.length() == 0) {
|
||||
final public String getPermission()
|
||||
{
|
||||
if ((this.permission == null) || (this.permission.length() == 0))
|
||||
{
|
||||
this.permission = "plots." + command.toLowerCase();
|
||||
}
|
||||
return this.permission;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
public String getDescription()
|
||||
{
|
||||
return this.description;
|
||||
}
|
||||
|
||||
final public Set<String> getAliases() {
|
||||
final public Set<String> getAliases()
|
||||
{
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
final public Argument<?>[] getRequiredArguments() {
|
||||
if (this.requiredArguments == null) {
|
||||
return new Argument<?>[0];
|
||||
}
|
||||
final public Argument<?>[] getRequiredArguments()
|
||||
{
|
||||
if (this.requiredArguments == null) { return new Argument<?>[0]; }
|
||||
return this.requiredArguments;
|
||||
}
|
||||
|
||||
final public CommandCategory getCategory() {
|
||||
if (category == null) {
|
||||
return CommandCategory.DEBUG;
|
||||
}
|
||||
final public CommandCategory getCategory()
|
||||
{
|
||||
if (category == null) { return CommandCategory.DEBUG; }
|
||||
return this.category;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
public boolean equals(final Object obj)
|
||||
{
|
||||
if (this == obj) { return true; }
|
||||
if (obj == null) { return false; }
|
||||
if (getClass() != obj.getClass()) { return false; }
|
||||
final Command<?> other = (Command<?>) obj;
|
||||
if (this.hashCode() != other.hashCode()) {
|
||||
return false;
|
||||
}
|
||||
if (this.hashCode() != other.hashCode()) { return false; }
|
||||
return this.command.equals(other.command);
|
||||
}
|
||||
|
||||
|
||||
private int hash;
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (hash == 0) {
|
||||
public int hashCode()
|
||||
{
|
||||
if (hash == 0)
|
||||
{
|
||||
hash = getCommand().hashCode();
|
||||
}
|
||||
return hash;
|
||||
|
Reference in New Issue
Block a user