Solved Creative InventoryClickEvent

Discussion in 'Spigot Plugin Development' started by David_Mayr, Oct 6, 2019.

  1. When i cancel the InventoryClickEvent in creative i get the item in my hand and it stays in my inventory(so i have a duplicate) how can i fix this?
     
  2. event.setCancelled(true);
    event.setCursor(new ItemStack(Material.AIR));
    event.setResult(Event.Result.DENY);
    after all these things i can still get the duplicate of the item... and yes i did use the
    InventoryCreativeEvent
     
  3. Because you can't. Creative mode items is fully controlled by the client, you can spawn almost anything in your inventory.
     
  4. I had a prison server and wanted my builders to go in creative, but not to duplicate items. So I wrote this code in my InventoryClickEvent:

    Code (Java):

    ItemStack stack = event.getCurrentItem();
    if (stack == null || stack.getType() == Material.AIR) {
          stack = event.getCursor();
          if (stack == null || stack.getType() == Material.AIR) {
              return;
          }
    }
         
    //HERE YOU CAN CHECK IF THE STACK MATCHES A SPECIFIC ITEM AND CANCEL THE EVENT
    //WITH event.setCancelled(true);
     
    This has solved my problem, they can have the item on their cursor, but it will cancel the event when they try to add it to their inventory.
     
  5. This is a thread from 2019...
     
    • Agree Agree x 1
  6. Please mark it as solved? Lmfao?
     
  7. I feel like it is clear enough that this is solved. I would have asked if somebody knew anything or wrote "bump"...
     
  8. Yeah I saw it was solved after I went back but wasn’t sure how to delete the post lmao
     
  9. I’m also on phone so it makes it harder
     
  10. I marked it as solved after you wrote that. I think we should stop writing here since it bloats the thread activity screen ^^