Solved Players can't move items in their upper inventory?

Discussion in 'Spigot Plugin Development' started by Fluddershy, Apr 22, 2017.

  1. Hello, I have a problem with a plugin I am working with, why I'm posting this in the Plugin Development forum. Anyway, so, when player's try to use items in their upper inventory, like a health potion, it just teleports it back, and it shows up in their hotbar, but when they use it, it disappears, and moments later, it's back where it was before players used it. That was a long sentence.. Carrying on, I'm going to show you what happens with a quick gif. I was having this problem for a while, but I can't show you code, because there's like 50 events for an InventoryClickEvent and thousands of lines of code.

    GIF: https://gyazo.com/ca03758eb3b6c04b650fc22f74036718

    What the heck? I think it's a InventoryClickEvent but I checked them all and made a return; if they weren't in that inventory. Help is super appreciated! Thanks in advance!
     
  2. IIRC this happens when you cancel an InventoryClickEvent. So you would probably have to recheck the logic of all your InventoryClickEvents.
     
  3. Usually when I have weird inventory errors I write player.updateInventory() each time I edit the inventory. You can try putting this statement in a delayed task too.
     
  4. So... Can you give me some pseudo code? I don't get you're "logic"
    Ima try that rn
     
    • Creative Creative x 1
  5. To check if the problem is coming from cancelling the click event, create a temporary listener which has the priority of MONITOR and broadcasts event.isCancelled. Since it's very rare that it's anything other than that, seems you're in for a long while debugging all those 50 listeners (That's wayyyy too many, most of them probably do the same logic in their first few lines anyway).

    Another issue could be calling p.updateInventory in the interactevent, it causes really weird behaviour sometimes, add a bit of delay using a task, or better yet, don't use it at all in that scenario, p.updateInventory is actually needed very rarely.
     
  6. Im using Bukkit#createInventory() btw and I'll just debug all the listeners, like you said, they mostly do the same logic :D
     
  7. Ah, your main post was rather confusing. Are you sure which plugin is causing the issue? Sounds like some similar bugs I've seen with p.updateInventory, I'd search for usages of that first
     
  8. Do you use InventoryClickEvent#setCancelled(true)? If so the code is probably surrounded by some logic using if statements. I'm referring to that logic. There is probably something wrong with it that allows the code to cancel the event. Even tho you clearly don't want that.
     
  9. I've done going to all the events, adding a if(!e.getInventory#getTitle().equals("blag") { e.setCancelled(false);
    Also, it's not really cancelling it, it's more of like a buggy, you move it, and it wont work until you interact with that slot and it doesn't work but slowly goes back to the slot it was taking from in the upper inventory.
     
  10. When an item is moved from top slot to bottom slot and it gets cancelled the item is still actually in the top slot. But the client shows that the item moved to the bottom inventory. If you move items in the inventory using code then you should call player.updateInventory() after the movement as Max604 suggested. Then the client will show that the item still is in the top slot.
    Anyway calling e.setCancelled(false); won't do much for you. Just verify that the logic where you call e.setCancelled(true); is correct. (If you even cancel the event)
     
  11. Okay, so I figured it out, partially thanks to you guys, partically because my stupidity took a hike! So, It was when I was adding the items that they were needing and update. So I had to add a p.updateInventory() to my InventoryBuilder class. Thanks everyone for you're blood, sweat, and tears! <3