InventoryMoveItemEvent

Discussion in 'Spigot Plugin Development' started by RedNinjaPlaysMC, May 17, 2016.

  1. I need help when I use:

    @EventHandler
    public void breakBlock(InventoryMoveItemEvent e)
    {
    e.setCancelled(true);
    }

    it doesnt seem to be working. Please help me!
     
  2. Is this meant to be called when you break a block?
     
  3. It is when you move something in your inventory.
     
  4. And what is your problem with it?
     
  5. It doesnt seem to work with e.setCancelled(true)
     
  6. By any chance is this in your Main class or a seperate one?
     
  7. In your main class are you registering the event on enable?
     
  8. My main class:

    package me.redninjaplaysmc;

    import org.bukkit.plugin.java.JavaPlugin;

    public class InventoryManager extends JavaPlugin {
    @Override
    public void onEnable() {
    new PlayerListener(this);
    }
    @Override
    public void onDisable() {

    }

    }
     
  9. I'm pretty sure to register an event listener you call 'Bukkit.getServer().getPluginManager().registerEvents(new YourListenerClassName(), this);'
    Where "YourListenerClassName" is replaced with your listener class name
     
  10. Doing this works for my other plugin
     
  11. You're not register the event. Do
    Code (Java):
    Bukkit.getServer().getPluginManager().registerEvents(new Event(), this);
    !
     
  12. Is not the good method to do what you want, read the Javadoc...
     
  13. nvm i did do that before but it still doesnt seem to work
     
  14. is this supposed to work?

    @EventHandler
    public void breakBlock(InventoryMoveItemEvent e)
    {
    e.setCancelled(true);
    }
     
  15. public PlayerListener(InventoryManager inventoryManager)
    {
    inventoryManager.getServer().getPluginManager().registerEvents(this, inventoryManager);
    }
    @EventHandler
    public void breakBlock(InventoryMoveItemEvent e)
    {
    e.setCancelled(true);
    }
    }
     
  16. Only, if you move item from a inventory to your. :)
     
  17. From the JavaDocs about this event: Called when some entity or block (e.g. hopper) tries to move items directly from one inventory to another.
    Are you trying to cancel a hopper moving items into another inventory or stop players moving items around their inventory?