Skip to content

Commit 3976383

Browse files
authored
Merge pull request #304 from BentoBoxWorld/develop
Version 1.12.3
2 parents ffc1a3e + db6da6e commit 3976383

File tree

5 files changed

+72
-34
lines changed

5 files changed

+72
-34
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<!-- Do not change unless you want different name for local builds. -->
6868
<build.number>-LOCAL</build.number>
6969
<!-- This allows to change between versions. -->
70-
<build.version>1.12.2</build.version>
70+
<build.version>1.12.3</build.version>
7171
<!-- SonarCloud -->
7272
<sonar.projectKey>BentoBoxWorld_AOneBlock</sonar.projectKey>
7373
<sonar.organization>bentobox-world</sonar.organization>

src/main/java/world/bentobox/aoneblock/AOneBlock.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,19 @@ public void allLoaded() {
264264

265265
// Manage Old Holograms
266266
if (useHolographicDisplays()) {
267-
for (Island island : getIslands().getIslands()) {
267+
getIslands().getIslands().stream()
268+
.filter(i -> this.inWorld(i.getWorld()))
269+
.forEach(island -> {
268270
OneBlockIslands oneBlockIsland = getOneBlocksIsland(island);
269271
String hololine = oneBlockIsland.getHologram();
270272
Location center = island.getCenter();
271-
if (hololine != null) {
273+
if (!hololine.isEmpty()) {
272274
final Hologram hologram = HologramsAPI.createHologram(BentoBox.getInstance(), center.add(0.5, 2.6, 0.5));
273275
for (String line : hololine.split("\\n")) {
274276
hologram.appendTextLine(ChatColor.translateAlternateColorCodes('&', line));
275277
}
276278
}
277-
}
279+
});
278280
}
279281
}
280282

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

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public void incrementBlockNumber() {
9393
/**
9494
* @return the hologram Line
9595
*/
96+
@NonNull
9697
public String getHologram() {
9798
return hologram == null ? "" : hologram;
9899
}

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

+64-29
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import world.bentobox.aoneblock.oneblocks.OneBlocksManager;
5858
import world.bentobox.aoneblock.oneblocks.Requirement;
5959
import world.bentobox.bank.Bank;
60+
import world.bentobox.bentobox.api.events.BentoBoxReadyEvent;
6061
import world.bentobox.bentobox.api.events.island.IslandCreatedEvent;
6162
import world.bentobox.bentobox.api.events.island.IslandDeleteEvent;
6263
import world.bentobox.bentobox.api.events.island.IslandResettedEvent;
@@ -174,6 +175,23 @@ public BlockListener(@NonNull AOneBlock addon) {
174175
oneBlocksManager = addon.getOneBlockManager();
175176
}
176177

178+
/**
179+
* This cleans up the cache files in the database and removed old junk.
180+
* This is to address a bug introduced 2 years ago that caused non AOneBlock islands
181+
* to be stored in the AOneBlock database. This should be able to be
182+
* removed in the future.
183+
* @deprecated will be removed in the future
184+
* @param e event
185+
*/
186+
@Deprecated(since = "1.12.3", forRemoval = true)
187+
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
188+
private void cleanCache(BentoBoxReadyEvent e) {
189+
handler.loadObjects().forEach(i ->
190+
addon.getIslandsManager().getIslandById(i.getUniqueId())
191+
.filter(is -> !addon.inWorld(is.getWorld()) || is.isUnowned())
192+
.ifPresent(is -> handler.deleteID(is.getUniqueId())));
193+
}
194+
177195
/**
178196
* Save the island cache
179197
*/
@@ -182,9 +200,9 @@ public void saveCache() {
182200
}
183201

184202

185-
// ---------------------------------------------------------------------
186-
// Section: Listeners
187-
// ---------------------------------------------------------------------
203+
// ---------------------------------------------------------------------
204+
// Section: Listeners
205+
// ---------------------------------------------------------------------
188206

189207

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

292310
Optional<Island> optionalIsland = this.addon.getIslands().
293-
getIslandAt(location).
294-
filter(island -> location.getBlock().getLocation().equals(island.getCenter()));
311+
getIslandAt(location).
312+
filter(island -> location.getBlock().getLocation().equals(island.getCenter()));
295313

296314
if (optionalIsland.isPresent())
297315
{
@@ -302,9 +320,9 @@ public void onItemStackSpawn(EntitySpawnEvent event)
302320
}
303321

304322

305-
// ---------------------------------------------------------------------
306-
// Section: Processing methods
307-
// ---------------------------------------------------------------------
323+
// ---------------------------------------------------------------------
324+
// Section: Processing methods
325+
// ---------------------------------------------------------------------
308326

309327

310328
private void setUp(@NonNull Island island) {
@@ -488,24 +506,34 @@ private void playWarning(@NonNull OneBlockIslands is, @NonNull Block block) {
488506
* @return true if this is a new phase, false if not
489507
*/
490508
private boolean checkPhase(@Nullable Player player, @NonNull Island i, @NonNull OneBlockIslands is, @NonNull OneBlockPhase phase) {
509+
// Handle NPCs
510+
User user;
511+
if (player == null || player.hasMetadata("NPC")) {
512+
// Default to the owner
513+
user = addon.getPlayers().getUser(i.getOwner());
514+
} else {
515+
user = User.getInstance(player);
516+
}
517+
491518
String phaseName = phase.getPhaseName() == null ? "" : phase.getPhaseName();
492519
if (!is.getPhaseName().equalsIgnoreCase(phaseName)) {
493520
// Run previous phase end commands
494521
oneBlocksManager.getPhase(is.getPhaseName()).ifPresent(oldPhase -> {
495522
String oldPhaseName = oldPhase.getPhaseName() == null ? "" : oldPhase.getPhaseName();
496-
Util.runCommands(User.getInstance(player),
523+
Util.runCommands(user,
497524
replacePlaceholders(player, oldPhaseName, phase.getBlockNumber(), i, oldPhase.getEndCommands()),
498525
"Commands run for end of " + oldPhaseName);
499526
});
500527
// Set the phase name
501528
is.setPhaseName(phaseName);
502-
if (player != null) {
503-
player.sendTitle(phaseName, null, -1, -1, -1);
504-
// Run phase start commands
505-
Util.runCommands(User.getInstance(player),
506-
replacePlaceholders(player, phaseName, phase.getBlockNumber(), i, phase.getStartCommands()),
507-
"Commands run for start of " + phaseName);
529+
if (user.isPlayer() && user.isOnline() && addon.inWorld(user.getWorld())) {
530+
user.getPlayer().sendTitle(phaseName, null, -1, -1, -1);
508531
}
532+
// Run phase start commands
533+
Util.runCommands(user,
534+
replacePlaceholders(player, phaseName, phase.getBlockNumber(), i, phase.getStartCommands()),
535+
"Commands run for start of " + phaseName);
536+
509537
saveIsland(i);
510538
return true;
511539
}
@@ -644,7 +672,7 @@ private void makeSpace(@NonNull Entity entity, @NonNull Location spawnLocation)
644672
// Make space for entity based on the entity's size
645673
final BoundingBox boundingBox = entity.getBoundingBox();
646674
final boolean isWaterProtected = this.addon.getSettings().isWaterMobProtection() &&
647-
WATER_ENTITIES.contains(entity.getType());
675+
WATER_ENTITIES.contains(entity.getType());
648676

649677
for (double y = boundingBox.getMinY(); y <= Math.min(boundingBox.getMaxY(), world.getMaxHeight()); y++)
650678
{
@@ -673,9 +701,9 @@ private void makeSpace(@NonNull Entity entity, @NonNull Location spawnLocation)
673701
for (double z = boundingBox.getMinZ() - 0.5; z < boundingBox.getMaxZ() + 0.5; z++)
674702
{
675703
block = world.getBlockAt(new Location(world,
676-
x,
677-
y,
678-
z));
704+
x,
705+
y,
706+
z));
679707

680708
// Check if block should be marked.
681709
this.checkBlock(block, boundingBox, isWaterProtected, airBlocks, waterBlocks);
@@ -688,9 +716,9 @@ else if (boundingBox.getWidthX() > 1)
688716
for (double x = boundingBox.getMinX() - 0.5; x < boundingBox.getMaxX() + 0.5; x++)
689717
{
690718
block = world.getBlockAt(new Location(world,
691-
x,
692-
y,
693-
spawnLocation.getZ()));
719+
x,
720+
y,
721+
spawnLocation.getZ()));
694722

695723
// Check if block should be marked.
696724
this.checkBlock(block, boundingBox, isWaterProtected, airBlocks, waterBlocks);
@@ -702,9 +730,9 @@ else if (boundingBox.getWidthZ() > 1)
702730
for (double z = boundingBox.getMinZ() - 0.5; z < boundingBox.getMaxZ() + 0.5; z++)
703731
{
704732
block = world.getBlockAt(new Location(world,
705-
spawnLocation.getX(),
706-
y,
707-
z));
733+
spawnLocation.getX(),
734+
y,
735+
z));
708736

709737
// Check if block should be marked.
710738
this.checkBlock(block, boundingBox, isWaterProtected, airBlocks, waterBlocks);
@@ -749,10 +777,10 @@ else if (boundingBox.getWidthZ() > 1)
749777
* @param waterBlocks List of water blocks.
750778
*/
751779
private void checkBlock(Block block,
752-
BoundingBox boundingBox,
753-
boolean isWaterEntity,
754-
List<Block> airBlocks,
755-
List<Block> waterBlocks)
780+
BoundingBox boundingBox,
781+
boolean isWaterEntity,
782+
List<Block> airBlocks,
783+
List<Block> waterBlocks)
756784
{
757785
// Check if block should be marked for destroying.
758786
if (block.getBoundingBox().overlaps(boundingBox))
@@ -815,6 +843,13 @@ public OneBlockIslands getIsland(@NonNull Island i) {
815843
return cache.containsKey(i.getUniqueId()) ? cache.get(i.getUniqueId()) : loadIsland(i.getUniqueId());
816844
}
817845

846+
/**
847+
* Get all the OneBlockIslands from the Database
848+
* @return list of oneblock islands
849+
*/
850+
public List<OneBlockIslands> getAllIslands() {
851+
return handler.loadObjects();
852+
}
818853

819854
@NonNull
820855
private OneBlockIslands loadIsland(@NonNull String uniqueId) {
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
'11000':
1+
'12000':
22
gotoBlock: 0

0 commit comments

Comments
 (0)