mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-09-30 16:17:58 +02: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) {
|
if (args.hasFlag('t') || temporaryTicks != null) {
|
||||||
registry = temporaryRegistry;
|
registry = temporaryRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
ItemStack stack = new ItemStack(Material.STONE, 1);
|
ItemStack stack = new ItemStack(Material.STONE, 1);
|
||||||
try {
|
try {
|
||||||
@ -1182,7 +1183,7 @@ public class NPCCommands {
|
|||||||
}
|
}
|
||||||
if (delay != null) {
|
if (delay != null) {
|
||||||
trait.setDelayTicks(Util.toTicks(delay));
|
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()) {
|
if (!output.isEmpty()) {
|
||||||
Messaging.send(sender, output.trim());
|
Messaging.send(sender, output.trim());
|
||||||
@ -1485,7 +1486,7 @@ public class NPCCommands {
|
|||||||
}
|
}
|
||||||
if (randomLookDelay != null) {
|
if (randomLookDelay != null) {
|
||||||
trait.setRandomLookDelay(Math.max(1, Util.toTicks(randomLookDelay)));
|
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;
|
toggle = false;
|
||||||
}
|
}
|
||||||
if (randomPitch != null) {
|
if (randomPitch != null) {
|
||||||
@ -2178,6 +2179,7 @@ public class NPCCommands {
|
|||||||
if (pitch != null) {
|
if (pitch != null) {
|
||||||
loc.setPitch(pitch);
|
loc.setPitch(pitch);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trait.addPose(save, loc, args.hasFlag('d'))) {
|
if (trait.addPose(save, loc, args.hasFlag('d'))) {
|
||||||
Messaging.sendTr(sender, Messages.POSE_ADDED);
|
Messaging.sendTr(sender, Messages.POSE_ADDED);
|
||||||
} else {
|
} else {
|
||||||
@ -2408,7 +2410,7 @@ public class NPCCommands {
|
|||||||
public void respawn(CommandContext args, CommandSender sender, NPC npc, @Arg(1) Duration delay) {
|
public void respawn(CommandContext args, CommandSender sender, NPC npc, @Arg(1) Duration delay) {
|
||||||
if (delay != null) {
|
if (delay != null) {
|
||||||
npc.data().setPersistent(NPC.Metadata.RESPAWN_DELAY, Util.toTicks(delay));
|
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 {
|
} else {
|
||||||
Messaging.sendTr(sender, Messages.RESPAWN_DELAY_DESCRIBE, npc.data().get(NPC.Metadata.RESPAWN_DELAY, -1));
|
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.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -40,6 +41,7 @@ import net.citizensnpcs.util.Util;
|
|||||||
@TraitName("hologramtrait")
|
@TraitName("hologramtrait")
|
||||||
public class HologramTrait extends Trait {
|
public class HologramTrait extends Trait {
|
||||||
private Location currentLoc;
|
private Location currentLoc;
|
||||||
|
private BiFunction<String, Player, String> customHologramSupplier;
|
||||||
@Persist
|
@Persist
|
||||||
private HologramDirection direction = HologramDirection.BOTTOM_UP;
|
private HologramDirection direction = HologramDirection.BOTTOM_UP;
|
||||||
private double lastEntityHeight = 0;
|
private double lastEntityHeight = 0;
|
||||||
@ -398,6 +400,13 @@ public class HologramTrait extends Trait {
|
|||||||
reloadLineHolograms();
|
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) {
|
public void setUseTextDisplay(boolean use) {
|
||||||
this.useTextDisplay = use;
|
this.useTextDisplay = use;
|
||||||
reloadLineHolograms();
|
reloadLineHolograms();
|
||||||
@ -460,7 +469,10 @@ public class HologramTrait extends Trait {
|
|||||||
public void spawnNPC(double height) {
|
public void spawnNPC(double height) {
|
||||||
String name = Placeholders.replace(text, null, npc);
|
String name = Placeholders.replace(text, null, npc);
|
||||||
this.hologram = createHologram(name, height);
|
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);
|
hologram.data().set(NPC.Metadata.HOLOGRAM_LINE_SUPPLIER, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user