Prevent putting certain items in crafting table

Discussion in 'Plugin Development' started by DarthAimbot, Aug 18, 2018.

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

    DarthAimbot

    Hi all! I am trying to prevent certain items from being moved into inventories such as Crafting tables, anvils, furnaces, etc... As well as the 4 slot inventory in the default player inventory.
    I was wondering what Events were triggered during these actions, Thanks!
    Best I got from google was prepareitemcraftevent which is after the items are in the table and upon attempting to complete the craft.
     
  2. Offline

    KarimAKL

    @DarthAimbot Why not use InventoryClickEvent & InventoryDragEvent and check if the inventory is instanceof CraftingInventory etc? (I don't remember the exact name)
     
  3. Offline

    DarthAimbot

    @KarimAKL
    I am already canceling those for the specific items I don't want to be placed in those inventories.
    The problem is that the player can hover over the spot in the crafting table and press (0-9) and still get the item to go in.
    Normally I use this to get the item of (0-9) and then cancel it
    Code:
    ItemStack hotbarItem = inventoryClickEvent.getClickedInventory().getItem(inventoryClickEvent.getHotbarButton());
    
    but when the cursor is over the crafting inventories, that returns null.


    Edit: I have uploaded a video of the null response I am referring to. https://imgur.com/RvTrci6
     
    Last edited: Aug 18, 2018
  4. Offline

    KarimAKL

    I see, i unfortunately cannot help you with this as i'm not sure why it's doing this. :/ I haven't looked too much into inventories yet.
     
  5. Offline

    DarthAimbot

  6. Offline

    Zombie_Striker

  7. Offline

    DarthAimbot

    @Zombie_Striker
    I have been trying in many different ways to get that event to work..
    I can't cancel that specific event.
     
  8. Offline

    Zombie_Striker

    @DarthAimbot
    You can't cancel them. However, you can change the "Result" so that the player can't craft anything (do this by setting the result to null or to AIR)
     
  9. Offline

    DarthAimbot

    @Zombie_Striker, I apologize if I wasn't clear in my initial message.
    But the goal is not to prevent them from crafting anything specific. The item I am using is Iron_Bars. Nothing can be crafted anyway.
    The goal is to prevent that specific item from even being moved into the crafting table.
    The purpose for this is that it is an item that is suppose to always be in the players inventory in a specific slot. but if the player can just put it in the crafting table, then that is broken. Thanks for responding tho!
     
  10. Offline

    Zombie_Striker

    @DarthAimbot
    I'm not sure if Bukkit listens for when players use the number keys. You may need to listen to InventoryClickEvent/InvnetoryEvent and manually check if the iron bars are in that slot. Then, if it isn't, close the inventory and re-add the item.
     
Thread Status:
Not open for further replies.

Share This Page