1.8.8 Prevent items from going into chests

Discussion in 'Spigot Plugin Development' started by snipingmster, Feb 20, 2020.

  1. Is there a plugin already out that is able to disable certain items from going into containers E.G. a player wants to put a mob spawner into a chest i want to make it to where they cant do that, as well as make it to where they can not put the spawners into there PlayerVaults. Is there a plugin out that does this?
  2. Haven't been able to find one. This would be easy to do tho.
  3. See I’m sure it would be easy to do but idk where to even start, especially if there’s a plugin alrdy out for this.
  4. Well for recent version inventoryclickevent would be enough,might get stuffy when you want only specific spawners,otherwise you would check if the item is a spawner and cancel the event,not rly that hard
  5. Hoppers?
  6. As Stellrow said, the best way to deal with this is using the InventoryClickEvent. Just do some filtering in the items that go in and out (compare the Materials).
    If you want to filter specific items (eg Pig spawners) you should compare it by the EntityType of the getSpawnedType when casting the ItemStack.
  7. Use the InventoryClickEvent.
    You can then check if the clicked item is a spawner.
    Then you have to make sure that there is a second inventory (top inv)
    Code (Java):

    if (event.getView().getTopInventory() != null && event.getClickedInventory().equals(event.getView().getTopInventory())) {
     if (event.getCurrentItem().getType() == Material.MOB_SPAWNER) {
  8. Code (Text):
    public void onClick(InventoryClickEvent e) {
        Material[] blockedItems = new Material[] {Material.MOB_SPAWNER, Material.DIAMOND_SWORD}; // <- all blocked materials added in here!
        if(e.getInventory().getType().equals(InventoryType.CHEST)) {
            for(Material m : blockedItems) {
                if(e.getCurrentItem().equals(m)) {
    Also mark the thread solved if your issue has been solved to let us know everything is working and you do not need further assistance. :)
  9. So um where its InventoryClickEvent as my server is 1.8
  10. What exactly are you tryna do, just block specific materials from being put in a chest, use my method then?
  11. On my server i want to block mob spawners from being able to go inside Chests and PlayerVaults, so they cant put any spawner in a chest or player vault
  12. but i also dont know where InventoryClickEvent is i dont know where to locate it
  13. Also if i remember right in 1.8 the event doesnt stop dragging/shift clicking and some other actions,you have to manually detect them
    • Like Like x 1
  14. It does prevent those two. The event is being fired when a player clicks something when the menu is opened (doesn't even have to be in the menu, so make sure to check if the clickedinventory is not null). So if you cancel it, it won't be possible to drag stuff or shift click it as those are both click events.

    Please just try one of the methods given above and let us know if it worked before making any further doubts.
  15. Check again, and Spigot has an InventoryMoveItemEvent that gets fired when a player tries to move an item from one inventory to another. So this should work for hoppers, chests and custom inventories. So you might wanna check that one out