further command improvements

This commit is contained in:
Pyrbu 2023-05-10 16:01:14 +01:00
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 "com.github.retrooper.packetevents:spigot:2.0.0-SNAPSHOT"
implementation "space.arim.dazzleconf:dazzleconf-ext-snakeyaml:1.2.1" 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") 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 io.github.retrooper.packetevents.factory.spigot.SpigotPacketEventsBuilder;
import lol.pyr.director.adventure.command.CommandManager; import lol.pyr.director.adventure.command.CommandManager;
import lol.pyr.director.adventure.command.MultiCommand; 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.api.ZApiProvider;
import lol.pyr.znpcsplus.commands.*; import lol.pyr.znpcsplus.commands.*;
import lol.pyr.znpcsplus.commands.hologram.*; 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.config.Configs;
import lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
import lol.pyr.znpcsplus.interaction.InteractionPacketListener; import lol.pyr.znpcsplus.interaction.InteractionPacketListener;
@ -185,7 +188,12 @@ public class ZNpcsPlus extends JavaPlugin {
} }
private void registerCommands() { private void registerCommands() {
// TODO: Messages in here
CommandManager manager = new CommandManager(this, ADVENTURE, context -> {}); 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() manager.registerCommand("npc", new MultiCommand()
.addSubcommand("action", new ActionCommand()) .addSubcommand("action", new ActionCommand())
.addSubcommand("conversations", new ConversationsCommand()) .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.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.director.common.command.CommandExecutionException;
import java.util.Collections;
import java.util.List; import java.util.List;
public class ActionCommand implements CommandHandler { public class ActionCommand implements CommandHandler {
@Override @Override
public void run(CommandContext commandContext) throws CommandExecutionException { public void run(CommandContext context) throws CommandExecutionException {
commandContext.getSender().sendMessage("Not implemented yet."); context.send("Not implemented yet.");
} }
@Override @Override
public List<String> suggest(CommandContext context) throws CommandExecutionException { 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.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.director.common.command.CommandExecutionException;
import java.util.Collections;
import java.util.List; import java.util.List;
public class ConversationsCommand implements CommandHandler { public class ConversationsCommand implements CommandHandler {
@Override @Override
public void run(CommandContext commandContext) throws CommandExecutionException { public void run(CommandContext context) throws CommandExecutionException {
commandContext.getSender().sendMessage("Not implemented yet."); context.send("Not implemented yet.");
} }
@Override @Override
public List<String> suggest(CommandContext context) throws CommandExecutionException { 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.CommandContext;
import lol.pyr.director.adventure.command.CommandHandler; import lol.pyr.director.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.director.common.command.CommandExecutionException;
import lol.pyr.znpcsplus.ZNpcsPlus;
import lol.pyr.znpcsplus.entity.EntityPropertyImpl; import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcImpl; import lol.pyr.znpcsplus.npc.NpcImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import lol.pyr.znpcsplus.npc.NpcTypeImpl; 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 lol.pyr.znpcsplus.util.ZLocation;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
@ -21,39 +20,23 @@ import java.util.List;
public class CreateCommand implements CommandHandler { public class CreateCommand implements CommandHandler {
@Override @Override
public void run(CommandContext context) throws CommandExecutionException { public void run(CommandContext context) throws CommandExecutionException {
if (!(context.getSender() instanceof Player)) { context.setUsage(context.getLabel() + " create <npc_id> <npc_type> <npc_name>");
ZNpcsPlus.ADVENTURE.sender(context.getSender()).sendMessage(Component.text("Only players can use this command.", NamedTextColor.RED)); Player player = context.ensureSenderIsPlayer();
return;
} String id = context.popString();
Player player = (Player) context.getSender(); if (NpcRegistryImpl.get().get(id) != null) context.halt(Component.text("NPC with that ID already exists.", NamedTextColor.RED));
if (context.argSize() < 3) {
ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("Usage: /npc create <npc_id> <npc_type> <npc_name>", NamedTextColor.RED)); NpcTypeImpl type = context.parse(NpcTypeImpl.class);
return; String name = context.popString();
}
String npcId = context.popString(); NpcEntryImpl entry = NpcRegistryImpl.get().create(id, player.getWorld(), type, new ZLocation(player.getLocation()));
if (npcId.toLowerCase().startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)) { entry.enableEverything();
ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("You can not create an Npc with that ID", NamedTextColor.RED));
return; NpcImpl npc = entry.getNpc();
} if (type == NpcTypeImpl.PLAYER) PrefetchedDescriptor.forPlayer(name).thenAccept(skin -> npc.setProperty(EntityPropertyImpl.SKIN, skin));
NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(npcId); npc.getHologram().addLine(Component.text(name));
if (npcEntry != null) {
ZNpcsPlus.ADVENTURE.player(player).sendMessage(Component.text("NPC with that ID already exists.", NamedTextColor.RED)); context.send(Component.text("Created NPC with ID " + id + " and name " + name + ".", NamedTextColor.GREEN));
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));
} }
@Override @Override

@ -15,18 +15,10 @@ import java.util.List;
public class DeleteCommand implements CommandHandler { public class DeleteCommand implements CommandHandler {
@Override @Override
public void run(CommandContext context) throws CommandExecutionException { public void run(CommandContext context) throws CommandExecutionException {
if (context.argSize() != 1) { context.setUsage(context.getLabel() + " delete <npc_id>");
ZNpcsPlus.ADVENTURE.sender(context.getSender()).sendMessage(Component.text("Usage: /npc delete <npc_id>", NamedTextColor.RED)); NpcEntryImpl entry = context.parse(NpcEntryImpl.class);
return; NpcRegistryImpl.get().delete(entry.getId());
} ZNpcsPlus.ADVENTURE.sender(context.getSender()).sendMessage(Component.text("Deleted NPC with ID: " + entry.getId(), NamedTextColor.GREEN));
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));
} }
@Override @Override

@ -3,8 +3,7 @@ package lol.pyr.znpcsplus.commands;
import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.adventure.command.CommandHandler; import lol.pyr.director.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.director.common.command.CommandExecutionException;
import lol.pyr.znpcsplus.ZNpcsPlus; import lol.pyr.znpcsplus.npc.NpcImpl;
import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent; 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 net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Location; import org.bukkit.Location;
import java.util.Collections;
import java.util.List; import java.util.List;
public class ListCommand implements CommandHandler { public class ListCommand implements CommandHandler {
@Override @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(); 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)) { for (String id : NpcRegistryImpl.get().modifiableIds()) {
NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(id); NpcImpl npc = NpcRegistryImpl.get().get(id).getNpc();
Location location = npcEntry.getNpc().getLocation().toBukkitLocation(npcEntry.getNpc().getWorld()); Location location = npc.getLocation().toBukkitLocation(npc.getWorld());
component.append(Component.text("ID: " + id, NamedTextColor.GREEN)) component.append(Component.text("ID: " + id, NamedTextColor.GREEN))
.append(Component.text(" | ", NamedTextColor.GRAY)) .append(Component.text(" | ", NamedTextColor.GRAY))
.append(Component.text("Type: ", NamedTextColor.GREEN)) .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(" | ", NamedTextColor.GRAY))
.append(Component.text("Name: ", NamedTextColor.GREEN)) .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(" | ", 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(" | ", NamedTextColor.GRAY))
.append(Component.text("[TELEPORT]", NamedTextColor.DARK_GREEN).clickEvent(ClickEvent.runCommand("/npc teleport " + id))) .append(Component.text("[TELEPORT]", NamedTextColor.DARK_GREEN).clickEvent(ClickEvent.runCommand("/npc teleport " + id)))
.append(Component.text("\n", NamedTextColor.GRAY)); .append(Component.text("\n", NamedTextColor.GRAY));
} }
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(component.build()); context.send(component.build());
} }
@Override @Override
public List<String> suggest(CommandContext context) throws CommandExecutionException { 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.CommandContext;
import lol.pyr.director.adventure.command.CommandHandler; import lol.pyr.director.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.director.common.command.CommandExecutionException;
import lol.pyr.znpcsplus.ZNpcsPlus;
import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import lol.pyr.znpcsplus.util.ZLocation; import lol.pyr.znpcsplus.util.ZLocation;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class MoveCommand implements CommandHandler { public class MoveCommand implements CommandHandler {
@Override @Override
public void run(CommandContext commandContext) throws CommandExecutionException { public void run(CommandContext context) throws CommandExecutionException {
if (!(commandContext.getSender() instanceof Player)) { context.setUsage(context.getLabel() + " move <npc_id>");
commandContext.getSender().sendMessage("Only players can use this command!"); Player player = context.ensureSenderIsPlayer();
return; NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc();
} npc.setLocation(new ZLocation(player.getLocation()));
Player player = (Player) commandContext.getSender(); npc.respawn();
if (commandContext.argSize() == 0) { context.send(Component.text("NPC moved to your current location.", NamedTextColor.GREEN));
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));
} }
@Override @Override
public List<String> suggest(CommandContext context) throws CommandExecutionException { public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) { if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds());
return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList())); return Collections.emptyList();
}
return CommandHandler.super.suggest(context);
} }
} }

