diff --git a/pom.xml b/pom.xml index 8960a94..0057aed 100644 --- a/pom.xml +++ b/pom.xml @@ -106,12 +106,13 @@ com.songoda SongodaCore - LATEST + 2.6.10 com.songoda UltimateStacker LATEST + provided com.songoda @@ -129,6 +130,7 @@ com.github.brcdev-minecraft shopgui-api 1.0.0 + provided com.songoda diff --git a/src/main/java/com/songoda/epicspawners/EpicSpawners.java b/src/main/java/com/songoda/epicspawners/EpicSpawners.java index bdff926..880012d 100644 --- a/src/main/java/com/songoda/epicspawners/EpicSpawners.java +++ b/src/main/java/com/songoda/epicspawners/EpicSpawners.java @@ -217,24 +217,39 @@ public class EpicSpawners extends SongodaPlugin { for (PlacedSpawner spawner : spawners) { if (spawner.getWorld() == null) continue; - updateHologram(spawner); + createHologram(spawner); } } public void clearHologram(PlacedSpawner spawner) { - HologramManager.removeHologram(spawner.getLocation()); + HologramManager.removeHologram(spawner.getHologramId()); + } + + public void createHologram(PlacedSpawner spawner) { + // are holograms enabled? + if (!Settings.SPAWNER_HOLOGRAMS.getBoolean() || !HologramManager.getManager().isEnabled()) return; + + // create the hologram + HologramManager.createHologram(spawner.getHologramId(), spawner.getLocation(), getHologramName(spawner)); } public void updateHologram(PlacedSpawner spawner) { // are holograms enabled? if (!Settings.SPAWNER_HOLOGRAMS.getBoolean() || !HologramManager.getManager().isEnabled()) return; - int stackSize = spawner.getStackSize(); if (spawner.getSpawnerStacks().isEmpty()) return; - String name = spawner.getFirstTier().getCompiledDisplayName(spawner.getSpawnerStacks().size() > 1, stackSize).trim(); + + // check if it is created + if (!HologramManager.isHologramLoaded(spawner.getHologramId())) return; // create the hologram - HologramManager.updateHologram(spawner.getLocation(), name); + HologramManager.updateHologram(spawner.getHologramId(), getHologramName(spawner)); + } + + public String getHologramName(PlacedSpawner spawner) { + int stackSize = spawner.getStackSize(); + if (spawner.getSpawnerStacks().isEmpty()) return null; + return spawner.getFirstTier().getCompiledDisplayName(spawner.getSpawnerStacks().size() > 1, stackSize).trim(); } public void processChange(Block block) { diff --git a/src/main/java/com/songoda/epicspawners/listeners/BlockListeners.java b/src/main/java/com/songoda/epicspawners/listeners/BlockListeners.java index 05e12e2..99a29e6 100644 --- a/src/main/java/com/songoda/epicspawners/listeners/BlockListeners.java +++ b/src/main/java/com/songoda/epicspawners/listeners/BlockListeners.java @@ -190,7 +190,7 @@ public class BlockListeners implements Listener { EpicSpawners.getInstance().getDataManager().createSpawner(spawner); plugin.processChange(block); - plugin.updateHologram(spawner); + plugin.createHologram(spawner); plugin.getAppearanceTask().updateDisplayItem(spawner, spawnerTier); return; } diff --git a/src/main/java/com/songoda/epicspawners/spawners/spawner/PlacedSpawner.java b/src/main/java/com/songoda/epicspawners/spawners/spawner/PlacedSpawner.java index 5f5993d..1f69152 100644 --- a/src/main/java/com/songoda/epicspawners/spawners/spawner/PlacedSpawner.java +++ b/src/main/java/com/songoda/epicspawners/spawners/spawner/PlacedSpawner.java @@ -41,6 +41,11 @@ import java.util.UUID; public class PlacedSpawner extends SSpawner { + // This is the unique identifier for this hologram. + // It is reset on every plugin load. + // Used for holograms. + private final UUID uniqueId = UUID.randomUUID(); + // Id for database use. private int id; @@ -489,6 +494,10 @@ public class PlacedSpawner extends SSpawner { return modified; } + public String getHologramId() { + return "EpicSpawners-" + uniqueId; + } + @Override public int hashCode() { int result = 31 * (location == null ? 0 : location.hashCode());