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 * Get a file relative to the defined working directory. If the specified
* path is absolute, then the working directory is not used. * path is absolute, then the working directory is not used.
@ -1445,6 +1457,8 @@ public class WorldEdit {
} catch (MaxChangedBlocksException e) { } catch (MaxChangedBlocksException e) {
player.printError("Max blocks changed in an operation reached (" player.printError("Max blocks changed in an operation reached ("
+ e.getBlockLimit() + ")."); + e.getBlockLimit() + ").");
} catch (MaxBrushRadiusException e) {
player.printError("Maximum allowed brush radius/height: " + config.maxBrushRadius);
} catch (MaxRadiusException e) { } catch (MaxRadiusException e) {
player.printError("Maximum radius: " + config.maxRadius); player.printError("Maximum radius: " + config.maxRadius);
} catch (UnknownDirectionException e) { } catch (UnknownDirectionException e) {

View File

@ -77,11 +77,7 @@ public class BrushCommands {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
double radius = args.argsLength() > 1 ? args.getDouble(1) : 2; double radius = args.argsLength() > 1 ? args.getDouble(1) : 2;
if (radius > config.maxBrushRadius) { we.checkMaxBrushRadius(radius);
player.printError("Maximum allowed brush radius: "
+ config.maxBrushRadius);
return;
}
BrushTool tool = session.getBrushTool(player.getItemInHand()); BrushTool tool = session.getBrushTool(player.getItemInHand());
Pattern fill = we.getBlockPattern(player, args.getString(0)); Pattern fill = we.getBlockPattern(player, args.getString(0));
@ -116,18 +112,10 @@ public class BrushCommands {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
double radius = args.argsLength() > 1 ? args.getDouble(1) : 2; double radius = args.argsLength() > 1 ? args.getDouble(1) : 2;
if (radius > config.maxBrushRadius) { we.checkMaxBrushRadius(radius);
player.printError("Maximum allowed brush radius: "
+ config.maxBrushRadius);
return;
}
int height = args.argsLength() > 2 ? args.getInteger(2) : 1; int height = args.argsLength() > 2 ? args.getInteger(2) : 1;
if (height > config.maxBrushRadius) { we.checkMaxBrushRadius(height);
player.printError("Maximum allowed brush radius/height: "
+ config.maxBrushRadius);
return;
}
BrushTool tool = session.getBrushTool(player.getItemInHand()); BrushTool tool = session.getBrushTool(player.getItemInHand());
Pattern fill = we.getBlockPattern(player, args.getString(0)); Pattern fill = we.getBlockPattern(player, args.getString(0));
@ -170,13 +158,9 @@ public class BrushCommands {
Vector size = clipboard.getSize(); Vector size = clipboard.getSize();
if (size.getBlockX() > config.maxBrushRadius we.checkMaxBrushRadius(size.getBlockX());
|| size.getBlockY() > config.maxBrushRadius we.checkMaxBrushRadius(size.getBlockY());
|| size.getBlockZ() > config.maxBrushRadius) { we.checkMaxBrushRadius(size.getBlockZ());
player.printError("Maximum allowed brush radius/height: "
+ config.maxBrushRadius);
return;
}
BrushTool tool = session.getBrushTool(player.getItemInHand()); BrushTool tool = session.getBrushTool(player.getItemInHand());
tool.setBrush(new ClipboardBrush(clipboard, args.hasFlag('a')), "worldedit.brush.clipboard"); tool.setBrush(new ClipboardBrush(clipboard, args.hasFlag('a')), "worldedit.brush.clipboard");
@ -202,11 +186,7 @@ public class BrushCommands {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
double radius = args.argsLength() > 0 ? args.getDouble(0) : 2; double radius = args.argsLength() > 0 ? args.getDouble(0) : 2;
if (radius > config.maxBrushRadius) { we.checkMaxBrushRadius(radius);
player.printError("Maximum allowed brush radius: "
+ config.maxBrushRadius);
return;
}
int iterations = args.argsLength() > 1 ? args.getInteger(1) : 4; int iterations = args.argsLength() > 1 ? args.getInteger(1) : 4;
@ -232,11 +212,7 @@ public class BrushCommands {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
double radius = args.argsLength() > 1 ? args.getDouble(1) : 5; double radius = args.argsLength() > 1 ? args.getDouble(1) : 5;
if (radius > config.maxBrushRadius) { we.checkMaxBrushRadius(radius);
player.printError("Maximum allowed brush radius: "
+ config.maxBrushRadius);
return;
}
BrushTool tool = session.getBrushTool(player.getItemInHand()); BrushTool tool = session.getBrushTool(player.getItemInHand());
Pattern fill = new SingleBlockPattern(new BaseBlock(0)); Pattern fill = new SingleBlockPattern(new BaseBlock(0));
@ -268,11 +244,7 @@ public class BrushCommands {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
double radius = args.argsLength() > 0 ? args.getDouble(0) : 5; double radius = args.argsLength() > 0 ? args.getDouble(0) : 5;
if (radius > config.maxBrushRadius) { we.checkMaxBrushRadius(radius);
player.printError("Maximum allowed brush radius: "
+ config.maxBrushRadius);
return;
}
BrushTool tool = session.getBrushTool(player.getItemInHand()); BrushTool tool = session.getBrushTool(player.getItemInHand());
tool.setSize(radius); tool.setSize(radius);
@ -303,7 +275,7 @@ public class BrushCommands {
// hmmmm not horribly worried about this because -1 is still rather efficient, // 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 // 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 // - 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); maxRadius = Math.max(config.maxBrushRadius, config.butcherMaxRadius);
} }
if (radius > maxRadius) { if (radius > maxRadius) {

View File

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