diff --git a/src/main/java/world/bentobox/aoneblock/dataobjects/OneBlockIslands.java b/src/main/java/world/bentobox/aoneblock/dataobjects/OneBlockIslands.java index c4d0c0e4..c8c7aef0 100644 --- a/src/main/java/world/bentobox/aoneblock/dataobjects/OneBlockIslands.java +++ b/src/main/java/world/bentobox/aoneblock/dataobjects/OneBlockIslands.java @@ -57,44 +57,44 @@ public class OneBlockIslands implements DataObject { */ @NonNull public String getPhaseName() { - return phaseName == null ? "" : phaseName; + return phaseName == null ? "" : phaseName; } /** * @param phaseName the phaseName to set */ public void setPhaseName(String phaseName) { - this.phaseName = phaseName; + this.phaseName = phaseName; } public OneBlockIslands(String uniqueId) { - this.uniqueId = uniqueId; + this.uniqueId = uniqueId; } /** * @return the blockNumber */ public int getBlockNumber() { - return blockNumber; + return blockNumber; } /** * @param blockNumber the blockNumber to set */ public void setBlockNumber(int blockNumber) { - this.blockNumber = blockNumber; + this.blockNumber = blockNumber; } /** * Increments the block number */ public void incrementBlockNumber() { - // Ensure that lifetime is always at least blockNumber - if (this.lifetime < this.blockNumber) { - this.lifetime = this.blockNumber; - } - this.blockNumber++; - this.lifetime++; + // Ensure that lifetime is always at least blockNumber + if (this.lifetime < this.blockNumber) { + this.lifetime = this.blockNumber; + } + this.blockNumber++; + this.lifetime++; } /** @@ -102,14 +102,14 @@ public void incrementBlockNumber() { */ @NonNull public String getHologram() { - return hologram == null ? "" : hologram; + return hologram == null ? "" : hologram; } /** * @param hologramLine Hologram line */ public void setHologram(String hologramLine) { - this.hologram = hologramLine; + this.hologram = hologramLine; } /* @@ -119,7 +119,7 @@ public void setHologram(String hologramLine) { */ @Override public String getUniqueId() { - return uniqueId; + return uniqueId; } /* @@ -131,16 +131,16 @@ public String getUniqueId() { */ @Override public void setUniqueId(String uniqueId) { - this.uniqueId = uniqueId; + this.uniqueId = uniqueId; } /** * @return the queue */ public Queue getQueue() { - if (queue == null) - queue = new LinkedList<>(); - return queue; + if (queue == null) + queue = new LinkedList<>(); + return queue; } /** @@ -150,16 +150,16 @@ public Queue getQueue() { * @return list of upcoming mobs */ public List getNearestMob(int i) { - return getQueue().stream().limit(i).filter(obo -> - // Include OneBlockObjects that are Entity, or custom block of type - // MobCustomBlock - obo.isEntity() || (obo.isCustomBlock() && obo.getCustomBlock() instanceof MobCustomBlock)).map(obo -> { - if (obo.isCustomBlock() && obo.getCustomBlock() instanceof MobCustomBlock mb) { - return mb.getMob(); - } + return getQueue().stream().limit(i).filter(obo -> + // Include OneBlockObjects that are Entity, or custom block of type + // MobCustomBlock + obo.isEntity() || (obo.isCustomBlock() && obo.getCustomBlock() instanceof MobCustomBlock)).map(obo -> { + if (obo.isCustomBlock() && obo.getCustomBlock() instanceof MobCustomBlock mb) { + return mb.getMob(); + } - return obo.getEntityType(); - }).toList(); + return obo.getEntityType(); + }).toList(); } /** @@ -168,7 +168,7 @@ public List getNearestMob(int i) { * @param nextBlock the OneBlockObject to be added */ public void add(OneBlockObject nextBlock) { - getQueue().add(nextBlock); + getQueue().add(nextBlock); } /** @@ -182,17 +182,17 @@ public void add(OneBlockObject nextBlock) { * empty. */ public OneBlockObject pollAndAdd(OneBlockObject toAdd) { - getQueue(); - OneBlockObject b = queue.poll(); - queue.add(toAdd); - return b; + getQueue(); + OneBlockObject b = queue.poll(); + queue.add(toAdd); + return b; } /** * Clear the look ahead queue */ public void clearQueue() { - getQueue().clear(); + getQueue().clear(); } /** @@ -200,31 +200,31 @@ public void clearQueue() { * count */ public long getLifetime() { - // Ensure that lifetime is always at least blockNumber - if (this.lifetime < this.blockNumber) { - this.lifetime = this.blockNumber; - } - return lifetime; + // Ensure that lifetime is always at least blockNumber + if (this.lifetime < this.blockNumber) { + this.lifetime = this.blockNumber; + } + return lifetime; } /** * @param lifetime lifetime number of blocks broken to set */ public void setLifetime(long lifetime) { - this.lifetime = lifetime; + this.lifetime = lifetime; } /** * @return Timestamp of last phase change */ public long getLastPhaseChangeTime() { - return this.lastPhaseChangeTime; + return this.lastPhaseChangeTime; } /** * @param lastPhaseChangeTime Timestamp of last phase change */ public void setLastPhaseChangeTime(long lastPhaseChangeTime) { - this.lastPhaseChangeTime = lastPhaseChangeTime; + this.lastPhaseChangeTime = lastPhaseChangeTime; } } diff --git a/src/main/java/world/bentobox/aoneblock/listeners/HoloListener.java b/src/main/java/world/bentobox/aoneblock/listeners/HoloListener.java index a343dce7..34b0560d 100644 --- a/src/main/java/world/bentobox/aoneblock/listeners/HoloListener.java +++ b/src/main/java/world/bentobox/aoneblock/listeners/HoloListener.java @@ -9,6 +9,8 @@ import org.bukkit.Location; import org.bukkit.World; import org.bukkit.entity.Display.Billboard; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; import org.bukkit.entity.TextDisplay; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -99,7 +101,7 @@ private void updateLines(Island island, OneBlockIslands oneBlockIsland) { String holoLine = oneBlockIsland.getHologram(); // Clear hologram if empty - if (holoLine.isEmpty() && optionalHologram.isPresent()) { + if (holoLine.isBlank() && optionalHologram.isPresent()) { clearIfInitialized(optionalHologram.get()); return; } @@ -140,6 +142,21 @@ private void deleteHologram(@NonNull Island island) { if (hologram != null) { clearIfInitialized(hologram); } + // Clear any residual ones that are not cached for some reason + clearTextDisplayNearBlock(island); + } + + private void clearTextDisplayNearBlock(Island island) { + World world = island.getWorld(); + if (world == null) + return; + Location pos = island.getCenter().clone().add(parseVector(addon.getSettings().getOffset())); + // Search for entities in a small radius (e.g., 1 block around) + for (Entity entity : world.getNearbyEntities(pos, 1, 1, 1)) { + if (entity.getType() == EntityType.TEXT_DISPLAY) { + ((TextDisplay) entity).remove(); + } + } } protected void setUp(@NonNull Island island, @NonNull OneBlockIslands is, boolean newIsland) {