Update to new hologram system.

This commit is contained in:
Fernando Pettinelli 2022-01-01 15:09:35 -03:00
parent 7c7bf2be91
commit c560b55722
4 changed files with 33 additions and 7 deletions

View File

@ -106,12 +106,13 @@
<dependency>
<groupId>com.songoda</groupId>
<artifactId>SongodaCore</artifactId>
<version>LATEST</version>
<version>2.6.10</version>
</dependency>
<dependency>
<groupId>com.songoda</groupId>
<artifactId>UltimateStacker</artifactId>
<version>LATEST</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.songoda</groupId>
@ -129,6 +130,7 @@
<groupId>com.github.brcdev-minecraft</groupId>
<artifactId>shopgui-api</artifactId>
<version>1.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.songoda</groupId>

View File

@ -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) {

View File

@ -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;
}

View File

@ -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());