commit
30dca8f678
17 changed files with 613 additions and 19 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.2"
|
||||
implementation "lol.pyr:director-adventure:2.0.4"
|
||||
implementation project(":api")
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ 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.znpcsplus.api.ZApiProvider;
|
||||
import lol.pyr.znpcsplus.commands.*;
|
||||
import lol.pyr.znpcsplus.entity.EntityPropertyImpl;
|
||||
import lol.pyr.znpcsplus.npc.NpcTypeImpl;
|
||||
import lol.pyr.znpcsplus.config.Configs;
|
||||
|
@ -57,6 +58,7 @@ public class ZNpcsPlus extends JavaPlugin {
|
|||
public static boolean PLACEHOLDERS_SUPPORTED;
|
||||
|
||||
private boolean enabled = false;
|
||||
public static final String DEBUG_NPC_PREFIX = "debug_npc";
|
||||
|
||||
public static void debug(String str) {
|
||||
if (!Configs.config().debugEnabled()) return;
|
||||
|
@ -144,7 +146,7 @@ public class ZNpcsPlus extends JavaPlugin {
|
|||
World world = Bukkit.getWorld("world");
|
||||
if (world == null) world = Bukkit.getWorlds().get(0);
|
||||
for (NpcTypeImpl type : NpcTypeImpl.values()) {
|
||||
NpcEntryImpl entry = NpcRegistryImpl.get().create("debug_npc" + (z * wrap + x), world, type, new ZLocation(x * 3, 200, z * 3, 0, 0));
|
||||
NpcEntryImpl entry = NpcRegistryImpl.get().create(ZNpcsPlus.DEBUG_NPC_PREFIX + (z * wrap + x), world, type, new ZLocation(x * 3, 200, z * 3, 0, 0));
|
||||
entry.setProcessed(true);
|
||||
NpcImpl npc = entry.getNpc();
|
||||
if (type.getType() == EntityTypes.PLAYER) {
|
||||
|
@ -159,13 +161,13 @@ public class ZNpcsPlus extends JavaPlugin {
|
|||
z++;
|
||||
}
|
||||
}
|
||||
NpcEntryImpl entry = NpcRegistryImpl.get().create("debug_npc" + (z * wrap + x), world, NpcTypeImpl.byName("player"), new ZLocation(x * 3, 200, z * 3, 0, 0));
|
||||
NpcEntryImpl entry = NpcRegistryImpl.get().create(ZNpcsPlus.DEBUG_NPC_PREFIX + (z * wrap + x), world, NpcTypeImpl.byName("player"), new ZLocation(x * 3, 200, z * 3, 0, 0));
|
||||
entry.setProcessed(true);
|
||||
NpcImpl npc = entry.getNpc();
|
||||
npc.setProperty(EntityPropertyImpl.SKIN, new FetchingDescriptor("jeb_"));
|
||||
npc.addAction(new MessageAction(1000L, "<red>Hi, I'm jeb!"));
|
||||
x++;
|
||||
entry = NpcRegistryImpl.get().create("debug_npc" + (z * wrap + x), world, NpcTypeImpl.byName("player"), new ZLocation(x * 3, 200, z * 3, 0, 0));
|
||||
entry = NpcRegistryImpl.get().create(ZNpcsPlus.DEBUG_NPC_PREFIX + (z * wrap + x), world, NpcTypeImpl.byName("player"), new ZLocation(x * 3, 200, z * 3, 0, 0));
|
||||
entry.setProcessed(true);
|
||||
npc = entry.getNpc();
|
||||
npc.setProperty(EntityPropertyImpl.SKIN, new MirrorDescriptor());
|
||||
|
@ -184,6 +186,23 @@ public class ZNpcsPlus extends JavaPlugin {
|
|||
|
||||
private void registerCommands() {
|
||||
CommandManager manager = new CommandManager(this, ADVENTURE, context -> {});
|
||||
manager.registerCommand("npc", new MultiCommand());
|
||||
manager.registerCommand("npc", new MultiCommand()
|
||||
.addSubcommand("action", new ActionCommand())
|
||||
.addSubcommand("conversations", new ConversationsCommand())
|
||||
.addSubcommand("create", new CreateCommand())
|
||||
.addSubcommand("delete", new DeleteCommand())
|
||||
.addSubcommand("holo", new MultiCommand()
|
||||
.addSubcommand("add", new HoloAddCommand())
|
||||
.addSubcommand("delete", new HoloDeleteCommand())
|
||||
.addSubcommand("info", new HoloInfoCommand())
|
||||
.addSubcommand("insert", new HoloInsertCommand())
|
||||
.addSubcommand("set", new HoloSetCommand())
|
||||
)
|
||||
.addSubcommand("list", new ListCommand())
|
||||
.addSubcommand("move", new MoveCommand())
|
||||
.addSubcommand("path", new PathCommand())
|
||||
.addSubcommand("properties", new PropertiesCommand())
|
||||
.addSubcommand("teleport", new TeleportCommand())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
package lol.pyr.znpcsplus.command;
|
||||
|
||||
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.npc.NpcRegistryImpl;
|
||||
|
||||
public class CreateCommand implements CommandHandler {
|
||||
@Override
|
||||
public void run(CommandContext context) throws CommandExecutionException {
|
||||
String id = context.popString();
|
||||
NpcRegistryImpl.get().get(id);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
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 java.util.List;
|
||||
|
||||
public class ActionCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void run(CommandContext commandContext) throws CommandExecutionException {
|
||||
commandContext.getSender().sendMessage("Not implemented yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
return CommandHandler.super.suggest(context);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
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 java.util.List;
|
||||
|
||||
public class ConversationsCommand implements CommandHandler {
|
||||
@Override
|
||||
public void run(CommandContext commandContext) throws CommandExecutionException {
|
||||
commandContext.getSender().sendMessage("Not implemented yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
return CommandHandler.super.suggest(context);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
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.util.ZLocation;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
if (context.argSize() == 1) {
|
||||
return context.suggestLiteral("<npc_id>");
|
||||
}
|
||||
if (context.argSize() == 2) {
|
||||
return context.suggestCollection(NpcTypeImpl.values().stream().map(NpcTypeImpl::getName).collect(Collectors.toList()));
|
||||
}
|
||||
if (context.argSize() == 3) {
|
||||
return context.suggestLiteral("<npc_name>");
|
||||
}
|
||||
return CommandHandler.super.suggest(context);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
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.NpcRegistryImpl;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
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.NpcRegistryImpl;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
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.NpcRegistryImpl;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,53 @@
|
|||
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.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.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);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
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.NpcRegistryImpl;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
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.NpcRegistryImpl;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
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.NpcRegistryImpl;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ListCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void run(CommandContext commandContext) 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());
|
||||
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(" | ", NamedTextColor.GRAY))
|
||||
.append(Component.text("Name: ", NamedTextColor.GREEN))
|
||||
.append(npcEntry.getNpc().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(" | ", 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());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
return CommandHandler.super.suggest(context);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
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.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.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));
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
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 java.util.List;
|
||||
|
||||
public class PathCommand implements CommandHandler {
|
||||
@Override
|
||||
public void run(CommandContext commandContext) throws CommandExecutionException {
|
||||
commandContext.getSender().sendMessage("Not implemented yet.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
return CommandHandler.super.suggest(context);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
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 java.util.List;
|
||||
|
||||
public class PropertiesCommand implements CommandHandler {
|
||||
@Override
|
||||
public void run(CommandContext commandContext) throws CommandExecutionException {
|
||||
commandContext.getSender().sendMessage("Not implemented yet!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggest(CommandContext context) throws CommandExecutionException {
|
||||
return CommandHandler.super.suggest(context);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
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.NpcRegistryImpl;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue