From 592a4c7310001e764209319aa80620c53ef7d3cb Mon Sep 17 00:00:00 2001 From: BONNe Date: Thu, 29 Aug 2019 00:07:08 +0300 Subject: [PATCH] Fix server crash when COOP player tried to complete ISLAND type challenge (#174). The issue was that I used wrong command to check island owner. It is fixed. Also added 2 protective code, that prevents from trying to select large areas for block searching. --- .../challenges/tasks/TryToComplete.java | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java b/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java index 074dcc9..550e64a 100644 --- a/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java +++ b/src/main/java/world/bentobox/challenges/tasks/TryToComplete.java @@ -523,7 +523,7 @@ public class TryToComplete } // Player is not on island else if (ChallengesAddon.CHALLENGES_WORLD_PROTECTION.isSetForWorld(this.world) && - !this.addon.getIslands().userIsOnIsland(this.user.getWorld(), this.user)) + !this.addon.getIslands().locationIsOnIsland(this.user.getPlayer(), this.user.getLocation())) { this.user.sendMessage("challenges.errors.not-on-island"); result = EMPTY_RESULT; @@ -845,8 +845,16 @@ public class TryToComplete // Init location in player position. BoundingBox boundingBox = this.user.getPlayer().getBoundingBox().clone(); - // Expand position with search radius. - boundingBox.expand(this.challenge.getSearchRadius()); + // Expand position with search radius. Unless someone sets search radius larger than island + // range. In this situation use island range. + int distance = this.addon.getPlugin().getIWM().getIslandDistance(this.world); + + if (this.challenge.getSearchRadius() < distance + 1) + { + distance = this.challenge.getSearchRadius(); + } + + boundingBox.expand(distance); if (ChallengesAddon.CHALLENGES_WORLD_PROTECTION.isSetForWorld(this.world)) { @@ -866,17 +874,28 @@ public class TryToComplete int range = island.getRange(); - int islandMaxX = island.getMinX() + range * 2; - int islandMaxZ = island.getMinZ() + range * 2; - - if (boundingBox.getMaxX() > islandMaxX) + if (boundingBox.getMaxX() > island.getMaxX()) { - boundingBox.expand(BlockFace.WEST, Math.abs(boundingBox.getMaxX() - islandMaxX)); + boundingBox.expand(BlockFace.WEST, Math.abs(boundingBox.getMaxX() - island.getMaxX())); } - if (boundingBox.getMaxZ() > islandMaxZ) + if (boundingBox.getMaxZ() > island.getMinZ()) { - boundingBox.expand(BlockFace.SOUTH, Math.abs(boundingBox.getMaxZ() - islandMaxZ)); + boundingBox.expand(BlockFace.SOUTH, Math.abs(boundingBox.getMaxZ() - island.getMinZ())); + } + + // Protection code. Do not allow to select too large region for completing challenge. + if (boundingBox.getWidthX() > distance * 2 + 3 || + boundingBox.getWidthZ() > distance * 2 + 3 || + boundingBox.getHeight() > distance * 2 + 3) + { + this.addon.logError("BoundingBox is larger than SearchRadius. " + + " | Search Distance: " + this.challenge.getSearchRadius() + + " | Location: " + this.user.getLocation().toString() + + " | Center: " + island.getCenter().toString() + + " | Range: " + range); + + return EMPTY_RESULT; } }