InventoryClickEvent

Discussion in 'Plugin Development' started by mcgamer99, Jul 10, 2012.

  1. Offline

    mcgamer99

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I try to stop the InventoryClickEvent for the players that aren't op, with set the InventoryClickEvent to cancel, but the code don't work, ALL players can't move items in their inventory, how I set that the op can move the items?

    The code:
    Code:
        @EventHandler
        public void onClickInventory(InventoryClickEvent event){
           
            if(event.getWhoClicked().isOp()) {
                event.setCancelled(false);
                return;
            }
           
            if(!event.getWhoClicked().isOp()) {
            event.setCancelled(true);
            return;
            }
        }
  2. Offline

    gjossep

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Event.getWhoClicked does not return a player so try this, but make sure you learn from it!
    Btw it works!
    Code:java
    1. @EventHandler
    2. public void onClickInventory(InventoryClickEvent event){
    3. Player player = Bukkit.getPlayer(event.getWhoClicked().getName());
    4. if(!player.isOp())
    5. {
    6. event.setCancelled(true);
    7. }
    8.  
    9. }
    mcgamer99 likes this.

Share This Page