From 0adc1c31926aaa1ef4a9e70b2db7a0b93b70647a Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Sat, 6 Feb 2021 01:55:54 +0100 Subject: [PATCH] The Enhanced Auto Crafter now requires confirmation too --- .../auto_crafters/EnhancedAutoCrafter.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/EnhancedAutoCrafter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/EnhancedAutoCrafter.java index e6827c64f..55bb09b1c 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/EnhancedAutoCrafter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/auto_crafters/EnhancedAutoCrafter.java @@ -4,6 +4,8 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; import javax.annotation.ParametersAreNonnullByDefault; +import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.Sound; import org.bukkit.block.Block; import org.bukkit.block.BlockState; @@ -12,8 +14,12 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.cscorelib2.data.PersistentDataAPI; +import io.github.thebusybiscuit.cscorelib2.item.CustomItem; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin; +import io.github.thebusybiscuit.slimefun4.implementation.tasks.AsyncRecipeChoiceTask; +import io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils; import io.papermc.lib.PaperLib; +import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu; import me.mrCookieSlime.Slimefun.Lists.RecipeType; import me.mrCookieSlime.Slimefun.Objects.Category; import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem; @@ -55,10 +61,31 @@ public class EnhancedAutoCrafter extends AbstractAutoCrafter { AbstractRecipe recipe = AbstractRecipe.of(item); if (recipe != null) { - setSelectedRecipe(b, recipe); + ChestMenu menu = new ChestMenu(getItemName()); + menu.setPlayerInventoryClickable(false); + menu.setEmptySlotsClickable(false); + + ChestMenuUtils.drawBackground(menu, background); + ChestMenuUtils.drawBackground(menu, 45, 46, 47, 48, 50, 51, 52, 53); + + menu.addItem(49, new CustomItem(Material.CRAFTING_TABLE, ChatColor.GREEN + SlimefunPlugin.getLocalization().getMessage(p, "messages.auto-crafting.select"))); + menu.addMenuClickHandler(49, (pl, stack, slot, action) -> { + setSelectedRecipe(b, recipe); + p.playSound(p.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1); + SlimefunPlugin.getLocalization().sendMessage(p, "messages.auto-crafting.recipe-set"); + showRecipe(p, b, recipe); + return false; + }); + + AsyncRecipeChoiceTask task = new AsyncRecipeChoiceTask(); + recipe.show(menu, task); + menu.open(p); + p.playSound(p.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1); - SlimefunPlugin.getLocalization().sendMessage(p, "messages.auto-crafting.recipe-set"); - showRecipe(p, b, recipe); + + if (!task.isEmpty()) { + task.start(menu.toInventory()); + } } else { SlimefunPlugin.getLocalization().sendMessage(p, "messages.auto-crafting.no-recipes"); }