Save viewer instance in AbstractWindow

This commit is contained in:
NichtStudioCode 2023-06-11 16:38:00 +02:00
parent 7b0767b9f4
commit e19447f7b9
6 changed files with 12 additions and 10 deletions

@ -27,7 +27,7 @@ public abstract class AbstractDoubleWindow extends AbstractWindow {
protected Inventory upperInventory; protected Inventory upperInventory;
public AbstractDoubleWindow(Player player, ComponentWrapper title, int size, Inventory upperInventory, boolean closeable) { public AbstractDoubleWindow(Player player, ComponentWrapper title, int size, Inventory upperInventory, boolean closeable) {
super(player.getUniqueId(), title, size, closeable); super(player, title, size, closeable);
this.upperInventory = upperInventory; this.upperInventory = upperInventory;
this.playerInventory = player.getInventory(); this.playerInventory = player.getInventory();
} }

@ -31,8 +31,8 @@ public abstract class AbstractSingleWindow extends AbstractWindow {
private final int size; private final int size;
protected org.bukkit.inventory.Inventory inventory; protected org.bukkit.inventory.Inventory inventory;
public AbstractSingleWindow(UUID viewerUUID, ComponentWrapper title, AbstractGui gui, org.bukkit.inventory.Inventory inventory, boolean closeable) { public AbstractSingleWindow(Player viewer, ComponentWrapper title, AbstractGui gui, org.bukkit.inventory.Inventory inventory, boolean closeable) {
super(viewerUUID, title, gui.getSize(), closeable); super(viewer, title, gui.getSize(), closeable);
this.gui = gui; this.gui = gui;
this.size = gui.getSize(); this.size = gui.getSize();
this.inventory = inventory; this.inventory = inventory;

@ -41,6 +41,7 @@ public abstract class AbstractWindow implements Window, GuiParent {
private static final NamespacedKey SLOT_KEY = new NamespacedKey(InvUI.getInstance().getPlugin(), "slot"); private static final NamespacedKey SLOT_KEY = new NamespacedKey(InvUI.getInstance().getPlugin(), "slot");
private final Player viewer;
private final UUID viewerUUID; private final UUID viewerUUID;
private final SlotElement[] elementsDisplayed; private final SlotElement[] elementsDisplayed;
private List<Runnable> openHandlers; private List<Runnable> openHandlers;
@ -51,8 +52,9 @@ public abstract class AbstractWindow implements Window, GuiParent {
private boolean currentlyOpen; private boolean currentlyOpen;
private boolean hasHandledClose; private boolean hasHandledClose;
public AbstractWindow(UUID viewerUUID, ComponentWrapper title, int size, boolean closeable) { public AbstractWindow(Player viewer, ComponentWrapper title, int size, boolean closeable) {
this.viewerUUID = viewerUUID; this.viewer = viewer;
this.viewerUUID = viewer.getUniqueId();
this.title = title; this.title = title;
this.closeable = closeable; this.closeable = closeable;
this.elementsDisplayed = new SlotElement[size]; this.elementsDisplayed = new SlotElement[size];
@ -389,8 +391,8 @@ public abstract class AbstractWindow implements Window, GuiParent {
} }
@Override @Override
public @Nullable Player getViewer() { public @NotNull Player getViewer() {
return Bukkit.getPlayer(viewerUUID); return viewer;
} }
public @NotNull String getLang() { public @NotNull String getLang() {

@ -24,7 +24,7 @@ final class AnvilSingleWindowImpl extends AbstractSingleWindow implements AnvilW
@Nullable List<@NotNull Consumer<@NotNull String>> renameHandlers, @Nullable List<@NotNull Consumer<@NotNull String>> renameHandlers,
boolean closable boolean closable
) { ) {
super(player.getUniqueId(), title, gui, null, closable); super(player, title, gui, null, closable);
anvilInventory = InventoryAccess.createAnvilInventory(player, title.localized(player), renameHandlers); anvilInventory = InventoryAccess.createAnvilInventory(player, title.localized(player), renameHandlers);
inventory = anvilInventory.getBukkitInventory(); inventory = anvilInventory.getBukkitInventory();
} }

@ -30,7 +30,7 @@ final class CartographySingleWindowImpl extends AbstractSingleWindow implements
@NotNull AbstractGui gui, @NotNull AbstractGui gui,
boolean closeable boolean closeable
) { ) {
super(player.getUniqueId(), title, createWrappingGui(gui), null, closeable); super(player, title, createWrappingGui(gui), null, closeable);
if (gui.getWidth() != 2 || gui.getHeight() != 1) throw new IllegalArgumentException("Gui has to be 2x1"); if (gui.getWidth() != 2 || gui.getHeight() != 1) throw new IllegalArgumentException("Gui has to be 2x1");
cartographyInventory = InventoryAccess.createCartographyInventory(player, title.localized(player)); cartographyInventory = InventoryAccess.createCartographyInventory(player, title.localized(player));

@ -15,7 +15,7 @@ final class NormalSingleWindowImpl extends AbstractSingleWindow {
@NotNull AbstractGui gui, @NotNull AbstractGui gui,
boolean closeable boolean closeable
) { ) {
super(player.getUniqueId(), title, gui, InventoryUtils.createMatchingInventory(gui, ""), closeable); super(player, title, gui, InventoryUtils.createMatchingInventory(gui, ""), closeable);
} }
public static final class BuilderImpl public static final class BuilderImpl