Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public class WorldEditPlugin extends JavaPlugin {
public void onLoad() {

//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.
Plugin[] plugins = Bukkit.getServer().getPluginManager().getPlugins();
for (Plugin p : plugins) {
Expand All @@ -138,6 +137,14 @@ public void onLoad() {
//noinspection ResultOfMethodCallIgnored
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();

// Setup platform
Expand All @@ -148,14 +155,14 @@ public void onLoad() {
migrateLegacyConfig();
//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
permissionAttachmentManager = new BukkitPermissionAttachmentManager(this);
//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);
if (Files.exists(delChunks)) {
ChunkDeleter.runFromFile(delChunks, true);
Expand Down Expand Up @@ -189,8 +196,6 @@ public void onEnable() {
new FaweBukkit(this);
//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());

PermissionsResolverManager.initialize(this); // Setup permission resolver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ limits:
max-polygonal-points:
default: -1
maximum: 20
# radius, superpickaxe, brush radius are ignored, use FAWE config limits
max-radius: -1
max-super-pickaxe-size: 5
max-brush-radius: 100
butcher-radius:
default: -1
# Ignored, use FAWE config limits
maximum: -1
disallowed-blocks:
- "minecraft:wheat"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public ScrollRange(BrushTool tool) {

@Override
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);
getTool().setRange(newSize);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public ScrollSize(BrushTool tool) {

@Override
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));
getTool().setSize(newSize);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fastasyncworldedit.core.limit.FaweLimit;
import com.fastasyncworldedit.core.limit.PropertyRemap;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockTypesCache;
Expand Down Expand Up @@ -138,8 +139,22 @@ public FaweLimit getLimit(Actor actor) {
);
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,
newLimit.MAX_ITERATIONS != -1 ? newLimit.MAX_ITERATIONS : Integer.MAX_VALUE
limit.MAX_ITERATIONS, 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,
Expand Down Expand Up @@ -342,6 +357,14 @@ public static class LIMITS extends ConfigBlock {
public int MAX_ITERATIONS = 1000;
@Comment("Max allowed entities (e.g. cows)")
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({
"Blockstates include Banner, Beacon, BrewingStand, Chest, CommandBlock, ",
"CreatureSpawner, Dispenser, Dropper, EndGateway, Furnace, Hopper, Jukebox, ",
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ public class FaweLimit {
public int MAX_ENTITIES = 0;
public int MAX_HISTORY = 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 SPEED_REDUCTION = Integer.MAX_VALUE;
public boolean FAST_PLACEMENT = false;
Expand Down Expand Up @@ -119,6 +123,10 @@ public void THROW_MAX_ENTITIES(int amt) {
MAX.UNIVERSAL_DISALLOWED_BLOCKS = false;
MAX.DISALLOWED_BLOCKS = 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() {
Expand Down Expand Up @@ -244,7 +252,12 @@ public boolean isUnlimited() {
&& (STRIP_NBT == null || STRIP_NBT.isEmpty())
// && !UNIVERSAL_DISALLOWED_BLOCKS --> do not include this, it effectively has no relevance
&& (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) {
Expand All @@ -265,6 +278,10 @@ public void set(FaweLimit limit) {
UNIVERSAL_DISALLOWED_BLOCKS = limit.UNIVERSAL_DISALLOWED_BLOCKS;
DISALLOWED_BLOCKS = limit.DISALLOWED_BLOCKS;
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() {
Expand All @@ -286,6 +303,10 @@ public FaweLimit copy() {
limit.UNIVERSAL_DISALLOWED_BLOCKS = UNIVERSAL_DISALLOWED_BLOCKS;
limit.DISALLOWED_BLOCKS = DISALLOWED_BLOCKS;
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,26 @@
public abstract class LocalConfiguration {

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 traceUnflushedSessions = true;
public Set<String> disallowedBlocks = new HashSet<>();
protected BlockMask disallowedBlocksMask;
/**
* @deprecated Use actor's limit {@link com.fastasyncworldedit.core.limit.FaweLimit#MAX_CHANGES}
*/
@Deprecated
public int defaultChangeLimit = -1;
/**
* @deprecated Use actor's limit {@link com.fastasyncworldedit.core.limit.FaweLimit#MAX_CHANGES}
*/
@Deprecated
public int maxChangeLimit = -1;
public int defaultVerticalHeight = 256;
public int defaultMaxPolygonalPoints = -1;
Expand All @@ -68,8 +82,20 @@ public abstract class LocalConfiguration {
public boolean snapshotsConfigured = false;
public SnapshotRepository snapshotRepo = null;
public SnapshotDatabase snapshotDatabase = null;
/**
* @deprecated Use actor's limit {@link com.fastasyncworldedit.core.limit.FaweLimit#MAX_RADIUS}
*/
@Deprecated
public int maxRadius = -1;
/**
* @deprecated Use actor's limit {@link com.fastasyncworldedit.core.limit.FaweLimit#MAX_SUPER_PICKAXE_SIZE}
*/
@Deprecated
public int maxSuperPickaxeSize = 5;
/**
* @deprecated Use actor's limit {@link com.fastasyncworldedit.core.limit.FaweLimit#MAX_BRUSH_RADIUS}
*/
@Deprecated
public int maxBrushRadius = 6;
public boolean logCommands = false;
public String logFile = "";
Expand All @@ -92,6 +118,10 @@ public abstract class LocalConfiguration {
public String scriptsDir = "craftscripts";
public boolean showHelpInfo = true; // unused
public int butcherDefaultRadius = -1;
/**
* @deprecated Use actor's limit {@link com.fastasyncworldedit.core.limit.FaweLimit#MAX_BUTCHER_RADIUS}
*/
@Deprecated
public int butcherMaxRadius = -1;
public boolean allowSymlinks = false;
public boolean serverSideCUI = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,24 @@

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.
*
* @deprecated Use {@link RadiusLimitException}
*/
@Deprecated
public class MaxBrushRadiusException extends MaxRadiusException {

//FAWE start

/**
* @deprecated Use {@link BrushRadiusLimitException}
*/
@Deprecated
public MaxBrushRadiusException() {
}
//FAWE end
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,24 @@

package com.sk89q.worldedit;

import com.fastasyncworldedit.core.exception.RadiusLimitException;

/**
* Thrown when a maximum radius is reached, such as, for example,
* in the case of a sphere command.
*
* @deprecated Use {@link RadiusLimitException}
*/
@Deprecated
public class MaxRadiusException extends WorldEditException {

//FAWE start
/**
* @deprecated Use {@link RadiusLimitException}
*/
@Deprecated
public MaxRadiusException() {
}
//FAWE end

}
Loading
Loading