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.
This commit is contained in:
BONNe 2019-08-29 00:07:08 +03:00 committed by BuildTools
parent 12dd740959
commit 592a4c7310
1 changed files with 29 additions and 10 deletions

View File

@ -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;
}
}