forked from UnlegitDqrk/unlegitlibrary
55 lines
1.7 KiB
Java
55 lines
1.7 KiB
Java
package dev.unlegitdqrk.unlegitlibrary.command;
|
|
|
|
import javax.management.InstanceAlreadyExistsException;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public abstract class Command {
|
|
|
|
private final CommandManager commandManager;
|
|
private final String name;
|
|
private final String description;
|
|
private final String usage;
|
|
private final List<CommandPermission> permissions;
|
|
private final List<String> aliases;
|
|
|
|
public Command(CommandManager commandManager, String name, String description, String usage, List<CommandPermission> permissions, List<String> aliases) throws InstanceAlreadyExistsException {
|
|
this.commandManager = commandManager;
|
|
this.name = name;
|
|
this.description = description;
|
|
this.usage = usage;
|
|
this.permissions = permissions;
|
|
this.aliases = aliases;
|
|
|
|
boolean exists = commandManager.getCommand(name) != null;
|
|
if (!exists) for (String alias : aliases) exists = commandManager.getCommand(alias) != null;
|
|
if (exists) throw new InstanceAlreadyExistsException("Command with this name or some alias alreadx exists!");
|
|
}
|
|
|
|
public final String getName() {
|
|
return name;
|
|
}
|
|
|
|
public final CommandManager getCommandManager() {
|
|
return commandManager;
|
|
}
|
|
|
|
public final String getDescription() {
|
|
return description;
|
|
}
|
|
|
|
public final String getUsage() {
|
|
return usage;
|
|
}
|
|
|
|
public final List<CommandPermission> getPermissions() {
|
|
return new ArrayList<>(permissions);
|
|
}
|
|
|
|
public final List<String> getAliases() {
|
|
return new ArrayList<>(aliases);
|
|
}
|
|
|
|
public abstract void execute(CommandExecutor commandExecutor, String label, String[] args);
|
|
}
|