cancelling InventoryClickEvent doens't work

Discussion in 'Spigot Plugin Development' started by sky_berry, Jul 2, 2018.

Thread Status:
Not open for further replies.
  1. I
     
    #1 sky_berry, Jul 2, 2018
    Last edited: Apr 24, 2019
  2. By default in minecraft, you can't put items on head.
    I don't haven't completely understand but if I understand well it's look like:

    Code (Text):
    if(event.getClickedInventory() == null) return;
    if(event.getSlotType() == SlotType.ARMOR) {
               
        ItemStack item = event.getCurrentItem();
        if(item == null) return;
        if(item.getType() == Material.ENCHANTED_BOOK) {
                   
                   
            event.getWhoClicked().sendMessage("§cSorry, but you can't put that on armor slot.");
            event.setCancelled(true);
                   
        }          
    }
     
  3. Try LOWEST so it fires first, and hope the other plugin is ignoring cancelled events.

    The priorities will fire from lowest to highest, this gives higher ones the ability to override what lower one's did (explains why the names low->high seem backwards)

    If the other plugin is adding item to head in normal priority and then you cancel in highest, you didn't really cancel anything.

    If you cancel in lowest and the other plugin listens in normal and ignores cancelled events, then you have successfully cancelled it.

    If the other plugin does not ignore events, then you will have to undo the action in a higher priority.
     
  4. it has to be if statements usually is never other plugins and you should only have the plugin your working on the server.
     
  5. Don't forget that if the player has an item on their cursor already they can bypass InventoryClickEvent when drag-placing. Make sure you handle InventoryDragEvent too.
     
  6. did you have write
    Code (Text):
    getServer().getPluginManager().registerEvents(new Class(this), this);
     
  7. Remove all the checks and debug it. If nothing happens, then you did not register your events.
     
Thread Status:
Not open for further replies.