Disable any crafting recipe that uses certain items?

Discussion in 'Plugin Development' started by Hedgehogs4Me, Apr 10, 2014.

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

    Hedgehogs4Me

    Hi Bukkit people. Sorry if the following sounds incredibly stupid, but I'm still, shall we say, working on some fundamentals.

    I was trying to figure out how to do something that sounds incredibly easy: disable any crafting recipe that uses certain items as ingredients (in my case, gold and diamonds). Now, I can quite easily ban the creation of any diamond or gold tools/armor by cancelling a PrepareItemCraftEvent if a list contains event.getRecipe().getResult().getType(), but I figured it'd be a lot cleaner and more supportive of future versions or other plugins if I could just have it search for recipes that contain diamonds or gold and do it that way.

    Is this possible? I've been checking through docs everywhere and I can't find anything. In the meantime I'll just list everything, but I'll feel terrible while doing it.

    EDIT: result.name().contains("GOLD") / ("DIAMOND") makes it a little shorter and probably less resource intensive, but it really is ugly as all sin so I'd still prefer if I could do it the way I'm asking about.
     
  2. Offline

    Timbo_KZ

    Hedgehogs4Me
    result.name().contains("GOLD") / ("DIAMOND") is not the best way to do it as you can't be 100% sure the name will contain gold or diamond, e.g. the clock. I've just taken a look the JavaDocs and it looks like Recipe object doesn't have something like .contains(), so I think the best way to do this is to get the crafting inventory (event.getInventory()) and then get an array of ItemStack's in the recipe (event.getInventory().getMatrix()). Finally, iterate through the array and check if it contains given items.

    Btw, I've never done this before and all my knowledge come from JavaDocs. Always thoroughly read JavaDocs.
    http://jd.bukkit.org/beta/doxygen/d...tEvent.html#a7f883fa98121362cfffa3e5128f667f9
    http://jd.bukkit.org/beta/doxygen/d...bukkit_1_1inventory_1_1CraftingInventory.html
     
Thread Status:
Not open for further replies.

Share This Page