mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 06:50:12 +01:00
SPIGOT-3308: RecipeIterator cannot longer remove recipes
This commit is contained in:
parent
023f438cca
commit
7ef2b20d0b
1 changed files with 18 additions and 5 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue