feat: move limits for (brush, superpickaxe and normal) radii to fawe (#2635)

- closes #2587
This commit is contained in:
Jordan 2024-05-24 15:09:57 +02:00 committed by GitHub
parent 3dc949e383
commit f9c523c173
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 470 additions and 101 deletions

View File

@ -120,7 +120,6 @@ public class WorldEditPlugin extends JavaPlugin {
public void onLoad() { public void onLoad() {
//FAWE start //FAWE start
this.bukkitConsoleCommandSender = new BukkitCommandSender(this, Bukkit.getConsoleSender());
// This is already covered by Spigot, however, a more pesky warning with a proper explanation over "Ambiguous plugin name..." can't hurt. // This is already covered by Spigot, however, a more pesky warning with a proper explanation over "Ambiguous plugin name..." can't hurt.
Plugin[] plugins = Bukkit.getServer().getPluginManager().getPlugins(); Plugin[] plugins = Bukkit.getServer().getPluginManager().getPlugins();
for (Plugin p : plugins) { for (Plugin p : plugins) {
@ -138,6 +137,14 @@ public class WorldEditPlugin extends JavaPlugin {
//noinspection ResultOfMethodCallIgnored //noinspection ResultOfMethodCallIgnored
getDataFolder().mkdirs(); getDataFolder().mkdirs();
//FAWE start - Modify WorldEdit config name
config = new BukkitConfiguration(new YAMLProcessor(new File(getDataFolder(), "worldedit-config.yml"), true), this);
// Load config before we say we've loaded platforms as it is used in listeners of the event
// Load config in onLoad to ensure it is loaded before FAWE settings to allow (inelegant) copying of values across
// where needed
config.load();
//FAWE end
WorldEdit worldEdit = WorldEdit.getInstance(); WorldEdit worldEdit = WorldEdit.getInstance();
// Setup platform // Setup platform
@ -148,14 +155,14 @@ public class WorldEditPlugin extends JavaPlugin {
migrateLegacyConfig(); migrateLegacyConfig();
//FAWE end //FAWE end
//FAWE start - Modify WorldEdit config name
config = new BukkitConfiguration(new YAMLProcessor(new File(getDataFolder(), "worldedit-config.yml"), true), this);
//FAWE end
//FAWE start - Setup permission attachments //FAWE start - Setup permission attachments
permissionAttachmentManager = new BukkitPermissionAttachmentManager(this); permissionAttachmentManager = new BukkitPermissionAttachmentManager(this);
//FAWE end //FAWE end
//FAWE start - initialise bukkitConsoleCommandSender later
this.bukkitConsoleCommandSender = new BukkitCommandSender(this, Bukkit.getConsoleSender());
//FAWE end
Path delChunks = Paths.get(getDataFolder().getPath(), DELCHUNKS_FILE_NAME); Path delChunks = Paths.get(getDataFolder().getPath(), DELCHUNKS_FILE_NAME);
if (Files.exists(delChunks)) { if (Files.exists(delChunks)) {
ChunkDeleter.runFromFile(delChunks, true); ChunkDeleter.runFromFile(delChunks, true);
@ -189,8 +196,6 @@ public class WorldEditPlugin extends JavaPlugin {
new FaweBukkit(this); new FaweBukkit(this);
//FAWE end //FAWE end
config.load(); // Load config before we say we've loaded platforms as it is used in listeners of the event
WorldEdit.getInstance().getEventBus().post(new PlatformsRegisteredEvent()); WorldEdit.getInstance().getEventBus().post(new PlatformsRegisteredEvent());
PermissionsResolverManager.initialize(this); // Setup permission resolver PermissionsResolverManager.initialize(this); // Setup permission resolver

View File

@ -24,11 +24,13 @@ limits:
max-polygonal-points: max-polygonal-points:
default: -1 default: -1
maximum: 20 maximum: 20
# radius, superpickaxe, brush radius are ignored, use FAWE config limits
max-radius: -1 max-radius: -1
max-super-pickaxe-size: 5 max-super-pickaxe-size: 5
max-brush-radius: 100 max-brush-radius: 100
butcher-radius: butcher-radius:
default: -1 default: -1
# Ignored, use FAWE config limits
maximum: -1 maximum: -1
disallowed-blocks: disallowed-blocks:
- "minecraft:wheat" - "minecraft:wheat"

View File

@ -13,7 +13,7 @@ public class ScrollRange extends Scroll {
@Override @Override
public boolean increment(Player player, int amount) { public boolean increment(Player player, int amount) {
int max = WorldEdit.getInstance().getConfiguration().maxBrushRadius; int max = player.getLimit().MAX_BRUSH_RADIUS;
int newSize = MathMan.wrap(getTool().getRange() + amount, (int) (getTool().getSize() + 1), max); int newSize = MathMan.wrap(getTool().getRange() + amount, (int) (getTool().getSize() + 1), max);
getTool().setRange(newSize); getTool().setRange(newSize);
return true; return true;

View File

@ -12,7 +12,7 @@ public class ScrollSize extends Scroll {
@Override @Override
public boolean increment(Player player, int amount) { public boolean increment(Player player, int amount) {
int max = WorldEdit.getInstance().getConfiguration().maxRadius; int max = player.getLimit().MAX_RADIUS;
double newSize = Math.max(0, Math.min(max == -1 ? 4095 : max, getTool().getSize() + amount)); double newSize = Math.max(0, Math.min(max == -1 ? 4095 : max, getTool().getSize() + amount));
getTool().setSize(newSize); getTool().setSize(newSize);
return true; return true;

View File

@ -2,6 +2,7 @@ package com.fastasyncworldedit.core.configuration;
import com.fastasyncworldedit.core.limit.FaweLimit; import com.fastasyncworldedit.core.limit.FaweLimit;
import com.fastasyncworldedit.core.limit.PropertyRemap; import com.fastasyncworldedit.core.limit.PropertyRemap;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
@ -140,8 +141,22 @@ public class Settings extends Config {
); );
limit.MAX_FAILS = Math.max(limit.MAX_FAILS, newLimit.MAX_FAILS != -1 ? newLimit.MAX_FAILS : Integer.MAX_VALUE); limit.MAX_FAILS = Math.max(limit.MAX_FAILS, newLimit.MAX_FAILS != -1 ? newLimit.MAX_FAILS : Integer.MAX_VALUE);
limit.MAX_ITERATIONS = Math.max( limit.MAX_ITERATIONS = Math.max(
limit.MAX_ITERATIONS, limit.MAX_ITERATIONS, newLimit.MAX_ITERATIONS != -1 ? newLimit.MAX_ITERATIONS : Integer.MAX_VALUE);
newLimit.MAX_ITERATIONS != -1 ? newLimit.MAX_ITERATIONS : Integer.MAX_VALUE limit.MAX_RADIUS = Math.max(
limit.MAX_RADIUS,
newLimit.MAX_RADIUS != -1 ? newLimit.MAX_RADIUS : Integer.MAX_VALUE
);
limit.MAX_SUPER_PICKAXE_SIZE = Math.max(
limit.MAX_SUPER_PICKAXE_SIZE,
newLimit.MAX_SUPER_PICKAXE_SIZE != -1 ? newLimit.MAX_SUPER_PICKAXE_SIZE : Integer.MAX_VALUE
);
limit.MAX_BRUSH_RADIUS = Math.max(
limit.MAX_BRUSH_RADIUS,
newLimit.MAX_BRUSH_RADIUS != -1 ? newLimit.MAX_BRUSH_RADIUS : Integer.MAX_VALUE
);
limit.MAX_BUTCHER_RADIUS = Math.max(
limit.MAX_BUTCHER_RADIUS,
newLimit.MAX_BUTCHER_RADIUS != -1 ? newLimit.MAX_BUTCHER_RADIUS : Integer.MAX_VALUE
); );
limit.MAX_HISTORY = Math.max( limit.MAX_HISTORY = Math.max(
limit.MAX_HISTORY, limit.MAX_HISTORY,
@ -352,6 +367,14 @@ public class Settings extends Config {
public int MAX_ITERATIONS = 1000; public int MAX_ITERATIONS = 1000;
@Comment("Max allowed entities (e.g. cows)") @Comment("Max allowed entities (e.g. cows)")
public int MAX_ENTITIES = 1337; public int MAX_ENTITIES = 1337;
@Comment("Max allowed radius (e.g. for //sphere)")
public int MAX_RADIUS = LocalConfiguration.MAX_RADIUS;
@Comment("Max allowed superpickaxe size")
public int MAX_SUPER_PICKAXE_SIZE = LocalConfiguration.MAX_SUPER_RADIUS;
@Comment("Max allowed brush radius")
public int MAX_BRUSH_RADIUS = LocalConfiguration.MAX_BRUSH_RADIUS;
@Comment("Max allowed butcher radius")
public int MAX_BUTCHER_RADIUS = LocalConfiguration.MAX_BUTCHER_RADIUS;
@Comment({ @Comment({
"Blockstates include Banner, Beacon, BrewingStand, Chest, CommandBlock, ", "Blockstates include Banner, Beacon, BrewingStand, Chest, CommandBlock, ",
"CreatureSpawner, Dispenser, Dropper, EndGateway, Furnace, Hopper, Jukebox, ", "CreatureSpawner, Dispenser, Dropper, EndGateway, Furnace, Hopper, Jukebox, ",

View File

@ -0,0 +1,30 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.fastasyncworldedit.core.exception;
/**
* Thrown when a maximum radius for a brush is reached.
*/
public class BrushRadiusLimitException extends RadiusLimitException {
public BrushRadiusLimitException(int maxBrushRadius) {
super(maxBrushRadius);
}
}

View File

@ -0,0 +1,41 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.fastasyncworldedit.core.exception;
import com.sk89q.worldedit.WorldEditException;
/**
* Thrown when a maximum radius is reached, such as, for example,
* in the case of a sphere command.
*/
public class RadiusLimitException extends WorldEditException {
private final int maxRadius;
public RadiusLimitException(int maxRadius) {
this.maxRadius = maxRadius;
}
public int getMaxRadius() {
return maxRadius;
}
//FAWE end
}

View File

@ -18,6 +18,10 @@ public class FaweLimit {
public int SCHEM_FILE_SIZE_LIMIT = 0; public int SCHEM_FILE_SIZE_LIMIT = 0;
public int SCHEM_FILE_NUM_LIMIT = 0; public int SCHEM_FILE_NUM_LIMIT = 0;
public int MAX_EXPRESSION_MS = 0; public int MAX_EXPRESSION_MS = 0;
public int MAX_RADIUS = 0;
public int MAX_SUPER_PICKAXE_SIZE = 0;
public int MAX_BRUSH_RADIUS = 0;
public int MAX_BUTCHER_RADIUS = 0;
public int INVENTORY_MODE = Integer.MAX_VALUE; public int INVENTORY_MODE = Integer.MAX_VALUE;
public int SPEED_REDUCTION = Integer.MAX_VALUE; public int SPEED_REDUCTION = Integer.MAX_VALUE;
public boolean FAST_PLACEMENT = false; public boolean FAST_PLACEMENT = false;
@ -123,6 +127,10 @@ public class FaweLimit {
MAX.UNIVERSAL_DISALLOWED_BLOCKS = false; MAX.UNIVERSAL_DISALLOWED_BLOCKS = false;
MAX.DISALLOWED_BLOCKS = Collections.emptySet(); MAX.DISALLOWED_BLOCKS = Collections.emptySet();
MAX.REMAP_PROPERTIES = Collections.emptySet(); MAX.REMAP_PROPERTIES = Collections.emptySet();
MAX.MAX_RADIUS = Integer.MAX_VALUE;
MAX.MAX_SUPER_PICKAXE_SIZE = Integer.MAX_VALUE;
MAX.MAX_BRUSH_RADIUS = Integer.MAX_VALUE;
MAX.MAX_BUTCHER_RADIUS = Integer.MAX_VALUE;
} }
public boolean MAX_CHANGES() { public boolean MAX_CHANGES() {
@ -250,7 +258,12 @@ public class FaweLimit {
&& (STRIP_NBT == null || STRIP_NBT.isEmpty()) && (STRIP_NBT == null || STRIP_NBT.isEmpty())
// && !UNIVERSAL_DISALLOWED_BLOCKS --> do not include this, it effectively has no relevance // && !UNIVERSAL_DISALLOWED_BLOCKS --> do not include this, it effectively has no relevance
&& (DISALLOWED_BLOCKS == null || DISALLOWED_BLOCKS.isEmpty()) && (DISALLOWED_BLOCKS == null || DISALLOWED_BLOCKS.isEmpty())
&& (REMAP_PROPERTIES == null || REMAP_PROPERTIES.isEmpty()); && (REMAP_PROPERTIES == null || REMAP_PROPERTIES.isEmpty())
&& MAX_RADIUS == Integer.MAX_VALUE
&& MAX_SUPER_PICKAXE_SIZE == Integer.MAX_VALUE
&& MAX_BRUSH_RADIUS == Integer.MAX_VALUE
&& MAX_BUTCHER_RADIUS == Integer.MAX_VALUE;
} }
public void set(FaweLimit limit) { public void set(FaweLimit limit) {
@ -273,6 +286,10 @@ public class FaweLimit {
UNIVERSAL_DISALLOWED_BLOCKS = limit.UNIVERSAL_DISALLOWED_BLOCKS; UNIVERSAL_DISALLOWED_BLOCKS = limit.UNIVERSAL_DISALLOWED_BLOCKS;
DISALLOWED_BLOCKS = limit.DISALLOWED_BLOCKS; DISALLOWED_BLOCKS = limit.DISALLOWED_BLOCKS;
REMAP_PROPERTIES = limit.REMAP_PROPERTIES; REMAP_PROPERTIES = limit.REMAP_PROPERTIES;
MAX_RADIUS = limit.MAX_RADIUS;
MAX_SUPER_PICKAXE_SIZE = limit.MAX_SUPER_PICKAXE_SIZE;
MAX_BRUSH_RADIUS = limit.MAX_BRUSH_RADIUS;
MAX_BUTCHER_RADIUS = limit.MAX_BUTCHER_RADIUS;
} }
public FaweLimit copy() { public FaweLimit copy() {
@ -296,6 +313,10 @@ public class FaweLimit {
limit.UNIVERSAL_DISALLOWED_BLOCKS = UNIVERSAL_DISALLOWED_BLOCKS; limit.UNIVERSAL_DISALLOWED_BLOCKS = UNIVERSAL_DISALLOWED_BLOCKS;
limit.DISALLOWED_BLOCKS = DISALLOWED_BLOCKS; limit.DISALLOWED_BLOCKS = DISALLOWED_BLOCKS;
limit.REMAP_PROPERTIES = REMAP_PROPERTIES; limit.REMAP_PROPERTIES = REMAP_PROPERTIES;
limit.MAX_RADIUS = MAX_RADIUS;
limit.MAX_SUPER_PICKAXE_SIZE = MAX_SUPER_PICKAXE_SIZE;
limit.MAX_BRUSH_RADIUS = MAX_BRUSH_RADIUS;
limit.MAX_BUTCHER_RADIUS = MAX_BUTCHER_RADIUS;
return limit; return limit;
} }

View File

@ -52,12 +52,26 @@ import java.util.Set;
public abstract class LocalConfiguration { public abstract class LocalConfiguration {
private static final Logger LOGGER = LogManagerCompat.getLogger(); private static final Logger LOGGER = LogManagerCompat.getLogger();
//FAWE start - inelegant but required to transfer to FAWE limits as defaults
public static int MAX_RADIUS;
public static int MAX_SUPER_RADIUS;
public static int MAX_BRUSH_RADIUS;
public static int MAX_BUTCHER_RADIUS;
//FAWE end
public boolean profile = false; public boolean profile = false;
public boolean traceUnflushedSessions = true; public boolean traceUnflushedSessions = true;
public Set<String> disallowedBlocks = new HashSet<>(); public Set<String> disallowedBlocks = new HashSet<>();
protected BlockMask disallowedBlocksMask; protected BlockMask disallowedBlocksMask;
/**
* @deprecated Use actor's limit {@link com.fastasyncworldedit.core.limit.FaweLimit#MAX_CHANGES}
*/
@Deprecated
public int defaultChangeLimit = -1; public int defaultChangeLimit = -1;
/**
* @deprecated Use actor's limit {@link com.fastasyncworldedit.core.limit.FaweLimit#MAX_CHANGES}
*/
@Deprecated
public int maxChangeLimit = -1; public int maxChangeLimit = -1;
public int defaultVerticalHeight = 256; public int defaultVerticalHeight = 256;
public int defaultMaxPolygonalPoints = -1; public int defaultMaxPolygonalPoints = -1;
@ -68,8 +82,20 @@ public abstract class LocalConfiguration {
public boolean snapshotsConfigured = false; public boolean snapshotsConfigured = false;
public SnapshotRepository snapshotRepo = null; public SnapshotRepository snapshotRepo = null;
public SnapshotDatabase snapshotDatabase = null; public SnapshotDatabase snapshotDatabase = null;
/**
* @deprecated Use actor's limit {@link com.fastasyncworldedit.core.limit.FaweLimit#MAX_RADIUS}
*/
@Deprecated
public int maxRadius = -1; public int maxRadius = -1;
/**
* @deprecated Use actor's limit {@link com.fastasyncworldedit.core.limit.FaweLimit#MAX_SUPER_PICKAXE_SIZE}
*/
@Deprecated
public int maxSuperPickaxeSize = 5; public int maxSuperPickaxeSize = 5;
/**
* @deprecated Use actor's limit {@link com.fastasyncworldedit.core.limit.FaweLimit#MAX_BRUSH_RADIUS}
*/
@Deprecated
public int maxBrushRadius = 6; public int maxBrushRadius = 6;
public boolean logCommands = false; public boolean logCommands = false;
public String logFile = ""; public String logFile = "";
@ -92,6 +118,10 @@ public abstract class LocalConfiguration {
public String scriptsDir = "craftscripts"; public String scriptsDir = "craftscripts";
public boolean showHelpInfo = true; // unused public boolean showHelpInfo = true; // unused
public int butcherDefaultRadius = -1; public int butcherDefaultRadius = -1;
/**
* @deprecated Use actor's limit {@link com.fastasyncworldedit.core.limit.FaweLimit#MAX_BUTCHER_RADIUS}
*/
@Deprecated
public int butcherMaxRadius = -1; public int butcherMaxRadius = -1;
public boolean allowSymlinks = false; public boolean allowSymlinks = false;
public boolean serverSideCUI = true; public boolean serverSideCUI = true;

View File

@ -19,9 +19,24 @@
package com.sk89q.worldedit; package com.sk89q.worldedit;
import com.fastasyncworldedit.core.exception.BrushRadiusLimitException;
import com.fastasyncworldedit.core.exception.RadiusLimitException;
/** /**
* Thrown when a maximum radius for a brush is reached. * Thrown when a maximum radius for a brush is reached.
*
* @deprecated Use {@link RadiusLimitException}
*/ */
@Deprecated
public class MaxBrushRadiusException extends MaxRadiusException { public class MaxBrushRadiusException extends MaxRadiusException {
//FAWE start
/**
* @deprecated Use {@link BrushRadiusLimitException}
*/
@Deprecated
public MaxBrushRadiusException() {
}
//FAWE end
} }

View File

@ -19,10 +19,24 @@
package com.sk89q.worldedit; package com.sk89q.worldedit;
import com.fastasyncworldedit.core.exception.RadiusLimitException;
/** /**
* Thrown when a maximum radius is reached, such as, for example, * Thrown when a maximum radius is reached, such as, for example,
* in the case of a sphere command. * in the case of a sphere command.
*
* @deprecated Use {@link RadiusLimitException}
*/ */
@Deprecated
public class MaxRadiusException extends WorldEditException { public class MaxRadiusException extends WorldEditException {
//FAWE start
/**
* @deprecated Use {@link RadiusLimitException}
*/
@Deprecated
public MaxRadiusException() {
}
//FAWE end
} }

View File

@ -20,6 +20,8 @@
package com.sk89q.worldedit; package com.sk89q.worldedit;
import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.exception.BrushRadiusLimitException;
import com.fastasyncworldedit.core.exception.RadiusLimitException;
import com.fastasyncworldedit.core.extension.factory.TransformFactory; import com.fastasyncworldedit.core.extension.factory.TransformFactory;
import com.fastasyncworldedit.core.extent.ResettableExtent; import com.fastasyncworldedit.core.extent.ResettableExtent;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
@ -437,7 +439,9 @@ public final class WorldEdit {
* *
* @param radius the radius * @param radius the radius
* @throws MaxRadiusException if the radius is bigger than the configured radius * @throws MaxRadiusException if the radius is bigger than the configured radius
* @deprecated Use {@link WorldEdit#checkMaxRadius(double, Actor)}
*/ */
@Deprecated
public void checkMaxRadius(double radius) throws MaxRadiusException { public void checkMaxRadius(double radius) throws MaxRadiusException {
if (getConfiguration().maxRadius > 0 && radius > getConfiguration().maxRadius) { if (getConfiguration().maxRadius > 0 && radius > getConfiguration().maxRadius) {
throw new MaxRadiusException(); throw new MaxRadiusException();
@ -449,7 +453,9 @@ public final class WorldEdit {
* *
* @param radius the radius * @param radius the radius
* @throws MaxBrushRadiusException if the radius is bigger than the configured radius * @throws MaxBrushRadiusException if the radius is bigger than the configured radius
* @deprecated Use {@link WorldEdit#checkMaxBrushRadius(double, Actor)}
*/ */
@Deprecated
public void checkMaxBrushRadius(double radius) throws MaxBrushRadiusException { public void checkMaxBrushRadius(double radius) throws MaxBrushRadiusException {
if (getConfiguration().maxBrushRadius > 0 && radius > getConfiguration().maxBrushRadius) { if (getConfiguration().maxBrushRadius > 0 && radius > getConfiguration().maxBrushRadius) {
throw new MaxBrushRadiusException(); throw new MaxBrushRadiusException();
@ -457,6 +463,10 @@ public final class WorldEdit {
} }
//FAWE start //FAWE start
/**
* @deprecated Use {@link WorldEdit#checkMaxBrushRadius(Expression, Actor)}
*/
@Deprecated(forRemoval = true, since = "TODO")
public void checkMaxBrushRadius(Expression radius) throws MaxBrushRadiusException { public void checkMaxBrushRadius(Expression radius) throws MaxBrushRadiusException {
double val = radius.evaluate(); double val = radius.evaluate();
checkArgument(val >= 0, "Radius must be a positive number."); checkArgument(val >= 0, "Radius must be a positive number.");
@ -466,6 +476,53 @@ public final class WorldEdit {
} }
} }
} }
/**
* Check the given radius against the give actor's limit.
*
* @param radius Radius to check
* @param actor Actor to check for
* @throws MaxRadiusException If given radius larger than allowed
* @since TODO
*/
public void checkMaxRadius(double radius, Actor actor) {
int max = actor.getLimit().MAX_RADIUS;
if (max > 0 && radius > max) {
throw new RadiusLimitException(max);
}
}
/**
* Check the given radius against the give actor's limit.
*
* @param radius Radius to check
* @param actor Actor to check for
* @throws MaxRadiusException If given radius larger than allowed
* @since TODO
*/
public void checkMaxBrushRadius(double radius, Actor actor) {
int max = actor.getLimit().MAX_BRUSH_RADIUS;
if (max > 0 && radius > max) {
throw new RadiusLimitException(max);
}
}
/**
* Check the given radius against the give actor's limit.
*
* @param expression Radius to check
* @param actor Actor to check for
* @throws BrushRadiusLimitException If given radius larger than allowed
* @since TODO
*/
public void checkMaxBrushRadius(Expression expression, Actor actor) {
double radius = expression.evaluate();
checkArgument(radius >= 0, "Radius must be a positive number.");
int max = actor.getLimit().MAX_BRUSH_RADIUS;
if (max > 0 && radius > max) {
throw new BrushRadiusLimitException(max);
}
}
//FAWE end //FAWE end
/** /**

View File

@ -186,7 +186,10 @@ public class BrushCommands {
@ArgFlag(name = 'm', desc = "Mask to limit blocks being considered", def = "") @ArgFlag(name = 'm', desc = "Mask to limit blocks being considered", def = "")
Mask mask Mask mask
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
checkCommandArgument(minFreqDiff >= 0 && minFreqDiff <= 26, "minFreqDiff not in range 0 <= value <= 26"); checkCommandArgument(minFreqDiff >= 0 && minFreqDiff <= 26, "minFreqDiff not in range 0 <= value <= 26");
if (mask != null && !(mask instanceof CachedMask)) { if (mask != null && !(mask instanceof CachedMask)) {
mask = new CachedMask(mask, false); mask = new CachedMask(mask, false);
@ -212,7 +215,10 @@ public class BrushCommands {
@Arg(desc = "fillRec", def = "1") @Arg(desc = "fillRec", def = "1")
int fillRec int fillRec
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
set(context, new ErodeBrush(erodefaces, erodeRec, fillFaces, fillRec), "worldedit.brush.erode").setSize(radius); set(context, new ErodeBrush(erodefaces, erodeRec, fillFaces, fillRec), "worldedit.brush.erode").setSize(radius);
} }
@ -234,7 +240,10 @@ public class BrushCommands {
@Arg(desc = "fillRec", def = "1") @Arg(desc = "fillRec", def = "1")
int fillRec int fillRec
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
set(context, new RaiseBrush(erodefaces, erodeRec, fillFaces, fillRec), "worldedit.brush.pull").setSize(radius); set(context, new RaiseBrush(erodefaces, erodeRec, fillFaces, fillRec), "worldedit.brush.pull").setSize(radius);
} }
@ -252,7 +261,10 @@ public class BrushCommands {
@Arg(name = "filled", desc = "Whether the circle should be filled", def = "false") @Arg(name = "filled", desc = "Whether the circle should be filled", def = "false")
boolean filled boolean filled
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
set(context, new CircleBrush(filled), "worldedit.brush.sphere").setSize(radius).setFill(fill); set(context, new CircleBrush(filled), "worldedit.brush.sphere").setSize(radius).setFill(fill);
} }
@ -276,7 +288,10 @@ public class BrushCommands {
@Switch(name = 'd', desc = "Apply in depth first order") @Switch(name = 'd', desc = "Apply in depth first order")
boolean depthFirst boolean depthFirst
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
set(context, new RecurseBrush(depthFirst), "worldedit.brush.recursive").setSize(radius).setFill(fill) set(context, new RecurseBrush(depthFirst), "worldedit.brush.recursive").setSize(radius).setFill(fill)
.setMask(new IdMask(editSession)); .setMask(new IdMask(editSession));
} }
@ -299,7 +314,10 @@ public class BrushCommands {
@Switch(name = 'f', desc = "Create a flat line") @Switch(name = 'f', desc = "Create a flat line")
boolean flat boolean flat
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
set(context, new LineBrush(shell, select, flat), "worldedit.brush.line").setSize(radius).setFill(fill); set(context, new LineBrush(shell, select, flat), "worldedit.brush.line").setSize(radius).setFill(fill);
} }
@ -326,7 +344,10 @@ public class BrushCommands {
Expression radius Expression radius
) )
throws WorldEditException { throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
player.print(Caption.of("fawe.worldedit.brush.brush.spline", (radius))); player.print(Caption.of("fawe.worldedit.brush.brush.spline", (radius)));
set(context, new SplineBrush(player), "worldedit.brush.spline").setSize(radius).setFill(fill); set(context, new SplineBrush(player), "worldedit.brush.spline").setSize(radius).setFill(fill);
} }
@ -379,7 +400,10 @@ public class BrushCommands {
@Switch(name = 'd', desc = "sags the catenary toward the facing direction") @Switch(name = 'd', desc = "sags the catenary toward the facing direction")
boolean facingDirection boolean facingDirection
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
set(context, new CatenaryBrush(shell, select, facingDirection, lengthFactor), "worldedit.brush.spline") set(context, new CatenaryBrush(shell, select, facingDirection, lengthFactor), "worldedit.brush.spline")
.setSize(radius).setFill(fill); .setSize(radius).setFill(fill);
} }
@ -411,7 +435,10 @@ public class BrushCommands {
double quality double quality
) throws WorldEditException { ) throws WorldEditException {
player.print(Caption.of("fawe.worldedit.brush.brush.spline", (radius))); player.print(Caption.of("fawe.worldedit.brush.brush.spline", (radius)));
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
set(context, new SurfaceSpline(tension, bias, continuity, quality), "surfacespline").setSize(radius) set(context, new SurfaceSpline(tension, bias, continuity, quality), "surfacespline").setSize(radius)
.setFill(fill); .setFill(fill);
} }
@ -436,9 +463,11 @@ public class BrushCommands {
double amplitude double amplitude
) throws WorldEditException { ) throws WorldEditException {
double max = MathMan.max(radius.getX(), radius.getY(), radius.getZ()); double max = MathMan.max(radius.getX(), radius.getY(), radius.getZ());
worldEdit.checkMaxBrushRadius(max); worldEdit.checkMaxBrushRadius(
Brush brush = max,
new BlobBrush(radius.divide(max), frequency / 100, amplitude / 100, sphericity / 100); context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
Brush brush = new BlobBrush(radius.divide(max), frequency / 100, amplitude / 100, sphericity / 100);
set(context, brush, "worldedit.brush.rock").setSize(max).setFill(fill); set(context, brush, "worldedit.brush.rock").setSize(max).setFill(fill);
} }
@ -459,7 +488,10 @@ public class BrushCommands {
@Arg(desc = "Lines", def = "10") @Arg(desc = "Lines", def = "10")
int count int count
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
set(context, new ShatterBrush(count), "worldedit.brush.shatter").setSize(radius).setFill(fill) set(context, new ShatterBrush(count), "worldedit.brush.shatter").setSize(radius).setFill(fill)
.setMask(new ExistingBlockMask(editSession)); .setMask(new ExistingBlockMask(editSession));
} }
@ -490,7 +522,10 @@ public class BrushCommands {
boolean randomRotate boolean randomRotate
) )
throws WorldEditException, FileNotFoundException { throws WorldEditException, FileNotFoundException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
InputStream stream = getHeightmapStream(image); InputStream stream = getHeightmapStream(image);
HeightBrush brush; HeightBrush brush;
int minY = player.getWorld().getMinY(); int minY = player.getWorld().getMinY();
@ -526,7 +561,10 @@ public class BrushCommands {
URL url = new URL(imageURL); URL url = new URL(imageURL);
MainUtil.checkImageHost(url.toURI()); MainUtil.checkImageHost(url.toURI());
BufferedImage image = MainUtil.readImage(url); BufferedImage image = MainUtil.readImage(url);
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
if (yscale != 1) { if (yscale != 1) {
ImageUtil.scaleAlpha(image, yscale); ImageUtil.scaleAlpha(image, yscale);
alpha = true; alpha = true;
@ -553,7 +591,10 @@ public class BrushCommands {
@Arg(desc = "Expression", def = "5") @Arg(desc = "Expression", def = "5")
Expression radius Expression radius
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
set(context, new SurfaceSphereBrush(), "worldedit.brush.surface").setFill(fill).setSize(radius); set(context, new SurfaceSphereBrush(), "worldedit.brush.surface").setFill(fill).setSize(radius);
} }
@ -578,7 +619,10 @@ public class BrushCommands {
@Switch(name = 'o', desc = "Overlay the block") @Switch(name = 'o', desc = "Overlay the block")
boolean overlay boolean overlay
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
Brush brush; Brush brush;
if (overlay) { if (overlay) {
brush = new ScatterOverlayBrush((int) points, (int) distance); brush = new ScatterOverlayBrush((int) points, (int) distance);
@ -612,7 +656,10 @@ public class BrushCommands {
@Switch(name = 'r', desc = "Apply random rotation") @Switch(name = 'r', desc = "Apply random rotation")
boolean rotate boolean rotate
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
try { try {
MultiClipboardHolder clipboards = MultiClipboardHolder clipboards =
ClipboardFormats.loadAllFromInput(player, clipboardStr, null, true); ClipboardFormats.loadAllFromInput(player, clipboardStr, null, true);
@ -651,7 +698,10 @@ public class BrushCommands {
List<Pattern> patternLayers List<Pattern> patternLayers
) )
throws WorldEditException { throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
set(context, new LayerBrush(patternLayers.toArray(new Pattern[0])), "worldedit.brush.layer").setSize(radius); set(context, new LayerBrush(patternLayers.toArray(new Pattern[0])), "worldedit.brush.layer").setSize(radius);
} }
@ -678,7 +728,10 @@ public class BrushCommands {
@Arg(desc = "boolean", def = "true") @Arg(desc = "boolean", def = "true")
boolean solid boolean solid
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
set(context, new SplatterBrush((int) points, (int) recursion, solid), "worldedit.brush.splatter").setSize(radius) set(context, new SplatterBrush((int) points, (int) recursion, solid), "worldedit.brush.splatter").setSize(radius)
.setFill(fill); .setFill(fill);
} }
@ -711,7 +764,10 @@ public class BrushCommands {
boolean print boolean print
) )
throws WorldEditException { throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
set( set(
context, context,
new ScatterCommand((int) points, (int) distance, StringMan.join(commandStr, " "), print), new ScatterCommand((int) points, (int) distance, StringMan.join(commandStr, " "), print),
@ -838,7 +894,10 @@ public class BrushCommands {
InjectedValueAccess context InjectedValueAccess context
) )
throws WorldEditException, FileNotFoundException { throws WorldEditException, FileNotFoundException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
InputStream stream = getHeightmapStream(image); InputStream stream = getHeightmapStream(image);
HeightBrush brush; HeightBrush brush;
int minY = player.getWorld().getMinY(); int minY = player.getWorld().getMinY();
@ -908,7 +967,10 @@ public class BrushCommands {
@Switch(name = 'a', desc = "Apply auto view based rotation on paste") @Switch(name = 'a', desc = "Apply auto view based rotation on paste")
boolean autoRotate boolean autoRotate
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
player.print(Caption.of("fawe.worldedit.brush.brush.copy", (radius))); player.print(Caption.of("fawe.worldedit.brush.brush.copy", (radius)));
set(context, new CopyPastaBrush(player, session, randomRotate, autoRotate), "worldedit.brush.copy").setSize(radius); set(context, new CopyPastaBrush(player, session, randomRotate, autoRotate), "worldedit.brush.copy").setSize(radius);
@ -933,7 +995,10 @@ public class BrushCommands {
@Switch(name = 'p', desc = "Show any printed output") @Switch(name = 'p', desc = "Show any printed output")
boolean print boolean print
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
String cmd = StringMan.join(input, " "); String cmd = StringMan.join(input, " ");
set(context, new CommandBrush(cmd, print), "worldedit.brush.command").setSize(radius); set(context, new CommandBrush(cmd, print), "worldedit.brush.command").setSize(radius);
} }
@ -1042,7 +1107,7 @@ public class BrushCommands {
String permission String permission
) )
throws WorldEditException { throws WorldEditException {
WorldEdit.getInstance().checkMaxBrushRadius(radius); WorldEdit.getInstance().checkMaxBrushRadius(radius, player);
BrushTool tool = session.getBrushTool(player); BrushTool tool = session.getBrushTool(player);
tool.setSize(radius); tool.setSize(radius);
tool.setFill(null); tool.setFill(null);
@ -1197,7 +1262,10 @@ public class BrushCommands {
@Switch(name = 'f', desc = "Create falling spheres instead") @Switch(name = 'f', desc = "Create falling spheres instead")
boolean falling boolean falling
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
Brush brush; Brush brush;
if (hollow) { if (hollow) {
brush = new HollowSphereBrush(); brush = new HollowSphereBrush();
@ -1244,8 +1312,14 @@ public class BrushCommands {
@Switch(name = 'h', desc = "Create hollow cylinders instead") @Switch(name = 'h', desc = "Create hollow cylinders instead")
boolean hollow boolean hollow
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
worldEdit.checkMaxBrushRadius(height); radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
worldEdit.checkMaxBrushRadius(
height,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
BrushSettings settings; BrushSettings settings;
if (hollow) { if (hollow) {
@ -1293,9 +1367,18 @@ public class BrushCommands {
BlockVector3 size = clipboard.getDimensions(); BlockVector3 size = clipboard.getDimensions();
worldEdit.checkMaxBrushRadius(size.getBlockX() / 2D - 1); worldEdit.checkMaxBrushRadius(
worldEdit.checkMaxBrushRadius(size.getBlockY() / 2D - 1); size.getBlockX() / 2D - 1,
worldEdit.checkMaxBrushRadius(size.getBlockZ() / 2D - 1); context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
worldEdit.checkMaxBrushRadius(
size.getBlockY() / 2D - 1,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
worldEdit.checkMaxBrushRadius(
size.getBlockZ() / 2D - 1,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
set( set(
context, context,
@ -1324,7 +1407,10 @@ public class BrushCommands {
Mask mask, Mask mask,
InjectedValueAccess context InjectedValueAccess context
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
//FAWE start //FAWE start
FaweLimit limit = Settings.settings().getLimit(player); FaweLimit limit = Settings.settings().getLimit(player);
@ -1359,7 +1445,10 @@ public class BrushCommands {
@ArgFlag(name = 'm', desc = "The mask of blocks to use for the heightmap") @ArgFlag(name = 'm', desc = "The mask of blocks to use for the heightmap")
Mask mask, InjectedValueAccess context Mask mask, InjectedValueAccess context
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
//FAWE start //FAWE start
FaweLimit limit = Settings.settings().getLimit(player); FaweLimit limit = Settings.settings().getLimit(player);
@ -1386,7 +1475,10 @@ public class BrushCommands {
@Arg(desc = "The radius to extinguish", def = "5") @Arg(desc = "The radius to extinguish", def = "5")
Expression radius Expression radius
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
set(context, new SphereBrush(), "worldedit.brush.ex").setSize(radius).setFill(BlockTypes.AIR.getDefaultState()) set(context, new SphereBrush(), "worldedit.brush.ex").setSize(radius).setFill(BlockTypes.AIR.getDefaultState())
.setMask(new SingleBlockTypeMask(editSession, BlockTypes.FIRE)); .setMask(new SingleBlockTypeMask(editSession, BlockTypes.FIRE));
@ -1405,7 +1497,10 @@ public class BrushCommands {
@Switch(name = 'h', desc = "Affect blocks starting at max Y, rather than the target location Y + radius") @Switch(name = 'h', desc = "Affect blocks starting at max Y, rather than the target location Y + radius")
boolean fromMaxY boolean fromMaxY
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
set(context, new GravityBrush(fromMaxY), "worldedit.brush.gravity").setSize(radius); set(context, new GravityBrush(fromMaxY), "worldedit.brush.gravity").setSize(radius);
} }
@ -1439,7 +1534,10 @@ public class BrushCommands {
@Switch(name = 'w', desc = "Also kill water mobs") @Switch(name = 'w', desc = "Also kill water mobs")
boolean killWater, InjectedValueAccess context boolean killWater, InjectedValueAccess context
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(
radius,
context.injectedValue(Key.of(Player.class)).orElseThrow(() -> new IllegalStateException("No player"))
);
CreatureButcher flags = new CreatureButcher(player); CreatureButcher flags = new CreatureButcher(player);
flags.or( flags.or(
@ -1508,7 +1606,7 @@ public class BrushCommands {
RegionFactory shape, RegionFactory shape,
String permission String permission
) throws WorldEditException { ) throws WorldEditException {
WorldEdit.getInstance().checkMaxBrushRadius(radius); WorldEdit.getInstance().checkMaxBrushRadius(radius, player);
BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()); BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
tool.setSize(radius); tool.setSize(radius);
tool.setFill(null); tool.setFill(null);

View File

@ -130,9 +130,9 @@ public class GenerationCommands {
return 0; return 0;
} }
} }
worldEdit.checkMaxRadius(radiusX); worldEdit.checkMaxRadius(radiusX, actor);
worldEdit.checkMaxRadius(radiusZ); worldEdit.checkMaxRadius(radiusZ, actor);
worldEdit.checkMaxRadius(height); worldEdit.checkMaxRadius(height, actor);
if (thickness > radiusX || thickness > radiusZ) { if (thickness > radiusX || thickness > radiusZ) {
actor.print(Caption.of("worldedit.hcyl.thickness-too-large")); actor.print(Caption.of("worldedit.hcyl.thickness-too-large"));
@ -178,9 +178,9 @@ public class GenerationCommands {
} }
} }
worldEdit.checkMaxRadius(radiusX); worldEdit.checkMaxRadius(radiusX, actor);
worldEdit.checkMaxRadius(radiusZ); worldEdit.checkMaxRadius(radiusZ, actor);
worldEdit.checkMaxRadius(height); worldEdit.checkMaxRadius(height, actor);
BlockVector3 pos = session.getPlacementPosition(actor); BlockVector3 pos = session.getPlacementPosition(actor);
int affected = editSession.makeCylinder(pos, pattern, radiusX, radiusZ, height, !hollow); int affected = editSession.makeCylinder(pos, pattern, radiusX, radiusZ, height, !hollow);
@ -224,9 +224,9 @@ public class GenerationCommands {
} }
} }
worldEdit.checkMaxRadius(radiusX); worldEdit.checkMaxRadius(radiusX, actor);
worldEdit.checkMaxRadius(radiusZ); worldEdit.checkMaxRadius(radiusZ, actor);
worldEdit.checkMaxRadius(height); worldEdit.checkMaxRadius(height, actor);
BlockVector3 pos = session.getPlacementPosition(actor); BlockVector3 pos = session.getPlacementPosition(actor);
int affected = editSession.makeCone(pos, pattern, radiusX, radiusZ, height, !hollow, thickness); int affected = editSession.makeCone(pos, pattern, radiusX, radiusZ, height, !hollow, thickness);
@ -290,9 +290,9 @@ public class GenerationCommands {
} }
} }
worldEdit.checkMaxRadius(radiusX); worldEdit.checkMaxRadius(radiusX, actor);
worldEdit.checkMaxRadius(radiusY); worldEdit.checkMaxRadius(radiusY, actor);
worldEdit.checkMaxRadius(radiusZ); worldEdit.checkMaxRadius(radiusZ, actor);
BlockVector3 pos = session.getPlacementPosition(actor); BlockVector3 pos = session.getPlacementPosition(actor);
if (raised) { if (raised) {
pos = pos.add(0, (int) radiusY, 0); pos = pos.add(0, (int) radiusY, 0);
@ -323,7 +323,7 @@ public class GenerationCommands {
double density double density
) throws WorldEditException { ) throws WorldEditException {
checkCommandArgument(0 <= density && density <= 100, "Density must be between 0 and 100"); checkCommandArgument(0 <= density && density <= 100, "Density must be between 0 and 100");
worldEdit.checkMaxRadius(size); worldEdit.checkMaxRadius(size, actor);
density /= 100; density /= 100;
int affected = editSession.makeForest(session.getPlacementPosition(actor), size, density, type); int affected = editSession.makeForest(session.getPlacementPosition(actor), size, density, type);
actor.print(Caption.of("worldedit.forestgen.created", TextComponent.of(affected))); actor.print(Caption.of("worldedit.forestgen.created", TextComponent.of(affected)));
@ -345,7 +345,7 @@ public class GenerationCommands {
double density double density
) throws WorldEditException { ) throws WorldEditException {
checkCommandArgument(0 <= density && density <= 100, "Density must be between 0 and 100"); checkCommandArgument(0 <= density && density <= 100, "Density must be between 0 and 100");
worldEdit.checkMaxRadius(size); worldEdit.checkMaxRadius(size, actor);
int affected = editSession.makePumpkinPatches(session.getPlacementPosition(actor), size, density); int affected = editSession.makePumpkinPatches(session.getPlacementPosition(actor), size, density);
actor.print(Caption.of("worldedit.pumpkins.created", TextComponent.of(affected))); actor.print(Caption.of("worldedit.pumpkins.created", TextComponent.of(affected)));
return affected; return affected;
@ -382,7 +382,7 @@ public class GenerationCommands {
@Switch(name = 'h', desc = "Make a hollow pyramid") @Switch(name = 'h', desc = "Make a hollow pyramid")
boolean hollow boolean hollow
) throws WorldEditException { ) throws WorldEditException {
worldEdit.checkMaxRadius(size); worldEdit.checkMaxRadius(size, actor);
BlockVector3 pos = session.getPlacementPosition(actor); BlockVector3 pos = session.getPlacementPosition(actor);
int affected = editSession.makePyramid(pos, pattern, size, !hollow); int affected = editSession.makePyramid(pos, pattern, size, !hollow);
if (actor instanceof Player && Settings.settings().GENERAL.UNSTUCK_ON_GENERATE) { if (actor instanceof Player && Settings.settings().GENERAL.UNSTUCK_ON_GENERATE) {
@ -736,7 +736,7 @@ public class GenerationCommands {
double amplitude double amplitude
) throws WorldEditException { ) throws WorldEditException {
double max = MathMan.max(radius.getX(), radius.getY(), radius.getZ()); double max = MathMan.max(radius.getX(), radius.getY(), radius.getZ());
worldEdit.checkMaxRadius(max); worldEdit.checkMaxRadius(max, actor);
BlockVector3 pos = session.getPlacementPosition(actor); BlockVector3 pos = session.getPlacementPosition(actor);
int affected = editSession.makeBlob( int affected = editSession.makeBlob(
pos, pos,

View File

@ -66,10 +66,11 @@ public class SuperPickaxeCommands {
int range int range
) throws WorldEditException { ) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); if (range > player.getLimit().MAX_SUPER_PICKAXE_SIZE) {
player.print(Caption.of(
if (range > config.maxSuperPickaxeSize) { "worldedit.tool.superpickaxe.max-range",
player.print(Caption.of("worldedit.tool.superpickaxe.max-range", TextComponent.of(config.maxSuperPickaxeSize))); TextComponent.of(player.getLimit().MAX_SUPER_PICKAXE_SIZE)
));
return; return;
} }
session.setSuperPickaxe(new AreaPickaxe(range)); session.setSuperPickaxe(new AreaPickaxe(range));
@ -89,10 +90,11 @@ public class SuperPickaxeCommands {
double range double range
) throws WorldEditException { ) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); if (range > player.getLimit().MAX_SUPER_PICKAXE_SIZE) {
player.print(Caption.of(
if (range > config.maxSuperPickaxeSize) { "worldedit.tool.superpickaxe.max-range",
player.print(Caption.of("worldedit.tool.superpickaxe.max-range", TextComponent.of(config.maxSuperPickaxeSize))); TextComponent.of(player.getLimit().MAX_SUPER_PICKAXE_SIZE)
));
return; return;
} }

View File

@ -297,10 +297,11 @@ public class ToolCommands {
int range int range
) throws WorldEditException { ) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); if (range > player.getLimit().MAX_SUPER_PICKAXE_SIZE) {
player.print(Caption.of(
if (range > config.maxSuperPickaxeSize) { "worldedit.tool.superpickaxe.max-range",
player.print(Caption.of("worldedit.tool.superpickaxe.max-range", TextComponent.of(config.maxSuperPickaxeSize))); TextComponent.of(player.getLimit().MAX_SUPER_PICKAXE_SIZE)
));
return; return;
} }
setTool(player, session, new FloodFillTool(range, pattern), "worldedit.tool.floodfill.equip"); setTool(player, session, new FloodFillTool(range, pattern), "worldedit.tool.floodfill.equip");

View File

@ -154,7 +154,7 @@ public class ToolUtilCommands {
@Arg(desc = "The size of the brush") @Arg(desc = "The size of the brush")
int size int size
) throws WorldEditException { ) throws WorldEditException {
we.checkMaxBrushRadius(size); we.checkMaxBrushRadius(size, player);
session.getBrushTool(player).setSize(size); session.getBrushTool(player).setSize(size);
player.print(Caption.of("worldedit.tool.size.set")); player.print(Caption.of("worldedit.tool.size.set"));

View File

@ -246,8 +246,9 @@ public class UtilityCommands {
double radius = radiusExp.evaluate(); double radius = radiusExp.evaluate();
//FAWE end //FAWE end
radius = Math.max(1, radius); radius = Math.max(1, radius);
we.checkMaxRadius(radius); we.checkMaxRadius(radius, actor);
depth = Math.max(1, depth); depth = Math.max(1, depth);
we.checkMaxRadius(depth, actor);
BlockVector3 pos = session.getPlacementPosition(actor); BlockVector3 pos = session.getPlacementPosition(actor);
int affected = editSession.fillDirection(pos, pattern, radius, depth, direction); int affected = editSession.fillDirection(pos, pattern, radius, depth, direction);
@ -333,9 +334,9 @@ public class UtilityCommands {
double radius = radiusExp.evaluate(); double radius = radiusExp.evaluate();
//FAWE end //FAWE end
radius = Math.max(1, radius); radius = Math.max(1, radius);
we.checkMaxRadius(radius); we.checkMaxRadius(radius, actor);
depth = depth == null ? Integer.MAX_VALUE : Math.max(1, depth); depth = depth == null ? Integer.MAX_VALUE : Math.max(1, depth);
we.checkMaxRadius(radius); we.checkMaxRadius(radius, actor);
BlockVector3 pos = session.getPlacementPosition(actor); BlockVector3 pos = session.getPlacementPosition(actor);
int affected = editSession.fillXZ(pos, pattern, radius, depth, true); int affected = editSession.fillXZ(pos, pattern, radius, depth, true);
@ -364,7 +365,7 @@ public class UtilityCommands {
//FAWE end //FAWE end
double radius = radiusExp.evaluate(); double radius = radiusExp.evaluate();
radius = Math.max(0, radius); radius = Math.max(0, radius);
we.checkMaxRadius(radius); we.checkMaxRadius(radius, actor);
int affected = editSession.drainArea(session.getPlacementPosition(actor), radius, waterlogged, plants); int affected = editSession.drainArea(session.getPlacementPosition(actor), radius, waterlogged, plants);
actor.print(Caption.of("worldedit.drain.drained", TextComponent.of(affected))); actor.print(Caption.of("worldedit.drain.drained", TextComponent.of(affected)));
return affected; return affected;
@ -383,7 +384,7 @@ public class UtilityCommands {
double radius double radius
) throws WorldEditException { ) throws WorldEditException {
radius = Math.max(0, radius); radius = Math.max(0, radius);
we.checkMaxRadius(radius); we.checkMaxRadius(radius, actor);
int affected = editSession.fixLiquid(session.getPlacementPosition(actor), radius, BlockTypes.LAVA); int affected = editSession.fixLiquid(session.getPlacementPosition(actor), radius, BlockTypes.LAVA);
actor.print(Caption.of("worldedit.fixlava.fixed", TextComponent.of(affected))); actor.print(Caption.of("worldedit.fixlava.fixed", TextComponent.of(affected)));
return affected; return affected;
@ -402,7 +403,7 @@ public class UtilityCommands {
double radius double radius
) throws WorldEditException { ) throws WorldEditException {
radius = Math.max(0, radius); radius = Math.max(0, radius);
we.checkMaxRadius(radius); we.checkMaxRadius(radius, actor);
int affected = editSession.fixLiquid(session.getPlacementPosition(actor), radius, BlockTypes.WATER); int affected = editSession.fixLiquid(session.getPlacementPosition(actor), radius, BlockTypes.WATER);
actor.print(Caption.of("worldedit.fixwater.fixed", TextComponent.of(affected))); actor.print(Caption.of("worldedit.fixwater.fixed", TextComponent.of(affected)));
return affected; return affected;
@ -423,7 +424,7 @@ public class UtilityCommands {
Integer height Integer height
) throws WorldEditException { ) throws WorldEditException {
size = Math.max(1, size); size = Math.max(1, size);
we.checkMaxRadius(size); we.checkMaxRadius(size, actor);
height = height != null height = height != null
? Math.min((world.getMaxY() - world.getMinY() + 1), height + 1) ? Math.min((world.getMaxY() - world.getMinY() + 1), height + 1)
@ -448,7 +449,7 @@ public class UtilityCommands {
Integer height Integer height
) throws WorldEditException { ) throws WorldEditException {
size = Math.max(1, size); size = Math.max(1, size);
we.checkMaxRadius(size); we.checkMaxRadius(size, actor);
height = height != null height = height != null
? Math.min((world.getMaxY() - world.getMinY() + 1), height + 1) ? Math.min((world.getMaxY() - world.getMinY() + 1), height + 1)
@ -476,7 +477,7 @@ public class UtilityCommands {
new MaskTraverser(mask).setNewExtent(editSession); new MaskTraverser(mask).setNewExtent(editSession);
//FAWE end //FAWE end
radius = Math.max(1, radius); radius = Math.max(1, radius);
we.checkMaxRadius(radius); we.checkMaxRadius(radius, actor);
int affected = editSession.removeNear(session.getPlacementPosition(actor), mask, radius); int affected = editSession.removeNear(session.getPlacementPosition(actor), mask, radius);
actor.print(Caption.of("worldedit.removenear.removed", TextComponent.of(affected))); actor.print(Caption.of("worldedit.removenear.removed", TextComponent.of(affected)));
@ -503,7 +504,7 @@ public class UtilityCommands {
new MaskTraverser(from).setNewExtent(editSession); new MaskTraverser(from).setNewExtent(editSession);
//FAWE end //FAWE end
radius = Math.max(1, radius); radius = Math.max(1, radius);
we.checkMaxRadius(radius); we.checkMaxRadius(radius, actor);
BlockVector3 base = session.getPlacementPosition(actor); BlockVector3 base = session.getPlacementPosition(actor);
BlockVector3 min = base.subtract(radius, radius, radius); BlockVector3 min = base.subtract(radius, radius, radius);
@ -542,7 +543,7 @@ public class UtilityCommands {
) throws WorldEditException { ) throws WorldEditException {
size = Math.max(1, size); size = Math.max(1, size);
height = Math.max(1, height); height = Math.max(1, height);
we.checkMaxRadius(size); we.checkMaxRadius(size, actor);
BlockVector3 position = session.getPlacementPosition(actor); BlockVector3 position = session.getPlacementPosition(actor);
@ -579,7 +580,7 @@ public class UtilityCommands {
) throws WorldEditException { ) throws WorldEditException {
size = Math.max(1, size); size = Math.max(1, size);
height = Math.max(1, height); height = Math.max(1, height);
we.checkMaxRadius(size); we.checkMaxRadius(size, actor);
int affected = editSession.thaw(session.getPlacementPosition(actor), size, height); int affected = editSession.thaw(session.getPlacementPosition(actor), size, height);
actor.print(Caption.of( actor.print(Caption.of(
@ -610,7 +611,7 @@ public class UtilityCommands {
) throws WorldEditException { ) throws WorldEditException {
size = Math.max(1, size); size = Math.max(1, size);
height = Math.max(1, height); height = Math.max(1, height);
we.checkMaxRadius(size); we.checkMaxRadius(size, actor);
final boolean onlyNormalDirt = !convertCoarse; final boolean onlyNormalDirt = !convertCoarse;
final int affected = editSession.green( final int affected = editSession.green(
@ -635,11 +636,9 @@ public class UtilityCommands {
Integer radius Integer radius
) throws WorldEditException { ) throws WorldEditException {
LocalConfiguration config = we.getConfiguration(); int defaultRadius = actor.getLimit().MAX_RADIUS != -1 ? Math.min(40, actor.getLimit().MAX_RADIUS) : 40;
int defaultRadius = config.maxRadius != -1 ? Math.min(40, config.maxRadius) : 40;
int size = radius != null ? Math.max(1, radius) : defaultRadius; int size = radius != null ? Math.max(1, radius) : defaultRadius;
we.checkMaxRadius(size); we.checkMaxRadius(size, actor);
Mask mask = new BlockTypeMask(editSession, BlockTypes.FIRE); Mask mask = new BlockTypeMask(editSession, BlockTypes.FIRE);
int affected = editSession.removeNear(session.getPlacementPosition(actor), mask, size); int affected = editSession.removeNear(session.getPlacementPosition(actor), mask, size);
@ -685,12 +684,12 @@ public class UtilityCommands {
actor.print(Caption.of("worldedit.butcher.explain-all")); actor.print(Caption.of("worldedit.butcher.explain-all"));
return 0; return 0;
} else if (radius == -1) { } else if (radius == -1) {
if (config.butcherMaxRadius != -1) { if (actor.getLimit().MAX_BUTCHER_RADIUS != -1) {
radius = config.butcherMaxRadius; radius = actor.getLimit().MAX_BUTCHER_RADIUS;
} }
} }
if (config.butcherMaxRadius != -1) { if (actor.getLimit().MAX_BUTCHER_RADIUS != -1) {
radius = Math.min(radius, config.butcherMaxRadius); radius = Math.min(radius, actor.getLimit().MAX_BUTCHER_RADIUS);
} }
CreatureButcher flags = new CreatureButcher(actor); CreatureButcher flags = new CreatureButcher(actor);

View File

@ -477,7 +477,7 @@ public class BrushTool
try { try {
new PatternTraverser(current).reset(editSession); new PatternTraverser(current).reset(editSession);
double size = current.getSize(); double size = current.getSize();
WorldEdit.getInstance().checkMaxBrushRadius(size); WorldEdit.getInstance().checkMaxBrushRadius(size, player);
brush.build(editSession, target.toBlockPoint(), current.getMaterial(), size); brush.build(editSession, target.toBlockPoint(), current.getMaterial(), size);
} catch (MaxChangedBlocksException e) { } catch (MaxChangedBlocksException e) {
player.print(Caption.of("worldedit.tool.max-block-changes")); player.print(Caption.of("worldedit.tool.max-block-changes"));

View File

@ -75,7 +75,7 @@ public @interface Confirm {
if (checkExisting(context)) { if (checkExisting(context)) {
return true; return true;
} }
int max = WorldEdit.getInstance().getConfiguration().maxRadius; int max = actor.getLimit().MAX_RADIUS;
if (max != -1 && value > max) { if (max != -1 && value > max) {
actor.print(Caption.of("fawe.cancel.reason.confirm.radius", actor.print(Caption.of("fawe.cancel.reason.confirm.radius",
value, max, getArgs(context) value, max, getArgs(context)

View File

@ -20,6 +20,8 @@
package com.sk89q.worldedit.internal.command.exception; package com.sk89q.worldedit.internal.command.exception;
import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.exception.BrushRadiusLimitException;
import com.fastasyncworldedit.core.exception.RadiusLimitException;
import com.fastasyncworldedit.core.internal.exception.FaweException; import com.fastasyncworldedit.core.internal.exception.FaweException;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.DisallowedItemException; import com.sk89q.worldedit.DisallowedItemException;
@ -134,6 +136,18 @@ public class WorldEditExceptionConverter extends ExceptionConverterHelper {
); );
} }
//FAWE start
@ExceptionMatch
public void convert(BrushRadiusLimitException e) throws CommandException {
throw newCommandException(Caption.of("fawe.error.limit.max-brush-radius", TextComponent.of(e.getMaxRadius())), e);
}
@ExceptionMatch
public void convert(RadiusLimitException e) throws CommandException {
throw newCommandException(Caption.of("fawe.error.limit.max-radius", TextComponent.of(e.getMaxRadius())), e);
}
//FAWE end
@ExceptionMatch @ExceptionMatch
public void convert(UnknownDirectionException e) throws CommandException { public void convert(UnknownDirectionException e) throws CommandException {
throw newCommandException(e.getRichMessage(), e); throw newCommandException(e.getRichMessage(), e);

View File

@ -136,6 +136,14 @@ public class PropertiesConfiguration extends LocalConfiguration {
scriptsDir = getString("craftscript-dir", scriptsDir); scriptsDir = getString("craftscript-dir", scriptsDir);
butcherDefaultRadius = getInt("butcher-default-radius", butcherDefaultRadius); butcherDefaultRadius = getInt("butcher-default-radius", butcherDefaultRadius);
butcherMaxRadius = getInt("butcher-max-radius", butcherMaxRadius); butcherMaxRadius = getInt("butcher-max-radius", butcherMaxRadius);
//FAWE start
MAX_RADIUS = maxRadius;
MAX_BRUSH_RADIUS = maxBrushRadius;
MAX_SUPER_RADIUS = maxSuperPickaxeSize;
MAX_BUTCHER_RADIUS = butcherMaxRadius;
//FAWE end
allowSymlinks = getBool("allow-symbolic-links", allowSymlinks); allowSymlinks = getBool("allow-symbolic-links", allowSymlinks);
serverSideCUI = getBool("server-side-cui", serverSideCUI); serverSideCUI = getBool("server-side-cui", serverSideCUI);
extendedYLimit = getBool("extended-y-limit", extendedYLimit); extendedYLimit = getBool("extended-y-limit", extendedYLimit);

View File

@ -95,6 +95,13 @@ public class YAMLConfiguration extends LocalConfiguration {
butcherDefaultRadius = Math.max(-1, config.getInt("limits.butcher-radius.default", butcherDefaultRadius)); butcherDefaultRadius = Math.max(-1, config.getInt("limits.butcher-radius.default", butcherDefaultRadius));
butcherMaxRadius = Math.max(-1, config.getInt("limits.butcher-radius.maximum", butcherMaxRadius)); butcherMaxRadius = Math.max(-1, config.getInt("limits.butcher-radius.maximum", butcherMaxRadius));
//FAWE start
MAX_RADIUS = maxRadius;
MAX_BRUSH_RADIUS = maxBrushRadius;
MAX_SUPER_RADIUS = maxSuperPickaxeSize;
MAX_BUTCHER_RADIUS = butcherMaxRadius;
//FAWE end
disallowedBlocks = config.getStringList("limits.disallowed-blocks", Lists.newArrayList(getDefaultDisallowedBlocks())) disallowedBlocks = config.getStringList("limits.disallowed-blocks", Lists.newArrayList(getDefaultDisallowedBlocks()))
.stream() .stream()
.map(s -> s.contains(":") ? s.toLowerCase(Locale.ROOT) : ("minecraft:" + s).toLowerCase(Locale.ROOT)) .map(s -> s.contains(":") ? s.toLowerCase(Locale.ROOT) : ("minecraft:" + s).toLowerCase(Locale.ROOT))

View File

@ -137,6 +137,8 @@
"fawe.error.limit.disallowed-property": "Your limit disallows use of property '{0}'", "fawe.error.limit.disallowed-property": "Your limit disallows use of property '{0}'",
"fawe.error.region-mask-invalid": "Invalid region mask: {0}", "fawe.error.region-mask-invalid": "Invalid region mask: {0}",
"fawe.error.occurred-continuing": "Ignorable error occurred during edit: {0}", "fawe.error.occurred-continuing": "Ignorable error occurred during edit: {0}",
"fawe.error.limit.max-brush-radius": "Maximum brush radius in limit: {0}",
"fawe.error.limit.max-radius": "Maximum radius in limit: {0}",
"fawe.cancel.count": "Cancelled {0} edits.", "fawe.cancel.count": "Cancelled {0} edits.",
"fawe.cancel.reason.confirm": "Use //confirm to execute {0}", "fawe.cancel.reason.confirm": "Use //confirm to execute {0}",
"fawe.cancel.reason.confirm.region": "Your selection is large ({0} -> {1}, containing {3} blocks). Use //confirm to execute {2}", "fawe.cancel.reason.confirm.region": "Your selection is large ({0} -> {1}, containing {3} blocks). Use //confirm to execute {2}",