From 0098037647cf474aaf1653b5e9ea90e7e9f16580 Mon Sep 17 00:00:00 2001 From: ShaneBee Date: Sun, 2 Feb 2020 10:32:49 +1100 Subject: [PATCH] #618: Add method to remove a recipe by its key --- .../java/org/bukkit/craftbukkit/CraftServer.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 0dfe176b4e..8d1aba5354 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -41,6 +41,7 @@ import java.util.function.Consumer; import java.util.logging.Level; import java.util.logging.Logger; import javax.imageio.ImageIO; +import it.unimi.dsi.fastutil.objects.Object2ObjectLinkedOpenHashMap; import jline.console.ConsoleReader; import net.minecraft.server.Advancement; import net.minecraft.server.ArgumentEntity; @@ -58,6 +59,7 @@ import net.minecraft.server.Enchantments; import net.minecraft.server.EntityPlayer; import net.minecraft.server.EnumDifficulty; import net.minecraft.server.EnumGamemode; +import net.minecraft.server.IRecipe; import net.minecraft.server.Item; import net.minecraft.server.ItemWorldMap; import net.minecraft.server.Items; @@ -1117,6 +1119,20 @@ public final class CraftServer implements Server { console.reload(); // Not ideal but hard to reload a subset of a resource pack } + @Override + public boolean removeRecipe(NamespacedKey recipeKey) { + Preconditions.checkArgument(recipeKey != null, "recipeKey == null"); + + MinecraftKey mcKey = CraftNamespacedKey.toMinecraft(recipeKey); + for (Object2ObjectLinkedOpenHashMap> recipes : getServer().getCraftingManager().recipes.values()) { + if (recipes.remove(mcKey) != null) { + return true; + } + } + + return false; + } + @Override public Map getCommandAliases() { ConfigurationSection section = commandsConfiguration.getConfigurationSection("aliases");