Add /npc speak --range

This commit is contained in:
fullwall 2022-10-15 16:59:09 +08:00
parent 1213c5462c
commit 856b40b890

View File

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