Enable text display by default
This commit is contained in:
parent
eac2d33c21
commit
bdc2264fc6
|
@ -9,8 +9,10 @@ import java.util.stream.Collectors;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.entity.Display.Billboard;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
|
import org.bukkit.entity.TextDisplay;
|
||||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
@ -46,7 +48,7 @@ public class HologramTrait extends Trait {
|
||||||
private NPC nameNPC;
|
private NPC nameNPC;
|
||||||
private final NPCRegistry registry = CitizensAPI.createCitizensBackedNPCRegistry(new MemoryNPCDataStore());
|
private final NPCRegistry registry = CitizensAPI.createCitizensBackedNPCRegistry(new MemoryNPCDataStore());
|
||||||
private int t;
|
private int t;
|
||||||
private boolean useTextDisplay = false;
|
private boolean useTextDisplay = SUPPORTS_TEXT_DISPLAY;
|
||||||
|
|
||||||
public HologramTrait() {
|
public HologramTrait() {
|
||||||
super("hologramtrait");
|
super("hologramtrait");
|
||||||
|
@ -91,6 +93,7 @@ public class HologramTrait extends Trait {
|
||||||
NPC hologramNPC = null;
|
NPC hologramNPC = null;
|
||||||
if (useTextDisplay) {
|
if (useTextDisplay) {
|
||||||
hologramNPC = registry.createNPC(EntityType.TEXT_DISPLAY, line);
|
hologramNPC = registry.createNPC(EntityType.TEXT_DISPLAY, line);
|
||||||
|
hologramNPC.addTrait(new ClickRedirectTrait(npc));
|
||||||
} else {
|
} else {
|
||||||
hologramNPC = registry.createNPC(EntityType.ARMOR_STAND, line);
|
hologramNPC = registry.createNPC(EntityType.ARMOR_STAND, line);
|
||||||
hologramNPC.getOrAddTrait(ArmorStandTrait.class).setAsHelperEntityWithName(npc);
|
hologramNPC.getOrAddTrait(ArmorStandTrait.class).setAsHelperEntityWithName(npc);
|
||||||
|
@ -104,6 +107,10 @@ public class HologramTrait extends Trait {
|
||||||
+ (direction == HologramDirection.BOTTOM_UP ? heightOffset : getMaxHeight() - heightOffset),
|
+ (direction == HologramDirection.BOTTOM_UP ? heightOffset : getMaxHeight() - heightOffset),
|
||||||
0));
|
0));
|
||||||
|
|
||||||
|
if (useTextDisplay) {
|
||||||
|
((TextDisplay) hologramNPC.getEntity()).setBillboard(Billboard.CENTER);
|
||||||
|
}
|
||||||
|
|
||||||
Matcher itemMatcher = ITEM_MATCHER.matcher(line);
|
Matcher itemMatcher = ITEM_MATCHER.matcher(line);
|
||||||
if (itemMatcher.matches()) {
|
if (itemMatcher.matches()) {
|
||||||
Material item = SpigotUtil.isUsing1_13API() ? Material.matchMaterial(itemMatcher.group(1), false)
|
Material item = SpigotUtil.isUsing1_13API() ? Material.matchMaterial(itemMatcher.group(1), false)
|
||||||
|
@ -141,7 +148,7 @@ public class HologramTrait extends Trait {
|
||||||
private double getHeight(int lineNumber) {
|
private double getHeight(int lineNumber) {
|
||||||
double base = (lastNameplateVisible ? 0 : -getLineHeight());
|
double base = (lastNameplateVisible ? 0 : -getLineHeight());
|
||||||
if (useTextDisplay) {
|
if (useTextDisplay) {
|
||||||
base += 0.15;
|
base += 0.27;
|
||||||
}
|
}
|
||||||
for (int i = 0; i <= lineNumber; i++) {
|
for (int i = 0; i <= lineNumber; i++) {
|
||||||
HologramLine line = lines.get(i);
|
HologramLine line = lines.get(i);
|
||||||
|
@ -186,11 +193,6 @@ public class HologramTrait extends Trait {
|
||||||
return nameNPC != null && nameNPC.isSpawned() ? nameNPC.getEntity() : null;
|
return nameNPC != null && nameNPC.isSpawned() ? nameNPC.getEntity() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getRotationDistance(Location loc) {
|
|
||||||
return Math.abs(loc.getYaw() - npc.getStoredLocation().getYaw())
|
|
||||||
+ Math.abs(loc.getPitch() - npc.getStoredLocation().getPitch());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(DataKey root) {
|
public void load(DataKey root) {
|
||||||
clear();
|
clear();
|
||||||
|
@ -284,8 +286,7 @@ public class HologramTrait extends Trait {
|
||||||
|
|
||||||
boolean updatePosition = currentLoc.getWorld() != npc.getStoredLocation().getWorld()
|
boolean updatePosition = currentLoc.getWorld() != npc.getStoredLocation().getWorld()
|
||||||
|| currentLoc.distance(npc.getStoredLocation()) >= 0.001 || lastNameplateVisible != nameplateVisible
|
|| currentLoc.distance(npc.getStoredLocation()) >= 0.001 || lastNameplateVisible != nameplateVisible
|
||||||
|| Math.abs(lastEntityHeight - getEntityHeight()) >= 0.05
|
|| Math.abs(lastEntityHeight - getEntityHeight()) >= 0.05;
|
||||||
|| (useTextDisplay && getRotationDistance(currentLoc) >= 0.001);
|
|
||||||
boolean updateName = false;
|
boolean updateName = false;
|
||||||
if (t++ >= Setting.HOLOGRAM_UPDATE_RATE.asTicks() + Util.getFastRandom().nextInt(3) /* add some jitter */) {
|
if (t++ >= Setting.HOLOGRAM_UPDATE_RATE.asTicks() + Util.getFastRandom().nextInt(3) /* add some jitter */) {
|
||||||
t = 0;
|
t = 0;
|
||||||
|
@ -396,8 +397,9 @@ public class HologramTrait extends Trait {
|
||||||
reloadLineHolograms();
|
reloadLineHolograms();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUseTextDisplay(boolean useTextDisplay) {
|
public void setUseTextDisplay(boolean use) {
|
||||||
this.useTextDisplay = useTextDisplay;
|
this.useTextDisplay = use;
|
||||||
|
reloadLineHolograms();
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum HologramDirection {
|
public enum HologramDirection {
|
||||||
|
@ -448,4 +450,12 @@ public class HologramTrait extends Trait {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final Pattern ITEM_MATCHER = Pattern.compile("<item:(.*?)([:].*?)?>");
|
private static final Pattern ITEM_MATCHER = Pattern.compile("<item:(.*?)([:].*?)?>");
|
||||||
|
private static boolean SUPPORTS_TEXT_DISPLAY = false;
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
EntityType.valueOf("TEXT_DISPLAY");
|
||||||
|
SUPPORTS_TEXT_DISPLAY = true;
|
||||||
|
} catch (IllegalArgumentException iae) {
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue