How would I describe this? o.O

Discussion in 'Plugin Development' started by CraftCreeper6, Dec 18, 2014.

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

    CraftCreeper6

    Hi! I am little bit stuck! I am wanting to check a players currency, if they have enough take the specified amount. Although, I have encountered a strange issue. There is NO stacktrace.
    Code:
    @EventHandler
        public void onInvClick(InventoryClickEvent e){
           
            Player player = (Player) e.getWhoClicked();
           
            switch(e.getCurrentItem().getType()){
           
            case STONE:
                player.sendMessage("d");
                if(core.hasEnough(player, 128)){
                    player.sendMessage("d");
                        core.takeCurrency(player, 128);
                    player.getWorld().playSound(player.getLocation(), Sound.ARROW_HIT, 1, 1);
                    e.setCancelled(false);
                } else if (!core.hasEnough(player, 128)){
                    player.sendMessage("d");
                    player.getWorld().playSound(player.getLocation(), Sound.IRONGOLEM_HIT, 1, 1);
                    e.setCancelled(true);
                }
                player.sendMessage("d");
                break;
            default: e.setCancelled(true);
                break;
           
            }
           
        }
    Above is my code. I have made it so I do NOT have enough, to make me not able to take the item. Although, it does not work. takeCurrency & hasEnough method:
    Code:
    public boolean hasEnough(Player player, int amount){
           return amount<curr.getInt(player.getName());
        }
       
        public void takeCurrency(Player player, int amount){
            if(hasEnough(player, amount)){
                curr.set(player.getName(), (getAmount(player)-amount));
                try {
                    curr.save(currency);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
     
  2. Offline

    mine-care

    Is curr.getInt returning -1 probably?
    Try printing the variables and the results of such methods as a debug feature.
     
  3. Offline

    CraftCreeper6

    @Datdenkikniet @mine-care
    I registered events :)
    Also, I'll have a check.
    EDIT: The event just DOESN'T fire.
    EDIT: WAIT!!!! NOOOOOOOO I forgot to register events... Damn. I mis-read ):
     
    Datdenkikniet and Rocoty like this.
  4. Gotcha :)
     
Thread Status:
Not open for further replies.

Share This Page