expose more display entity properties to config

This commit is contained in:
2023-07-22 21:35:30 +02:00
parent c675be69e6
commit ca4a3eaf16
4 changed files with 63 additions and 21 deletions
@@ -80,6 +80,9 @@ public class NJNConfig {
DisplayContent displayContent = new DisplayContent(); DisplayContent displayContent = new DisplayContent();
displayContent.setRefreshRate(displayContentSection.getInt("refresh-rate", 0)); displayContent.setRefreshRate(displayContentSection.getInt("refresh-rate", 0));
displayContent.setSeeThrough(displayContentSection.getBoolean("see-through", false));
displayContent.setInterpolationDelay(displayContentSection.getInt("interpolation-delay", displayContent.getRefreshRate()));
displayContent.setInterpolationDuration(displayContentSection.getInt("interpolation-duration", displayContent.getRefreshRate()));
Display.Billboard billboard = Display.Billboard.HORIZONTAL; Display.Billboard billboard = Display.Billboard.HORIZONTAL;
try { try {
@@ -94,7 +97,10 @@ public class NJNConfig {
if (frameSection == null) return; if (frameSection == null) return;
String text = frameSection.getString("text", null); String text = frameSection.getString("text", null);
String backgroundColor = frameSection.getString("background"); String backgroundColor = frameSection.getString("background");
displayContent.addFrame(new DisplayFrame(text, colorFromHex(backgroundColor))); float scaleX = (float) frameSection.getDouble("scale-x", 1);
float scaleY = (float) frameSection.getDouble("scale-y", 1);
float scaleZ = (float) frameSection.getDouble("offset-z", 1);
displayContent.addFrame(new DisplayFrame(text, colorFromHex(backgroundColor), scaleX, scaleY, scaleZ));
}); });
Permission permission = new Permission("notjustnameplates.display." + displayContentSection.getName(), "Allows player to use " + displayContentSection.getName() + " nameplate", PermissionDefault.FALSE); Permission permission = new Permission("notjustnameplates.display." + displayContentSection.getName(), "Allows player to use " + displayContentSection.getName() + " nameplate", PermissionDefault.FALSE);
plugin.getServer().getPluginManager().addPermission(permission); plugin.getServer().getPluginManager().addPermission(permission);
@@ -10,12 +10,12 @@ import java.util.List;
public class DisplayContent { public class DisplayContent {
private final List<DisplayFrame> frames = new ArrayList<>(); private final List<DisplayFrame> frames = new ArrayList<>();
private int refreshRate = 0; private int refreshRate, interpolationDuration, interpolationDelay, currentFrame;
private int currentFrame = 0;
private Display.Billboard billboard = Display.Billboard.HORIZONTAL; private Display.Billboard billboard = Display.Billboard.HORIZONTAL;
private boolean seeThrough = false;
public DisplayContent() {} public DisplayContent() {
}
/** /**
* Set the refresh rate of the display in ticks. 0 means no refresh rate. * Set the refresh rate of the display in ticks. 0 means no refresh rate.
@@ -36,6 +36,30 @@ public class DisplayContent {
return billboard; return billboard;
} }
public void setSeeThrough(boolean seeThrough) {
this.seeThrough = seeThrough;
}
public boolean getSeeThrough() {
return seeThrough;
}
public void setInterpolationDelay(int interpolationDelay) {
this.interpolationDelay = interpolationDelay;
}
public void setInterpolationDuration(int interpolationDuration) {
this.interpolationDuration = interpolationDuration;
}
public int getInterpolationDelay() {
return interpolationDelay;
}
public int getInterpolationDuration() {
return interpolationDuration;
}
public void addFrame(DisplayFrame frame) { public void addFrame(DisplayFrame frame) {
frames.add(frame); frames.add(frame);
} }
@@ -1,13 +1,6 @@
package me.youhavetrouble.notjustnameplates.displays; package me.youhavetrouble.notjustnameplates.displays;
import org.bukkit.Color; import org.bukkit.Color;
import org.jetbrains.annotations.Nullable;
public record DisplayFrame(String text, Color backgroundColor) {
public DisplayFrame(@Nullable String text, @Nullable Color backgroundColor) {
this.text = text;
this.backgroundColor = backgroundColor;
}
public record DisplayFrame(String text, Color backgroundColor, float scaleX, float scaleY, float scaleZ) {
} }
@@ -60,20 +60,26 @@ public class Nameplate {
textDisplay.setPersistent(false); textDisplay.setPersistent(false);
textDisplay.setAlignment(alignment); textDisplay.setAlignment(alignment);
textDisplay.setBillboard(this.content.getBillboard()); textDisplay.setBillboard(this.content.getBillboard());
textDisplay.setSeeThrough(this.content.getSeeThrough());
textDisplay.setShadowRadius(0); textDisplay.setShadowRadius(0);
textDisplay.setInterpolationDuration(content.getInterpolationDuration());
textDisplay.setInterpolationDelay(content.getInterpolationDelay());
Color backgroundColor = this.content.getCurrentFrame().backgroundColor(); Color backgroundColor = this.content.getCurrentFrame().backgroundColor();
if (backgroundColor != null) textDisplay.setBackgroundColor(backgroundColor); if (backgroundColor != null) textDisplay.setBackgroundColor(backgroundColor);
textDisplay.text(parseText(this.content.getCurrentFrame().text(), player)); textDisplay.text(parseText(this.content.getCurrentFrame().text(), player));
textDisplay.setTransformation( textDisplay.setTransformation(new Transformation(
new Transformation( new Vector3f(0, heightOffset, 0), // offset
new Vector3f(0, heightOffset, 0), // offset new AxisAngle4f(0, 0, 0, 0), // left rotation
new AxisAngle4f(0, 0, 0, 0), // left rotation new Vector3f(
new Vector3f(1, 1, 1), // scale content.getCurrentFrame().scaleX(),
new AxisAngle4f(0, 0, 0, 0) // right rotation content.getCurrentFrame().scaleY(),
)); content.getCurrentFrame().scaleZ()
), // scale
new AxisAngle4f(0, 0, 0, 0) // right rotation
));
}); });
if (!this.visibleForOwner) { if (!this.visibleForOwner) {
player.hideEntity(NotJustNameplates.getInstance(), textDisplay); player.hideEntity(NotJustNameplates.getInstance(), textDisplay);
@@ -144,7 +150,17 @@ public class Nameplate {
textDisplay.text(parseText(this.content.getCurrentFrame().text(), player)); textDisplay.text(parseText(this.content.getCurrentFrame().text(), player));
textDisplay.setBillboard(this.content.getBillboard()); textDisplay.setBillboard(this.content.getBillboard());
textDisplay.setInterpolationDuration(content.getRefreshRate());
textDisplay.setTransformation(new Transformation(
new Vector3f(0, heightOffset, 0), // offset
new AxisAngle4f(0, 0, 0, 0), // left rotation
new Vector3f(
content.getCurrentFrame().scaleX(),
content.getCurrentFrame().scaleY(),
content.getCurrentFrame().scaleZ()
), // scale
new AxisAngle4f(0, 0, 0, 0) // right rotation
));
Color backgroundColor = this.content.getCurrentFrame().backgroundColor(); Color backgroundColor = this.content.getCurrentFrame().backgroundColor();
if (backgroundColor == null) { if (backgroundColor == null) {
@@ -153,6 +169,9 @@ public class Nameplate {
textDisplay.setBackgroundColor(backgroundColor); textDisplay.setBackgroundColor(backgroundColor);
} }
textDisplay.setInterpolationDuration(content.getInterpolationDuration());
textDisplay.setInterpolationDelay(content.getInterpolationDelay());
setVisibleForOwner(this.visibleForOwner || player.hasPermission("notjustnameplates.seeown")); setVisibleForOwner(this.visibleForOwner || player.hasPermission("notjustnameplates.seeown"));
} }