diff --git a/src/main/java/de/studiocode/invgui/animation/Animation.java b/src/main/java/de/studiocode/invgui/animation/Animation.java index a2b369f..2854a92 100644 --- a/src/main/java/de/studiocode/invgui/animation/Animation.java +++ b/src/main/java/de/studiocode/invgui/animation/Animation.java @@ -1,6 +1,7 @@ package de.studiocode.invgui.animation; import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -8,18 +9,53 @@ import java.util.function.BiConsumer; public interface Animation { + /** + * Sets the {@link Player} that will see this animation. + * Useful for playing sounds in a showHandler. ({@link #addShowHandler(BiConsumer)}) + * + * @param player The {@link Player} that will se this {@link Animation}. + */ void setPlayer(@NotNull Player player); + /** + * Sets the bounds of the {@link Inventory} this {@link Animation} will take place in. + * + * @param width The width of the {@link Inventory} + * @param height The height {@link Inventory} + */ void setBounds(int width, int height); + /** + * Sets the slots that should be shown. + * + * @param slots The slots that should be shown. + */ void setSlots(List slots); + /** + * Adds a show handler. + * Can be used to for example play a sound when a slot pops up. + * + * @param show The show handler as a {@link BiConsumer} consisting of + * frame number (first int) and slot index to show (second int). + */ void addShowHandler(@NotNull BiConsumer show); - void setFinishHandler(@NotNull Runnable finish); + /** + * Adds a {@link Runnable} that should run after the {@link Animation} is finished. + * + * @param finish The {@link Runnable} that should run after the {@link Animation} is finished. + */ + void addFinishHandler(@NotNull Runnable finish); + /** + * Starts the {@link Animation}. + */ void start(); + /** + * Cancels the {@link Animation}. + */ void cancel(); } diff --git a/src/main/java/de/studiocode/invgui/item/impl/CommandItem.java b/src/main/java/de/studiocode/invgui/item/impl/CommandItem.java index 1b4e09b..bdf20e1 100644 --- a/src/main/java/de/studiocode/invgui/item/impl/CommandItem.java +++ b/src/main/java/de/studiocode/invgui/item/impl/CommandItem.java @@ -7,7 +7,7 @@ import org.bukkit.event.inventory.InventoryClickEvent; import org.jetbrains.annotations.NotNull; /** - * An item that will force a player to run a command or say something in the chat when clicked + * An item that will force a player to run a command or say something in the chat when clicked. */ public class CommandItem extends SimpleItem { diff --git a/src/main/java/de/studiocode/invgui/item/itembuilder/ItemBuilder.java b/src/main/java/de/studiocode/invgui/item/itembuilder/ItemBuilder.java index f062b8d..2ff4e32 100644 --- a/src/main/java/de/studiocode/invgui/item/itembuilder/ItemBuilder.java +++ b/src/main/java/de/studiocode/invgui/item/itembuilder/ItemBuilder.java @@ -167,6 +167,11 @@ public class ItemBuilder { return this; } + /** + * Contains the texture value for a player head. + * + * @see ItemBuilder + */ public static class PlayerHead { private final String textureValue; diff --git a/src/main/java/de/studiocode/invgui/window/Window.java b/src/main/java/de/studiocode/invgui/window/Window.java index 2284d9c..cd419ed 100644 --- a/src/main/java/de/studiocode/invgui/window/Window.java +++ b/src/main/java/de/studiocode/invgui/window/Window.java @@ -4,6 +4,10 @@ import de.studiocode.invgui.animation.Animation; import de.studiocode.invgui.gui.GUI; import de.studiocode.invgui.item.Item; import de.studiocode.invgui.item.itembuilder.ItemBuilder; +import de.studiocode.invgui.window.impl.BaseWindow; +import de.studiocode.invgui.window.impl.DropperWindow; +import de.studiocode.invgui.window.impl.HopperWindow; +import de.studiocode.invgui.window.impl.NormalInventoryWindow; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryOpenEvent; @@ -15,6 +19,11 @@ import java.util.UUID; /** * A window is the way to show a player a GUI. * Windows can only have one viewer at a time. + * + * @see BaseWindow + * @see NormalInventoryWindow + * @see HopperWindow + * @see DropperWindow */ public interface Window { diff --git a/src/main/java/de/studiocode/invgui/window/WindowManager.java b/src/main/java/de/studiocode/invgui/window/WindowManager.java index fd7e890..bc74947 100644 --- a/src/main/java/de/studiocode/invgui/window/WindowManager.java +++ b/src/main/java/de/studiocode/invgui/window/WindowManager.java @@ -28,36 +28,58 @@ public class WindowManager implements Listener { () -> windows.forEach(Window::handleTick), 0, 1); } + /** + * Gets the {@link WindowManager} instance or creates a new one if there isn't one. + * + * @return The {@link WindowManager} instance + */ public static WindowManager getInstance() { - return instance == null ? instance = new WindowManager() : instance; + return hasInstance() ? instance = new WindowManager() : instance; } + /** + * Gets if the {@link WindowManager} already has an instance. + * + * @return if the {@link WindowManager} already has an instance + */ public static boolean hasInstance() { return instance != null; } + /** + * Adds a {@link Window} to the list of windows. + * This method is usually called by the {@link Window} itself. + * + * @param window The {@link Window} to add + */ public void addWindow(Window window) { windows.add(window); } + /** + * Removes a {@link Window} from the list of windows. + * This method is usually called by the {@link Window} itself. + * + * @param window The {@link Window} to remove + */ public void removeWindow(Window window) { windows.remove(window); } /** - * Find a window to an inventory + * Finds the window to an inventory. * * @param inventory The inventory * @return The window that belongs to that inventory */ public Optional findWindow(Inventory inventory) { return windows.stream() - .filter(w -> w.getInventory().equals(inventory)) + .filter(w -> w.getInventory() == inventory) .findFirst(); } /** - * Find a window to a player + * Finds the window to a player. * * @param player The player * @return The window that the player has open @@ -69,7 +91,7 @@ public class WindowManager implements Listener { } /** - * Get a list of all currently active windows + * Gets a list of all currently active windows. * * @return A list of all windows */