From 19b917e905e562250d1c23cf46e5260a83703502 Mon Sep 17 00:00:00 2001 From: fullwall Date: Tue, 25 Apr 2023 23:56:50 +0800 Subject: [PATCH] Add unstable API for hologramtrait --- .../net/citizensnpcs/commands/NPCCommands.java | 8 +++++--- .../java/net/citizensnpcs/trait/HologramTrait.java | 14 +++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java index b6882f7ae..a28d82466 100644 --- a/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/main/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -692,6 +692,7 @@ public class NPCCommands { if (args.hasFlag('t') || temporaryTicks != null) { registry = temporaryRegistry; } + if (item != null) { ItemStack stack = new ItemStack(Material.STONE, 1); try { @@ -1182,7 +1183,7 @@ public class NPCCommands { } if (delay != null) { trait.setDelayTicks(Util.toTicks(delay)); - output += " " + Messaging.tr(Messages.HOME_TRAIT_DELAY_SET, delay); + output += " " + Messaging.tr(Messages.HOME_TRAIT_DELAY_SET, Util.toTicks(delay)); } if (!output.isEmpty()) { Messaging.send(sender, output.trim()); @@ -1485,7 +1486,7 @@ public class NPCCommands { } if (randomLookDelay != null) { trait.setRandomLookDelay(Math.max(1, Util.toTicks(randomLookDelay))); - Messaging.sendTr(sender, Messages.LOOKCLOSE_RANDOM_DELAY_SET, npc.getName(), randomLookDelay); + Messaging.sendTr(sender, Messages.LOOKCLOSE_RANDOM_DELAY_SET, npc.getName(), Util.toTicks(randomLookDelay)); toggle = false; } if (randomPitch != null) { @@ -2178,6 +2179,7 @@ public class NPCCommands { if (pitch != null) { loc.setPitch(pitch); } + if (trait.addPose(save, loc, args.hasFlag('d'))) { Messaging.sendTr(sender, Messages.POSE_ADDED); } else { @@ -2408,7 +2410,7 @@ public class NPCCommands { public void respawn(CommandContext args, CommandSender sender, NPC npc, @Arg(1) Duration delay) { if (delay != null) { npc.data().setPersistent(NPC.Metadata.RESPAWN_DELAY, Util.toTicks(delay)); - Messaging.sendTr(sender, Messages.RESPAWN_DELAY_SET, delay); + Messaging.sendTr(sender, Messages.RESPAWN_DELAY_SET, Util.toTicks(delay)); } else { Messaging.sendTr(sender, Messages.RESPAWN_DELAY_DESCRIBE, npc.data().get(NPC.Metadata.RESPAWN_DELAY, -1)); } diff --git a/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java b/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java index 8fb8156f1..6d9201197 100644 --- a/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java +++ b/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java @@ -2,6 +2,7 @@ package net.citizensnpcs.trait; import java.util.Collection; import java.util.List; +import java.util.function.BiFunction; import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -40,6 +41,7 @@ import net.citizensnpcs.util.Util; @TraitName("hologramtrait") public class HologramTrait extends Trait { private Location currentLoc; + private BiFunction customHologramSupplier; @Persist private HologramDirection direction = HologramDirection.BOTTOM_UP; private double lastEntityHeight = 0; @@ -398,6 +400,13 @@ public class HologramTrait extends Trait { reloadLineHolograms(); } + /** + * Implementation-specific method: {@see NPC.Metadata#HOLOGRAM_LINE_SUPPLIER} + */ + public void setPerPlayerTextSupplier(BiFunction nameSupplier) { + this.customHologramSupplier = nameSupplier; + } + public void setUseTextDisplay(boolean use) { this.useTextDisplay = use; reloadLineHolograms(); @@ -460,7 +469,10 @@ public class HologramTrait extends Trait { public void spawnNPC(double height) { String name = Placeholders.replace(text, null, npc); this.hologram = createHologram(name, height); - if (Placeholders.containsPlayerPlaceholder(text)) { + if (customHologramSupplier != null) { + hologram.data().set(NPC.Metadata.HOLOGRAM_LINE_SUPPLIER, + (Function) p -> customHologramSupplier.apply(text, p)); + } else if (Placeholders.containsPlayerPlaceholder(text)) { hologram.data().set(NPC.Metadata.HOLOGRAM_LINE_SUPPLIER, this); } }