mirror of
https://github.com/YouHaveTrouble/NotJustNameplates.git
synced 2026-05-11 22:16:57 +00:00
enable the ability to override any frame value if player is sneaking
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "me.youhavetrouble"
|
group = "me.youhavetrouble"
|
||||||
version = "1.15.0"
|
version = "1.16.0"
|
||||||
description = "Nameplates using display entities"
|
description = "Nameplates using display entities"
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
|||||||
@@ -98,6 +98,15 @@ public class NJNConfig {
|
|||||||
framesSection.getKeys(false).forEach(frameName -> {
|
framesSection.getKeys(false).forEach(frameName -> {
|
||||||
ConfigurationSection frameSection = framesSection.getConfigurationSection(frameName);
|
ConfigurationSection frameSection = framesSection.getConfigurationSection(frameName);
|
||||||
if (frameSection == null) return;
|
if (frameSection == null) return;
|
||||||
|
ConfigurationSection sneakOverrideSection = frameSection.getConfigurationSection("sneak-override");
|
||||||
|
displayContent.addFrame(parseFrame(frameSection, sneakOverrideSection));
|
||||||
|
});
|
||||||
|
Permission permission = new Permission("notjustnameplates.display." + displayContentSection.getName(), "Allows player to use " + displayContentSection.getName() + " nameplate", PermissionDefault.FALSE);
|
||||||
|
plugin.getServer().getPluginManager().addPermission(permission);
|
||||||
|
return displayContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DisplayFrame parseFrame(ConfigurationSection frameSection, ConfigurationSection sneakOverrideSection) {
|
||||||
String text = frameSection.getString("text", null);
|
String text = frameSection.getString("text", null);
|
||||||
String backgroundColor = frameSection.getString("background");
|
String backgroundColor = frameSection.getString("background");
|
||||||
float scaleX = (float) frameSection.getDouble("scale-x", 1);
|
float scaleX = (float) frameSection.getDouble("scale-x", 1);
|
||||||
@@ -107,19 +116,52 @@ public class NJNConfig {
|
|||||||
float offsetY = (float) frameSection.getDouble("offset-y", 0);
|
float offsetY = (float) frameSection.getDouble("offset-y", 0);
|
||||||
float offsetZ = (float) frameSection.getDouble("offset-z", 0);
|
float offsetZ = (float) frameSection.getDouble("offset-z", 0);
|
||||||
boolean shadowed = frameSection.getBoolean("shadowed", false);
|
boolean shadowed = frameSection.getBoolean("shadowed", false);
|
||||||
byte textOpacity = (byte) Math.min(Math.max(frameSection.getInt("text-opacity", 255), 0), 255);
|
byte textOpacity = (byte) Math.clamp(frameSection.getInt("text-opacity", 255), 0, 255);
|
||||||
displayContent.addFrame(new DisplayFrame(
|
|
||||||
|
DisplayFrame sneakOverride = null;
|
||||||
|
if (sneakOverrideSection != null) {
|
||||||
|
if (!sneakOverrideSection.isSet("text")) {
|
||||||
|
sneakOverrideSection.set("text", text);
|
||||||
|
}
|
||||||
|
if (!sneakOverrideSection.isSet("background")) {
|
||||||
|
sneakOverrideSection.set("background", backgroundColor);
|
||||||
|
}
|
||||||
|
if (!sneakOverrideSection.isSet("scale-x")) {
|
||||||
|
sneakOverrideSection.set("scale-x", scaleX);
|
||||||
|
}
|
||||||
|
if (!sneakOverrideSection.isSet("scale-y")) {
|
||||||
|
sneakOverrideSection.set("scale-y", scaleY);
|
||||||
|
}
|
||||||
|
if (!sneakOverrideSection.isSet("scale-z")) {
|
||||||
|
sneakOverrideSection.set("scale-z", scaleZ);
|
||||||
|
}
|
||||||
|
if (!sneakOverrideSection.isSet("offset-x")) {
|
||||||
|
sneakOverrideSection.set("offset-x", offsetX);
|
||||||
|
}
|
||||||
|
if (!sneakOverrideSection.isSet("offset-y")) {
|
||||||
|
sneakOverrideSection.set("offset-y", offsetY);
|
||||||
|
}
|
||||||
|
if (!sneakOverrideSection.isSet("offset-z")) {
|
||||||
|
sneakOverrideSection.set("offset-z", offsetZ);
|
||||||
|
}
|
||||||
|
if (!sneakOverrideSection.isSet("shadowed")) {
|
||||||
|
sneakOverrideSection.set("shadowed", shadowed);
|
||||||
|
}
|
||||||
|
if (!sneakOverrideSection.isSet("text-opacity")) {
|
||||||
|
sneakOverrideSection.set("text-opacity", frameSection.getInt("text-opacity", 255));
|
||||||
|
}
|
||||||
|
sneakOverride = parseFrame(sneakOverrideSection, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new DisplayFrame(
|
||||||
text,
|
text,
|
||||||
colorFromHex(backgroundColor),
|
colorFromHex(backgroundColor),
|
||||||
new Vector3f(scaleX, scaleY, scaleZ),
|
new Vector3f(scaleX, scaleY, scaleZ),
|
||||||
new Vector3f(offsetX, offsetY, offsetZ),
|
new Vector3f(offsetX, offsetY, offsetZ),
|
||||||
shadowed,
|
shadowed,
|
||||||
textOpacity
|
textOpacity,
|
||||||
));
|
sneakOverride
|
||||||
});
|
);
|
||||||
Permission permission = new Permission("notjustnameplates.display." + displayContentSection.getName(), "Allows player to use " + displayContentSection.getName() + " nameplate", PermissionDefault.FALSE);
|
|
||||||
plugin.getServer().getPluginManager().addPermission(permission);
|
|
||||||
return displayContent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Color colorFromHex(@Nullable String hex) {
|
private Color colorFromHex(@Nullable String hex) {
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package me.youhavetrouble.notjustnameplates.displays;
|
package me.youhavetrouble.notjustnameplates.displays;
|
||||||
|
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.joml.Vector3f;
|
import org.joml.Vector3f;
|
||||||
|
|
||||||
public record DisplayFrame(
|
public record DisplayFrame(
|
||||||
@@ -9,6 +10,7 @@ public record DisplayFrame(
|
|||||||
Vector3f scale,
|
Vector3f scale,
|
||||||
Vector3f offset,
|
Vector3f offset,
|
||||||
boolean shadowed,
|
boolean shadowed,
|
||||||
byte textOpacity
|
byte textOpacity,
|
||||||
|
@Nullable DisplayFrame sneakOverride
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package me.youhavetrouble.notjustnameplates.nameplates;
|
|||||||
import de.myzelyam.api.vanish.VanishAPI;
|
import de.myzelyam.api.vanish.VanishAPI;
|
||||||
import me.youhavetrouble.notjustnameplates.NotJustNameplates;
|
import me.youhavetrouble.notjustnameplates.NotJustNameplates;
|
||||||
import me.youhavetrouble.notjustnameplates.displays.DisplayContent;
|
import me.youhavetrouble.notjustnameplates.displays.DisplayContent;
|
||||||
|
import me.youhavetrouble.notjustnameplates.displays.DisplayFrame;
|
||||||
import me.youhavetrouble.notjustnameplates.text.TextParser;
|
import me.youhavetrouble.notjustnameplates.text.TextParser;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -46,10 +47,14 @@ public class Nameplate {
|
|||||||
private void createDisplayEntity() {
|
private void createDisplayEntity() {
|
||||||
if (textDisplay != null && !textDisplay.isDead()) return;
|
if (textDisplay != null && !textDisplay.isDead()) return;
|
||||||
if (this.content == null) return;
|
if (this.content == null) return;
|
||||||
if (content.getCurrentFrame().text() == null) return;
|
|
||||||
Player player = Bukkit.getPlayer(playerUuid);
|
Player player = Bukkit.getPlayer(playerUuid);
|
||||||
if (player == null) return;
|
if (player == null) return;
|
||||||
|
|
||||||
|
DisplayFrame currentFrame = player.isSneaking() && content.getCurrentFrame().sneakOverride() != null ? content.getCurrentFrame().sneakOverride() : content.getCurrentFrame();
|
||||||
|
|
||||||
|
if (currentFrame.text() == null) return;
|
||||||
|
|
||||||
this.textDisplay = (TextDisplay) player.getWorld().spawnEntity(
|
this.textDisplay = (TextDisplay) player.getWorld().spawnEntity(
|
||||||
player.getEyeLocation(),
|
player.getEyeLocation(),
|
||||||
EntityType.TEXT_DISPLAY,
|
EntityType.TEXT_DISPLAY,
|
||||||
@@ -65,18 +70,18 @@ public class Nameplate {
|
|||||||
textDisplay.setShadowRadius(0);
|
textDisplay.setShadowRadius(0);
|
||||||
textDisplay.setInterpolationDuration(content.getInterpolationDuration());
|
textDisplay.setInterpolationDuration(content.getInterpolationDuration());
|
||||||
textDisplay.setInterpolationDelay(content.getInterpolationDelay());
|
textDisplay.setInterpolationDelay(content.getInterpolationDelay());
|
||||||
textDisplay.setShadowed(content.getCurrentFrame().shadowed());
|
textDisplay.setShadowed(currentFrame.shadowed());
|
||||||
textDisplay.setTextOpacity(content.getCurrentFrame().textOpacity());
|
textDisplay.setTextOpacity(currentFrame.textOpacity());
|
||||||
|
|
||||||
Color backgroundColor = this.content.getCurrentFrame().backgroundColor();
|
Color backgroundColor = currentFrame.backgroundColor();
|
||||||
if (backgroundColor != null) textDisplay.setBackgroundColor(backgroundColor);
|
if (backgroundColor != null) textDisplay.setBackgroundColor(backgroundColor);
|
||||||
|
|
||||||
textDisplay.text(parseText(this.content.getCurrentFrame().text(), player));
|
textDisplay.text(parseText(currentFrame.text(), player));
|
||||||
|
|
||||||
textDisplay.setTransformation(new Transformation(
|
textDisplay.setTransformation(new Transformation(
|
||||||
content.getCurrentFrame().offset(),
|
currentFrame.offset(),
|
||||||
new AxisAngle4f(0, 0, 0, 0), // left rotation
|
new AxisAngle4f(0, 0, 0, 0), // left rotation
|
||||||
content.getCurrentFrame().scale(),
|
currentFrame.scale(),
|
||||||
new AxisAngle4f(0, 0, 0, 0) // right rotation
|
new AxisAngle4f(0, 0, 0, 0) // right rotation
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -100,6 +105,10 @@ public class Nameplate {
|
|||||||
Bukkit.getScheduler().runTask(NotJustNameplates.getInstance(), this::remove);
|
Bukkit.getScheduler().runTask(NotJustNameplates.getInstance(), this::remove);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DisplayContent getContent() {
|
||||||
|
return this.content;
|
||||||
|
}
|
||||||
|
|
||||||
public void setAlignment(@NotNull TextDisplay.TextAlignment alignment) {
|
public void setAlignment(@NotNull TextDisplay.TextAlignment alignment) {
|
||||||
this.alignment = alignment;
|
this.alignment = alignment;
|
||||||
if (textDisplay == null || textDisplay.isDead()) return;
|
if (textDisplay == null || textDisplay.isDead()) return;
|
||||||
@@ -139,10 +148,6 @@ public class Nameplate {
|
|||||||
remove();
|
remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (content.getCurrentFrame().text() == null) {
|
|
||||||
remove();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (player.getGameMode() == GameMode.SPECTATOR) {
|
if (player.getGameMode() == GameMode.SPECTATOR) {
|
||||||
remove();
|
remove();
|
||||||
return;
|
return;
|
||||||
@@ -151,12 +156,10 @@ public class Nameplate {
|
|||||||
remove();
|
remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NotJustNameplates.isSuperVanishHooked() && VanishAPI.isInvisible(player)) {
|
if (NotJustNameplates.isSuperVanishHooked() && VanishAPI.isInvisible(player)) {
|
||||||
remove();
|
remove();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NotJustNameplates.isVanishNoPacketHooked()) {
|
if (NotJustNameplates.isVanishNoPacketHooked()) {
|
||||||
VanishPlugin vanishPlugin = (VanishPlugin) Bukkit.getPluginManager().getPlugin("VanishNoPacket");
|
VanishPlugin vanishPlugin = (VanishPlugin) Bukkit.getPluginManager().getPlugin("VanishNoPacket");
|
||||||
if (vanishPlugin != null && vanishPlugin.getManager().isVanished(player)) {
|
if (vanishPlugin != null && vanishPlugin.getManager().isVanished(player)) {
|
||||||
@@ -164,6 +167,15 @@ public class Nameplate {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (content == null) {
|
||||||
|
remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
DisplayFrame currentFrame = player.isSneaking() && content.getCurrentFrame().sneakOverride() != null ? content.getCurrentFrame().sneakOverride() : content.getCurrentFrame();
|
||||||
|
if (currentFrame.text() == null) {
|
||||||
|
remove();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
createDisplayEntity();
|
createDisplayEntity();
|
||||||
if (textDisplay == null || textDisplay.isDead()) return;
|
if (textDisplay == null || textDisplay.isDead()) return;
|
||||||
@@ -180,19 +192,19 @@ public class Nameplate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
textDisplay.text(parseText(this.content.getCurrentFrame().text(), player));
|
textDisplay.text(parseText(currentFrame.text(), player));
|
||||||
|
|
||||||
textDisplay.setBillboard(this.content.getBillboard());
|
textDisplay.setBillboard(this.content.getBillboard());
|
||||||
textDisplay.setShadowed(content.getCurrentFrame().shadowed());
|
textDisplay.setShadowed(currentFrame.shadowed());
|
||||||
textDisplay.setTextOpacity(content.getCurrentFrame().textOpacity());
|
textDisplay.setTextOpacity(currentFrame.textOpacity());
|
||||||
textDisplay.setTransformation(new Transformation(
|
textDisplay.setTransformation(new Transformation(
|
||||||
content.getCurrentFrame().offset(),
|
currentFrame.offset(),
|
||||||
new AxisAngle4f(0, 0, 0, 0), // left rotation
|
new AxisAngle4f(0, 0, 0, 0), // left rotation
|
||||||
content.getCurrentFrame().scale(),
|
currentFrame.scale(),
|
||||||
new AxisAngle4f(0, 0, 0, 0) // right rotation
|
new AxisAngle4f(0, 0, 0, 0) // right rotation
|
||||||
));
|
));
|
||||||
|
|
||||||
Color backgroundColor = this.content.getCurrentFrame().backgroundColor();
|
Color backgroundColor = currentFrame.backgroundColor();
|
||||||
if (backgroundColor == null) {
|
if (backgroundColor == null) {
|
||||||
textDisplay.setDefaultBackground(true);
|
textDisplay.setDefaultBackground(true);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -51,6 +51,15 @@ public class NameplateManager implements Listener {
|
|||||||
nameplate.remove();
|
nameplate.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
|
public void onPlayerSneak(PlayerToggleSneakEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
Nameplate nameplate = nameplates.get(player.getUniqueId());
|
||||||
|
if (nameplate == null) return;
|
||||||
|
if (nameplate.getContent().getCurrentFrame().sneakOverride() == null) return;
|
||||||
|
nameplate.update();
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerMove(PlayerMoveEvent event) {
|
public void onPlayerMove(PlayerMoveEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
|
|||||||
Reference in New Issue
Block a user