@ -4,16 +4,17 @@ import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.adventure.command.CommandHandler; import lol.pyr.director.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.director.common.command.CommandExecutionException;
import java.util.Collections;
import java.util.List; import java.util.List;
public class PathCommand implements CommandHandler { public class PathCommand implements CommandHandler {
@Override @Override
public void run(CommandContext commandContext) throws CommandExecutionException { public void run(CommandContext context) throws CommandExecutionException {
commandContext.getSender().sendMessage("Not implemented yet."); context.send("Not implemented yet.");
} }
@Override @Override
public List<String> suggest(CommandContext context) throws CommandExecutionException { 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.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.director.common.command.CommandExecutionException;
import java.util.Collections;
import java.util.List; import java.util.List;
public class PropertiesCommand implements CommandHandler { public class PropertiesCommand implements CommandHandler {
@Override @Override
public void run(CommandContext commandContext) throws CommandExecutionException { public void run(CommandContext context) throws CommandExecutionException {
commandContext.getSender().sendMessage("Not implemented yet!"); context.send("Not implemented yet!");
} }
@Override @Override
public List<String> suggest(CommandContext context) throws CommandExecutionException { 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.CommandContext;
import lol.pyr.director.adventure.command.CommandHandler; import lol.pyr.director.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException; import lol.pyr.director.common.command.CommandExecutionException;
import lol.pyr.znpcsplus.ZNpcsPlus;
import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class TeleportCommand implements CommandHandler { public class TeleportCommand implements CommandHandler {
@Override @Override
public void run(CommandContext commandContext) throws CommandExecutionException { public void run(CommandContext context) throws CommandExecutionException {
if (!(commandContext.getSender() instanceof Player)) { context.setUsage(context.getLabel() + " teleport <npc_id>");
commandContext.getSender().sendMessage("Only players can use this command!"); Player player = context.ensureSenderIsPlayer();
return; NpcImpl npc = context.parse(NpcEntryImpl.class).getNpc();
} player.teleport(npc.getLocation().toBukkitLocation(npc.getWorld()));
Player player = (Player) commandContext.getSender(); context.send(Component.text("Teleported to NPC!", NamedTextColor.GREEN));
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));
} }
@Override @Override
public List<String> suggest(CommandContext context) throws CommandExecutionException { public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) { if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds());
return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList())); return Collections.emptyList();
}
return CommandHandler.super.suggest(context);
} }
} }

