Event not cancelling

Discussion in 'Plugin Development' started by ZonalYewHD, May 27, 2014.

Thread Status:
Not open for further replies.
  1. I am developing version 2.0 for a plugin, and I am having issues making an inventory read-only. Basically, if the player has a permission, and they run a command, an inventory exactly like someone else's opens up. They can also edit this inventory, and it will update in real time. However, if they do not have this permission, they can still see the player's inventory, but they can't edit it.

    The event is handled as below:
    Code:
    @EventHandler
    public void onPlayerInventoryClick(InventoryClickEvent event){
    Player player = (Player) event.getWhoClicked();
    if(player.getInventory().getName().equalsIgnoreCase("inventory")){
    if(player.hasPermission("agtools.see.player.inv.edit")){
    return;
    }else if(!player.hasPermission("agtools.see.player.inv.edit")){
    event.setCancelled(true);
    }
    }
    }
    
    The command, with the argument, is below:
    Code:
    } else if (args[1].equalsIgnoreCase("inv")) {
    if (player.hasPermission("agtools.see.player.inv")) {
    Player targetPlayer = player.getServer().getPlayer(
    args[0]);
    if (targetPlayer == null) {
    player.sendMessage(RED + args[0] + GOLD
    + " is not online!");
    return true;
    }
    if(player.hasPermission("agtools.see.inv.edit")){
    player.openInventory(targetPlayer.getInventory());
    }else{
    player.sendMessage(RED + "Showing the inventory of " + targetPlayer.getName() + ". You will not be able to edit this inventory.");
    Inventory inventory;
    inventory = Bukkit.createInventory(null, 36, targetPlayer.getName() + "'s Inventory");
    ItemStack[] items = targetPlayer.getInventory().getContents();
    inventory.setContents(items);
    player.sendMessage(GOLD + "Opening " + RED + targetPlayer.getName() + GOLD + "'s inventory...");
    player.openInventory(inventory);
    }
     
    }
    
    Also, yes, I have registered my events, so I know that is not the issue. What happens with that is given above is an inventory is opened, but the player can edit it. What did I do wrong/what can I do to fix it?
     
  2. Offline

    1Achmed1

    Are you sure that your plugin ever gets to the else in that first if? Are you sure that the default inventory is called inventory, if it's capitalized correctly?
     
  3. Yes, the formatting is kept here.
    Yes, I defined Inventory as inventory, here.
     
  4. Offline

    chingo247

    I am stuck on the same problem... The event.setCancelled method worked in 1.6.4 for me, but in 1.7.2 it doesnt do anything. What version are you using?
     
  5. Offline

    1Achmed1

Thread Status:
Not open for further replies.

Share This Page