This commit is contained in:
NichtStudioCode 2021-01-21 00:17:58 +01:00
parent ab98b0dee4
commit 397ff4fe50
5 changed files with 79 additions and 7 deletions

@ -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<Integer> 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<Integer, Integer> 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();
}

@ -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 {

@ -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;

@ -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 {

@ -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<Window> 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
*/