mirror of
https://github.com/plexusorg/Plex.git
synced 2026-07-14 21:44:55 +00:00
Overhaul menu system and simplify it heavily, separating Pageable Menus and regular Menus into two different implementations
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package dev.plex.menu;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.Accessors;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Taah
|
||||
* @since 6:49 AM [02-09-2023]
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@Accessors(fluent = true)
|
||||
public abstract class AbstractMenu
|
||||
{
|
||||
public static final Map<Component, AbstractMenu> INVENTORIES = Maps.newHashMap();
|
||||
private final Component name;
|
||||
private final Inventory inventory;
|
||||
|
||||
public AbstractMenu(Component name, Rows rows)
|
||||
{
|
||||
this.name = name;
|
||||
this.inventory = Bukkit.createInventory(null, rows.slots, name);
|
||||
|
||||
INVENTORIES.put(name, this);
|
||||
}
|
||||
|
||||
public AbstractMenu(String name, Rows rows)
|
||||
{
|
||||
this(SafeMiniMessage.mmDeserializeWithoutEvents(name), rows);
|
||||
}
|
||||
|
||||
public void open(Player player)
|
||||
{
|
||||
player.openInventory(this.inventory);
|
||||
}
|
||||
|
||||
public abstract boolean onClick(InventoryView view, Inventory inventory, Player player, ItemStack clicked);
|
||||
|
||||
public enum Rows
|
||||
{
|
||||
ONE(9), TWO(18), THREE(27), FOUR(36), FIVE(45), SIX(54);
|
||||
|
||||
private final int slots;
|
||||
|
||||
Rows(int slots)
|
||||
{
|
||||
this.slots = slots;
|
||||
}
|
||||
|
||||
public int slots()
|
||||
{
|
||||
return this.slots;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user