Solved deleting item in hand is working WEIRD

Discussion in 'Plugin Development' started by soulofw0lf, May 3, 2013.

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

    soulofw0lf

    So i have a food replacement plugin i've been working on all day and thought i had it finished, till while testing it for bugs it turns out if you spam right click the food to eat it you don't lose one and if you hold it down while eatting you continously lose them. here's the relevant piece of code
    Code:
        @EventHandler(priority=EventPriority.HIGH)
        public void onPlayerUse(PlayerInteractEvent event){
            Player p = event.getPlayer();
            ItemStack item = p.getItemInHand();
            if(item == null || item.getTypeId() == 0){
                return;
            } else {
                if (p.getItemInHand() != null){
                    ItemMeta im = p.getItemInHand().getItemMeta();
                    int health = p.getHealth();
                    int maxhealth = p.getMaxHealth();
                    if (im.hasDisplayName()){
                        String iname = im.getDisplayName();
                        if (this.getConfig().contains("Food." + iname)){
                            if ((event.getAction() == Action.RIGHT_CLICK_AIR) || (event.getAction() == Action.RIGHT_CLICK_BLOCK)){
                                if (health == maxhealth){
                                    p.sendMessage("you cannot eat while your health is full1");
                                    return;
                                } else
                                {
                                    if (getConfig().contains(p.getName())){
                                        p.sendMessage("You are already eatting!");
                                        return;
                                    } else {
                                        getConfig().set(p.getName(), "eatting");
                                        Integer inhand = item.getAmount() -1;
                                        p.setItemInHand(null);
                                        p.setItemInHand(new ItemStack(item.getType(), inhand));
                                        Location old = p.getLocation();
                                        saveConfig();
                                        this.foodConsumption(p, iname, old);
    I have no clue why it's behaving like this.
     
Thread Status:
Not open for further replies.

Share This Page