24package com.dreamfirestudios.dreamcore.DreamTextDisplay;
26import com.dreamfirestudios.dreamcore.DreamChat.DreamMessageFormatter;
27import com.dreamfirestudios.dreamcore.DreamChat.DreamMessageSettings;
29import org.bukkit.entity.Display;
30import org.bukkit.entity.TextDisplay;
31import org.jetbrains.annotations.NotNull;
32import org.jetbrains.annotations.Nullable;
33import org.joml.Vector3f;
58 private World world = firstLoadedWorld();
59 private Location location = world.getSpawnLocation();
62 private double scale = 1.0D;
63 private Vector3f leftRotation =
new Vector3f(0f, 0f, 0f);
64 private float viewRange = 0.1f;
65 private float shadowRadius = 0.3f;
66 private float shadowStrength = 5f;
67 private float displayWidth = 50f;
68 private float displayHeight = 50f;
69 private Display.Billboard billboard = Display.Billboard.CENTER;
70 private Color glowColor = Color.RED;
71 private Display.Brightness brightness =
new Display.Brightness(15, 15);
74 private Color backgroundColor = Color.RED;
75 private int lineWidth = 50;
76 private byte textOpacity = (byte) 0xFF;
78 private static @NotNull World firstLoadedWorld() {
79 return Bukkit.getWorlds().isEmpty()
80 ? Bukkit.createWorld(
new WorldCreator(
"world"))
81 : Bukkit.getWorlds().get(0);
90 this.world = java.util.Objects.requireNonNull(world,
"world");
91 if (this.location ==
null || this.location.getWorld() ==
null) {
92 this.location = world.getSpawnLocation();
99 this.location = java.util.Objects.requireNonNull(location,
"location");
100 if (this.location.getWorld() !=
null) {
101 this.world = this.location.getWorld();
108 if (scale <= 0)
throw new IllegalArgumentException(
"Scale must be > 0");
118 this.leftRotation = java.util.Objects.requireNonNull(leftRotation,
"leftRotation");
124 if (viewRange < 0f)
throw new IllegalArgumentException(
"viewRange must be >= 0");
125 this.viewRange = viewRange;
131 if (shadowRadius < 0f)
throw new IllegalArgumentException(
"shadowRadius must be >= 0");
132 this.shadowRadius = shadowRadius;
138 if (shadowStrength < 0f)
throw new IllegalArgumentException(
"shadowStrength must be >= 0");
139 this.shadowStrength = shadowStrength;
144 if (displayHeight <= 0f)
throw new IllegalArgumentException(
"displayHeight must be > 0");
145 this.displayHeight = displayHeight;
150 if (displayWidth <= 0f)
throw new IllegalArgumentException(
"displayWidth must be > 0");
151 this.displayWidth = displayWidth;
156 this.billboard = java.util.Objects.requireNonNull(billboard,
"billboard");
161 this.glowColor = java.util.Objects.requireNonNull(glowColor,
"glowColor");
166 this.backgroundColor = java.util.Objects.requireNonNull(backgroundColor,
"backgroundColor");
171 if (lineWidth < 0)
throw new IllegalArgumentException(
"lineWidth must be >= 0");
172 this.lineWidth = lineWidth;
181 this.brightness = java.util.Objects.requireNonNull(brightness,
"brightness");
187 if (opacity0to255 < 0 || opacity0to255 > 255) {
188 throw new IllegalArgumentException(
"textOpacity must be in range 0..255");
190 this.textOpacity = (byte) (opacity0to255 & 0xFF);
204 public @NotNull TextDisplay
spawn(@NotNull String text) {
205 java.util.Objects.requireNonNull(text,
"text");
206 if (world ==
null)
throw new IllegalStateException(
"World is null");
207 if (location ==
null || location.getWorld() ==
null) {
208 throw new IllegalStateException(
"Location/world must be set before spawning");
211 final TextDisplay td = world.spawn(location, TextDisplay.class);
214 td.text(DreamMessageFormatter.format(text, DreamMessageSettings.all()));
217 var t = td.getTransformation();
218 t.getScale().set(scale);
220 t.getLeftRotation().x = leftRotation.x;
221 t.getLeftRotation().y = leftRotation.y;
222 t.getLeftRotation().z = leftRotation.z;
223 td.setTransformation(t);
226 td.setViewRange(viewRange);
227 td.setShadowRadius(shadowRadius);
228 td.setShadowStrength(shadowStrength);
229 td.setDisplayHeight(displayHeight);
230 td.setDisplayWidth(displayWidth);
231 td.setBillboard(billboard);
232 td.setGlowColorOverride(glowColor);
233 td.setBrightness(brightness);
234 td.setBackgroundColor(backgroundColor);
235 td.setLineWidth(lineWidth);
236 td.setTextOpacity(textOpacity);
TextDisplayBuilder location(@NotNull Location location)
Sets the spawn location (world taken from the location).
TextDisplayBuilder lineWidth(int lineWidth)
TextDisplayBuilder leftRotation(@NotNull Vector3f leftRotation)
Left-rotation convenience vector (mapped into the underlying quaternion's xyz components).
TextDisplayBuilder itemGlowColor(@NotNull Color glowColor)
TextDisplayBuilder backgroundColor(@NotNull Color backgroundColor)
TextDisplay spawn(@NotNull String text)
Spawns a TextDisplay with the configured properties and the given MiniMessage text.
TextDisplayBuilder displayHeight(float displayHeight)
TextDisplayBuilder itemScale(double scale)
Uniform scale applied to the text display transform.
TextDisplayBuilder shadowStrength(float shadowStrength)
Shadow strength; higher = darker.
TextDisplayBuilder textOpacity(int opacity0to255)
Sets text opacity (0..255).
TextDisplayBuilder billboard(@NotNull Display.Billboard billboard)
TextDisplayBuilder shadowRadius(float shadowRadius)
Shadow radius in blocks.
TextDisplayBuilder viewRange(float viewRange)
View range; 0.1 ~ 16 blocks.
TextDisplayBuilder itemBrightness(@NotNull Display.Brightness brightness)
Sets explicit brightness (block, sky).
TextDisplayBuilder world(@NotNull World world)
Sets the world where the display will be spawned.
TextDisplayBuilder displayWidth(float displayWidth)
Builder utility for spawning configured TextDisplay entities.
static TextDisplayBuilder textDisplay()
Preferred factory name.
static TextDisplayBuilder BlockDisplayBuilder()
Backward-compatible alias (was misnamed previously).
Event fired after a TextDisplay is spawned by DreamTextDisplay.