Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,59 +57,59 @@ 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++;
}

/**
* @return the hologram Line
*/
@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;
}

/*
Expand All @@ -119,7 +119,7 @@ public void setHologram(String hologramLine) {
*/
@Override
public String getUniqueId() {
return uniqueId;
return uniqueId;
}

/*
Expand All @@ -131,16 +131,16 @@ public String getUniqueId() {
*/
@Override
public void setUniqueId(String uniqueId) {
this.uniqueId = uniqueId;
this.uniqueId = uniqueId;
}

/**
* @return the queue
*/
public Queue<OneBlockObject> getQueue() {
if (queue == null)
queue = new LinkedList<>();
return queue;
if (queue == null)
queue = new LinkedList<>();
return queue;
}

/**
Expand All @@ -150,16 +150,16 @@ public Queue<OneBlockObject> getQueue() {
* @return list of upcoming mobs
*/
public List<EntityType> 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();
}

/**
Expand All @@ -168,7 +168,7 @@ public List<EntityType> getNearestMob(int i) {
* @param nextBlock the OneBlockObject to be added
*/
public void add(OneBlockObject nextBlock) {
getQueue().add(nextBlock);
getQueue().add(nextBlock);
}

/**
Expand All @@ -182,49 +182,49 @@ 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();
}

/**
* @return the lifetime number of blocks broken not including the current block
* 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
Loading