Made a checkMaxBrushRadius method for centralized use.

This commit is contained in:
wizjany 2013-08-02 21:33:11 -04:00
parent bc39a913ea
commit d7324f6b13
4 changed files with 35 additions and 43 deletions

View File

@ -0,0 +1,10 @@
package com.sk89q.worldedit;
/**
*
* Thrown when a maximum radius for a brush is reached.
*
*/
public class MaxBrushRadiusException extends MaxRadiusException {
}

View File

@ -917,6 +917,18 @@ public class WorldEdit {
}
}
/**
* Checks to see if the specified brush radius is within bounds.
*
* @param radius
* @throws MaxBrushRadiusException
*/
public void checkMaxBrushRadius(double radius) throws MaxBrushRadiusException {
if (config.maxBrushRadius > 0 && radius > config.maxBrushRadius) {
throw new MaxBrushRadiusException();
}
}
/**
* Get a file relative to the defined working directory. If the specified
* path is absolute, then the working directory is not used.
@ -1445,6 +1457,8 @@ public class WorldEdit {
} catch (MaxChangedBlocksException e) {
player.printError("Max blocks changed in an operation reached ("
+ e.getBlockLimit() + ").");
} catch (MaxBrushRadiusException e) {
player.printError("Maximum allowed brush radius/height: " + config.maxBrushRadius);
} catch (MaxRadiusException e) {
player.printError("Maximum radius: " + config.maxRadius);
} catch (UnknownDirectionException e) {

View File

@ -77,11 +77,7 @@ public class BrushCommands {
LocalConfiguration config = we.getConfiguration();
double radius = args.argsLength() > 1 ? args.getDouble(1) : 2;
if (radius > config.maxBrushRadius) {
player.printError("Maximum allowed brush radius: "
+ config.maxBrushRadius);
return;
}
we.checkMaxBrushRadius(radius);
BrushTool tool = session.getBrushTool(player.getItemInHand());
Pattern fill = we.getBlockPattern(player, args.getString(0));
@ -116,18 +112,10 @@ public class BrushCommands {
LocalConfiguration config = we.getConfiguration();
double radius = args.argsLength() > 1 ? args.getDouble(1) : 2;
if (radius > config.maxBrushRadius) {
player.printError("Maximum allowed brush radius: "
+ config.maxBrushRadius);
return;
}
we.checkMaxBrushRadius(radius);
int height = args.argsLength() > 2 ? args.getInteger(2) : 1;
if (height > config.maxBrushRadius) {
player.printError("Maximum allowed brush radius/height: "
+ config.maxBrushRadius);
return;
}
we.checkMaxBrushRadius(height);
BrushTool tool = session.getBrushTool(player.getItemInHand());
Pattern fill = we.getBlockPattern(player, args.getString(0));
@ -170,13 +158,9 @@ public class BrushCommands {
Vector size = clipboard.getSize();
if (size.getBlockX() > config.maxBrushRadius
|| size.getBlockY() > config.maxBrushRadius
|| size.getBlockZ() > config.maxBrushRadius) {
player.printError("Maximum allowed brush radius/height: "
+ config.maxBrushRadius);
return;
}
we.checkMaxBrushRadius(size.getBlockX());
we.checkMaxBrushRadius(size.getBlockY());
we.checkMaxBrushRadius(size.getBlockZ());
BrushTool tool = session.getBrushTool(player.getItemInHand());
tool.setBrush(new ClipboardBrush(clipboard, args.hasFlag('a')), "worldedit.brush.clipboard");
@ -202,11 +186,7 @@ public class BrushCommands {
LocalConfiguration config = we.getConfiguration();
double radius = args.argsLength() > 0 ? args.getDouble(0) : 2;
if (radius > config.maxBrushRadius) {
player.printError("Maximum allowed brush radius: "
+ config.maxBrushRadius);
return;
}
we.checkMaxBrushRadius(radius);
int iterations = args.argsLength() > 1 ? args.getInteger(1) : 4;
@ -232,11 +212,7 @@ public class BrushCommands {
LocalConfiguration config = we.getConfiguration();
double radius = args.argsLength() > 1 ? args.getDouble(1) : 5;
if (radius > config.maxBrushRadius) {
player.printError("Maximum allowed brush radius: "
+ config.maxBrushRadius);
return;
}
we.checkMaxBrushRadius(radius);
BrushTool tool = session.getBrushTool(player.getItemInHand());
Pattern fill = new SingleBlockPattern(new BaseBlock(0));
@ -268,11 +244,7 @@ public class BrushCommands {
LocalConfiguration config = we.getConfiguration();
double radius = args.argsLength() > 0 ? args.getDouble(0) : 5;
if (radius > config.maxBrushRadius) {
player.printError("Maximum allowed brush radius: "
+ config.maxBrushRadius);
return;
}
we.checkMaxBrushRadius(radius);
BrushTool tool = session.getBrushTool(player.getItemInHand());
tool.setSize(radius);
@ -303,7 +275,7 @@ public class BrushCommands {
// hmmmm not horribly worried about this because -1 is still rather efficient,
// the problem arises when butcherMaxRadius is some really high number but not infinite
// - original idea taken from https://github.com/sk89q/worldedit/pull/198#issuecomment-6463108
if (player.hasPermission("worldedit. butcher")) {
if (player.hasPermission("worldedit.butcher")) {
maxRadius = Math.max(config.maxBrushRadius, config.butcherMaxRadius);
}
if (radius > maxRadius) {

View File

@ -152,11 +152,7 @@ public class ToolUtilCommands {
LocalConfiguration config = we.getConfiguration();
int radius = args.getInteger(0);
if (radius > config.maxBrushRadius) {
player.printError("Maximum allowed brush radius: "
+ config.maxBrushRadius);
return;
}
we.checkMaxBrushRadius(radius);
session.getBrushTool(player.getItemInHand()).setSize(radius);
player.print("Brush size set.");