patison234

Untitled

Jul 31st, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. package com.gmail.filoghost.touchscreen.command;
  2.  
  3. import com.gmail.filoghost.touchscreen.TouchscreenHolograms;
  4. import com.gmail.filoghost.touchscreen.command.subs.AddCommand;
  5. import com.gmail.filoghost.touchscreen.command.subs.ClearAllCommand;
  6. import com.gmail.filoghost.touchscreen.command.subs.DetailsCommand;
  7. import com.gmail.filoghost.touchscreen.command.subs.HelpCommand;
  8. import com.gmail.filoghost.touchscreen.command.subs.ListCommand;
  9. import com.gmail.filoghost.touchscreen.command.subs.RemoveCommand;
  10. import com.gmail.filoghost.touchscreen.exception.CommandException;
  11. import java.util.ArrayList;
  12. import java.util.Arrays;
  13. import java.util.List;
  14. import org.bukkit.ChatColor;
  15. import org.bukkit.command.Command;
  16. import org.bukkit.command.CommandExecutor;
  17. import org.bukkit.command.CommandSender;
  18. import org.bukkit.plugin.PluginDescriptionFile;
  19.  
  20. public class CommandHandler
  21. implements CommandExecutor
  22. {
  23. private List<TouchSubCommand> subCommands;
  24.  
  25. public CommandHandler()
  26. {
  27. this.subCommands = new ArrayList();
  28.  
  29. registerSubCommand(new ClearAllCommand());
  30. registerSubCommand(new ListCommand());
  31. registerSubCommand(new AddCommand());
  32. registerSubCommand(new RemoveCommand());
  33. registerSubCommand(new DetailsCommand());
  34.  
  35. registerSubCommand(new HelpCommand());
  36. }
  37.  
  38. public void registerSubCommand(TouchSubCommand subCommand)
  39. {
  40. this.subCommands.add(subCommand);
  41. }
  42.  
  43. public List<TouchSubCommand> getSubCommands()
  44. {
  45. return new ArrayList(this.subCommands);
  46. }
  47.  
  48. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
  49. {
  50. if (args.length == 0)
  51. {
  52. sender.sendMessage("");
  53. sender.sendMessage(ChatColor.DARK_GREEN + ChatColor.BOLD + "Touchscreen Holograms");
  54. sender.sendMessage(ChatColor.GREEN + "Version: " + ChatColor.GRAY + TouchscreenHolograms.instance.getDescription().getVersion());
  55. sender.sendMessage(ChatColor.GREEN + "Developer: " + ChatColor.GRAY + "filoghost");
  56. sender.sendMessage(ChatColor.GREEN + "Commands: " + ChatColor.GRAY + "/touch help");
  57. return true;
  58. }
  59. for (TouchSubCommand subCommand : this.subCommands) {
  60. if (subCommand.isValidTrigger(args[0]))
  61. {
  62. if (!subCommand.hasPermission(sender))
  63. {
  64. sender.sendMessage(ChatColor.RED + "You don't have permission.");
  65. return true;
  66. }
  67. if (args.length - 1 >= subCommand.getMinimumArguments()) {
  68. try
  69. {
  70. subCommand.execute(sender, (String[])Arrays.copyOfRange(args, 1, args.length));
  71. }
  72. catch (CommandException e)
  73. {
  74. sender.sendMessage(ChatColor.RED + e.getMessage());
  75. }
  76. } else {
  77. sender.sendMessage(ChatColor.RED + "Usage: /" + label + " " + subCommand.getName() + " " + subCommand.getPossibleArguments());
  78. }
  79. return true;
  80. }
  81. }
  82. sender.sendMessage(ChatColor.RED + "Unknown sub-command. Type \"/touch help\" for a list of commands.");
  83. return true;
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment