Solved Player interact breaking eating?

Discussion in 'Plugin Development' started by torpkev, Dec 11, 2018.

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

    torpkev

    Hi all,

    I have some PlayerInteract code that I use to detect if a player is doing something, but it seems to be breaking the player eating.

    So the code is like this (I've stripped out the stuff for flint and wooden_hoe as it isn't being used at this point)
    Code:
    public class PlayerInteract implements Listener {
        @EventHandler
        public void onInteract(PlayerInteractEvent evt) {
            EquipmentSlot e = evt.getHand(); //Get the hand of the event and set it to 'e'.
            if (e.equals(EquipmentSlot.HAND)) { //If the event is fired by HAND (main hand) - using this because if I don't, the event fires twice
                // evt.isCancelled() returns true if eating
                if (Check.MainHand(evt.getPlayer()) == Material.FLINT) { 
                    // do stuff if flint
                }
                if (Check.MainHand(evt.getPlayer()) == Material.WOODEN_HOE) { 
                    // do stuff if wooden_hoe
                }
                // Any non-flint | non-wooden hoe interaction performed with main hand
                // evt.isCancelled() returns true if eating
            }
        }
    }
    If I try to eat, the part of the code that has "// Any non-flint | non-wooden hoe interaction performed with main hand" fires - when I check evt.isCancelled(), it is returning true.. but I have no idea why. So the player can't eat.

    I've tried manually setting the evt.setCancelled(false); - it didn't make a difference

    Has anyone run into this before or can see some massive glaring issue?
     
    Last edited: Dec 11, 2018
  2. Offline

    MightyOne

    I don't think the now visible code is cancelling anything.
    Maybe post the full code so we can get an image of what is actually happening.
     
  3. Offline

    torpkev

    Nevermind.. apparently I'm as dumb as a box of rocks sometimes.

    It didn't occur to me that I wasn't eating at all because I was in creative mode. I'm surprised I can't eat chorus fruit in creative though, even though you can eat it if not hungry in survival. Oh well, there's a couple of hours of pointless troubleshooting dealt with. I finally removed all of the listener code and it was still happening, then the penny dropped.

    Problem was me, not my code. Thanks for looking though!
     
    Last edited: Dec 11, 2018
    MightyOne likes this.
Thread Status:
Not open for further replies.

Share This Page