@ -3,41 +3,27 @@ package lol.pyr.znpcsplus.commands.hologram;
import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.adventure.command.CommandHandler; import lol.pyr.director.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException; 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.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class HoloAddCommand implements CommandHandler { public class HoloAddCommand implements CommandHandler {
@Override @Override
public void run(CommandContext commandContext) throws CommandExecutionException { public void run(CommandContext context) throws CommandExecutionException {
if (commandContext.argSize() < 2) { context.setUsage(context.getLabel() + " holo add <npc_id> <text>");
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Usage: /npc holo add <npc_id> <text>", NamedTextColor.RED)); HologramImpl hologram = context.parse(NpcEntryImpl.class).getNpc().getHologram();
return; hologram.addLine(Component.text(context.dumpAllArgs()));
} context.send(Component.text("NPC line added!", NamedTextColor.GREEN));
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));
} }
@Override @Override
public List<String> suggest(CommandContext context) throws CommandExecutionException { public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) { if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds());
return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList())); return Collections.emptyList();
}
if (context.argSize() == 2) {
return context.suggestStream(Stream.of("<text>"));
}
return CommandHandler.super.suggest(context);
} }
} }

@ -3,53 +3,33 @@ package lol.pyr.znpcsplus.commands.hologram;
import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.adventure.command.CommandHandler; import lol.pyr.director.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException; 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.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
public class HoloDeleteCommand implements CommandHandler { public class HoloDeleteCommand implements CommandHandler {
@Override @Override
public void run(CommandContext commandContext) throws CommandExecutionException { public void run(CommandContext context) throws CommandExecutionException {
if (commandContext.argSize() < 2) { context.setUsage(context.getLabel() + " holo delete <npc_id> <line>");
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Usage: /npc holo delete <npc_id> <line>", NamedTextColor.RED)); HologramImpl hologram = context.parse(NpcEntryImpl.class).getNpc().getHologram();
return; int line = context.parse(Integer.class);
} if (line < 0 || line >= hologram.getLines().size()) context.halt(Component.text("Invalid line number!", NamedTextColor.RED));
String id = commandContext.popString(); hologram.removeLine(line);
NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(id); context.send(Component.text("NPC line removed.", NamedTextColor.GREEN));
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));
} }
@Override @Override
public List<String> suggest(CommandContext context) throws CommandExecutionException { public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) { if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds());
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.iterate(0, n -> n + 1)
} .limit(context.suggestionParse(1, NpcEntryImpl.class).getNpc().getHologram().getLines().size())
if (context.argSize() == 2) { .map(String::valueOf));
int lines = NpcRegistryImpl.get().get(context.popString()).getNpc().getHologram().getLines().size(); return Collections.emptyList();
return context.suggestStream(Stream.iterate(0, n -> n + 1).limit(lines).map(String::valueOf));
}
return CommandHandler.super.suggest(context);
} }
} }

