further command improvements
This commit is contained in:
parent
6566260089
commit
a2503cb3cb
18 changed files with 187 additions and 280 deletions
|
@ -28,7 +28,7 @@ dependencies {
|
|||
implementation "com.github.retrooper.packetevents:spigot:2.0.0-SNAPSHOT"
|
||||
implementation "space.arim.dazzleconf:dazzleconf-ext-snakeyaml:1.2.1"
|
||||
|
||||
implementation "lol.pyr:director-adventure:2.0.4"
|
||||
implementation "lol.pyr:director-adventure:2.0.6"
|
||||
implementation project(":api")
|
||||
}
|
||||
|
||||
|
|
|
@ -6,9 +6,12 @@ import com.github.retrooper.packetevents.protocol.entity.type.EntityTypes;
|
|||
import io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;
|
||||
import lol.pyr.director.adventure.command.CommandManager;
|
||||
import lol.pyr.director.adventure.command.MultiCommand;
|
||||
import lol.pyr.director.adventure.parse.primitive.IntegerParser;
|
||||
import lol.pyr.znpcsplus.api.ZApiProvider;
|
||||
import lol.pyr.znpcsplus.commands.*;
|
||||
import lol.pyr.znpcsplus.commands.hologram.*;
|
||||
import lol.pyr.znpcsplus.commands.parsers.NpcEntryParser;
|
||||
import lol.pyr.znpcsplus.commands.parsers.NpcTypeParser;
|
||||
import lol.pyr.znpcsplus.config.Configs;
|
||||
import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
|
||||
import lol.pyr.znpcsplus.interaction.InteractionPacketListener;
|
||||
|
@ -185,7 +188,12 @@ public class ZNpcsPlus extends JavaPlugin {
|
|||
}
|
||||
|
||||
private void registerCommands() {
|
||||
// TODO: Messages in here
|
||||
CommandManager manager = new CommandManager(this, ADVENTURE, context -> {});
|
||||
manager.registerParser(NpcTypeImpl.class, new NpcTypeParser(context -> {}));
|
||||
manager.registerParser(NpcEntryImpl.class, new NpcEntryParser(context -> {}));
|
||||
manager.registerParser(Integer.class, new IntegerParser(context -> {}));
|
||||
|
||||
manager.registerCommand("npc", new MultiCommand()
|
||||
.addSubcommand("action", new ActionCommand())
|
||||
.addSubcommand("conversations", new ConversationsCommand())
|
||||
|
|
|
@ -4,17 +4,18 @@ import lol.pyr.director.adventure.command.CommandContext;
|
|||
import lol.pyr.director.adventure.command.CommandHandler;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ActionCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void run(CommandContext commandContext) throws CommandExecutionException {
|
||||
commandContext.getSender().sendMessage("Not implemented yet.");
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
context.send("Not implemented yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
return CommandHandler.super.suggest(context);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,16 +4,17 @@ import lol.pyr.director.adventure.command.CommandContext;
|
|||
import lol.pyr.director.adventure.command.CommandHandler;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ConversationsCommand implements CommandHandler {
|
||||
@Override
|
||||
public void run(CommandContext commandContext) throws CommandExecutionException {
|
||||
commandContext.getSender().sendMessage("Not implemented yet.");
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
context.send("Not implemented yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
return CommandHandler.super.suggest(context);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,13 +3,12 @@ package lol.pyr.znpcsplus.commands;
|
|||
import lol.pyr.director.adventure.command.CommandContext;
|
||||
import lol.pyr.director.adventure.command.CommandHandler;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
import lol.pyr.znpcsplus.ZNpcsPlus;
|
||||
import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcTypeImpl;
|
||||
import lol.pyr.znpcsplus.skin.descriptor.FetchingDescriptor;
|
||||
import lol.pyr.znpcsplus.skin.descriptor.PrefetchedDescriptor;
|
||||
import lol.pyr.znpcsplus.util.ZLocation;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
@ -21,39 +20,23 @@ import java.util.List;
|
|||
public class CreateCommand implements CommandHandler {
|
||||
@Override
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
if (!(context.getSender() instanceof Player)) {
|
||||
ZNpcsPlus.ADVENTURE.sender(context.getSender()).sendMessage(Component.text("Only players can use this command.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
Player player = (Player) context.getSender();
|
||||
if (context.argSize() < 3) {
|
||||
ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("Usage: /npc create <npc_id> <npc_type> <npc_name>", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
String npcId = context.popString();
|
||||
if (npcId.toLowerCase().startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)) {
|
||||
ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("You can not create an Npc with that ID", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(npcId);
|
||||
if (npcEntry != null) {
|
||||
ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("NPC with that ID already exists.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
NpcTypeImpl npcType = NpcTypeImpl.byName(context.popString().toUpperCase());
|
||||
if (npcType == null) {
|
||||
ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("Invalid NPC type.", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
String npcName = context.popString();
|
||||
NpcEntryImpl npcEntry1 = NpcRegistryImpl.get().create(npcId, player.getWorld(), npcType, new ZLocation(player.getLocation()));
|
||||
npcEntry1.enableEverything();
|
||||
NpcImpl npc = npcEntry1.getNpc();
|
||||
if (npcType == NpcTypeImpl.PLAYER) {
|
||||
npc.setProperty(EntityPropertyImpl.SKIN, new FetchingDescriptor(npcName));
|
||||
}
|
||||
npc.getHologram().addLine(Component.text(npcName));
|
||||
ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("Created NPC with ID " + npcId + " and name " + npcName + ".", NamedTextColor.GREEN));
|
||||
context.setUsage(context.getLabel() + " create <npc_id> <npc_type> <npc_name>");
|
||||
Player player = context.ensureSenderIsPlayer();
|
||||
|
||||
String id = context.popString();
|
||||
if (NpcRegistryImpl.get().get(id) != null) context.halt(Component.text("NPC with that ID already exists.", NamedTextColor.RED));
|
||||
|
||||
NpcTypeImpl type = context.parse(NpcTypeImpl.class);
|
||||
String name = context.popString();
|
||||
|
||||
NpcEntryImpl entry = NpcRegistryImpl.get().create(id, player.getWorld(), type, new ZLocation(player.getLocation()));
|
||||
entry.enableEverything();
|
||||
|
||||
NpcImpl npc = entry.getNpc();
|
||||
if (type == NpcTypeImpl.PLAYER) PrefetchedDescriptor.forPlayer(name).thenAccept(skin -> npc.setProperty(EntityPropertyImpl.SKIN, skin));
|
||||
npc.getHologram().addLine(Component.text(name));
|
||||
|
||||
context.send(Component.text("Created NPC with ID " + id + " and name " + name + ".", NamedTextColor.GREEN));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,18 +15,10 @@ import java.util.List;
|
|||
public class DeleteCommand implements CommandHandler {
|
||||
@Override
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
if (context.argSize() != 1) {
|
||||
ZNpcsPlus.ADVENTURE.sender(context.getSender()).sendMessage(Component.text("Usage: /npc delete <npc_id>", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
String id = context.popString();
|
||||
NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(id);
|
||||
if (npcEntry == null) {
|
||||
ZNpcsPlus.ADVENTURE.sender(context.getSender()).sendMessage(Component.text("NPC not found!", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
NpcRegistryImpl.get().delete(id);
|
||||
ZNpcsPlus.ADVENTURE.sender(context.getSender()).sendMessage(Component.text("Deleted NPC with ID: " + id, NamedTextColor.GREEN));
|
||||
context.setUsage(context.getLabel() + " delete <npc_id>");
|
||||
NpcEntryImpl entry = context.parse(NpcEntryImpl.class);
|
||||
NpcRegistryImpl.get().delete(entry.getId());
|
||||
ZNpcsPlus.ADVENTURE.sender(context.getSender()).sendMessage(Component.text("Deleted NPC with ID: " + entry.getId(), NamedTextColor.GREEN));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,8 +3,7 @@ package lol.pyr.znpcsplus.commands;
|
|||
import lol.pyr.director.adventure.command.CommandContext;
|
||||
import lol.pyr.director.adventure.command.CommandHandler;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
import lol.pyr.znpcsplus.ZNpcsPlus;
|
||||
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
|
@ -12,34 +11,35 @@ import net.kyori.adventure.text.event.ClickEvent;
|
|||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ListCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void run(CommandContext commandContext) throws CommandExecutionException {
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
TextComponent.Builder component = Component.text("Npc's:\n").color(NamedTextColor.GOLD).toBuilder();
|
||||
for (String id : lol.pyr.znpcsplus.npc.NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).toArray(String[]::new)) {
|
||||
NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(id);
|
||||
Location location = npcEntry.getNpc().getLocation().toBukkitLocation(npcEntry.getNpc().getWorld());
|
||||
for (String id : NpcRegistryImpl.get().modifiableIds()) {
|
||||
NpcImpl npc = NpcRegistryImpl.get().get(id).getNpc();
|
||||
Location location = npc.getLocation().toBukkitLocation(npc.getWorld());
|
||||
component.append(Component.text("ID: " + id, NamedTextColor.GREEN))
|
||||
.append(Component.text(" | ", NamedTextColor.GRAY))
|
||||
.append(Component.text("Type: ", NamedTextColor.GREEN))
|
||||
.append(Component.text(npcEntry.getNpc().getType().getName(), NamedTextColor.GREEN))
|
||||
.append(Component.text(npc.getType().getName(), NamedTextColor.GREEN))
|
||||
.append(Component.text(" | ", NamedTextColor.GRAY))
|
||||
.append(Component.text("Name: ", NamedTextColor.GREEN))
|
||||
.append(npcEntry.getNpc().getHologram().getLine(0).color(NamedTextColor.GREEN))
|
||||
.append(npc.getHologram().getLine(0).color(NamedTextColor.GREEN))
|
||||
.append(Component.text(" | ", NamedTextColor.GRAY))
|
||||
.append(Component.text("Location: " + npcEntry.getNpc().getWorld().getName() + " X:" + location.getBlockX() + " Y:" + location.getBlockY() + " Z:" + location.getBlockZ(), NamedTextColor.GREEN))
|
||||
.append(Component.text("Location: " + npc.getWorld().getName() + " X:" + location.getBlockX() + " Y:" + location.getBlockY() + " Z:" + location.getBlockZ(), NamedTextColor.GREEN))
|
||||
.append(Component.text(" | ", NamedTextColor.GRAY))
|
||||
.append(Component.text("[TELEPORT]", NamedTextColor.DARK_GREEN).clickEvent(ClickEvent.runCommand("/npc teleport " + id)))
|
||||
.append(Component.text("\n", NamedTextColor.GRAY));
|
||||
}
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(component.build());
|
||||
context.send(component.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
return CommandHandler.super.suggest(context);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,44 +3,31 @@ package lol.pyr.znpcsplus.commands;
|
|||
import lol.pyr.director.adventure.command.CommandContext;
|
||||
import lol.pyr.director.adventure.command.CommandHandler;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
import lol.pyr.znpcsplus.ZNpcsPlus;
|
||||
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
|
||||
import lol.pyr.znpcsplus.util.ZLocation;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MoveCommand implements CommandHandler {
|
||||
@Override
|
||||
public void run(CommandContext commandContext) throws CommandExecutionException {
|
||||
if (!(commandContext.getSender() instanceof Player)) {
|
||||
commandContext.getSender().sendMessage("Only players can use this command!");
|
||||
return;
|
||||
}
|
||||
Player player = (Player) commandContext.getSender();
|
||||
if (commandContext.argSize() == 0) {
|
||||
ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("Usage: /npc <npc_id>", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(commandContext.popString());
|
||||
if (npcEntry == null) {
|
||||
ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("NPC not found!", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
npcEntry.getNpc().setLocation(new ZLocation(player.getLocation()));
|
||||
npcEntry.getNpc().respawn();
|
||||
ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("NPC moved!", NamedTextColor.GREEN));
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
context.setUsage(context.getLabel() + " move <npc_id>");
|
||||
Player player = context.ensureSenderIsPlayer();
|
||||
NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc();
|
||||
npc.setLocation(new ZLocation(player.getLocation()));
|
||||
npc.respawn();
|
||||
context.send(Component.text("NPC moved to your current location.", NamedTextColor.GREEN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
if (context.argSize() == 1) {
|
||||
return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList()));
|
||||
}
|
||||
return CommandHandler.super.suggest(context);
|
||||
if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds());
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,16 +4,17 @@ import lol.pyr.director.adventure.command.CommandContext;
|
|||
import lol.pyr.director.adventure.command.CommandHandler;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PathCommand implements CommandHandler {
|
||||
@Override
|
||||
public void run(CommandContext commandContext) throws CommandExecutionException {
|
||||
commandContext.getSender().sendMessage("Not implemented yet.");
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
context.send("Not implemented yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
return CommandHandler.super.suggest(context);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,16 +4,17 @@ import lol.pyr.director.adventure.command.CommandContext;
|
|||
import lol.pyr.director.adventure.command.CommandHandler;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PropertiesCommand implements CommandHandler {
|
||||
@Override
|
||||
public void run(CommandContext commandContext) throws CommandExecutionException {
|
||||
commandContext.getSender().sendMessage("Not implemented yet!");
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
context.send("Not implemented yet!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
return CommandHandler.super.suggest(context);
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,42 +3,29 @@ package lol.pyr.znpcsplus.commands;
|
|||
import lol.pyr.director.adventure.command.CommandContext;
|
||||
import lol.pyr.director.adventure.command.CommandHandler;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
import lol.pyr.znpcsplus.ZNpcsPlus;
|
||||
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TeleportCommand implements CommandHandler {
|
||||
@Override
|
||||
public void run(CommandContext commandContext) throws CommandExecutionException {
|
||||
if (!(commandContext.getSender() instanceof Player)) {
|
||||
commandContext.getSender().sendMessage("Only players can use this command!");
|
||||
return;
|
||||
}
|
||||
Player player = (Player) commandContext.getSender();
|
||||
if (commandContext.argSize() == 0) {
|
||||
ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("Usage: /npc teleport <npc_id>", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(commandContext.popString());
|
||||
if (npcEntry == null) {
|
||||
ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("NPC not found!", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
player.teleport(npcEntry.getNpc().getLocation().toBukkitLocation(npcEntry.getNpc().getWorld()));
|
||||
ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("Teleported to NPC!", NamedTextColor.GREEN));
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
context.setUsage(context.getLabel() + " teleport <npc_id>");
|
||||
Player player = context.ensureSenderIsPlayer();
|
||||
NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc();
|
||||
player.teleport(npc.getLocation().toBukkitLocation(npc.getWorld()));
|
||||
context.send(Component.text("Teleported to NPC!", NamedTextColor.GREEN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
if (context.argSize() == 1) {
|
||||
return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList()));
|
||||
}
|
||||
return CommandHandler.super.suggest(context);
|
||||
if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds());
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,41 +3,27 @@ package lol.pyr.znpcsplus.commands.hologram;
|
|||
import lol.pyr.director.adventure.command.CommandContext;
|
||||
import lol.pyr.director.adventure.command.CommandHandler;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
import lol.pyr.znpcsplus.ZNpcsPlus;
|
||||
import lol.pyr.znpcsplus.hologram.HologramImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class HoloAddCommand implements CommandHandler {
|
||||
@Override
|
||||
public void run(CommandContext commandContext) throws CommandExecutionException {
|
||||
if (commandContext.argSize() < 2) {
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Usage: /npc holo add <npc_id> <text>", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
String id = commandContext.popString();
|
||||
NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(id);
|
||||
if (npcEntry == null) {
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("NPC not found!", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
npcEntry.getNpc().getHologram().addLine(Component.text(commandContext.dumpAllArgs()));
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("NPC line added!", NamedTextColor.GREEN));
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
context.setUsage(context.getLabel() + " holo add <npc_id> <text>");
|
||||
HologramImpl hologram = context.parse(NpcEntryImpl.class).getNpc().getHologram();
|
||||
hologram.addLine(Component.text(context.dumpAllArgs()));
|
||||
context.send(Component.text("NPC line added!", NamedTextColor.GREEN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
if (context.argSize() == 1) {
|
||||
return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList()));
|
||||
}
|
||||
if (context.argSize() == 2) {
|
||||
return context.suggestStream(Stream.of("<text>"));
|
||||
}
|
||||
return CommandHandler.super.suggest(context);
|
||||
if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds());
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,53 +3,33 @@ package lol.pyr.znpcsplus.commands.hologram;
|
|||
import lol.pyr.director.adventure.command.CommandContext;
|
||||
import lol.pyr.director.adventure.command.CommandHandler;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
import lol.pyr.znpcsplus.ZNpcsPlus;
|
||||
import lol.pyr.znpcsplus.hologram.HologramImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class HoloDeleteCommand implements CommandHandler {
|
||||
@Override
|
||||
public void run(CommandContext commandContext) throws CommandExecutionException {
|
||||
if (commandContext.argSize() < 2) {
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Usage: /npc holo delete <npc_id> <line>", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
String id = commandContext.popString();
|
||||
NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(id);
|
||||
if (npcEntry == null) {
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("NPC not found!", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
int line;
|
||||
try {
|
||||
line = Integer.parseInt(commandContext.popString());
|
||||
} catch (NumberFormatException e) {
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Invalid line number!", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (line < 0 || line >= npcEntry.getNpc().getHologram().getLines().size()) {
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Invalid line number!", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
npcEntry.getNpc().getHologram().removeLine(line);
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("NPC line removed!", NamedTextColor.GREEN));
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
context.setUsage(context.getLabel() + " holo delete <npc_id> <line>");
|
||||
HologramImpl hologram = context.parse(NpcEntryImpl.class).getNpc().getHologram();
|
||||
int line = context.parse(Integer.class);
|
||||
if (line < 0 || line >= hologram.getLines().size()) context.halt(Component.text("Invalid line number!", NamedTextColor.RED));
|
||||
hologram.removeLine(line);
|
||||
context.send(Component.text("NPC line removed.", NamedTextColor.GREEN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
if (context.argSize() == 1) {
|
||||
return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList()));
|
||||
}
|
||||
if (context.argSize() == 2) {
|
||||
int lines = NpcRegistryImpl.get().get(context.popString()).getNpc().getHologram().getLines().size();
|
||||
return context.suggestStream(Stream.iterate(0, n -> n + 1).limit(lines).map(String::valueOf));
|
||||
}
|
||||
return CommandHandler.super.suggest(context);
|
||||
if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds());
|
||||
if (context.argSize() == 2) return context.suggestStream(Stream.iterate(0, n -> n + 1)
|
||||
.limit(context.suggestionParse(1, NpcEntryImpl.class).getNpc().getHologram().getLines().size())
|
||||
.map(String::valueOf));
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,51 +3,30 @@ package lol.pyr.znpcsplus.commands.hologram;
|
|||
import lol.pyr.director.adventure.command.CommandContext;
|
||||
import lol.pyr.director.adventure.command.CommandHandler;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
import lol.pyr.znpcsplus.ZNpcsPlus;
|
||||
import lol.pyr.znpcsplus.hologram.HologramImpl;
|
||||
import lol.pyr.znpcsplus.hologram.HologramLine;
|
||||
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class HoloInfoCommand implements CommandHandler {
|
||||
@Override
|
||||
public void run(CommandContext commandContext) throws CommandExecutionException {
|
||||
if (!(commandContext.getSender() instanceof Player)) {
|
||||
commandContext.getSender().sendMessage("Only players can use this command!");
|
||||
return;
|
||||
}
|
||||
Player player = (Player) commandContext.getSender();
|
||||
if (commandContext.argSize() < 1) {
|
||||
ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("Usage: /npc holo info <npc_id>", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
String id = commandContext.popString();
|
||||
NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(id);
|
||||
if (npcEntry == null) {
|
||||
ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("NPC not found!", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
List<HologramLine> lines = npcEntry.getNpc().getHologram().getLines();
|
||||
TextComponent component = Component.text("NPC Hologram Info of ID " + npcEntry.getId() + ":", NamedTextColor.GREEN);
|
||||
component = component.append(Component.newline());
|
||||
for (HologramLine line : lines) {
|
||||
component = component.append(line.getText());
|
||||
component = component.append(Component.newline());
|
||||
}
|
||||
ZNpcsPlus.ADVENTURE.player(player).sendMessage(component);
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
context.setUsage(context.getLabel() + " holo info <npc_id>");
|
||||
NpcEntryImpl entry = context.parse(NpcEntryImpl.class);
|
||||
HologramImpl hologram = entry.getNpc().getHologram();
|
||||
Component component = Component.text("NPC Hologram Info of ID " + entry.getId() + ":", NamedTextColor.GREEN).appendNewline();
|
||||
for (HologramLine line : hologram.getLines()) component = component.append(line.getText()).appendNewline();
|
||||
context.send(component);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
if (context.argSize() == 1) {
|
||||
return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList()));
|
||||
}
|
||||
return CommandHandler.super.suggest(context);
|
||||
if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds());
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,55 +3,33 @@ package lol.pyr.znpcsplus.commands.hologram;
|
|||
import lol.pyr.director.adventure.command.CommandContext;
|
||||
import lol.pyr.director.adventure.command.CommandHandler;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
import lol.pyr.znpcsplus.ZNpcsPlus;
|
||||
import lol.pyr.znpcsplus.hologram.HologramImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class HoloInsertCommand implements CommandHandler {
|
||||
@Override
|
||||
public void run(CommandContext commandContext) throws CommandExecutionException {
|
||||
if (commandContext.argSize() < 3) {
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Usage: /npc holo insert <npc_id> <line> <text>", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
String id = commandContext.popString();
|
||||
NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(id);
|
||||
if (npcEntry == null) {
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("NPC not found!", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
int line;
|
||||
try {
|
||||
line = Integer.parseInt(commandContext.popString());
|
||||
} catch (NumberFormatException e) {
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Invalid line number!", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (line < 0 || line >= npcEntry.getNpc().getHologram().getLines().size()) {
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Invalid line number!", NamedTextColor.RED));
|
||||
}
|
||||
npcEntry.getNpc().getHologram().insertLine(line, Component.text(commandContext.dumpAllArgs()));
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("NPC line inserted!", NamedTextColor.GREEN));
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
context.setUsage(context.getLabel() + " holo insert <npc_id> <line> <text>");
|
||||
HologramImpl hologram = context.parse(NpcEntryImpl.class).getNpc().getHologram();
|
||||
int line = context.parse(Integer.class);
|
||||
if (line < 0 || line >= hologram.getLines().size()) context.halt(Component.text("Invalid line number!", NamedTextColor.RED));
|
||||
hologram.insertLine(line, Component.text(context.dumpAllArgs()));
|
||||
context.send(Component.text("NPC line inserted!", NamedTextColor.GREEN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
if (context.argSize() == 1) {
|
||||
return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList()));
|
||||
}
|
||||
if (context.argSize() == 2) {
|
||||
int lines = NpcRegistryImpl.get().get(context.popString()).getNpc().getHologram().getLines().size();
|
||||
return context.suggestStream(Stream.iterate(0, n -> n + 1).limit(lines).map(String::valueOf));
|
||||
}
|
||||
if (context.argSize() == 3) {
|
||||
return context.suggestStream(Stream.of("<text>"));
|
||||
}
|
||||
return CommandHandler.super.suggest(context);
|
||||
if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds());
|
||||
if (context.argSize() == 2) return context.suggestStream(Stream.iterate(0, n -> n + 1)
|
||||
.limit(context.suggestionParse(1, NpcEntryImpl.class).getNpc().getHologram().getLines().size())
|
||||
.map(String::valueOf));
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,56 +3,34 @@ package lol.pyr.znpcsplus.commands.hologram;
|
|||
import lol.pyr.director.adventure.command.CommandContext;
|
||||
import lol.pyr.director.adventure.command.CommandHandler;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
import lol.pyr.znpcsplus.ZNpcsPlus;
|
||||
import lol.pyr.znpcsplus.hologram.HologramImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class HoloSetCommand implements CommandHandler {
|
||||
@Override
|
||||
public void run(CommandContext commandContext) throws CommandExecutionException {
|
||||
if (commandContext.argSize() < 2) {
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Usage: /npc holo set <npc_id> <line> <text>", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
String id = commandContext.popString();
|
||||
NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(id);
|
||||
if (npcEntry == null) {
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("NPC not found!", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
int line;
|
||||
try {
|
||||
line = Integer.parseInt(commandContext.popString());
|
||||
} catch (NumberFormatException e) {
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Invalid line number!", NamedTextColor.RED));
|
||||
return;
|
||||
}
|
||||
if (line < 0 || line >= npcEntry.getNpc().getHologram().getLines().size()) {
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Invalid line number!", NamedTextColor.RED));
|
||||
}
|
||||
npcEntry.getNpc().getHologram().removeLine(line);
|
||||
npcEntry.getNpc().getHologram().insertLine(line, Component.text(commandContext.dumpAllArgs()));
|
||||
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("NPC line set!", NamedTextColor.GREEN));
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
context.setUsage(context.getLabel() + " holo set <npc_id> <line> <text>");
|
||||
HologramImpl hologram = context.parse(NpcEntryImpl.class).getNpc().getHologram();
|
||||
int line = context.parse(Integer.class);
|
||||
if (line < 0 || line >= hologram.getLines().size()) context.halt(Component.text("Invalid line number!", NamedTextColor.RED));
|
||||
hologram.removeLine(line);
|
||||
hologram.insertLine(line, Component.text(context.dumpAllArgs()));
|
||||
context.send(Component.text("NPC line set!", NamedTextColor.GREEN));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
if (context.argSize() == 1) {
|
||||
return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList()));
|
||||
}
|
||||
if (context.argSize() == 2) {
|
||||
int lines = NpcRegistryImpl.get().get(context.popString()).getNpc().getHologram().getLines().size();
|
||||
return context.suggestStream(Stream.iterate(0, n -> n + 1).limit(lines).map(String::valueOf));
|
||||
}
|
||||
if (context.argSize() == 3) {
|
||||
return context.suggestStream(Stream.of("<text>"));
|
||||
}
|
||||
return CommandHandler.super.suggest(context);
|
||||
if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds());
|
||||
if (context.argSize() == 2) return context.suggestStream(Stream.iterate(0, n -> n + 1)
|
||||
.limit(context.suggestionParse(1, NpcEntryImpl.class).getNpc().getHologram().getLines().size())
|
||||
.map(String::valueOf));
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package lol.pyr.znpcsplus.commands.parsers;
|
||||
|
||||
import lol.pyr.director.adventure.command.CommandContext;
|
||||
import lol.pyr.director.adventure.parse.ParserType;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
import lol.pyr.director.common.message.Message;
|
||||
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
|
||||
|
||||
import java.util.Deque;
|
||||
|
||||
public class NpcEntryParser extends ParserType<NpcEntryImpl> {
|
||||
public NpcEntryParser(Message<CommandContext> message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NpcEntryImpl parse(Deque<String> deque) throws CommandExecutionException {
|
||||
NpcEntryImpl entry = NpcRegistryImpl.get().get(deque.pop());
|
||||
if (entry == null || !entry.isAllowCommandModification()) throw new CommandExecutionException();
|
||||
return entry;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package lol.pyr.znpcsplus.commands.parsers;
|
||||
|
||||
import lol.pyr.director.adventure.command.CommandContext;
|
||||
import lol.pyr.director.adventure.parse.ParserType;
|
||||
import lol.pyr.director.common.command.CommandExecutionException;
|
||||
import lol.pyr.director.common.message.Message;
|
||||
import lol.pyr.znpcsplus.npc.NpcTypeImpl;
|
||||
|
||||
import java.util.Deque;
|
||||
|
||||
public class NpcTypeParser extends ParserType<NpcTypeImpl> {
|
||||
public NpcTypeParser(Message<CommandContext> message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NpcTypeImpl parse(Deque<String> deque) throws CommandExecutionException {
|
||||
NpcTypeImpl type = NpcTypeImpl.byName(deque.pop());
|
||||
if (type == null) throw new CommandExecutionException();
|
||||
return type;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue