Solved Ban Recipes!

Discussion in 'Plugin Development' started by JoeyDevs, Nov 22, 2014.

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

    JoeyDevs

    Hey Guys,

    I wanna ban crafting recipes but how?
    Can anyone help me out because A exisitng plugin is no option.
     
  2. Offline

    Googlelover1234

  3. Offline

    JoeyDevs

    Oke Thanks, And then with getresult?
     
  4. Offline

    Googlelover1234

    JoeyDevs
    So getResult returns an ItemStack, so yes, you check the type of the ItemStack, and if you don't want it, setResult as air.
     
  5. Offline

    JoeyDevs

    On what event should i put it? I'm searching trough to the list but i cannot find a craft event or something!
     
  6. Offline

    Googlelover1234

    JoeyDevs
    It doesn't extend Event, so it wouldn't go into any event. Let me look up how to use it.
    EDIT: Alright, so it extends Inventory, so you'd create a new Crafting Inventory, and you can use its methods.

    Something like this:

    Code:java
    1. Inventory inv;
    2.  
    3. inv = Bukkit.createInventory(null, InventoryType.CRAFTING);
     
  7. Offline

    TeddyTheTeddy

    You can create a listener that uses the CraftItemEvent, then check what the recipe's result is. If it is the banned item cancel the event.
     
  8. Offline

    mrCookieSlime

    JoeyDevs
    Actually the best method for disabling recipes would be to iterate through all Recipes and remove the one you want to ban from the Recipe List.

    Code:java
    1. Iterator<Recipe> recipes = Bukkit.recipeIterator();
    2. Recipe recipe;
    3. while (recipes.hasNext()) {
    4. recipe = recipes.next();
    5. if (recipe != null && recipe.getResult().isSimilar(yourItem) {
    6. recipes.remove();
    7. }
    8. }


    Put this in your onEnable method.
     
  9. Offline

    JoeyDevs

    Thanks I heard about this a while ago but cannot find it back!

    Thanks to everyone that helped me out but this was the one I needed!


    Problem: SOLVED
     
Thread Status:
Not open for further replies.

Share This Page