Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CommandManager implements CommandExecutor {
- private Main plugin = Main.getInstance();
- private ArrayList<SubCommands> commands = new ArrayList<SubCommands>();
- public String help = "help";
- public void setup() {
- plugin.getCommand("test").setExecutor(this);
- this.commands.add(new Help());
- }
- public boolean onCommand(CommandSender sender, Command command, String string, String[] args) {
- Player player = (Player) sender;
- if (command.getName().equalsIgnoreCase("test")) {
- if (args.length == 0) {
- player.sendMessage("Do /test help for more information ");
- }
- SubCommands cmd = this.get(args[0]);
- if (cmd == null) {
- player.sendMessage("Invalid Arguments!");
- return true;
- }
- ArrayList<String> arrayList = new ArrayList<String>();
- arrayList.addAll(Arrays.asList(args));
- arrayList.remove(0);
- try{
- cmd.onCommand(player,args);
- }catch (Exception e){
- player.sendMessage("An error has occurred.");
- e.printStackTrace();
- }
- }
- return true;
- }
- private SubCommands get(String name) {
- Iterator<SubCommands> subcommands = this.commands.iterator();
- while (subcommands.hasNext()) {
- SubCommands sc = (SubCommands) subcommands.next();
- if (sc.name().equalsIgnoreCase(name)) {
- return sc;
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement