Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.gmail.filoghost.touchscreen.command;
- import com.gmail.filoghost.touchscreen.TouchscreenHolograms;
- import com.gmail.filoghost.touchscreen.command.subs.AddCommand;
- import com.gmail.filoghost.touchscreen.command.subs.ClearAllCommand;
- import com.gmail.filoghost.touchscreen.command.subs.DetailsCommand;
- import com.gmail.filoghost.touchscreen.command.subs.HelpCommand;
- import com.gmail.filoghost.touchscreen.command.subs.ListCommand;
- import com.gmail.filoghost.touchscreen.command.subs.RemoveCommand;
- import com.gmail.filoghost.touchscreen.exception.CommandException;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.List;
- import org.bukkit.ChatColor;
- import org.bukkit.command.Command;
- import org.bukkit.command.CommandExecutor;
- import org.bukkit.command.CommandSender;
- import org.bukkit.plugin.PluginDescriptionFile;
- public class CommandHandler
- implements CommandExecutor
- {
- private List<TouchSubCommand> subCommands;
- public CommandHandler()
- {
- this.subCommands = new ArrayList();
- registerSubCommand(new ClearAllCommand());
- registerSubCommand(new ListCommand());
- registerSubCommand(new AddCommand());
- registerSubCommand(new RemoveCommand());
- registerSubCommand(new DetailsCommand());
- registerSubCommand(new HelpCommand());
- }
- public void registerSubCommand(TouchSubCommand subCommand)
- {
- this.subCommands.add(subCommand);
- }
- public List<TouchSubCommand> getSubCommands()
- {
- return new ArrayList(this.subCommands);
- }
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
- {
- if (args.length == 0)
- {
- sender.sendMessage("");
- sender.sendMessage(ChatColor.DARK_GREEN + ChatColor.BOLD + "Touchscreen Holograms");
- sender.sendMessage(ChatColor.GREEN + "Version: " + ChatColor.GRAY + TouchscreenHolograms.instance.getDescription().getVersion());
- sender.sendMessage(ChatColor.GREEN + "Developer: " + ChatColor.GRAY + "filoghost");
- sender.sendMessage(ChatColor.GREEN + "Commands: " + ChatColor.GRAY + "/touch help");
- return true;
- }
- for (TouchSubCommand subCommand : this.subCommands) {
- if (subCommand.isValidTrigger(args[0]))
- {
- if (!subCommand.hasPermission(sender))
- {
- sender.sendMessage(ChatColor.RED + "You don't have permission.");
- return true;
- }
- if (args.length - 1 >= subCommand.getMinimumArguments()) {
- try
- {
- subCommand.execute(sender, (String[])Arrays.copyOfRange(args, 1, args.length));
- }
- catch (CommandException e)
- {
- sender.sendMessage(ChatColor.RED + e.getMessage());
- }
- } else {
- sender.sendMessage(ChatColor.RED + "Usage: /" + label + " " + subCommand.getName() + " " + subCommand.getPossibleArguments());
- }
- return true;
- }
- }
- sender.sendMessage(ChatColor.RED + "Unknown sub-command. Type \"/touch help\" for a list of commands.");
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment