Add basics of /npc gui
This commit is contained in:
parent
8c120aae52
commit
a4dde9f017
|
@ -82,6 +82,7 @@ import net.citizensnpcs.api.util.Colorizer;
|
|||
import net.citizensnpcs.api.util.Messaging;
|
||||
import net.citizensnpcs.api.util.Paginator;
|
||||
import net.citizensnpcs.api.util.SpigotUtil;
|
||||
import net.citizensnpcs.commands.gui.NPCConfigurator;
|
||||
import net.citizensnpcs.npc.EntityControllers;
|
||||
import net.citizensnpcs.npc.NPCSelector;
|
||||
import net.citizensnpcs.npc.Template;
|
||||
|
@ -829,6 +830,18 @@ public class NPCCommands {
|
|||
Messaging.sendTr(sender, key, npc.getName());
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "gui",
|
||||
desc = "Display NPC configuration GUI",
|
||||
modifiers = { "gui" },
|
||||
min = 1,
|
||||
max = 1,
|
||||
permission = "citizens.npc.gui")
|
||||
public void gui(CommandContext args, Player sender, NPC npc) {
|
||||
InventoryMenu.createSelfRegistered(new NPCConfigurator(npc)).present(sender);
|
||||
}
|
||||
|
||||
@Command(
|
||||
aliases = { "npc" },
|
||||
usage = "hologram add [text] | set [line #] [text] | remove [line #] | clear | lineheight [height] | direction [up|down]",
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
package net.citizensnpcs.commands.gui;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.citizensnpcs.api.gui.CitizensInventoryClickEvent;
|
||||
import net.citizensnpcs.api.gui.InventoryMenuPage;
|
||||
import net.citizensnpcs.api.gui.InventoryMenuSlot;
|
||||
import net.citizensnpcs.api.gui.Menu;
|
||||
import net.citizensnpcs.api.gui.MenuContext;
|
||||
import net.citizensnpcs.api.gui.ModalMenuInput;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.util.Messaging;
|
||||
import net.citizensnpcs.util.Util;
|
||||
|
||||
@Menu(title = "Configure NPC", type = InventoryType.CHEST, dimensions = { 5, 9 })
|
||||
public class NPCConfigurator extends InventoryMenuPage {
|
||||
private final NPC npc;
|
||||
|
||||
private NPCConfigurator() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public NPCConfigurator(NPC npc) {
|
||||
this.npc = npc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialise(MenuContext ctx) {
|
||||
for (Map.Entry<Integer, ConfiguratorInfo> entry : SLOT_MAP.entrySet()) {
|
||||
ConfiguratorInfo info = entry.getValue();
|
||||
InventoryMenuSlot slot = ctx.getSlot(entry.getKey());
|
||||
slot.setItemStack(new ItemStack(info.material, 1));
|
||||
slot.addClickHandler((evt) -> {
|
||||
info.clickHandler.accept(new ConfiguratorEvent(ctx, npc, slot, evt));
|
||||
});
|
||||
info.clickHandler.accept(new ConfiguratorEvent(ctx, npc, slot, null));
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConfiguratorEvent {
|
||||
private final MenuContext ctx;
|
||||
private final CitizensInventoryClickEvent event;
|
||||
private final NPC npc;
|
||||
private final InventoryMenuSlot slot;
|
||||
|
||||
public ConfiguratorEvent(MenuContext ctx, NPC npc, InventoryMenuSlot slot, CitizensInventoryClickEvent evt) {
|
||||
this.ctx = ctx;
|
||||
this.npc = npc;
|
||||
this.slot = slot;
|
||||
this.event = evt;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ConfiguratorInfo {
|
||||
private final Consumer<ConfiguratorEvent> clickHandler;
|
||||
private final Material material;
|
||||
|
||||
public ConfiguratorInfo(Material mat, Consumer<ConfiguratorEvent> con) {
|
||||
this.material = mat;
|
||||
this.clickHandler = con;
|
||||
}
|
||||
}
|
||||
|
||||
private static final Map<Integer, ConfiguratorInfo> SLOT_MAP = Maps.newHashMap();
|
||||
static {
|
||||
SLOT_MAP.put(0, new ConfiguratorInfo(Util.getFallbackMaterial("OAK_SIGN", "SIGN"), (evt) -> {
|
||||
evt.slot.setDescription("Edit NPC name\n" + evt.npc.getName());
|
||||
if (evt.event != null) {
|
||||
Messaging.send(evt.event.getWhoClicked(), "Type new NPC name or [[exit]]");
|
||||
ModalMenuInput.captureInput((Player) evt.event.getWhoClicked(), evt.ctx.getMenu(),
|
||||
(input) -> evt.npc.setName(input));
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue