Overhauled GUI component-based backend to support reactive and static slots

This commit is contained in:
Auxilor
2022-09-29 15:08:34 +01:00
parent ab8c946914
commit 0caa328b1e
8 changed files with 121 additions and 31 deletions

View File

@@ -1,6 +1,12 @@
package com.willfp.eco.core.gui.component;
import com.willfp.eco.core.gui.menu.Menu;
import com.willfp.eco.core.gui.slot.FillerSlot;
import com.willfp.eco.core.gui.slot.Slot;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
@@ -30,6 +36,28 @@ public interface GUIComponent {
* @return The slot, or null if no slot at the location.
*/
@Nullable
Slot getSlotAt(final int row,
final int column);
default Slot getSlotAt(int row,
int column) {
return new FillerSlot(new ItemStack(Material.AIR));
}
/**
* Get the slot at a certain position in the component.
* <p>
* If your component doesn't use context data (player, menu),
* then it will default to the raw slot.
*
* @param row The row (1-indexed).
* @param column The column (1-indexed).
* @param player The player.
* @param menu The menu.
* @return The slot, or null if no slot at the location.
*/
@Nullable
default Slot getSlotAt(int row,
int column,
@NotNull Player player,
@NotNull Menu menu) {
return getSlotAt(row, column);
}
}

View File

@@ -28,7 +28,10 @@ public interface Menu {
int getRows();
/**
* Get slot at given row and column.
* Get a static slot at a given row and column.
* <p>
* If the slot at the location is reactive, this will return
* an empty slot.
*
* @param row The row.
* @param column The column.
@@ -37,6 +40,24 @@ public interface Menu {
Slot getSlot(int row,
int column);
/**
* Get a slot at a given row and column.
* <p>
* Defaults to static slot if no reactive slot exists.
*
* @param row The row.
* @param column The column.
* @param player The player
* @param menu The menu.
* @return The slot.
*/
default Slot getSlot(int row,
int column,
@NotNull Player player,
@NotNull Menu menu) {
return this.getSlot(row, column);
}
/**
* Get the menu title.
*