fix: upstream missing Region#getBoundingBox() (#1908)

Use block change limit for //copy and //cut

(cherry picked from commit fd8dbdd7b7b8b561db98a45b4eae3810dedb1551)
This commit is contained in:
Hannes Greule 2022-08-19 13:41:24 +02:00 committed by GitHub
parent cc1b466a04
commit ab659eadde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 0 deletions

View File

@ -38,6 +38,7 @@ import com.google.common.collect.Lists;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissions;
@ -105,6 +106,20 @@ import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION;
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class) @CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
public class ClipboardCommands { public class ClipboardCommands {
/**
* Throws if the region would allocate a clipboard larger than the block change limit.
*
* @param region The region to check
* @param session The session
* @throws MaxChangedBlocksException if the volume exceeds the limit
*/
private void checkRegionBounds(Region region, LocalSession session) throws MaxChangedBlocksException {
int limit = session.getBlockChangeLimit();
if (region.getBoundingBox().getVolume() > limit) {
throw new MaxChangedBlocksException(limit);
}
}
@Command( @Command(
name = "/copy", name = "/copy",
aliases = "/cp", aliases = "/cp",

View File

@ -256,6 +256,11 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
return pos1.getMaximum(pos2); return pos1.getMaximum(pos2);
} }
@Override
public CuboidRegion getBoundingBox() {
return this;
}
@Override @Override
public int getMinimumY() { public int getMinimumY() {
return minY; return minY;

View File

@ -72,6 +72,15 @@ public interface Region extends Iterable<BlockVector3>, Cloneable, IBatchProcess
} }
//FAWE end //FAWE end
/**
* Get the bounding box of this region as a {@link CuboidRegion}.
*
* @return the bounding box
*/
default CuboidRegion getBoundingBox() {
return new CuboidRegion(getMinimumPoint(), getMaximumPoint());
}
/** /**
* Get the center point of a region. * Get the center point of a region.
* Note: Coordinates will not be integers * Note: Coordinates will not be integers