Skip to content

Commit

Permalink
Fix server crash when COOP player tried to complete ISLAND type chall…
Browse files Browse the repository at this point in the history
…enge (#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.
  • Loading branch information
BONNe authored and BuildTools committed Aug 28, 2019
1 parent 12dd740 commit 592a4c7
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/main/java/world/bentobox/challenges/tasks/TryToComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ else if (Util.getWorld(this.world) != Util.getWorld(this.user.getWorld()) ||
}
// 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;
Expand Down Expand Up @@ -845,8 +845,16 @@ private ChallengeResult checkSurrounding(int factor)
// 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))
{
Expand All @@ -866,17 +874,28 @@ private ChallengeResult checkSurrounding(int factor)

int range = island.getRange();

int islandMaxX = island.getMinX() + range * 2;
int islandMaxZ = island.getMinZ() + range * 2;
if (boundingBox.getMaxX() > island.getMaxX())
{
boundingBox.expand(BlockFace.WEST, Math.abs(boundingBox.getMaxX() - island.getMaxX()));
}

if (boundingBox.getMaxX() > islandMaxX)
if (boundingBox.getMaxZ() > island.getMinZ())
{
boundingBox.expand(BlockFace.WEST, Math.abs(boundingBox.getMaxX() - islandMaxX));
boundingBox.expand(BlockFace.SOUTH, Math.abs(boundingBox.getMaxZ() - island.getMinZ()));
}

if (boundingBox.getMaxZ() > islandMaxZ)
// 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)
{
boundingBox.expand(BlockFace.SOUTH, Math.abs(boundingBox.getMaxZ() - islandMaxZ));
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;
}
}

Expand Down

0 comments on commit 592a4c7

Please sign in to comment.