Protecting certain slots from being used

Discussion in 'Spigot Plugin Development' started by spinnekoppie, May 12, 2016.

  1. I need to reserve certain slots in the inventory from being used by a player. I have managed to do this using InventoryClickEvent. However, one can still place items in those slot when you hold shift down to spread items over slots. How can I prevent this?
  2. You can check the player shift clicked, if they did, check to see if the item slot you want to leave reserved is null, if it isn't then cancel the event.
  3. But that would cancel everything that has been placed, even if they were in other slots. I think that will be a bit annoying. It looks like an alternative would be to use a scheduler and drop the items from the reserved slots on the next tick but that sounds complicated.
  4. Well what you could also do instead of cancelling the event is, once you've determined they've shift-clicked an item in, you can just take the item out of that slot an set it back to the slot they shift-clicked. You know that slot has to be empty because they just shift-clicked it.
  5. That sounds like a plan. How does one detect a shift click?
  6. event.isShiftClick()