Nothing happens. I don't think the event is even triggering?

Discussion in 'Plugin Development' started by frozenpoptartmc, May 25, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    frozenpoptartmc

    Code:java
    1.  
    2. @EventHandler
    3. public void onInvClick(InventoryClickEvent event){
    4. if(event.getInventory() == beaconinv){
    5. if(event.getCurrentItem().getType() == Material.ROTTEN_FLESH){
    6. event.setCancelled(true);
    7. event.getWhoClicked().closeInventory();
    8. event.getWhoClicked().getInventory().addItem(new ItemStack(Material.ROTTEN_FLESH, 1));
    9. if(event.getWhoClicked().getInventory().contains(Material.BEACON)){
    10. event.getWhoClicked().getInventory().remove(Material.BEACON);
    11. Bukkit.broadcastMessage(ChatColor.GOLD + event.getWhoClicked().getName() + " took Rotten Flesh from the beacon!");
    12. }
    13. }
    14.  

    and yes, i actually created beaconinv and added items to it, but not in this event.
    i don't get any errors, but when i click the rotten flesh, nothing happens.
    help would be much appreciated!
    thanks
     
  2. Offline

    felixfritz

    Instead of checking with the == sign, try event.getInventory().equals(beaconinv) . That might work.

    To see, if it's even calling the event, put some System.out.println() 's in there, just to log, if it triggered.
     
  3. Offline

    Minnymin3

    That wont make a difference. Its the same function.
    The problem is that you are checking if the inventory is the exact same (ie same itemstacks in the same slots) which im assuming it is not. I would add people's name to a list when they open the inventory then check if the player's name is in the list and cancel the click then remove them from the list if they are on the list with the inventory close event.
     
  4. Offline

    frozenpoptartmc

    I am. :p
    The inventory can't be updated by players (new items added, new items taken out).
    I also have a PlayerInteractEvent which when they right click the beacon, it clears the beacons inventory and adds the items in the exact same order every time.


    I'll try that and reply if I need any more help or if it works, thanks!

    IT WORKS! :D
    Thank you so much!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
Thread Status:
Not open for further replies.

Share This Page