Solved Detect Hotbar Button on Current Item

Discussion in 'Plugin Development' started by NathanWolf, Jan 7, 2015.

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

    NathanWolf

    Is there any way to detect a player pressing the hotbar button that corresponds to the currently equipped item? I don't seem to get a PlayerItemHeldEvent or an InventoryClickEvent for this.

    Maybe the client ignores this action (since it normally does nothing) ?

    I don't have much hope, given what I've seen, but I thought I'd ask in case anyone knew some trick to it.

    Thanks in advance!
     
  2. Offline

    mythbusterma

    @NathanWolf

    Perhaps a PlayerHeldItemEvent is fired with the source and destination being the same?
     
  3. Offline

    teej107

    Post code attempt.
     
  4. Offline

    CheesyFreezy

    Code:
    @Eventhandler
    Public void onInventoryClick(InventoryClickEvent event) {
       Player player = (Player)event.getWhoClicked();
    
       player.sendMessage("Current Slot Clicked: " + event.getSlot());
    }
     
  5. Offline

    NathanWolf

    @CheesyFreezy @mythbusterma

    I have debugged both event handlers, I promise :)

    Code:
        @EventHandler
        public void onInventoryClick(InventoryClickEvent event) {
            getLogger().info("CLICK: " + event.getAction() + ", " + event.getClick() + " on " + event.getSlotType() + " in "+ event.getInventory().getType() + " slots: " + event.getSlot() + ":" + event.getRawSlot());
    
    ...
    
        @EventHandler
        public void onPlayerEquip(PlayerItemHeldEvent event)
        {
            getLogger().info("ITEM HELD: " + event.getNewSlot());
    
    Neither fire in the case where you hit the same button as you already have equipped, unfortunately,

    @teej107 I know that's a good boilerplate response, but in this case I'm not asking for code or even for help with code, really. Mostly I'd like a definitive answer about client behavior, because I'm guessing this is not possible.

    If I knew how to debug packets, I think that'd be the best way- see if the client sends any packet at all when you hit that button. But I can't do that with code (er, can I?), so I've got nothing to show other than the two obvious event handlers with debug logs, and I can say for sure they're not firing.

    Thanks, you all!
     
  6. Offline

    1Rogue

    I'm gonna say no because iirc the client does not send information regarding your own inventory unless you click or move something. Highlighting the hotbar on the same spot probably has a check client-side that just makes it do nothing. Things like that, and opening their own inventory etc aren't detectable from the server.
     
    NathanWolf likes this.
Thread Status:
Not open for further replies.

Share This Page