From 76a5f4ea6f25d55fd0a57047007e2b2f4dc85313 Mon Sep 17 00:00:00 2001
From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com>
Date: Fri, 1 Nov 2024 15:23:32 -0500
Subject: [PATCH 1/6] wip-syncing-to-desktop
---
.../core/services/holograms/Hologram.java | 93 +++++++------------
.../services/holograms/HologramsService.java | 2 +-
2 files changed, 37 insertions(+), 58 deletions(-)
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java
index b69e71d534..cde3f8ec5d 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java
@@ -10,40 +10,26 @@
import org.bukkit.Bukkit;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
+import org.bukkit.entity.TextDisplay;
/**
- * This represents an {@link ArmorStand} that can expire and be renamed.
+ * A {@link TextDisplay} or {@link ArmorStand} (if pre1.19.4) used
+ * for displaying text "holograms".
*
- * @author TheBusyBiscuit
- *
+ * @author TheBusyBiscuit, JustAHuman
*/
-class Hologram {
-
- /**
- * This is the minimum duration after which the {@link Hologram} will expire.
- */
+public class Hologram {
private static final long EXPIRES_AFTER = TimeUnit.MINUTES.toMillis(10);
- /**
- * The {@link UUID} of the {@link ArmorStand}.
- */
private final UUID uniqueId;
-
- /**
- * The timestamp of when the {@link ArmorStand} was last accessed.
- */
private long lastAccess;
-
- /**
- * The label of this {@link Hologram}.
- */
- private String label;
+ private String text;
/**
* This creates a new {@link Hologram} for the given {@link UUID}.
*
* @param uniqueId
- * The {@link UUID} of the corresponding {@link ArmorStand}
+ * The {@link UUID} of the corresponding {@link TextDisplay} or {@link ArmorStand}
*/
Hologram(@Nonnull UUID uniqueId) {
this.uniqueId = uniqueId;
@@ -51,20 +37,19 @@ class Hologram {
}
/**
- * This returns the corresponding {@link ArmorStand}
+ * This returns the corresponding {@link TextDisplay} or {@link ArmorStand}
* and also updates the "lastAccess" timestamp.
*
- * If the {@link ArmorStand} was removed, it will return null.
+ * If the entity was removed, it will return null.
*
- * @return The {@link ArmorStand} or null.
+ * @return The {@link Entity} or null.
*/
@Nullable
- ArmorStand getArmorStand() {
- Entity n = Bukkit.getEntity(uniqueId);
-
- if (n instanceof ArmorStand armorStand && n.isValid()) {
+ public Entity getEntity() {
+ Entity entity = Bukkit.getEntity(uniqueId);
+ if ((entity instanceof TextDisplay || entity instanceof ArmorStand) && entity.isValid()) {
this.lastAccess = System.currentTimeMillis();
- return armorStand;
+ return entity;
} else {
this.lastAccess = 0;
return null;
@@ -72,63 +57,57 @@ ArmorStand getArmorStand() {
}
/**
- * This checks if the associated {@link ArmorStand} has despawned.
- *
- * @return Whether the {@link ArmorStand} despawned
+ * @return Whether the associated {@link Entity} despawned.
*/
- boolean hasDespawned() {
- return getArmorStand() == null;
+ public boolean hasDespawned() {
+ return getEntity() == null;
}
/**
* This returns whether this {@link Hologram} has expired.
- * The armorstand will expire if the last access has been more than 10
- * minutes ago.
+ * The {@link Hologram} has expired if the last access was
+ * more than 10 minutes ago.
*
* @return Whether this {@link Hologram} has expired
*/
- boolean hasExpired() {
+ public boolean hasExpired() {
return System.currentTimeMillis() - lastAccess > EXPIRES_AFTER;
}
/**
* This method sets the label of this {@link Hologram}.
*
- * @param label
+ * @param text
* The label to set
*/
- void setLabel(@Nullable String label) {
- if (Objects.equals(this.label, label)) {
+ void setText(@Nullable String text) {
+ if (Objects.equals(this.text, text)) {
/*
* Label is already set, no need to cause an entity
* update. But we can update the lastAccess flag.
*/
this.lastAccess = System.currentTimeMillis();
- } else {
- this.label = label;
- ArmorStand entity = getArmorStand();
+ return;
+ }
- if (entity != null) {
- if (label != null) {
- entity.setCustomNameVisible(true);
- entity.setCustomName(label);
- } else {
- entity.setCustomNameVisible(false);
- entity.setCustomName(null);
- }
- }
+ this.text = text;
+ Entity entity = getEntity();
+ if (entity instanceof ArmorStand armorStand) {
+ armorStand.setCustomNameVisible(text != null);
+ armorStand.setCustomName(text);
+ } else if (entity instanceof TextDisplay textDisplay) {
+ textDisplay.setText(text);
}
}
/**
- * This will remove the {@link ArmorStand} and expire this {@link Hologram}.
+ * This will remove the {@link Entity} and expire this {@link Hologram}.
*/
void remove() {
- ArmorStand armorstand = getArmorStand();
-
- if (armorstand != null) {
+ Entity entity = getEntity();
+ if (entity != null) {
lastAccess = 0;
- armorstand.remove();
+ entity.remove();
}
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java
index 2673dd9b91..3de797ce39 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java
@@ -318,7 +318,7 @@ public boolean removeHologram(@Nonnull Location loc) {
public void setHologramLabel(@Nonnull Location loc, @Nullable String label) {
Validate.notNull(loc, "Location must not be null");
- updateHologram(loc, hologram -> hologram.setLabel(label));
+ updateHologram(loc, hologram -> hologram.setText(label));
}
}
From 6237bd951914eff85173321bb3427c8d2aaa63dc Mon Sep 17 00:00:00 2001
From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com>
Date: Fri, 1 Nov 2024 17:33:00 -0500
Subject: [PATCH 2/6] wip swapping to laptop
---
.../holograms/ArmorStandHologram.java | 32 +++++
.../core/services/holograms/Hologram.java | 78 ++++-------
.../services/holograms/HologramsService.java | 126 ++++++------------
.../holograms/TextDisplayHologram.java | 33 +++++
.../items/blocks/HologramProjector.java | 37 +++--
.../slimefun4/utils/NumberUtils.java | 2 +-
src/main/resources/languages/en/messages.yml | 1 +
7 files changed, 160 insertions(+), 149 deletions(-)
create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/ArmorStandHologram.java
create mode 100644 src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/TextDisplayHologram.java
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/ArmorStandHologram.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/ArmorStandHologram.java
new file mode 100644
index 0000000000..512b4b34f7
--- /dev/null
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/ArmorStandHologram.java
@@ -0,0 +1,32 @@
+package io.github.thebusybiscuit.slimefun4.core.services.holograms;
+
+import org.bukkit.entity.ArmorStand;
+
+import java.util.Objects;
+
+public class ArmorStandHologram extends Hologram {
+
+ public ArmorStandHologram(ArmorStand entity) {
+ super(entity.getUniqueId());
+ }
+
+ @Override
+ public void setText(String text) {
+ this.lastAccess = System.currentTimeMillis();
+ if (Objects.equals(this.text, text)) {
+ return;
+ }
+
+ ArmorStand entity = getEntity();
+ if (entity != null) {
+ entity.setCustomName(text);
+ entity.setCustomNameVisible(text != null);
+ }
+ }
+
+ @Override
+ public Class getEntityType() {
+ return ArmorStand.class;
+ }
+
+}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java
index cde3f8ec5d..78040d57ea 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java
@@ -1,6 +1,5 @@
package io.github.thebusybiscuit.slimefun4.core.services.holograms;
-import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@@ -8,56 +7,37 @@
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
-import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
-import org.bukkit.entity.TextDisplay;
/**
- * A {@link TextDisplay} or {@link ArmorStand} (if pre1.19.4) used
- * for displaying text "holograms".
+ * A {@link Hologram} is a wrapper around an {@link Entity}
+ * for displaying text as "holograms".
*
* @author TheBusyBiscuit, JustAHuman
*/
-public class Hologram {
+public abstract class Hologram {
private static final long EXPIRES_AFTER = TimeUnit.MINUTES.toMillis(10);
- private final UUID uniqueId;
- private long lastAccess;
- private String text;
+ protected final UUID uniqueId;
+ protected long lastAccess;
+ protected String text;
/**
* This creates a new {@link Hologram} for the given {@link UUID}.
*
* @param uniqueId
- * The {@link UUID} of the corresponding {@link TextDisplay} or {@link ArmorStand}
+ * The {@link UUID} of the corresponding {@link Entity}
*/
- Hologram(@Nonnull UUID uniqueId) {
+ protected Hologram(@Nonnull UUID uniqueId) {
this.uniqueId = uniqueId;
this.lastAccess = System.currentTimeMillis();
}
- /**
- * This returns the corresponding {@link TextDisplay} or {@link ArmorStand}
- * and also updates the "lastAccess" timestamp.
- *
- * If the entity was removed, it will return null.
- *
- * @return The {@link Entity} or null.
- */
- @Nullable
- public Entity getEntity() {
- Entity entity = Bukkit.getEntity(uniqueId);
- if ((entity instanceof TextDisplay || entity instanceof ArmorStand) && entity.isValid()) {
- this.lastAccess = System.currentTimeMillis();
- return entity;
- } else {
- this.lastAccess = 0;
- return null;
- }
- }
+ public abstract void setText(@Nullable String text);
+ public abstract Class getEntityType();
/**
- * @return Whether the associated {@link Entity} despawned.
+ * @return Whether the associated {@link Entity} has despawned.
*/
public boolean hasDespawned() {
return getEntity() == null;
@@ -67,7 +47,7 @@ public boolean hasDespawned() {
* This returns whether this {@link Hologram} has expired.
* The {@link Hologram} has expired if the last access was
* more than 10 minutes ago.
- *
+ *
* @return Whether this {@link Hologram} has expired
*/
public boolean hasExpired() {
@@ -75,35 +55,29 @@ public boolean hasExpired() {
}
/**
- * This method sets the label of this {@link Hologram}.
+ * This returns the corresponding {@link Entity}
+ * and also updates the "lastAccess" timestamp.
+ *
+ * If the entity was removed, it will return null.
*
- * @param text
- * The label to set
+ * @return The {@link Entity} or null.
*/
- void setText(@Nullable String text) {
- if (Objects.equals(this.text, text)) {
- /*
- * Label is already set, no need to cause an entity
- * update. But we can update the lastAccess flag.
- */
+ @Nullable
+ public E getEntity() {
+ Entity entity = Bukkit.getEntity(uniqueId);
+ if (getEntityType().isInstance(entity) && entity.isValid()) {
this.lastAccess = System.currentTimeMillis();
- return;
- }
-
- this.text = text;
- Entity entity = getEntity();
- if (entity instanceof ArmorStand armorStand) {
- armorStand.setCustomNameVisible(text != null);
- armorStand.setCustomName(text);
- } else if (entity instanceof TextDisplay textDisplay) {
- textDisplay.setText(text);
+ return getEntityType().cast(entity);
+ } else {
+ this.lastAccess = 0;
+ return null;
}
}
/**
* This will remove the {@link Entity} and expire this {@link Hologram}.
*/
- void remove() {
+ public void remove() {
Entity entity = getEntity();
if (entity != null) {
lastAccess = 0;
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java
index 3de797ce39..e183652ad4 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java
@@ -2,7 +2,6 @@
import java.util.Collection;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.Map;
import java.util.function.Consumer;
import java.util.logging.Level;
@@ -11,6 +10,7 @@
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
+import io.github.bakedlibs.dough.data.persistent.PersistentDataAPI;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -19,6 +19,7 @@
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
+import org.bukkit.entity.TextDisplay;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.Plugin;
@@ -31,54 +32,26 @@
/**
* This service is responsible for handling holograms.
*
- * @author TheBusyBiscuit
+ * @author TheBusyBiscuit, JustAHuman
*
+ * @see Hologram
* @see HologramOwner
*/
public class HologramsService {
-
- /**
- * The radius in which we scan for holograms
- */
- private static final double RADIUS = 0.45;
-
- /**
- * The frequency at which to purge.
- * Every 45 seconds.
- */
+ private static final double SCAN_RADIUS = 0.45;
private static final long PURGE_RATE = 45L * 20L;
+ private static final Vector DEFAULT_OFFSET = new Vector(0.5, 0.75, 0.5);
- /**
- * Our {@link Plugin} instance
- */
private final Plugin plugin;
- /**
- * The default hologram offset
- */
- private final Vector defaultOffset = new Vector(0.5, 0.75, 0.5);
-
- /**
- * The {@link NamespacedKey} used to store data on a hologram
- */
private final NamespacedKey persistentDataKey;
+ private final Map> cache = new HashMap<>();
+ protected boolean started = false;
- /**
- * Our cache to save {@link Entity} lookups
- */
- private final Map cache = new HashMap<>();
-
- /**
- * This constructs a new {@link HologramsService}.
- *
- * @param plugin
- * Our {@link Plugin} instance
- */
public HologramsService(@Nonnull Plugin plugin) {
- this.plugin = plugin;
-
// Null-Validation is performed in the NamespacedKey constructor
- persistentDataKey = new NamespacedKey(plugin, "hologram_id");
+ this.plugin = plugin;
+ this.persistentDataKey = new NamespacedKey(plugin, "hologram_id");
}
/**
@@ -86,6 +59,11 @@ public HologramsService(@Nonnull Plugin plugin) {
* purge-task.
*/
public void start() {
+ if (started) {
+ // TODO: Log a warning/what do reviewers think?
+ return;
+ }
+
plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, this::purge, PURGE_RATE, PURGE_RATE);
}
@@ -96,67 +74,48 @@ public void start() {
*/
@Nonnull
public Vector getDefaultOffset() {
- return defaultOffset;
+ return DEFAULT_OFFSET.clone();
}
/**
* This purges any expired {@link Hologram}.
*/
private void purge() {
- Iterator iterator = cache.values().iterator();
-
- while (iterator.hasNext()) {
- Hologram hologram = iterator.next();
-
- if (hologram.hasExpired()) {
- iterator.remove();
- }
- }
+ cache.values().removeIf(Hologram::hasExpired);
}
/**
* This returns the {@link Hologram} associated with the given {@link Location}.
- * If createIfNoneExists is set to true a new {@link ArmorStand} will be spawned
+ * If createIfNoneExists is set to true a new {@link Hologram} will be spawned
* if no existing one could be found.
*
* @param loc
* The {@link Location}
* @param createIfNoneExists
- * Whether to create a new {@link ArmorStand} if none was found
+ * Whether to create a new {@link Hologram} if none was found
*
* @return The existing (or newly created) hologram
*/
@Nullable
- private Hologram getHologram(@Nonnull Location loc, boolean createIfNoneExists) {
+ private Hologram> getHologram(@Nonnull Location loc, boolean createIfNoneExists) {
Validate.notNull(loc, "Location cannot be null");
BlockPosition position = new BlockPosition(loc);
- Hologram hologram = cache.get(position);
+ Hologram> hologram = cache.get(position);
- // Check if the ArmorStand was cached and still exists
+ // Check if the Hologram was cached and still exists
if (hologram != null && !hologram.hasDespawned()) {
return hologram;
}
// Scan all nearby entities which could be possible holograms
- Collection holograms = loc.getWorld().getNearbyEntities(loc, RADIUS, RADIUS, RADIUS, this::isHologram);
-
- for (Entity n : holograms) {
- if (n instanceof ArmorStand) {
- PersistentDataContainer container = n.getPersistentDataContainer();
-
- /*
- * Any hologram we created will have a persistent data key for identification.
- * Make sure that the value matches our BlockPosition.
- */
- if (hasHologramData(container, position)) {
- if (hologram != null) {
- // Fixes #2927 - Remove any duplicates we find
- n.remove();
- } else {
- hologram = getAsHologram(position, n, container);
- }
- }
+ Collection holograms = loc.getWorld().getNearbyEntities(loc, SCAN_RADIUS, SCAN_RADIUS, SCAN_RADIUS, entity -> isHologram(entity, position));
+ for (Entity entity : holograms) {
+ if (hologram == null) {
+ hologram = getAsHologram(position, entity);
+ } else {
+ // Fixes #2927 - Remove any duplicates we find
+ entity.remove();
}
}
@@ -172,31 +131,30 @@ private Hologram getHologram(@Nonnull Location loc, boolean createIfNoneExists)
}
@ParametersAreNonnullByDefault
- private boolean hasHologramData(PersistentDataContainer container, BlockPosition position) {
- if (container.has(persistentDataKey, PersistentDataType.LONG)) {
- long value = container.get(persistentDataKey, PersistentDataType.LONG);
- return value == position.getPosition();
- } else {
- return false;
- }
+ private boolean hasHologramData(Entity entity, BlockPosition position) {
+ return PersistentDataAPI.getLong(entity, persistentDataKey) == position.getPosition();
}
/**
- * This checks if a given {@link Entity} is an {@link ArmorStand}
+ * This checks if a given {@link Entity} is an {@link TextDisplay} or {@link ArmorStand}
* and whether it has the correct attributes to be considered a {@link Hologram}.
*
- * @param n
+ * @param entity
* The {@link Entity} to check
*
* @return Whether this could be a hologram
*/
- private boolean isHologram(@Nonnull Entity n) {
- if (n instanceof ArmorStand armorStand) {
+ private boolean isHologram(@Nonnull Entity entity, BlockPosition position) {
+ if (entity instanceof ArmorStand armorStand) {
// The absolute minimum requirements to count as a hologram
- return !armorStand.isVisible() && armorStand.isSilent() && !armorStand.hasGravity();
- } else {
- return false;
+ return !armorStand.isVisible()
+ && armorStand.isSilent()
+ && !armorStand.hasGravity()
+ && hasHologramData(armorStand, position);
+ } else if (entity instanceof TextDisplay textDisplay) {
+ return hasHologramData(textDisplay, position);
}
+ return false;
}
/**
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/TextDisplayHologram.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/TextDisplayHologram.java
new file mode 100644
index 0000000000..5ff377ad59
--- /dev/null
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/TextDisplayHologram.java
@@ -0,0 +1,33 @@
+package io.github.thebusybiscuit.slimefun4.core.services.holograms;
+
+import org.bukkit.entity.TextDisplay;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+import java.util.Objects;
+
+public class TextDisplayHologram extends Hologram {
+
+ public TextDisplayHologram(@Nonnull TextDisplay textDisplay) {
+ super(textDisplay.getUniqueId());
+ }
+
+ @Override
+ public void setText(@Nullable String text) {
+ this.lastAccess = System.currentTimeMillis();
+ if (Objects.equals(this.text, text)) {
+ return;
+ }
+
+ TextDisplay textDisplay = getEntity();
+ if (textDisplay != null) {
+ textDisplay.setText(text);
+ }
+ }
+
+ @Override
+ public Class getEntityType() {
+ return TextDisplay.class;
+ }
+
+}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java
index 21891d293a..878c07b5ea 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java
@@ -31,6 +31,7 @@
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
+import org.bukkit.util.Vector;
/**
* The {@link HologramProjector} is a very simple block which allows the {@link Player}
@@ -59,13 +60,12 @@ public HologramProjector(ItemGroup itemGroup, SlimefunItemStack item, RecipeType
return new BlockPlaceHandler(false) {
@Override
- public void onPlayerPlace(BlockPlaceEvent e) {
+ public void onPlayerPlace(@Nonnull BlockPlaceEvent e) {
Block b = e.getBlockPlaced();
BlockStorage.addBlockInfo(b, "text", "Edit me via the Projector");
BlockStorage.addBlockInfo(b, OFFSET_PARAMETER, "0.5");
BlockStorage.addBlockInfo(b, "owner", e.getPlayer().getUniqueId().toString());
-
- getArmorStand(b, true);
+ updateHologram(b, "Edit me via the Projector");
}
};
@@ -76,12 +76,12 @@ public void onPlayerPlace(BlockPlaceEvent e) {
@Override
public void onBlockBreak(@Nonnull Block b) {
- killArmorStand(b);
+ removeHologram(b);
}
};
}
- public @Nonnull BlockUseHandler onRightClick() {
+ private @Nonnull BlockUseHandler onRightClick() {
return e -> {
e.cancel();
@@ -94,10 +94,23 @@ public void onBlockBreak(@Nonnull Block b) {
};
}
+ public double getOffset(@Nonnull Block projector) {
+ return NumberUtils.reparseDouble(Double.parseDouble(BlockStorage.getLocationInfo(projector.getLocation(), OFFSET_PARAMETER)));
+ }
+
+ public String getText(@Nonnull Block projector) {
+ return BlockStorage.getLocationInfo(projector.getLocation(), "text");
+ }
+
+ @Override
+ public @Nonnull Vector getHologramOffset(@Nonnull Block projector) {
+ return new Vector(0.5, getOffset(projector), 0.5);
+ }
+
private void openEditor(@Nonnull Player p, @Nonnull Block projector) {
ChestMenu menu = new ChestMenu(Slimefun.getLocalization().getMessage(p, "machines.HOLOGRAM_PROJECTOR.inventory-title"));
- menu.addItem(0, new CustomItemStack(Material.NAME_TAG, "&7Text &e(Click to edit)", "", "&f" + ChatColors.color(BlockStorage.getLocationInfo(projector.getLocation(), "text"))));
+ menu.addItem(0, new CustomItemStack(Material.NAME_TAG, "&7Text &e(Click to edit)", "", "&f" + getText(projector)));
menu.addMenuClickHandler(0, (pl, slot, item, action) -> {
pl.closeInventory();
Slimefun.getLocalization().sendMessage(pl, "machines.HOLOGRAM_PROJECTOR.enter-text", true);
@@ -106,22 +119,22 @@ private void openEditor(@Nonnull Player p, @Nonnull Block projector) {
// Fixes #3445 - Make sure the projector is not broken
if (!BlockStorage.check(projector, getId())) {
// Hologram projector no longer exists.
- // TODO: Add a chat message informing the player that their message was ignored.
+ Slimefun.getLocalization().sendMessage(pl, "machines.HOLOGRAM_PROJECTOR.broken", true);
return;
}
- ArmorStand hologram = getArmorStand(projector, true);
- hologram.setCustomName(ChatColors.color(message));
- BlockStorage.addBlockInfo(projector, "text", hologram.getCustomName());
+ message = ChatColors.color(message);
+ updateHologram(projector, message);
+ BlockStorage.addBlockInfo(projector, "text", message);
openEditor(pl, projector);
});
return false;
});
- menu.addItem(1, new CustomItemStack(Material.CLOCK, "&7Offset: &e" + NumberUtils.roundDecimalNumber(Double.valueOf(BlockStorage.getLocationInfo(projector.getLocation(), OFFSET_PARAMETER)) + 1.0D), "", "&fLeft Click: &7+0.1", "&fRight Click: &7-0.1"));
+ menu.addItem(1, new CustomItemStack(Material.CLOCK, "&7Offset: &e" + NumberUtils.roundDecimalNumber(getOffset(projector) + 1.0D), "", "&fLeft Click: &7+0.1", "&fRight Click: &7-0.1"));
menu.addMenuClickHandler(1, (pl, slot, item, action) -> {
- double offset = NumberUtils.reparseDouble(Double.valueOf(BlockStorage.getLocationInfo(projector.getLocation(), OFFSET_PARAMETER)) + (action.isRightClicked() ? -0.1F : 0.1F));
+ double offset = getOffset(projector) + (action.isRightClicked() ? -0.1F : 0.1F);
ArmorStand hologram = getArmorStand(projector, true);
Location l = new Location(projector.getWorld(), projector.getX() + 0.5, projector.getY() + offset, projector.getZ() + 0.5);
hologram.teleport(l);
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java
index 0b85e6e68d..1b1bf24fc8 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/NumberUtils.java
@@ -224,7 +224,7 @@ public static int getInt(@Nonnull String str, int defaultValue) {
}
public static double reparseDouble(double number) {
- return Double.valueOf(roundDecimalNumber(number));
+ return Double.parseDouble(roundDecimalNumber(number));
}
public static long getLong(@Nullable Long value, long defaultValue) {
diff --git a/src/main/resources/languages/en/messages.yml b/src/main/resources/languages/en/messages.yml
index 77bd80895a..c1b84c73a8 100644
--- a/src/main/resources/languages/en/messages.yml
+++ b/src/main/resources/languages/en/messages.yml
@@ -316,6 +316,7 @@ machines:
HOLOGRAM_PROJECTOR:
enter-text: '&7Please enter your desired Hologram Text into your Chat. &r(Color Codes are supported!)'
inventory-title: 'Hologram Editor'
+ broken: '&cThe Hologram Projector you were editing has been broken, your message has been ignored.'
ELEVATOR:
no-destinations: '&4No destinations found'
From 73bd2b4412deba02f8476d6edacae324f31bb842 Mon Sep 17 00:00:00 2001
From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com>
Date: Fri, 1 Nov 2024 20:02:25 -0500
Subject: [PATCH 3/6] finish lots of stuff
---
.../slimefun4/api/MinecraftVersion.java | 6 +
.../core/attributes/HologramOwner.java | 31 ++--
.../holograms/ArmorStandHologram.java | 25 ++-
.../core/services/holograms/Hologram.java | 8 +
.../services/holograms/HologramsService.java | 161 ++++++++----------
.../holograms/TextDisplayHologram.java | 21 ++-
.../items/blocks/HologramProjector.java | 74 ++------
.../slimefun4/utils/ArmorStandUtils.java | 9 +-
8 files changed, 172 insertions(+), 163 deletions(-)
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java
index 4fc0160ac6..d02a94e229 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java
@@ -43,6 +43,12 @@ public enum MinecraftVersion {
*/
MINECRAFT_1_19(19, "1.19.x"),
+ /**
+ * This constant represents Minecraft (Java Edition) Version 1.19.4
+ * This minor update added display entities
+ */
+ MINECRAFT_1_19_4(19, 4, "1.19.4+"),
+
/**
* This constant represents Minecraft (Java Edition) Version 1.20
* ("The Trails & Tales Update")
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/HologramOwner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/HologramOwner.java
index b14e32c35c..55f24a1689 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/HologramOwner.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/HologramOwner.java
@@ -1,6 +1,7 @@
package io.github.thebusybiscuit.slimefun4.core.attributes;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import org.bukkit.Location;
import org.bukkit.block.Block;
@@ -14,37 +15,45 @@
/**
* This {@link ItemAttribute} manages holograms.
*
- * @author TheBusyBiscuit
+ * @author TheBusyBiscuit, JustAHuman
*
* @see HologramProjector
* @see HologramsService
- *
*/
public interface HologramOwner extends ItemAttribute {
/**
* This will update the hologram text for the given {@link Block}.
*
- * @param b
+ * @param block
* The {@link Block} to which the hologram belongs
*
* @param text
- * The nametag for the hologram
+ * The text for the hologram
*/
- default void updateHologram(@Nonnull Block b, @Nonnull String text) {
- Location loc = b.getLocation().add(getHologramOffset(b));
- Slimefun.getHologramsService().setHologramLabel(loc, ChatColors.color(text));
+ default void updateHologram(@Nonnull Block block, @Nullable String text) {
+ Location location = block.getLocation().add(getHologramOffset(block));
+ if (text != null) {
+ text = ChatColors.color(text);
+ }
+ Slimefun.getHologramsService().setHologramLabel(location, text);
+ }
+
+ default void setOffset(@Nonnull Block block, Vector offset) {
+ Location hologramLocation = block.getLocation().add(getHologramOffset(block));
+ Location newHologramLocation = block.getLocation().add(offset);
+ Slimefun.getHologramsService().teleportHologram(hologramLocation, newHologramLocation);
}
/**
* This will remove the hologram for the given {@link Block}.
*
- * @param b
+ * @param block
* The {@link Block} to which the hologram blocks
*/
- default void removeHologram(@Nonnull Block b) {
- Location loc = b.getLocation().add(getHologramOffset(b));
- Slimefun.getHologramsService().removeHologram(loc);
+ default void removeHologram(@Nonnull Block block) {
+ Location location = block.getLocation().add(getHologramOffset(block));
+ Slimefun.getHologramsService().removeHologram(location);
}
/**
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/ArmorStandHologram.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/ArmorStandHologram.java
index 512b4b34f7..397b270f97 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/ArmorStandHologram.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/ArmorStandHologram.java
@@ -1,12 +1,18 @@
package io.github.thebusybiscuit.slimefun4.core.services.holograms;
+import io.github.bakedlibs.dough.blocks.BlockPosition;
+import io.github.bakedlibs.dough.data.persistent.PersistentDataAPI;
+import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
+import io.github.thebusybiscuit.slimefun4.utils.ArmorStandUtils;
+import org.bukkit.Location;
import org.bukkit.entity.ArmorStand;
+import org.bukkit.entity.Entity;
import java.util.Objects;
public class ArmorStandHologram extends Hologram {
- public ArmorStandHologram(ArmorStand entity) {
+ private ArmorStandHologram(ArmorStand entity) {
super(entity.getUniqueId());
}
@@ -29,4 +35,21 @@ public Class getEntityType() {
return ArmorStand.class;
}
+ public static Hologram> of(Entity entity, BlockPosition position) {
+ if (!(entity instanceof ArmorStand armorStand)) {
+ return null;
+ }
+
+ armorStand.setAI(false);
+ armorStand.setInvulnerable(true);
+ ArmorStandUtils.setupArmorStand(armorStand);
+ PersistentDataAPI.setLong(entity, Slimefun.getHologramsService().getKey(), position.getPosition());
+ return new ArmorStandHologram(armorStand);
+ }
+
+ public static Hologram> create(Location location, BlockPosition position) {
+ ArmorStand armorStand = location.getWorld().spawn(location, ArmorStand.class);
+ return of(armorStand, position);
+ }
+
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java
index 78040d57ea..576db83b33 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java
@@ -7,6 +7,7 @@
import javax.annotation.Nullable;
import org.bukkit.Bukkit;
+import org.bukkit.Location;
import org.bukkit.entity.Entity;
/**
@@ -74,6 +75,13 @@ public E getEntity() {
}
}
+ public void teleport(Location location) {
+ E getEntity = getEntity();
+ if (getEntity != null) {
+ getEntity.teleport(location);
+ }
+ }
+
/**
* This will remove the {@link Entity} and expire this {@link Hologram}.
*/
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java
index e183652ad4..be8920830b 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java
@@ -11,6 +11,7 @@
import javax.annotation.ParametersAreNonnullByDefault;
import io.github.bakedlibs.dough.data.persistent.PersistentDataAPI;
+import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@@ -18,10 +19,7 @@
import org.bukkit.Server;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
-import org.bukkit.entity.EntityType;
import org.bukkit.entity.TextDisplay;
-import org.bukkit.persistence.PersistentDataContainer;
-import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector;
@@ -43,15 +41,14 @@ public class HologramsService {
private static final Vector DEFAULT_OFFSET = new Vector(0.5, 0.75, 0.5);
private final Plugin plugin;
-
- private final NamespacedKey persistentDataKey;
+ private final NamespacedKey key;
private final Map> cache = new HashMap<>();
protected boolean started = false;
public HologramsService(@Nonnull Plugin plugin) {
// Null-Validation is performed in the NamespacedKey constructor
this.plugin = plugin;
- this.persistentDataKey = new NamespacedKey(plugin, "hologram_id");
+ this.key = new NamespacedKey(plugin, "hologram_id");
}
/**
@@ -68,15 +65,19 @@ public void start() {
}
/**
- * This returns the default {@link Hologram} offset.
- *
- * @return The default offset
+ * @return The default {@link Hologram} offset
*/
- @Nonnull
- public Vector getDefaultOffset() {
+ public @Nonnull Vector getDefaultOffset() {
return DEFAULT_OFFSET.clone();
}
+ /**
+ * @return The {@link NamespacedKey} marking an entity as a hologram & storing its position
+ */
+ public @Nonnull NamespacedKey getKey() {
+ return key;
+ }
+
/**
* This purges any expired {@link Hologram}.
*/
@@ -99,6 +100,7 @@ private void purge() {
@Nullable
private Hologram> getHologram(@Nonnull Location loc, boolean createIfNoneExists) {
Validate.notNull(loc, "Location cannot be null");
+ Validate.notNull(loc.getWorld(), "The Location's World cannot be null");
BlockPosition position = new BlockPosition(loc);
Hologram> hologram = cache.get(position);
@@ -112,7 +114,7 @@ private Hologram> getHologram(@Nonnull Location loc, boolean createIfNoneExist
Collection holograms = loc.getWorld().getNearbyEntities(loc, SCAN_RADIUS, SCAN_RADIUS, SCAN_RADIUS, entity -> isHologram(entity, position));
for (Entity entity : holograms) {
if (hologram == null) {
- hologram = getAsHologram(position, entity);
+ hologram = getAsHologram(entity, position);
} else {
// Fixes #2927 - Remove any duplicates we find
entity.remove();
@@ -120,11 +122,10 @@ private Hologram> getHologram(@Nonnull Location loc, boolean createIfNoneExist
}
if (hologram == null && createIfNoneExists) {
- // Spawn a new ArmorStand
- ArmorStand armorstand = (ArmorStand) loc.getWorld().spawnEntity(loc, EntityType.ARMOR_STAND);
- PersistentDataContainer container = armorstand.getPersistentDataContainer();
-
- return getAsHologram(position, armorstand, container);
+ if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_19_4)) {
+ return TextDisplayHologram.create(loc, position);
+ }
+ return ArmorStandHologram.create(loc, position);
} else {
return hologram;
}
@@ -132,7 +133,7 @@ private Hologram> getHologram(@Nonnull Location loc, boolean createIfNoneExist
@ParametersAreNonnullByDefault
private boolean hasHologramData(Entity entity, BlockPosition position) {
- return PersistentDataAPI.getLong(entity, persistentDataKey) == position.getPosition();
+ return PersistentDataAPI.getLong(entity, key) == position.getPosition();
}
/**
@@ -158,41 +159,22 @@ private boolean isHologram(@Nonnull Entity entity, BlockPosition position) {
}
/**
- * This will cast the {@link Entity} to an {@link ArmorStand} and it will apply
- * all necessary attributes to the {@link ArmorStand}, then return a {@link Hologram}.
- *
+ * This will cast and find the matching {@link Hologram} for the given {@link Entity}.
+ *
+ * @param entity
+ * * The {@link Entity}
* @param position
* The {@link BlockPosition} of this hologram
- * @param entity
- * The {@link Entity}
- * @param container
- * The {@link PersistentDataContainer} of the given {@link Entity}
*
* @return The {@link Hologram}
*/
- @Nullable
- private Hologram getAsHologram(@Nonnull BlockPosition position, @Nonnull Entity entity, @Nonnull PersistentDataContainer container) {
- if (entity instanceof ArmorStand armorStand) {
- armorStand.setVisible(false);
- armorStand.setInvulnerable(true);
- armorStand.setSilent(true);
- armorStand.setMarker(true);
- armorStand.setAI(false);
- armorStand.setGravity(false);
- armorStand.setRemoveWhenFarAway(false);
-
- // Set a persistent tag to re-identify the correct hologram later
- container.set(persistentDataKey, PersistentDataType.LONG, position.getPosition());
-
- // Store in cache for faster access
- Hologram hologram = new Hologram(armorStand.getUniqueId());
- cache.put(position, hologram);
-
- return hologram;
- } else {
- // This should never be reached
- return null;
+ @ParametersAreNonnullByDefault
+ private @Nullable Hologram> getAsHologram(Entity entity, BlockPosition position) {
+ Hologram> hologram = TextDisplayHologram.of(entity, position);
+ if (hologram == null) {
+ hologram = ArmorStandHologram.of(entity, position);
}
+ return hologram;
}
/**
@@ -206,27 +188,22 @@ private Hologram getAsHologram(@Nonnull BlockPosition position, @Nonnull Entity
* @param consumer
* The callback to run
*/
- private void updateHologram(@Nonnull Location loc, @Nonnull Consumer consumer) {
+ private void updateHologram(@Nonnull Location loc, @Nonnull Consumer> consumer) {
Validate.notNull(loc, "Location must not be null");
Validate.notNull(consumer, "Callbacks must not be null");
+ if (!Bukkit.isPrimaryThread()) {
+ Slimefun.runSync(() -> updateHologram(loc, consumer));
+ return;
+ }
- Runnable runnable = () -> {
- try {
- Hologram hologram = getHologram(loc, true);
-
- if (hologram != null) {
- consumer.accept(hologram);
- }
- } catch (Exception | LinkageError x) {
- Slimefun.logger().log(Level.SEVERE, "Hologram located at {0}", new BlockPosition(loc));
- Slimefun.logger().log(Level.SEVERE, "Something went wrong while trying to update this hologram", x);
+ try {
+ Hologram> hologram = getHologram(loc, true);
+ if (hologram != null) {
+ consumer.accept(hologram);
}
- };
-
- if (Bukkit.isPrimaryThread()) {
- runnable.run();
- } else {
- Slimefun.runSync(runnable);
+ } catch (Exception | LinkageError x) {
+ Slimefun.logger().log(Level.SEVERE, "Hologram located at {0}", new BlockPosition(loc));
+ Slimefun.logger().log(Level.SEVERE, "Something went wrong while trying to update this hologram", x);
}
}
@@ -235,48 +212,52 @@ private void updateHologram(@Nonnull Location loc, @Nonnull Consumer c
*
* This method must be executed on the main {@link Server} {@link Thread}.
*
- * @param loc
+ * @param location
* The {@link Location}
*
* @return Whether the {@link Hologram} could be removed, false if the {@link Hologram} does not
* exist or was already removed
*/
- public boolean removeHologram(@Nonnull Location loc) {
- Validate.notNull(loc, "Location cannot be null");
-
- if (Bukkit.isPrimaryThread()) {
- try {
- Hologram hologram = getHologram(loc, false);
+ public boolean removeHologram(@Nonnull Location location) {
+ Validate.notNull(location, "Location cannot be null");
+ if (!Bukkit.isPrimaryThread()) {
+ throw new UnsupportedOperationException("You cannot remove a hologram asynchronously.");
+ }
- if (hologram != null) {
- cache.remove(new BlockPosition(loc));
- hologram.remove();
- return true;
- } else {
- return false;
- }
- } catch (Exception | LinkageError x) {
- Slimefun.logger().log(Level.SEVERE, "Hologram located at {0}", new BlockPosition(loc));
- Slimefun.logger().log(Level.SEVERE, "Something went wrong while trying to remove this hologram", x);
+ try {
+ Hologram> hologram = getHologram(location, false);
+ if (hologram == null) {
return false;
}
- } else {
- throw new UnsupportedOperationException("You cannot remove a hologram asynchronously.");
+
+ cache.remove(new BlockPosition(location));
+ hologram.remove();
+ return true;
+ } catch (Exception | LinkageError x) {
+ Slimefun.logger().log(Level.SEVERE, "Hologram located at {0}", new BlockPosition(location));
+ Slimefun.logger().log(Level.SEVERE, "Something went wrong while trying to remove this hologram", x);
+ return false;
}
}
/**
- * This will update the label of the {@link Hologram}.
+ * This will update the text of the {@link Hologram}.
*
- * @param loc
+ * @param location
* The {@link Location} of this {@link Hologram}
- * @param label
- * The label to set, can be null
+ * @param text
+ * The text to set, can be null
*/
- public void setHologramLabel(@Nonnull Location loc, @Nullable String label) {
- Validate.notNull(loc, "Location must not be null");
+ public void setHologramLabel(@Nonnull Location location, @Nullable String text) {
+ Validate.notNull(location, "Location must not be null");
+
+ updateHologram(location, hologram -> hologram.setText(text));
+ }
+
+ public void teleportHologram(@Nonnull Location location, @Nonnull Location to) {
+ Validate.notNull(location, "Location must not be null");
- updateHologram(loc, hologram -> hologram.setText(label));
+ updateHologram(location, hologram -> hologram.teleport(to));
}
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/TextDisplayHologram.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/TextDisplayHologram.java
index 5ff377ad59..e2fb270e6d 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/TextDisplayHologram.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/TextDisplayHologram.java
@@ -1,5 +1,10 @@
package io.github.thebusybiscuit.slimefun4.core.services.holograms;
+import io.github.bakedlibs.dough.blocks.BlockPosition;
+import io.github.bakedlibs.dough.data.persistent.PersistentDataAPI;
+import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
+import org.bukkit.Location;
+import org.bukkit.entity.Entity;
import org.bukkit.entity.TextDisplay;
import javax.annotation.Nonnull;
@@ -8,7 +13,7 @@
public class TextDisplayHologram extends Hologram {
- public TextDisplayHologram(@Nonnull TextDisplay textDisplay) {
+ private TextDisplayHologram(@Nonnull TextDisplay textDisplay) {
super(textDisplay.getUniqueId());
}
@@ -30,4 +35,18 @@ public Class getEntityType() {
return TextDisplay.class;
}
+ public static TextDisplayHologram of(Entity entity, BlockPosition position) {
+ if (!(entity instanceof TextDisplay textDisplay)) {
+ return null;
+ }
+
+ PersistentDataAPI.setLong(entity, Slimefun.getHologramsService().getKey(), position.getPosition());
+ return new TextDisplayHologram(textDisplay);
+ }
+
+ public static TextDisplayHologram create(Location location, BlockPosition position) {
+ TextDisplay textDisplay = location.getWorld().spawn(location, TextDisplay.class);
+ return of(textDisplay, position);
+ }
+
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java
index 878c07b5ea..52bd502b6c 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/blocks/HologramProjector.java
@@ -3,11 +3,8 @@
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
-import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
-import org.bukkit.entity.ArmorStand;
-import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;
@@ -25,7 +22,6 @@
import io.github.thebusybiscuit.slimefun4.core.services.holograms.HologramsService;
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
import io.github.thebusybiscuit.slimefun4.implementation.handlers.SimpleBlockBreakHandler;
-import io.github.thebusybiscuit.slimefun4.utils.ArmorStandUtils;
import io.github.thebusybiscuit.slimefun4.utils.ChatUtils;
import io.github.thebusybiscuit.slimefun4.utils.NumberUtils;
@@ -43,10 +39,8 @@
*
* @see HologramOwner
* @see HologramsService
- *
*/
public class HologramProjector extends SlimefunItem implements HologramOwner {
-
private static final String OFFSET_PARAMETER = "offset";
@ParametersAreNonnullByDefault
@@ -58,38 +52,34 @@ public HologramProjector(ItemGroup itemGroup, SlimefunItemStack item, RecipeType
private @Nonnull BlockPlaceHandler onPlace() {
return new BlockPlaceHandler(false) {
-
@Override
- public void onPlayerPlace(@Nonnull BlockPlaceEvent e) {
- Block b = e.getBlockPlaced();
- BlockStorage.addBlockInfo(b, "text", "Edit me via the Projector");
- BlockStorage.addBlockInfo(b, OFFSET_PARAMETER, "0.5");
- BlockStorage.addBlockInfo(b, "owner", e.getPlayer().getUniqueId().toString());
- updateHologram(b, "Edit me via the Projector");
+ public void onPlayerPlace(@Nonnull BlockPlaceEvent event) {
+ Block block = event.getBlockPlaced();
+ BlockStorage.addBlockInfo(block, "text", "Edit me via the Projector");
+ BlockStorage.addBlockInfo(block, OFFSET_PARAMETER, "0.5");
+ BlockStorage.addBlockInfo(block, "owner", event.getPlayer().getUniqueId().toString());
+ updateHologram(block, "Edit me via the Projector");
}
-
};
}
private @Nonnull BlockBreakHandler onBreak() {
return new SimpleBlockBreakHandler() {
-
@Override
- public void onBlockBreak(@Nonnull Block b) {
- removeHologram(b);
+ public void onBlockBreak(@Nonnull Block block) {
+ removeHologram(block);
}
};
}
private @Nonnull BlockUseHandler onRightClick() {
- return e -> {
- e.cancel();
-
- Player p = e.getPlayer();
- Block b = e.getClickedBlock().get();
+ return event -> {
+ event.cancel();
- if (BlockStorage.getLocationInfo(b.getLocation(), "owner").equals(p.getUniqueId().toString())) {
- openEditor(p, b);
+ Player player = event.getPlayer();
+ Block block = event.getClickedBlock().get();
+ if (BlockStorage.getLocationInfo(block.getLocation(), "owner").equals(player.getUniqueId().toString())) {
+ openEditor(player, block);
}
};
}
@@ -135,45 +125,13 @@ private void openEditor(@Nonnull Player p, @Nonnull Block projector) {
menu.addItem(1, new CustomItemStack(Material.CLOCK, "&7Offset: &e" + NumberUtils.roundDecimalNumber(getOffset(projector) + 1.0D), "", "&fLeft Click: &7+0.1", "&fRight Click: &7-0.1"));
menu.addMenuClickHandler(1, (pl, slot, item, action) -> {
double offset = getOffset(projector) + (action.isRightClicked() ? -0.1F : 0.1F);
- ArmorStand hologram = getArmorStand(projector, true);
- Location l = new Location(projector.getWorld(), projector.getX() + 0.5, projector.getY() + offset, projector.getZ() + 0.5);
- hologram.teleport(l);
-
- BlockStorage.addBlockInfo(projector, OFFSET_PARAMETER, String.valueOf(offset));
+ setOffset(projector, new Vector(0.5, offset, 0.5));
openEditor(pl, projector);
+ BlockStorage.addBlockInfo(projector, OFFSET_PARAMETER, String.valueOf(offset));
return false;
});
menu.open(p);
}
- private static ArmorStand getArmorStand(@Nonnull Block projector, boolean createIfNoneExists) {
- String nametag = BlockStorage.getLocationInfo(projector.getLocation(), "text");
- double offset = Double.parseDouble(BlockStorage.getLocationInfo(projector.getLocation(), OFFSET_PARAMETER));
- Location l = new Location(projector.getWorld(), projector.getX() + 0.5, projector.getY() + offset, projector.getZ() + 0.5);
-
- for (Entity n : l.getChunk().getEntities()) {
- if (n instanceof ArmorStand armorStand && l.distanceSquared(n.getLocation()) < 0.4) {
- String customName = n.getCustomName();
-
- if (customName != null && customName.equals(nametag)) {
- return armorStand;
- }
- }
- }
-
- if (!createIfNoneExists) {
- return null;
- }
-
- return ArmorStandUtils.spawnArmorStand(l, nametag);
- }
-
- private static void killArmorStand(@Nonnull Block b) {
- ArmorStand hologram = getArmorStand(b, false);
-
- if (hologram != null) {
- hologram.remove();
- }
- }
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ArmorStandUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ArmorStandUtils.java
index e2cf5ae10f..48ba1fb1ce 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ArmorStandUtils.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/utils/ArmorStandUtils.java
@@ -43,7 +43,7 @@ private ArmorStandUtils() {}
/**
* Spawns an {@link ArmorStand} at the given {@link Location}
*
- * Set Properties: Invisible, Silent, Marker, No-Gravity, No Base Plate, Don't Remove When Far Away
+ * For set properties see {@link #setupArmorStand(ArmorStand)}
*
* @param location The {@link Location} to spawn the {@link ArmorStand}
*
@@ -63,7 +63,12 @@ private ArmorStandUtils() {}
return location.getWorld().spawn(location, ArmorStand.class, ArmorStandUtils::setupArmorStand);
}
- private static void setupArmorStand(ArmorStand armorStand) {
+ /**
+ * Sets Invisible, Silent, Marker, No-Gravity, No Base Plate, Don't Remove When Far Away
+ *
+ * @param armorStand The {@link ArmorStand} to set up
+ */
+ public static void setupArmorStand(ArmorStand armorStand) {
armorStand.setVisible(false);
armorStand.setSilent(true);
armorStand.setMarker(true);
From f594e1950aa2d32881927fac8943464315401c05 Mon Sep 17 00:00:00 2001
From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com>
Date: Fri, 1 Nov 2024 20:25:32 -0500
Subject: [PATCH 4/6] javadocs, rearrange a bit, visibilty
---
.../core/attributes/HologramOwner.java | 62 +++++++++++--------
.../holograms/ArmorStandHologram.java | 6 +-
.../core/services/holograms/Hologram.java | 3 +-
.../services/holograms/HologramsService.java | 53 +++++++++-------
.../holograms/TextDisplayHologram.java | 6 +-
5 files changed, 72 insertions(+), 58 deletions(-)
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/HologramOwner.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/HologramOwner.java
index 55f24a1689..c21b4e016a 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/HologramOwner.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/attributes/HologramOwner.java
@@ -1,7 +1,6 @@
package io.github.thebusybiscuit.slimefun4.core.attributes;
import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import org.bukkit.Location;
import org.bukkit.block.Block;
@@ -21,6 +20,20 @@
* @see HologramsService
*/
public interface HologramOwner extends ItemAttribute {
+ /**
+ * This returns the offset of the hologram as a {@link Vector}.
+ * This offset is applied to {@link Block#getLocation()} when spawning
+ * the hologram.
+ *
+ * @param block
+ * The {@link Block} which serves as the origin point
+ *
+ * @return The hologram offset
+ */
+ @Nonnull
+ default Vector getHologramOffset(@Nonnull Block block) {
+ return Slimefun.getHologramsService().getDefaultOffset();
+ }
/**
* This will update the hologram text for the given {@link Block}.
@@ -31,17 +44,32 @@ public interface HologramOwner extends ItemAttribute {
* @param text
* The text for the hologram
*/
- default void updateHologram(@Nonnull Block block, @Nullable String text) {
- Location location = block.getLocation().add(getHologramOffset(block));
- if (text != null) {
- text = ChatColors.color(text);
+ default void updateHologram(@Nonnull Block block, @Nonnull String text) {
+ Location location = block.getLocation();
+ if (Slimefun.getTickerTask().isDeletedSoon(location)) {
+ return;
}
- Slimefun.getHologramsService().setHologramLabel(location, text);
+
+ Slimefun.getHologramsService().setHologramLabel(location.add(getHologramOffset(block)), ChatColors.color(text));
}
- default void setOffset(@Nonnull Block block, Vector offset) {
- Location hologramLocation = block.getLocation().add(getHologramOffset(block));
- Location newHologramLocation = block.getLocation().add(offset);
+ /**
+ * This will update the hologram text for the given {@link Block}.
+ *
+ * @param block
+ * The {@link Block} to which the hologram belongs
+ *
+ * @param offset
+ * The new offset for the hologram
+ */
+ default void setOffset(@Nonnull Block block, @Nonnull Vector offset) {
+ Location location = block.getLocation();
+ if (Slimefun.getTickerTask().isDeletedSoon(location)) {
+ return;
+ }
+
+ Location hologramLocation = location.clone().add(getHologramOffset(block));
+ Location newHologramLocation = location.clone().add(offset);
Slimefun.getHologramsService().teleportHologram(hologramLocation, newHologramLocation);
}
@@ -55,20 +83,4 @@ default void removeHologram(@Nonnull Block block) {
Location location = block.getLocation().add(getHologramOffset(block));
Slimefun.getHologramsService().removeHologram(location);
}
-
- /**
- * This returns the offset of the hologram as a {@link Vector}.
- * This offset is applied to {@link Block#getLocation()} when spawning
- * the hologram.
- *
- * @param block
- * The {@link Block} which serves as the origin point
- *
- * @return The hologram offset
- */
- @Nonnull
- default Vector getHologramOffset(@Nonnull Block block) {
- return Slimefun.getHologramsService().getDefaultOffset();
- }
-
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/ArmorStandHologram.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/ArmorStandHologram.java
index 397b270f97..b98bd3adc4 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/ArmorStandHologram.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/ArmorStandHologram.java
@@ -11,7 +11,6 @@
import java.util.Objects;
public class ArmorStandHologram extends Hologram {
-
private ArmorStandHologram(ArmorStand entity) {
super(entity.getUniqueId());
}
@@ -35,7 +34,7 @@ public Class getEntityType() {
return ArmorStand.class;
}
- public static Hologram> of(Entity entity, BlockPosition position) {
+ static ArmorStandHologram of(Entity entity, BlockPosition position) {
if (!(entity instanceof ArmorStand armorStand)) {
return null;
}
@@ -47,9 +46,8 @@ public static Hologram> of(Entity entity, BlockPosition position) {
return new ArmorStandHologram(armorStand);
}
- public static Hologram> create(Location location, BlockPosition position) {
+ static ArmorStandHologram create(Location location, BlockPosition position) {
ArmorStand armorStand = location.getWorld().spawn(location, ArmorStand.class);
return of(armorStand, position);
}
-
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java
index 576db83b33..ecbe8fc96e 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java
@@ -16,7 +16,7 @@
*
* @author TheBusyBiscuit, JustAHuman
*/
-public abstract class Hologram {
+abstract class Hologram {
private static final long EXPIRES_AFTER = TimeUnit.MINUTES.toMillis(10);
protected final UUID uniqueId;
@@ -92,5 +92,4 @@ public void remove() {
entity.remove();
}
}
-
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java
index be8920830b..f9307859c5 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java
@@ -207,14 +207,42 @@ private void updateHologram(@Nonnull Location loc, @Nonnull Consumer
}
}
+ /**
+ * This will update the text of the {@link Hologram}.
+ *
+ * @param location
+ * The {@link Location} of this {@link Hologram}
+ * @param text
+ * The text to set, can be null
+ */
+ public void setHologramLabel(@Nonnull Location location, @Nullable String text) {
+ Validate.notNull(location, "Location must not be null");
+
+ updateHologram(location, hologram -> hologram.setText(text));
+ }
+
+ /**
+ * This will teleport the {@link Hologram} to the given {@link Location}.
+ *
+ * @param location
+ * The {@link Location} of this {@link Hologram}
+ * @param to
+ * The {@link Location} to teleport the {@link Hologram} to
+ */
+ public void teleportHologram(@Nonnull Location location, @Nonnull Location to) {
+ Validate.notNull(location, "Location must not be null");
+
+ updateHologram(location, hologram -> hologram.teleport(to));
+ }
+
/**
* This removes the {@link Hologram} at that given {@link Location}.
*
* This method must be executed on the main {@link Server} {@link Thread}.
- *
+ *
* @param location
* The {@link Location}
- *
+ *
* @return Whether the {@link Hologram} could be removed, false if the {@link Hologram} does not
* exist or was already removed
*/
@@ -239,25 +267,4 @@ public boolean removeHologram(@Nonnull Location location) {
return false;
}
}
-
- /**
- * This will update the text of the {@link Hologram}.
- *
- * @param location
- * The {@link Location} of this {@link Hologram}
- * @param text
- * The text to set, can be null
- */
- public void setHologramLabel(@Nonnull Location location, @Nullable String text) {
- Validate.notNull(location, "Location must not be null");
-
- updateHologram(location, hologram -> hologram.setText(text));
- }
-
- public void teleportHologram(@Nonnull Location location, @Nonnull Location to) {
- Validate.notNull(location, "Location must not be null");
-
- updateHologram(location, hologram -> hologram.teleport(to));
- }
-
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/TextDisplayHologram.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/TextDisplayHologram.java
index e2fb270e6d..15baf23a68 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/TextDisplayHologram.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/TextDisplayHologram.java
@@ -12,7 +12,6 @@
import java.util.Objects;
public class TextDisplayHologram extends Hologram {
-
private TextDisplayHologram(@Nonnull TextDisplay textDisplay) {
super(textDisplay.getUniqueId());
}
@@ -35,7 +34,7 @@ public Class getEntityType() {
return TextDisplay.class;
}
- public static TextDisplayHologram of(Entity entity, BlockPosition position) {
+ static TextDisplayHologram of(Entity entity, BlockPosition position) {
if (!(entity instanceof TextDisplay textDisplay)) {
return null;
}
@@ -44,9 +43,8 @@ public static TextDisplayHologram of(Entity entity, BlockPosition position) {
return new TextDisplayHologram(textDisplay);
}
- public static TextDisplayHologram create(Location location, BlockPosition position) {
+ static TextDisplayHologram create(Location location, BlockPosition position) {
TextDisplay textDisplay = location.getWorld().spawn(location, TextDisplay.class);
return of(textDisplay, position);
}
-
}
From 7abd04e268f8fc5f410c485afd32ed2460c758dd Mon Sep 17 00:00:00 2001
From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com>
Date: Sat, 2 Nov 2024 09:18:28 -0500
Subject: [PATCH 5/6] no type variable, more version checks
---
.../holograms/ArmorStandHologram.java | 4 +--
.../core/services/holograms/Hologram.java | 8 ++---
.../services/holograms/HologramsService.java | 29 ++++++++++---------
.../holograms/TextDisplayHologram.java | 6 ++--
4 files changed, 25 insertions(+), 22 deletions(-)
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/ArmorStandHologram.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/ArmorStandHologram.java
index b98bd3adc4..cfbe0497ba 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/ArmorStandHologram.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/ArmorStandHologram.java
@@ -10,7 +10,7 @@
import java.util.Objects;
-public class ArmorStandHologram extends Hologram {
+public class ArmorStandHologram extends Hologram {
private ArmorStandHologram(ArmorStand entity) {
super(entity.getUniqueId());
}
@@ -22,7 +22,7 @@ public void setText(String text) {
return;
}
- ArmorStand entity = getEntity();
+ Entity entity = getEntity();
if (entity != null) {
entity.setCustomName(text);
entity.setCustomNameVisible(text != null);
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java
index ecbe8fc96e..13b959dd68 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/Hologram.java
@@ -16,7 +16,7 @@
*
* @author TheBusyBiscuit, JustAHuman
*/
-abstract class Hologram {
+abstract class Hologram {
private static final long EXPIRES_AFTER = TimeUnit.MINUTES.toMillis(10);
protected final UUID uniqueId;
@@ -35,7 +35,7 @@ protected Hologram(@Nonnull UUID uniqueId) {
}
public abstract void setText(@Nullable String text);
- public abstract Class getEntityType();
+ public abstract Class extends Entity> getEntityType();
/**
* @return Whether the associated {@link Entity} has despawned.
@@ -64,7 +64,7 @@ public boolean hasExpired() {
* @return The {@link Entity} or null.
*/
@Nullable
- public E getEntity() {
+ public Entity getEntity() {
Entity entity = Bukkit.getEntity(uniqueId);
if (getEntityType().isInstance(entity) && entity.isValid()) {
this.lastAccess = System.currentTimeMillis();
@@ -76,7 +76,7 @@ public E getEntity() {
}
public void teleport(Location location) {
- E getEntity = getEntity();
+ Entity getEntity = getEntity();
if (getEntity != null) {
getEntity.teleport(location);
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java
index f9307859c5..98e49db942 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/HologramsService.java
@@ -19,7 +19,7 @@
import org.bukkit.Server;
import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.Entity;
-import org.bukkit.entity.TextDisplay;
+import org.bukkit.entity.EntityType;
import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector;
@@ -42,7 +42,7 @@ public class HologramsService {
private final Plugin plugin;
private final NamespacedKey key;
- private final Map> cache = new HashMap<>();
+ private final Map cache = new HashMap<>();
protected boolean started = false;
public HologramsService(@Nonnull Plugin plugin) {
@@ -98,12 +98,12 @@ private void purge() {
* @return The existing (or newly created) hologram
*/
@Nullable
- private Hologram> getHologram(@Nonnull Location loc, boolean createIfNoneExists) {
+ private Hologram getHologram(@Nonnull Location loc, boolean createIfNoneExists) {
Validate.notNull(loc, "Location cannot be null");
Validate.notNull(loc.getWorld(), "The Location's World cannot be null");
BlockPosition position = new BlockPosition(loc);
- Hologram> hologram = cache.get(position);
+ Hologram hologram = cache.get(position);
// Check if the Hologram was cached and still exists
if (hologram != null && !hologram.hasDespawned()) {
@@ -137,8 +137,8 @@ private boolean hasHologramData(Entity entity, BlockPosition position) {
}
/**
- * This checks if a given {@link Entity} is an {@link TextDisplay} or {@link ArmorStand}
- * and whether it has the correct attributes to be considered a {@link Hologram}.
+ * This checks if a given {@link Entity} is an is the right type of entity
+ * with the right properties to be a {@link Hologram}.
*
* @param entity
* The {@link Entity} to check
@@ -152,8 +152,8 @@ private boolean isHologram(@Nonnull Entity entity, BlockPosition position) {
&& armorStand.isSilent()
&& !armorStand.hasGravity()
&& hasHologramData(armorStand, position);
- } else if (entity instanceof TextDisplay textDisplay) {
- return hasHologramData(textDisplay, position);
+ } else if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_19_4) && entity.getType() == EntityType.TEXT_DISPLAY) {
+ return hasHologramData(entity, position);
}
return false;
}
@@ -169,8 +169,11 @@ private boolean isHologram(@Nonnull Entity entity, BlockPosition position) {
* @return The {@link Hologram}
*/
@ParametersAreNonnullByDefault
- private @Nullable Hologram> getAsHologram(Entity entity, BlockPosition position) {
- Hologram> hologram = TextDisplayHologram.of(entity, position);
+ private @Nullable Hologram getAsHologram(Entity entity, BlockPosition position) {
+ Hologram hologram = null;
+ if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_19_4)) {
+ hologram = TextDisplayHologram.of(entity, position);
+ }
if (hologram == null) {
hologram = ArmorStandHologram.of(entity, position);
}
@@ -188,7 +191,7 @@ private boolean isHologram(@Nonnull Entity entity, BlockPosition position) {
* @param consumer
* The callback to run
*/
- private void updateHologram(@Nonnull Location loc, @Nonnull Consumer> consumer) {
+ private void updateHologram(@Nonnull Location loc, @Nonnull Consumer consumer) {
Validate.notNull(loc, "Location must not be null");
Validate.notNull(consumer, "Callbacks must not be null");
if (!Bukkit.isPrimaryThread()) {
@@ -197,7 +200,7 @@ private void updateHologram(@Nonnull Location loc, @Nonnull Consumer
}
try {
- Hologram> hologram = getHologram(loc, true);
+ Hologram hologram = getHologram(loc, true);
if (hologram != null) {
consumer.accept(hologram);
}
@@ -253,7 +256,7 @@ public boolean removeHologram(@Nonnull Location location) {
}
try {
- Hologram> hologram = getHologram(location, false);
+ Hologram hologram = getHologram(location, false);
if (hologram == null) {
return false;
}
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/TextDisplayHologram.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/TextDisplayHologram.java
index 15baf23a68..7b7e691e11 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/TextDisplayHologram.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/holograms/TextDisplayHologram.java
@@ -11,7 +11,7 @@
import javax.annotation.Nullable;
import java.util.Objects;
-public class TextDisplayHologram extends Hologram {
+public class TextDisplayHologram extends Hologram {
private TextDisplayHologram(@Nonnull TextDisplay textDisplay) {
super(textDisplay.getUniqueId());
}
@@ -23,8 +23,8 @@ public void setText(@Nullable String text) {
return;
}
- TextDisplay textDisplay = getEntity();
- if (textDisplay != null) {
+ Entity entity = getEntity();
+ if (entity instanceof TextDisplay textDisplay) {
textDisplay.setText(text);
}
}
From c3d81e335e25053175594a5b18943c33549f0eb2 Mon Sep 17 00:00:00 2001
From: JustAHuman-xD <65748158+JustAHuman-xD@users.noreply.github.com>
Date: Sat, 2 Nov 2024 09:26:19 -0500
Subject: [PATCH 6/6] fix tests
---
.../slimefun4/api/MinecraftVersion.java | 2 +-
src/test/resources/biomes/1.19.4.json | 65 +++++++++++++++++++
2 files changed, 66 insertions(+), 1 deletion(-)
create mode 100644 src/test/resources/biomes/1.19.4.json
diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java
index d02a94e229..c1f623e7a5 100644
--- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java
+++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/MinecraftVersion.java
@@ -47,7 +47,7 @@ public enum MinecraftVersion {
* This constant represents Minecraft (Java Edition) Version 1.19.4
* This minor update added display entities
*/
- MINECRAFT_1_19_4(19, 4, "1.19.4+"),
+ MINECRAFT_1_19_4(19, 4, "1.19.4"),
/**
* This constant represents Minecraft (Java Edition) Version 1.20
diff --git a/src/test/resources/biomes/1.19.4.json b/src/test/resources/biomes/1.19.4.json
new file mode 100644
index 0000000000..65022a47a0
--- /dev/null
+++ b/src/test/resources/biomes/1.19.4.json
@@ -0,0 +1,65 @@
+[
+ "minecraft:ocean",
+ "minecraft:plains",
+ "minecraft:desert",
+ "minecraft:windswept_hills",
+ "minecraft:forest",
+ "minecraft:taiga",
+ "minecraft:swamp",
+ "minecraft:mangrove_swamp",
+ "minecraft:river",
+ "minecraft:nether_wastes",
+ "minecraft:the_end",
+ "minecraft:frozen_ocean",
+ "minecraft:frozen_river",
+ "minecraft:snowy_plains",
+ "minecraft:mushroom_fields",
+ "minecraft:beach",
+ "minecraft:jungle",
+ "minecraft:sparse_jungle",
+ "minecraft:deep_ocean",
+ "minecraft:stony_shore",
+ "minecraft:snowy_beach",
+ "minecraft:birch_forest",
+ "minecraft:dark_forest",
+ "minecraft:snowy_taiga",
+ "minecraft:old_growth_pine_taiga",
+ "minecraft:windswept_forest",
+ "minecraft:savanna",
+ "minecraft:savanna_plateau",
+ "minecraft:badlands",
+ "minecraft:wooded_badlands",
+ "minecraft:small_end_islands",
+ "minecraft:end_midlands",
+ "minecraft:end_highlands",
+ "minecraft:end_barrens",
+ "minecraft:warm_ocean",
+ "minecraft:lukewarm_ocean",
+ "minecraft:cold_ocean",
+ "minecraft:deep_lukewarm_ocean",
+ "minecraft:deep_cold_ocean",
+ "minecraft:deep_frozen_ocean",
+ "minecraft:the_void",
+ "minecraft:sunflower_plains",
+ "minecraft:windswept_gravelly_hills",
+ "minecraft:flower_forest",
+ "minecraft:ice_spikes",
+ "minecraft:old_growth_birch_forest",
+ "minecraft:old_growth_spruce_taiga",
+ "minecraft:windswept_savanna",
+ "minecraft:eroded_badlands",
+ "minecraft:bamboo_jungle",
+ "minecraft:soul_sand_valley",
+ "minecraft:crimson_forest",
+ "minecraft:warped_forest",
+ "minecraft:basalt_deltas",
+ "minecraft:dripstone_caves",
+ "minecraft:lush_caves",
+ "minecraft:deep_dark",
+ "minecraft:meadow",
+ "minecraft:grove",
+ "minecraft:snowy_slopes",
+ "minecraft:frozen_peaks",
+ "minecraft:jagged_peaks",
+ "minecraft:stony_peaks"
+]
\ No newline at end of file