Skip to content

Commit d44858f

Browse files
authored
Merge pull request #2746 from BentoBoxWorld/api_allow_range_mismatches
Add API to allow a Game Mode to bypass range checks
2 parents 54e4f6c + 6904a06 commit d44858f

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

src/main/java/world/bentobox/bentobox/api/addons/GameModeAddon.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,13 @@ public boolean isFixIslandCenter() {
190190
return true;
191191
}
192192

193+
/**
194+
* Indicates whether BentoBox should fail to run if island ranges in a Game Mode are different.
195+
* For some Game Modes, this is not an issue. Also disables console errors if islands cannot be made.
196+
* @return default is true
197+
* @since 3.8.2
198+
*/
199+
public boolean isEnforceEqualRanges() {
200+
return true;
201+
}
193202
}

src/main/java/world/bentobox/bentobox/managers/IslandsManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,6 +1302,7 @@ public void load() throws IOException {
13021302
}
13031303
// Check island distance and if incorrect stop BentoBox
13041304
else if (!plugin.getSettings().isOverrideSafetyCheck()
1305+
&& plugin.getIWM().getAddon(island.getWorld()).map(GameModeAddon::isEnforceEqualRanges).orElse(true)
13051306
&& island.getWorld() != null
13061307
&& plugin.getIWM().inWorld(island.getWorld())
13071308
&& island.getRange() != plugin.getIWM().getIslandDistance(island.getWorld())) {

src/main/java/world/bentobox/bentobox/managers/island/NewIsland.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ private void cleanUpUser(Location loc) {
298298
// Set protection range based on user's permission, if different from default
299299
island.setProtectionRange(user.getPermissionValue(
300300
plugin.getIWM().getAddon(island.getWorld()).map(GameModeAddon::getPermissionPrefix).orElse("")
301-
+ "island.range",
301+
+ "island.range",
302302
island.getProtectionRange()));
303303
}
304304

@@ -312,14 +312,18 @@ private Location makeNextIsland() throws IOException {
312312
// Use location strategy to find next available spot
313313
Location next = this.locationStrategy.getNextLocation(world, user);
314314
if (next == null) {
315-
plugin.logError("Failed to make island - no unoccupied spot found.");
316-
plugin.logError("If the world was imported, try multiple times until all unowned islands are known.");
315+
if (plugin.getIWM().getAddon(world).map(GameModeAddon::isEnforceEqualRanges).orElse(true)) {
316+
plugin.logError("Failed to make island - no unoccupied spot found.");
317+
plugin.logError("If the world was imported, try multiple times until all unowned islands are known.");
318+
}
317319
throw new IOException("commands.island.create.cannot-create-island");
318320
}
319321
// Add island to grid
320322
island = plugin.getIslands().createIsland(next, user.getUniqueId());
321323
if (island == null) {
322-
plugin.logError("Failed to make island! Island could not be added to the grid.");
324+
if (plugin.getIWM().getAddon(world).map(GameModeAddon::isEnforceEqualRanges).orElse(true)) {
325+
plugin.logError("Failed to make island! Island could not be added to the grid.");
326+
}
323327
throw new IOException("commands.island.create.unable-create-island");
324328
}
325329
return next;
@@ -359,8 +363,8 @@ private void tidyUp(Island oldIsland) {
359363

360364
// Fire exit event for plugins/addons
361365
IslandEvent.builder().involvedPlayer(user.getUniqueId())
362-
.reason(reason == Reason.RESET ? Reason.RESETTED : Reason.CREATED).island(island)
363-
.location(island.getCenter()).oldIsland(oldIsland).build();
366+
.reason(reason == Reason.RESET ? Reason.RESETTED : Reason.CREATED).island(island)
367+
.location(island.getCenter()).oldIsland(oldIsland).build();
364368

365369
}
366370
}

0 commit comments

Comments
 (0)