@ -3,51 +3,30 @@ package lol.pyr.znpcsplus.commands.hologram;
import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.adventure.command.CommandHandler; import lol.pyr.director.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException; 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.hologram.HologramLine;
import lol.pyr.znpcsplus.npc.NpcEntryImpl; import lol.pyr.znpcsplus.npc.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
public class HoloInfoCommand implements CommandHandler { public class HoloInfoCommand implements CommandHandler {
@Override @Override
public void run(CommandContext commandContext) throws CommandExecutionException { public void run(CommandContext context) throws CommandExecutionException {
if (!(commandContext.getSender() instanceof Player)) { context.setUsage(context.getLabel() + " holo info <npc_id>");
commandContext.getSender().sendMessage("Only players can use this command!"); NpcEntryImpl entry = context.parse(NpcEntryImpl.class);
return; HologramImpl hologram = entry.getNpc().getHologram();
} Component component = Component.text("NPC Hologram Info of ID " + entry.getId() + ":", NamedTextColor.GREEN).appendNewline();
Player player = (Player) commandContext.getSender(); for (HologramLine line : hologram.getLines()) component = component.append(line.getText()).appendNewline();
if (commandContext.argSize() < 1) { context.send(component);
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);
} }
@Override @Override
public List<String> suggest(CommandContext context) throws CommandExecutionException { public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) { if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds());
return context.suggestCollection(NpcRegistryImpl.get().ids().stream().filter(s -> !s.startsWith(ZNpcsPlus.DEBUG_NPC_PREFIX)).collect(Collectors.toList())); return Collections.emptyList();
}
return CommandHandler.super.suggest(context);
} }
} }

