From 7ef2b20d0b37bf991a18555f676c877312a2befd Mon Sep 17 00:00:00 2001 From: md_5 Date: Sat, 7 Sep 2019 17:07:36 +1000 Subject: [PATCH] SPIGOT-3308: RecipeIterator cannot longer remove recipes --- .../craftbukkit/inventory/RecipeIterator.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/RecipeIterator.java b/src/main/java/org/bukkit/craftbukkit/inventory/RecipeIterator.java index 33fd782642..1223bfc7f5 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/RecipeIterator.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/RecipeIterator.java @@ -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 { - private final Iterator> recipes; + private final Iterator, Object2ObjectLinkedOpenHashMap>>> recipes; + private Iterator> 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(); } }