Skip to content

Commit 2f6af5a

Browse files
authored
Merge pull request #409 from BentoBoxWorld/develop
Remove holograms even if they are not cached
2 parents 27d8b29 + 8ae0b83 commit 2f6af5a

File tree

2 files changed

+59
-42
lines changed

2 files changed

+59
-42
lines changed

src/main/java/world/bentobox/aoneblock/dataobjects/OneBlockIslands.java

+41-41
Original file line numberDiff line numberDiff line change
@@ -57,59 +57,59 @@ public class OneBlockIslands implements DataObject {
5757
*/
5858
@NonNull
5959
public String getPhaseName() {
60-
return phaseName == null ? "" : phaseName;
60+
return phaseName == null ? "" : phaseName;
6161
}
6262

6363
/**
6464
* @param phaseName the phaseName to set
6565
*/
6666
public void setPhaseName(String phaseName) {
67-
this.phaseName = phaseName;
67+
this.phaseName = phaseName;
6868
}
6969

7070
public OneBlockIslands(String uniqueId) {
71-
this.uniqueId = uniqueId;
71+
this.uniqueId = uniqueId;
7272
}
7373

7474
/**
7575
* @return the blockNumber
7676
*/
7777
public int getBlockNumber() {
78-
return blockNumber;
78+
return blockNumber;
7979
}
8080

8181
/**
8282
* @param blockNumber the blockNumber to set
8383
*/
8484
public void setBlockNumber(int blockNumber) {
85-
this.blockNumber = blockNumber;
85+
this.blockNumber = blockNumber;
8686
}
8787

8888
/**
8989
* Increments the block number
9090
*/
9191
public void incrementBlockNumber() {
92-
// Ensure that lifetime is always at least blockNumber
93-
if (this.lifetime < this.blockNumber) {
94-
this.lifetime = this.blockNumber;
95-
}
96-
this.blockNumber++;
97-
this.lifetime++;
92+
// Ensure that lifetime is always at least blockNumber
93+
if (this.lifetime < this.blockNumber) {
94+
this.lifetime = this.blockNumber;
95+
}
96+
this.blockNumber++;
97+
this.lifetime++;
9898
}
9999

100100
/**
101101
* @return the hologram Line
102102
*/
103103
@NonNull
104104
public String getHologram() {
105-
return hologram == null ? "" : hologram;
105+
return hologram == null ? "" : hologram;
106106
}
107107

108108
/**
109109
* @param hologramLine Hologram line
110110
*/
111111
public void setHologram(String hologramLine) {
112-
this.hologram = hologramLine;
112+
this.hologram = hologramLine;
113113
}
114114

115115
/*
@@ -119,7 +119,7 @@ public void setHologram(String hologramLine) {
119119
*/
120120
@Override
121121
public String getUniqueId() {
122-
return uniqueId;
122+
return uniqueId;
123123
}
124124

125125
/*
@@ -131,16 +131,16 @@ public String getUniqueId() {
131131
*/
132132
@Override
133133
public void setUniqueId(String uniqueId) {
134-
this.uniqueId = uniqueId;
134+
this.uniqueId = uniqueId;
135135
}
136136

137137
/**
138138
* @return the queue
139139
*/
140140
public Queue<OneBlockObject> getQueue() {
141-
if (queue == null)
142-
queue = new LinkedList<>();
143-
return queue;
141+
if (queue == null)
142+
queue = new LinkedList<>();
143+
return queue;
144144
}
145145

146146
/**
@@ -150,16 +150,16 @@ public Queue<OneBlockObject> getQueue() {
150150
* @return list of upcoming mobs
151151
*/
152152
public List<EntityType> getNearestMob(int i) {
153-
return getQueue().stream().limit(i).filter(obo ->
154-
// Include OneBlockObjects that are Entity, or custom block of type
155-
// MobCustomBlock
156-
obo.isEntity() || (obo.isCustomBlock() && obo.getCustomBlock() instanceof MobCustomBlock)).map(obo -> {
157-
if (obo.isCustomBlock() && obo.getCustomBlock() instanceof MobCustomBlock mb) {
158-
return mb.getMob();
159-
}
153+
return getQueue().stream().limit(i).filter(obo ->
154+
// Include OneBlockObjects that are Entity, or custom block of type
155+
// MobCustomBlock
156+
obo.isEntity() || (obo.isCustomBlock() && obo.getCustomBlock() instanceof MobCustomBlock)).map(obo -> {
157+
if (obo.isCustomBlock() && obo.getCustomBlock() instanceof MobCustomBlock mb) {
158+
return mb.getMob();
159+
}
160160

161-
return obo.getEntityType();
162-
}).toList();
161+
return obo.getEntityType();
162+
}).toList();
163163
}
164164

165165
/**
@@ -168,7 +168,7 @@ public List<EntityType> getNearestMob(int i) {
168168
* @param nextBlock the OneBlockObject to be added
169169
*/
170170
public void add(OneBlockObject nextBlock) {
171-
getQueue().add(nextBlock);
171+
getQueue().add(nextBlock);
172172
}
173173

174174
/**
@@ -182,49 +182,49 @@ public void add(OneBlockObject nextBlock) {
182182
* empty.
183183
*/
184184
public OneBlockObject pollAndAdd(OneBlockObject toAdd) {
185-
getQueue();
186-
OneBlockObject b = queue.poll();
187-
queue.add(toAdd);
188-
return b;
185+
getQueue();
186+
OneBlockObject b = queue.poll();
187+
queue.add(toAdd);
188+
return b;
189189
}
190190

191191
/**
192192
* Clear the look ahead queue
193193
*/
194194
public void clearQueue() {
195-
getQueue().clear();
195+
getQueue().clear();
196196
}
197197

198198
/**
199199
* @return the lifetime number of blocks broken not including the current block
200200
* count
201201
*/
202202
public long getLifetime() {
203-
// Ensure that lifetime is always at least blockNumber
204-
if (this.lifetime < this.blockNumber) {
205-
this.lifetime = this.blockNumber;
206-
}
207-
return lifetime;
203+
// Ensure that lifetime is always at least blockNumber
204+
if (this.lifetime < this.blockNumber) {
205+
this.lifetime = this.blockNumber;
206+
}
207+
return lifetime;
208208
}
209209

210210
/**
211211
* @param lifetime lifetime number of blocks broken to set
212212
*/
213213
public void setLifetime(long lifetime) {
214-
this.lifetime = lifetime;
214+
this.lifetime = lifetime;
215215
}
216216

217217
/**
218218
* @return Timestamp of last phase change
219219
*/
220220
public long getLastPhaseChangeTime() {
221-
return this.lastPhaseChangeTime;
221+
return this.lastPhaseChangeTime;
222222
}
223223

224224
/**
225225
* @param lastPhaseChangeTime Timestamp of last phase change
226226
*/
227227
public void setLastPhaseChangeTime(long lastPhaseChangeTime) {
228-
this.lastPhaseChangeTime = lastPhaseChangeTime;
228+
this.lastPhaseChangeTime = lastPhaseChangeTime;
229229
}
230230
}