@ -3,55 +3,33 @@ package lol.pyr.znpcsplus.commands.hologram;
import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.adventure.command.CommandHandler; import lol.pyr.director.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException; 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.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
public class HoloInsertCommand implements CommandHandler { public class HoloInsertCommand implements CommandHandler {
@Override @Override
public void run(CommandContext commandContext) throws CommandExecutionException { public void run(CommandContext context) throws CommandExecutionException {
if (commandContext.argSize() < 3) { context.setUsage(context.getLabel() + " holo insert <npc_id> <line> <text>");
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Usage: /npc holo insert <npc_id> <line> <text>", NamedTextColor.RED)); HologramImpl hologram = context.parse(NpcEntryImpl.class).getNpc().getHologram();
return; int line = context.parse(Integer.class);
} if (line < 0 || line >= hologram.getLines().size()) context.halt(Component.text("Invalid line number!", NamedTextColor.RED));
String id = commandContext.popString(); hologram.insertLine(line, Component.text(context.dumpAllArgs()));
NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(id); context.send(Component.text("NPC line inserted!", NamedTextColor.GREEN));
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));
} }
@Override @Override
public List<String> suggest(CommandContext context) throws CommandExecutionException { public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) { if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds());
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.iterate(0, n -> n + 1)
} .limit(context.suggestionParse(1, NpcEntryImpl.class).getNpc().getHologram().getLines().size())
if (context.argSize() == 2) { .map(String::valueOf));
int lines = NpcRegistryImpl.get().get(context.popString()).getNpc().getHologram().getLines().size(); return Collections.emptyList();
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);
} }
} }

@ -3,56 +3,34 @@ package lol.pyr.znpcsplus.commands.hologram;
import lol.pyr.director.adventure.command.CommandContext; import lol.pyr.director.adventure.command.CommandContext;
import lol.pyr.director.adventure.command.CommandHandler; import lol.pyr.director.adventure.command.CommandHandler;
import lol.pyr.director.common.command.CommandExecutionException; 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.NpcEntryImpl;
import lol.pyr.znpcsplus.npc.NpcRegistryImpl; import lol.pyr.znpcsplus.npc.NpcRegistryImpl;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
public class HoloSetCommand implements CommandHandler { public class HoloSetCommand implements CommandHandler {
@Override @Override
public void run(CommandContext commandContext) throws CommandExecutionException { public void run(CommandContext context) throws CommandExecutionException {
if (commandContext.argSize() < 2) { context.setUsage(context.getLabel() + " holo set <npc_id> <line> <text>");
ZNpcsPlus.ADVENTURE.sender(commandContext.getSender()).sendMessage(Component.text("Usage: /npc holo set <npc_id> <line> <text>", NamedTextColor.RED)); HologramImpl hologram = context.parse(NpcEntryImpl.class).getNpc().getHologram();
return; int line = context.parse(Integer.class);
} if (line < 0 || line >= hologram.getLines().size()) context.halt(Component.text("Invalid line number!", NamedTextColor.RED));
String id = commandContext.popString(); hologram.removeLine(line);
NpcEntryImpl npcEntry = NpcRegistryImpl.get().get(id); hologram.insertLine(line, Component.text(context.dumpAllArgs()));
if (npcEntry == null) { context.send(Component.text("NPC line set!", NamedTextColor.GREEN));
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));
} }
@Override @Override
public List<String> suggest(CommandContext context) throws CommandExecutionException { public List<String> suggest(CommandContext context) throws CommandExecutionException {
if (context.argSize() == 1) { if (context.argSize() == 1) return context.suggestCollection(NpcRegistryImpl.get().modifiableIds());
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.iterate(0, n -> n + 1)
} .limit(context.suggestionParse(1, NpcEntryImpl.class).getNpc().getHologram().getLines().size())
if (context.argSize() == 2) { .map(String::valueOf));
int lines = NpcRegistryImpl.get().get(context.popString()).getNpc().getHologram().getLines().size(); return Collections.emptyList();
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);
} }
} }

@ -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;
}
}