diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/AutoCrafterListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/AutoCrafterListener.java index 27a1a8dca..d9d9f9b32 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/AutoCrafterListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/AutoCrafterListener.java @@ -1,6 +1,5 @@ package io.github.thebusybiscuit.slimefun4.implementation.listeners; -import java.util.List; import java.util.Optional; import javax.annotation.ParametersAreNonnullByDefault; @@ -8,13 +7,12 @@ import javax.annotation.ParametersAreNonnullByDefault; import org.bukkit.GameRule; import org.bukkit.Keyed; import org.bukkit.NamespacedKey; -import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.event.Event.Result; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.inventory.EquipmentSlot; -import org.bukkit.entity.Player; +import org.bukkit.inventory.Recipe; import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; @@ -22,7 +20,8 @@ import io.github.thebusybiscuit.slimefun4.implementation.items.autocrafters.Abst import io.github.thebusybiscuit.slimefun4.implementation.items.autocrafters.EnhancedAutoCrafter; import io.github.thebusybiscuit.slimefun4.implementation.items.electric.gadgets.Multimeter; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; -import org.bukkit.inventory.Recipe; + +import static org.bukkit.Bukkit.getRecipesFor; /** * This {@link Listener} is responsible for providing interactions to the auto crafters. @@ -45,11 +44,8 @@ public class AutoCrafterListener implements Listener { @EventHandler public void onInteract(PlayerRightClickEvent e) { Optional clickedBlock = e.getClickedBlock(); - List recipes = org.bukkit.Bukkit.getRecipesFor(e.getItem()); - Player p = e.getPlayer(); - World w = p.getWorld(); NamespacedKey recipeKey; - Boolean unlocked = true; + boolean unlocked = true; // We want to make sure we used the main hand, the interaction was not cancelled and a Block was clicked. if (e.getHand() == EquipmentSlot.HAND && e.useBlock() != Result.DENY && clickedBlock.isPresent()) { @@ -71,16 +67,17 @@ public class AutoCrafterListener implements Listener { } // Check if the recipe of the item is disabled. - for (Recipe recipe : recipes) { + for (Recipe recipe : getRecipesFor(e.getItem())) { recipeKey = ((Keyed) recipe).getKey(); - if (!p.hasDiscoveredRecipe(recipeKey)) { + if (!e.getPlayer().hasDiscoveredRecipe(recipeKey)) { unlocked = false; + break; } } - if (w.getGameRuleValue(GameRule.DO_LIMITED_CRAFTING) && !unlocked){ + if (e.getPlayer().getWorld().getGameRuleValue(GameRule.DO_LIMITED_CRAFTING) && !unlocked) { e.cancel(); - SlimefunPlugin.getLocalization().sendMessage(p, "messages.auto-crafting.recipe-disabled"); + SlimefunPlugin.getLocalization().sendMessage(e.getPlayer(), "messages.auto-crafting.recipe-disabled"); return; }