SPIGOT-3308: RecipeIterator cannot longer remove recipes

This commit is contained in:
md_5 2019-09-07 17:07:36 +10:00
parent 023f438cca
commit 7ef2b20d0b

View File

@ -1,29 +1,42 @@
package org.bukkit.craftbukkit.inventory;
import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap;
import java.util.Iterator;
import java.util.Map;
import net.minecraft.server.IRecipe;
import net.minecraft.server.MinecraftKey;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.Recipes;
import org.bukkit.inventory.Recipe;
public class RecipeIterator implements Iterator<Recipe> {
private final Iterator<IRecipe<?>> recipes;
private final Iterator<Map.Entry<Recipes<?>, Object2ObjectLinkedOpenHashMap<MinecraftKey, IRecipe<?>>>> recipes;
private Iterator<IRecipe<?>> current;
public RecipeIterator() {
this.recipes = MinecraftServer.getServer().getCraftingManager().b().iterator();
this.recipes = MinecraftServer.getServer().getCraftingManager().recipes.entrySet().iterator();
}
@Override
public boolean hasNext() {
return recipes.hasNext();
return (current != null && current.hasNext()) || recipes.hasNext();
}
@Override
public Recipe next() {
return recipes.next().toBukkitRecipe();
if (current == null || !current.hasNext()) {
current = recipes.next().getValue().values().iterator();
}
return current.next().toBukkitRecipe();
}
@Override
public void remove() {
recipes.remove();
if (current == null) {
throw new IllegalStateException("next() not yet called");
}
current.remove();
}
}