mirror of
https://github.com/YouHaveTrouble/NotJustNameplates.git
synced 2026-05-11 22:16:57 +00:00
slowly abstracting away
This commit is contained in:
@@ -5,9 +5,16 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
|
|
||||||
public final class NotJustNameplates extends JavaPlugin {
|
public final class NotJustNameplates extends JavaPlugin {
|
||||||
|
|
||||||
|
private static NotJustNameplates instance;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
instance = this;
|
||||||
getServer().getPluginManager().registerEvents(new TeamManagementListener(this), this);
|
getServer().getPluginManager().registerEvents(new TeamManagementListener(this), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static NotJustNameplates getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
package me.youhavetrouble.notjustnameplates.nameplates;
|
package me.youhavetrouble.notjustnameplates.nameplates;
|
||||||
|
|
||||||
|
import me.youhavetrouble.notjustnameplates.NotJustNameplates;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Color;
|
||||||
import org.bukkit.entity.Display;
|
import org.bukkit.entity.Display;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -10,6 +11,7 @@ import org.bukkit.entity.TextDisplay;
|
|||||||
import org.bukkit.event.entity.CreatureSpawnEvent;
|
import org.bukkit.event.entity.CreatureSpawnEvent;
|
||||||
import org.bukkit.util.Transformation;
|
import org.bukkit.util.Transformation;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.joml.AxisAngle4f;
|
import org.joml.AxisAngle4f;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
@@ -19,11 +21,15 @@ public class Nameplate {
|
|||||||
|
|
||||||
private Component name;
|
private Component name;
|
||||||
private final UUID playerUuid;
|
private final UUID playerUuid;
|
||||||
private float heightOffset = 0.75f;
|
private float heightOffset = 0.7f;
|
||||||
|
private Color backgroundColor = null;
|
||||||
|
private Display.Billboard billboard = Display.Billboard.CENTER;
|
||||||
|
private TextDisplay.TextAlignment alignment = TextDisplay.TextAlignment.CENTER;
|
||||||
|
private boolean visibleForOwner = true;
|
||||||
|
|
||||||
private TextDisplay textDisplay;
|
private TextDisplay textDisplay;
|
||||||
|
|
||||||
public Nameplate(@NotNull UUID playerUuid, @NotNull Component name) {
|
public Nameplate(@NotNull UUID playerUuid, Component name) {
|
||||||
this.playerUuid = playerUuid;
|
this.playerUuid = playerUuid;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
@@ -32,20 +38,17 @@ public class Nameplate {
|
|||||||
if (textDisplay != null && !textDisplay.isDead()) return;
|
if (textDisplay != null && !textDisplay.isDead()) return;
|
||||||
Player player = Bukkit.getPlayer(playerUuid);
|
Player player = Bukkit.getPlayer(playerUuid);
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
this.textDisplay = (TextDisplay) player.getWorld()
|
this.textDisplay = (TextDisplay) player.getWorld().spawnEntity(
|
||||||
.spawnEntity(
|
player.getEyeLocation(),
|
||||||
calculateCurrentLocation(),
|
|
||||||
EntityType.TEXT_DISPLAY,
|
EntityType.TEXT_DISPLAY,
|
||||||
CreatureSpawnEvent.SpawnReason.CUSTOM, entity -> {
|
CreatureSpawnEvent.SpawnReason.CUSTOM, entity -> {
|
||||||
TextDisplay textDisplay = (TextDisplay) entity;
|
TextDisplay textDisplay = (TextDisplay) entity;
|
||||||
textDisplay.setCustomNameVisible(true);
|
|
||||||
textDisplay.setSilent(true);
|
|
||||||
textDisplay.setInvulnerable(true);
|
textDisplay.setInvulnerable(true);
|
||||||
textDisplay.setPersistent(false);
|
textDisplay.setPersistent(false);
|
||||||
textDisplay.text(this.name);
|
textDisplay.setAlignment(alignment);
|
||||||
textDisplay.setAlignment(TextDisplay.TextAlignment.CENTER);
|
textDisplay.setBillboard(billboard);
|
||||||
textDisplay.setBillboard(Display.Billboard.CENTER);
|
textDisplay.setShadowRadius(0);
|
||||||
textDisplay.setInvulnerable(true);
|
if (this.backgroundColor != null) textDisplay.setBackgroundColor(this.backgroundColor);
|
||||||
textDisplay.setTransformation(
|
textDisplay.setTransformation(
|
||||||
new Transformation(
|
new Transformation(
|
||||||
new Vector3f(0, heightOffset, 0), // offset
|
new Vector3f(0, heightOffset, 0), // offset
|
||||||
@@ -54,6 +57,9 @@ public class Nameplate {
|
|||||||
new AxisAngle4f(0, 0, 0, 0) // right rotation
|
new AxisAngle4f(0, 0, 0, 0) // right rotation
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
if (!this.visibleForOwner) {
|
||||||
|
player.hideEntity(NotJustNameplates.getInstance(), textDisplay);
|
||||||
|
}
|
||||||
player.addPassenger(textDisplay);
|
player.addPassenger(textDisplay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,6 +80,56 @@ public class Nameplate {
|
|||||||
textDisplay.text(name);
|
textDisplay.text(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setBillboard(@NotNull Display.Billboard billboard) {
|
||||||
|
this.billboard = billboard;
|
||||||
|
if (textDisplay == null || textDisplay.isDead()) return;
|
||||||
|
textDisplay.setBillboard(billboard);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Display.Billboard getBillboard() {
|
||||||
|
return billboard;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlignment(@NotNull TextDisplay.TextAlignment alignment) {
|
||||||
|
this.alignment = alignment;
|
||||||
|
if (textDisplay == null || textDisplay.isDead()) return;
|
||||||
|
textDisplay.setAlignment(alignment);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TextDisplay.TextAlignment getAlignment() {
|
||||||
|
return alignment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBackgroundColor(@Nullable Color color) {
|
||||||
|
this.backgroundColor = color;
|
||||||
|
if (textDisplay == null || textDisplay.isDead()) return;
|
||||||
|
if (this.backgroundColor == null) {
|
||||||
|
textDisplay.setDefaultBackground(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
textDisplay.setBackgroundColor(this.backgroundColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color getBackgroundColor() {
|
||||||
|
return backgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVisibleForOwner(boolean visible) {
|
||||||
|
this.visibleForOwner = visible;
|
||||||
|
if (textDisplay == null || textDisplay.isDead()) return;
|
||||||
|
Player player = Bukkit.getPlayer(playerUuid);
|
||||||
|
if (player == null) return;
|
||||||
|
if (visible) {
|
||||||
|
player.showEntity(NotJustNameplates.getInstance(), textDisplay);
|
||||||
|
} else {
|
||||||
|
player.hideEntity(NotJustNameplates.getInstance(), textDisplay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isVisibleForOwner() {
|
||||||
|
return this.visibleForOwner;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set height offset from the player's eye location
|
* Set height offset from the player's eye location
|
||||||
*/
|
*/
|
||||||
@@ -81,10 +137,8 @@ public class Nameplate {
|
|||||||
this.heightOffset = heightOffset;
|
this.heightOffset = heightOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location calculateCurrentLocation() {
|
public float getHeightOffset() {
|
||||||
Player player = Bukkit.getPlayer(playerUuid);
|
return heightOffset;
|
||||||
if (player == null) return null;
|
|
||||||
return player.getEyeLocation().add(0, heightOffset, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,8 +146,7 @@ public class Nameplate {
|
|||||||
*/
|
*/
|
||||||
public void update() {
|
public void update() {
|
||||||
Player player = Bukkit.getPlayer(playerUuid);
|
Player player = Bukkit.getPlayer(playerUuid);
|
||||||
if (player == null) return;
|
if (player == null || player.isDead() || name == null) {
|
||||||
if (player.isDead()) {
|
|
||||||
remove();
|
remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -101,6 +154,7 @@ public class Nameplate {
|
|||||||
if (!player.getPassengers().contains(textDisplay)) {
|
if (!player.getPassengers().contains(textDisplay)) {
|
||||||
player.addPassenger(textDisplay);
|
player.addPassenger(textDisplay);
|
||||||
}
|
}
|
||||||
|
textDisplay.text(this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void remove() {
|
protected void remove() {
|
||||||
|
|||||||
-1
@@ -4,7 +4,6 @@ import me.youhavetrouble.notjustnameplates.NotJustNameplates;
|
|||||||
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
|
import net.minecraft.network.protocol.game.ClientboundSetPlayerTeamPacket;
|
||||||
import net.minecraft.world.scores.PlayerTeam;
|
import net.minecraft.world.scores.PlayerTeam;
|
||||||
import net.minecraft.world.scores.Scoreboard;
|
import net.minecraft.world.scores.Scoreboard;
|
||||||
import net.minecraft.world.scores.Team;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
|
import org.bukkit.craftbukkit.v1_20_R1.entity.CraftPlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
nameplates:
|
||||||
|
default:
|
||||||
|
text:
|
||||||
|
- "%player_displayname%"
|
||||||
|
|
||||||
|
# Billboard options are as follows:
|
||||||
|
# "center" - pivots around center point
|
||||||
|
# "vertical" - pivots around vertical axis
|
||||||
|
# "horizontal" - pivots around horizontal axis
|
||||||
|
# "fixed" - no rotation
|
||||||
|
billboard: "center"
|
||||||
|
|
||||||
Reference in New Issue
Block a user