69 lines
2.7 KiB
Java
69 lines
2.7 KiB
Java
package com.dunerealms.menus;
|
|
|
|
import java.util.Map;
|
|
import java.util.UUID;
|
|
import org.bukkit.Material;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.event.inventory.ClickType;
|
|
import org.bukkit.inventory.Inventory;
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
final class ServiceMenu extends Menu {
|
|
private final String section;
|
|
private final String title;
|
|
private final String subtitle;
|
|
private final ItemStack[] cards;
|
|
private final Map<Integer, Runnable> actions;
|
|
private final UUID world;
|
|
|
|
ServiceMenu(DuneMenusPlugin plugin, Player player, String section, String title, String description,
|
|
Inventory inventory, Map<Integer, Runnable> actions) {
|
|
super(plugin, player, null);
|
|
this.section = section;
|
|
this.title = title.replaceFirst("^NPC (dashboard|turn-in) · ", "");
|
|
this.subtitle = description.lines().findFirst().orElse("");
|
|
this.cards = inventory.getContents();
|
|
this.actions = Map.copyOf(actions);
|
|
this.world = player.getWorld().getUID();
|
|
}
|
|
|
|
String id() { return section; }
|
|
Skin skin() {
|
|
return switch (section) {
|
|
case "missions" -> Skin.QUEST;
|
|
case "exchange" -> Skin.MARKET;
|
|
case "spice" -> Skin.SPICE;
|
|
case "war" -> Skin.WAR;
|
|
case "politics" -> Skin.POLITICS;
|
|
case "travel" -> Skin.TRAVEL;
|
|
case "house", "mentat" -> Skin.HOUSE;
|
|
default -> Skin.GOLD;
|
|
};
|
|
}
|
|
String title() { return title; }
|
|
String subtitle() { return subtitle; }
|
|
int rows() { return cards.length / 9; }
|
|
|
|
void draw() {
|
|
backdrop(Material.BLACK_STAINED_GLASS_PANE);
|
|
for (int slot = 0; slot < cards.length; slot++) {
|
|
ItemStack card = cards[slot];
|
|
Runnable action = actions.get(slot);
|
|
if (card == null || action == null && card.getType().name().endsWith("_PANE") &&
|
|
(card.getItemMeta() == null || !card.getItemMeta().hasLore())) continue;
|
|
if (action == null) put(slot, card);
|
|
else put(slot, card, click -> {
|
|
if (click != ClickType.LEFT && !(section.equals("exchange") && click == ClickType.RIGHT)) return;
|
|
Runnable run = () -> {
|
|
if (plugin.hasOpenMenu(player, this) && player.isOnline() && world.equals(player.getWorld().getUID())) {
|
|
end();
|
|
action.run();
|
|
}
|
|
};
|
|
if (player.getOpenInventory().getTopInventory().getHolder() == this)
|
|
plugin.getServer().getScheduler().runTask(plugin, run);
|
|
else run.run();
|
|
});
|
|
}
|
|
}
|
|
}
|

Staff