From 856b40b890fa33c4f0b0a8f70dd3a93b2f1760cb Mon Sep 17 00:00:00 2001 From: fullwall Date: Sat, 15 Oct 2022 16:59:09 +0800 Subject: [PATCH] Add /npc speak --range --- .../java/net/citizensnpcs/commands/NPCCommands.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java index 58c848c7b..7f06014f3 100644 --- a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -2513,13 +2513,13 @@ public class NPCCommands { @Command( aliases = { "npc" }, - usage = "speak [message] --target [npcid|player name] (--type vocal_type)", + usage = "speak [message] --target [npcid|player name] --range (range to look for entities to speak to in blocks) (--type vocal_type)", desc = "Says a message from the NPC", modifiers = { "speak" }, min = 2, permission = "citizens.npc.speak") public void speak(CommandContext args, CommandSender sender, NPC npc, @Flag("type") String type, - @Flag("target") String target) throws CommandException { + @Flag("target") String target, @Flag("range") Float range) throws CommandException { String message = Colorizer.parseColors(args.getJoinedStrings(1)); if (message.length() <= 0) { @@ -2543,6 +2543,14 @@ public class NPCCommands { } } + if (range != null) { + npc.getEntity().getNearbyEntities(range / 2, range, range / 2).forEach((e) -> { + if (!CitizensAPI.getNPCRegistry().isNPC(e)) { + context.addRecipient(e); + } + }); + } + if (type == null || !CitizensAPI.getSpeechFactory().isRegistered(type)) { type = npc.getOrAddTrait(Speech.class).getDefaultVocalChord(); }