NPCOptionsGUI.java 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package me.lethunderhawk.fluxapi.npc.gui;
  2. import me.lethunderhawk.fluxapi.FluxService;
  3. import me.lethunderhawk.fluxapi.util.gui.InventoryGUI;
  4. import me.lethunderhawk.fluxapi.util.gui.input.SignMenuFactory;
  5. import me.lethunderhawk.fluxapi.util.itemdesign.ItemOptions;
  6. import me.lethunderhawk.fluxapi.util.itemdesign.LoreDesigner;
  7. import me.lethunderhawk.fluxapi.main.FluxAPI;
  8. import me.lethunderhawk.fluxapi.npc.abstraction.NPC;
  9. import me.lethunderhawk.fluxapi.npc.manager.NPCManager;
  10. import net.kyori.adventure.text.Component;
  11. import net.kyori.adventure.text.format.NamedTextColor;
  12. import org.bukkit.Material;
  13. import org.bukkit.entity.Player;
  14. import org.bukkit.event.inventory.ClickType;
  15. import org.bukkit.inventory.ItemStack;
  16. import java.util.List;
  17. public class NPCOptionsGUI extends InventoryGUI {
  18. private final NPC npc;
  19. public NPCOptionsGUI(NPC npc) {
  20. super("Options for NPC: " + npc.getName(), 36);
  21. this.npc = npc;
  22. }
  23. private void editName(Player player, ClickType type) {
  24. if(player.hasPermission("npc.edit")) {
  25. SignMenuFactory.Menu menu = new SignMenuFactory(FluxService.get(FluxAPI.class)).newMenu(List.of(
  26. npc.getName(),
  27. "^^^^^^^^",
  28. "Edit the name",
  29. "of this NPC"
  30. )).reopenIfFail(true);
  31. menu.response((Player pl, String[] input) -> {
  32. String newName = input[0];
  33. if(newName.isEmpty()) return false;
  34. pl.sendMessage("Renamed " + npc.getName() + " to " + newName);
  35. FluxService.get(NPCManager.class).renameNPCbyId(npc.getOptions().getEntity().getUniqueId(), newName);
  36. return true;
  37. });
  38. menu.open(player);
  39. }
  40. }
  41. @Override
  42. public void buildContent() {
  43. fillGlassPaneBackground();
  44. ItemStack item = new ItemOptions(Material.OAK_SIGN)
  45. .setName(Component.text("Rename this NPC", NamedTextColor.YELLOW))
  46. .setLore(
  47. 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)
  48. )
  49. .buildItemStack();
  50. setItemWithClickAction(4, item, this::editName);
  51. }
  52. @Override
  53. public void update() {
  54. }
  55. }