| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- package me.lethunderhawk.fluxapi.npc.gui;
- import me.lethunderhawk.fluxapi.FluxService;
- import me.lethunderhawk.fluxapi.util.gui.InventoryGUI;
- import me.lethunderhawk.fluxapi.util.gui.input.SignMenuFactory;
- import me.lethunderhawk.fluxapi.util.itemdesign.ItemOptions;
- import me.lethunderhawk.fluxapi.util.itemdesign.LoreDesigner;
- import me.lethunderhawk.fluxapi.main.FluxAPI;
- import me.lethunderhawk.fluxapi.npc.abstraction.NPC;
- import me.lethunderhawk.fluxapi.npc.manager.NPCManager;
- import net.kyori.adventure.text.Component;
- import net.kyori.adventure.text.format.NamedTextColor;
- import org.bukkit.Material;
- import org.bukkit.entity.Player;
- import org.bukkit.event.inventory.ClickType;
- import org.bukkit.inventory.ItemStack;
- import java.util.List;
- public class NPCOptionsGUI extends InventoryGUI {
- private final NPC npc;
- public NPCOptionsGUI(NPC npc) {
- super("Options for NPC: " + npc.getName(), 36);
- this.npc = npc;
- }
- private void editName(Player player, ClickType type) {
- if(player.hasPermission("npc.edit")) {
- SignMenuFactory.Menu menu = new SignMenuFactory(FluxService.get(FluxAPI.class)).newMenu(List.of(
- npc.getName(),
- "^^^^^^^^",
- "Edit the name",
- "of this NPC"
- )).reopenIfFail(true);
- menu.response((Player pl, String[] input) -> {
- String newName = input[0];
- if(newName.isEmpty()) return false;
- pl.sendMessage("Renamed " + npc.getName() + " to " + newName);
- FluxService.get(NPCManager.class).renameNPCbyId(npc.getOptions().getEntity().getUniqueId(), newName);
- return true;
- });
- menu.open(player);
- }
- }
- @Override
- public void buildContent() {
- fillGlassPaneBackground();
- ItemStack item = new ItemOptions(Material.OAK_SIGN)
- .setName(Component.text("Rename this NPC", NamedTextColor.YELLOW))
- .setLore(
- LoreDesigner.createLore("Opens a new sign input which will allow you to rename the NPC's base Name", "Opens a new sign input which ", NamedTextColor.GRAY)
- )
- .buildItemStack();
- setItemWithClickAction(4, item, this::editName);
- }
- @Override
- public void update() {
- }
- }
|