From 0a823c33c7564e7970d31b506b8fab0b1f71cd47 Mon Sep 17 00:00:00 2001 From: NichtStudioCode <51272202+NichtStudioCode@users.noreply.github.com> Date: Fri, 7 Jan 2022 15:32:18 +0100 Subject: [PATCH] Structure#addIngredient(inventory, background) --- .../invui/gui/builder/GUIBuilder.java | 6 +++++ .../invui/gui/structure/Structure.java | 22 ++++++++++++------- .../gui/structure/VISlotElementSupplier.java | 7 ++++-- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/InvUI/src/main/java/de/studiocode/invui/gui/builder/GUIBuilder.java b/InvUI/src/main/java/de/studiocode/invui/gui/builder/GUIBuilder.java index caa29a7..5711566 100644 --- a/InvUI/src/main/java/de/studiocode/invui/gui/builder/GUIBuilder.java +++ b/InvUI/src/main/java/de/studiocode/invui/gui/builder/GUIBuilder.java @@ -10,6 +10,7 @@ import de.studiocode.invui.virtualinventory.VirtualInventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ShapedRecipe; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.function.Supplier; @@ -60,6 +61,11 @@ public class GUIBuilder { return this; } + public GUIBuilder addIngredient(char key, @NotNull VirtualInventory inventory, @Nullable ItemProvider background) { + context.getStructure().addIngredient(key, inventory, background); + return this; + } + public GUIBuilder addIngredient(char key, @NotNull SlotElement element) { context.getStructure().addIngredient(key, element); return this; diff --git a/InvUI/src/main/java/de/studiocode/invui/gui/structure/Structure.java b/InvUI/src/main/java/de/studiocode/invui/gui/structure/Structure.java index b7acfff..8f4cc5b 100644 --- a/InvUI/src/main/java/de/studiocode/invui/gui/structure/Structure.java +++ b/InvUI/src/main/java/de/studiocode/invui/gui/structure/Structure.java @@ -11,6 +11,7 @@ import de.studiocode.invui.virtualinventory.VirtualInventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ShapedRecipe; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.function.Supplier; @@ -63,45 +64,50 @@ public class Structure implements Cloneable { } public Structure addIngredient(char key, @NotNull ItemStack itemStack) { - if (ingredientList != null) throw new UnsupportedOperationException("Structure is locked"); + if (ingredientList != null) throw new IllegalStateException("Structure is locked"); return addIngredient(key, new ItemWrapper(itemStack)); } public Structure addIngredient(char key, @NotNull ItemProvider itemProvider) { - if (ingredientList != null) throw new UnsupportedOperationException("Structure is locked"); + if (ingredientList != null) throw new IllegalStateException("Structure is locked"); return addIngredient(key, new SimpleItem(itemProvider)); } public Structure addIngredient(char key, @NotNull Item item) { - if (ingredientList != null) throw new UnsupportedOperationException("Structure is locked"); + if (ingredientList != null) throw new IllegalStateException("Structure is locked"); return addIngredient(key, new ItemSlotElement(item)); } public Structure addIngredient(char key, @NotNull VirtualInventory inventory) { - if (ingredientList != null) throw new UnsupportedOperationException("Structure is locked"); + if (ingredientList != null) throw new IllegalStateException("Structure is locked"); return addIngredientElementSupplier(key, new VISlotElementSupplier(inventory)); } + public Structure addIngredient(char key, @NotNull VirtualInventory inventory, @Nullable ItemProvider background) { + if (ingredientList != null) throw new IllegalStateException("Structure is locked"); + return addIngredientElementSupplier(key, new VISlotElementSupplier(inventory, background)); + } + public Structure addIngredient(char key, @NotNull SlotElement element) { - if (ingredientList != null) throw new UnsupportedOperationException("Structure is locked"); + if (ingredientList != null) throw new IllegalStateException("Structure is locked"); ingredientMap.put(key, new Ingredient(element)); return this; } public Structure addIngredient(char key, @NotNull String marker) { - if (ingredientList != null) throw new UnsupportedOperationException("Structure is locked"); + if (ingredientList != null) throw new IllegalStateException("Structure is locked"); ingredientMap.put(key, new Ingredient(marker)); return this; } public Structure addIngredient(char key, @NotNull Supplier itemSupplier) { - if (ingredientList != null) throw new UnsupportedOperationException("Structure is locked"); + if (ingredientList != null) throw new IllegalStateException("Structure is locked"); ingredientMap.put(key, new Ingredient(() -> new ItemSlotElement(itemSupplier.get()))); return this; } public Structure addIngredientElementSupplier(char key, @NotNull Supplier elementSupplier) { - if (ingredientList != null) throw new UnsupportedOperationException("Structure is locked"); + if (ingredientList != null) throw new IllegalStateException("Structure is locked"); ingredientMap.put(key, new Ingredient(elementSupplier)); return this; } diff --git a/InvUI/src/main/java/de/studiocode/invui/gui/structure/VISlotElementSupplier.java b/InvUI/src/main/java/de/studiocode/invui/gui/structure/VISlotElementSupplier.java index d369b27..9b5dcaf 100644 --- a/InvUI/src/main/java/de/studiocode/invui/gui/structure/VISlotElementSupplier.java +++ b/InvUI/src/main/java/de/studiocode/invui/gui/structure/VISlotElementSupplier.java @@ -3,6 +3,8 @@ package de.studiocode.invui.gui.structure; import de.studiocode.invui.gui.SlotElement.VISlotElement; import de.studiocode.invui.item.ItemProvider; import de.studiocode.invui.virtualinventory.VirtualInventory; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.function.Supplier; @@ -12,16 +14,17 @@ public class VISlotElementSupplier implements Supplier { private final ItemProvider background; private int slot = -1; - public VISlotElementSupplier(VirtualInventory inventory) { + public VISlotElementSupplier(@NotNull VirtualInventory inventory) { this.inventory = inventory; this.background = null; } - public VISlotElementSupplier(VirtualInventory inventory, ItemProvider background) { + public VISlotElementSupplier(@NotNull VirtualInventory inventory, @Nullable ItemProvider background) { this.inventory = inventory; this.background = background; } + @NotNull @Override public VISlotElement get() { if (++slot == inventory.getSize()) slot = 0;