src/main/java/world/bentobox/aoneblock/listeners/HoloListener.java

+18-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import org.bukkit.Location;
1010
import org.bukkit.World;
1111
import org.bukkit.entity.Display.Billboard;
12+
import org.bukkit.entity.Entity;
13+
import org.bukkit.entity.EntityType;
1214
import org.bukkit.entity.TextDisplay;
1315
import org.bukkit.event.EventHandler;
1416
import org.bukkit.event.EventPriority;
@@ -99,7 +101,7 @@ private void updateLines(Island island, OneBlockIslands oneBlockIsland) {
99101
String holoLine = oneBlockIsland.getHologram();
100102

101103
// Clear hologram if empty
102-
if (holoLine.isEmpty() && optionalHologram.isPresent()) {
104+
if (holoLine.isBlank() && optionalHologram.isPresent()) {
103105
clearIfInitialized(optionalHologram.get());
104106
return;
105107
}
@@ -140,6 +142,21 @@ private void deleteHologram(@NonNull Island island) {
140142
if (hologram != null) {
141143
clearIfInitialized(hologram);
142144
}
145+
// Clear any residual ones that are not cached for some reason
146+
clearTextDisplayNearBlock(island);
147+
}
148+
149+
private void clearTextDisplayNearBlock(Island island) {
150+
World world = island.getWorld();
151+
if (world == null)
152+
return;
153+
Location pos = island.getCenter().clone().add(parseVector(addon.getSettings().getOffset()));
154+
// Search for entities in a small radius (e.g., 1 block around)
155+
for (Entity entity : world.getNearbyEntities(pos, 1, 1, 1)) {
156+
if (entity.getType() == EntityType.TEXT_DISPLAY) {
157+
((TextDisplay) entity).remove();
158+
}
159+
}
143160
}
144161

145162
protected void setUp(@NonNull Island island, @NonNull OneBlockIslands is, boolean newIsland) {

0 commit comments

Comments
 (0)