[1.9-1.16] Custom Recipes and Crafting (CraftEnhance)

[1.9-1.16] Custom Recipes and Crafting (CraftEnhance)

44.3k Downloads

i found a thing to improve

Johvu opened this issue ยท 4 comments

commented

So I found a thing to improve in the code at CraftEnhance there is getserver.resetRecipes(); that makes some plugins that interfere crafting to duplicate items

commented

I've added this. Thanks for the suggestion.

commented

Basically some plugins register the recipes via the Bukkit api but also save them in their own data structures to handle them later.
Removing them using the bukkit api via Bukkit.resetRecipes() breaks these plugins.

An easy fix to avoid breaking other plugins is that one, basically you just have to check if the recipe has CraftEnhance namespace to avoid removing other plugins recipes (code not tested but should work if the namespace is correct) .

Iterator<Recipe> it = Bukkit.getServer().recipeIterator();
while (it.hasNext()) {
  Recipe r = it.next();
  // do your comparisions with the recipe
  if(recipe instanceof Keyed)
  {
    if(((Keyed) recipe).getKey().getNamespace().equals("craftenhance"))
    {
      it.remove();
    }
  }
}

Here is the code that should be changed, I think it's the only problematic one

Also refer to this warning

Messenger.Message("WARN: This reload function is causing some issues currently. It's being worked on.");

commented

Should be modifiable, I'm quite sure since I think I use a similar method in my plugins, to avoid breaking others :D

Let me know if you need more help

commented

Thank you for your suggestion. I had the impression that the iterator was immutable, that's why I was using Bukkit.resetRecipes(), but I'm sure you're right in that it's not.