Skip to content

Commit

Permalink
Don't allow claims to be made outside of worldborder (GriefPrevention…
Browse files Browse the repository at this point in the history
  • Loading branch information
QarthO authored Apr 28, 2024
1 parent f6388bd commit 14ce8e6
Showing 1 changed file with 34 additions and 6 deletions.
40 changes: 34 additions & 6 deletions src/main/java/me/ryanhamshire/GriefPrevention/DataStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,14 @@ synchronized public CreateClaimResult createClaim(World world, int x1, int x2, i
smally = sanitizeClaimDepth(parent, smally);
}

//claims can't be made outside the world border
final Location smallerBoundaryCorner = new Location(world, smallx, smally, smallz);
final Location greaterBoundaryCorner = new Location(world, bigx, bigy, bigz);
if(!world.getWorldBorder().isInside(smallerBoundaryCorner) || !world.getWorldBorder().isInside(greaterBoundaryCorner)){
result.succeeded = false;
return result;
}

//creative mode claims always go to bedrock
if (GriefPrevention.instance.config_claims_worldModes.get(world) == ClaimsMode.Creative)
{
Expand All @@ -923,8 +931,8 @@ synchronized public CreateClaimResult createClaim(World world, int x1, int x2, i

//create a new claim instance (but don't save it, yet)
Claim newClaim = new Claim(
new Location(world, smallx, smally, smallz),
new Location(world, bigx, bigy, bigz),
smallerBoundaryCorner,
greaterBoundaryCorner,
ownerID,
new ArrayList<>(),
new ArrayList<>(),
Expand Down Expand Up @@ -1159,8 +1167,19 @@ void resizeClaimWithChecks(Player player, PlayerData playerData, int newx1, int
if (playerData.claimResizing.parent == null)
{
//measure new claim, apply size rules
int newWidth = (Math.abs(newx1 - newx2) + 1);
int newHeight = (Math.abs(newz1 - newz2) + 1);
int newWidth;
int newHeight;
try
{
newWidth = Math.abs(Math.subtractExact(newx1, newx2)) + 1;
newHeight = Math.abs(Math.subtractExact(newz1, newz2)) + 1;
}
catch (ArithmeticException e)
{
GriefPrevention.sendMessage(player, TextMode.Err, Messages.ResizeClaimInsufficientArea, String.valueOf(GriefPrevention.instance.config_claims_minArea));
return;
}

boolean smaller = newWidth < playerData.claimResizing.getWidth() || newHeight < playerData.claimResizing.getHeight();

if (!player.hasPermission("griefprevention.adminclaims") && !playerData.claimResizing.isAdminClaim() && smaller)
Expand All @@ -1182,8 +1201,17 @@ void resizeClaimWithChecks(Player player, PlayerData playerData, int newx1, int
//make sure player has enough blocks to make up the difference
if (!playerData.claimResizing.isAdminClaim() && player.getName().equals(playerData.claimResizing.getOwnerName()))
{
int newArea = newWidth * newHeight;
int blocksRemainingAfter = playerData.getRemainingClaimBlocks() + playerData.claimResizing.getArea() - newArea;
int newArea;
int blocksRemainingAfter;
try
{
newArea = Math.multiplyExact(newWidth, newHeight);
blocksRemainingAfter = playerData.getRemainingClaimBlocks() + (playerData.claimResizing.getArea() - newArea);
}
catch (ArithmeticException e)
{
blocksRemainingAfter = -1;
}

if (blocksRemainingAfter < 0)
{
Expand Down

0 comments on commit 14ce8e6

Please sign in to comment.