Advertisement
Guest User

Untitled

a guest
Sep 24th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1. public class CommandManager implements CommandExecutor {
  2.    
  3.     private Main plugin = Main.getInstance();
  4.     private ArrayList<SubCommands> commands = new ArrayList<SubCommands>();
  5.  
  6.     public String help = "help";
  7.  
  8.     public void setup() {
  9.         plugin.getCommand("test").setExecutor(this);
  10.         this.commands.add(new Help());
  11.     }
  12.  
  13.     public boolean onCommand(CommandSender sender, Command command, String string, String[] args) {
  14.         Player player = (Player) sender;
  15.  
  16.         if (command.getName().equalsIgnoreCase("test")) {
  17.             if (args.length == 0) {
  18.                 player.sendMessage("Do /test help for more information ");
  19.             }
  20.            
  21.             SubCommands cmd = this.get(args[0]);
  22.            
  23.             if (cmd == null) {
  24.                 player.sendMessage("Invalid Arguments!");
  25.                 return true;
  26.             }
  27.  
  28.             ArrayList<String> arrayList = new ArrayList<String>();
  29.             arrayList.addAll(Arrays.asList(args));
  30.             arrayList.remove(0);
  31.  
  32.             try{
  33.                 cmd.onCommand(player,args);
  34.             }catch (Exception e){
  35.                 player.sendMessage("An error has occurred.");
  36.                 e.printStackTrace();
  37.             }
  38.         }
  39.         return true;
  40.     }
  41.  
  42.     private SubCommands get(String name) {
  43.         Iterator<SubCommands> subcommands = this.commands.iterator();
  44.  
  45.         while (subcommands.hasNext()) {
  46.             SubCommands sc = (SubCommands) subcommands.next();
  47.  
  48.             if (sc.name().equalsIgnoreCase(name)) {
  49.                 return sc;
  50.             }
  51.         }
  52.         return null;
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement