Command variable is not working.

Discussion in 'Plugin Development' started by MYCRAFTisbest, Dec 2, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    MYCRAFTisbest

    Hi. I tried to use the following code...
    Code:
        @Override
          public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            if(commandLabel.equalsIgnoreCase("Booth") || commandLabel.equalsIgnoreCase("h")){
                Player player = (Player) sender;
                if (player.hasPermission("booth.claim")){
                if (args.length == 0){
                    (player).sendMessage(ChatColor.GREEN + "[BoothCon] Congrats! If you can read this, that means you are eligable to obtain a booth. Type /booth <booth name> to claim a booth.");
                }
                else if (args.length == 1){
                    String boothName = args[0];
                    File file = new File(getDataFolder(), File.separator + boothName + ".booth");
                    if (!file.exists()){
                    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "region addowner " + boothName + " " + player.getName());
                    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "pex user " + player.getName() + " group set boothowner");
                    Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "pex user " + player.getName() + " remove booth.claim");
                    (player).sendMessage(ChatColor.GREEN + "[BoothCon] Enjoy your booth.");
                    }
                    else{
                        (player).sendMessage(ChatColor.GREEN + "[BoothCon]" + ChatColor.RED + "THIS BOOT HAS BEEN CLAMED!");
                    }
                }
            }
                else if (player.hasPermission("booth.admin")){
                    if(commandLabel.equalsIgnoreCase("RemoveBooth") || commandLabel.equalsIgnoreCase("h")){
                        if (args.length == 1){
                            String boothName = args[0];
                            File file = new File(getDataFolder(), File.separator + boothName + ".booth");
                            if (!file.exists()){
                                (player).sendMessage(ChatColor.GREEN + "[BoothCon]" + ChatColor.RED + "ERROR: 404  Booth not found!  Check your spelling.");
                            }
                            else{
                                if(file.delete()){
                                    (player).sendMessage(ChatColor.GREEN + "[BoothCon] Booth Removed!");
                                }
                                else{
                                    (player).sendMessage(ChatColor.GREEN + "[BoothCon]" + ChatColor.RED + "AN ERROR HAS OCCURED! Try again and if the problem continues, please manually remove the file.");
                                }
                            }
                        }
                    }
                }
            }
            return true;
        }
    I can't seem to figure out why it is incorrectly recording the value of the second half of the command. Please help.

    It is for an event on new years eve. So time is a bit more valuable. *BUMP*

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  2. Offline

    NoLiver92

    Can you specify the command - how it's used and in the code show what the second part of the command is?

    However I believe u mean the admin part. If so because the if statement before it also takes 1 argument that is run and not the admin permission section. I suggest swapping the 2 if systems over (swap the order) so that the admin one is first. This is because the admin can do the player command before the admin one but the player can't do admin command. If you change the order then admins will run admins and player will do the player bit of the command
     
  3. Offline

    MYCRAFTisbest

    The command should be /booth <BoothName>
    It seems that I am incorrectly getting boothName to equal the second value.
    Should it be equal to args[1]?

    It is just the second argument that is being ignored.

    Also the second half should delete the file created by the user.
     
  4. Offline

    NoLiver92

    No args[0] is what u want. Try removing the file delete out of the if statement because in the if statement it checks if its been deleted. Not actually deleting it
     
  5. Offline

    MYCRAFTisbest


    It isn't even adding the file. It is completely ignoring anything that contains the argument.
     
Thread Status:
Not open for further replies.

Share This Page