diff --git a/hscore-minecraft/hscore-minecraft-gui-mask/src/main/java/me/hsgamer/hscore/minecraft/gui/mask/MaskSlot.java b/hscore-minecraft/hscore-minecraft-gui-mask/src/main/java/me/hsgamer/hscore/minecraft/gui/mask/MaskSlot.java new file mode 100644 index 0000000000..1b31ddb436 --- /dev/null +++ b/hscore-minecraft/hscore-minecraft-gui-mask/src/main/java/me/hsgamer/hscore/minecraft/gui/mask/MaskSlot.java @@ -0,0 +1,58 @@ +package me.hsgamer.hscore.minecraft.gui.mask; + +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +/** + * The slot for the mask + */ +public interface MaskSlot { + /** + * Create a mask slot from the slots + * + * @param slots the slots + * + * @return the mask slot + */ + @NotNull + static MaskSlot of(@NotNull List<@NotNull Integer> slots) { + return () -> slots; + } + + /** + * Create a mask slot from the slots + * + * @param slots the slots + * + * @return the mask slot + */ + @NotNull + static MaskSlot of(@NotNull Integer... slots) { + List slotList = Arrays.asList(slots); + return () -> slotList; + } + + /** + * Create a mask slot from the slot stream + * + * @param slotStream the slot stream + * + * @return the mask slot + */ + @NotNull + static MaskSlot of(IntStream slotStream) { + return of(slotStream.boxed().collect(Collectors.toList())); + } + + /** + * Get the slots + * + * @return the slots + */ + @NotNull + List getSlots(); +} diff --git a/hscore-minecraft/hscore-minecraft-gui-mask/src/main/java/me/hsgamer/hscore/minecraft/gui/mask/impl/ButtonPaginatedMask.java b/hscore-minecraft/hscore-minecraft-gui-mask/src/main/java/me/hsgamer/hscore/minecraft/gui/mask/impl/ButtonPaginatedMask.java index 5f86bf00ff..5997709555 100644 --- a/hscore-minecraft/hscore-minecraft-gui-mask/src/main/java/me/hsgamer/hscore/minecraft/gui/mask/impl/ButtonPaginatedMask.java +++ b/hscore-minecraft/hscore-minecraft-gui-mask/src/main/java/me/hsgamer/hscore/minecraft/gui/mask/impl/ButtonPaginatedMask.java @@ -1,6 +1,7 @@ package me.hsgamer.hscore.minecraft.gui.mask.impl; import me.hsgamer.hscore.minecraft.gui.button.Button; +import me.hsgamer.hscore.minecraft.gui.mask.MaskSlot; import org.jetbrains.annotations.NotNull; import java.util.*; @@ -9,27 +10,27 @@ * The button paginated mask, those with a long list of {@link Button} divided into pages. */ public abstract class ButtonPaginatedMask extends PaginatedMask { - protected final List slots = new ArrayList<>(); + private final MaskSlot maskSlot; /** * Create a new mask * - * @param name the name of the mask - * @param slots the slots + * @param name the name of the mask + * @param maskSlot the mask slot */ - protected ButtonPaginatedMask(@NotNull String name, @NotNull List<@NotNull Integer> slots) { + protected ButtonPaginatedMask(@NotNull String name, @NotNull MaskSlot maskSlot) { super(name); - this.slots.addAll(slots); + this.maskSlot = maskSlot; } /** - * Get the slots + * Get the mask slot * - * @return the slots + * @return the mask slot */ @NotNull - public List<@NotNull Integer> getSlots() { - return Collections.unmodifiableList(slots); + public MaskSlot getMaskSlot() { + return maskSlot; } /** @@ -45,13 +46,14 @@ protected ButtonPaginatedMask(@NotNull String name, @NotNull List<@NotNull Integ @Override public @NotNull Map generateButtons(@NotNull UUID uuid, int size) { List