mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-23 02:55:45 +01:00
Add unstable API for hologramtrait
This commit is contained in:
parent
7a345b2962
commit
19b917e905
@ -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));
|
||||
}
|
||||
|
@ -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<String, Player, String> 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<String, Player, String> 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<Player, String>) p -> customHologramSupplier.apply(text, p));
|
||||
} else if (Placeholders.containsPlayerPlaceholder(text)) {
|
||||
hologram.data().set(NPC.Metadata.HOLOGRAM_LINE_SUPPLIER, this);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user