Solved Skipping if statement?

Discussion in 'Plugin Development' started by MCnumi, Sep 20, 2015.

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

    MCnumi

    Hi there,

    I am currently working on a XPbank plugin, and I hit a error.

    here is the code:
    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            Player p = (Player) sender;
            String XP = ChatColor.DARK_GRAY + "[" + ChatColor.GREEN + ChatColor.BOLD + "XXXXXXX" + ChatColor.DARK_GRAY + "] " + ChatColor.WHITE;
            int getxp = p.getTotalExperience();
            if (cmd.getName().equalsIgnoreCase("XPdep")) {
                if(sender.hasPermission("xpinfo.deposit")) {
    
                    {
                        int amountToAdd = 0;
                        try
                        {
                            amountToAdd = Integer.parseInt(args[0]);
                        }catch (Exception e)
                        {
                            p.sendMessage(XP + "You must enter a number!");
                            return true;
                        }
    
                       if(getxp >= amountToAdd) {
                            ParticleEffect.DRIP_WATER.display(1, 0, 1, 10, 5000, p.getLocation(), p);
                            Account.deposit(amountToAdd);
                            Bukkit.getServer().getPlayerExact(sender.getName()).giveExpLevels(Integer.parseInt(args[0]) - (Integer.parseInt(args[0]) * 2));
                            p.sendMessage(XP + "Successfully deposited " + args[0] + " to your account!");          
                        } else {
                            p.sendMessage("You do not have " + args[0]  + " XP!");
                            return true;
                        }
                    }
                }
    For some reason it skips
    and goes straight to
    Whenever I do /xpdep <amount>
    it says "You do not have " + args[0] + " XP!"

    Thanks.
     
    Last edited: Sep 20, 2015
  2. Offline

    pedrinholuizf

    Maybe "[B ][/B ]" infront of if?
     
  3. Offline

    MCnumi

    Thats not it. I tried to make it bold while putting here.
     
  4. Offline

    rbrick

    @MCnumi Are you sure that "getxp" is greater than or equal to "amountToAdd"?
     
  5. Offline

    MCnumi

    100% I also did it in gms.
     
  6. Offline

    Zombie_Striker

    @MCnumi
    DEBUG!!!!!!!!!!!!!!

    What is getXP equal to? What is arg[0]? What is amountToAdd equal to? Did you even try to debug?
     
  7. Offline

    MCnumi

    @Zombie_Striker uhh, amountToAdd =Integer.parseInt(args[0]);
    int getxp = p.getTotalExperience();

    args[0] is the argument... what are you saying?
     
  8. Offline

    RoboticPlayer

    He is saying that you should debug, add messages/if statements for different parts of your code to see where exactly it isn't working.
     
  9. Offline

    MCnumi

    Thank you, I thought he was talking about the debug tab and I was so confused... it is not working when it hits the first if statement.
     
  10. Offline

    RoboticPlayer

    Also, make sure you check before casting sender to Player.
     
  11. Offline

    Zombie_Striker

    @MCnumi
    Here is what I want you to do:
    1. Make a reply. The first line will be what the command is (such as /XPdep 1 )
    2. The second line should be what amountToAdd is EQUAL TO. (Is it 1? does it equal 0? Does it equal -1? WHAT DOES THE SERVER SAY IT IS EQUAL TO)
    3. Third line is what getxp is equal to. Same concept as 2#.
    4. FourthLine will be arg[0]. This time, what is the String equal to (does it have a space at the end? Does it have a space at the begining? any extra chars?)
    You can print out those values by using System.our.println("VALUE "+value);
     
  12. Offline

    MCnumi

    Got it. had to do with JRE.
     
Thread Status:
Not open for further replies.

Share This Page