Major improvements to menus
This commit is contained in:
@@ -30,6 +30,8 @@ public interface GUIComponent {
|
||||
|
||||
/**
|
||||
* Get the slot at a certain position in the component.
|
||||
* <p>
|
||||
* It's safe to assume to the row and column will always be in bounds.
|
||||
*
|
||||
* @param row The row (1-indexed).
|
||||
* @param column The column (1-indexed).
|
||||
@@ -46,6 +48,8 @@ public interface GUIComponent {
|
||||
* <p>
|
||||
* If your component doesn't use context data (player, menu),
|
||||
* then it will default to the raw slot.
|
||||
* <p>
|
||||
* It's safe to assume to the row and column will always be in bounds.
|
||||
*
|
||||
* @param row The row (1-indexed).
|
||||
* @param column The column (1-indexed).
|
||||
|
||||
@@ -70,7 +70,9 @@ public interface MenuBuilder {
|
||||
* @param mask The mask.
|
||||
* @return The builder.
|
||||
*/
|
||||
MenuBuilder setMask(@NotNull FillerMask mask);
|
||||
default MenuBuilder setMask(@NotNull FillerMask mask) {
|
||||
return this.addComponent(0, 0, mask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the menu close handler.
|
||||
@@ -79,8 +81,7 @@ public interface MenuBuilder {
|
||||
* @return The builder.
|
||||
*/
|
||||
default MenuBuilder onClose(@NotNull Consumer<InventoryCloseEvent> action) {
|
||||
onClose((event, menu) -> action.accept(event));
|
||||
return this;
|
||||
return this.onClose((event, menu) -> action.accept(event));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.willfp.eco.core.gui.slot;
|
||||
|
||||
import com.willfp.eco.core.gui.component.GUIComponent;
|
||||
import com.willfp.eco.core.items.builder.ItemStackBuilder;
|
||||
import com.willfp.eco.core.recipe.parts.EmptyTestableItem;
|
||||
import com.willfp.eco.core.recipe.parts.MaterialTestableItem;
|
||||
@@ -7,6 +8,7 @@ import com.willfp.eco.util.ListUtils;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -26,12 +28,17 @@ import java.util.List;
|
||||
* "11111111"
|
||||
* );
|
||||
*/
|
||||
public class FillerMask {
|
||||
public class FillerMask implements GUIComponent {
|
||||
/**
|
||||
* Mask.
|
||||
*/
|
||||
private final List<List<Slot>> mask;
|
||||
|
||||
/**
|
||||
* Rows.
|
||||
*/
|
||||
private final int rows;
|
||||
|
||||
/**
|
||||
* Create a new filler mask.
|
||||
*
|
||||
@@ -71,7 +78,8 @@ public class FillerMask {
|
||||
throw new IllegalArgumentException("Items cannot be empty!");
|
||||
}
|
||||
|
||||
mask = ListUtils.create2DList(6, 9);
|
||||
rows = pattern.length;
|
||||
mask = ListUtils.create2DList(rows, 9);
|
||||
|
||||
for (int i = 0; i < items.items().length; i++) {
|
||||
ItemStack itemStack = new ItemStackBuilder(items.items()[i])
|
||||
@@ -107,4 +115,20 @@ public class FillerMask {
|
||||
public List<List<Slot>> getMask() {
|
||||
return this.mask;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRows() {
|
||||
return rows;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColumns() {
|
||||
return 9;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Slot getSlotAt(final int row,
|
||||
final int column) {
|
||||
return mask.get(row).get(column);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.willfp.eco.core.gui.slot;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -9,37 +8,16 @@ import org.jetbrains.annotations.NotNull;
|
||||
* <p>
|
||||
* Useful for backgrounds.
|
||||
*/
|
||||
public class FillerSlot implements Slot {
|
||||
/**
|
||||
* The ItemStack.
|
||||
*/
|
||||
private final ItemStack itemStack;
|
||||
|
||||
public class FillerSlot extends CustomSlot {
|
||||
/**
|
||||
* Create new filler slot.
|
||||
*
|
||||
* @param itemStack The ItemStack.
|
||||
*/
|
||||
public FillerSlot(@NotNull final ItemStack itemStack) {
|
||||
this.itemStack = itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItemStack(@NotNull final Player player) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCaptive() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ItemStack.
|
||||
*
|
||||
* @return The ItemStack.
|
||||
*/
|
||||
public ItemStack getItemStack() {
|
||||
return this.itemStack;
|
||||
init(
|
||||
Slot.builder(itemStack)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.willfp.eco.core.gui.slot.functional.SlotHandler;
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotModifier;
|
||||
import com.willfp.eco.core.gui.slot.functional.SlotUpdater;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -14,6 +15,28 @@ import java.util.function.Predicate;
|
||||
* Builder to create slots.
|
||||
*/
|
||||
public interface SlotBuilder {
|
||||
/**
|
||||
* Set click handler.
|
||||
*
|
||||
* @param type The click type.
|
||||
* @param handler The handler.
|
||||
* @return The builder.
|
||||
*/
|
||||
SlotBuilder onClick(@NotNull ClickType type,
|
||||
@NotNull SlotHandler handler);
|
||||
|
||||
/**
|
||||
* Set click handler.
|
||||
*
|
||||
* @param type The click type.
|
||||
* @param action The handler.
|
||||
* @return The builder.
|
||||
*/
|
||||
default SlotBuilder onClick(@NotNull final ClickType type,
|
||||
@NotNull final BiConsumer<InventoryClickEvent, Slot> action) {
|
||||
return onClick(type, (event, slot, menu) -> action.accept(event, slot));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set click handler.
|
||||
*
|
||||
@@ -30,7 +53,9 @@ public interface SlotBuilder {
|
||||
* @param handler The handler.
|
||||
* @return The builder.
|
||||
*/
|
||||
SlotBuilder onLeftClick(@NotNull SlotHandler handler);
|
||||
default SlotBuilder onLeftClick(@NotNull final SlotHandler handler) {
|
||||
return onClick(ClickType.LEFT, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set click handler.
|
||||
@@ -48,7 +73,9 @@ public interface SlotBuilder {
|
||||
* @param handler The handler.
|
||||
* @return The builder.
|
||||
*/
|
||||
SlotBuilder onRightClick(@NotNull SlotHandler handler);
|
||||
default SlotBuilder onRightClick(@NotNull final SlotHandler handler) {
|
||||
return onClick(ClickType.RIGHT, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set click handler.
|
||||
@@ -66,7 +93,9 @@ public interface SlotBuilder {
|
||||
* @param handler The handler.
|
||||
* @return The builder.
|
||||
*/
|
||||
SlotBuilder onShiftLeftClick(@NotNull SlotHandler handler);
|
||||
default SlotBuilder onShiftLeftClick(@NotNull final SlotHandler handler) {
|
||||
return onClick(ClickType.SHIFT_LEFT, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set click handler.
|
||||
@@ -84,7 +113,9 @@ public interface SlotBuilder {
|
||||
* @param handler The handler.
|
||||
* @return The builder.
|
||||
*/
|
||||
SlotBuilder onShiftRightClick(@NotNull SlotHandler handler);
|
||||
default SlotBuilder onShiftRightClick(@NotNull final SlotHandler handler) {
|
||||
return onClick(ClickType.SHIFT_RIGHT, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set click handler.
|
||||
@@ -102,7 +133,9 @@ public interface SlotBuilder {
|
||||
* @param handler The handler.
|
||||
* @return The builder.
|
||||
*/
|
||||
SlotBuilder onMiddleClick(@NotNull SlotHandler handler);
|
||||
default SlotBuilder onMiddleClick(@NotNull final SlotHandler handler) {
|
||||
return onClick(ClickType.MIDDLE, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent captive for players that match a predicate.
|
||||
|
||||
Reference in New Issue
Block a user