Allow merging of dispatchers during command registration
This commit is contained in:
parent
3ee4ab1e73
commit
6138a20105
@ -67,6 +67,8 @@ public class Settings extends Config {
|
||||
public HISTORY HISTORY;
|
||||
@Create
|
||||
public PATHS PATHS;
|
||||
@Create
|
||||
public REGION_RESTRICTIONS_OPTIONS REGION_RESTRICTIONS_OPTIONS;
|
||||
|
||||
@Comment("Paths for various directories")
|
||||
public static final class PATHS {
|
||||
@ -74,6 +76,8 @@ public class Settings extends Config {
|
||||
@Comment({
|
||||
"Put any minecraft or mod jars for FAWE to be aware of block textures",
|
||||
})
|
||||
public String PATTERNS = "patterns";
|
||||
public String MASKS = "masks";
|
||||
public String TEXTURES = "textures";
|
||||
public String HEIGHTMAP = "heightmap";
|
||||
public String HISTORY = "history";
|
||||
@ -86,6 +90,16 @@ public class Settings extends Config {
|
||||
public boolean PER_PLAYER_SCHEMATICS = true;
|
||||
}
|
||||
|
||||
@Comment("Region restriction settings")
|
||||
public static final class REGION_RESTRICTIONS_OPTIONS {
|
||||
@Comment({
|
||||
"What type of users are allowed to WorldEdit in a region",
|
||||
" - MEMBER = Players added to a region",
|
||||
" - OWNER = Players who own the region"
|
||||
})
|
||||
public String MODE = "MEMBER";
|
||||
}
|
||||
|
||||
|
||||
@Create // This value will be generated automatically
|
||||
public ConfigBlock<LIMITS> LIMITS;
|
||||
@ -334,6 +348,12 @@ public class Settings extends Config {
|
||||
"Might cause client-side FPS lagg in some situations"
|
||||
})
|
||||
public boolean KEEP_ENTITIES_IN_BLOCKS = false;
|
||||
|
||||
@Comment({
|
||||
"[SAFE] Experimental scripting support for Java 9",
|
||||
" - "
|
||||
})
|
||||
public boolean MODERN_CRAFTSCRIPTS = false;
|
||||
}
|
||||
|
||||
public static class WEB {
|
||||
|
@ -70,40 +70,12 @@ import java.util.List;
|
||||
@Command(aliases = {"brush", "br", "tool"},
|
||||
desc = "Commands to build and draw from far away. [More Info](https://git.io/vSPYf)"
|
||||
)
|
||||
public class BrushCommands extends MethodCommands {
|
||||
public class BrushCommands extends BrushProcessor {
|
||||
|
||||
public BrushCommands(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
}
|
||||
|
||||
private BrushSettings set(LocalSession session, CommandContext context, Brush brush) throws InvalidToolBindException {
|
||||
CommandLocals locals = context.getLocals();
|
||||
Actor actor = locals.get(Actor.class);
|
||||
BrushSettings bs = new BrushSettings();
|
||||
|
||||
BrushTool tool = session.getBrushTool((Player) actor, false);
|
||||
if (tool != null) {
|
||||
BrushSettings currentContext = tool.getContext();
|
||||
if (currentContext != null) {
|
||||
Brush currentBrush = currentContext.getBrush();
|
||||
if (currentBrush != null && currentBrush.getClass() == brush.getClass()) {
|
||||
bs = currentContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bs.addPermissions(getPermissions());
|
||||
|
||||
if (locals != null) {
|
||||
String args = (String) locals.get("arguments");
|
||||
if (args != null) {
|
||||
bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1));
|
||||
}
|
||||
}
|
||||
return bs.setBrush(brush);
|
||||
}
|
||||
|
||||
|
||||
@Command(
|
||||
aliases = {"blendball", "bb", "blend"},
|
||||
usage = "[radius=5]",
|
||||
@ -115,7 +87,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.blendball")
|
||||
public BrushSettings blendBallBrush(Player player, LocalSession session, @Optional("5") double radius, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
return set(session, context, new BlendBall()).setSize(radius);
|
||||
}
|
||||
|
||||
@ -129,7 +101,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.erode")
|
||||
public BrushSettings erodeBrush(Player player, LocalSession session, @Optional("5") double radius, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
return set(session, context, new ErodeBrush()).setSize(radius);
|
||||
}
|
||||
|
||||
@ -143,7 +115,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.pull")
|
||||
public BrushSettings pullBrush(Player player, LocalSession session, @Optional("5") double radius, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
return set(session, context, new RaiseBrush()).setSize(radius);
|
||||
}
|
||||
|
||||
@ -158,7 +130,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.sphere")
|
||||
public BrushSettings circleBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("5") double radius, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
return set(session, context, new CircleBrush(player)).setSize(radius).setFill(fill);
|
||||
}
|
||||
|
||||
@ -174,7 +146,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.recursive")
|
||||
public BrushSettings recursiveBrush(Player player, LocalSession session, EditSession editSession, Pattern fill, @Optional("5") double radius, @Switch('d') boolean depthFirst, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
return set(session, context,
|
||||
new RecurseBrush(depthFirst))
|
||||
.setSize(radius)
|
||||
@ -197,7 +169,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.line")
|
||||
public BrushSettings lineBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("0") double radius, @Switch('h') boolean shell, @Switch('s') boolean select, @Switch('f') boolean flat, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
return set(session, context,
|
||||
new LineBrush(shell, select, flat))
|
||||
.setSize(radius)
|
||||
@ -218,7 +190,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.spline")
|
||||
public BrushSettings splineBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("25") double radius, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
player.print(BBC.getPrefix() + BBC.BRUSH_SPLINE.f(radius));
|
||||
return set(session, context,
|
||||
new SplineBrush(player, session))
|
||||
@ -255,7 +227,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.spline")
|
||||
public BrushSettings catenaryBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("1.2") @Range(min=1) double lengthFactor, @Optional("0") double radius, @Switch('h') boolean shell, @Switch('s') boolean select, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
return set(session, context,
|
||||
new CatenaryBrush(shell, select, lengthFactor))
|
||||
.setSize(radius)
|
||||
@ -274,7 +246,7 @@ public class BrushCommands extends MethodCommands {
|
||||
@CommandPermissions("worldedit.brush.surfacespline") // 0, 0, 0, 10, 0,
|
||||
public BrushSettings surfaceSpline(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("0") double radius, @Optional("0") double tension, @Optional("0") double bias, @Optional("0") double continuity, @Optional("10") double quality, CommandContext context) throws WorldEditException {
|
||||
player.print(BBC.getPrefix() + BBC.BRUSH_SPLINE.f(radius));
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
return set(session, context,
|
||||
new SurfaceSpline(tension, bias, continuity, quality))
|
||||
.setSize(radius)
|
||||
@ -292,7 +264,7 @@ public class BrushCommands extends MethodCommands {
|
||||
@CommandPermissions("worldedit.brush.rock")
|
||||
public BrushSettings blobBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("10") Vector radius, @Optional("100") double sphericity, @Optional("30") double frequency, @Optional("50") double amplitude, CommandContext context) throws WorldEditException {
|
||||
double max = MathMan.max(radius.getBlockX(), radius.getBlockY(), radius.getBlockZ());
|
||||
worldEdit.checkMaxBrushRadius(max);
|
||||
getWorldEdit().checkMaxBrushRadius(max);
|
||||
Brush brush = new BlobBrush(radius.divide(max), frequency / 100, amplitude / 100, sphericity / 100);
|
||||
return set(session, context,
|
||||
brush)
|
||||
@ -314,7 +286,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.sphere")
|
||||
public BrushSettings sphereBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("2") @Range(min=0) double radius, @Switch('h') boolean hollow, @Switch('f') boolean falling, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
|
||||
Brush brush;
|
||||
if (hollow) {
|
||||
@ -355,7 +327,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.shatter")
|
||||
public BrushSettings shatterBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("10") double radius, @Optional("10") int count, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
return set(session, context,
|
||||
new ShatterBrush(count))
|
||||
.setSize(radius)
|
||||
@ -376,7 +348,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.stencil")
|
||||
public BrushSettings stencilBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("5") double radius, @Optional("") final String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Optional("1") final double yscale, @Switch('w') boolean onlyWhite, @Switch('r') boolean randomRotate, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
InputStream stream = getHeightmapStream(image);
|
||||
HeightBrush brush;
|
||||
try {
|
||||
@ -407,7 +379,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.stencil")
|
||||
public BrushSettings imageBrush(Player player, EditSession editSession, LocalSession session, @Optional("5") double radius, BufferedImage image, @Optional("1") @Range(min=Double.MIN_NORMAL) final double yscale, @Switch('a') boolean alpha, @Switch('f') boolean fadeOut, CommandContext context) throws WorldEditException, IOException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
if (yscale != 1) {
|
||||
ImageUtil.scaleAlpha(image, yscale);
|
||||
alpha = true;
|
||||
@ -435,7 +407,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.surface")
|
||||
public BrushSettings surfaceBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("5") double radius, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
return set(session, context, new SurfaceSphereBrush()).setFill(fill).setSize(radius);
|
||||
}
|
||||
|
||||
@ -453,7 +425,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.scatter")
|
||||
public BrushSettings scatterBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("5") double radius, @Optional("5") double points, @Optional("1") double distance, @Switch('o') boolean overlay, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
Brush brush;
|
||||
if (overlay) {
|
||||
brush = new ScatterOverlayBrush((int) points, (int) distance);
|
||||
@ -479,7 +451,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.populateschematic")
|
||||
public BrushSettings scatterSchemBrush(Player player, EditSession editSession, LocalSession session, Mask mask, String clipboard, @Optional("30") double radius, @Optional("50") double density, @Switch('r') boolean rotate, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
|
||||
|
||||
try {
|
||||
@ -514,7 +486,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.layer")
|
||||
public BrushSettings surfaceLayer(Player player, EditSession editSession, LocalSession session, double radius, CommandContext args, CommandContext context) throws WorldEditException, InvalidUsageException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
ParserContext parserContext = new ParserContext();
|
||||
parserContext.setActor(player);
|
||||
parserContext.setWorld(player.getWorld());
|
||||
@ -533,7 +505,7 @@ public class BrushCommands extends MethodCommands {
|
||||
} catch (IllegalArgumentException ignore) {
|
||||
for (int i = 1; i < args.argsLength(); i++) {
|
||||
String arg = args.getString(i);
|
||||
blocks.add(worldEdit.getBlockFactory().parseFromInput(arg, parserContext));
|
||||
blocks.add(getWorldEdit().getBlockFactory().parseFromInput(arg, parserContext));
|
||||
}
|
||||
}
|
||||
return set(session, context,
|
||||
@ -554,7 +526,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.splatter")
|
||||
public BrushSettings splatterBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("5") double radius, @Optional("1") double points, @Optional("5") double recursion, @Optional("true") boolean solid, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
return set(session, context,
|
||||
new SplatterBrush((int) points, (int) recursion, solid))
|
||||
.setSize(radius)
|
||||
@ -575,7 +547,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.scattercommand")
|
||||
public BrushSettings scatterCommandBrush(Player player, EditSession editSession, LocalSession session, double radius, double points, double distance, CommandContext args, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
return set(session, context,
|
||||
new ScatterCommand((int) points, (int) distance, args.getJoinedStrings(3)))
|
||||
.setSize(radius);
|
||||
@ -595,8 +567,8 @@ public class BrushCommands extends MethodCommands {
|
||||
@CommandPermissions("worldedit.brush.cylinder")
|
||||
public BrushSettings cylinderBrush(Player player, EditSession editSession, LocalSession session, Pattern fill,
|
||||
@Optional("2") double radius, @Optional("1") int height, @Switch('h') boolean hollow, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
worldEdit.checkMaxBrushRadius(height);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(height);
|
||||
|
||||
BrushSettings settings;
|
||||
if (hollow) {
|
||||
@ -627,9 +599,9 @@ public class BrushCommands extends MethodCommands {
|
||||
|
||||
Vector size = clipboard.getDimensions();
|
||||
|
||||
worldEdit.checkMaxBrushRadius(size.getBlockX());
|
||||
worldEdit.checkMaxBrushRadius(size.getBlockY());
|
||||
worldEdit.checkMaxBrushRadius(size.getBlockZ());
|
||||
getWorldEdit().checkMaxBrushRadius(size.getBlockX());
|
||||
getWorldEdit().checkMaxBrushRadius(size.getBlockY());
|
||||
getWorldEdit().checkMaxBrushRadius(size.getBlockZ());
|
||||
return set(session, context, new ClipboardBrush(holder, ignoreAir, usingOrigin));
|
||||
}
|
||||
|
||||
@ -649,7 +621,7 @@ public class BrushCommands extends MethodCommands {
|
||||
@Optional("2") double radius, @Optional("4") int iterations, @Switch('n')
|
||||
boolean naturalBlocksOnly, CommandContext context) throws WorldEditException {
|
||||
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
|
||||
FawePlayer fp = FawePlayer.wrap(player);
|
||||
FaweLimit limit = Settings.IMP.getLimit(fp);
|
||||
@ -669,7 +641,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.ex")
|
||||
public BrushSettings extinguishBrush(Player player, LocalSession session, EditSession editSession, @Optional("5") double radius, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
|
||||
Pattern fill = (new BaseBlock(0));
|
||||
return set(session, context,
|
||||
@ -693,7 +665,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.gravity")
|
||||
public BrushSettings gravityBrush(Player player, LocalSession session, @Optional("5") double radius, @Switch('h') boolean fromMaxY, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
|
||||
return set(session, context,
|
||||
new GravityBrush(fromMaxY))
|
||||
@ -755,6 +727,31 @@ public class BrushCommands extends MethodCommands {
|
||||
return terrainBrush(player, session, radius, image, rotation, yscale, true, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CONE, context);
|
||||
}
|
||||
|
||||
private BrushSettings terrainBrush(Player player, LocalSession session, double radius, String image, int rotation, double yscale, boolean flat, boolean randomRotate, boolean layers, boolean smooth, ScalableHeightMap.Shape shape, CommandContext context) throws WorldEditException {
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
InputStream stream = getHeightmapStream(image);
|
||||
HeightBrush brush;
|
||||
if (flat) {
|
||||
try {
|
||||
brush = new FlattenBrush(stream, rotation, yscale, layers, smooth, image.equalsIgnoreCase("#clipboard") ? session.getClipboard().getClipboard() : null, shape);
|
||||
} catch (EmptyClipboardException ignore) {
|
||||
brush = new FlattenBrush(stream, rotation, yscale, layers, smooth, null, shape);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
brush = new HeightBrush(stream, rotation, yscale, layers, smooth, image.equalsIgnoreCase("#clipboard") ? session.getClipboard().getClipboard() : null);
|
||||
} catch (EmptyClipboardException ignore) {
|
||||
brush = new HeightBrush(stream, rotation, yscale, layers, smooth, null);
|
||||
}
|
||||
}
|
||||
if (randomRotate) {
|
||||
brush.setRandomRotate(true);
|
||||
}
|
||||
return set(session, context,
|
||||
brush)
|
||||
.setSize(radius);
|
||||
}
|
||||
|
||||
private InputStream getHeightmapStream(String filename) {
|
||||
String filenamePng = (filename.endsWith(".png") ? filename : filename + ".png");
|
||||
File file = new File(Fawe.imp().getDirectory(), Settings.IMP.PATHS.HEIGHTMAP + File.separator + filenamePng);
|
||||
@ -786,31 +783,6 @@ public class BrushCommands extends MethodCommands {
|
||||
return null;
|
||||
}
|
||||
|
||||
private BrushSettings terrainBrush(Player player, LocalSession session, double radius, String image, int rotation, double yscale, boolean flat, boolean randomRotate, boolean layers, boolean smooth, ScalableHeightMap.Shape shape, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
InputStream stream = getHeightmapStream(image);
|
||||
HeightBrush brush;
|
||||
if (flat) {
|
||||
try {
|
||||
brush = new FlattenBrush(stream, rotation, yscale, layers, smooth, image.equalsIgnoreCase("#clipboard") ? session.getClipboard().getClipboard() : null, shape);
|
||||
} catch (EmptyClipboardException ignore) {
|
||||
brush = new FlattenBrush(stream, rotation, yscale, layers, smooth, null, shape);
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
brush = new HeightBrush(stream, rotation, yscale, layers, smooth, image.equalsIgnoreCase("#clipboard") ? session.getClipboard().getClipboard() : null);
|
||||
} catch (EmptyClipboardException ignore) {
|
||||
brush = new HeightBrush(stream, rotation, yscale, layers, smooth, null);
|
||||
}
|
||||
}
|
||||
if (randomRotate) {
|
||||
brush.setRandomRotate(true);
|
||||
}
|
||||
return set(session, context,
|
||||
brush)
|
||||
.setSize(radius);
|
||||
}
|
||||
|
||||
|
||||
@Command(
|
||||
aliases = {"copypaste", "copy", "paste", "cp", "copypasta"},
|
||||
@ -827,7 +799,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.copy")
|
||||
public BrushSettings copy(Player player, LocalSession session, @Optional("5") double radius, @Switch('r') boolean randomRotate, @Switch('a') boolean autoRotate, CommandContext context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
getWorldEdit().checkMaxBrushRadius(radius);
|
||||
player.print(BBC.getPrefix() + BBC.BRUSH_COPY.f(radius));
|
||||
|
||||
return set(session, context,
|
||||
@ -876,7 +848,7 @@ public class BrushCommands extends MethodCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.butcher")
|
||||
public BrushSettings butcherBrush(Player player, LocalSession session, CommandContext args, CommandContext context) throws WorldEditException {
|
||||
LocalConfiguration config = worldEdit.getConfiguration();
|
||||
LocalConfiguration config = getWorldEdit().getConfiguration();
|
||||
|
||||
double radius = args.argsLength() > 0 ? args.getDouble(0) : 5;
|
||||
double maxRadius = config.maxBrushRadius;
|
||||
|
@ -2,17 +2,19 @@ package com.sk89q.worldedit.command;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.object.brush.BrushSettings;
|
||||
import com.plotsquared.general.commands.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.command.tool.BrushTool;
|
||||
import com.sk89q.worldedit.command.tool.InvalidToolBindException;
|
||||
import com.sk89q.worldedit.command.tool.brush.Brush;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.util.command.CallableProcessor;
|
||||
|
||||
public class BrushProcessor implements CallableProcessor<BrushSettings> {
|
||||
public class BrushProcessor extends MethodCommands implements CallableProcessor<BrushSettings> {
|
||||
private final WorldEdit worldEdit;
|
||||
|
||||
public BrushProcessor(WorldEdit worldEdit) {
|
||||
@ -24,7 +26,7 @@ public class BrushProcessor implements CallableProcessor<BrushSettings> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public BrushSettings process(CommandLocals locals, BrushSettings settings) throws Command.CommandException, WorldEditException {
|
||||
public BrushSettings process(CommandLocals locals, BrushSettings settings) throws WorldEditException {
|
||||
Actor actor = locals.get(Actor.class);
|
||||
LocalSession session = worldEdit.getSessionManager().get(actor);
|
||||
session.setTool(null, (Player) actor);
|
||||
@ -36,4 +38,31 @@ public class BrushProcessor implements CallableProcessor<BrushSettings> {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public BrushSettings set(LocalSession session, CommandContext context, Brush brush) throws InvalidToolBindException {
|
||||
CommandLocals locals = context.getLocals();
|
||||
Actor actor = locals.get(Actor.class);
|
||||
BrushSettings bs = new BrushSettings();
|
||||
|
||||
BrushTool tool = session.getBrushTool((Player) actor, false);
|
||||
if (tool != null) {
|
||||
BrushSettings currentContext = tool.getContext();
|
||||
if (currentContext != null) {
|
||||
Brush currentBrush = currentContext.getBrush();
|
||||
if (currentBrush != null && currentBrush.getClass() == brush.getClass()) {
|
||||
bs = currentContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bs.addPermissions(getPermissions());
|
||||
|
||||
if (locals != null) {
|
||||
String args = (String) locals.get("arguments");
|
||||
if (args != null) {
|
||||
bs.addSetting(BrushSettings.SettingType.BRUSH, args.substring(args.indexOf(' ') + 1));
|
||||
}
|
||||
}
|
||||
return bs.setBrush(brush);
|
||||
}
|
||||
}
|
@ -33,34 +33,9 @@ import com.boydti.fawe.util.chat.UsageMessage;
|
||||
import com.boydti.fawe.wrappers.FakePlayer;
|
||||
import com.boydti.fawe.wrappers.LocationMaskedPlayerWrapper;
|
||||
import com.google.common.base.Joiner;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.minecraft.util.commands.CommandPermissionsException;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.BiomeCommands;
|
||||
import com.sk89q.worldedit.command.BrushCommands;
|
||||
import com.sk89q.worldedit.command.BrushOptionsCommands;
|
||||
import com.sk89q.worldedit.command.BrushProcessor;
|
||||
import com.sk89q.worldedit.command.ChunkCommands;
|
||||
import com.sk89q.worldedit.command.ClipboardCommands;
|
||||
import com.sk89q.worldedit.command.GenerationCommands;
|
||||
import com.sk89q.worldedit.command.HistoryCommands;
|
||||
import com.sk89q.worldedit.command.NavigationCommands;
|
||||
import com.sk89q.worldedit.command.OptionsCommands;
|
||||
import com.sk89q.worldedit.command.RegionCommands;
|
||||
import com.sk89q.worldedit.command.SchematicCommands;
|
||||
import com.sk89q.worldedit.command.ScriptingCommands;
|
||||
import com.sk89q.worldedit.command.SelectionCommands;
|
||||
import com.sk89q.worldedit.command.SnapshotCommands;
|
||||
import com.sk89q.worldedit.command.SnapshotUtilCommands;
|
||||
import com.sk89q.worldedit.command.SuperPickaxeCommands;
|
||||
import com.sk89q.worldedit.command.ToolCommands;
|
||||
import com.sk89q.worldedit.command.UtilityCommands;
|
||||
import com.sk89q.worldedit.command.WorldEditCommands;
|
||||
import com.sk89q.minecraft.util.commands.*;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.command.*;
|
||||
import com.sk89q.worldedit.command.argument.ReplaceParser;
|
||||
import com.sk89q.worldedit.command.argument.TreeGeneratorParser;
|
||||
import com.sk89q.worldedit.command.composition.ApplyCommand;
|
||||
@ -72,11 +47,7 @@ import com.sk89q.worldedit.event.platform.CommandEvent;
|
||||
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
|
||||
import com.sk89q.worldedit.function.factory.Deform;
|
||||
import com.sk89q.worldedit.function.factory.Deform.Mode;
|
||||
import com.sk89q.worldedit.internal.command.ActorAuthorizer;
|
||||
import com.sk89q.worldedit.internal.command.CommandLoggingHandler;
|
||||
import com.sk89q.worldedit.internal.command.UserCommandCompleter;
|
||||
import com.sk89q.worldedit.internal.command.WorldEditBinding;
|
||||
import com.sk89q.worldedit.internal.command.WorldEditExceptionConverter;
|
||||
import com.sk89q.worldedit.internal.command.*;
|
||||
import com.sk89q.worldedit.session.request.Request;
|
||||
import com.sk89q.worldedit.util.auth.AuthorizationException;
|
||||
import com.sk89q.worldedit.util.command.CommandCallable;
|
||||
@ -91,6 +62,7 @@ import com.sk89q.worldedit.util.command.parametric.ParametricBuilder;
|
||||
import com.sk89q.worldedit.util.eventbus.Subscribe;
|
||||
import com.sk89q.worldedit.util.logging.DynamicStreamHandler;
|
||||
import com.sk89q.worldedit.util.logging.LogFormat;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
@ -103,7 +75,6 @@ import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static com.sk89q.worldedit.util.command.composition.LegacyCommandAdapter.adapt;
|
||||
|
||||
@ -128,6 +99,7 @@ public final class CommandManager {
|
||||
|
||||
private ParametricBuilder builder;
|
||||
private Map<Object, String[]> methodMap;
|
||||
private Map<CommandCallable, String[][]> commandMap;
|
||||
|
||||
private static CommandManager INSTANCE;
|
||||
|
||||
@ -164,6 +136,7 @@ public final class CommandManager {
|
||||
builder.addInvokeListener(new CommandLoggingHandler(worldEdit, commandLog));
|
||||
|
||||
this.methodMap = new ConcurrentHashMap<>();
|
||||
this.commandMap = new ConcurrentHashMap<>();
|
||||
|
||||
try {
|
||||
Class.forName("com.intellectualcrafters.plot.PS");
|
||||
@ -191,19 +164,60 @@ public final class CommandManager {
|
||||
*/
|
||||
public void registerCommands(Object clazz, String... aliases) {
|
||||
if (platform != null) {
|
||||
DispatcherNode graph = new CommandGraph().builder(builder).commands();
|
||||
if (aliases.length == 0) {
|
||||
graph = graph.registerMethods(clazz);
|
||||
builder.registerMethodsAsCommands(dispatcher, clazz);
|
||||
} else {
|
||||
graph = graph.group(aliases).registerMethods(clazz).parent();
|
||||
DispatcherNode graph = new CommandGraph().builder(builder).commands();
|
||||
graph = graph.registerMethods(clazz);
|
||||
dispatcher.registerCommand(graph.graph().getDispatcher(), aliases);
|
||||
}
|
||||
Dispatcher dispatcher = graph.graph().getDispatcher();
|
||||
platform.registerCommands(dispatcher);
|
||||
} else {
|
||||
methodMap.put(clazz, aliases);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a command with the provided aliases and register all methods of the class as sub commands.<br>
|
||||
* - You should try to register commands during startup
|
||||
*
|
||||
* @param clazz The class containing all the sub command methods
|
||||
* @param aliases The aliases to give the command
|
||||
*/
|
||||
public void registerCommands(Object clazz, Object processor, String... aliases) {
|
||||
if (platform != null) {
|
||||
if (aliases.length == 0) {
|
||||
builder.registerMethodsAsCommands(dispatcher, clazz);
|
||||
} else {
|
||||
DispatcherNode graph = new CommandGraph().builder(builder).commands();
|
||||
graph = graph.registerMethods(clazz);
|
||||
dispatcher.registerCommand(graph.graph().getDispatcher(), aliases);
|
||||
}
|
||||
platform.registerCommands(dispatcher);
|
||||
} else {
|
||||
methodMap.put(clazz, aliases);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerCommand(String[] aliases, Command command, CommandCallable callable) {
|
||||
if (platform != null) {
|
||||
if (aliases.length == 0) {
|
||||
dispatcher.registerCommand(callable, command.aliases());
|
||||
} else {
|
||||
DispatcherNode graph = new CommandGraph().builder(builder).commands();
|
||||
graph = graph.register(callable, command.aliases());
|
||||
dispatcher.registerCommand(graph.graph().getDispatcher(), aliases);
|
||||
}
|
||||
platform.registerCommands(dispatcher);
|
||||
} else {
|
||||
commandMap.putIfAbsent(callable, new String[][] {aliases, command.aliases()});
|
||||
}
|
||||
}
|
||||
|
||||
public ParametricBuilder getBuilder() {
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the dispatcher
|
||||
*/
|
||||
@ -219,7 +233,16 @@ public final class CommandManager {
|
||||
graph = graph.group(aliases).registerMethods(entry.getKey()).parent();
|
||||
}
|
||||
}
|
||||
methodMap.clear();
|
||||
|
||||
for (Map.Entry<CommandCallable, String[][]> entry : commandMap.entrySet()) {
|
||||
String[][] aliases = entry.getValue();
|
||||
CommandCallable callable = entry.getKey();
|
||||
if (aliases[0].length == 0) {
|
||||
graph = graph.register(callable, aliases[1]);
|
||||
} else {
|
||||
graph = graph.group(aliases[0]).register(callable, aliases[1]).parent();
|
||||
}
|
||||
}
|
||||
|
||||
dispatcher = graph
|
||||
.group("/anvil")
|
||||
@ -245,7 +268,6 @@ public final class CommandManager {
|
||||
.groupAndDescribe(BrushCommands.class)
|
||||
.registerMethods(new ToolCommands(worldEdit))
|
||||
.registerMethods(new BrushOptionsCommands(worldEdit))
|
||||
.registerMethods(new BrushCommands(worldEdit), new BrushProcessor(worldEdit))
|
||||
.register(adapt(new ShapedBrushCommand(new DeformCommand(), "worldedit.brush.deform")), "deform")
|
||||
.register(adapt(new ShapedBrushCommand(new ApplyCommand(new ReplaceParser(), "Set all blocks within region"), "worldedit.brush.set")), "set")
|
||||
.register(adapt(new ShapedBrushCommand(new PaintCommand(), "worldedit.brush.paint")), "paint")
|
||||
|
@ -60,11 +60,21 @@ public class SimpleDispatcher implements Dispatcher {
|
||||
// Check for replacements
|
||||
for (String a : alias) {
|
||||
String lower = a.toLowerCase();
|
||||
if (commands.containsKey(lower)) {
|
||||
CommandMapping existing = commands.get(lower);
|
||||
if (existing != null) {
|
||||
CommandCallable existingCallable = existing.getCallable();
|
||||
if (existingCallable instanceof Dispatcher && callable instanceof Dispatcher) {
|
||||
Dispatcher existingDispatcher = (Dispatcher) existingCallable;
|
||||
Dispatcher newDispatcher = (Dispatcher) callable;
|
||||
for (CommandMapping add : newDispatcher.getCommands()) {
|
||||
existingDispatcher.registerCommand(add.getCallable(), add.getAllAliases());
|
||||
}
|
||||
} else {
|
||||
Fawe.debug("Replacing commands is currently undefined behavior: " + StringMan.getString(alias));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (String a : alias) {
|
||||
String lower = a.toLowerCase();
|
||||
|
Loading…
Reference in New Issue
Block a user