Skip to content

Commit

Permalink
Merge pull request #304 from BentoBoxWorld/develop
Browse files Browse the repository at this point in the history
Version 1.12.3
  • Loading branch information
tastybento authored Feb 25, 2023
2 parents ffc1a3e + db6da6e commit 3976383
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 34 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<!-- Do not change unless you want different name for local builds. -->
<build.number>-LOCAL</build.number>
<!-- This allows to change between versions. -->
<build.version>1.12.2</build.version>
<build.version>1.12.3</build.version>
<!-- SonarCloud -->
<sonar.projectKey>BentoBoxWorld_AOneBlock</sonar.projectKey>
<sonar.organization>bentobox-world</sonar.organization>
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/world/bentobox/aoneblock/AOneBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,19 @@ public void allLoaded() {

// Manage Old Holograms
if (useHolographicDisplays()) {
for (Island island : getIslands().getIslands()) {
getIslands().getIslands().stream()
.filter(i -> this.inWorld(i.getWorld()))
.forEach(island -> {
OneBlockIslands oneBlockIsland = getOneBlocksIsland(island);
String hololine = oneBlockIsland.getHologram();
Location center = island.getCenter();
if (hololine != null) {
if (!hololine.isEmpty()) {
final Hologram hologram = HologramsAPI.createHologram(BentoBox.getInstance(), center.add(0.5, 2.6, 0.5));
for (String line : hololine.split("\\n")) {
hologram.appendTextLine(ChatColor.translateAlternateColorCodes('&', line));
}
}
}
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public void incrementBlockNumber() {
/**
* @return the hologram Line
*/
@NonNull
public String getHologram() {
return hologram == null ? "" : hologram;
}
Expand Down
93 changes: 64 additions & 29 deletions src/main/java/world/bentobox/aoneblock/listeners/BlockListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import world.bentobox.aoneblock.oneblocks.OneBlocksManager;
import world.bentobox.aoneblock.oneblocks.Requirement;
import world.bentobox.bank.Bank;
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
import world.bentobox.bentobox.api.events.island.IslandCreatedEvent;
import world.bentobox.bentobox.api.events.island.IslandDeleteEvent;
import world.bentobox.bentobox.api.events.island.IslandResettedEvent;
Expand Down Expand Up @@ -174,6 +175,23 @@ public BlockListener(@NonNull AOneBlock addon) {
oneBlocksManager = addon.getOneBlockManager();
}

/**
* This cleans up the cache files in the database and removed old junk.
* This is to address a bug introduced 2 years ago that caused non AOneBlock islands
* to be stored in the AOneBlock database. This should be able to be
* removed in the future.
* @deprecated will be removed in the future
* @param e event
*/
@Deprecated(since = "1.12.3", forRemoval = true)
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void cleanCache(BentoBoxReadyEvent e) {
handler.loadObjects().forEach(i ->
addon.getIslandsManager().getIslandById(i.getUniqueId())
.filter(is -> !addon.inWorld(is.getWorld()) || is.isUnowned())
.ifPresent(is -> handler.deleteID(is.getUniqueId())));
}

/**
* Save the island cache
*/
Expand All @@ -182,9 +200,9 @@ public void saveCache() {
}


// ---------------------------------------------------------------------
// Section: Listeners
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Section: Listeners
// ---------------------------------------------------------------------


@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
Expand Down Expand Up @@ -290,8 +308,8 @@ public void onItemStackSpawn(EntitySpawnEvent event)
Location location = event.getLocation();

Optional<Island> optionalIsland = this.addon.getIslands().
getIslandAt(location).
filter(island -> location.getBlock().getLocation().equals(island.getCenter()));
getIslandAt(location).
filter(island -> location.getBlock().getLocation().equals(island.getCenter()));

if (optionalIsland.isPresent())
{
Expand All @@ -302,9 +320,9 @@ public void onItemStackSpawn(EntitySpawnEvent event)
}


// ---------------------------------------------------------------------
// Section: Processing methods
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Section: Processing methods
// ---------------------------------------------------------------------


private void setUp(@NonNull Island island) {
Expand Down Expand Up @@ -488,24 +506,34 @@ private void playWarning(@NonNull OneBlockIslands is, @NonNull Block block) {
* @return true if this is a new phase, false if not
*/
private boolean checkPhase(@Nullable Player player, @NonNull Island i, @NonNull OneBlockIslands is, @NonNull OneBlockPhase phase) {
// Handle NPCs
User user;
if (player == null || player.hasMetadata("NPC")) {
// Default to the owner
user = addon.getPlayers().getUser(i.getOwner());
} else {
user = User.getInstance(player);
}

String phaseName = phase.getPhaseName() == null ? "" : phase.getPhaseName();
if (!is.getPhaseName().equalsIgnoreCase(phaseName)) {
// Run previous phase end commands
oneBlocksManager.getPhase(is.getPhaseName()).ifPresent(oldPhase -> {
String oldPhaseName = oldPhase.getPhaseName() == null ? "" : oldPhase.getPhaseName();
Util.runCommands(User.getInstance(player),
Util.runCommands(user,
replacePlaceholders(player, oldPhaseName, phase.getBlockNumber(), i, oldPhase.getEndCommands()),
"Commands run for end of " + oldPhaseName);
});
// Set the phase name
is.setPhaseName(phaseName);
if (player != null) {
player.sendTitle(phaseName, null, -1, -1, -1);
// Run phase start commands
Util.runCommands(User.getInstance(player),
replacePlaceholders(player, phaseName, phase.getBlockNumber(), i, phase.getStartCommands()),
"Commands run for start of " + phaseName);
if (user.isPlayer() && user.isOnline() && addon.inWorld(user.getWorld())) {
user.getPlayer().sendTitle(phaseName, null, -1, -1, -1);
}
// Run phase start commands
Util.runCommands(user,
replacePlaceholders(player, phaseName, phase.getBlockNumber(), i, phase.getStartCommands()),
"Commands run for start of " + phaseName);

saveIsland(i);
return true;
}
Expand Down Expand Up @@ -644,7 +672,7 @@ private void makeSpace(@NonNull Entity entity, @NonNull Location spawnLocation)
// Make space for entity based on the entity's size
final BoundingBox boundingBox = entity.getBoundingBox();
final boolean isWaterProtected = this.addon.getSettings().isWaterMobProtection() &&
WATER_ENTITIES.contains(entity.getType());
WATER_ENTITIES.contains(entity.getType());

for (double y = boundingBox.getMinY(); y <= Math.min(boundingBox.getMaxY(), world.getMaxHeight()); y++)
{
Expand Down Expand Up @@ -673,9 +701,9 @@ private void makeSpace(@NonNull Entity entity, @NonNull Location spawnLocation)
for (double z = boundingBox.getMinZ() - 0.5; z < boundingBox.getMaxZ() + 0.5; z++)
{
block = world.getBlockAt(new Location(world,
x,
y,
z));
x,
y,
z));

// Check if block should be marked.
this.checkBlock(block, boundingBox, isWaterProtected, airBlocks, waterBlocks);
Expand All @@ -688,9 +716,9 @@ else if (boundingBox.getWidthX() > 1)
for (double x = boundingBox.getMinX() - 0.5; x < boundingBox.getMaxX() + 0.5; x++)
{
block = world.getBlockAt(new Location(world,
x,
y,
spawnLocation.getZ()));
x,
y,
spawnLocation.getZ()));

// Check if block should be marked.
this.checkBlock(block, boundingBox, isWaterProtected, airBlocks, waterBlocks);
Expand All @@ -702,9 +730,9 @@ else if (boundingBox.getWidthZ() > 1)
for (double z = boundingBox.getMinZ() - 0.5; z < boundingBox.getMaxZ() + 0.5; z++)
{
block = world.getBlockAt(new Location(world,
spawnLocation.getX(),
y,
z));
spawnLocation.getX(),
y,
z));

// Check if block should be marked.
this.checkBlock(block, boundingBox, isWaterProtected, airBlocks, waterBlocks);
Expand Down Expand Up @@ -749,10 +777,10 @@ else if (boundingBox.getWidthZ() > 1)
* @param waterBlocks List of water blocks.
*/
private void checkBlock(Block block,
BoundingBox boundingBox,
boolean isWaterEntity,
List<Block> airBlocks,
List<Block> waterBlocks)
BoundingBox boundingBox,
boolean isWaterEntity,
List<Block> airBlocks,
List<Block> waterBlocks)
{
// Check if block should be marked for destroying.
if (block.getBoundingBox().overlaps(boundingBox))
Expand Down Expand Up @@ -815,6 +843,13 @@ public OneBlockIslands getIsland(@NonNull Island i) {
return cache.containsKey(i.getUniqueId()) ? cache.get(i.getUniqueId()) : loadIsland(i.getUniqueId());
}

/**
* Get all the OneBlockIslands from the Database
* @return list of oneblock islands
*/
public List<OneBlockIslands> getAllIslands() {
return handler.loadObjects();
}

@NonNull
private OneBlockIslands loadIsland(@NonNull String uniqueId) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/phases/12000_goto_0.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
'11000':
'12000':
gotoBlock: 0

0 comments on commit 3976383

Please sign in to comment.