Command not functioning correctly.

Discussion in 'Plugin Development' started by StyL_TwisT, Apr 21, 2013.

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

    StyL_TwisT

    Hello,

    I am having trouble with a rank plugin that I am making:

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(sender instanceof Player){
                if(cmd.getName().equalsIgnoreCase("rankup")){
                    Player player = (Player) sender;
                    EconomyResponse n = econ.withdrawPlayer(player.getName(), 10000);
                    EconomyResponse a = econ.withdrawPlayer(player.getName(), 25000);
                    EconomyResponse s = econ.withdrawPlayer(player.getName(), 50000);
                    EconomyResponse p = econ.withdrawPlayer(player.getName(), 80000);
                    EconomyResponse e = econ.withdrawPlayer(player.getName(), 120000);
                    EconomyResponse m = econ.withdrawPlayer(player.getName(), 200000);
                    CommandSender console = this.getServer().getConsoleSender();
                    if(player.hasPermission("rank.newbie")){
                        if(n.transactionSuccess()){
                            Bukkit.dispatchCommand(console, "pex promote " + player.getName());
                            Bukkit.broadcastMessage("§b[§3Ranks§b] §e" + player.getName() + "§6 has been promoted to Beginner!" );
                            player.sendMessage("§bYou have been promoted to Beginner!");
                        }else{
                            player.sendMessage("§cYou do not have enough credits, Beginner requires 10,000.");
                        }
                    }else if(player.hasPermission("rank.beginner")){
                        if(a.transactionSuccess()){
                            Bukkit.dispatchCommand(console, "pex promote " + player.getName());
                            Bukkit.broadcastMessage("§b[§3Ranks§b] §e" + player.getName() + "§6 has been promoted to Amateur!" );
                            player.sendMessage("§bYou have been promoted to Amateur!");
                        }else{
                            player.sendMessage("§cYou do not have enough credits, Amateur requires 25,000.");
                        }
                    }else if(player.hasPermission("rank.amateur")){
                        if(s.transactionSuccess()){
                            Bukkit.dispatchCommand(console, "pex promote " + player.getName());
                            Bukkit.broadcastMessage("§b[§3Ranks§b] §e" + player.getName() + "§6 has been promoted to Semi-Pro!" );
                            player.sendMessage("§bYou have been promoted to Semi-Pro!");
                        }else{
                            player.sendMessage("§cYou do not have enough credits, Semi-Pro requires 50,000.");
                        }
                    }else if(player.hasPermission("rank.semipro")){
                        if(p.transactionSuccess()){
                            Bukkit.dispatchCommand(console, "pex promote " + player.getName());
                            Bukkit.broadcastMessage("§b[§3Ranks§b] §e" + player.getName() + "§6 has been promoted to Professional!" );
                            player.sendMessage("§bYou have been promoted to Professional!");
                        }else{
                            player.sendMessage("§cYou do not have enough credits, Professional requires 80,000.");
                        }
                    }else if(player.hasPermission("rank.pro")){
                        if(e.transactionSuccess()){
                            Bukkit.dispatchCommand(console, "pex promote " + player.getName());
                            Bukkit.broadcastMessage("§b[§3Ranks§b] §e" + player.getName() + "§6 has been promoted to Expert!" );
                            player.sendMessage("§bYou have been promoted to Expert!");
                        }else{
                            player.sendMessage("§cYou do not have enough credits, Expert requires 120,000.");
                        }
                    }else if(player.hasPermission("rank.expert")){
                        if(m.transactionSuccess()){
                            Bukkit.dispatchCommand(console, "pex promote " + player.getName());
                            Bukkit.broadcastMessage("§b[§3Ranks§b] §e" + player.getName() + "§6 has been promoted to Master!" );
                            player.sendMessage("§bYou have been promoted to Master!");
                        }else{
                            player.sendMessage("§cYou do not have enough credits, Master requires 200,000.");
                        }
                    }else if(player.hasPermission("rank.master")){
                        player.sendMessage("§cYou are the highest rank, you can no longer rank up.");
                    }
                
                }else if(cmd.getName().equalsIgnoreCase("balance")){
                    Player player = (Player) sender;
                    player.sendMessage(String.format("§b[§3Credits§b] §6You have §e%s§6credits.", econ.format(econ.getBalance(player.getName()))));
    
                }
            
            }
            return false;
        
        }
        
    }
    The first /rankup works fine (Newbie --> Beginner) but after that even when I have enough it displays the message saying I don't have enough, and takes away 10,000? its somehow running the withdraw command from the Newbie ---> Beginner, when I clearly have the permission "rank.beginner" not "rank.newbie"

    Can anyone help me with this?

    Thanks,

    StyL TwisT
     
  2. Offline

    kreashenz

    Maybe a bracket problem? Check your brackets.
     
  3. Offline

    StyL_TwisT

    Looks fine to me?
     
  4. Offline

    kreashenz

    StyL_TwisT You'd be surprised, hover over each of your brackets and see if they match where they start and where they should end.
     
  5. Offline

    StyL_TwisT

    Thats what I have done and they are all correct

    Anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  6. Offline

    coolgangsam2

  7. Offline

    coolgangsam2

  8. Offline

    Lolmewn

    You're first taking 10.000, then taking 25.000, etc. I'd just use booleans and .hasMoney or something similar.
     
  9. Offline

    coolgangsam2

    Thanks, ill tell him that when he comes on :>
     
  10. Offline

    StyL_TwisT

    Yes, but I am checking whether the player has the permission first, rank beginner doesn't have the permission "rank.newbie" so why would it take 10,000?
     
  11. Offline

    Lolmewn

    Because you're withdrawing the money before checking the permissions.
     
  12. Offline

    StyL_TwisT

    I have fixed it now:) thanks for the help, I just had to put the EconomyResponses inside the corresponding if statements
     
Thread Status:
Not open for further replies.

Share This Page