Advertisement
Guest User

Untitled

a guest
Nov 19th, 2014
20
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. package me.rw_craft.elitemctntwars;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Arrays;
  5.  
  6. import me.rw_craft.elitemctntwars.cmds.Create;
  7. import me.rw_craft.elitemctntwars.cmds.Delete;
  8. import me.rw_craft.elitemctntwars.cmds.ForceStart;
  9. import me.rw_craft.elitemctntwars.cmds.ForceStop;
  10. import me.rw_craft.elitemctntwars.cmds.Join;
  11. import me.rw_craft.elitemctntwars.cmds.Leave;
  12. import me.rw_craft.elitemctntwars.cmds.SetLocation;
  13. import me.rw_craft.elitemctntwars.cmds.SubCommand;
  14.  
  15. import org.bukkit.command.Command;
  16. import org.bukkit.command.CommandExecutor;
  17. import org.bukkit.command.CommandSender;
  18. import org.bukkit.entity.Player;
  19.  
  20. public class CommandManager implements CommandExecutor {
  21.  
  22. private ArrayList<SubCommand> commands = new ArrayList<SubCommand>();
  23.  
  24. public void Setup() {
  25. commands.add(new Create());
  26. commands.add(new Delete());
  27. commands.add(new ForceStart());
  28. commands.add(new ForceStop());
  29. commands.add(new Join());
  30. commands.add(new Leave());
  31. commands.add(new SetLocation());
  32. }
  33.  
  34. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
  35. if (!(sender instanceof Player)) {
  36. MessageManager.getInstance().severe(sender, "Only Players Can Use Commands (You're A Snowman? <3)");
  37. return true;
  38. }
  39.  
  40. Player p = (Player) sender;
  41.  
  42. if (cmd.getName().equalsIgnoreCase("tntwars")) {
  43. if (args.length == 0) {
  44. for (SubCommand c : commands) {
  45. MessageManager.getInstance().info(p, "/tntwars" + c.name() + "(" + aliases(c) + ")" + "-" + c.info());
  46. }
  47. return true;
  48. }
  49.  
  50. SubCommand target = get(args[0]);
  51.  
  52. if (target == null) {
  53. MessageManager.getInstance().severe(p, "/tntwars" + args[0] + "Is Not A Valid Sub-Command");
  54. return true;
  55. }
  56. ArrayList<String> a = new ArrayList<String>();
  57. a.addAll(Arrays.asList(args));
  58. a.remove(0);
  59. args = a.toArray(new String[a.size()]);
  60.  
  61. try {
  62. target.onCommand(p, args);
  63. }
  64. catch (Exception e) {
  65. MessageManager.getInstance().severe(p, "An Error Has Occured, Please Report It To A Server Administrator: "+e.getCause());
  66. e.printStackTrace();
  67. }
  68. }
  69. return true;
  70. }
  71.  
  72. private String aliases(SubCommand cmd) {
  73.  
  74. String fin = "";
  75.  
  76. for (String a : cmd.aliases()) {
  77. fin += a = " | ";
  78. }
  79.  
  80. return fin.substring(0, fin.lastIndexOf("|"));
  81. }
  82.  
  83. private SubCommand get(String name) {
  84. for (SubCommand cmd : commands) {
  85. if (cmd.name().equalsIgnoreCase(name)) return cmd;
  86. }
  87. return null;
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement