Refactoring, added missing javadoc

This commit is contained in:
NichtStudioCode 2021-02-05 11:56:51 +01:00
parent 2df18412ef
commit 6ca55ef678
11 changed files with 50 additions and 17 deletions

@ -50,6 +50,7 @@ public class GUIBuilder {
* define where which {@link Item} should be. * define where which {@link Item} should be.
* *
* @param structure The structure {@link String} * @param structure The structure {@link String}
* @return The {@link GUIBuilder}
*/ */
public GUIBuilder setStructure(@NotNull String structure) { public GUIBuilder setStructure(@NotNull String structure) {
String cleanedStructure = structure.replace(" ", "").replace("\n", ""); String cleanedStructure = structure.replace(" ", "").replace("\n", "");
@ -66,6 +67,7 @@ public class GUIBuilder {
* *
* @param key The ingredient key * @param key The ingredient key
* @param item The {@link Item} * @param item The {@link Item}
* @return The {@link GUIBuilder}
*/ */
public GUIBuilder setIngredient(char key, @NotNull Item item) { public GUIBuilder setIngredient(char key, @NotNull Item item) {
ingredientMap.put(key, new Ingredient(item)); ingredientMap.put(key, new Ingredient(item));
@ -78,6 +80,7 @@ public class GUIBuilder {
* *
* @param key The ingredient key * @param key The ingredient key
* @param slotElement The {@link SlotElement} * @param slotElement The {@link SlotElement}
* @return The {@link GUIBuilder}
*/ */
public GUIBuilder setIngredient(char key, @NotNull SlotElement slotElement) { public GUIBuilder setIngredient(char key, @NotNull SlotElement slotElement) {
ingredientMap.put(key, new Ingredient(slotElement)); ingredientMap.put(key, new Ingredient(slotElement));

@ -27,7 +27,7 @@ public class VirtualInventory implements ConfigurationSerializable {
* *
* @param uuid The {@link UUID} this {@link VirtualInventory} should have. * @param uuid The {@link UUID} this {@link VirtualInventory} should have.
* Can be null, only used for serialization. * Can be null, only used for serialization.
* @param size The size of the {@link VirtualInventory} ( size > 0 ) * @param size The size of the {@link VirtualInventory}
* @param items An array of {@link ItemStack} which reflects the contents of this * @param items An array of {@link ItemStack} which reflects the contents of this
* {@link VirtualInventory}, therefore the length of that array has * {@link VirtualInventory}, therefore the length of that array has
* to be the same as <code>size</code>. * to be the same as <code>size</code>.

@ -5,8 +5,8 @@ import de.studiocode.invui.gui.GUIParent;
import de.studiocode.invui.item.Item; import de.studiocode.invui.item.Item;
import de.studiocode.invui.item.itembuilder.ItemBuilder; import de.studiocode.invui.item.itembuilder.ItemBuilder;
import de.studiocode.invui.virtualinventory.VirtualInventory; import de.studiocode.invui.virtualinventory.VirtualInventory;
import de.studiocode.invui.window.impl.combined.combinedgui.SimpleCombinedGUIWindow; import de.studiocode.invui.window.impl.combined.combinedgui.SimpleCombinedWindow;
import de.studiocode.invui.window.impl.combined.splitgui.SimpleSplitGUIWindow; import de.studiocode.invui.window.impl.combined.splitgui.SimpleSplitWindow;
import de.studiocode.invui.window.impl.single.SimpleWindow; import de.studiocode.invui.window.impl.single.SimpleWindow;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
@ -22,8 +22,8 @@ import java.util.UUID;
* Windows can only have one viewer. * Windows can only have one viewer.
* *
* @see SimpleWindow * @see SimpleWindow
* @see SimpleCombinedGUIWindow * @see SimpleCombinedWindow
* @see SimpleSplitGUIWindow * @see SimpleSplitWindow
*/ */
public interface Window extends GUIParent { public interface Window extends GUIParent {
@ -53,6 +53,8 @@ public interface Window extends GUIParent {
* A method called by the {@link WindowManager} to notify the Window * A method called by the {@link WindowManager} to notify the Window
* that {@link ItemStack}s have been shift-clicked from the lower * that {@link ItemStack}s have been shift-clicked from the lower
* {@link Inventory} to this {@link Window} * {@link Inventory} to this {@link Window}
*
* @param event The {@link InventoryClickEvent} associated with this action.
*/ */
void handleItemShift(InventoryClickEvent event); void handleItemShift(InventoryClickEvent event);

@ -1,11 +1,14 @@
package de.studiocode.invui.window; package de.studiocode.invui.window;
import de.studiocode.invui.InvUI; import de.studiocode.invui.InvUI;
import de.studiocode.invui.window.impl.combined.BaseCombinedWindow;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityPickupItemEvent;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.inventory.*; import org.bukkit.event.inventory.*;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
@ -145,4 +148,14 @@ public class WindowManager implements Listener {
findWindows(event.getEntity()).forEach(window -> window.handleViewerDeath(event)); findWindows(event.getEntity()).forEach(window -> window.handleViewerDeath(event));
} }
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void handleItemPickup(EntityPickupItemEvent event) {
Entity entity = event.getEntity();
if (entity instanceof Player) {
Optional<Window> window = findOpenWindow(((Player) entity));
if (window.isPresent() && window.get() instanceof BaseCombinedWindow)
event.setCancelled(true);
}
}
} }

@ -3,6 +3,7 @@ package de.studiocode.invui.window.impl.combined;
import de.studiocode.invui.gui.SlotElement.ItemStackHolder; import de.studiocode.invui.gui.SlotElement.ItemStackHolder;
import de.studiocode.invui.gui.SlotElement.VISlotElement; import de.studiocode.invui.gui.SlotElement.VISlotElement;
import de.studiocode.invui.util.SlotUtils; import de.studiocode.invui.util.SlotUtils;
import de.studiocode.invui.window.Window;
import de.studiocode.invui.window.impl.BaseWindow; import de.studiocode.invui.window.impl.BaseWindow;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
@ -14,7 +15,9 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
/**
* A {@link Window} that uses both top and player {@link Inventory}.
*/
public abstract class BaseCombinedWindow extends BaseWindow { public abstract class BaseCombinedWindow extends BaseWindow {
private final Inventory playerInventory; private final Inventory playerInventory;

@ -3,16 +3,20 @@ package de.studiocode.invui.window.impl.combined.combinedgui;
import de.studiocode.invui.gui.GUI; import de.studiocode.invui.gui.GUI;
import de.studiocode.invui.gui.SlotElement.ItemStackHolder; import de.studiocode.invui.gui.SlotElement.ItemStackHolder;
import de.studiocode.invui.util.SlotUtils; import de.studiocode.invui.util.SlotUtils;
import de.studiocode.invui.window.Window;
import de.studiocode.invui.window.impl.combined.BaseCombinedWindow; import de.studiocode.invui.window.impl.combined.BaseCombinedWindow;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
public abstract class CombinedGUIWindow extends BaseCombinedWindow { /**
* A {@link Window} where top and player {@link Inventory} are affected by the same {@link GUI}.
*/
public abstract class CombinedWindow extends BaseCombinedWindow {
private final GUI gui; private final GUI gui;
public CombinedGUIWindow(Player player, GUI gui, Inventory upperInventory, boolean closeable, boolean closeOnEvent) { public CombinedWindow(Player player, GUI gui, Inventory upperInventory, boolean closeable, boolean closeOnEvent) {
super(player, gui.getSize(), upperInventory, closeable, closeOnEvent); super(player, gui.getSize(), upperInventory, closeable, closeOnEvent);
this.gui = gui; this.gui = gui;

@ -5,9 +5,9 @@ import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
public class SimpleCombinedGUIWindow extends CombinedGUIWindow { public class SimpleCombinedWindow extends CombinedWindow {
public SimpleCombinedGUIWindow(Player player, String title, GUI gui, boolean closeable, boolean closeOnEvent) { public SimpleCombinedWindow(Player player, String title, GUI gui, boolean closeable, boolean closeOnEvent) {
super(player, gui, createInventory(gui, title), closeable, closeOnEvent); super(player, gui, createInventory(gui, title), closeable, closeOnEvent);
} }

@ -8,12 +8,12 @@ import org.bukkit.inventory.ItemStack;
import java.util.function.Consumer; import java.util.function.Consumer;
public class AnvilSplitGUIWindow extends SplitGUIWindow { public class AnvilSplitWindow extends SplitWindow {
private final AnvilInventory anvilInventory; private final AnvilInventory anvilInventory;
public AnvilSplitGUIWindow(Player player, String title, GUI upperGui, GUI lowerGui, public AnvilSplitWindow(Player player, String title, GUI upperGui, GUI lowerGui,
boolean closeable, Consumer<String> renameHandler) { boolean closeable, Consumer<String> renameHandler) {
super(player, upperGui, lowerGui, null, false, closeable, true); super(player, upperGui, lowerGui, null, false, closeable, true);

@ -4,9 +4,9 @@ import de.studiocode.invui.gui.GUI;
import de.studiocode.invui.util.InventoryUtils; import de.studiocode.invui.util.InventoryUtils;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class SimpleSplitGUIWindow extends SplitGUIWindow { public class SimpleSplitWindow extends SplitWindow {
public SimpleSplitGUIWindow(Player player, String title, GUI upperGui, GUI lowerGui, boolean closeable, boolean closeOnEvent) { public SimpleSplitWindow(Player player, String title, GUI upperGui, GUI lowerGui, boolean closeable, boolean closeOnEvent) {
super(player, upperGui, lowerGui, InventoryUtils.createMatchingInventory(upperGui, title), true, closeable, closeOnEvent); super(player, upperGui, lowerGui, InventoryUtils.createMatchingInventory(upperGui, title), true, closeable, closeOnEvent);
} }

@ -3,17 +3,21 @@ package de.studiocode.invui.window.impl.combined.splitgui;
import de.studiocode.invui.gui.GUI; import de.studiocode.invui.gui.GUI;
import de.studiocode.invui.gui.SlotElement.ItemStackHolder; import de.studiocode.invui.gui.SlotElement.ItemStackHolder;
import de.studiocode.invui.util.SlotUtils; import de.studiocode.invui.util.SlotUtils;
import de.studiocode.invui.window.Window;
import de.studiocode.invui.window.impl.combined.BaseCombinedWindow; import de.studiocode.invui.window.impl.combined.BaseCombinedWindow;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
public abstract class SplitGUIWindow extends BaseCombinedWindow { /**
* A {@link Window} where top and player {@link Inventory} are affected by different {@link GUI}s.
*/
public abstract class SplitWindow extends BaseCombinedWindow {
private final GUI upperGui; private final GUI upperGui;
private final GUI lowerGui; private final GUI lowerGui;
public SplitGUIWindow(Player player, GUI upperGui, GUI lowerGui, Inventory upperInventory, boolean initItems, boolean closeable, boolean closeOnEvent) { public SplitWindow(Player player, GUI upperGui, GUI lowerGui, Inventory upperInventory, boolean initItems, boolean closeable, boolean closeOnEvent) {
super(player, upperGui.getSize() + lowerGui.getSize(), upperInventory, closeable, closeOnEvent); super(player, upperGui.getSize() + lowerGui.getSize(), upperInventory, closeable, closeOnEvent);
this.upperGui = upperGui; this.upperGui = upperGui;
this.lowerGui = lowerGui; this.lowerGui = lowerGui;

@ -2,6 +2,7 @@ package de.studiocode.invui.window.impl.single;
import de.studiocode.invui.gui.GUI; import de.studiocode.invui.gui.GUI;
import de.studiocode.invui.gui.SlotElement.ItemStackHolder; import de.studiocode.invui.gui.SlotElement.ItemStackHolder;
import de.studiocode.invui.window.Window;
import de.studiocode.invui.window.impl.BaseWindow; import de.studiocode.invui.window.impl.BaseWindow;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.entity.PlayerDeathEvent;
@ -11,6 +12,9 @@ import org.bukkit.inventory.ItemStack;
import java.util.UUID; import java.util.UUID;
/**
* A {@link Window} that just uses the top {@link Inventory}.
*/
public abstract class SingleWindow extends BaseWindow { public abstract class SingleWindow extends BaseWindow {
private final GUI gui; private final GUI gui;