From 07d93c2765858d142513dd8ba4d1d00593929524 Mon Sep 17 00:00:00 2001 From: NichtStudioCode <51272202+NichtStudioCode@users.noreply.github.com> Date: Sun, 26 Feb 2023 16:44:07 +0100 Subject: [PATCH] Added some javadoc comments --- .../xyz/xenondevs/invui/gui/PagedGui.java | 4 +- .../xyz/xenondevs/invui/gui/ScrollGui.java | 6 +- .../invui/gui/structure/Ingredient.java | 49 ++++- .../invui/gui/structure/IngredientList.java | 26 ++- .../xenondevs/invui/gui/structure/Marker.java | 5 + .../invui/gui/structure/Markers.java | 5 +- .../invui/gui/structure/Structure.java | 191 ++++++++++++++++-- .../xenondevs/invui/window/AnvilWindow.java | 66 +++++- .../invui/window/CartographyWindow.java | 63 ++++++ 9 files changed, 385 insertions(+), 30 deletions(-) diff --git a/invui/src/main/java/xyz/xenondevs/invui/gui/PagedGui.java b/invui/src/main/java/xyz/xenondevs/invui/gui/PagedGui.java index 77f4057..7f71256 100644 --- a/invui/src/main/java/xyz/xenondevs/invui/gui/PagedGui.java +++ b/invui/src/main/java/xyz/xenondevs/invui/gui/PagedGui.java @@ -33,7 +33,7 @@ public interface PagedGui extends Gui { * @return The created {@link PagedGui}. */ static @NotNull PagedGui<@NotNull Item> items(@NotNull Consumer<@NotNull Builder<@NotNull Item>> consumer) { - Builder<@NotNull Item> builder = items(); + Builder builder = items(); consumer.accept(builder); return builder.build(); } @@ -78,7 +78,7 @@ public interface PagedGui extends Gui { * @return The created {@link PagedGui}. */ static @NotNull PagedGui<@NotNull Gui> guis(@NotNull Consumer<@NotNull Builder<@NotNull Gui>> consumer) { - Builder<@NotNull Gui> builder = guis(); + Builder builder = guis(); consumer.accept(builder); return builder.build(); } diff --git a/invui/src/main/java/xyz/xenondevs/invui/gui/ScrollGui.java b/invui/src/main/java/xyz/xenondevs/invui/gui/ScrollGui.java index d953205..e691cc2 100644 --- a/invui/src/main/java/xyz/xenondevs/invui/gui/ScrollGui.java +++ b/invui/src/main/java/xyz/xenondevs/invui/gui/ScrollGui.java @@ -30,7 +30,7 @@ public interface ScrollGui extends Gui { * @return The created {@link ScrollGui}. */ static @NotNull ScrollGui<@NotNull Item> items(@NotNull Consumer<@NotNull Builder<@NotNull Item>> consumer) { - Builder<@NotNull Item> builder = items(); + Builder builder = items(); consumer.accept(builder); return builder.build(); } @@ -76,7 +76,7 @@ public interface ScrollGui extends Gui { * @return The created {@link ScrollGui}. */ static @NotNull ScrollGui<@NotNull Gui> guis(@NotNull Consumer<@NotNull Builder<@NotNull Gui>> consumer) { - Builder<@NotNull Gui> builder = guis(); + Builder builder = guis(); consumer.accept(builder); return builder.build(); } @@ -122,7 +122,7 @@ public interface ScrollGui extends Gui { * @return The created {@link ScrollGui}. */ static @NotNull ScrollGui<@NotNull VirtualInventory> inventories(@NotNull Consumer<@NotNull Builder<@NotNull VirtualInventory>> consumer) { - Builder<@NotNull VirtualInventory> builder = inventories(); + Builder builder = inventories(); consumer.accept(builder); return builder.build(); } diff --git a/invui/src/main/java/xyz/xenondevs/invui/gui/structure/Ingredient.java b/invui/src/main/java/xyz/xenondevs/invui/gui/structure/Ingredient.java index 9c7e2eb..3cce4b3 100644 --- a/invui/src/main/java/xyz/xenondevs/invui/gui/structure/Ingredient.java +++ b/invui/src/main/java/xyz/xenondevs/invui/gui/structure/Ingredient.java @@ -1,5 +1,7 @@ package xyz.xenondevs.invui.gui.structure; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import xyz.xenondevs.invui.gui.SlotElement; import java.util.function.Supplier; @@ -10,36 +12,73 @@ class Ingredient { private final Marker marker; private final Supplier elementSupplier; - public Ingredient(SlotElement slotElement) { + /** + * Creates a new {@link Ingredient} of the specified {@link SlotElement}. + * + * @param slotElement The {@link SlotElement}. + */ + public Ingredient(@NotNull SlotElement slotElement) { this.slotElement = slotElement; this.elementSupplier = null; this.marker = null; } - public Ingredient(Supplier elementSupplier) { + /** + * Creates a new {@link Ingredient} of the specified {@link SlotElement} {@link Supplier}. + * The {@link Supplier} will be invoked for each slot that the {@link Ingredient} is placed on. + * + * @param elementSupplier The {@link Supplier}. + */ + public Ingredient(@NotNull Supplier elementSupplier) { this.elementSupplier = elementSupplier; this.slotElement = null; this.marker = null; } - public Ingredient(Marker marker) { + /** + * Creates a new {@link Ingredient} of the specified {@link Marker}. + * + * @param marker The {@link Marker}. + */ + public Ingredient(@NotNull Marker marker) { this.marker = marker; this.slotElement = null; this.elementSupplier = null; } - public SlotElement getSlotElement() { + /** + * Gets the {@link SlotElement} of this {@link Ingredient}. + * + * @return The {@link SlotElement} or null if this {@link Ingredient} is a {@link Marker}. + */ + public @Nullable SlotElement getSlotElement() { return slotElement == null ? elementSupplier.get() : slotElement; } - public Marker getMarker() { + /** + * Gets the {@link Marker} of this {@link Ingredient}. + * + * @return The {@link Marker} or null if this {@link Ingredient} is a {@link SlotElement} or a {@link Supplier} + * for {@link SlotElement SlotElements}. + */ + public @Nullable Marker getMarker() { return marker; } + /** + * Checks if this {@link Ingredient} is a {@link SlotElement} or a {@link Supplier} for {@link SlotElement SlotElements}. + * + * @return Whether this {@link Ingredient} is a {@link SlotElement}. + */ public boolean isSlotElement() { return slotElement != null || elementSupplier != null; } + /** + * Checks if this {@link Ingredient} is a {@link Marker}. + * + * @return Whether this {@link Ingredient} is a {@link Marker}. + */ public boolean isMarker() { return marker != null; } diff --git a/invui/src/main/java/xyz/xenondevs/invui/gui/structure/IngredientList.java b/invui/src/main/java/xyz/xenondevs/invui/gui/structure/IngredientList.java index d105441..5151aa6 100644 --- a/invui/src/main/java/xyz/xenondevs/invui/gui/structure/IngredientList.java +++ b/invui/src/main/java/xyz/xenondevs/invui/gui/structure/IngredientList.java @@ -13,6 +13,14 @@ public class IngredientList extends ArrayList { private final int width; private final int height; + /** + * Creates a new {@link IngredientList}. + * + * @param width The width of the structure. + * @param height The height of the structure. + * @param structure The structure string. + * @param ingredientMap The {@link HashMap} containing the {@link Ingredient Ingredients}. + */ public IngredientList(int width, int height, String structure, HashMap ingredientMap) { this.width = width; this.height = height; @@ -24,6 +32,11 @@ public class IngredientList extends ArrayList { } } + /** + * Inserts the {@link Ingredient Ingredients} into the specified {@link Gui}. + * + * @param gui The {@link Gui}. + */ public void insertIntoGui(Gui gui) { if (size() != gui.getSize()) throw new IllegalArgumentException("Structure size does not match Gui size"); @@ -47,7 +60,7 @@ public class IngredientList extends ArrayList { } - public List findIndicesOfVerticalMarker(Marker marker) { + private List findIndicesOfVerticalMarker(Marker marker) { List indices = new ArrayList<>(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { @@ -61,6 +74,12 @@ public class IngredientList extends ArrayList { return indices; } + /** + * Finds all indices of the specified {@link Marker}. + * + * @param marker The {@link Marker}. + * @return The indices. + */ public int[] findIndicesOfMarker(Marker marker) { List indices; if (marker.isHorizontal()) { @@ -72,6 +91,11 @@ public class IngredientList extends ArrayList { return indices.stream().mapToInt(Integer::intValue).toArray(); } + /** + * Finds all indices of the {@link Markers#CONTENT_LIST_SLOT_HORIZONTAL} and {@link Markers#CONTENT_LIST_SLOT_VERTICAL} {@link Marker Markers}. + * + * @return The indices. + */ public int[] findContentListSlots() { return Stream.concat( findIndicesOfHorizontalMarker(Markers.CONTENT_LIST_SLOT_HORIZONTAL).stream(), diff --git a/invui/src/main/java/xyz/xenondevs/invui/gui/structure/Marker.java b/invui/src/main/java/xyz/xenondevs/invui/gui/structure/Marker.java index 8192365..2b4dc2b 100644 --- a/invui/src/main/java/xyz/xenondevs/invui/gui/structure/Marker.java +++ b/invui/src/main/java/xyz/xenondevs/invui/gui/structure/Marker.java @@ -1,5 +1,10 @@ package xyz.xenondevs.invui.gui.structure; +/** + * Used to mark slots in a {@link Structure} as special slots. + * + * @see Markers + */ public class Marker { private final boolean horizontal; diff --git a/invui/src/main/java/xyz/xenondevs/invui/gui/structure/Markers.java b/invui/src/main/java/xyz/xenondevs/invui/gui/structure/Markers.java index 1e6d5b4..a766203 100644 --- a/invui/src/main/java/xyz/xenondevs/invui/gui/structure/Markers.java +++ b/invui/src/main/java/xyz/xenondevs/invui/gui/structure/Markers.java @@ -1,5 +1,6 @@ package xyz.xenondevs.invui.gui.structure; +import org.jetbrains.annotations.NotNull; import xyz.xenondevs.invui.gui.AbstractPagedGui; import xyz.xenondevs.invui.gui.AbstractScrollGui; import xyz.xenondevs.invui.gui.AbstractTabGui; @@ -13,12 +14,12 @@ public class Markers { * The marker for horizontal content list slots in {@link AbstractPagedGui PagedGuis}, * {@link AbstractScrollGui ScrollGuis} and {@link AbstractTabGui TabGuis} */ - public static final Marker CONTENT_LIST_SLOT_HORIZONTAL = new Marker(true); + public static final @NotNull Marker CONTENT_LIST_SLOT_HORIZONTAL = new Marker(true); /** * The marker for vertical content list slots in {@link AbstractPagedGui PagedGuis}, * {@link AbstractScrollGui ScrollGuis} and {@link AbstractTabGui TabGuis} */ - public static final Marker CONTENT_LIST_SLOT_VERTICAL = new Marker(false); + public static final @NotNull Marker CONTENT_LIST_SLOT_VERTICAL = new Marker(false); } diff --git a/invui/src/main/java/xyz/xenondevs/invui/gui/structure/Structure.java b/invui/src/main/java/xyz/xenondevs/invui/gui/structure/Structure.java index 1a42bf0..4a68dc4 100644 --- a/invui/src/main/java/xyz/xenondevs/invui/gui/structure/Structure.java +++ b/invui/src/main/java/xyz/xenondevs/invui/gui/structure/Structure.java @@ -2,6 +2,7 @@ package xyz.xenondevs.invui.gui.structure; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ShapedRecipe; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import xyz.xenondevs.invui.gui.Gui; @@ -32,11 +33,24 @@ public class Structure implements Cloneable { private HashMap ingredientMap = new HashMap<>(); private IngredientList ingredientList; - public Structure(String... structureData) { + /** + * Sets the {@link Structure} of the {@link Gui} using the given structure data Strings. + * Each String is interpreted as a row of the {@link Gui}. All Strings must have the same length. + * + * @param structureData The structure data + */ + public Structure(@NotNull String @NotNull ... structureData) { this(sanitize(structureData[0]).length(), structureData.length, String.join("", structureData)); } - public Structure(int width, int height, String structureData) { + /** + * Sets the {@link Structure} of the {@link Gui} using the given structure data, width and height. + * + * @param width The width of the {@link Gui} + * @param height The height of the {@link Gui} + * @param structureData The structure data + */ + public Structure(int width, int height, @NotNull String structureData) { this.width = width; this.height = height; this.structureData = sanitize(structureData); @@ -49,84 +63,219 @@ public class Structure implements Cloneable { return s.replace(" ", "").replace("\n", ""); } + /** + * Adds a global {@link ItemStack} ingredient under the given key. + * Global ingredients will be used for all {@link Structure Structures} which do not have an ingredient defined for + * that key. + * + * @param key The key of the ingredient + * @param itemStack The {@link ItemStack} ingredient + */ public static void addGlobalIngredient(char key, @NotNull ItemStack itemStack) { addGlobalIngredient(key, new ItemWrapper(itemStack)); } + /** + * Adds a global {@link ItemProvider} ingredient under the given key. + * Global ingredients will be used for all {@link Structure Structures} which do not have an ingredient defined for + * that key. + * + * @param key The key of the ingredient + * @param itemProvider The {@link ItemProvider} ingredient + */ public static void addGlobalIngredient(char key, @NotNull ItemProvider itemProvider) { addGlobalIngredient(key, new SimpleItem(itemProvider)); } + /** + * Adds a global {@link Item} ingredient under the given key. + * Global ingredients will be used for all {@link Structure Structures} which do not have an ingredient defined for + * that key. + * + * @param key The key of the ingredient + * @param item The {@link Item} ingredient + */ public static void addGlobalIngredient(char key, @NotNull Item item) { addGlobalIngredient(key, new ItemSlotElement(item)); } + /** + * Adds a global {@link Item} {@link Supplier} ingredient under the given key. + * Global ingredients will be used for all {@link Structure Structures} which do not have an ingredient defined for + * that key. + * + * @param key The key of the ingredient + * @param itemSupplier The {@link Item} {@link Supplier} ingredient + */ public static void addGlobalIngredient(char key, @NotNull Supplier itemSupplier) { addGlobalIngredientElementSupplier(key, () -> new ItemSlotElement(itemSupplier.get())); } + /** + * Adds a global {@link SlotElement} ingredient under the given key. + * Global ingredients will be used for all {@link Structure Structures} which do not have an ingredient defined for + * that key. + * + * @param key The key of the ingredient + * @param element The {@link SlotElement} ingredient + */ public static void addGlobalIngredient(char key, @NotNull SlotElement element) { globalIngredientMap.put(key, new Ingredient(element)); } + /** + * Adds a global {@link Marker} ingredient under the given key. + * Global ingredients will be used for all {@link Structure Structures} which do not have an ingredient defined for + * that key. + * + * @param key The key of the ingredient + * @param marker The {@link Marker} ingredient + */ public static void addGlobalIngredient(char key, @NotNull Marker marker) { globalIngredientMap.put(key, new Ingredient(marker)); } + /** + * Adds a global {@link SlotElement} {@link Supplier} ingredient under the given key. + * Global ingredients will be used for all {@link Structure Structures} which do not have an ingredient defined for + * that key. + * + * @param key The key of the ingredient + * @param elementSupplier The {@link SlotElement} {@link Supplier} ingredient + */ public static void addGlobalIngredientElementSupplier(char key, @NotNull Supplier elementSupplier) { globalIngredientMap.put(key, new Ingredient(elementSupplier)); } - public Structure addIngredient(char key, @NotNull ItemStack itemStack) { + /** + * Adds an {@link ItemStack} ingredient under the given key. + * + * @param key The key of the ingredient + * @param itemStack The {@link ItemStack} ingredient + * @return This {@link Structure} + */ + @Contract("_, _ -> this") + public @NotNull Structure addIngredient(char key, @NotNull ItemStack itemStack) { if (ingredientList != null) throw new IllegalStateException("Structure is locked"); return addIngredient(key, new ItemWrapper(itemStack)); } - public Structure addIngredient(char key, @NotNull ItemProvider itemProvider) { + /** + * Adds an {@link ItemProvider} ingredient under the given key. + * + * @param key The key of the ingredient + * @param itemProvider The {@link ItemProvider} ingredient + * @return This {@link Structure} + */ + @Contract("_, _ -> this") + public @NotNull Structure addIngredient(char key, @NotNull ItemProvider itemProvider) { if (ingredientList != null) throw new IllegalStateException("Structure is locked"); return addIngredient(key, new SimpleItem(itemProvider)); } - public Structure addIngredient(char key, @NotNull Item item) { + /** + * Adds an {@link Item} ingredient under the given key. + * + * @param key The key of the ingredient + * @param item The {@link Item} ingredient + * @return This {@link Structure} + */ + @Contract("_, _ -> this") + public @NotNull Structure addIngredient(char key, @NotNull Item item) { if (ingredientList != null) throw new IllegalStateException("Structure is locked"); return addIngredient(key, new ItemSlotElement(item)); } - public Structure addIngredient(char key, @NotNull VirtualInventory inventory) { + /** + * Adds a {@link VirtualInventory} ingredient under the given key. + * + * @param key The key of the ingredient + * @param inventory The {@link VirtualInventory} ingredient + * @return This {@link Structure} + */ + @Contract("_, _ -> this") + public @NotNull Structure addIngredient(char key, @NotNull VirtualInventory inventory) { 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) { + /** + * Adds a {@link VirtualInventory} ingredient under the given key. + * + * @param key The key of the ingredient + * @param inventory The {@link VirtualInventory} ingredient + * @param background The background {@link ItemProvider} for the {@link VirtualInventory} + * @return This {@link Structure} + */ + @Contract("_, _, _ -> this") + public @NotNull 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) { + /** + * Adds a {@link VirtualInventory} ingredient under the given key. + * + * @param key The key of the ingredient + * @param element The {@link SlotElement} ingredient + * @return This {@link Structure} + */ + @Contract("_, _ -> this") + public @NotNull Structure addIngredient(char key, @NotNull SlotElement element) { if (ingredientList != null) throw new IllegalStateException("Structure is locked"); ingredientMap.put(key, new Ingredient(element)); return this; } - public Structure addIngredient(char key, @NotNull Marker marker) { + /** + * Adds a {@link Marker} ingredient under the given key. + * + * @param key The key of the ingredient + * @param marker The {@link Marker} ingredient + * @return This {@link Structure} + */ + @Contract("_, _ -> this") + public @NotNull Structure addIngredient(char key, @NotNull Marker marker) { 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) { + /** + * Adds an {@link ItemStack} {@link Supplier} ingredient under the given key. + * + * @param key The key of the ingredient + * @param itemSupplier The {@link ItemStack} {@link Supplier} ingredient + * @return This {@link Structure} + */ + @Contract("_, _ -> this") + public @NotNull Structure addIngredient(char key, @NotNull Supplier itemSupplier) { 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) { + /** + * Adds a {@link SlotElement} {@link Supplier} ingredient under the given key. + * + * @param key The key of the ingredient + * @param elementSupplier The {@link SlotElement} {@link Supplier} ingredient + * @return This {@link Structure} + */ + @Contract("_, _ -> this") + public @NotNull Structure addIngredientElementSupplier(char key, @NotNull Supplier elementSupplier) { if (ingredientList != null) throw new IllegalStateException("Structure is locked"); ingredientMap.put(key, new Ingredient(elementSupplier)); return this; } - public IngredientList getIngredientList() { + /** + * Gets the {@link IngredientList} for this {@link Structure}. + * Calling this method will lock the {@link Structure} and prevent further changes. + * + * @return The {@link IngredientList} + */ + public @NotNull IngredientList getIngredientList() { if (ingredientList != null) return ingredientList; HashMap ingredients = new HashMap<>(globalIngredientMap); @@ -134,16 +283,32 @@ public class Structure implements Cloneable { return ingredientList = new IngredientList(width, height, structureData, ingredients); } + /** + * Gets the width of this {@link Structure}. + * + * @return The width + */ public int getWidth() { return width; } + /** + * Gets the height of this {@link Structure}. + * + * @return The height + */ public int getHeight() { return height; } + /** + * Clones this {@link Structure}. + * + * @return The cloned {@link Structure} + */ + @Contract(value = "-> new", pure = true) @Override - public Structure clone() { + public @NotNull Structure clone() { try { Structure clone = (Structure) super.clone(); clone.ingredientMap = new HashMap<>(ingredientMap); diff --git a/invui/src/main/java/xyz/xenondevs/invui/window/AnvilWindow.java b/invui/src/main/java/xyz/xenondevs/invui/window/AnvilWindow.java index 3a1d1af..90fe2b0 100644 --- a/invui/src/main/java/xyz/xenondevs/invui/window/AnvilWindow.java +++ b/invui/src/main/java/xyz/xenondevs/invui/window/AnvilWindow.java @@ -4,44 +4,102 @@ import org.bukkit.entity.Player; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import xyz.xenondevs.invui.gui.Gui; import java.util.List; import java.util.function.Consumer; +/** + * A {@link Window} that uses an anvil inventory. + */ public interface AnvilWindow extends Window { + /** + * Creates a new {@link Builder.Single Window Builder} for a single {@link AnvilWindow}. + * @return The new {@link Builder.Single Window Builder}. + */ static @NotNull Builder.Single single() { return new AnvilSingleWindowImpl.BuilderImpl(); } + /** + * Creates a new single {@link AnvilWindow} after configuring a {@link Builder.Single Window Builder} using the given {@link Consumer}. + * @param consumer The {@link Consumer} to configure the {@link Builder.Single Window Builder}. + * @return The created {@link AnvilWindow}. + */ static @NotNull AnvilWindow single(@NotNull Consumer consumer) { Builder.Single builder = single(); consumer.accept(builder); return builder.build(); } + /** + * Creates a new {@link Builder.Split Window Builder} for a split {@link AnvilWindow}. + * @return The new {@link Builder.Split Window Builder}. + */ static @NotNull Builder.Split split() { return new AnvilSplitWindowImpl.BuilderImpl(); } + /** + * Creates a new split {@link AnvilWindow} after configuring a {@link Builder.Split Window Builder} using the given {@link Consumer}. + * @param consumer The {@link Consumer} to configure the {@link Builder.Split Window Builder}. + * @return The created {@link AnvilWindow}. + */ static @NotNull AnvilWindow split(Consumer consumer) { Builder.Split builder = split(); consumer.accept(builder); return builder.build(); } + /** + * Gets the current rename text. + * @return The current rename text. + */ @Nullable String getRenameText(); + /** + * An {@link AnvilWindow} builder. + * @param The builder type. + * + * @see Window.Builder.Normal + * @see CartographyWindow.Builder + */ interface Builder> extends Window.Builder { - + + /** + * Sets the rename handlers of the {@link AnvilWindow}. + * @param renameHandlers The new rename handlers. + * @return The current builder. + */ @Contract("_ -> this") @NotNull S setRenameHandlers(@NotNull List<@NotNull Consumer> renameHandlers); - + + /** + * Adds a rename handler to the {@link AnvilWindow}. + * @param renameHandler The rename handler to add. + * @return The current builder. + */ @Contract("_ -> this") @NotNull S addRenameHandler(@NotNull Consumer renameHandler); - + + /** + * A single {@link AnvilWindow} builder. Combines both {@link AnvilWindow.Builder} and {@link Window.Builder.Single} + * for an {@link AnvilWindow} with only one {@link Gui} that does not access the {@link Player Player's} inventory. + * + * @see Window.Builder.Normal.Single + * @see CartographyWindow.Builder.Single + */ interface Single extends Builder, Window.Builder.Single {} - + + /** + * A split {@link AnvilWindow} builder. Combines both {@link AnvilWindow.Builder} and {@link Window.Builder.Double} + * for an {@link AnvilWindow} with two {@link Gui Guis}, where the lower {@link Gui} is used to fill the + * {@link Player Player's} inventory. + * + * @see Window.Builder.Normal.Split + * @see CartographyWindow.Builder.Split + */ interface Split extends Builder, Window.Builder.Double {} } diff --git a/invui/src/main/java/xyz/xenondevs/invui/window/CartographyWindow.java b/invui/src/main/java/xyz/xenondevs/invui/window/CartographyWindow.java index 54c0a62..49d7bf5 100644 --- a/invui/src/main/java/xyz/xenondevs/invui/window/CartographyWindow.java +++ b/invui/src/main/java/xyz/xenondevs/invui/window/CartographyWindow.java @@ -5,47 +5,110 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import xyz.xenondevs.inventoryaccess.map.MapIcon; import xyz.xenondevs.inventoryaccess.map.MapPatch; +import xyz.xenondevs.invui.gui.Gui; import java.util.List; import java.util.function.Consumer; +/** + * A {@link Window} that uses a cartography table inventory. + */ public interface CartographyWindow extends Window { + /** + * Creates a new {@link Builder.Single Window Builder} for a single {@link CartographyWindow}. + * + * @return The new {@link Builder.Single Window Builder}. + */ static @NotNull Builder.Single single() { return new CartographySingleWindowImpl.BuilderImpl(); } + /** + * Creates a new single {@link CartographyWindow} after configuring a {@link Builder.Single Window Builder} using the given {@link Consumer}. + * + * @param consumer The {@link Consumer} to configure the {@link Builder.Single Window Builder}. + * @return The created {@link CartographyWindow}. + */ static @NotNull CartographyWindow single(@NotNull Consumer consumer) { Builder.Single builder = single(); consumer.accept(builder); return builder.build(); } + /** + * Creates a new {@link Builder.Split Window Builder} for a split {@link CartographyWindow}. + * + * @return The new {@link Builder.Split Window Builder}. + */ static @NotNull Builder.Split split() { return new CartographySplitWindowImpl.BuilderImpl(); } + /** + * Creates a new split {@link CartographyWindow} after configuring a {@link Builder.Split Window Builder} using the given {@link Consumer}. + * + * @param consumer The {@link Consumer} to configure the {@link Builder.Split Window Builder}. + * @return The created {@link CartographyWindow}. + */ static @NotNull CartographyWindow split(@NotNull Consumer consumer) { Builder.Split builder = split(); consumer.accept(builder); return builder.build(); } + /** + * Updates the map in the cartography table. + * + * @param patch The {@link MapPatch} to apply to the map. + * @param icons The {@link MapIcon MapIcons} to display on the map. + */ void updateMap(@Nullable MapPatch patch, @Nullable List icons); + /** + * Updates the map in the cartography table. + * + * @param patch The {@link MapPatch} to apply to the map. + */ default void updateMap(@Nullable MapPatch patch) { updateMap(patch, null); } + /** + * Updates the map in the cartography table. + * + * @param icons The {@link MapIcon MapIcons} to display on the map. + */ default void updateMap(@Nullable List icons) { updateMap(null, icons); } + /** + * Resets the map in the cartography table. + */ void resetMap(); + /** + * A {@link CartographyWindow} builder. + * + * @param The builder type. + * @see Window.Builder.Normal + * @see Window.Builder + */ interface Builder> extends Window.Builder { + /** + * A single {@link CartographyWindow} builder. Combines both {@link CartographyWindow.Builder} an + * {@link Window.Builder.Single} for a {@link CartographyWindow} with only one {@link Gui} that does not + * access the {@link Player Player's} inventory. + */ interface Single extends Builder, Window.Builder.Single {} + + /** + * A split {@link CartographyWindow} builder. Combines both {@link CartographyWindow.Builder} an + * {@link Window.Builder.Double} for a {@link CartographyWindow} with two {@link Gui Guis}, where the lower + * {@link Gui} is used to fill the {@link Player Player's} inventory. + */ interface Split extends Builder, Window.Builder.Double {} }