geforkt von Mirrors/FastAsyncWorldEdit
CommandContext + Confirmation
Use InjectedValueAccess instead Fix command confirmation
Dieser Commit ist enthalten in:
Ursprung
81298bf555
Commit
f500b5e056
@ -5,7 +5,7 @@ import com.boydti.fawe.jnbt.anvil.HeightMapMCAGenerator;
|
||||
import com.boydti.fawe.object.FawePlayer;
|
||||
import com.boydti.fawe.object.changeset.CFIChangeSet;
|
||||
import org.enginehub.piston.annotation.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@ -34,7 +34,7 @@ public class CFICommand extends MethodCommands {
|
||||
desc = "Start CreateFromImage"
|
||||
)
|
||||
@CommandPermissions("worldedit.anvil.cfi")
|
||||
public void cfi(FawePlayer fp, CommandContext context) throws CommandException, IOException {
|
||||
public void cfi(FawePlayer fp, InjectedValueAccess context) throws CommandException, IOException {
|
||||
CFICommands.CFISettings settings = child.getSettings(fp);
|
||||
settings.popMessages(fp);
|
||||
dispatch(fp, settings, context);
|
||||
@ -47,7 +47,7 @@ public class CFICommand extends MethodCommands {
|
||||
}
|
||||
}
|
||||
|
||||
private void dispatch(FawePlayer fp, CFICommands.CFISettings settings, CommandContext context) throws CommandException {
|
||||
private void dispatch(FawePlayer fp, CFICommands.CFISettings settings, InjectedValueAccess context) throws CommandException {
|
||||
if (!settings.hasGenerator()) {
|
||||
if (context.argsLength() == 0) {
|
||||
String hmCmd = child.alias() + " ";
|
||||
|
@ -23,7 +23,7 @@ import com.boydti.fawe.util.image.ImageUtil;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
||||
import java.util.stream.IntStream;
|
||||
import org.enginehub.piston.annotation.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||
import com.sk89q.worldedit.EmptyClipboardException;
|
||||
@ -839,7 +839,7 @@ public class CFICommands extends MethodCommands {
|
||||
desc = "Select a mask"
|
||||
)
|
||||
@CommandPermissions("worldedit.anvil.cfi")
|
||||
public void mask(FawePlayer fp, @Optional FawePrimitiveBinding.ImageUri imageMask, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name='w', desc = "TODO") boolean disableWhiteOnly, CommandContext context) throws ParameterException{
|
||||
public void mask(FawePlayer fp, @Optional FawePrimitiveBinding.ImageUri imageMask, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name='w', desc = "TODO") boolean disableWhiteOnly, InjectedValueAccess context) throws ParameterException{
|
||||
CFISettings settings = assertSettings(fp);
|
||||
String[] split = getArguments(context).split(" ");
|
||||
int index = 2;
|
||||
@ -864,7 +864,7 @@ public class CFICommands extends MethodCommands {
|
||||
desc = "Select a pattern"
|
||||
)
|
||||
@CommandPermissions("worldedit.anvil.cfi")
|
||||
public void pattern(FawePlayer fp, @Arg(name = "pattern", desc = "Pattern", def = "") Pattern pattern, CommandContext context) throws ParameterException, CommandException {
|
||||
public void pattern(FawePlayer fp, @Arg(name = "pattern", desc = "Pattern", def = "") Pattern pattern, InjectedValueAccess context) throws ParameterException, CommandException {
|
||||
CFISettings settings = assertSettings(fp);
|
||||
String[] split = getArguments(context).split(" ");
|
||||
int index = 2;
|
||||
@ -904,7 +904,7 @@ public class CFICommands extends MethodCommands {
|
||||
desc = "Select an image"
|
||||
)
|
||||
@CommandPermissions("worldedit.anvil.cfi")
|
||||
public void image(FawePlayer fp, @Optional FawePrimitiveBinding.ImageUri image, CommandContext context) throws ParameterException, CommandException {
|
||||
public void image(FawePlayer fp, @Optional FawePrimitiveBinding.ImageUri image, InjectedValueAccess context) throws ParameterException, CommandException {
|
||||
CFISettings settings = getSettings(fp);
|
||||
String[] split = getArguments(context).split(" ");
|
||||
int index = 2;
|
||||
|
@ -25,9 +25,9 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.math.Vector2;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.session.request.Request;
|
||||
import com.sk89q.worldedit.util.command.binding.Range;
|
||||
import com.sk89q.worldedit.internal.annotation.Range;
|
||||
import com.sk89q.worldedit.util.command.binding.Text;
|
||||
import com.sk89q.worldedit.util.command.binding.Validate;
|
||||
import com.sk89q.worldedit.internal.annotation.Validate;
|
||||
import com.sk89q.worldedit.util.command.parametric.ArgumentStack;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingBehavior;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingMatch;
|
||||
|
@ -1,7 +1,6 @@
|
||||
package com.boydti.fawe.object;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.command.CFICommands;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.object.brush.visualization.VirtualWorld;
|
||||
@ -11,12 +10,11 @@ import com.boydti.fawe.object.task.SimpleAsyncNotifyQueue;
|
||||
import com.boydti.fawe.regions.FaweMaskManager;
|
||||
import com.boydti.fawe.util.EditSessionBuilder;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.SetQueue;
|
||||
import com.boydti.fawe.util.TaskManager;
|
||||
import com.boydti.fawe.util.WEManager;
|
||||
import com.boydti.fawe.wrappers.LocationMaskedPlayerWrapper;
|
||||
import com.boydti.fawe.wrappers.PlayerWrapper;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.EmptyClipboardException;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
@ -53,9 +51,7 @@ import java.text.NumberFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -151,19 +147,20 @@ public abstract class FawePlayer<T> extends Metadatable {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
private void setConfirmTask(@NotNull Runnable task, CommandContext context, String command) {
|
||||
private void setConfirmTask(@NotNull Runnable task, InjectedValueAccess context, String command) {
|
||||
CommandEvent event = new CommandEvent(getPlayer(), command);
|
||||
if (task != null) {
|
||||
Runnable newTask = () -> PlatformCommandManager.getInstance().handleCommandTask(() -> {
|
||||
task.run();
|
||||
return null;
|
||||
}, context.getLocals());
|
||||
}, context, getPlayer(), getSession(), event);
|
||||
setMeta("cmdConfirm", newTask);
|
||||
} else {
|
||||
setMeta("cmdConfirm", new CommandEvent(getPlayer(), command));
|
||||
setMeta("cmdConfirm", event);
|
||||
}
|
||||
}
|
||||
|
||||
public void checkConfirmation(@NotNull Runnable task, String command, int times, int limit, CommandContext context) throws RegionOperationException {
|
||||
public void checkConfirmation(@NotNull Runnable task, String command, int times, int limit, InjectedValueAccess context) throws RegionOperationException {
|
||||
if (command != null && !getMeta("cmdConfirmRunning", false)) {
|
||||
if (times > limit) {
|
||||
setConfirmTask(task, context, command);
|
||||
@ -174,7 +171,7 @@ public abstract class FawePlayer<T> extends Metadatable {
|
||||
task.run();
|
||||
}
|
||||
|
||||
public void checkConfirmationRadius(@NotNull Runnable task, String command, int radius, CommandContext context) throws RegionOperationException {
|
||||
public void checkConfirmationRadius(@NotNull Runnable task, String command, int radius, InjectedValueAccess context) throws RegionOperationException {
|
||||
if (command != null && !getMeta("cmdConfirmRunning", false)) {
|
||||
if (radius > 0) {
|
||||
if (radius > 448) {
|
||||
@ -187,7 +184,7 @@ public abstract class FawePlayer<T> extends Metadatable {
|
||||
task.run();
|
||||
}
|
||||
|
||||
public void checkConfirmationStack(@NotNull Runnable task, String command, Region region, int times, CommandContext context) throws RegionOperationException {
|
||||
public void checkConfirmationStack(@NotNull Runnable task, String command, Region region, int times, InjectedValueAccess context) throws RegionOperationException {
|
||||
if (command != null && !getMeta("cmdConfirmRunning", false)) {
|
||||
if (region != null) {
|
||||
BlockVector3 min = region.getMinimumPoint();
|
||||
@ -204,7 +201,7 @@ public abstract class FawePlayer<T> extends Metadatable {
|
||||
task.run();
|
||||
}
|
||||
|
||||
public void checkConfirmationRegion(@NotNull Runnable task, String command, Region region, CommandContext context) throws RegionOperationException {
|
||||
public void checkConfirmationRegion(@NotNull Runnable task, String command, Region region, InjectedValueAccess context) throws RegionOperationException {
|
||||
if (command != null && !getMeta("cmdConfirmRunning", false)) {
|
||||
if (region != null) {
|
||||
BlockVector3 min = region.getMinimumPoint();
|
||||
@ -361,28 +358,6 @@ public abstract class FawePlayer<T> extends Metadatable {
|
||||
return getPlayer().getWorld();
|
||||
}
|
||||
|
||||
public FaweQueue getFaweQueue(boolean autoQueue) {
|
||||
return getFaweQueue(true, autoQueue);
|
||||
}
|
||||
|
||||
public FaweQueue getFaweQueue(boolean fast, boolean autoQueue) {
|
||||
CFICommands.CFISettings settings = this.getMeta("CFISettings");
|
||||
if (settings != null && settings.hasGenerator()) {
|
||||
return settings.getGenerator();
|
||||
} else {
|
||||
return SetQueue.IMP.getNewQueue(getWorld(), true, autoQueue);
|
||||
}
|
||||
}
|
||||
|
||||
public FaweQueue getMaskedFaweQueue(boolean autoQueue) {
|
||||
FaweQueue queue = getFaweQueue(autoQueue);
|
||||
Region[] allowedRegions = getCurrentRegions();
|
||||
if (allowedRegions.length == 1 && allowedRegions[0].isGlobal()) {
|
||||
return queue;
|
||||
}
|
||||
return new MaskedFaweQueue(queue, allowedRegions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all the undo EditSession's from disk for a world <br>
|
||||
* - Usually already called when necessary
|
||||
|
@ -13,7 +13,7 @@ import com.sk89q.worldedit.util.command.Description;
|
||||
import com.sk89q.worldedit.util.command.Dispatcher;
|
||||
import com.sk89q.worldedit.util.command.Parameter;
|
||||
import com.sk89q.worldedit.util.command.PrimaryAliasComparator;
|
||||
import com.sk89q.worldedit.util.command.binding.Range;
|
||||
import com.sk89q.worldedit.internal.annotation.Range;
|
||||
import com.sk89q.worldedit.util.command.parametric.ParameterData;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
|
@ -489,7 +489,7 @@ public abstract class CommandsManager<T> {
|
||||
newFlags.add(flags[i]);
|
||||
}
|
||||
|
||||
CommandContext context = new CommandContext(newArgs, valueFlags);
|
||||
InjectedValueAccess context = new InjectedValueAccess(newArgs, valueFlags);
|
||||
|
||||
if (context.argsLength() < cmd.min()) {
|
||||
throw new CommandUsageException("Too few arguments.", getUsage(args, level, cmd));
|
||||
|
@ -60,7 +60,7 @@ import com.boydti.fawe.object.mask.IdMask;
|
||||
import com.boydti.fawe.util.ColorUtil;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.boydti.fawe.util.image.ImageUtil;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.minecraft.util.commands.Step;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
@ -149,7 +149,7 @@ public class BrushCommands {
|
||||
@CommandPermissions("worldedit.brush.blendball")
|
||||
public BrushSettings blendBallBrush(Player player, LocalSession session,
|
||||
@Arg(desc = "The radius to sample for blending", def = "5")
|
||||
double radius, CommandContext context) throws WorldEditException {
|
||||
double radius, InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
Brush brush = new BlendBall();
|
||||
CommandLocals locals = context.getLocals();
|
||||
@ -189,7 +189,7 @@ public class BrushCommands {
|
||||
@CommandPermissions("worldedit.brush.erode")
|
||||
public BrushSettings erodeBrush(Player player, LocalSession session,
|
||||
@Arg(desc = "The radius for eroding", def = "5")
|
||||
double radius, CommandContext context) throws WorldEditException {
|
||||
double radius, InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
Brush brush = new ErodeBrush();
|
||||
CommandLocals locals = context.getLocals();
|
||||
@ -229,7 +229,7 @@ public class BrushCommands {
|
||||
@CommandPermissions("worldedit.brush.pull")
|
||||
public BrushSettings pullBrush(Player player, LocalSession session,
|
||||
@Arg(desc = "The radius to sample for blending", def = "5")
|
||||
double radius, CommandContext context) throws WorldEditException {
|
||||
double radius, InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
Brush brush = new RaiseBrush();
|
||||
CommandLocals locals = context.getLocals();
|
||||
@ -269,7 +269,7 @@ public class BrushCommands {
|
||||
@CommandPermissions("worldedit.brush.sphere")
|
||||
public BrushSettings circleBrush(Player player, EditSession editSession, LocalSession session, Pattern fill,
|
||||
@Arg(desc = "The radius to sample for blending", def = "5")
|
||||
double radius, CommandContext context) throws WorldEditException {
|
||||
double radius, InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
Brush brush = new CircleBrush(player);
|
||||
CommandLocals locals = context.getLocals();
|
||||
@ -313,7 +313,7 @@ public class BrushCommands {
|
||||
@CommandPermissions("worldedit.brush.recursive")
|
||||
public BrushSettings recursiveBrush(Player player, LocalSession session, EditSession editSession, Pattern fill,
|
||||
@Arg(desc = "The radius to sample for blending", def = "5")
|
||||
double radius, @Switch(name='d', desc = "TODO") boolean depthFirst, CommandContext context) throws WorldEditException {
|
||||
double radius, @Switch(name='d', desc = "TODO") boolean depthFirst, InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
Brush brush = new RecurseBrush(depthFirst);
|
||||
CommandLocals locals = context.getLocals();
|
||||
@ -358,7 +358,7 @@ public class BrushCommands {
|
||||
@CommandPermissions("worldedit.brush.line")
|
||||
public BrushSettings lineBrush(Player player, EditSession editSession, LocalSession session, Pattern fill,
|
||||
@Arg(desc = "The radius to sample for blending", def = "0")
|
||||
double radius, @Switch(name='h', desc = "TODO") boolean shell, @Switch(name='s', desc = "TODO") boolean select, @Switch(name='f', desc = "TODO") boolean flat, CommandContext context) throws WorldEditException {
|
||||
double radius, @Switch(name='h', desc = "TODO") boolean shell, @Switch(name='s', desc = "TODO") boolean select, @Switch(name='f', desc = "TODO") boolean flat, InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
Brush brush = new LineBrush(shell, select, flat);
|
||||
CommandLocals locals = context.getLocals();
|
||||
@ -404,7 +404,7 @@ public class BrushCommands {
|
||||
@CommandPermissions("worldedit.brush.spline")
|
||||
public BrushSettings splineBrush(Player player, EditSession editSession, LocalSession session, Pattern fill,
|
||||
@Arg(desc = "The radius to sample for blending", def = "25")
|
||||
double radius, CommandContext context) throws WorldEditException {
|
||||
double radius, InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
player.print(BBC.BRUSH_SPLINE.f(radius));
|
||||
Brush brush = new SplineBrush(player, session);
|
||||
@ -448,7 +448,7 @@ public class BrushCommands {
|
||||
"Set [copies] to a value > 0 if you want to have your selection pasted a limited amount of times equally spaced on the curve"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.sweep")
|
||||
public BrushSettings sweepBrush(Player player, LocalSession session, EditSession editSession, @Arg(name = "copies", desc = "int", def = "-1") int copies, CommandContext context) throws WorldEditException {
|
||||
public BrushSettings sweepBrush(Player player, LocalSession session, EditSession editSession, @Arg(name = "copies", desc = "int", def = "-1") int copies, InjectedValueAccess context) throws WorldEditException {
|
||||
player.print(BBC.BRUSH_SPLINE.s());
|
||||
Brush brush = new SweepBrush(copies);
|
||||
CommandLocals locals = context.getLocals();
|
||||
@ -494,7 +494,7 @@ public class BrushCommands {
|
||||
@CommandPermissions("worldedit.brush.spline")
|
||||
public BrushSettings catenaryBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("1.2") @Range(min=1) double lengthFactor,
|
||||
@Arg(desc = "The radius to sample for blending", def = "0")
|
||||
double radius, @Switch(name='h', desc = "TODO") boolean shell, @Switch(name='s', desc = "TODO") boolean select, @Switch(name='d', desc = "TODO") boolean facingDirection, CommandContext context) throws WorldEditException {
|
||||
double radius, @Switch(name='h', desc = "TODO") boolean shell, @Switch(name='s', desc = "TODO") boolean select, @Switch(name='d', desc = "TODO") boolean facingDirection, InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
Brush brush = new CatenaryBrush(shell, select, facingDirection, lengthFactor);
|
||||
CommandLocals locals = context.getLocals();
|
||||
@ -537,7 +537,7 @@ public class BrushCommands {
|
||||
@CommandPermissions("worldedit.brush.surfacespline") // 0, 0, 0, 10, 0,
|
||||
public BrushSettings surfaceSpline(Player player, EditSession editSession, LocalSession session, Pattern fill,
|
||||
@Arg(desc = "The radius to sample for blending", def = "0")
|
||||
double radius, @Arg(name = "tension", desc = "double", def = "0") double tension, @Arg(name = "bias", desc = "double", def = "0") double bias, @Arg(name = "continuity", desc = "double", def = "0") double continuity, @Arg(name = "quality", desc = "double", def = "10") double quality, CommandContext context) throws WorldEditException {
|
||||
double radius, @Arg(name = "tension", desc = "double", def = "0") double tension, @Arg(name = "bias", desc = "double", def = "0") double bias, @Arg(name = "continuity", desc = "double", def = "0") double continuity, @Arg(name = "quality", desc = "double", def = "10") double quality, InjectedValueAccess context) throws WorldEditException {
|
||||
player.print(BBC.BRUSH_SPLINE.f(radius));
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
Brush brush = new SurfaceSpline(tension, bias, continuity, quality);
|
||||
@ -577,7 +577,7 @@ public class BrushCommands {
|
||||
desc = "Creates a distorted sphere"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.rock")
|
||||
public BrushSettings blobBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Vector3", def = "10") Vector3 radius, @Arg(name = "sphericity", desc = "double", def = "100") double sphericity, @Arg(name = "frequency", desc = "double", def = "30") double frequency, @Arg(name = "amplitude", desc = "double", def = "50") double amplitude, CommandContext context) throws WorldEditException {
|
||||
public BrushSettings blobBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Vector3", def = "10") Vector3 radius, @Arg(name = "sphericity", desc = "double", def = "100") double sphericity, @Arg(name = "frequency", desc = "double", def = "30") double frequency, @Arg(name = "amplitude", desc = "double", def = "50") double amplitude, InjectedValueAccess context) throws WorldEditException {
|
||||
double max = MathMan.max(radius.getX(), radius.getY(), radius.getZ());
|
||||
worldEdit.checkMaxBrushRadius(max);
|
||||
Brush brush = new BlobBrush(radius.divide(max), frequency / 100, amplitude / 100, sphericity / 100);
|
||||
@ -625,7 +625,7 @@ public class BrushCommands {
|
||||
@Switch(name = 'h', desc = "Create hollow spheres instead")
|
||||
boolean hollow,
|
||||
@Switch(name = 'f', desc = "Create falling spheres instead")
|
||||
boolean falling, CommandContext context) throws WorldEditException {
|
||||
boolean falling, InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
Brush brush;
|
||||
if (hollow) {
|
||||
@ -687,7 +687,7 @@ public class BrushCommands {
|
||||
public BrushSettings shatterBrush(Player player, EditSession editSession, LocalSession session, Pattern fill,
|
||||
@Arg(desc = "The radius to sample for blending", def = "10")
|
||||
double radius,
|
||||
@Arg(desc = "Lines", def = "10") int count, CommandContext context) throws WorldEditException {
|
||||
@Arg(desc = "Lines", def = "10") int count, InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
Brush brush = new ShatterBrush(count);
|
||||
CommandLocals locals = context.getLocals();
|
||||
@ -728,7 +728,7 @@ public class BrushCommands {
|
||||
"The -r flag will apply random rotation"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.stencil")
|
||||
public BrushSettings stencilBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "image", desc = "String", def = "") String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Arg(name = "yscale", desc = "double", def = "1") final double yscale, @Switch(name='w', desc = "TODO") boolean onlyWhite, @Switch(name='r', desc = "TODO") boolean randomRotate, CommandContext context) throws WorldEditException, FileNotFoundException, ParameterException {
|
||||
public BrushSettings stencilBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "image", desc = "String", def = "") String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Arg(name = "yscale", desc = "double", def = "1") final double yscale, @Switch(name='w', desc = "TODO") boolean onlyWhite, @Switch(name='r', desc = "TODO") boolean randomRotate, InjectedValueAccess context) throws WorldEditException, FileNotFoundException, ParameterException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
InputStream stream = getHeightmapStream(image);
|
||||
HeightBrush brush;
|
||||
@ -779,7 +779,7 @@ public class BrushCommands {
|
||||
"The -f blends the image with the existing terrain"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.stencil")
|
||||
public BrushSettings imageBrush(Player player, EditSession editSession, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, FawePrimitiveBinding.ImageUri imageUri, @Optional("1") @Range(min=Double.MIN_NORMAL) final double yscale, @Switch(name='a', desc = "TODO") boolean alpha, @Switch(name='f', desc = "TODO") boolean fadeOut, CommandContext context) throws WorldEditException, IOException, ParameterException {
|
||||
public BrushSettings imageBrush(Player player, EditSession editSession, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, FawePrimitiveBinding.ImageUri imageUri, @Optional("1") @Range(min=Double.MIN_NORMAL) final double yscale, @Switch(name='a', desc = "TODO") boolean alpha, @Switch(name='f', desc = "TODO") boolean fadeOut, InjectedValueAccess context) throws WorldEditException, IOException, ParameterException {
|
||||
BufferedImage image = imageUri.load();
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
if (yscale != 1) {
|
||||
@ -830,7 +830,7 @@ public class BrushCommands {
|
||||
"The -r flag will apply random rotation"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.surface")
|
||||
public BrushSettings surfaceBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, CommandContext context) throws WorldEditException {
|
||||
public BrushSettings surfaceBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
Brush brush = new SurfaceSphereBrush();
|
||||
CommandLocals locals = context.getLocals();
|
||||
@ -871,7 +871,7 @@ public class BrushCommands {
|
||||
"Video: https://youtu.be/RPZIaTbqoZw?t=34s"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.scatter")
|
||||
public BrushSettings scatterBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "points", desc = "double", def = "5") double points, @Arg(name = "distance", desc = "double", def = "1") double distance, @Switch(name='o', desc = "TODO") boolean overlay, CommandContext context) throws WorldEditException {
|
||||
public BrushSettings scatterBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "points", desc = "double", def = "5") double points, @Arg(name = "distance", desc = "double", def = "1") double distance, @Switch(name='o', desc = "TODO") boolean overlay, InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
Brush brush;
|
||||
if (overlay) {
|
||||
@ -917,7 +917,7 @@ public class BrushCommands {
|
||||
"The -r flag will apply random rotation"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.populateschematic")
|
||||
public BrushSettings scatterSchemBrush(Player player, EditSession editSession, LocalSession session, Mask mask, String clipboard, @Arg(name = "radius", desc = "Expression", def = "30") Expression radius, @Arg(name = "density", desc = "double", def = "50") double density, @Switch(name='r', desc = "TODO") boolean rotate, CommandContext context) throws WorldEditException {
|
||||
public BrushSettings scatterSchemBrush(Player player, EditSession editSession, LocalSession session, Mask mask, String clipboard, @Arg(name = "radius", desc = "Expression", def = "30") Expression radius, @Arg(name = "density", desc = "double", def = "50") double density, @Switch(name='r', desc = "TODO") boolean rotate, InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
|
||||
|
||||
@ -975,7 +975,7 @@ public class BrushCommands {
|
||||
"Pic: https://i.imgur.com/XV0vYoX.png"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.layer")
|
||||
public BrushSettings surfaceLayer(Player player, EditSession editSession, LocalSession session, Expression radius, CommandContext args, CommandContext context) throws WorldEditException, InvalidUsageException {
|
||||
public BrushSettings surfaceLayer(Player player, EditSession editSession, LocalSession session, Expression radius, InjectedValueAccess args, InjectedValueAccess context) throws WorldEditException, InvalidUsageException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
ParserContext parserContext = new ParserContext();
|
||||
parserContext.setActor(player);
|
||||
@ -1038,7 +1038,7 @@ public class BrushCommands {
|
||||
"Note: The seeds define how many splotches there are, recursion defines how large, solid defines whether the pattern is applied per seed, else per block."
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.splatter")
|
||||
public BrushSettings splatterBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "points", desc = "double", def = "1") double points, @Arg(name = "recursion", desc = "double", def = "5") double recursion, @Arg(name = "solid", desc = "boolean", def = "true") boolean solid, CommandContext context) throws WorldEditException {
|
||||
public BrushSettings splatterBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "points", desc = "double", def = "1") double points, @Arg(name = "recursion", desc = "double", def = "5") double recursion, @Arg(name = "solid", desc = "boolean", def = "true") boolean solid, InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
Brush brush = new SplatterBrush((int) points, (int) recursion, solid);
|
||||
CommandLocals locals = context.getLocals();
|
||||
@ -1082,7 +1082,7 @@ public class BrushCommands {
|
||||
" - Placeholders: {x}, {y}, {z}, {world}, {size}"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.scattercommand")
|
||||
public BrushSettings scatterCommandBrush(Player player, EditSession editSession, LocalSession session, Expression radius, double points, double distance, CommandContext args, CommandContext context) throws WorldEditException {
|
||||
public BrushSettings scatterCommandBrush(Player player, EditSession editSession, LocalSession session, Expression radius, double points, double distance, InjectedValueAccess args, InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
Brush brush = new ScatterCommand((int) points, (int) distance, args.getJoinedStrings(3));
|
||||
CommandLocals locals = context.getLocals();
|
||||
@ -1130,7 +1130,7 @@ public class BrushCommands {
|
||||
int height,
|
||||
@Switch(name = 'h', desc = "Create hollow cylinders instead")
|
||||
boolean hollow,
|
||||
CommandContext context) throws WorldEditException {
|
||||
InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
worldEdit.checkMaxBrushRadius(height);
|
||||
|
||||
@ -1222,7 +1222,7 @@ public class BrushCommands {
|
||||
boolean pasteBiomes,
|
||||
@ArgFlag(name = 'm', desc = "Skip blocks matching this mask in the clipboard", def = "")
|
||||
Mask sourceMask,
|
||||
CommandContext context) throws WorldEditException {
|
||||
InjectedValueAccess context) throws WorldEditException {
|
||||
ClipboardHolder holder = session.getClipboard();
|
||||
Clipboard clipboard = holder.getClipboard();
|
||||
|
||||
@ -1274,7 +1274,7 @@ public class BrushCommands {
|
||||
@Arg(desc = "The number of iterations to perform", def = "4")
|
||||
int iterations,
|
||||
@Arg(desc = "The mask of blocks to use for the heightmap", def = "")
|
||||
Mask mask, CommandContext context) throws WorldEditException {
|
||||
Mask mask, InjectedValueAccess context) throws WorldEditException {
|
||||
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
|
||||
@ -1322,7 +1322,7 @@ public class BrushCommands {
|
||||
public BrushSettings extinguishBrush(Player player, LocalSession session, EditSession editSession,
|
||||
@Arg(desc = "The radius to extinguish", def = "5")
|
||||
double radius,
|
||||
CommandContext context) throws WorldEditException {
|
||||
InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
|
||||
BrushTool tool = session.getBrushTool(player, false);
|
||||
@ -1369,7 +1369,7 @@ public class BrushCommands {
|
||||
double radius,
|
||||
@Switch(name = 'h', desc = "Affect blocks starting at max Y, rather than the target location Y + radius")
|
||||
boolean fromMaxY,
|
||||
CommandContext context) throws WorldEditException {
|
||||
InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
|
||||
BrushTool tool = session.getBrushTool(player, false);
|
||||
@ -1415,7 +1415,7 @@ public class BrushCommands {
|
||||
"Snow Pic: https://i.imgur.com/Hrzn0I4.png"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.height")
|
||||
public BrushSettings heightBrush(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "image", desc = "String", def = "") final String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Arg(name = "yscale", desc = "double", def = "1") final double yscale, @Switch(name='r', desc = "TODO") boolean randomRotate, @Switch(name='l', desc = "TODO") boolean layers, @Switch(name='s', desc = "TODO") boolean dontSmooth, CommandContext context) throws WorldEditException, FileNotFoundException, ParameterException {
|
||||
public BrushSettings heightBrush(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "image", desc = "String", def = "") final String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Arg(name = "yscale", desc = "double", def = "1") final double yscale, @Switch(name='r', desc = "TODO") boolean randomRotate, @Switch(name='l', desc = "TODO") boolean layers, @Switch(name='s', desc = "TODO") boolean dontSmooth, InjectedValueAccess context) throws WorldEditException, FileNotFoundException, ParameterException {
|
||||
return terrainBrush(player, session, radius, image, rotation, yscale, false, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CONE, context);
|
||||
}
|
||||
|
||||
@ -1429,7 +1429,7 @@ public class BrushCommands {
|
||||
" - The `-s` flag disables smoothing"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.height")
|
||||
public BrushSettings cliffBrush(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "image", desc = "String", def = "") String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Arg(name = "yscale", desc = "double", def = "1") final double yscale, @Switch(name='r', desc = "TODO") boolean randomRotate, @Switch(name='l', desc = "TODO") boolean layers, @Switch(name='s', desc = "TODO") boolean dontSmooth, CommandContext context) throws WorldEditException, FileNotFoundException, ParameterException {
|
||||
public BrushSettings cliffBrush(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "image", desc = "String", def = "") String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Arg(name = "yscale", desc = "double", def = "1") final double yscale, @Switch(name='r', desc = "TODO") boolean randomRotate, @Switch(name='l', desc = "TODO") boolean layers, @Switch(name='s', desc = "TODO") boolean dontSmooth, InjectedValueAccess context) throws WorldEditException, FileNotFoundException, ParameterException {
|
||||
return terrainBrush(player, session, radius, image, rotation, yscale, true, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CYLINDER, context);
|
||||
}
|
||||
|
||||
@ -1443,11 +1443,11 @@ public class BrushCommands {
|
||||
desc = "This brush raises or lowers land towards the clicked point"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.height")
|
||||
public BrushSettings flattenBrush(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "image", desc = "String", def = "") final String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Arg(name = "yscale", desc = "double", def = "1") final double yscale, @Switch(name='r', desc = "TODO") boolean randomRotate, @Switch(name='l', desc = "TODO") boolean layers, @Switch(name='s', desc = "TODO") boolean dontSmooth, CommandContext context) throws WorldEditException, FileNotFoundException, ParameterException {
|
||||
public BrushSettings flattenBrush(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Arg(name = "image", desc = "String", def = "") final String image, @Optional("0") @Step(90) @Range(min=0, max=360) final int rotation, @Arg(name = "yscale", desc = "double", def = "1") final double yscale, @Switch(name='r', desc = "TODO") boolean randomRotate, @Switch(name='l', desc = "TODO") boolean layers, @Switch(name='s', desc = "TODO") boolean dontSmooth, InjectedValueAccess context) throws WorldEditException, FileNotFoundException, ParameterException {
|
||||
return terrainBrush(player, session, radius, image, rotation, yscale, true, randomRotate, layers, !dontSmooth, ScalableHeightMap.Shape.CONE, context);
|
||||
}
|
||||
|
||||
private BrushSettings terrainBrush(Player player, LocalSession session, Expression radius, String image, int rotation, double yscale, boolean flat, boolean randomRotate, boolean layers, boolean smooth, ScalableHeightMap.Shape shape, CommandContext context) throws WorldEditException, FileNotFoundException, ParameterException {
|
||||
private BrushSettings terrainBrush(Player player, LocalSession session, Expression radius, String image, int rotation, double yscale, boolean flat, boolean randomRotate, boolean layers, boolean smooth, ScalableHeightMap.Shape shape, InjectedValueAccess context) throws WorldEditException, FileNotFoundException, ParameterException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
InputStream stream = getHeightmapStream(image);
|
||||
HeightBrush brush;
|
||||
@ -1519,7 +1519,7 @@ public class BrushCommands {
|
||||
"Video: https://www.youtube.com/watch?v=RPZIaTbqoZw"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.copy")
|
||||
public BrushSettings copy(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Switch(name='r', desc = "TODO") boolean randomRotate, @Switch(name='a', desc = "TODO") boolean autoRotate, CommandContext context) throws WorldEditException {
|
||||
public BrushSettings copy(Player player, LocalSession session, @Arg(name = "radius", desc = "Expression", def = "5") Expression radius, @Switch(name='r', desc = "TODO") boolean randomRotate, @Switch(name='a', desc = "TODO") boolean autoRotate, InjectedValueAccess context) throws WorldEditException {
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
player.print(BBC.BRUSH_COPY.f(radius));
|
||||
|
||||
@ -1563,7 +1563,7 @@ public class BrushCommands {
|
||||
" - Placeholders: {x}, {y}, {z}, {world}, {size}"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.command")
|
||||
public BrushSettings command(Player player, LocalSession session, Expression radius, CommandContext args, CommandContext context) throws WorldEditException {
|
||||
public BrushSettings command(Player player, LocalSession session, Expression radius, InjectedValueAccess args, InjectedValueAccess context) throws WorldEditException {
|
||||
String cmd = args.getJoinedStrings(1);
|
||||
Brush brush = new CommandBrush(cmd);
|
||||
CommandLocals locals = context.getLocals();
|
||||
@ -1602,7 +1602,7 @@ public class BrushCommands {
|
||||
desc = "Butcher brush, kills mobs within a radius"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.butcher")
|
||||
public BrushSettings butcherBrush(Player player, LocalSession session, CommandContext args,
|
||||
public BrushSettings butcherBrush(Player player, LocalSession session, InjectedValueAccess args,
|
||||
@Arg(desc = "Radius to kill mobs in", def = "5")
|
||||
double radius,
|
||||
@Switch(name = 'p', desc = "Also kill pets")
|
||||
|
@ -13,7 +13,7 @@ import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
|
||||
import org.enginehub.piston.annotation.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@ -29,7 +29,7 @@ import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.HandSide;
|
||||
import com.sk89q.worldedit.util.command.binding.Range;
|
||||
import com.sk89q.worldedit.internal.annotation.Range;
|
||||
import com.sk89q.worldedit.util.command.parametric.Optional;
|
||||
import org.enginehub.piston.annotation.param.Arg;
|
||||
import org.enginehub.piston.annotation.param.Switch;
|
||||
@ -136,7 +136,7 @@ public class BrushOptionsCommands extends MethodCommands {
|
||||
" -p <page> prints the requested page\n"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.list")
|
||||
public void list(Actor actor, CommandContext args, @Switch(name='p', desc = "TODO") @Arg(name = "page", desc = "int", def = "1") int page) throws WorldEditException {
|
||||
public void list(Actor actor, InjectedValueAccess args, @Switch(name='p', desc = "TODO") @Arg(name = "page", desc = "int", def = "1") int page) throws WorldEditException {
|
||||
String baseCmd = Commands.getAlias(BrushCommands.class, "brush") + " " + Commands.getAlias(BrushOptionsCommands.class, "loadbrush");
|
||||
File dir = MainUtil.getFile(Fawe.imp().getDirectory(), "brushes");
|
||||
UtilityCommands.list(dir, actor, args, page, null, true, baseCmd);
|
||||
@ -153,7 +153,7 @@ public class BrushOptionsCommands extends MethodCommands {
|
||||
aliases = {"/none"},
|
||||
desc = "Unbind a bound tool from your current item"
|
||||
)
|
||||
public void none(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
||||
public void none(Player player, LocalSession session, InjectedValueAccess args) throws WorldEditException {
|
||||
session.setTool(player, null);
|
||||
BBC.TOOL_NONE.send(player);
|
||||
}
|
||||
@ -164,7 +164,7 @@ public class BrushOptionsCommands extends MethodCommands {
|
||||
desc = "Toggle the super pickaxe function"
|
||||
)
|
||||
@CommandPermissions("worldedit.superpickaxe")
|
||||
public void togglePickaxe(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
||||
public void togglePickaxe(Player player, LocalSession session, InjectedValueAccess args) throws WorldEditException {
|
||||
String newState = args.getString(0, null);
|
||||
if (session.hasSuperPickAxe()) {
|
||||
if ("on".equals(newState)) {
|
||||
@ -191,7 +191,7 @@ public class BrushOptionsCommands extends MethodCommands {
|
||||
descFooter = "Set the right click brush"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.primary")
|
||||
public void primary(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
||||
public void primary(Player player, LocalSession session, InjectedValueAccess args) throws WorldEditException {
|
||||
BaseItem item = player.getItemInHand(HandSide.MAIN_HAND);
|
||||
BrushTool tool = session.getBrushTool(player, false);
|
||||
session.setTool(item, null, player);
|
||||
@ -210,7 +210,7 @@ public class BrushOptionsCommands extends MethodCommands {
|
||||
descFooter = "Set the left click brush"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.secondary")
|
||||
public void secondary(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
||||
public void secondary(Player player, LocalSession session, InjectedValueAccess args) throws WorldEditException {
|
||||
BaseItem item = player.getItemInHand(HandSide.MAIN_HAND);
|
||||
BrushTool tool = session.getBrushTool(player, false);
|
||||
session.setTool(item, null, player);
|
||||
@ -269,7 +269,7 @@ public class BrushOptionsCommands extends MethodCommands {
|
||||
desc = "Set the targeting mask"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.targetmask")
|
||||
public void targetMask(Player player, EditSession editSession, LocalSession session, CommandContext context) throws WorldEditException {
|
||||
public void targetMask(Player player, EditSession editSession, LocalSession session, InjectedValueAccess context) throws WorldEditException {
|
||||
BrushTool tool = session.getBrushTool(player, false);
|
||||
if (tool == null) {
|
||||
BBC.BRUSH_NONE.send(player);
|
||||
@ -306,7 +306,7 @@ public class BrushOptionsCommands extends MethodCommands {
|
||||
desc = "Toggle between different target modes"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.scroll")
|
||||
public void scroll(Player player, EditSession editSession, LocalSession session, @Optional @Switch(name='h', desc = "TODO") boolean offHand, CommandContext args) throws WorldEditException {
|
||||
public void scroll(Player player, EditSession editSession, LocalSession session, @Optional @Switch(name='h', desc = "TODO") boolean offHand, InjectedValueAccess args) throws WorldEditException {
|
||||
BrushTool bt = session.getBrushTool(player, false);
|
||||
if (bt == null) {
|
||||
BBC.BRUSH_NONE.send(player);
|
||||
@ -331,7 +331,7 @@ public class BrushOptionsCommands extends MethodCommands {
|
||||
desc = "Set the brush destination mask"
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.options.mask", "worldedit.mask.brush"})
|
||||
public void mask(Player player, LocalSession session, EditSession editSession, @Optional @Switch(name='h', desc = "TODO") boolean offHand, CommandContext context) throws WorldEditException {
|
||||
public void mask(Player player, LocalSession session, EditSession editSession, @Optional @Switch(name='h', desc = "TODO") boolean offHand, InjectedValueAccess context) throws WorldEditException {
|
||||
BrushTool tool = session.getBrushTool(player, false);
|
||||
if (tool == null) {
|
||||
player.print(BBC.BRUSH_NONE.f());
|
||||
@ -362,7 +362,7 @@ public class BrushOptionsCommands extends MethodCommands {
|
||||
descFooter = "Set the brush source mask"
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.options.mask", "worldedit.mask.brush"})
|
||||
public void smask(Player player, LocalSession session, EditSession editSession, @Optional @Switch(name='h', desc = "TODO") boolean offHand, CommandContext context) throws WorldEditException {
|
||||
public void smask(Player player, LocalSession session, EditSession editSession, @Optional @Switch(name='h', desc = "TODO") boolean offHand, InjectedValueAccess context) throws WorldEditException {
|
||||
BrushTool tool = session.getBrushTool(player, false);
|
||||
if (tool == null) {
|
||||
player.print(BBC.BRUSH_NONE.f());
|
||||
@ -391,7 +391,7 @@ public class BrushOptionsCommands extends MethodCommands {
|
||||
desc = "Set the brush transform"
|
||||
)
|
||||
@CommandPermissions({"worldedit.brush.options.transform", "worldedit.transform.brush"})
|
||||
public void transform(Player player, LocalSession session, EditSession editSession, @Optional @Switch(name='h', desc = "TODO") boolean offHand, CommandContext context) throws WorldEditException {
|
||||
public void transform(Player player, LocalSession session, EditSession editSession, @Optional @Switch(name='h', desc = "TODO") boolean offHand, InjectedValueAccess context) throws WorldEditException {
|
||||
BrushTool tool = session.getBrushTool(player, false);
|
||||
if (tool == null) {
|
||||
player.print(BBC.BRUSH_NONE.f());
|
||||
@ -421,7 +421,7 @@ public class BrushOptionsCommands extends MethodCommands {
|
||||
desc = "Set the brush material"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.options.material")
|
||||
public void material(Player player, EditSession editSession, LocalSession session, Pattern pattern, @Switch(name='h', desc = "TODO") boolean offHand, CommandContext context) throws WorldEditException {
|
||||
public void material(Player player, EditSession editSession, LocalSession session, Pattern pattern, @Switch(name='h', desc = "TODO") boolean offHand, InjectedValueAccess context) throws WorldEditException {
|
||||
BrushTool tool = session.getBrushTool(player, false);
|
||||
if (tool == null) {
|
||||
player.print(BBC.BRUSH_NONE.f());
|
||||
@ -444,7 +444,7 @@ public class BrushOptionsCommands extends MethodCommands {
|
||||
desc = "Set the brush range"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.options.range")
|
||||
public void range(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
||||
public void range(Player player, LocalSession session, InjectedValueAccess args) throws WorldEditException {
|
||||
int range = Math.max(0, Math.min(256, args.getInteger(0)));
|
||||
BrushTool tool = session.getBrushTool(player, false);
|
||||
if (tool == null) {
|
||||
@ -460,7 +460,7 @@ public class BrushOptionsCommands extends MethodCommands {
|
||||
desc = "Set the brush size"
|
||||
)
|
||||
@CommandPermissions("worldedit.brush.options.size")
|
||||
public void size(Player player, LocalSession session, CommandContext args, @Switch(name='h', desc = "TODO") boolean offHand) throws WorldEditException {
|
||||
public void size(Player player, LocalSession session, InjectedValueAccess args, @Switch(name='h', desc = "TODO") boolean offHand) throws WorldEditException {
|
||||
int radius = args.getInteger(0);
|
||||
worldEdit.checkMaxBrushRadius(radius);
|
||||
BrushTool tool = session.getBrushTool(player, false);
|
||||
|
@ -37,7 +37,7 @@ import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.MaskTraverser;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
@ -122,7 +122,7 @@ public class ClipboardCommands {
|
||||
@Switch(name = 'b', desc = "Also copy biomes")
|
||||
boolean copyBiomes,
|
||||
@ArgFlag(name = 'm', desc = "Set the exclude mask, matching blocks become air", def = "")
|
||||
Mask mask, CommandContext context) throws WorldEditException {
|
||||
Mask mask, InjectedValueAccess context) throws WorldEditException {
|
||||
BlockVector3 min = region.getMinimumPoint();
|
||||
BlockVector3 max = region.getMaximumPoint();
|
||||
|
||||
@ -242,7 +242,7 @@ public class ClipboardCommands {
|
||||
boolean copyBiomes,
|
||||
@ArgFlag(name = 'm', desc = "Set the exclude mask, matching blocks become air", def = "")
|
||||
Mask mask,
|
||||
CommandContext context) throws WorldEditException {
|
||||
InjectedValueAccess context) throws WorldEditException {
|
||||
BlockVector3 min = region.getMinimumPoint();
|
||||
BlockVector3 max = region.getMaximumPoint();
|
||||
|
||||
|
@ -28,7 +28,7 @@ import com.boydti.fawe.util.CleanTextureUtil;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.boydti.fawe.util.RandomTextureUtil;
|
||||
import com.boydti.fawe.util.TextureUtil;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@ -298,7 +298,7 @@ public class GeneralCommands {
|
||||
desc = "Set the global mask"
|
||||
)
|
||||
@CommandPermissions("worldedit.global-texture")
|
||||
public void gtexture(FawePlayer player, LocalSession session, EditSession editSession, @Arg(name = "context", desc = "CommandContext", def = "") CommandContext context) throws WorldEditException, FileNotFoundException, ParameterException {
|
||||
public void gtexture(FawePlayer player, LocalSession session, EditSession editSession, @Arg(name = "context", desc = "InjectedValueAccess", def = "") InjectedValueAccess context) throws WorldEditException, FileNotFoundException, ParameterException {
|
||||
if (context == null || context.argsLength() == 0) {
|
||||
session.setTextureUtil(null);
|
||||
BBC.TEXTURE_DISABLED.send(player);
|
||||
@ -373,7 +373,7 @@ public class GeneralCommands {
|
||||
desc = "Set the global transform"
|
||||
)
|
||||
@CommandPermissions({"worldedit.global-transform", "worldedit.transform.global"})
|
||||
public void gtransform(Player player, EditSession editSession, LocalSession session, @Arg(name = "context", desc = "CommandContext", def = "") CommandContext context) throws WorldEditException {
|
||||
public void gtransform(Player player, EditSession editSession, LocalSession session, @Arg(name = "context", desc = "InjectedValueAccess", def = "") InjectedValueAccess context) throws WorldEditException {
|
||||
if (context == null || context.argsLength() == 0) {
|
||||
session.setTransform(null);
|
||||
BBC.TRANSFORM_DISABLED.send(player);
|
||||
|
@ -29,7 +29,7 @@ import com.boydti.fawe.util.TextureUtil;
|
||||
import com.boydti.fawe.util.image.ImageUtil;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
@ -45,7 +45,6 @@ import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.operation.Operations;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.function.visitor.RegionVisitor;
|
||||
import com.sk89q.worldedit.internal.annotation.Radii;
|
||||
import com.sk89q.worldedit.internal.annotation.Selection;
|
||||
import static com.sk89q.worldedit.internal.command.CommandUtil.checkCommandArgument;
|
||||
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
||||
@ -55,7 +54,7 @@ import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
import com.sk89q.worldedit.util.command.binding.Range;
|
||||
import com.sk89q.worldedit.internal.annotation.Range;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import org.enginehub.piston.annotation.Command;
|
||||
@ -104,7 +103,7 @@ public class GenerationCommands {
|
||||
@Arg(desc = "TODO", def = "25") int individualRarity,
|
||||
@Arg(desc = "TODO", def = "0") int pocketChance,
|
||||
@Arg(desc = "TODO", def = "0") int pocketMin,
|
||||
@Arg(desc = "TODO", def = "3") int pocketMax, CommandContext context) throws WorldEditException {
|
||||
@Arg(desc = "TODO", def = "3") int pocketMax, InjectedValueAccess context) throws WorldEditException {
|
||||
fp.checkConfirmationRegion(() -> {
|
||||
CavesGen gen = new CavesGen(size, frequency, rarity, minY, maxY, systemFrequency, individualRarity, pocketChance, pocketMin, pocketMax);
|
||||
editSession.generate(region, gen);
|
||||
@ -119,7 +118,7 @@ public class GenerationCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.generation.ore")
|
||||
@Logging(PLACEMENT)
|
||||
public void ores(FawePlayer player, LocalSession session, EditSession editSession, @Selection Region region, Mask mask, CommandContext context) throws WorldEditException {
|
||||
public void ores(FawePlayer player, LocalSession session, EditSession editSession, @Selection Region region, Mask mask, InjectedValueAccess context) throws WorldEditException {
|
||||
player.checkConfirmationRegion(() -> {
|
||||
editSession.addOres(region, mask);
|
||||
BBC.VISITOR_BLOCK.send(player, editSession.getBlockChangeCount());
|
||||
@ -173,7 +172,7 @@ public class GenerationCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.generation.ore")
|
||||
@Logging(PLACEMENT)
|
||||
public void ore(FawePlayer player, LocalSession session, EditSession editSession, @Selection Region region, Mask mask, Pattern material, @Range(min = 0) int size, int freq, @Range(min = 0, max = 100) int rarity, @Range(min = 0, max = 255) int minY, @Range(min = 0, max = 255) int maxY, CommandContext context) throws WorldEditException {
|
||||
public void ore(FawePlayer player, LocalSession session, EditSession editSession, @Selection Region region, Mask mask, Pattern material, @Range(min = 0) int size, int freq, @Range(min = 0, max = 100) int rarity, @Range(min = 0, max = 255) int minY, @Range(min = 0, max = 255) int maxY, InjectedValueAccess context) throws WorldEditException {
|
||||
player.checkConfirmationRegion(() -> {
|
||||
editSession.addOre(region, mask, material, size, freq, rarity, minY, maxY);
|
||||
BBC.VISITOR_BLOCK.send(player, editSession.getBlockChangeCount());
|
||||
@ -192,7 +191,7 @@ public class GenerationCommands {
|
||||
BlockVector2 radius,
|
||||
@Arg(desc = "The height of the cylinder", def = "1")
|
||||
int height,
|
||||
@Range(min = 1) @Arg(name = "thickness", desc = "double", def = "1") double thickness, CommandContext context) throws WorldEditException {
|
||||
@Range(min = 1) @Arg(name = "thickness", desc = "double", def = "1") double thickness, InjectedValueAccess context) throws WorldEditException {
|
||||
double max = MathMan.max(radius.getBlockX(), radius.getBlockZ());
|
||||
worldEdit.checkMaxRadius(max);
|
||||
BlockVector3 pos = session.getPlacementPosition(player);
|
||||
@ -215,7 +214,7 @@ public class GenerationCommands {
|
||||
@Arg(desc = "The height of the cylinder", def = "1")
|
||||
int height,
|
||||
@Switch(name = 'h', desc = "Make a hollow cylinder")
|
||||
boolean hollow, CommandContext context) throws WorldEditException {
|
||||
boolean hollow, InjectedValueAccess context) throws WorldEditException {
|
||||
double max = Math.max(radius.getBlockX(), radius.getBlockZ());
|
||||
worldEdit.checkMaxRadius(max);
|
||||
BlockVector3 pos = session.getPlacementPosition(player);
|
||||
@ -237,7 +236,7 @@ public class GenerationCommands {
|
||||
@Arg(desc = "The radii of the sphere. Order is N/S, U/D, E/W") BlockVector3 radii,
|
||||
@Switch(name = 'r', desc = "Raise the bottom of the sphere to the placement position")
|
||||
boolean raised,
|
||||
CommandContext context) throws WorldEditException {
|
||||
InjectedValueAccess context) throws WorldEditException {
|
||||
sphere(fp, player, session, editSession, pattern, radii, raised, true, context);
|
||||
}
|
||||
|
||||
@ -312,7 +311,7 @@ public class GenerationCommands {
|
||||
@Arg(desc = "The pattern of blocks to set")
|
||||
Pattern pattern,
|
||||
@Arg(desc = "The size of the pyramid")
|
||||
int size, CommandContext context) throws WorldEditException {
|
||||
int size, InjectedValueAccess context) throws WorldEditException {
|
||||
pyramid(fp, player, session, editSession, pattern, size, true, context);
|
||||
}
|
||||
|
||||
@ -329,7 +328,7 @@ public class GenerationCommands {
|
||||
int size,
|
||||
@Switch(name = 'h', desc = "Make a hollow pyramid")
|
||||
boolean hollow,
|
||||
CommandContext context) throws WorldEditException {
|
||||
InjectedValueAccess context) throws WorldEditException {
|
||||
BlockVector3 pos = session.getPlacementPosition(player);
|
||||
worldEdit.checkMaxRadius(size);
|
||||
fp.checkConfirmationRadius(() -> {
|
||||
|
@ -33,7 +33,7 @@ import com.boydti.fawe.object.changeset.DiskStorageHistory;
|
||||
import com.boydti.fawe.regions.FaweMaskManager;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
@ -44,7 +44,7 @@ import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.util.command.binding.Range;
|
||||
import com.sk89q.worldedit.internal.annotation.Range;
|
||||
import org.enginehub.piston.annotation.param.Switch;
|
||||
import com.sk89q.worldedit.util.command.parametric.Optional;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
@ -220,7 +220,7 @@ public class HistoryCommands extends MethodCommands {
|
||||
int times,
|
||||
@Arg(name = "player", desc = "Undo this player's operations", def = "")
|
||||
String playerName,
|
||||
CommandContext context) throws WorldEditException {
|
||||
InjectedValueAccess context) throws WorldEditException {
|
||||
if (session.hasFastMode()) {
|
||||
BBC.COMMAND_UNDO_DISABLED.send(player);
|
||||
return;
|
||||
|
@ -2,7 +2,7 @@ package com.sk89q.worldedit.command;
|
||||
|
||||
import com.boydti.fawe.config.Commands;
|
||||
import org.enginehub.piston.annotation.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
@ -71,7 +71,7 @@ public class MethodCommands {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getArguments(CommandContext context) {
|
||||
public String getArguments(InjectedValueAccess context) {
|
||||
if (context == null) return null;
|
||||
CommandLocals locals = context.getLocals();
|
||||
if (locals != null) {
|
||||
|
@ -15,7 +15,6 @@ import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
|
||||
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.pattern.ClipboardPattern;
|
||||
@ -26,8 +25,7 @@ import com.sk89q.worldedit.internal.expression.ExpressionException;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment;
|
||||
import com.sk89q.worldedit.session.ClipboardHolder;
|
||||
import com.sk89q.worldedit.util.command.binding.Range;
|
||||
import com.sk89q.worldedit.util.command.parametric.Optional;
|
||||
import com.sk89q.worldedit.internal.annotation.Range;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import org.enginehub.piston.annotation.param.Arg;
|
||||
|
||||
|
@ -43,7 +43,7 @@ import com.boydti.fawe.object.exception.FaweException;
|
||||
import com.boydti.fawe.object.visitor.Fast2DIterator;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
@ -79,8 +79,7 @@ import com.sk89q.worldedit.regions.RegionOperationException;
|
||||
import com.sk89q.worldedit.regions.Regions;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
import com.sk89q.worldedit.util.command.binding.Range;
|
||||
import com.sk89q.worldedit.util.command.parametric.Optional;
|
||||
import com.sk89q.worldedit.internal.annotation.Range;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
@ -300,7 +299,7 @@ public class RegionCommands {
|
||||
int thickness,
|
||||
@Switch(name = 'h', desc = "Generate only a shell")
|
||||
boolean shell,
|
||||
CommandContext context) throws WorldEditException {
|
||||
InjectedValueAccess context) throws WorldEditException {
|
||||
if (!(region instanceof ConvexPolyhedralRegion)) {
|
||||
player.printError("//curve only works with convex polyhedral selections");
|
||||
return;
|
||||
@ -323,7 +322,7 @@ public class RegionCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.region.replace")
|
||||
@Logging(REGION)
|
||||
public void replace(FawePlayer player, EditSession editSession, @Selection Region region, @Arg(name = "from", desc = "Mask", def = "") Mask from, Pattern to, CommandContext context) throws WorldEditException {
|
||||
public void replace(FawePlayer player, EditSession editSession, @Selection Region region, @Arg(name = "from", desc = "Mask", def = "") Mask from, Pattern to, InjectedValueAccess context) throws WorldEditException {
|
||||
player.checkConfirmationRegion(() -> {
|
||||
int affected = editSession.replaceBlocks(region, from == null ? new ExistingBlockMask(editSession) : from, to);
|
||||
BBC.VISITOR_BLOCK.send(player, affected);
|
||||
@ -344,7 +343,7 @@ public class RegionCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.region.set")
|
||||
@Logging(REGION)
|
||||
public void set(FawePlayer player, LocalSession session, EditSession editSession, @Selection Region selection, Pattern to, CommandContext context) throws WorldEditException {
|
||||
public void set(FawePlayer player, LocalSession session, EditSession editSession, @Selection Region selection, Pattern to, InjectedValueAccess context) throws WorldEditException {
|
||||
player.checkConfirmationRegion(() -> {
|
||||
int affected = editSession.setBlocks(selection, to);
|
||||
if (affected != 0) {
|
||||
@ -363,7 +362,7 @@ public class RegionCommands {
|
||||
@Logging(REGION)
|
||||
public void overlay(FawePlayer player, EditSession editSession, @Selection Region region,
|
||||
@Arg(desc = "The pattern of blocks to overlay")
|
||||
Pattern pattern, CommandContext context) throws WorldEditException {
|
||||
Pattern pattern, InjectedValueAccess context) throws WorldEditException {
|
||||
player.checkConfirmationRegion(() -> {
|
||||
int affected = editSession.overlayCuboidBlocks(region, pattern);
|
||||
BBC.VISITOR_BLOCK.send(player, affected);
|
||||
@ -376,7 +375,7 @@ public class RegionCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.region.overlay")
|
||||
@Logging(REGION)
|
||||
public void lay(FawePlayer player, EditSession editSession, @Selection Region region, Pattern pattern, CommandContext context) throws WorldEditException {
|
||||
public void lay(FawePlayer player, EditSession editSession, @Selection Region region, Pattern pattern, InjectedValueAccess context) throws WorldEditException {
|
||||
player.checkConfirmationRegion(() -> {
|
||||
BlockVector3 max = region.getMaximumPoint();
|
||||
int maxY = max.getBlockY();
|
||||
@ -414,7 +413,7 @@ public class RegionCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.region.naturalize")
|
||||
@Logging(REGION)
|
||||
public void naturalize(FawePlayer player, EditSession editSession, @Selection Region region, CommandContext context) throws WorldEditException {
|
||||
public void naturalize(FawePlayer player, EditSession editSession, @Selection Region region, InjectedValueAccess context) throws WorldEditException {
|
||||
player.checkConfirmationRegion(() -> {
|
||||
int affected = editSession.naturalizeCuboidBlocks(region);
|
||||
BBC.VISITOR_BLOCK.send(player, affected);
|
||||
@ -427,7 +426,7 @@ public class RegionCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.region.walls")
|
||||
@Logging(REGION)
|
||||
public void walls(FawePlayer player, EditSession editSession, @Selection Region region, Pattern pattern, CommandContext context) throws WorldEditException {
|
||||
public void walls(FawePlayer player, EditSession editSession, @Selection Region region, Pattern pattern, InjectedValueAccess context) throws WorldEditException {
|
||||
player.checkConfirmationRegion(() -> {
|
||||
int affected = editSession.makeWalls(region, pattern);
|
||||
BBC.VISITOR_BLOCK.send(player, affected);
|
||||
@ -441,7 +440,7 @@ public class RegionCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.region.faces")
|
||||
@Logging(REGION)
|
||||
public void faces(FawePlayer player, EditSession editSession, @Selection Region region, Pattern pattern, CommandContext context) throws WorldEditException {
|
||||
public void faces(FawePlayer player, EditSession editSession, @Selection Region region, Pattern pattern, InjectedValueAccess context) throws WorldEditException {
|
||||
player.checkConfirmationRegion(() -> {
|
||||
int affected = editSession.makeCuboidFaces(region, pattern);
|
||||
BBC.VISITOR_BLOCK.send(player, affected);
|
||||
@ -455,7 +454,7 @@ public class RegionCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.region.smooth")
|
||||
@Logging(REGION)
|
||||
public void smooth(FawePlayer player, EditSession editSession, @Selection Region region, @Arg(name = "iterations", desc = "int", def = "1") int iterations, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name='s', desc = "TODO") boolean snow, CommandContext context) throws WorldEditException {
|
||||
public void smooth(FawePlayer player, EditSession editSession, @Selection Region region, @Arg(name = "iterations", desc = "int", def = "1") int iterations, @Arg(name = "mask", desc = "Mask", def = "") Mask mask, @Switch(name='s', desc = "TODO") boolean snow, InjectedValueAccess context) throws WorldEditException {
|
||||
BlockVector3 min = region.getMinimumPoint();
|
||||
BlockVector3 max = region.getMaximumPoint();
|
||||
long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1));
|
||||
@ -538,7 +537,7 @@ public class RegionCommands {
|
||||
|
||||
@Switch(name='e', desc = "TODO") boolean skipEntities,
|
||||
@Switch(name='a', desc = "TODO") boolean skipAir,
|
||||
CommandContext context) throws WorldEditException {
|
||||
InjectedValueAccess context) throws WorldEditException {
|
||||
player.checkConfirmationRegion(() -> {
|
||||
int affected = editSession.moveRegion(region, direction, count, !skipAir, !skipEntities, copyBiomes, replace);
|
||||
|
||||
@ -569,7 +568,7 @@ public class RegionCommands {
|
||||
@Selection Region region,
|
||||
@Arg(name = "replace", desc = "BlockStateHolder", def = "air") BlockStateHolder replace,
|
||||
@Switch(name='m', desc = "TODO") boolean notFullHeight,
|
||||
CommandContext context) throws WorldEditException {
|
||||
InjectedValueAccess context) throws WorldEditException {
|
||||
player.checkConfirmationRegion(() -> {
|
||||
int affected = editSession.fall(region, !notFullHeight, replace);
|
||||
BBC.VISITOR_BLOCK.send(player, affected);
|
||||
@ -594,7 +593,7 @@ public class RegionCommands {
|
||||
@Switch(name = 'b', desc = "//TODO") boolean copyBiomes,
|
||||
@Switch(name = 'e', desc = "//TODO") boolean skipEntities,
|
||||
@Switch(name = 'a', desc = "Ignore air blocks")
|
||||
boolean ignoreAirBlocks, @Switch(name='m', desc = "TODO") Mask sourceMask, CommandContext context) throws WorldEditException {
|
||||
boolean ignoreAirBlocks, @Switch(name='m', desc = "TODO") Mask sourceMask, InjectedValueAccess context) throws WorldEditException {
|
||||
player.checkConfirmationStack(() -> {
|
||||
if (sourceMask != null) {
|
||||
editSession.addSourceMask(sourceMask);
|
||||
@ -680,7 +679,7 @@ public class RegionCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.regen")
|
||||
@Logging(REGION)
|
||||
public void regenerateChunk(FawePlayer player, LocalSession session, EditSession editSession, @Selection Region region, CommandContext context) throws WorldEditException {
|
||||
public void regenerateChunk(FawePlayer player, LocalSession session, EditSession editSession, @Selection Region region, InjectedValueAccess context) throws WorldEditException {
|
||||
player.checkConfirmationRegion(() -> {
|
||||
Mask mask = session.getMask();
|
||||
session.setMask((Mask) null);
|
||||
@ -728,7 +727,7 @@ public class RegionCommands {
|
||||
@Arg(desc = "The pattern of blocks to replace the hollowed area with", def = "air")
|
||||
Pattern pattern,
|
||||
|
||||
CommandContext context) throws WorldEditException {
|
||||
InjectedValueAccess context) throws WorldEditException {
|
||||
Mask finalMask = mask == null ? new SolidBlockMask(editSession) : mask;
|
||||
player.checkConfirmationRegion(() -> {
|
||||
int affected = editSession.hollowOutRegion(region, thickness, pattern, finalMask);
|
||||
@ -759,7 +758,7 @@ public class RegionCommands {
|
||||
@Logging(REGION)
|
||||
public void flora(FawePlayer player, EditSession editSession, @Selection Region region,
|
||||
@Arg(desc = "The density of the forest", def = "5")
|
||||
double density, CommandContext context) throws WorldEditException {
|
||||
double density, InjectedValueAccess context) throws WorldEditException {
|
||||
player.checkConfirmationRegion(() -> {
|
||||
FloraGenerator generator = new FloraGenerator(editSession);
|
||||
GroundFunction ground = new GroundFunction(new ExistingBlockMask(editSession), generator);
|
||||
|
@ -34,7 +34,7 @@ import com.boydti.fawe.object.schematic.StructureFormat;
|
||||
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.chat.Message;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@ -566,7 +566,7 @@ public class SchematicCommands {
|
||||
" -f <format> restricts by format\n"
|
||||
)
|
||||
@CommandPermissions("worldedit.schematic.show")
|
||||
public void show(Player player, CommandContext args, @Switch(name='f', desc = "TODO") String formatName) {
|
||||
public void show(Player player, InjectedValueAccess args, @Switch(name='f', desc = "TODO") String formatName) {
|
||||
FawePlayer fp = FawePlayer.wrap(player);
|
||||
if (args.argsLength() == 0) {
|
||||
if (fp.getSession().getVirtualWorld() != null) fp.setVirtualWorld(null);
|
||||
@ -627,7 +627,7 @@ public class SchematicCommands {
|
||||
descFooter = "Note: Format is not fully verified until loading."
|
||||
)
|
||||
@CommandPermissions("worldedit.schematic.list")
|
||||
public void list(FawePlayer fp, Actor actor, CommandContext args,
|
||||
public void list(FawePlayer fp, Actor actor, InjectedValueAccess args,
|
||||
@ArgFlag(name = 'p', desc = "Page to view.", def = "1")
|
||||
int page,
|
||||
@Switch(name = 'f', desc = "Restricts by format.")
|
||||
|
@ -24,7 +24,7 @@ import static com.sk89q.worldedit.command.util.Logging.LogMode.ALL;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.wrappers.LocationMaskedPlayerWrapper;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
@ -80,7 +80,7 @@ public class ScriptingCommands {
|
||||
desc = ""
|
||||
)
|
||||
@CommandPermissions("fawe.setupdispatcher")
|
||||
public void setupdispatcher(Player player, LocalSession session, final CommandContext args) throws WorldEditException {
|
||||
public void setupdispatcher(Player player, LocalSession session, final InjectedValueAccess args) throws WorldEditException {
|
||||
PlatformCommandManager.getInstance().setupDispatcher();
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ public class ScriptingCommands {
|
||||
)
|
||||
@CommandPermissions("worldedit.scripting.execute")
|
||||
@Logging(ALL)
|
||||
public void execute(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
||||
public void execute(Player player, LocalSession session, InjectedValueAccess args) throws WorldEditException {
|
||||
final String[] scriptArgs = args.getSlice(1);
|
||||
final String filename = args.getString(0);
|
||||
|
||||
|
@ -21,7 +21,7 @@ package com.sk89q.worldedit.command;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import org.enginehub.piston.annotation.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
@ -56,7 +56,7 @@ public class SuperPickaxeCommands {
|
||||
desc = "Enable the area super pickaxe pickaxe mode"
|
||||
)
|
||||
@CommandPermissions("worldedit.superpickaxe.area")
|
||||
public void area(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
||||
public void area(Player player, LocalSession session, InjectedValueAccess args) throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
int range = args.getInteger(0);
|
||||
@ -77,7 +77,7 @@ public class SuperPickaxeCommands {
|
||||
desc = "Enable the recursive super pickaxe pickaxe mode"
|
||||
)
|
||||
@CommandPermissions("worldedit.superpickaxe.recursive")
|
||||
public void recursive(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
||||
public void recursive(Player player, LocalSession session, InjectedValueAccess args) throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
double range = args.getDouble(0);
|
||||
|
@ -32,7 +32,7 @@ import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.boydti.fawe.util.chat.Message;
|
||||
import com.boydti.fawe.util.image.ImageUtil;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
@ -72,8 +72,7 @@ import com.sk89q.worldedit.regions.CylinderRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.command.CommandMapping;
|
||||
import com.sk89q.worldedit.util.command.Dispatcher;
|
||||
import com.sk89q.worldedit.util.command.binding.Range;
|
||||
import com.sk89q.worldedit.util.command.parametric.Optional;
|
||||
import com.sk89q.worldedit.internal.annotation.Range;
|
||||
import com.sk89q.worldedit.util.formatting.component.SubtleFormat;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||
@ -218,7 +217,7 @@ public class UtilityCommands {
|
||||
)
|
||||
@CommandQueued(false)
|
||||
@CommandPermissions("worldedit.patterns")
|
||||
public void patterns(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
||||
public void patterns(Player player, LocalSession session, InjectedValueAccess args) throws WorldEditException {
|
||||
displayModifierHelp(player, DefaultPatternParser.class, args);
|
||||
}
|
||||
|
||||
@ -234,7 +233,7 @@ public class UtilityCommands {
|
||||
)
|
||||
@CommandQueued(false)
|
||||
@CommandPermissions("worldedit.masks")
|
||||
public void masks(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
||||
public void masks(Player player, LocalSession session, InjectedValueAccess args) throws WorldEditException {
|
||||
displayModifierHelp(player, DefaultMaskParser.class, args);
|
||||
}
|
||||
|
||||
@ -249,11 +248,11 @@ public class UtilityCommands {
|
||||
)
|
||||
@CommandQueued(false)
|
||||
@CommandPermissions("worldedit.transforms")
|
||||
public void transforms(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
||||
public void transforms(Player player, LocalSession session, InjectedValueAccess args) throws WorldEditException {
|
||||
displayModifierHelp(player, DefaultTransformParser.class, args);
|
||||
}
|
||||
|
||||
private void displayModifierHelp(Player player, Class<? extends FaweParser> clazz, CommandContext args) {
|
||||
private void displayModifierHelp(Player player, Class<? extends FaweParser> clazz, InjectedValueAccess args) {
|
||||
FaweParser parser = FaweAPI.getParser(clazz);
|
||||
if (args.argsLength() == 0) {
|
||||
String base = getCommand().aliases()[0];
|
||||
@ -722,7 +721,7 @@ public class UtilityCommands {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void list(File dir, Actor actor, CommandContext args, @Range(min = 0) int page, String formatName, boolean playerFolder, String onClickCmd) {
|
||||
public static void list(File dir, Actor actor, InjectedValueAccess args, @Range(min = 0) int page, String formatName, boolean playerFolder, String onClickCmd) {
|
||||
list(dir, actor, args, page, -1, formatName, playerFolder, new RunnableVal3<Message, URI, String>() {
|
||||
@Override
|
||||
public void run(Message m, URI uri, String fileName) {
|
||||
@ -732,7 +731,7 @@ public class UtilityCommands {
|
||||
});
|
||||
}
|
||||
|
||||
public static void list(File dir, Actor actor, CommandContext args, @Range(min = 0) int page, int perPage, String formatName, boolean playerFolder, RunnableVal3<Message, URI, String> eachMsg) {
|
||||
public static void list(File dir, Actor actor, InjectedValueAccess args, @Range(min = 0) int page, int perPage, String formatName, boolean playerFolder, RunnableVal3<Message, URI, String> eachMsg) {
|
||||
AtomicInteger pageInt = new AtomicInteger(page);
|
||||
List<File> fileList = new ArrayList<>();
|
||||
if (perPage == -1) perPage = actor instanceof Player ? 12 : 20; // More pages for console
|
||||
@ -799,7 +798,7 @@ public class UtilityCommands {
|
||||
m.send(actor);
|
||||
}
|
||||
|
||||
public static int getFiles(File dir, Actor actor, CommandContext args, @Range(min = 0) int page, int perPage, String formatName, boolean playerFolder, Consumer<File> forEachFile) {
|
||||
public static int getFiles(File dir, Actor actor, InjectedValueAccess args, @Range(min = 0) int page, int perPage, String formatName, boolean playerFolder, Consumer<File> forEachFile) {
|
||||
Consumer<File> rootFunction = forEachFile;
|
||||
|
||||
int len = args.argsLength();
|
||||
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.command.argument;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.composition.CommandExecutor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class BooleanFlag implements CommandExecutor<Boolean> {
|
||||
|
||||
private final String description;
|
||||
|
||||
public BooleanFlag(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandArgs args, CommandLocals locals) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.command.argument;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.composition.SimpleCommand;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
public class ItemParser extends SimpleCommand<BaseItem> {
|
||||
|
||||
private final StringParser stringParser;
|
||||
|
||||
public ItemParser(String name) {
|
||||
stringParser = addParameter(new StringParser(name, "The item name", null));
|
||||
}
|
||||
|
||||
public ItemParser(String name, String defaultSuggestion) {
|
||||
stringParser = addParameter(new StringParser(name, "The item name", defaultSuggestion));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseItem call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
String itemString = stringParser.call(args, locals);
|
||||
|
||||
Actor actor = locals.get(Actor.class);
|
||||
LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor);
|
||||
|
||||
ParserContext parserContext = new ParserContext();
|
||||
parserContext.setActor(actor);
|
||||
if (actor instanceof Entity) {
|
||||
Extent extent = ((Entity) actor).getExtent();
|
||||
if (extent instanceof World) {
|
||||
parserContext.setWorld((World) extent);
|
||||
}
|
||||
}
|
||||
parserContext.setSession(session);
|
||||
|
||||
try {
|
||||
return WorldEdit.getInstance().getItemFactory().parseFromInput(itemString, parserContext);
|
||||
} catch (InputParseException e) {
|
||||
throw new CommandException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Match an item";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean testPermission0(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.command.argument;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.blocks.BaseItem;
|
||||
import com.sk89q.worldedit.function.Contextual;
|
||||
import com.sk89q.worldedit.function.EditContext;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.util.Direction;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.composition.SimpleCommand;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
public class ItemUseParser extends SimpleCommand<Contextual<RegionFunction>> {
|
||||
|
||||
private final ItemParser itemParser = addParameter(new ItemParser("item", "minecraft:bone_meal"));
|
||||
|
||||
@Override
|
||||
public Contextual<RegionFunction> call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
BaseItem item = itemParser.call(args, locals);
|
||||
return new ItemUseFactory(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Applies an item";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean testPermission0(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static final class ItemUseFactory implements Contextual<RegionFunction> {
|
||||
private final BaseItem item;
|
||||
|
||||
private ItemUseFactory(BaseItem item) {
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegionFunction createFromContext(EditContext input) {
|
||||
World world = ((EditSession) input.getDestination()).getWorld();
|
||||
return new ItemUseFunction(world, item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "application of the item " + item.getType() + ":" + item.getNbtData();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ItemUseFunction implements RegionFunction {
|
||||
private final World world;
|
||||
private final BaseItem item;
|
||||
|
||||
private ItemUseFunction(World world, BaseItem item) {
|
||||
this.world = world;
|
||||
this.item = item;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(BlockVector3 position) throws WorldEditException {
|
||||
return world.useItem(position, item, Direction.UP);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.command.argument;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.argument.MissingArgumentException;
|
||||
import com.sk89q.worldedit.util.command.composition.CommandExecutor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class NumberParser implements CommandExecutor<Number> {
|
||||
|
||||
private final String name;
|
||||
private final String description;
|
||||
private final String defaultSuggestion;
|
||||
|
||||
public NumberParser(String name, String description) {
|
||||
this(name, description, null);
|
||||
}
|
||||
|
||||
public NumberParser(String name, String description, String defaultSuggestion) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.defaultSuggestion = defaultSuggestion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Number call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
try {
|
||||
String next = args.next();
|
||||
try {
|
||||
return Double.parseDouble(next);
|
||||
} catch (NumberFormatException ignored) {
|
||||
throw new CommandException("The value for <" + name + "> should be a number. '" + next + "' is not a number.");
|
||||
}
|
||||
} catch (MissingArgumentException e) {
|
||||
throw new CommandException("Missing value for <" + name + "> (try a number).");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
|
||||
String value = args.next();
|
||||
return value.isEmpty() && defaultSuggestion != null ? Lists.newArrayList(defaultSuggestion) : Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "<" + name + ">";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.command.argument;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.extension.input.InputParseException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extent.Extent;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.composition.SimpleCommand;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
public class PatternParser extends SimpleCommand<Pattern> {
|
||||
|
||||
private final StringParser stringParser;
|
||||
|
||||
public PatternParser(String name) {
|
||||
stringParser = addParameter(new StringParser(name, "The pattern"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pattern call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
String patternString = stringParser.call(args, locals);
|
||||
|
||||
Actor actor = locals.get(Actor.class);
|
||||
LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor);
|
||||
|
||||
ParserContext parserContext = new ParserContext();
|
||||
parserContext.setActor(actor);
|
||||
if (actor instanceof Entity) {
|
||||
Extent extent = ((Entity) actor).getExtent();
|
||||
if (extent instanceof World) {
|
||||
parserContext.setWorld((World) extent);
|
||||
}
|
||||
}
|
||||
parserContext.setSession(session);
|
||||
|
||||
try {
|
||||
return WorldEdit.getInstance().getPatternFactory().parseFromInput(patternString, parserContext);
|
||||
} catch (InputParseException e) {
|
||||
throw new CommandException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Choose a pattern";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission0(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.command.argument;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.regions.factory.CuboidRegionFactory;
|
||||
import com.sk89q.worldedit.regions.factory.CylinderRegionFactory;
|
||||
import com.sk89q.worldedit.regions.factory.RegionFactory;
|
||||
import com.sk89q.worldedit.regions.factory.SphereRegionFactory;
|
||||
import com.sk89q.worldedit.util.command.argument.ArgumentUtils;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.argument.MissingArgumentException;
|
||||
import com.sk89q.worldedit.util.command.composition.CommandExecutor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RegionFactoryParser implements CommandExecutor<RegionFactory> {
|
||||
|
||||
@Override
|
||||
public RegionFactory call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
try {
|
||||
String type = args.next();
|
||||
|
||||
switch (type) {
|
||||
case "cuboid":
|
||||
return new CuboidRegionFactory();
|
||||
case "sphere":
|
||||
return new SphereRegionFactory();
|
||||
case "cyl":
|
||||
case "cylinder":
|
||||
return new CylinderRegionFactory(1); // TODO: Adjustable height
|
||||
|
||||
default:
|
||||
throw new CommandException("Unknown shape type: " + type + " (try one of " + getUsage() + ")");
|
||||
}
|
||||
} catch (MissingArgumentException e) {
|
||||
throw new CommandException("Missing shape type (try one of " + getUsage() + ")");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
|
||||
return ArgumentUtils.getMatchingSuggestions(Lists.newArrayList("cuboid", "sphere", "cyl"), args.next());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "(cuboid | sphere | cyl)";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Defines a region";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.command.argument;
|
||||
|
||||
import com.sk89q.worldedit.function.Contextual;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.util.command.composition.BranchingCommand;
|
||||
|
||||
public class RegionFunctionParser extends BranchingCommand<Contextual<? extends RegionFunction>> {
|
||||
|
||||
public RegionFunctionParser() {
|
||||
super("functionTpe");
|
||||
putOption(new TreeGeneratorParser("treeType"), "forest");
|
||||
putOption(new ItemUseParser(), "item");
|
||||
putOption(new ReplaceParser(), "set");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Choose a block function";
|
||||
}
|
||||
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.command.argument;
|
||||
|
||||
import static com.sk89q.worldedit.util.GuavaUtil.firstNonNull;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.extent.NullExtent;
|
||||
import com.sk89q.worldedit.function.Contextual;
|
||||
import com.sk89q.worldedit.function.EditContext;
|
||||
import com.sk89q.worldedit.function.RegionFunction;
|
||||
import com.sk89q.worldedit.function.block.BlockReplace;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.composition.SimpleCommand;
|
||||
|
||||
|
||||
public class ReplaceParser extends SimpleCommand<Contextual<? extends RegionFunction>> {
|
||||
|
||||
private final PatternParser fillArg = addParameter(new PatternParser("fillPattern"));
|
||||
|
||||
@Override
|
||||
public Contextual<RegionFunction> call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
Pattern fill = fillArg.call(args, locals);
|
||||
return new ReplaceFactory(fill);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Replaces blocks";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean testPermission0(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static class ReplaceFactory implements Contextual<RegionFunction> {
|
||||
private final Pattern fill;
|
||||
|
||||
private ReplaceFactory(Pattern fill) {
|
||||
this.fill = fill;
|
||||
}
|
||||
|
||||
@Override
|
||||
public RegionFunction createFromContext(EditContext context) {
|
||||
return new BlockReplace(
|
||||
firstNonNull(context.getDestination(), new NullExtent()),
|
||||
firstNonNull(context.getFill(), fill));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "replace blocks";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,78 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.command.argument;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.argument.MissingArgumentException;
|
||||
import com.sk89q.worldedit.util.command.composition.CommandExecutor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class StringParser implements CommandExecutor<String> {
|
||||
|
||||
private final String name;
|
||||
private final String description;
|
||||
private final String defaultSuggestion;
|
||||
|
||||
public StringParser(String name, String description) {
|
||||
this(name, description, null);
|
||||
}
|
||||
|
||||
public StringParser(String name, String description, String defaultSuggestion) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.defaultSuggestion = defaultSuggestion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
try {
|
||||
return args.next();
|
||||
} catch (MissingArgumentException e) {
|
||||
throw new CommandException("Missing value for <" + name + ">.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
|
||||
String value = args.next();
|
||||
return value.isEmpty() && defaultSuggestion != null ? Lists.newArrayList(defaultSuggestion) : Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "<" + name + ">";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
package com.sk89q.worldedit.command.argument;
|
||||
|
||||
import org.enginehub.piston.converter.ArgumentConverter;
|
||||
|
||||
public class StringValidator implements ArgumentConverter<String> {
|
||||
}
|
@ -1,106 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.command.argument;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.function.Contextual;
|
||||
import com.sk89q.worldedit.function.EditContext;
|
||||
import com.sk89q.worldedit.function.generator.ForestGenerator;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
import com.sk89q.worldedit.util.command.argument.ArgumentUtils;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.argument.MissingArgumentException;
|
||||
import com.sk89q.worldedit.util.command.composition.CommandExecutor;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class TreeGeneratorParser implements CommandExecutor<Contextual<ForestGenerator>> {
|
||||
|
||||
private final String name;
|
||||
|
||||
public TreeGeneratorParser(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private String getOptionsList() {
|
||||
return Joiner.on(" | ").join(Arrays.asList(TreeType.values()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Contextual<ForestGenerator> call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
try {
|
||||
String input = args.next();
|
||||
TreeType type = TreeGenerator.lookup(input);
|
||||
if (type != null) {
|
||||
return new GeneratorFactory(type);
|
||||
} else {
|
||||
throw new CommandException("Unknown value for <" + name + "> (try one of " + getOptionsList() + ").");
|
||||
}
|
||||
} catch (MissingArgumentException e) {
|
||||
throw new CommandException("Missing value for <" + name + "> (try one of " + getOptionsList() + ").");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
|
||||
String s = args.next();
|
||||
return s.isEmpty() ? Lists.newArrayList(TreeType.getPrimaryAliases()) : ArgumentUtils.getMatchingSuggestions(TreeType.getAliases(), s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "<" + name + ">";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Choose a tree generator";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static final class GeneratorFactory implements Contextual<ForestGenerator> {
|
||||
private final TreeType type;
|
||||
|
||||
private GeneratorFactory(TreeType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForestGenerator createFromContext(EditContext input) {
|
||||
return new ForestGenerator((EditSession) input.getDestination(), type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "tree of type " + type;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -42,36 +42,36 @@ import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.ApplyBrushCommands;
|
||||
import com.sk89q.worldedit.command.BiomeCommands;
|
||||
import com.sk89q.worldedit.command.BiomeCommandsRegistration;
|
||||
//import com.sk89q.worldedit.command.BiomeCommandsRegistration;
|
||||
import com.sk89q.worldedit.command.BrushCommands;
|
||||
import com.sk89q.worldedit.command.ChunkCommands;
|
||||
import com.sk89q.worldedit.command.ChunkCommandsRegistration;
|
||||
//import com.sk89q.worldedit.command.ChunkCommandsRegistration;
|
||||
import com.sk89q.worldedit.command.ClipboardCommands;
|
||||
import com.sk89q.worldedit.command.ClipboardCommandsRegistration;
|
||||
//import com.sk89q.worldedit.command.ClipboardCommandsRegistration;
|
||||
import com.sk89q.worldedit.command.ExpandCommands;
|
||||
import com.sk89q.worldedit.command.GeneralCommands;
|
||||
import com.sk89q.worldedit.command.GeneralCommandsRegistration;
|
||||
//import com.sk89q.worldedit.command.GeneralCommandsRegistration;
|
||||
import com.sk89q.worldedit.command.GenerationCommands;
|
||||
import com.sk89q.worldedit.command.HistoryCommands;
|
||||
import com.sk89q.worldedit.command.HistoryCommandsRegistration;
|
||||
//import com.sk89q.worldedit.command.HistoryCommandsRegistration;
|
||||
import com.sk89q.worldedit.command.NavigationCommands;
|
||||
import com.sk89q.worldedit.command.NavigationCommandsRegistration;
|
||||
//import com.sk89q.worldedit.command.NavigationCommandsRegistration;
|
||||
import com.sk89q.worldedit.command.PaintBrushCommands;
|
||||
import com.sk89q.worldedit.command.RegionCommands;
|
||||
import com.sk89q.worldedit.command.SchematicCommands;
|
||||
import com.sk89q.worldedit.command.SchematicCommandsRegistration;
|
||||
//import com.sk89q.worldedit.command.SchematicCommandsRegistration;
|
||||
import com.sk89q.worldedit.command.ScriptingCommands;
|
||||
import com.sk89q.worldedit.command.SelectionCommands;
|
||||
import com.sk89q.worldedit.command.SnapshotCommands;
|
||||
import com.sk89q.worldedit.command.SnapshotCommandsRegistration;
|
||||
//import com.sk89q.worldedit.command.SnapshotCommandsRegistration;
|
||||
import com.sk89q.worldedit.command.SnapshotUtilCommands;
|
||||
import com.sk89q.worldedit.command.SuperPickaxeCommands;
|
||||
import com.sk89q.worldedit.command.SuperPickaxeCommandsRegistration;
|
||||
//import com.sk89q.worldedit.command.SuperPickaxeCommandsRegistration;
|
||||
import com.sk89q.worldedit.command.ToolCommands;
|
||||
import com.sk89q.worldedit.command.ToolUtilCommands;
|
||||
import com.sk89q.worldedit.command.UtilityCommands;
|
||||
import com.sk89q.worldedit.command.WorldEditCommands;
|
||||
import com.sk89q.worldedit.command.WorldEditCommandsRegistration;
|
||||
//import com.sk89q.worldedit.command.WorldEditCommandsRegistration;
|
||||
import com.sk89q.worldedit.command.argument.Arguments;
|
||||
import com.sk89q.worldedit.command.argument.BooleanConverter;
|
||||
import com.sk89q.worldedit.command.argument.CommaSeparatedValuesConverter;
|
||||
@ -104,8 +104,6 @@ import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.scripting.CommandScriptLoader;
|
||||
import com.sk89q.worldedit.session.request.Request;
|
||||
import com.sk89q.worldedit.util.auth.AuthorizationException;
|
||||
import com.sk89q.worldedit.util.command.CommandMapping;
|
||||
import com.sk89q.worldedit.util.command.parametric.AParametricCallable;
|
||||
import com.sk89q.worldedit.util.eventbus.Subscribe;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||
@ -137,6 +135,7 @@ import org.enginehub.piston.exception.ConditionFailedException;
|
||||
import org.enginehub.piston.exception.UsageException;
|
||||
import org.enginehub.piston.gen.CommandRegistration;
|
||||
import org.enginehub.piston.impl.CommandManagerServiceImpl;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import org.enginehub.piston.inject.InjectedValueStore;
|
||||
import org.enginehub.piston.inject.Key;
|
||||
import org.enginehub.piston.inject.MapBackedValueStore;
|
||||
@ -250,16 +249,17 @@ public final class PlatformCommandManager {
|
||||
});
|
||||
});
|
||||
globalInjectedValues.injectValue(Key.of(EditSession.class),
|
||||
context -> {
|
||||
LocalSession localSession = context.injectedValue(Key.of(LocalSession.class))
|
||||
.orElseThrow(() -> new IllegalStateException("No LocalSession"));
|
||||
return context.injectedValue(Key.of(Player.class))
|
||||
.map(player -> {
|
||||
EditSession editSession = localSession.createEditSession(player);
|
||||
editSession.enableStandardMode();
|
||||
return editSession;
|
||||
});
|
||||
});
|
||||
context -> {
|
||||
LocalSession localSession = context.injectedValue(Key.of(LocalSession.class))
|
||||
.orElseThrow(() -> new IllegalStateException("No LocalSession"));
|
||||
return context.injectedValue(Key.of(Player.class))
|
||||
.map(player -> {
|
||||
EditSession editSession = localSession.createEditSession(player);
|
||||
editSession.enableStandardMode();
|
||||
return editSession;
|
||||
});
|
||||
});
|
||||
globalInjectedValues.injectValue(Key.of(InjectedValueAccess.class), context -> Optional.of(context));
|
||||
}
|
||||
|
||||
private <CI> void registerSubCommands(String name, List<String> aliases, String desc,
|
||||
@ -581,14 +581,12 @@ public final class PlatformCommandManager {
|
||||
}
|
||||
|
||||
ThrowableSupplier<Throwable> task =
|
||||
() -> commandManager.execute(context,Lists.newArrayList(split));
|
||||
() -> commandManager.execute(context,Lists.newArrayList(split));
|
||||
|
||||
handleCommandTask(task, context, actor, session, event);
|
||||
}
|
||||
|
||||
public Object handleCommandTask(ThrowableSupplier<Throwable> task,
|
||||
MemoizingValueAccess context, @NotNull
|
||||
Actor actor, @Nullable LocalSession session, CommandEvent event) {
|
||||
public Object handleCommandTask(ThrowableSupplier<Throwable> task, InjectedValueAccess context, @NotNull Actor actor, @Nullable LocalSession session, CommandEvent event) {
|
||||
String[] split = parseArgs(event.getArguments())
|
||||
.map(Substring::getSubstring)
|
||||
.toArray(String[]::new);
|
||||
@ -602,7 +600,7 @@ public final class PlatformCommandManager {
|
||||
// exceptions without writing a hook into every dispatcher, we need to unwrap these
|
||||
// exceptions and rethrow their converted form, if their is one.
|
||||
try {
|
||||
commandManager.execute(context, ImmutableList.copyOf(split));
|
||||
return task.get();
|
||||
} catch (Throwable t) {
|
||||
// Use the exception converter to convert the exception if any of its causes
|
||||
// can be converted, otherwise throw the original exception
|
||||
@ -642,8 +640,13 @@ public final class PlatformCommandManager {
|
||||
} catch (Throwable t) {
|
||||
handleUnknownException(actor, t);
|
||||
} finally {
|
||||
if (context instanceof MemoizingValueAccess) {
|
||||
context = ((MemoizingValueAccess) context).snapshotMemory();
|
||||
} else {
|
||||
System.out.println("Invalid context " + context);
|
||||
}
|
||||
Optional<EditSession> editSessionOpt =
|
||||
context.snapshotMemory().injectedValue(Key.of(EditSession.class));
|
||||
context.injectedValue(Key.of(EditSession.class));
|
||||
|
||||
if (editSessionOpt.isPresent()) {
|
||||
EditSession editSession = editSessionOpt.get();
|
||||
|
@ -17,7 +17,9 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.binding;
|
||||
package com.sk89q.worldedit.internal.annotation;
|
||||
|
||||
import com.sk89q.worldedit.util.command.binding.PrimitiveBindings;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.binding;
|
||||
package com.sk89q.worldedit.internal.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
@ -1,12 +0,0 @@
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
|
||||
public interface CallableProcessor<T> {
|
||||
public Object process(CommandLocals locals, T value) throws CommandException, WorldEditException;
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
|
||||
/**
|
||||
* A command that can be executed.
|
||||
*/
|
||||
public interface CommandCallable extends CommandCompleter {
|
||||
|
||||
/**
|
||||
* Execute the correct command based on the input.
|
||||
*
|
||||
* <p>The implementing class must perform the necessary permission
|
||||
* checks.</p>
|
||||
*
|
||||
* @param arguments the arguments
|
||||
* @param locals the locals
|
||||
* @param parentCommands a list of parent commands, with the first most entry being the top-level command
|
||||
* @return the called command, or null if there was no command found
|
||||
* @throws CommandException thrown on a command error
|
||||
*/
|
||||
Object call(String arguments, CommandLocals locals, String[] parentCommands) throws CommandException;
|
||||
|
||||
/**
|
||||
* Get an object describing this command.
|
||||
*
|
||||
* @return the command description
|
||||
*/
|
||||
Description getDescription();
|
||||
|
||||
/**
|
||||
* Test whether this command can be executed with the given context.
|
||||
*
|
||||
* @param locals the locals
|
||||
* @return true if execution is permitted
|
||||
*/
|
||||
boolean testPermission(CommandLocals locals);
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides a method that can provide tab completion for commands.
|
||||
*/
|
||||
public interface CommandCompleter {
|
||||
|
||||
/**
|
||||
* Get a list of suggestions based on input.
|
||||
*
|
||||
* @param arguments the arguments entered up to this point
|
||||
* @param locals the locals
|
||||
* @return a list of suggestions
|
||||
* @throws CommandException thrown if there was a parsing error
|
||||
*/
|
||||
List<String> getSuggestions(String arguments, CommandLocals locals) throws CommandException;
|
||||
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
/**
|
||||
* Provides information about a mapping between a command and its aliases.
|
||||
*/
|
||||
public interface CommandMapping {
|
||||
|
||||
/**
|
||||
* Get the primary alias.
|
||||
*
|
||||
* @return the primary alias
|
||||
*/
|
||||
String getPrimaryAlias();
|
||||
|
||||
/**
|
||||
* Get a list of all aliases.
|
||||
*
|
||||
* @return aliases
|
||||
*/
|
||||
String[] getAllAliases();
|
||||
|
||||
/**
|
||||
* Get the callable
|
||||
*
|
||||
* @return the callable
|
||||
*/
|
||||
CommandCallable getCallable();
|
||||
|
||||
/**
|
||||
* Get the {@link Description} form the callable.
|
||||
*
|
||||
* @return the description
|
||||
*/
|
||||
Description getDescription();
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import java.util.List;
|
||||
|
||||
public class DelegateCallable implements CommandCallable {
|
||||
private final CommandCallable parent;
|
||||
|
||||
public CommandCallable getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public DelegateCallable(CommandCallable parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object call(String arguments, CommandLocals locals, String[] parentCommands) throws CommandException {
|
||||
return parent.call(arguments, locals, parentCommands);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Description getDescription() {
|
||||
return parent.getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
return parent.testPermission(locals);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(String arguments, CommandLocals locals) throws CommandException {
|
||||
return parent.getSuggestions(arguments, locals);
|
||||
}
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A description of a command.
|
||||
*/
|
||||
public interface Description {
|
||||
|
||||
/**
|
||||
* Get the list of parameters for this command.
|
||||
*
|
||||
* @return a list of parameters
|
||||
*/
|
||||
List<Parameter> getParameters();
|
||||
|
||||
/**
|
||||
* Get a short one-line description of this command.
|
||||
*
|
||||
* @return a description, or null if no description is available
|
||||
*/
|
||||
String getDescription();
|
||||
|
||||
/**
|
||||
* Get a longer help text about this command.
|
||||
*
|
||||
* @return a help text, or null if no help is available
|
||||
*/
|
||||
String getHelp();
|
||||
|
||||
/**
|
||||
* Get the usage string of this command.
|
||||
*
|
||||
* <p>A usage string may look like
|
||||
* {@code [-w <world>] <var1> <var2>}.</p>
|
||||
*
|
||||
* @return a usage string
|
||||
*/
|
||||
String getUsage();
|
||||
|
||||
/**
|
||||
* Get a list of permissions that the player may have to have permission.
|
||||
*
|
||||
* <p>Permission data may or may not be available. This is only useful as a
|
||||
* potential hint.</p>
|
||||
*
|
||||
* @return the list of permissions
|
||||
*/
|
||||
List<String> getPermissions();
|
||||
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Executes a command based on user input.
|
||||
*/
|
||||
public interface Dispatcher extends CommandCallable {
|
||||
|
||||
/**
|
||||
* Register a command with this dispatcher.
|
||||
*
|
||||
* @param callable the command executor
|
||||
* @param alias a list of aliases, where the first alias is the primary name
|
||||
*/
|
||||
void registerCommand(CommandCallable callable, String... alias);
|
||||
|
||||
/**
|
||||
* Get a list of commands. Each command, regardless of how many aliases
|
||||
* it may have, will only appear once in the returned set.
|
||||
*
|
||||
* <p>The returned collection cannot be modified.</p>
|
||||
*
|
||||
* @return a list of registrations
|
||||
*/
|
||||
Set<CommandMapping> getCommands();
|
||||
|
||||
/**
|
||||
* Get a list of primary aliases.
|
||||
*
|
||||
* <p>The returned collection cannot be modified.</p>
|
||||
*
|
||||
* @return a list of aliases
|
||||
*/
|
||||
Collection<String> getPrimaryAliases();
|
||||
|
||||
/**
|
||||
* Get a list of all the command aliases, which includes the primary alias.
|
||||
*
|
||||
* <p>A command may have more than one alias assigned to it. The returned
|
||||
* collection cannot be modified.</p>
|
||||
*
|
||||
* @return a list of aliases
|
||||
*/
|
||||
Collection<String> getAliases();
|
||||
|
||||
/**
|
||||
* Get the {@link CommandCallable} associated with an alias. Returns
|
||||
* null if no command is named by the given alias.
|
||||
*
|
||||
* @param alias the alias
|
||||
* @return the command mapping (null if not found)
|
||||
*/
|
||||
@Nullable CommandMapping get(String alias);
|
||||
|
||||
/**
|
||||
* Returns whether the dispatcher contains a registered command for the given alias.
|
||||
*
|
||||
* @param alias the alias
|
||||
* @return true if a registered command exists
|
||||
*/
|
||||
boolean contains(String alias);
|
||||
|
||||
}
|
@ -1,107 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Thrown when a command is not used properly.
|
||||
*
|
||||
* <p>When handling this exception, print the error message if it is not null.
|
||||
* Print a one line help instruction unless {@link #isFullHelpSuggested()}
|
||||
* is true, which, in that case, the full help of the command should be
|
||||
* shown.</p>
|
||||
*
|
||||
* <p>If no error message is set and full help is not to be shown, then a generic
|
||||
* "you used this command incorrectly" message should be shown.</p>
|
||||
*/
|
||||
public class InvalidUsageException extends CommandException {
|
||||
|
||||
private final CommandCallable command;
|
||||
private final boolean fullHelpSuggested;
|
||||
|
||||
/**
|
||||
* Create a new instance with no error message and with no suggestion
|
||||
* that full and complete help for the command should be shown. This will
|
||||
* result in a generic error message.
|
||||
*
|
||||
* @param command the command
|
||||
*/
|
||||
public InvalidUsageException(CommandCallable command) {
|
||||
this(null, command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance with a message and with no suggestion
|
||||
* that full and complete help for the command should be shown.
|
||||
*
|
||||
* @param message the message
|
||||
* @param command the command
|
||||
*/
|
||||
public InvalidUsageException(@Nullable String message, CommandCallable command) {
|
||||
this(message, command, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance with a message.
|
||||
*
|
||||
* @param message the message
|
||||
* @param command the command
|
||||
* @param fullHelpSuggested true if the full help for the command should be shown
|
||||
*/
|
||||
public InvalidUsageException(@Nullable String message, CommandCallable command, boolean fullHelpSuggested) {
|
||||
super(message);
|
||||
checkNotNull(command);
|
||||
this.command = command;
|
||||
this.fullHelpSuggested = fullHelpSuggested;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the command.
|
||||
*
|
||||
* @return the command
|
||||
*/
|
||||
public CommandCallable getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a simple usage string.
|
||||
*
|
||||
* @param prefix the command shebang (such as "/") -- may be blank
|
||||
* @return a usage string
|
||||
*/
|
||||
public String getSimpleUsageString(String prefix) {
|
||||
return getCommandUsed(prefix, command.getDescription().getUsage());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the full usage of the command should be shown.
|
||||
*
|
||||
* @return show full usage
|
||||
*/
|
||||
public boolean isFullHelpSuggested() {
|
||||
return fullHelpSuggested;
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
import com.sk89q.worldedit.util.command.parametric.ParameterException;
|
||||
|
||||
/**
|
||||
* Thrown when there is a missing parameter.
|
||||
*/
|
||||
public class MissingParameterException extends ParameterException {
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Always returns an empty list of suggestions.
|
||||
*/
|
||||
public class NullCompleter implements CommandCompleter {
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(String arguments, CommandLocals locals) throws CommandException {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
}
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
/**
|
||||
* Describes a parameter.
|
||||
*
|
||||
* @see Description
|
||||
*/
|
||||
public interface Parameter {
|
||||
|
||||
/**
|
||||
* The name of the parameter.
|
||||
*
|
||||
* @return the name
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* Get the flag associated with this parameter.
|
||||
*
|
||||
* @return the flag, or null if there is no flag associated
|
||||
* @see #isValueFlag()
|
||||
*/
|
||||
Character getFlag();
|
||||
|
||||
/**
|
||||
* Return whether the flag is a value flag.
|
||||
*
|
||||
* @return true if the flag is a value flag
|
||||
* @see #getFlag()
|
||||
*/
|
||||
boolean isValueFlag();
|
||||
|
||||
/**
|
||||
* Get whether this parameter is optional.
|
||||
*
|
||||
* @return true if the parameter does not have to be specified
|
||||
*/
|
||||
boolean isOptional();
|
||||
|
||||
/**
|
||||
* Get the default value as a string to be parsed by the binding.
|
||||
*
|
||||
* @return a default value, or null if none is set
|
||||
*/
|
||||
String[] getDefaultValue();
|
||||
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Compares the primary aliases of two {@link CommandMapping} using
|
||||
* {@link String#compareTo(String)}.
|
||||
*/
|
||||
public final class PrimaryAliasComparator implements Comparator<CommandMapping> {
|
||||
|
||||
/**
|
||||
* An instance of this class.
|
||||
*/
|
||||
public static final PrimaryAliasComparator INSTANCE = new PrimaryAliasComparator(null);
|
||||
private final @Nullable Pattern removalPattern;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param removalPattern a regex to remove unwanted characters from the compared aliases
|
||||
*/
|
||||
public PrimaryAliasComparator(@Nullable Pattern removalPattern) {
|
||||
this.removalPattern = removalPattern;
|
||||
}
|
||||
|
||||
private String clean(String alias) {
|
||||
if (removalPattern != null) {
|
||||
return removalPattern.matcher(alias).replaceAll("");
|
||||
}
|
||||
return alias;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(CommandMapping o1, CommandMapping o2) {
|
||||
return clean(o1.getPrimaryAlias()).compareTo(clean(o2.getPrimaryAlias()));
|
||||
}
|
||||
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
public class ProcessedCallable extends DelegateCallable {
|
||||
private final CallableProcessor processor;
|
||||
|
||||
public ProcessedCallable(CommandCallable parent, CallableProcessor processor) {
|
||||
super(parent);
|
||||
checkNotNull(processor);
|
||||
this.processor = processor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object call(String arguments, CommandLocals locals, String[] parentCommands) throws CommandException {
|
||||
try {
|
||||
return processor.process(locals, super.call(arguments, locals, parentCommands));
|
||||
} catch (WorldEditException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
import com.sk89q.worldedit.util.command.parametric.ParametricCallable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Tracks a command registration.
|
||||
*/
|
||||
public class SimpleCommandMapping implements CommandMapping {
|
||||
|
||||
private final String[] aliases;
|
||||
private final CommandCallable callable;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param callable the command callable
|
||||
* @param alias a list of all aliases, where the first one is the primary one
|
||||
*/
|
||||
public SimpleCommandMapping(CommandCallable callable, String... alias) {
|
||||
super();
|
||||
this.aliases = alias;
|
||||
this.callable = callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPrimaryAlias() {
|
||||
return aliases[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getAllAliases() {
|
||||
return aliases;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandCallable getCallable() {
|
||||
return callable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Description getDescription() {
|
||||
return getCallable().getDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return getPrimaryAlias().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null || !(obj instanceof CommandMapping)) {
|
||||
return false;
|
||||
}
|
||||
CommandMapping other = (CommandMapping) obj;
|
||||
if (other.getCallable() != getCallable()) {
|
||||
if (other.getCallable().getClass() != getCallable().getClass() || !(getCallable() instanceof ParametricCallable)) {
|
||||
return false;
|
||||
}
|
||||
Method oMeth = ((ParametricCallable) other.getCallable()).getMethod();
|
||||
Method meth = ((ParametricCallable) getCallable()).getMethod();
|
||||
if (!oMeth.equals(meth)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return other.getPrimaryAlias().equals(getPrimaryAlias());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "CommandMapping{" +
|
||||
"aliases=" + Arrays.toString(aliases) +
|
||||
", callable=" + callable +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
@ -1,135 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A simple implementation of {@link Description} which has setters.
|
||||
*/
|
||||
public class SimpleDescription implements Description {
|
||||
|
||||
private List<Parameter> parameters = new ArrayList<>();
|
||||
private List<String> permissions = new ArrayList<>();
|
||||
private String description;
|
||||
private String help;
|
||||
private String overrideUsage;
|
||||
|
||||
@Override
|
||||
public List<Parameter> getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of parameters.
|
||||
*
|
||||
* @param parameters the list of parameters
|
||||
* @see #getParameters()
|
||||
*/
|
||||
public SimpleDescription setParameters(List<Parameter> parameters) {
|
||||
this.parameters = Collections.unmodifiableList(parameters);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the description of the command.
|
||||
*
|
||||
* @param description the description
|
||||
* @see #getDescription()
|
||||
*/
|
||||
public SimpleDescription setDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return help;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the help text of the command.
|
||||
*
|
||||
* @param help the help text
|
||||
* @see #getHelp()
|
||||
*/
|
||||
public SimpleDescription setHelp(String help) {
|
||||
this.help = help;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the permissions of this command.
|
||||
*
|
||||
* @param permissions the permissions
|
||||
*/
|
||||
public SimpleDescription setPermissions(List<String> permissions) {
|
||||
this.permissions = Collections.unmodifiableList(permissions);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the usage string returned with a given one.
|
||||
*
|
||||
* @param usage usage string, or null
|
||||
*/
|
||||
public SimpleDescription overrideUsage(String usage) {
|
||||
this.overrideUsage = usage;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
if (overrideUsage != null) {
|
||||
return overrideUsage;
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
boolean first = true;
|
||||
|
||||
for (Parameter parameter : parameters) {
|
||||
if (!first) {
|
||||
builder.append(" ");
|
||||
}
|
||||
builder.append(parameter);
|
||||
first = false;
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getUsage();
|
||||
}
|
||||
|
||||
}
|
@ -1,196 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
|
||||
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.worldedit.command.util.CommandPermissionsException;
|
||||
import com.sk89q.minecraft.util.commands.WrappedCommandException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A simple implementation of {@link Dispatcher}.
|
||||
*/
|
||||
public class SimpleDispatcher implements Dispatcher {
|
||||
|
||||
private final Map<String, CommandMapping> commands = new HashMap<>();
|
||||
private final SimpleDescription description = new SimpleDescription();
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*/
|
||||
public SimpleDispatcher() {
|
||||
description.getParameters().add(new SimpleParameter("subcommand"));
|
||||
SimpleParameter extraArgs = new SimpleParameter("...");
|
||||
extraArgs.setOptional(true);
|
||||
description.getParameters().add(extraArgs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCommand(CommandCallable callable, String... alias) {
|
||||
CommandMapping mapping = new SimpleCommandMapping(callable, alias);
|
||||
|
||||
// Check for replacements
|
||||
for (String a : alias) {
|
||||
String lower = a.toLowerCase();
|
||||
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());
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
Fawe.debug("Replacing commands is currently undefined behavior: " + StringMan.getString(alias));
|
||||
commands.put(lower, mapping);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
commands.putIfAbsent(lower, mapping);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<CommandMapping> getCommands() {
|
||||
return Collections.unmodifiableSet(new HashSet<>(commands.values()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getAliases() {
|
||||
return Collections.unmodifiableSet(commands.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getPrimaryAliases() {
|
||||
Set<String> aliases = new HashSet<>();
|
||||
for (CommandMapping mapping : getCommands()) {
|
||||
aliases.add(mapping.getPrimaryAlias());
|
||||
}
|
||||
return Collections.unmodifiableSet(aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(String alias) {
|
||||
return commands.containsKey(alias.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandMapping get(String alias) {
|
||||
return commands.get(alias.toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object call(String arguments, CommandLocals locals, String[] parentCommands) throws CommandException {
|
||||
// We have permission for this command if we have permissions for subcommands
|
||||
if (parentCommands.length != 0 && !testPermission(locals)) {
|
||||
throw new CommandPermissionsException();
|
||||
}
|
||||
|
||||
String[] split = CommandContext.split(arguments);
|
||||
Set<String> aliases = getPrimaryAliases();
|
||||
|
||||
if (aliases.isEmpty()) {
|
||||
throw new InvalidUsageException("This command has no sub-commands.", this);
|
||||
} else if (split.length > 0) {
|
||||
String subCommand = split[0];
|
||||
String subArguments = Joiner.on(" ").join(Arrays.copyOfRange(split, 1, split.length));
|
||||
String[] subParents = Arrays.copyOf(parentCommands, parentCommands.length + 1);
|
||||
subParents[parentCommands.length] = subCommand;
|
||||
CommandMapping mapping = get(subCommand);
|
||||
|
||||
if (mapping != null) {
|
||||
try {
|
||||
return mapping.getCallable().call(subArguments, locals, subParents);
|
||||
} catch (CommandException e) {
|
||||
e.prependStack(subCommand);
|
||||
throw e;
|
||||
} catch (Throwable t) {
|
||||
throw new WrappedCommandException(t);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
throw new InvalidUsageException("Please choose a sub-command.", this, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(String arguments, CommandLocals locals) throws CommandException {
|
||||
String[] split = CommandContext.split(arguments);
|
||||
|
||||
if (split.length <= 1) {
|
||||
String prefix = split.length > 0 ? split[0] : "";
|
||||
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
|
||||
for (CommandMapping mapping : getCommands()) {
|
||||
if (mapping.getCallable().testPermission(locals)) {
|
||||
for (String alias : mapping.getAllAliases()) {
|
||||
if (prefix.isEmpty() || alias.startsWith(arguments)) {
|
||||
suggestions.add(mapping.getPrimaryAlias());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return suggestions;
|
||||
} else {
|
||||
String subCommand = split[0];
|
||||
CommandMapping mapping = get(subCommand);
|
||||
String passedArguments = Joiner.on(" ").join(Arrays.copyOfRange(split, 1, split.length));
|
||||
|
||||
if (mapping != null) {
|
||||
return mapping.getCallable().getSuggestions(passedArguments, locals);
|
||||
} else {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimpleDescription getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
// Checking every perm in the class here was unnecessarily stupid
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,134 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
/**
|
||||
* A simple implementation of {@link Parameter} that has setters.
|
||||
*/
|
||||
public class SimpleParameter implements Parameter {
|
||||
|
||||
private String name;
|
||||
private Character flag;
|
||||
private boolean isValue;
|
||||
private boolean isOptional;
|
||||
private String[] defaultValue;
|
||||
|
||||
/**
|
||||
* Create a new parameter with no name defined yet.
|
||||
*/
|
||||
public SimpleParameter() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new parameter of the given name.
|
||||
*
|
||||
* @param name the name
|
||||
*/
|
||||
public SimpleParameter(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the parameter.
|
||||
*
|
||||
* @param name the parameter name
|
||||
*/
|
||||
public SimpleParameter setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Character getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValueFlag() {
|
||||
return flag != null && isValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the flag used by this parameter.
|
||||
* @param flag the flag, or null if there is no flag
|
||||
* @param isValue true if the flag is a value flag
|
||||
*/
|
||||
public SimpleParameter setFlag(Character flag, boolean isValue) {
|
||||
this.flag = flag;
|
||||
this.isValue = isValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOptional() {
|
||||
return isOptional || getFlag() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this parameter is optional.
|
||||
*
|
||||
* @param isOptional true if this parameter is optional
|
||||
*/
|
||||
public SimpleParameter setOptional(boolean isOptional) {
|
||||
this.isOptional = isOptional;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default value.
|
||||
*
|
||||
* @param defaultValue a default value, or null if none
|
||||
*/
|
||||
public SimpleParameter setDefaultValue(String[] defaultValue) {
|
||||
this.defaultValue = defaultValue;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if (getFlag() != null) {
|
||||
if (isValueFlag()) {
|
||||
builder.append("[-")
|
||||
.append(getFlag()).append(" <").append(getName()).append(">]");
|
||||
} else {
|
||||
builder.append("[-").append(getFlag()).append("]");
|
||||
}
|
||||
} else {
|
||||
if (isOptional()) {
|
||||
builder.append("[<").append(getName()).append(">]");
|
||||
} else {
|
||||
builder.append("<").append(getName()).append(">");
|
||||
}
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command;
|
||||
|
||||
import com.sk89q.worldedit.util.command.parametric.ParameterException;
|
||||
|
||||
/**
|
||||
* Thrown when there are leftover parameters that were not consumed, particular in the
|
||||
* case of the user providing too many parameters.
|
||||
*/
|
||||
public class UnconsumedParameterException extends ParameterException {
|
||||
|
||||
private String unconsumed;
|
||||
|
||||
public UnconsumedParameterException(String unconsumed) {
|
||||
this.unconsumed = unconsumed;
|
||||
}
|
||||
|
||||
public String getUnconsumed() {
|
||||
return unconsumed;
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.argument;
|
||||
|
||||
public class ArgumentException extends Exception {
|
||||
|
||||
public ArgumentException() {
|
||||
}
|
||||
|
||||
public ArgumentException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ArgumentException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ArgumentException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.argument;
|
||||
|
||||
public class ArgumentParseException extends ArgumentException {
|
||||
|
||||
public ArgumentParseException() {
|
||||
}
|
||||
|
||||
public ArgumentParseException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ArgumentParseException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ArgumentParseException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.argument;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public final class ArgumentUtils {
|
||||
|
||||
private ArgumentUtils() {
|
||||
}
|
||||
|
||||
public static List<String> getMatchingSuggestions(Collection<String> items, String s) {
|
||||
if (s.isEmpty()) {
|
||||
return Lists.newArrayList(items);
|
||||
}
|
||||
List<String> suggestions = Lists.newArrayList();
|
||||
for (String item : items) {
|
||||
if (item.toLowerCase(Locale.ROOT).startsWith(s)) {
|
||||
suggestions.add(item);
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
}
|
@ -1,162 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.argument;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandArgs {
|
||||
|
||||
private final List<String> arguments;
|
||||
private int position = 0;
|
||||
|
||||
public CommandArgs(List<String> arguments) {
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
public CommandArgs(CommandArgs args) {
|
||||
this(Lists.newArrayList(args.arguments));
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return position < arguments.size();
|
||||
}
|
||||
|
||||
public String next() throws MissingArgumentException {
|
||||
try {
|
||||
return arguments.get(position++);
|
||||
} catch (IndexOutOfBoundsException ignored) {
|
||||
throw new MissingArgumentException("Too few arguments specified.");
|
||||
}
|
||||
}
|
||||
|
||||
public String uncheckedNext() {
|
||||
if (hasNext()) {
|
||||
return arguments.get(position);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String peek() throws MissingArgumentException {
|
||||
try {
|
||||
return arguments.get(position);
|
||||
} catch (IndexOutOfBoundsException ignored) {
|
||||
throw new MissingArgumentException("Too few arguments specified.");
|
||||
}
|
||||
}
|
||||
|
||||
public String uncheckedPeek() {
|
||||
if (hasNext()) {
|
||||
return arguments.get(position);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String remaining() throws MissingArgumentException {
|
||||
if (hasNext()) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
boolean first = true;
|
||||
while (hasNext()) {
|
||||
if (!first) {
|
||||
builder.append(" ");
|
||||
}
|
||||
builder.append(next());
|
||||
first = false;
|
||||
}
|
||||
return builder.toString();
|
||||
} else {
|
||||
throw new MissingArgumentException("Too few arguments specified.");
|
||||
}
|
||||
}
|
||||
|
||||
public String peekRemaining() throws MissingArgumentException {
|
||||
if (hasNext()) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
boolean first = true;
|
||||
while (hasNext()) {
|
||||
if (!first) {
|
||||
builder.append(" ");
|
||||
}
|
||||
builder.append(next());
|
||||
first = false;
|
||||
}
|
||||
return builder.toString();
|
||||
} else {
|
||||
throw new MissingArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
public int position() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return arguments.size();
|
||||
}
|
||||
|
||||
public void markConsumed() {
|
||||
position = arguments.size();
|
||||
}
|
||||
|
||||
public void requireAllConsumed() throws UnusedArgumentsException {
|
||||
if (hasNext()) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
try {
|
||||
builder.append(peekRemaining());
|
||||
} catch (MissingArgumentException e) {
|
||||
throw new RuntimeException("This should not have happened", e);
|
||||
}
|
||||
throw new UnusedArgumentsException("There were unused arguments: " + builder);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Parser {
|
||||
private boolean usingHangingArguments = false;
|
||||
|
||||
public boolean isUsingHangingArguments() {
|
||||
return usingHangingArguments;
|
||||
}
|
||||
|
||||
public Parser setUsingHangingArguments(boolean usingHangingArguments) {
|
||||
this.usingHangingArguments = usingHangingArguments;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandArgs parse(String arguments) throws CommandException {
|
||||
CommandContext context = new CommandContext(CommandContext.split("_ " + arguments), Collections.<Character>emptySet(), false, null, false);
|
||||
List<String> args = Lists.newArrayList();
|
||||
for (int i = 0; i < context.argsLength(); i++) {
|
||||
args.add(context.getString(i));
|
||||
}
|
||||
if (isUsingHangingArguments()) {
|
||||
if (arguments.isEmpty() || arguments.endsWith(" ")) {
|
||||
args.add("");
|
||||
}
|
||||
}
|
||||
return new CommandArgs(args);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.argument;
|
||||
|
||||
public class MissingArgumentException extends ArgumentException {
|
||||
|
||||
public MissingArgumentException() {
|
||||
}
|
||||
|
||||
public MissingArgumentException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public MissingArgumentException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public MissingArgumentException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.argument;
|
||||
|
||||
public class UnusedArgumentsException extends ArgumentException {
|
||||
|
||||
public UnusedArgumentsException() {
|
||||
}
|
||||
|
||||
public UnusedArgumentsException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public UnusedArgumentsException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public UnusedArgumentsException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -1,211 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.binding;
|
||||
|
||||
import com.sk89q.worldedit.internal.expression.Expression;
|
||||
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
||||
import com.sk89q.worldedit.internal.expression.runtime.EvaluationException;
|
||||
import com.sk89q.worldedit.util.command.parametric.ArgumentStack;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingBehavior;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingHelper;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingMatch;
|
||||
import com.sk89q.worldedit.util.command.parametric.ParameterException;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static com.sk89q.worldedit.util.command.parametric.BindingHelper.validate;
|
||||
|
||||
/**
|
||||
* Handles basic Java types such as {@link String}s, {@link Byte}s, etc.
|
||||
*
|
||||
* <p>Handles both the object and primitive types.</p>
|
||||
*/
|
||||
public final class PrimitiveBindings {
|
||||
|
||||
/**
|
||||
* Gets a type from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @param text the text annotation
|
||||
* @param modifiers a list of modifiers
|
||||
* @return the requested type
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(classifier = Text.class,
|
||||
type = String.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = -1,
|
||||
provideModifiers = true)
|
||||
public String getText(ArgumentStack context, Text text, Annotation[] modifiers)
|
||||
throws ParameterException {
|
||||
String v = context.remaining();
|
||||
validate(v, modifiers);
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a type from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @param modifiers a list of modifiers
|
||||
* @return the requested type
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = String.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
public String getString(ArgumentStack context, Annotation[] modifiers)
|
||||
throws ParameterException {
|
||||
String v = context.next();
|
||||
validate(v, modifiers);
|
||||
return v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a type from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return the requested type
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = { Boolean.class, boolean.class },
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public Boolean getBoolean(ArgumentStack context) throws ParameterException {
|
||||
return context.nextBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to parse numeric input as either a number or a mathematical expression.
|
||||
*
|
||||
* @param input input
|
||||
* @return a number
|
||||
* @throws ParameterException thrown on parse error
|
||||
*/
|
||||
private @Nullable Double parseNumericInput(@Nullable String input) throws ParameterException {
|
||||
if (input == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return Double.parseDouble(input);
|
||||
} catch (NumberFormatException e1) {
|
||||
try {
|
||||
Expression expression = Expression.compile(input);
|
||||
return expression.evaluate();
|
||||
} catch (EvaluationException e) {
|
||||
throw new ParameterException(String.format(
|
||||
"Expected '%s' to be a valid number (or a valid mathematical expression)", input));
|
||||
} catch (ExpressionException e) {
|
||||
throw new ParameterException(String.format(
|
||||
"Expected '%s' to be a number or valid math expression (error: %s)", input, e.getMessage()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a type from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @param modifiers a list of modifiers
|
||||
* @return the requested type
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = { Integer.class, int.class },
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
public Integer getInteger(ArgumentStack context, Annotation[] modifiers) throws ParameterException {
|
||||
Double v = parseNumericInput(context.next());
|
||||
if (v != null) {
|
||||
int intValue = v.intValue();
|
||||
validate(intValue, modifiers);
|
||||
return intValue;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a type from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @param modifiers a list of modifiers
|
||||
* @return the requested type
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = { Short.class, short.class },
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
public Short getShort(ArgumentStack context, Annotation[] modifiers) throws ParameterException {
|
||||
Integer v = getInteger(context, modifiers);
|
||||
if (v != null) {
|
||||
return v.shortValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a type from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @param modifiers a list of modifiers
|
||||
* @return the requested type
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = { Double.class, double.class },
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
public Double getDouble(ArgumentStack context, Annotation[] modifiers) throws ParameterException {
|
||||
Double v = parseNumericInput(context.next());
|
||||
if (v != null) {
|
||||
validate(v, modifiers);
|
||||
return v;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a type from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @param modifiers a list of modifiers
|
||||
* @return the requested type
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = { Float.class, float.class },
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true)
|
||||
public Float getFloat(ArgumentStack context, Annotation[] modifiers) throws ParameterException {
|
||||
Double v = getDouble(context, modifiers);
|
||||
if (v != null) {
|
||||
return v.floatValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.binding;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.worldedit.util.command.parametric.ArgumentStack;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingBehavior;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingHelper;
|
||||
import com.sk89q.worldedit.util.command.parametric.BindingMatch;
|
||||
import com.sk89q.worldedit.util.command.parametric.ParameterException;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import static com.sk89q.worldedit.util.command.parametric.BindingHelper.validate;
|
||||
|
||||
/**
|
||||
* Standard bindings that should be available to most configurations.
|
||||
*/
|
||||
public final class StandardBindings {
|
||||
|
||||
/**
|
||||
* Gets a {@link CommandContext} from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return a selection
|
||||
*/
|
||||
@BindingMatch(type = CommandContext.class,
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
public CommandContext getCommandContext(ArgumentStack context) {
|
||||
context.markConsumed(); // Consume entire stack
|
||||
return context.getContext();
|
||||
}
|
||||
|
||||
@BindingMatch(
|
||||
type = Annotation[].class,
|
||||
behavior = BindingBehavior.PROVIDES,
|
||||
consumedCount = 0,
|
||||
provideModifiers = true,
|
||||
provideType = true)
|
||||
public Annotation[] getModifiers(ArgumentStack context, Annotation[] modifiers, Type type) throws ParameterException {
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
@BindingMatch(
|
||||
type = Type.class,
|
||||
behavior = BindingBehavior.PROVIDES,
|
||||
consumedCount = 0,
|
||||
provideModifiers = true,
|
||||
provideType = true)
|
||||
public Type getType(ArgumentStack context, Annotation[] modifiers, Type type) throws ParameterException {
|
||||
return type;
|
||||
}
|
||||
|
||||
@BindingMatch(
|
||||
type = Enum.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1,
|
||||
provideModifiers = true,
|
||||
provideType = true)
|
||||
public Enum getEnum(ArgumentStack context, Annotation[] modifiers, Type type) throws ParameterException {
|
||||
String input = context.next();
|
||||
Enum value;
|
||||
try {
|
||||
value = Enum.valueOf((Class<Enum>) type, input);
|
||||
} catch (IllegalArgumentException ignore) {
|
||||
try {
|
||||
value = Enum.valueOf((Class<Enum>) type, input.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new ParameterException("Invalid input " + input + " for type " + type);
|
||||
}
|
||||
}
|
||||
validate(value.ordinal(), modifiers);
|
||||
validate(input, modifiers);
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.binding;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Indicates a command flag, such as {@code /command -f}.
|
||||
*
|
||||
* <p>If used on a boolean type, then the flag will be a non-value flag. If
|
||||
* used on any other type, then the flag will be a value flag.</p>
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.PARAMETER)
|
||||
public @interface Switch {
|
||||
|
||||
/**
|
||||
* The flag character.
|
||||
*
|
||||
* @return the flag character (A-Z a-z 0-9 is acceptable)
|
||||
*/
|
||||
char value();
|
||||
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.binding;
|
||||
|
||||
import com.sk89q.worldedit.util.command.parametric.ArgumentStack;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Indicates a {@link String} parameter will call {@link ArgumentStack#remaining()} and
|
||||
* therefore consume all remaining arguments.
|
||||
*
|
||||
* <p>This should only be used at the end of a list of parameters (of parameters that
|
||||
* need to consume from the stack of arguments), otherwise following parameters will
|
||||
* have no values left to consume.</p>
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.PARAMETER)
|
||||
public @interface Text {
|
||||
|
||||
}
|
@ -1,112 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.composition;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.util.command.argument.ArgumentUtils;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.argument.MissingArgumentException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public abstract class BranchingCommand<T> implements CommandExecutor<T> {
|
||||
|
||||
private final String name;
|
||||
private final Map<String, CommandExecutor<? extends T>> options = Maps.newHashMap();
|
||||
private final Set<String> primaryAliases = Sets.newHashSet();
|
||||
|
||||
public BranchingCommand(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void putOption(CommandExecutor<? extends T> executor, String primaryAlias, String... aliases) {
|
||||
options.put(primaryAlias, executor);
|
||||
primaryAliases.add(primaryAlias);
|
||||
for (String alias : aliases) {
|
||||
options.put(alias, executor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
try {
|
||||
String classifier = args.next();
|
||||
CommandExecutor<? extends T> executor = options.get(classifier.toLowerCase(Locale.ROOT));
|
||||
if (executor != null) {
|
||||
return executor.call(args, locals);
|
||||
} else {
|
||||
throw new CommandException("'" + classifier + "' isn't a valid option for '" + name + "'. " +
|
||||
"Try one of: " + Joiner.on(", ").join(primaryAliases));
|
||||
}
|
||||
} catch (MissingArgumentException e) {
|
||||
throw new CommandException("Missing value for <" + name + "> " +
|
||||
"(try one of " + Joiner.on(" | ").join(primaryAliases) + ").");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
|
||||
String classifier = args.next();
|
||||
try {
|
||||
CommandExecutor<? extends T> executor = options.get(classifier.toLowerCase(Locale.ROOT));
|
||||
if (executor != null) {
|
||||
return executor.getSuggestions(args, locals);
|
||||
}
|
||||
} catch (MissingArgumentException ignored) {
|
||||
}
|
||||
|
||||
return ArgumentUtils.getMatchingSuggestions((classifier.isEmpty() ? primaryAliases : options.keySet()), classifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
List<String> optionUsages = Lists.newArrayList();
|
||||
for (String alias : primaryAliases) {
|
||||
CommandExecutor<? extends T> executor = options.get(alias);
|
||||
String usage = executor.getUsage();
|
||||
if (usage.isEmpty()) {
|
||||
optionUsages.add(alias);
|
||||
} else {
|
||||
optionUsages.add(alias + " " + executor.getUsage());
|
||||
}
|
||||
}
|
||||
|
||||
return "(" + Joiner.on(" | ").join(optionUsages) + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
for (CommandExecutor<?> executor : options.values()) {
|
||||
if (!executor.testPermission(locals)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.composition;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.argument.MissingArgumentException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CommandExecutor<T> {
|
||||
|
||||
T call(CommandArgs args, CommandLocals locals) throws CommandException;
|
||||
|
||||
List<String> getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException;
|
||||
|
||||
String getUsage();
|
||||
|
||||
String getDescription();
|
||||
|
||||
boolean testPermission(CommandLocals locals);
|
||||
|
||||
}
|
@ -1,196 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.composition;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.argument.MissingArgumentException;
|
||||
import com.sk89q.worldedit.util.command.composition.FlagParser.FlagData;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class FlagParser implements CommandExecutor<FlagData> {
|
||||
|
||||
private final Map<Character, CommandExecutor<?>> flags = Maps.newHashMap();
|
||||
|
||||
public <T> Flag<T> registerFlag(char flag, CommandExecutor<T> executor) {
|
||||
Flag<T> ret = new Flag<>(flag);
|
||||
flags.put(flag, executor);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FlagData call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
Map<Character, Object> values = Maps.newHashMap();
|
||||
try {
|
||||
while (true) {
|
||||
String next = args.peek();
|
||||
if (next.equals("--")) {
|
||||
args.next();
|
||||
break;
|
||||
} else if (next.length() > 0 && next.charAt(0) == '-') {
|
||||
args.next();
|
||||
|
||||
if (next.length() == 1) {
|
||||
throw new CommandException("- must be followed by a flag (like -a), otherwise use -- before the - (i.e. /cmd -- - is a dash).");
|
||||
} else {
|
||||
for (int i = 1; i < next.length(); i++) {
|
||||
char flag = next.charAt(i);
|
||||
CommandExecutor<?> executor = flags.get(flag);
|
||||
if (executor != null) {
|
||||
values.put(flag, executor.call(args, locals));
|
||||
} else {
|
||||
throw new CommandException("Unknown flag: -" + flag + " (try one of -" + Joiner.on("").join(flags.keySet()) + " or put -- to skip flag parsing, i.e. /cmd -- -this begins with a dash).");
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (MissingArgumentException ignored) {
|
||||
}
|
||||
|
||||
return new FlagData(values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
|
||||
List<String> suggestions = Collections.emptyList();
|
||||
|
||||
while (true) {
|
||||
String next = args.peek();
|
||||
if (next.equals("--")) {
|
||||
args.next();
|
||||
break;
|
||||
} else if (next.length() > 0 && next.charAt(0) == '-') {
|
||||
args.next();
|
||||
|
||||
if (!args.hasNext()) { // Completing -| or -???|
|
||||
List<String> flagSuggestions = Lists.newArrayList();
|
||||
for (Character flag : flags.keySet()) {
|
||||
if (next.indexOf(flag) < 1) { // Don't add any flags that the user has entered
|
||||
flagSuggestions.add(next + flag);
|
||||
}
|
||||
}
|
||||
return flagSuggestions;
|
||||
} else { // Completing -??? ???|
|
||||
for (int i = 1; i < next.length(); i++) {
|
||||
char flag = next.charAt(i);
|
||||
CommandExecutor<?> executor = flags.get(flag);
|
||||
if (executor != null) {
|
||||
suggestions = executor.getSuggestions(args, locals);
|
||||
} else {
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
List<String> options = Lists.newArrayList();
|
||||
for (Entry<Character, CommandExecutor<?>> entry : flags.entrySet()) {
|
||||
String usage = entry.getValue().getUsage();
|
||||
options.add("[-" + entry.getKey() + (!usage.isEmpty() ? " " + usage : "") + "]");
|
||||
}
|
||||
return Joiner.on(" ").join(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "Read flags";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
for (CommandExecutor<?> executor : flags.values()) {
|
||||
if (!executor.testPermission(locals)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static class FlagData {
|
||||
private final Map<Character, Object> data;
|
||||
|
||||
private FlagData(Map<Character, Object> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return data.size();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return data.isEmpty();
|
||||
}
|
||||
|
||||
public Object get(char key) {
|
||||
return data.get(key);
|
||||
}
|
||||
|
||||
public boolean containsKey(char key) {
|
||||
return data.containsKey(key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static final class Flag<T> {
|
||||
private final char flag;
|
||||
|
||||
private Flag(char flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
public T get(FlagData data) {
|
||||
return (T) data.get(flag);
|
||||
}
|
||||
|
||||
public T get(FlagData data, T fallback) {
|
||||
T value = get(data);
|
||||
if (value == null) {
|
||||
return fallback;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,87 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.composition;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.util.command.CommandCallable;
|
||||
import com.sk89q.worldedit.util.command.Description;
|
||||
import com.sk89q.worldedit.util.command.SimpleDescription;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.argument.MissingArgumentException;
|
||||
import com.sk89q.worldedit.util.command.argument.UnusedArgumentsException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LegacyCommandAdapter implements CommandCallable {
|
||||
|
||||
private final CommandExecutor<?> executor;
|
||||
|
||||
private LegacyCommandAdapter(CommandExecutor<?> executor) {
|
||||
this.executor = executor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final Object call(String arguments, CommandLocals locals, String[] parentCommands) throws CommandException {
|
||||
CommandArgs args = new CommandArgs.Parser().parse(arguments);
|
||||
|
||||
if (args.hasNext()) {
|
||||
if (args.uncheckedPeek().equals("-?")) {
|
||||
throw new CommandException(executor.getUsage());
|
||||
}
|
||||
}
|
||||
|
||||
Object ret = executor.call(args, locals);
|
||||
try {
|
||||
args.requireAllConsumed();
|
||||
} catch (UnusedArgumentsException e) {
|
||||
throw new CommandException(e.getMessage());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Description getDescription() {
|
||||
return new SimpleDescription()
|
||||
.setDescription(executor.getDescription())
|
||||
.overrideUsage(executor.getUsage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
return executor.testPermission(locals);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(String arguments, CommandLocals locals) throws CommandException {
|
||||
CommandArgs args = new CommandArgs.Parser().setUsingHangingArguments(true).parse(arguments);
|
||||
try {
|
||||
return executor.getSuggestions(args, locals);
|
||||
} catch (MissingArgumentException e) {
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
}
|
||||
|
||||
public static LegacyCommandAdapter adapt(CommandExecutor<?> executor) {
|
||||
return new LegacyCommandAdapter(executor);
|
||||
}
|
||||
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.composition;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.util.command.composition.FlagParser.Flag;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ParameterCommand<T> implements CommandExecutor<T> {
|
||||
|
||||
private final List<CommandExecutor<?>> parameters = Lists.newArrayList();
|
||||
private final FlagParser flagParser = new FlagParser();
|
||||
|
||||
public ParameterCommand() {
|
||||
addParameter(flagParser);
|
||||
}
|
||||
|
||||
protected List<CommandExecutor<?>> getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public <E extends CommandExecutor<?>> E addParameter(E executor) {
|
||||
parameters.add(executor);
|
||||
return executor;
|
||||
}
|
||||
|
||||
public <E> Flag<E> addFlag(char flag, CommandExecutor<E> executor) {
|
||||
return flagParser.registerFlag(flag, executor);
|
||||
}
|
||||
|
||||
protected FlagParser getFlagParser() {
|
||||
return flagParser;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getUsage() {
|
||||
List<String> parts = Lists.newArrayList();
|
||||
for (CommandExecutor<?> executor : parameters) {
|
||||
String usage = executor.getUsage();
|
||||
if (!usage.isEmpty()) {
|
||||
parts.add(executor.getUsage());
|
||||
}
|
||||
}
|
||||
return Joiner.on(" ").join(parts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean testPermission(CommandLocals locals) {
|
||||
for (CommandExecutor<?> executor : parameters) {
|
||||
if (!executor.testPermission(locals)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return testPermission0(locals);
|
||||
}
|
||||
|
||||
protected abstract boolean testPermission0(CommandLocals locals);
|
||||
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.composition;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.argument.MissingArgumentException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ProvidedValue<T> implements CommandExecutor<T> {
|
||||
|
||||
private final T value;
|
||||
private final String description;
|
||||
|
||||
private ProvidedValue(T value, String description) {
|
||||
this.value = value;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T call(CommandArgs args, CommandLocals locals) throws CommandException {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsage() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public static <T> ProvidedValue<T> create(T value, String description) {
|
||||
return new ProvidedValue<>(value, description);
|
||||
}
|
||||
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.composition;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.util.command.argument.CommandArgs;
|
||||
import com.sk89q.worldedit.util.command.argument.MissingArgumentException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class SimpleCommand<T> extends ParameterCommand<T> {
|
||||
|
||||
@Override
|
||||
public final List<String> getSuggestions(CommandArgs args, CommandLocals locals) throws MissingArgumentException {
|
||||
List<String> suggestions = Lists.newArrayList();
|
||||
boolean seenParameter = false;
|
||||
for (CommandExecutor<?> parameter : getParameters()) {
|
||||
try {
|
||||
suggestions = parameter.getSuggestions(args, locals);
|
||||
seenParameter = true;
|
||||
} catch (MissingArgumentException e) {
|
||||
if (seenParameter) {
|
||||
return suggestions;
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
// There's nothing more anyway
|
||||
if (args.position() == args.size()) {
|
||||
return suggestions;
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.fluent;
|
||||
|
||||
import com.sk89q.worldedit.util.command.Dispatcher;
|
||||
import com.sk89q.worldedit.util.command.SimpleDispatcher;
|
||||
import com.sk89q.worldedit.util.command.parametric.ParametricBuilder;
|
||||
|
||||
/**
|
||||
* A fluent interface to creating a command graph.
|
||||
*
|
||||
* <p>A command graph may have multiple commands, and multiple sub-commands below that,
|
||||
* and possibly below that.</p>
|
||||
*/
|
||||
public class CommandGraph {
|
||||
|
||||
private final DispatcherNode rootDispatcher;
|
||||
private ParametricBuilder builder;
|
||||
|
||||
/**
|
||||
* Create a new command graph.
|
||||
*/
|
||||
public CommandGraph() {
|
||||
SimpleDispatcher dispatcher = new SimpleDispatcher();
|
||||
rootDispatcher = new DispatcherNode(this, null, dispatcher);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the root dispatcher node.
|
||||
*
|
||||
* @return the root dispatcher node
|
||||
*/
|
||||
public DispatcherNode commands() {
|
||||
return rootDispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link ParametricBuilder}.
|
||||
*
|
||||
* @return the builder, or null.
|
||||
*/
|
||||
public ParametricBuilder getBuilder() {
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the {@link ParametricBuilder} used for calls to
|
||||
* {@link DispatcherNode#registerMethods(Object)}.
|
||||
*
|
||||
* @param builder the builder, or null
|
||||
* @return this object
|
||||
*/
|
||||
public CommandGraph builder(ParametricBuilder builder) {
|
||||
this.builder = builder;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the root dispatcher.
|
||||
*
|
||||
* @return the root dispatcher
|
||||
*/
|
||||
public Dispatcher getDispatcher() {
|
||||
return rootDispatcher.getDispatcher();
|
||||
}
|
||||
|
||||
}
|
@ -1,194 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.fluent;
|
||||
|
||||
import com.boydti.fawe.config.Commands;
|
||||
|
||||
import org.enginehub.piston.annotation.Command;
|
||||
import com.sk89q.worldedit.util.command.CallableProcessor;
|
||||
import com.sk89q.worldedit.util.command.CommandCallable;
|
||||
import com.sk89q.worldedit.util.command.Dispatcher;
|
||||
import com.sk89q.worldedit.util.command.SimpleDispatcher;
|
||||
import com.sk89q.worldedit.util.command.parametric.ParametricBuilder;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* A collection of commands.
|
||||
*/
|
||||
public class DispatcherNode {
|
||||
|
||||
private final CommandGraph graph;
|
||||
private final DispatcherNode parent;
|
||||
private final SimpleDispatcher dispatcher;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param graph the root fluent graph object
|
||||
* @param parent the parent node, or null
|
||||
* @param dispatcher the dispatcher for this node
|
||||
*/
|
||||
DispatcherNode(CommandGraph graph, DispatcherNode parent,
|
||||
SimpleDispatcher dispatcher) {
|
||||
this.graph = graph;
|
||||
this.parent = parent;
|
||||
this.dispatcher = dispatcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the description.
|
||||
*
|
||||
* <p>This can only be used on {@link DispatcherNode}s returned by
|
||||
* {@link #group(String...)}.</p>
|
||||
*
|
||||
* @param description the description
|
||||
* @return this object
|
||||
*/
|
||||
public DispatcherNode describeAs(String description) {
|
||||
dispatcher.getDescription().setDescription(description);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a command with this dispatcher.
|
||||
*
|
||||
* @param callable the executor
|
||||
* @param alias the list of aliases, where the first alias is the primary one
|
||||
*/
|
||||
public DispatcherNode register(CommandCallable callable, String... alias) {
|
||||
dispatcher.registerCommand(callable, alias);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and register a command with this dispatcher using the
|
||||
* {@link ParametricBuilder} assigned on the root {@link CommandGraph}.
|
||||
*
|
||||
* @param object the object provided to the {@link ParametricBuilder}
|
||||
* @return this object
|
||||
* @see ParametricBuilder#registerMethodsAsCommands(com.sk89q.worldedit.util.command.Dispatcher, Object)
|
||||
*/
|
||||
public DispatcherNode registerMethods(Object object) {
|
||||
return registerMethods(object, object instanceof CallableProcessor ? (CallableProcessor) object : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and register a command with this dispatcher using the
|
||||
* {@link ParametricBuilder} assigned on the root {@link CommandGraph}.
|
||||
*
|
||||
* @param object the object provided to the {@link ParametricBuilder}
|
||||
* @return this object
|
||||
* @see ParametricBuilder#registerMethodsAsCommands(com.sk89q.worldedit.util.command.Dispatcher, Object)
|
||||
*/
|
||||
public DispatcherNode registerMethods(Object object, @Nullable CallableProcessor processor) {
|
||||
ParametricBuilder builder = graph.getBuilder();
|
||||
if (builder == null) {
|
||||
throw new RuntimeException("No ParametricBuilder set");
|
||||
}
|
||||
builder.registerMethodsAsCommands(getDispatcher(), object, processor);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and register sub commands with this dispatcher using the
|
||||
* {@link ParametricBuilder} assigned on the objects registered command aliases {@link com.sk89q.minecraft.util.commands.Command}.
|
||||
*
|
||||
* @param object the object provided to the {@link ParametricBuilder}
|
||||
* @return this object
|
||||
*/
|
||||
public DispatcherNode registerSubMethods(Object object) {
|
||||
return registerSubMethods(object, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build and register sub commands with this dispatcher using the
|
||||
* {@link ParametricBuilder} assigned on the objects registered command aliases {@link com.sk89q.minecraft.util.commands.Command}.
|
||||
*
|
||||
* @param object the object provided to the {@link ParametricBuilder}
|
||||
* @param processor the command processor
|
||||
* @return this object
|
||||
*/
|
||||
public DispatcherNode registerSubMethods(Object object, @Nullable CallableProcessor processor) {
|
||||
Class<? extends Object> clazz = object.getClass();
|
||||
return groupAndDescribe(clazz).registerMethods(object, processor).parent();
|
||||
}
|
||||
|
||||
public DispatcherNode groupAndDescribe(Class clazz) {
|
||||
Command cmd = (Command) clazz.getAnnotation(Command.class);
|
||||
if (cmd == null) {
|
||||
throw new RuntimeException("This class does not have any command annotations");
|
||||
}
|
||||
cmd = Commands.translate(clazz, cmd);
|
||||
DispatcherNode res = group(cmd.aliases());
|
||||
if (cmd.desc() != null && !cmd.desc().isEmpty()) {
|
||||
res = res.describeAs(cmd.desc());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new command that will contain sub-commands.
|
||||
*
|
||||
* <p>The object returned by this method can be used to add sub-commands. To
|
||||
* return to this "parent" context, use {@link DispatcherNode#graph()}.</p>
|
||||
*
|
||||
* @param alias the list of aliases, where the first alias is the primary one
|
||||
* @return an object to place sub-commands
|
||||
*/
|
||||
public DispatcherNode group(String... alias) {
|
||||
SimpleDispatcher command = new SimpleDispatcher();
|
||||
getDispatcher().registerCommand(command, alias);
|
||||
return new DispatcherNode(graph, this, command);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the parent node.
|
||||
*
|
||||
* @return the parent node
|
||||
* @throws RuntimeException if there is no parent node.
|
||||
*/
|
||||
public DispatcherNode parent() {
|
||||
if (parent != null) {
|
||||
return parent;
|
||||
}
|
||||
|
||||
throw new RuntimeException("This node does not have a parent");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the root command graph.
|
||||
*
|
||||
* @return the root command graph
|
||||
*/
|
||||
public CommandGraph graph() {
|
||||
return graph;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying dispatcher of this object.
|
||||
*
|
||||
* @return the dispatcher
|
||||
*/
|
||||
public Dispatcher getDispatcher() {
|
||||
return dispatcher;
|
||||
}
|
||||
|
||||
}
|
@ -1,303 +0,0 @@
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import com.boydti.fawe.command.SuggestInputParseException;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.sk89q.minecraft.util.commands.*;
|
||||
import com.sk89q.worldedit.util.command.*;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.*;
|
||||
|
||||
public abstract class AParametricCallable implements CommandCallable {
|
||||
// private final ParametricBuilder builder;
|
||||
// private ParameterData[] parameters;
|
||||
// private Set<Character> valueFlags = new HashSet<Character>();
|
||||
// private boolean anyFlags;
|
||||
// private Set<Character> legacyFlags = new HashSet<Character>();
|
||||
// private SimpleDescription description = new SimpleDescription();
|
||||
// private String permission;
|
||||
// private Command command;
|
||||
|
||||
public abstract ParameterData[] getParameters();
|
||||
public abstract Set<Character> getValueFlags();
|
||||
public abstract Set<Character> getLegacyFlags();
|
||||
public abstract SimpleDescription getDescription();
|
||||
public abstract String[] getPermissions();
|
||||
public abstract ParametricBuilder getBuilder();
|
||||
public abstract boolean anyFlags();
|
||||
public abstract Command getCommand();
|
||||
public Command getDefinition() {
|
||||
return getCommand();
|
||||
}
|
||||
public abstract String getGroup();
|
||||
@Override
|
||||
public abstract String toString();
|
||||
|
||||
/**
|
||||
* Get the right {@link ArgumentStack}.
|
||||
*
|
||||
* @param parameter the parameter
|
||||
* @param existing the existing scoped context
|
||||
* @return the context to use
|
||||
*/
|
||||
static ArgumentStack getScopedContext(Parameter parameter, ArgumentStack existing) {
|
||||
if (parameter.getFlag() != null) {
|
||||
CommandContext context = existing.getContext();
|
||||
|
||||
if (parameter.isValueFlag()) {
|
||||
return new StringArgumentStack(context, context.getFlag(parameter.getFlag()), false);
|
||||
} else {
|
||||
String v = context.hasFlag(parameter.getFlag()) ? "true" : "false";
|
||||
return new StringArgumentStack(context, v, true);
|
||||
}
|
||||
}
|
||||
|
||||
return existing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether a parameter is allowed to consume arguments.
|
||||
*
|
||||
* @param i the index of the parameter
|
||||
* @param scoped the scoped context
|
||||
* @return true if arguments may be consumed
|
||||
*/
|
||||
public boolean mayConsumeArguments(int i, ContextArgumentStack scoped) {
|
||||
CommandContext context = scoped.getContext();
|
||||
ParameterData parameter = getParameters()[i];
|
||||
|
||||
// Flag parameters: Always consume
|
||||
// Required non-flag parameters: Always consume
|
||||
// Optional non-flag parameters:
|
||||
// - Before required parameters: Consume if there are 'left over' args
|
||||
// - At the end: Always consumes
|
||||
|
||||
if (parameter.isOptional()) {
|
||||
if (parameter.getFlag() != null) {
|
||||
return !parameter.isValueFlag() || context.hasFlag(parameter.getFlag());
|
||||
} else {
|
||||
int numberFree = context.argsLength() - scoped.position();
|
||||
for (int j = i; j < getParameters().length; j++) {
|
||||
if (getParameters()[j].isNonFlagConsumer() && !getParameters()[j].isOptional()) {
|
||||
// We already checked if the consumed count was > -1
|
||||
// when we created this object
|
||||
numberFree -= getParameters()[j].getConsumedCount();
|
||||
}
|
||||
}
|
||||
|
||||
// Skip this optional parameter
|
||||
if (numberFree < 1) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default value for a parameter.
|
||||
*
|
||||
* @param i the index of the parameter
|
||||
* @param scoped the scoped context
|
||||
* @return a value
|
||||
* @throws ParameterException on an error
|
||||
* @throws CommandException on an error
|
||||
*/
|
||||
public Object getDefaultValue(int i, ContextArgumentStack scoped) throws ParameterException, CommandException, InvocationTargetException {
|
||||
CommandContext context = scoped.getContext();
|
||||
ParameterData parameter = getParameters()[i];
|
||||
|
||||
String[] defaultValue = parameter.getDefaultValue();
|
||||
if (defaultValue != null) {
|
||||
try {
|
||||
return parameter.getBinding().bind(parameter, new StringArgumentStack(context, defaultValue, false), false);
|
||||
} catch (MissingParameterException e) {
|
||||
throw new ParametricException(
|
||||
"The default value of the parameter using the binding " +
|
||||
parameter.getBinding().getClass() + " in the method\n" +
|
||||
toString() + "\nis invalid");
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check to see if all arguments, including flag arguments, were consumed.
|
||||
*
|
||||
* @param scoped the argument scope
|
||||
* @throws UnconsumedParameterException thrown if parameters were not consumed
|
||||
*/
|
||||
public void checkUnconsumed(ContextArgumentStack scoped) throws UnconsumedParameterException {
|
||||
CommandContext context = scoped.getContext();
|
||||
String unconsumed;
|
||||
String unconsumedFlags = getUnusedFlags(context);
|
||||
|
||||
if ((unconsumed = scoped.getUnconsumed()) != null) {
|
||||
throw new UnconsumedParameterException(unconsumed + " " + unconsumedFlags);
|
||||
}
|
||||
|
||||
if (unconsumedFlags != null) {
|
||||
throw new UnconsumedParameterException(unconsumedFlags);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get any unused flag arguments.
|
||||
*
|
||||
* @param context the command context
|
||||
*/
|
||||
public String getUnusedFlags(CommandContext context) {
|
||||
if (!anyFlags()) {
|
||||
Set<Character> unusedFlags = null;
|
||||
for (char flag : context.getFlags()) {
|
||||
boolean found = false;
|
||||
|
||||
if (getLegacyFlags().contains(flag)) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (ParameterData parameter : getParameters()) {
|
||||
Character paramFlag = parameter.getFlag();
|
||||
if (paramFlag != null && flag == paramFlag) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
if (unusedFlags == null) {
|
||||
unusedFlags = new HashSet<>();
|
||||
}
|
||||
unusedFlags.add(flag);
|
||||
}
|
||||
}
|
||||
|
||||
if (unusedFlags != null) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (Character flag : unusedFlags) {
|
||||
builder.append("-").append(flag).append(" ");
|
||||
}
|
||||
|
||||
return builder.toString().trim();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
String[] perms = getPermissions();
|
||||
if (perms != null && perms.length != 0) {
|
||||
for (String perm : perms) {
|
||||
if (getBuilder().getAuthorizer().testPermission(locals, perm)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(String arguments, CommandLocals locals) throws CommandException {
|
||||
String[] split = ("ignored" + " " + arguments).split(" ", -1);
|
||||
|
||||
// &a<current> &f<next>
|
||||
// &cerrors
|
||||
|
||||
CommandContext context = new CommandContext(split, getValueFlags(), !arguments.endsWith(" "), locals);
|
||||
ContextArgumentStack scoped = new ContextArgumentStack(context);
|
||||
|
||||
List<String> suggestions = new ArrayList<>(2);
|
||||
ParameterData parameter = null;
|
||||
ParameterData[] parameters = getParameters();
|
||||
String consumed = "";
|
||||
|
||||
boolean hasSuggestion = false;
|
||||
int maxConsumedI = 0; // The maximum argument index
|
||||
int minConsumedI = 0; // The minimum argument that has been consumed
|
||||
// Collect parameters
|
||||
try {
|
||||
for (;maxConsumedI < parameters.length; maxConsumedI++) {
|
||||
parameter = parameters[maxConsumedI];
|
||||
if (parameter.getBinding().getBehavior(parameter) != BindingBehavior.PROVIDES) {
|
||||
if (mayConsumeArguments(maxConsumedI, scoped)) {
|
||||
// Parse the user input into a method argument
|
||||
ArgumentStack usedArguments = getScopedContext(parameter, scoped);
|
||||
|
||||
usedArguments.mark();
|
||||
try {
|
||||
parameter.getBinding().bind(parameter, usedArguments, false);
|
||||
minConsumedI = maxConsumedI + 1;
|
||||
} catch (Throwable e) {
|
||||
while (e.getCause() != null && !(e instanceof ParameterException || e instanceof InvocationTargetException))
|
||||
e = e.getCause();
|
||||
consumed = usedArguments.reset();
|
||||
// Not optional? Then we can't execute this command
|
||||
if (!parameter.isOptional()) {
|
||||
if (!(e instanceof MissingParameterException)) minConsumedI = maxConsumedI;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (minConsumedI >= maxConsumedI && (parameter == null || parameter.getType() == CommandContext.class)) checkUnconsumed(scoped);
|
||||
} catch (MissingParameterException ignore) {
|
||||
} catch (UnconsumedParameterException e) {
|
||||
suggestions.add(BBC.color("&cToo many parameters! Unused parameters: " + e.getUnconsumed()));
|
||||
} catch (ParameterException e) {
|
||||
String name = parameter.getName();
|
||||
suggestions.add(BBC.color("&cFor parameter '" + name + "': " + e.getMessage()));
|
||||
} catch (InvocationTargetException e) {
|
||||
SuggestInputParseException suggestion = SuggestInputParseException.get(e);
|
||||
if (suggestion != null && !suggestion.getSuggestions().isEmpty()) {
|
||||
hasSuggestion = true;
|
||||
suggestions.addAll(suggestion.getSuggestions());
|
||||
} else {
|
||||
Throwable t = e;
|
||||
while (t.getCause() != null) t = t.getCause();
|
||||
String msg = t.getMessage();
|
||||
String name = parameter.getName();
|
||||
if (msg != null && !msg.isEmpty()) suggestions.add(BBC.color("&cFor parameter '" + name + "': " + msg));
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
throw new WrappedCommandException(t);
|
||||
}
|
||||
// If there's 1 or less suggestions already, then show parameter suggestion
|
||||
if (!hasSuggestion && suggestions.size() <= 1) {
|
||||
StringBuilder suggestion = new StringBuilder();
|
||||
outer:
|
||||
for (String prefix = ""; minConsumedI < parameters.length; minConsumedI++) {
|
||||
parameter = parameters[minConsumedI];
|
||||
if (parameter.getBinding().getBehavior(parameter) != BindingBehavior.PROVIDES) {
|
||||
suggestion.append(prefix);
|
||||
List<String> argSuggestions = parameter.getBinding().getSuggestions(parameter, consumed);
|
||||
switch (argSuggestions.size()) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
suggestion.append(argSuggestions.iterator().next());
|
||||
break;
|
||||
default:
|
||||
suggestion.setLength(0);
|
||||
suggestions.addAll(argSuggestions);
|
||||
break outer;
|
||||
|
||||
}
|
||||
consumed = "";
|
||||
prefix = " ";
|
||||
}
|
||||
}
|
||||
if (suggestion.length() != 0) suggestions.add(suggestion.toString());
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import com.sk89q.worldedit.util.command.SimpleDescription;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* An abstract listener.
|
||||
*/
|
||||
public abstract class AbstractInvokeListener implements InvokeListener {
|
||||
|
||||
@Override
|
||||
public void updateDescription(Object object, Method method,
|
||||
ParameterData[] parameters, SimpleDescription description) {
|
||||
}
|
||||
|
||||
}
|
@ -1,94 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
|
||||
public interface ArgumentStack {
|
||||
|
||||
/**
|
||||
* Get the next string, which may come from the stack or a value flag.
|
||||
*
|
||||
* @return the value
|
||||
* @throws ParameterException on a parameter error
|
||||
*/
|
||||
String next() throws ParameterException;
|
||||
|
||||
/**
|
||||
* Get the next integer, which may come from the stack or a value flag.
|
||||
*
|
||||
* @return the value
|
||||
* @throws ParameterException on a parameter error
|
||||
*/
|
||||
Integer nextInt() throws ParameterException;
|
||||
|
||||
/**
|
||||
* Get the next double, which may come from the stack or a value flag.
|
||||
*
|
||||
* @return the value
|
||||
* @throws ParameterException on a parameter error
|
||||
*/
|
||||
Double nextDouble() throws ParameterException;
|
||||
|
||||
/**
|
||||
* Get the next boolean, which may come from the stack or a value flag.
|
||||
*
|
||||
* @return the value
|
||||
* @throws ParameterException on a parameter error
|
||||
*/
|
||||
Boolean nextBoolean() throws ParameterException;
|
||||
|
||||
/**
|
||||
* Get all remaining string values, which will consume the rest of the stack.
|
||||
*
|
||||
* @return the value
|
||||
* @throws ParameterException on a parameter error
|
||||
*/
|
||||
String remaining() throws ParameterException;
|
||||
|
||||
/**
|
||||
* Set as completely consumed.
|
||||
*/
|
||||
void markConsumed();
|
||||
|
||||
/**
|
||||
* Get the underlying context.
|
||||
*
|
||||
* @return the context
|
||||
*/
|
||||
CommandContext getContext();
|
||||
|
||||
/**
|
||||
* Mark the current position of the stack.
|
||||
*
|
||||
* <p>The marked position initially starts at 0.</p>
|
||||
*/
|
||||
void mark();
|
||||
|
||||
/**
|
||||
* Reset to the previously {@link #mark()}ed position of the stack, and return
|
||||
* the arguments that were consumed between this point and that previous point.
|
||||
*
|
||||
* <p>The marked position initially starts at 0.</p>
|
||||
*
|
||||
* @return the consumed arguments
|
||||
*/
|
||||
String reset();
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.worldedit.util.command.binding.PrimitiveBindings;
|
||||
import com.sk89q.worldedit.util.command.binding.StandardBindings;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Used to parse user input for a command, based on available method types
|
||||
* and annotations.
|
||||
*
|
||||
* <p>A binding can be used to handle several types at once. For a binding to be
|
||||
* called, it must be registered with a {@link ParametricBuilder} with
|
||||
* {@link ParametricBuilder#addBinding(Binding, java.lang.reflect.Type...)}.</p>
|
||||
*
|
||||
* @see PrimitiveBindings an example of primitive bindings
|
||||
* @see StandardBindings standard bindings
|
||||
*/
|
||||
public interface Binding {
|
||||
|
||||
/**
|
||||
* Get the types that this binding handles.
|
||||
*
|
||||
* @return the types
|
||||
*/
|
||||
Type[] getTypes();
|
||||
|
||||
/**
|
||||
* Get how this binding consumes from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param parameter information about the parameter
|
||||
* @return the behavior
|
||||
*/
|
||||
BindingBehavior getBehavior(ParameterData parameter);
|
||||
|
||||
/**
|
||||
* Get the number of arguments that this binding will consume, if this
|
||||
* information is available.
|
||||
*
|
||||
* <p>This method must return -1 for binding behavior types that are not
|
||||
* {@link BindingBehavior#CONSUMES}.</p>
|
||||
*
|
||||
* @param parameter information about the parameter
|
||||
* @return the number of consumed arguments, or -1 if unknown or irrelevant
|
||||
*/
|
||||
int getConsumedCount(ParameterData parameter);
|
||||
|
||||
/**
|
||||
* Attempt to consume values (if required) from the given {@link ArgumentStack}
|
||||
* in order to instantiate an object for the given parameter.
|
||||
*
|
||||
* @param parameter information about the parameter
|
||||
* @param scoped the arguments the user has input
|
||||
* @param onlyConsume true to only consume arguments
|
||||
* @return an object parsed for the given parameter
|
||||
* @throws ParameterException thrown if the parameter could not be formulated
|
||||
* @throws CommandException on a command exception
|
||||
*/
|
||||
Object bind(ParameterData parameter, ArgumentStack scoped, boolean onlyConsume)
|
||||
throws ParameterException, CommandException, InvocationTargetException;
|
||||
|
||||
/**
|
||||
* Get a list of suggestions for the given parameter and user arguments.
|
||||
*
|
||||
* @param parameter information about the parameter
|
||||
* @param prefix what the user has typed so far (may be an empty string)
|
||||
* @return a list of suggestions
|
||||
*/
|
||||
List<String> getSuggestions(ParameterData parameter, String prefix);
|
||||
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import org.enginehub.piston.annotation.param.Switch;
|
||||
|
||||
/**
|
||||
* Determines the type of binding.
|
||||
*/
|
||||
public enum BindingBehavior {
|
||||
|
||||
/**
|
||||
* Always consumes from a {@link ArgumentStack}.
|
||||
*/
|
||||
CONSUMES,
|
||||
|
||||
/**
|
||||
* Sometimes consumes from a {@link ArgumentStack}.
|
||||
*
|
||||
* <p>Bindings that exhibit this behavior must be defined as a {@link Switch}
|
||||
* by commands utilizing the given binding.</p>
|
||||
*/
|
||||
INDETERMINATE,
|
||||
|
||||
/**
|
||||
* Never consumes from a {@link ArgumentStack}.
|
||||
*
|
||||
* <p>Bindings that exhibit this behavior generate objects from other sources,
|
||||
* such as from a {@link CommandLocals}. These are "magic" bindings that inject
|
||||
* variables.</p>
|
||||
*/
|
||||
PROVIDES
|
||||
|
||||
}
|
@ -1,300 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.worldedit.util.command.binding.Range;
|
||||
import com.sk89q.worldedit.util.command.binding.Validate;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A binding helper that uses the {@link BindingMatch} annotation to make
|
||||
* writing bindings extremely easy.
|
||||
*
|
||||
* <p>Methods must have the following and only the following parameters:</p>
|
||||
*
|
||||
* <ul>
|
||||
* <li>A {@link ArgumentStack}</li>
|
||||
* <li>A {@link Annotation} <strong>if there is a classifier set</strong></li>
|
||||
* <li>A {@link Annotation}[]
|
||||
* <strong>if there {@link BindingMatch#provideModifiers()} is true</strong></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>Methods may throw any exception. Exceptions may be converted using a
|
||||
* {@link ExceptionConverter} registered with the {@link ParametricBuilder}.</p>
|
||||
*/
|
||||
public class BindingHelper implements Binding {
|
||||
|
||||
private final List<BindingMap.BoundMethod> bindings;
|
||||
private final Type[] types;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*/
|
||||
public BindingHelper() {
|
||||
List<BindingMap.BoundMethod> bindings = new ArrayList<>();
|
||||
List<Type> types = new ArrayList<>();
|
||||
|
||||
for (Method method : this.getClass().getMethods()) {
|
||||
BindingMatch info = method.getAnnotation(BindingMatch.class);
|
||||
if (info != null) {
|
||||
Class<? extends Annotation> classifier = null;
|
||||
|
||||
// Set classifier
|
||||
if (!info.classifier().equals(Annotation.class)) {
|
||||
classifier = info.classifier();
|
||||
types.add(classifier);
|
||||
}
|
||||
|
||||
for (Type t : info.type()) {
|
||||
Type type = null;
|
||||
|
||||
// Set type
|
||||
if (!t.equals(Class.class)) {
|
||||
type = t;
|
||||
if (classifier == null) {
|
||||
types.add(type); // Only if there is no classifier set!
|
||||
}
|
||||
}
|
||||
|
||||
// Check to see if at least one is set
|
||||
if (type == null && classifier == null) {
|
||||
throw new RuntimeException(
|
||||
"A @BindingMatch needs either a type or classifier set");
|
||||
}
|
||||
|
||||
BindingMap.BoundMethod handler = new BindingMap.BoundMethod(info, type, classifier, method, this);
|
||||
bindings.add(handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(bindings);
|
||||
|
||||
this.bindings = bindings;
|
||||
|
||||
Type[] typesArray = new Type[types.size()];
|
||||
types.toArray(typesArray);
|
||||
this.types = typesArray;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Match a {@link BindingMatch} according to the given parameter.
|
||||
*
|
||||
* @param parameter the parameter
|
||||
* @return a binding
|
||||
*/
|
||||
private BindingMap.BoundMethod match(ParameterData parameter) {
|
||||
for (BindingMap.BoundMethod binding : bindings) {
|
||||
Annotation classifer = parameter.getClassifier();
|
||||
Type type = parameter.getType();
|
||||
|
||||
if (binding.classifier != null) {
|
||||
if (classifer != null && classifer.annotationType().equals(binding.classifier)) {
|
||||
if (binding.type == null || binding.type.equals(type)) {
|
||||
return binding;
|
||||
}
|
||||
}
|
||||
} else if (binding.type.equals(type)) {
|
||||
return binding;
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException("Unknown type");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type[] getTypes() {
|
||||
return types;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConsumedCount(ParameterData parameter) {
|
||||
return match(parameter).annotation.consumedCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindingBehavior getBehavior(ParameterData parameter) {
|
||||
return match(parameter).annotation.behavior();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object bind(ParameterData parameter, ArgumentStack scoped,
|
||||
boolean onlyConsume) throws ParameterException, CommandException, InvocationTargetException {
|
||||
BindingMap.BoundMethod binding = match(parameter);
|
||||
List<Object> args = new ArrayList<>();
|
||||
args.add(scoped);
|
||||
|
||||
if (binding.classifier != null) {
|
||||
args.add(parameter.getClassifier());
|
||||
}
|
||||
|
||||
if (binding.annotation.provideModifiers()) {
|
||||
args.add(parameter.getModifiers());
|
||||
}
|
||||
|
||||
if (onlyConsume && binding.annotation.behavior() == BindingBehavior.PROVIDES) {
|
||||
return null; // Nothing to consume, nothing to do
|
||||
}
|
||||
|
||||
Object[] argsArray = new Object[args.size()];
|
||||
args.toArray(argsArray);
|
||||
|
||||
try {
|
||||
return binding.method.invoke(this, argsArray);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new RuntimeException(
|
||||
"Processing of classifier " + parameter.getClassifier() +
|
||||
" and type " + parameter.getType() + " failed for method\n" +
|
||||
binding.method + "\nbecause the parameters for that method are wrong", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
if (e.getCause() instanceof ParameterException) {
|
||||
throw (ParameterException) e.getCause();
|
||||
} else if (e.getCause() instanceof CommandException) {
|
||||
throw (CommandException) e.getCause();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(ParameterData parameter, String prefix) {
|
||||
if (prefix.isEmpty()) {
|
||||
char bracket = parameter.isOptional() ? '[' : '<';
|
||||
char endBracket = StringMan.getMatchingBracket(bracket);
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("\u00A75");
|
||||
result.append(bracket);
|
||||
result.append("\u00A7r");
|
||||
if (parameter.getFlag() != null) {
|
||||
result.append('-').append(parameter.getFlag()).append("\u00A75 \u00A7r");
|
||||
}
|
||||
result.append(parameter.getName());
|
||||
if (parameter.getDefaultValue() != null) {
|
||||
result.append('=').append(StringMan.join(parameter.getDefaultValue(), " "));
|
||||
}
|
||||
Range range = parameter.getModifier(Range.class);
|
||||
if (range != null) {
|
||||
result.append('|').append(StringMan.prettyFormat(range.min())).append(",").append(StringMan.prettyFormat(range.max()));
|
||||
}
|
||||
result.append("\u00A75");
|
||||
result.append(endBracket);
|
||||
result.append("\u00A7r");
|
||||
return Collections.singletonList(result.toString());
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a number value using relevant modifiers.
|
||||
*
|
||||
* @param number the number
|
||||
* @param modifiers the list of modifiers to scan
|
||||
* @throws ParameterException on a validation error
|
||||
*/
|
||||
public static void validate(double number, Annotation[] modifiers)
|
||||
throws ParameterException {
|
||||
for (Annotation modifier : modifiers) {
|
||||
if (modifier instanceof Range) {
|
||||
Range range = (Range) modifier;
|
||||
if (number < range.min()) {
|
||||
throw new ParameterException(
|
||||
String.format(
|
||||
"A valid value is greater than or equal to %s " +
|
||||
"(you entered %s)", range.min(), number));
|
||||
} else if (number > range.max()) {
|
||||
throw new ParameterException(
|
||||
String.format(
|
||||
"A valid value is less than or equal to %s " +
|
||||
"(you entered %s)", range.max(), number));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a number value using relevant modifiers.
|
||||
*
|
||||
* @param number the number
|
||||
* @param modifiers the list of modifiers to scan
|
||||
* @throws ParameterException on a validation error
|
||||
*/
|
||||
public static void validate(int number, Annotation[] modifiers)
|
||||
throws ParameterException {
|
||||
for (Annotation modifier : modifiers) {
|
||||
if (modifier instanceof Range) {
|
||||
Range range = (Range) modifier;
|
||||
if (number < range.min()) {
|
||||
throw new ParameterException(
|
||||
String.format(
|
||||
"A valid value is greater than or equal to %s " +
|
||||
"(you entered %s)", range.min(), number));
|
||||
} else if (number > range.max()) {
|
||||
throw new ParameterException(
|
||||
String.format(
|
||||
"A valid value is less than or equal to %s " +
|
||||
"(you entered %s)", range.max(), number));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate a string value using relevant modifiers.
|
||||
*
|
||||
* @param string the string
|
||||
* @param modifiers the list of modifiers to scan
|
||||
* @throws ParameterException on a validation error
|
||||
*/
|
||||
public static void validate(String string, Annotation[] modifiers)
|
||||
throws ParameterException {
|
||||
if (string == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (Annotation modifier : modifiers) {
|
||||
if (modifier instanceof Validate) {
|
||||
Validate validate = (Validate) modifier;
|
||||
|
||||
if (!validate.regex().isEmpty()) {
|
||||
if (!string.matches(validate.regex())) {
|
||||
throw new ParameterException(
|
||||
String.format(
|
||||
"The given text doesn't match the right " +
|
||||
"format (technically speaking, the 'format' is %s)",
|
||||
validate.regex()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,300 +0,0 @@
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
import org.enginehub.piston.annotation.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.util.command.CommandMapping;
|
||||
import com.sk89q.worldedit.util.command.MissingParameterException;
|
||||
import com.sk89q.worldedit.util.command.SimpleDispatcher;
|
||||
import com.sk89q.worldedit.util.command.binding.Range;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A binding helper that uses the {@link BindingMatch} annotation to make
|
||||
* writing bindings extremely easy.
|
||||
*
|
||||
* <p>Methods must have the following and only the following parameters:</p>
|
||||
*
|
||||
* <ul>
|
||||
* <li>A {@link ArgumentStack}</li>
|
||||
* <li>A {@link Annotation} <strong>if there is a classifier set</strong></li>
|
||||
* <li>A {@link Annotation}[]
|
||||
* <strong>if there {@link BindingMatch#provideModifiers()} is true</strong></li>
|
||||
* </ul>
|
||||
*
|
||||
* <p>Methods may throw any exception. Exceptions may be converted using a
|
||||
* {@link ExceptionConverter} registered with the {@link ParametricBuilder}.</p>
|
||||
*/
|
||||
public class BindingMap implements Binding {
|
||||
|
||||
private final Set<Type> types;
|
||||
private final Map<Type, Binding> legacy;
|
||||
private final Map<Type, List<BoundMethod>> bindings;
|
||||
private final Map<Type, SimpleDispatcher> dynamicBindings;
|
||||
private final ParametricBuilder builder;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
* @param builder
|
||||
*/
|
||||
public BindingMap(ParametricBuilder builder) {
|
||||
this.dynamicBindings = new HashMap<>();
|
||||
this.legacy = new HashMap<>();
|
||||
this.bindings = new HashMap<>();
|
||||
this.builder = builder;
|
||||
this.types = new HashSet<>();
|
||||
|
||||
}
|
||||
|
||||
public void add(Object object, Type... requiredTypes) {
|
||||
Method[] methods = object.getClass().getDeclaredMethods();
|
||||
for (Method method : methods) {
|
||||
method.setAccessible(true);
|
||||
BindingMatch info = method.getAnnotation(BindingMatch.class);
|
||||
if (info != null) {
|
||||
Class<? extends Annotation> classifier = null;
|
||||
|
||||
// Set classifier
|
||||
if (!info.classifier().equals(Annotation.class)) {
|
||||
classifier = info.classifier();
|
||||
}
|
||||
|
||||
for (Type type : info.type()) {
|
||||
if (type == Void.class) {
|
||||
type = method.getReturnType();
|
||||
}
|
||||
BoundMethod handler = new BoundMethod(info, type, classifier, method, object);
|
||||
List<BoundMethod> list = bindings.get(type);
|
||||
if (list == null) bindings.put(type, list = new ArrayList<>());
|
||||
list.add(handler);
|
||||
types.add(type);
|
||||
}
|
||||
}
|
||||
Command definition = method.getAnnotation(Command.class);
|
||||
Class<?> type = method.getReturnType();
|
||||
if (definition != null && type != null) {
|
||||
SimpleDispatcher dispatcher = dynamicBindings.get(type);
|
||||
if (dispatcher == null) dynamicBindings.put(type, dispatcher = new SimpleDispatcher());
|
||||
builder.registerMethodAsCommands(method, dispatcher, object, null);
|
||||
types.add(type);
|
||||
}
|
||||
}
|
||||
if (requiredTypes != null && requiredTypes.length > 0) {
|
||||
for (Type type : requiredTypes) {
|
||||
legacy.put(type, (Binding) object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Match a {@link BindingMatch} according to the given parameter.
|
||||
*
|
||||
* @param pd the parameter
|
||||
* @return a binding
|
||||
*/
|
||||
private BoundMethod match(ParameterData pd) {
|
||||
Type type = pd.getType();
|
||||
BoundMethod result = null;
|
||||
while (type != null) {
|
||||
List<BoundMethod> methods = bindings.get(type);
|
||||
if (methods != null) {
|
||||
for (BoundMethod binding : methods) {
|
||||
if (binding.classifier != null) {
|
||||
if (pd.getClassifier() != null && pd.getClassifier().annotationType().equals(binding.classifier)) {
|
||||
if (binding.type == null) {
|
||||
result = binding;
|
||||
} else if (binding.type.equals(type)) {
|
||||
return binding;
|
||||
}
|
||||
|
||||
}
|
||||
} else if (binding.type.equals(type)) {
|
||||
if (result == null) result = binding;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result != null) return result;
|
||||
type = (type instanceof Class) ? ((Class) type).getSuperclass() : null;
|
||||
}
|
||||
throw new RuntimeException("Unknown type " + pd.getType());
|
||||
}
|
||||
|
||||
private SimpleDispatcher matchDynamic(ParameterData pd) {
|
||||
return dynamicBindings.get(pd.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getConsumedCount(ParameterData parameter) {
|
||||
return match(parameter).annotation.consumedCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BindingBehavior getBehavior(ParameterData parameter) {
|
||||
BoundMethod matched = match(parameter);
|
||||
if (matched != null) return matched.annotation.behavior();
|
||||
SimpleDispatcher dynamic = matchDynamic(parameter);
|
||||
return dynamic != null ? BindingBehavior.CONSUMES : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type[] getTypes() {
|
||||
return types.toArray(new Type[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object bind(ParameterData parameter, ArgumentStack scoped, boolean onlyConsume) throws ParameterException, CommandException, InvocationTargetException {
|
||||
BoundMethod binding = match(parameter);
|
||||
List<Object> args = new ArrayList<>();
|
||||
args.add(scoped);
|
||||
|
||||
if (binding.classifier != null) {
|
||||
args.add(parameter.getClassifier());
|
||||
}
|
||||
|
||||
if (binding.annotation.provideModifiers()) {
|
||||
args.add(parameter.getModifiers());
|
||||
}
|
||||
|
||||
if (binding.annotation.provideType()) {
|
||||
args.add(parameter.getType());
|
||||
}
|
||||
|
||||
if (onlyConsume && binding.annotation.behavior() == BindingBehavior.PROVIDES) {
|
||||
return null; // Nothing to consume, nothing to do
|
||||
}
|
||||
|
||||
if (binding.annotation.behavior() != BindingBehavior.PROVIDES) {
|
||||
SimpleDispatcher dynamic = matchDynamic(parameter);
|
||||
if (dynamic != null) {
|
||||
scoped.mark();
|
||||
String rest = scoped.remaining();
|
||||
scoped.reset();
|
||||
int start = rest.indexOf('{');
|
||||
if (start > 0) {
|
||||
int end = StringMan.findMatchingBracket(rest, start);
|
||||
if (end > start) {
|
||||
String alias = rest.substring(0, start);
|
||||
CommandMapping cmd = dynamic.get(alias);
|
||||
if (cmd != null) {
|
||||
String arguments = rest.substring(start + 1, end);
|
||||
CommandLocals locals = scoped.getContext().getLocals();
|
||||
Object result = cmd.getCallable().call(arguments, locals, new String[0]);
|
||||
int remaining = rest.length() - end;
|
||||
while (rest.length() > remaining) {
|
||||
scoped.next();
|
||||
try {
|
||||
scoped.mark();
|
||||
rest = scoped.remaining();
|
||||
scoped.reset();
|
||||
} catch (MissingParameterException ignore) { rest = ""; }
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Object[] argsArray = new Object[args.size()];
|
||||
args.toArray(argsArray);
|
||||
|
||||
try {
|
||||
return binding.method.invoke(binding.object, argsArray);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new RuntimeException(
|
||||
"Processing of classifier " + parameter.getClassifier() +
|
||||
" and type " + parameter.getType() + " failed for method\n" +
|
||||
binding.method + "\nbecause the parameters for that method are wrong", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
if (e.getCause() instanceof ParameterException) {
|
||||
throw (ParameterException) e.getCause();
|
||||
} else if (e.getCause() instanceof CommandException) {
|
||||
throw (CommandException) e.getCause();
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSuggestions(ParameterData parameter, String prefix) {
|
||||
Binding legacySuggestions = legacy.get(parameter.getType());
|
||||
if (legacySuggestions != null) {
|
||||
List<String> result = legacySuggestions.getSuggestions(parameter, prefix);
|
||||
if (result != null) return result;
|
||||
}
|
||||
if (prefix.isEmpty()) {
|
||||
char bracket = parameter.isOptional() ? '[' : '<';
|
||||
char endBracket = StringMan.getMatchingBracket(bracket);
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append("\u00A75");
|
||||
result.append(bracket);
|
||||
result.append("\u00A7r");
|
||||
if (parameter.getFlag() != null) {
|
||||
result.append('-').append(parameter.getFlag()).append("\u00A75 \u00A7r");
|
||||
}
|
||||
result.append(parameter.getName());
|
||||
if (parameter.getDefaultValue() != null) {
|
||||
result.append('=').append(StringMan.join(parameter.getDefaultValue(), " "));
|
||||
}
|
||||
Range range = parameter.getModifier(Range.class);
|
||||
if (range != null) {
|
||||
result.append('|').append(StringMan.prettyFormat(range.min())).append(",").append(StringMan.prettyFormat(range.max()));
|
||||
}
|
||||
result.append("\u00A75");
|
||||
result.append(endBracket);
|
||||
result.append("\u00A7r");
|
||||
return Collections.singletonList(result.toString());
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
protected static class BoundMethod implements Comparable<BoundMethod> {
|
||||
protected final BindingMatch annotation;
|
||||
protected final Type type;
|
||||
protected final Class<? extends Annotation> classifier;
|
||||
protected final Method method;
|
||||
protected final Object object;
|
||||
|
||||
BoundMethod(BindingMatch annotation, Type type,
|
||||
Class<? extends Annotation> classifier, Method method, Object object) {
|
||||
this.annotation = annotation;
|
||||
this.type = type;
|
||||
this.classifier = classifier;
|
||||
this.method = method;
|
||||
this.object = object;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(BoundMethod o) {
|
||||
if (classifier != null && o.classifier == null) {
|
||||
return -1;
|
||||
} else if (classifier == null && o.classifier != null) {
|
||||
return 1;
|
||||
} else if (classifier != null && o.classifier != null) {
|
||||
if (type != null && o.type == null) {
|
||||
return -1;
|
||||
} else if (type == null && o.type != null) {
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Denotes a match of a binding.
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface BindingMatch {
|
||||
|
||||
/**
|
||||
* The classifier.
|
||||
*
|
||||
* @return the classifier, or {@link Annotation} if not set
|
||||
*/
|
||||
Class<? extends Annotation> classifier() default Annotation.class;
|
||||
|
||||
/**
|
||||
* The type.
|
||||
*
|
||||
* @return the type, or {@link Class} if not set
|
||||
*/
|
||||
Class<?>[] type() default Class.class;
|
||||
|
||||
/**
|
||||
* The binding behavior.
|
||||
*
|
||||
* @return the behavior
|
||||
*/
|
||||
BindingBehavior behavior();
|
||||
|
||||
/**
|
||||
* Get the number of arguments that this binding consumes.
|
||||
*
|
||||
* @return -1 if unknown or irrelevant
|
||||
*/
|
||||
int consumedCount() default -1;
|
||||
|
||||
/**
|
||||
* Set whether an array of modifier annotations is provided in the list of
|
||||
* arguments.
|
||||
*
|
||||
* @return true to provide modifiers
|
||||
*/
|
||||
boolean provideModifiers() default false;
|
||||
|
||||
/**
|
||||
* If the type should be passed to the method
|
||||
*/
|
||||
boolean provideType() default false;
|
||||
|
||||
}
|
@ -1,178 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.worldedit.util.command.MissingParameterException;
|
||||
|
||||
/**
|
||||
* Makes an instance of a {@link CommandContext} into a stack of arguments
|
||||
* that can be consumed.
|
||||
*
|
||||
* @see ParametricBuilder a user of this class
|
||||
*/
|
||||
public class ContextArgumentStack implements ArgumentStack {
|
||||
|
||||
private final CommandContext context;
|
||||
private int index = 0;
|
||||
private int markedIndex = 0;
|
||||
|
||||
/**
|
||||
* Create a new instance using the given context.
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public ContextArgumentStack(CommandContext context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String next() throws ParameterException {
|
||||
try {
|
||||
return context.getString(index++);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new MissingParameterException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer nextInt() throws ParameterException {
|
||||
try {
|
||||
return Integer.parseInt(next());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ParameterException(
|
||||
"Expected a number, got '" + context.getString(index - 1) + "'");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double nextDouble() throws ParameterException {
|
||||
try {
|
||||
return Double.parseDouble(next());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ParameterException(
|
||||
"Expected a number, got '" + context.getString(index - 1) + "'");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean nextBoolean() throws ParameterException {
|
||||
try {
|
||||
return next().equalsIgnoreCase("true");
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new MissingParameterException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String remaining() throws ParameterException {
|
||||
try {
|
||||
String value = context.getJoinedStrings(index);
|
||||
index = context.argsLength();
|
||||
return value;
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new MissingParameterException();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the unconsumed arguments left over, without touching the stack.
|
||||
*
|
||||
* @return the unconsumed arguments
|
||||
*/
|
||||
public String getUnconsumed() {
|
||||
if (index >= context.argsLength()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return context.getJoinedStrings(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markConsumed() {
|
||||
index = context.argsLength();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current position.
|
||||
*
|
||||
* @return the position
|
||||
*/
|
||||
public int position() {
|
||||
return index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the current position of the stack.
|
||||
*
|
||||
* <p>The marked position initially starts at 0.</p>
|
||||
*/
|
||||
public void mark() {
|
||||
markedIndex = index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset to the previously {@link #mark()}ed position of the stack, and return
|
||||
* the arguments that were consumed between this point and that previous point.
|
||||
*
|
||||
* <p>The marked position initially starts at 0.</p>
|
||||
*
|
||||
* @return the consumed arguments
|
||||
*/
|
||||
public String reset() {
|
||||
String value = (index - 1 > markedIndex) ? context.getString(markedIndex, index - 1) : "";
|
||||
index = markedIndex;
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether any arguments were consumed between the marked position
|
||||
* and the current position.
|
||||
*
|
||||
* <p>The marked position initially starts at 0.</p>
|
||||
*
|
||||
* @return true if values were consumed.
|
||||
*/
|
||||
public boolean wasConsumed() {
|
||||
return markedIndex != index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the arguments that were consumed between this point and that marked point.
|
||||
*
|
||||
* <p>The marked position initially starts at 0.</p>
|
||||
*
|
||||
* @return the consumed arguments
|
||||
*/
|
||||
public String getConsumed() {
|
||||
return context.getString(markedIndex, index);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying context.
|
||||
*
|
||||
* @return the context
|
||||
*/
|
||||
@Override
|
||||
public CommandContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
/***
|
||||
*
|
||||
* Copyright (c) 2007 Paul Hammant
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holders nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
||||
* THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import com.thoughtworks.paranamer.CachingParanamer;
|
||||
|
||||
import java.lang.reflect.AccessibleObject;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Parameter;
|
||||
|
||||
/**
|
||||
* Default implementation of Paranamer reads from a post-compile added field called '__PARANAMER_DATA'
|
||||
*
|
||||
* @author Paul Hammant
|
||||
* @author Mauro Talevi
|
||||
* @author Guilherme Silveira
|
||||
*/
|
||||
public class FaweParanamer extends CachingParanamer {
|
||||
|
||||
@Override
|
||||
public String[] lookupParameterNames(AccessibleObject methodOrConstructor, boolean throwExceptionIfMissing) {
|
||||
Parameter[] params;
|
||||
if (methodOrConstructor instanceof Constructor) {
|
||||
params = ((Constructor) methodOrConstructor).getParameters();
|
||||
} else if (methodOrConstructor instanceof Method) {
|
||||
params = ((Method) methodOrConstructor).getParameters();
|
||||
} else {
|
||||
return super.lookupParameterNames(methodOrConstructor, throwExceptionIfMissing);
|
||||
}
|
||||
String[] names = new String[params.length];
|
||||
String[] defNames = null;
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
Parameter param = params[i];
|
||||
if (param.isNamePresent()) {
|
||||
names[i] = param.getName();
|
||||
} else {
|
||||
if (defNames == null) {
|
||||
defNames = super.lookupParameterNames(methodOrConstructor, throwExceptionIfMissing);
|
||||
if (defNames.length == 0)
|
||||
return defNames;
|
||||
}
|
||||
names[i] = defNames[i];
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
}
|
@ -1,339 +0,0 @@
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
|
||||
import com.google.common.primitives.Chars;
|
||||
import org.enginehub.piston.annotation.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissionsException;
|
||||
import com.sk89q.minecraft.util.commands.WrappedCommandException;
|
||||
import com.sk89q.worldedit.util.command.CommandCallable;
|
||||
import com.sk89q.worldedit.util.command.InvalidUsageException;
|
||||
import com.sk89q.worldedit.util.command.MissingParameterException;
|
||||
import com.sk89q.worldedit.util.command.Parameter;
|
||||
import com.sk89q.worldedit.util.command.SimpleDescription;
|
||||
import com.sk89q.worldedit.util.command.UnconsumedParameterException;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class FunctionParametricCallable extends AParametricCallable {
|
||||
|
||||
private final ParametricBuilder builder;
|
||||
private final ParameterData[] parameters;
|
||||
private final Set<Character> valueFlags = new HashSet<>();
|
||||
private final boolean anyFlags;
|
||||
private final Set<Character> legacyFlags = new HashSet<>();
|
||||
private final SimpleDescription description = new SimpleDescription();
|
||||
private final String permission;
|
||||
private final Command command;
|
||||
private final Function<Object[], ?> function;
|
||||
private final String group;
|
||||
|
||||
public FunctionParametricCallable(ParametricBuilder builder, String group, Command command, String permission, List<String> arguments, Function<Object[], ?> function) {
|
||||
this.command = command;
|
||||
this.permission = permission;
|
||||
this.builder = builder;
|
||||
this.function = function;
|
||||
this.group = group;
|
||||
|
||||
List<Object[]> paramParsables = new ArrayList<>();
|
||||
Map<String, Type> unqualified = new HashMap<>();
|
||||
for (Type type : builder.getBindings().getTypes()) {
|
||||
String typeStr = type.getTypeName();
|
||||
unqualified.put(typeStr, type);
|
||||
unqualified.put(typeStr.substring(typeStr.lastIndexOf('.') + 1), type);
|
||||
}
|
||||
{
|
||||
Object[] param = null; // name | type | optional value
|
||||
boolean checkEq = false;
|
||||
int checkEqI = 0;
|
||||
for (String arg : arguments) {
|
||||
if (arg.equals("=")) {
|
||||
checkEqI++;
|
||||
checkEq = true;
|
||||
} else if (param == null || !checkEq) {
|
||||
if (param != null) paramParsables.add(param);
|
||||
param = new Object[3];
|
||||
param[0] = arg;
|
||||
if (arg.length() == 1 && command.flags().contains(arg)) {
|
||||
param[1] = Boolean.class;
|
||||
} else {
|
||||
param[1] = String.class;
|
||||
}
|
||||
param[2] = null;
|
||||
checkEqI = 0;
|
||||
checkEq = false;
|
||||
} else {
|
||||
if (checkEqI == 1) {
|
||||
param[1] = unqualified.getOrDefault(arg, String.class);
|
||||
checkEq = false;
|
||||
} else if (checkEqI == 2) {
|
||||
char c = arg.charAt(0);
|
||||
if (c == '\'' || c == '"') arg = arg.substring(1, arg.length() - 1);
|
||||
param[2] = arg;
|
||||
checkEqI = 0;
|
||||
checkEq = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (param != null) paramParsables.add(param);
|
||||
}
|
||||
|
||||
parameters = new ParameterData[paramParsables.size()];
|
||||
List<Parameter> userParameters = new ArrayList<>();
|
||||
|
||||
// This helps keep tracks of @Nullables that appear in the middle of a list
|
||||
// of parameters
|
||||
int numOptional = 0;
|
||||
//
|
||||
// Go through each parameter
|
||||
for (int i = 0; i < paramParsables.size(); i++) {
|
||||
Object[] parsable = paramParsables.get(i);
|
||||
String paramName = (String) parsable[0];
|
||||
Type type = (Type) parsable[1];
|
||||
String optional = (String) parsable[2];
|
||||
|
||||
ParameterData parameter = new ParameterData();
|
||||
parameter.setType(type);
|
||||
parameter.setModifiers(new Annotation[0]);
|
||||
|
||||
boolean flag = paramName.length() == 1 && command.flags().contains(paramName);
|
||||
if (flag) {
|
||||
parameter.setFlag(paramName.charAt(0), type != boolean.class && type != Boolean.class);
|
||||
}
|
||||
|
||||
if (optional != null) {
|
||||
parameter.setOptional(true);
|
||||
if (!optional.equalsIgnoreCase("null")) parameter.setDefaultValue(new String[]{optional});
|
||||
}
|
||||
|
||||
parameter.setName(paramName);
|
||||
|
||||
// Track all value flags
|
||||
if (parameter.isValueFlag()) {
|
||||
valueFlags.add(parameter.getFlag());
|
||||
}
|
||||
|
||||
// No special @annotation binding... let's check for the type
|
||||
if (parameter.getBinding() == null) {
|
||||
parameter.setBinding(builder.getBindings());
|
||||
|
||||
// Don't know how to parse for this type of value
|
||||
if (parameter.getBinding() == null) {
|
||||
throw new ParametricException("Don't know how to handle the parameter type '" + type + "' in\n" + StringMan.getString(command.aliases()));
|
||||
}
|
||||
}
|
||||
|
||||
// Do some validation of this parameter
|
||||
parameter.validate(() -> StringMan.getString(command.aliases()), i + 1);
|
||||
|
||||
// Keep track of optional parameters
|
||||
if (parameter.isOptional() && parameter.getFlag() == null) {
|
||||
numOptional++;
|
||||
} else {
|
||||
if (numOptional > 0 && parameter.isNonFlagConsumer()) {
|
||||
if (parameter.getConsumedCount() < 0) {
|
||||
throw new ParametricException(
|
||||
"Found an parameter using the binding " +
|
||||
parameter.getBinding().getClass().getCanonicalName() +
|
||||
"\nthat does not know how many arguments it consumes, but " +
|
||||
"it follows an optional parameter\nMethod: " + StringMan.getString(command.aliases()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parameters[i] = parameter;
|
||||
|
||||
// Make a list of "real" parameters
|
||||
if (parameter.isUserInput()) {
|
||||
userParameters.add(parameter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Gather legacy flags
|
||||
anyFlags = command.anyFlags();
|
||||
legacyFlags.addAll(Chars.asList(command.flags().toCharArray()));
|
||||
|
||||
// Finish description
|
||||
description.setDescription(!command.desc().isEmpty() ? command.desc() : null);
|
||||
description.setHelp(!command.help().isEmpty() ? command.help() : null);
|
||||
description.overrideUsage(!command.usage().isEmpty() ? command.usage() : null);
|
||||
description.setPermissions(Arrays.asList(permission));
|
||||
|
||||
if (command.usage().isEmpty() && (command.min() > 0 || command.max() > 0)) {
|
||||
boolean hasUserParameters = false;
|
||||
|
||||
for (ParameterData parameter : parameters) {
|
||||
if (parameter.getBinding().getBehavior(parameter) != BindingBehavior.PROVIDES) {
|
||||
hasUserParameters = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasUserParameters) {
|
||||
description.overrideUsage("(unknown usage information)");
|
||||
}
|
||||
}
|
||||
|
||||
// Set parameters
|
||||
description.setParameters(userParameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParameterData[] getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
public Set<Character> getValueFlags() {
|
||||
return valueFlags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Character> getLegacyFlags() {
|
||||
return legacyFlags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object call(String stringArguments, CommandLocals locals, String[] parentCommands) throws CommandException {
|
||||
// Test permission
|
||||
if (!testPermission(locals)) {
|
||||
throw new CommandPermissionsException();
|
||||
}
|
||||
locals.putIfAbsent(CommandCallable.class, this);
|
||||
|
||||
String calledCommand = parentCommands.length > 0 ? parentCommands[parentCommands.length - 1] : "_";
|
||||
String[] split = (calledCommand + " " + stringArguments).split(" ", -1);
|
||||
CommandContext context = new CommandContext(split, getValueFlags(), false, locals);
|
||||
|
||||
// Provide help if -? is specified
|
||||
if (context.hasFlag('?')) {
|
||||
throw new InvalidUsageException(null, this, true);
|
||||
}
|
||||
|
||||
Object[] args = new Object[parameters.length];
|
||||
ContextArgumentStack arguments = new ContextArgumentStack(context);
|
||||
ParameterData parameter = null;
|
||||
|
||||
try {
|
||||
// preProcess handlers
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Collect parameters
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
parameter = parameters[i];
|
||||
|
||||
if (mayConsumeArguments(i, arguments)) {
|
||||
// Parse the user input into a method argument
|
||||
ArgumentStack usedArguments = getScopedContext(parameter, arguments);
|
||||
|
||||
try {
|
||||
usedArguments.mark();
|
||||
args[i] = parameter.getBinding().bind(parameter, usedArguments, false);
|
||||
} catch (ParameterException e) {
|
||||
// Not optional? Then we can't execute this command
|
||||
if (!parameter.isOptional()) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
usedArguments.reset();
|
||||
args[i] = getDefaultValue(i, arguments);
|
||||
}
|
||||
} else {
|
||||
args[i] = getDefaultValue(i, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for unused arguments
|
||||
checkUnconsumed(arguments);
|
||||
|
||||
// preInvoke handlers
|
||||
{
|
||||
if (context.argsLength() < command.min()) {
|
||||
throw new MissingParameterException();
|
||||
}
|
||||
if (command.max() != -1 && context.argsLength() > command.max()) {
|
||||
throw new UnconsumedParameterException(context.getRemainingString(command.max()));
|
||||
}
|
||||
}
|
||||
|
||||
// Execute!
|
||||
Object result = function.apply(args);
|
||||
|
||||
// postInvoke handlers
|
||||
{
|
||||
}
|
||||
return result;
|
||||
} catch (MissingParameterException e) {
|
||||
throw new InvalidUsageException("Too few parameters!", this, true);
|
||||
} catch (UnconsumedParameterException e) {
|
||||
throw new InvalidUsageException("Too many parameters! Unused parameters: " + e.getUnconsumed(), this, true);
|
||||
} catch (ParameterException e) {
|
||||
assert parameter != null;
|
||||
String name = parameter.getName();
|
||||
|
||||
throw new InvalidUsageException("For parameter '" + name + "': " + e.getMessage(), this, true);
|
||||
} catch (InvocationTargetException e) {
|
||||
if (e.getCause() instanceof CommandException) {
|
||||
throw (CommandException) e.getCause();
|
||||
}
|
||||
throw new WrappedCommandException(e);
|
||||
} catch (Throwable t) {
|
||||
throw new WrappedCommandException(t);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals) {
|
||||
return permission != null ? (builder.getAuthorizer().testPermission(locals, permission)) : true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimpleDescription getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPermissions() {
|
||||
return new String[]{permission};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParametricBuilder getBuilder() {
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean anyFlags() {
|
||||
return anyFlags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return command.aliases()[0];
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Called before and after a command is invoked for commands executed by a command
|
||||
* created using {@link ParametricBuilder}.
|
||||
*
|
||||
* <p>Invocation handlers are created by {@link InvokeListener}s. Multiple
|
||||
* listeners and handlers can be registered, and all be run. However, if one handler
|
||||
* throws an exception, future handlers will not execute and the command will
|
||||
* not execute (if thrown in
|
||||
* {@link #preInvoke(Object, Method, ParameterData[], Object[], CommandContext)}).</p>
|
||||
*
|
||||
* @see InvokeListener the factory
|
||||
*/
|
||||
public interface InvokeHandler {
|
||||
|
||||
/**
|
||||
* Called before parameters are processed.
|
||||
*
|
||||
* @param object the object
|
||||
* @param method the method
|
||||
* @param parameters the list of parameters
|
||||
* @param context the context
|
||||
* @throws CommandException can be thrown for an error, which will stop invocation
|
||||
* @throws ParameterException on parameter error
|
||||
*/
|
||||
void preProcess(Object object, Method method, ParameterData[] parameters,
|
||||
CommandContext context) throws CommandException, ParameterException;
|
||||
|
||||
/**
|
||||
* Called before the parameter is invoked.
|
||||
*
|
||||
* @param object the object
|
||||
* @param method the method
|
||||
* @param parameters the list of parameters
|
||||
* @param args the arguments to be given to the method
|
||||
* @param context the context
|
||||
* @throws CommandException can be thrown for an error, which will stop invocation
|
||||
* @throws ParameterException on parameter error
|
||||
*/
|
||||
void preInvoke(Object object, Method method, ParameterData[] parameters,
|
||||
Object[] args, CommandContext context) throws CommandException, ParameterException;
|
||||
|
||||
/**
|
||||
* Called after the parameter is invoked.
|
||||
*
|
||||
* @param object the object
|
||||
* @param method the method
|
||||
* @param parameters the list of parameters
|
||||
* @param args the arguments to be given to the method
|
||||
* @param context the context
|
||||
* @throws CommandException can be thrown for an error
|
||||
* @throws ParameterException on parameter error
|
||||
*/
|
||||
void postInvoke(Object object, Method method, ParameterData[] parameters,
|
||||
Object[] args, CommandContext context) throws CommandException, ParameterException;
|
||||
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||
import com.sk89q.worldedit.util.command.CommandCallable;
|
||||
import com.sk89q.worldedit.util.command.SimpleDescription;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Listens to events related to {@link ParametricBuilder}.
|
||||
*/
|
||||
public interface InvokeListener {
|
||||
|
||||
/**
|
||||
* Create a new invocation handler.
|
||||
*
|
||||
* <p>An example use of an {@link InvokeHandler} would be to verify permissions
|
||||
* added by the {@link CommandPermissions} annotation.</p>
|
||||
*
|
||||
* <p>For simple {@link InvokeHandler}, an object can implement both this
|
||||
* interface and {@link InvokeHandler}.</p>
|
||||
*
|
||||
* @return a new invocation handler
|
||||
*/
|
||||
InvokeHandler createInvokeHandler();
|
||||
|
||||
/**
|
||||
* During creation of a {@link CommandCallable} by a {@link ParametricBuilder},
|
||||
* this will be called in case the description needs to be updated.
|
||||
*
|
||||
* @param object the object
|
||||
* @param method the method
|
||||
* @param parameters a list of parameters
|
||||
* @param description the description to be updated
|
||||
*/
|
||||
void updateDescription(Object object, Method method, ParameterData[] parameters,
|
||||
SimpleDescription description);
|
||||
|
||||
}
|
@ -1,97 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import org.enginehub.piston.annotation.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.worldedit.util.command.MissingParameterException;
|
||||
import com.sk89q.worldedit.util.command.SimpleDescription;
|
||||
import com.sk89q.worldedit.util.command.UnconsumedParameterException;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* Handles legacy properties on {@link Command} such as {@link Command#min()} and
|
||||
* {@link Command#max()}.
|
||||
*/
|
||||
public class LegacyCommandsHandler extends AbstractInvokeListener implements InvokeHandler {
|
||||
|
||||
@Override
|
||||
public InvokeHandler createInvokeHandler() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preProcess(Object object, Method method,
|
||||
ParameterData[] parameters, CommandContext context)
|
||||
throws CommandException, ParameterException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preInvoke(Object object, Method method,
|
||||
ParameterData[] parameters, Object[] args, CommandContext context)
|
||||
throws ParameterException {
|
||||
Command annotation = method.getAnnotation(Command.class);
|
||||
|
||||
if (annotation != null) {
|
||||
if (context.argsLength() < annotation.min()) {
|
||||
throw new MissingParameterException();
|
||||
}
|
||||
|
||||
if (annotation.max() != -1 && context.argsLength() > annotation.max()) {
|
||||
throw new UnconsumedParameterException(
|
||||
context.getRemainingString(annotation.max()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInvoke(Object object, Method method,
|
||||
ParameterData[] parameters, Object[] args, CommandContext context) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDescription(Object object, Method method,
|
||||
ParameterData[] parameters, SimpleDescription description) {
|
||||
Command annotation = method.getAnnotation(Command.class);
|
||||
|
||||
// Handle the case for old commands where no usage is set and all of its
|
||||
// parameters are provider bindings, so its usage information would
|
||||
// be blank and would imply that there were no accepted parameters
|
||||
if (annotation != null && annotation.usage().isEmpty()
|
||||
&& (annotation.min() > 0 || annotation.max() > 0)) {
|
||||
boolean hasUserParameters = false;
|
||||
|
||||
for (ParameterData parameter : parameters) {
|
||||
if (parameter.getBinding().getBehavior(parameter) != BindingBehavior.PROVIDES) {
|
||||
hasUserParameters = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasUserParameters) {
|
||||
description.overrideUsage("(unknown usage information)");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Indicates an optional parameter.
|
||||
*/
|
||||
@Target(ElementType.PARAMETER)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Optional {
|
||||
|
||||
/**
|
||||
* The default value to use if no value is set.
|
||||
*
|
||||
* @return a string value, or an empty list
|
||||
*/
|
||||
String[] value() default {};
|
||||
|
||||
}
|
@ -1,206 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import com.sk89q.worldedit.util.command.SimpleParameter;
|
||||
import com.sk89q.worldedit.util.command.binding.PrimitiveBindings;
|
||||
import com.sk89q.worldedit.util.command.binding.Range;
|
||||
import com.sk89q.worldedit.util.command.binding.Text;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Describes a parameter in detail.
|
||||
*/
|
||||
public class ParameterData extends SimpleParameter {
|
||||
|
||||
private Binding binding;
|
||||
private Annotation classifier;
|
||||
private Annotation[] modifiers;
|
||||
private Type type;
|
||||
|
||||
/**
|
||||
* Get the binding associated with this parameter.
|
||||
*
|
||||
* @return the binding
|
||||
*/
|
||||
public Binding getBinding() {
|
||||
return binding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the binding associated with this parameter.
|
||||
*
|
||||
* @param binding the binding
|
||||
*/
|
||||
public void setBinding(Binding binding) {
|
||||
this.binding = binding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the main type of this parameter.
|
||||
*
|
||||
* <p>The type is normally that is used to determine which binding is used
|
||||
* for a particular method's parameter.</p>
|
||||
*
|
||||
* @return the main type
|
||||
* @see #getClassifier() which can override the type
|
||||
*/
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the main type of this parameter.
|
||||
*
|
||||
* @param type the main type
|
||||
*/
|
||||
public void setType(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the classifier annotation.
|
||||
*
|
||||
* <p>Normally, the type determines what binding is called, but classifiers
|
||||
* take precedence if one is found (and registered with
|
||||
* {@link ParametricBuilder#addBinding(Binding, Type...)}).
|
||||
* An example of a classifier annotation is {@link Text}.</p>
|
||||
*
|
||||
* @return the classifier annotation, null is possible
|
||||
*/
|
||||
public Annotation getClassifier() {
|
||||
return classifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the classifier annotation.
|
||||
*
|
||||
* @param classifier the classifier annotation, null is possible
|
||||
*/
|
||||
public void setClassifier(Annotation classifier) {
|
||||
this.classifier = classifier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of modifier annotations.
|
||||
*
|
||||
* <p>Modifier annotations are not considered in the process of choosing a binding
|
||||
* for a method parameter, but they can be used to modify the behavior of a binding.
|
||||
* An example of a modifier annotation is {@link Range}, which can restrict
|
||||
* numeric values handled by {@link PrimitiveBindings} to be within a range. The list
|
||||
* of annotations may contain a classifier and other unrelated annotations.</p>
|
||||
*
|
||||
* @return a list of annotations
|
||||
*/
|
||||
public Annotation[] getModifiers() {
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
<T extends Annotation> T getModifier(Class<T> annotatedType) {
|
||||
for (Annotation annotation : getModifiers()) {
|
||||
if (annotation.getClass() == annotatedType) return (T) annotation;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of modifiers.
|
||||
*
|
||||
* @param modifiers a list of annotations
|
||||
*/
|
||||
public void setModifiers(Annotation[] modifiers) {
|
||||
this.modifiers = modifiers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of arguments this binding consumes.
|
||||
*
|
||||
* @return -1 if unknown or unavailable
|
||||
*/
|
||||
int getConsumedCount() {
|
||||
return getBinding().getConsumedCount(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this parameter is entered by the user.
|
||||
*
|
||||
* @return true if this parameter is entered by the user.
|
||||
*/
|
||||
boolean isUserInput() {
|
||||
return getBinding().getBehavior(this) != BindingBehavior.PROVIDES;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether this parameter consumes non-flag arguments.
|
||||
*
|
||||
* @return true if this parameter consumes non-flag arguments
|
||||
*/
|
||||
boolean isNonFlagConsumer() {
|
||||
return getBinding().getBehavior(this) != BindingBehavior.PROVIDES && !isValueFlag();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate this parameter and its binding.
|
||||
*/
|
||||
public void validate(Method method, int parameterIndex) throws ParametricException {
|
||||
validate(method::toGenericString, parameterIndex);
|
||||
}
|
||||
|
||||
public void validate(Supplier<String> method, int parameterIndex) throws ParametricException {
|
||||
// We can't have indeterminate consumers without @Switches otherwise
|
||||
// it may screw up parameter processing for later bindings
|
||||
BindingBehavior behavior = getBinding().getBehavior(this);
|
||||
boolean indeterminate = (behavior == BindingBehavior.INDETERMINATE);
|
||||
if (!isValueFlag() && indeterminate) {
|
||||
throw new ParametricException(
|
||||
"@Switch missing for indeterminate consumer\n\n" +
|
||||
"Notably:\nFor the type " + type + ", the binding " +
|
||||
getBinding().getClass().getCanonicalName() +
|
||||
"\nmay or may not consume parameters (isIndeterminateConsumer(" + type + ") = true)" +
|
||||
"\nand therefore @Switch(flag) is required for parameter #" + parameterIndex + " of \n" +
|
||||
method.get());
|
||||
}
|
||||
|
||||
// getConsumedCount() better return -1 if the BindingBehavior is not CONSUMES
|
||||
if (behavior != BindingBehavior.CONSUMES && binding.getConsumedCount(this) != -1) {
|
||||
throw new ParametricException(
|
||||
"getConsumedCount() does not return -1 for binding " +
|
||||
getBinding().getClass().getCanonicalName() +
|
||||
"\neven though its behavior type is " + behavior.name() +
|
||||
"\nfor parameter #" + parameterIndex + " of \n" +
|
||||
method.get());
|
||||
}
|
||||
|
||||
// getConsumedCount() should not return 0 if the BindingBehavior is not PROVIDES
|
||||
if (behavior != BindingBehavior.PROVIDES && binding.getConsumedCount(this) == 0) {
|
||||
throw new ParametricException(
|
||||
"getConsumedCount() must not return 0 for binding " +
|
||||
getBinding().getClass().getCanonicalName() +
|
||||
"\nwhen its behavior type is " + behavior.name() + " and not PROVIDES " +
|
||||
"\nfor parameter #" + parameterIndex + " of \n" +
|
||||
method.get());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
/**
|
||||
* Thrown if there is an error with a parameter.
|
||||
*/
|
||||
public class ParameterException extends Exception {
|
||||
|
||||
public ParameterException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ParameterException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ParameterException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public ParameterException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
}
|
@ -1,269 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.boydti.fawe.command.FawePrimitiveBinding;
|
||||
import com.boydti.fawe.config.Commands;
|
||||
import com.google.common.collect.ImmutableBiMap.Builder;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||
import com.sk89q.worldedit.command.MethodCommands;
|
||||
import com.sk89q.worldedit.util.auth.Authorizer;
|
||||
import com.sk89q.worldedit.util.auth.NullAuthorizer;
|
||||
import com.sk89q.worldedit.util.command.CallableProcessor;
|
||||
import com.sk89q.worldedit.util.command.CommandCallable;
|
||||
import com.sk89q.worldedit.util.command.CommandCompleter;
|
||||
import com.sk89q.worldedit.util.command.Dispatcher;
|
||||
import com.sk89q.worldedit.util.command.NullCompleter;
|
||||
import com.sk89q.worldedit.util.command.ProcessedCallable;
|
||||
import com.sk89q.worldedit.util.command.binding.PrimitiveBindings;
|
||||
import com.sk89q.worldedit.util.command.binding.StandardBindings;
|
||||
import org.enginehub.piston.annotation.param.Switch;
|
||||
import com.thoughtworks.paranamer.Paranamer;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.enginehub.piston.annotation.Command;
|
||||
|
||||
/**
|
||||
* Creates commands using annotations placed on methods and individual parameters of
|
||||
* such methods.
|
||||
*
|
||||
* @see Command defines a command
|
||||
* @see Switch defines a flag
|
||||
*/
|
||||
public class ParametricBuilder {
|
||||
|
||||
private final BindingMap bindings;
|
||||
private final Paranamer paranamer = new FaweParanamer();
|
||||
private final List<InvokeListener> invokeListeners = new ArrayList<>();
|
||||
private Authorizer authorizer = new NullAuthorizer();
|
||||
private CommandCompleter defaultCompleter = new NullCompleter();
|
||||
|
||||
/**
|
||||
* Create a new builder.
|
||||
*
|
||||
* <p>This method will install {@link PrimitiveBindings} and
|
||||
* {@link StandardBindings} and default bindings.</p>
|
||||
*/
|
||||
public ParametricBuilder() {
|
||||
this.bindings = new BindingMap(this);
|
||||
this.bindings.add(new FawePrimitiveBinding());
|
||||
this.bindings.add(new StandardBindings());
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a binding for a given type or classifier (annotation).
|
||||
*
|
||||
* <p>Whenever a method parameter is encountered, a binding must be found for it
|
||||
* so that it can be called later to consume the stack of arguments provided by
|
||||
* the user and return an object that is later passed to
|
||||
* {@link Method#invoke(Object, Object...)}.</p>
|
||||
*
|
||||
* <p>Normally, a {@link Type} is used to discern between different bindings, but
|
||||
* if this is not specific enough, an annotation can be defined and used. This
|
||||
* makes it a "classifier" and it will take precedence over the base type. For
|
||||
* example, even if there is a binding that handles {@link String} parameters,
|
||||
* a special {@code @MyArg} annotation can be assigned to a {@link String}
|
||||
* parameter, which will cause the {@link Builder} to consult the {@link Binding}
|
||||
* associated with {@code @MyArg} rather than with the binding for
|
||||
* the {@link String} type.</p>
|
||||
*
|
||||
* @param binding the binding
|
||||
* @param type a list of types (if specified) to override the binding's types
|
||||
*/
|
||||
public void addBinding(Binding binding, Type... type) {
|
||||
this.bindings.add(binding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a binding (accepts @Command or @BindingMatch methods)
|
||||
* @param binding
|
||||
*/
|
||||
public void addBinding(Object binding) {
|
||||
this.bindings.add(binding);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach an invocation listener.
|
||||
*
|
||||
* <p>Invocation handlers are called in order that their listeners are
|
||||
* registered with a {@link ParametricBuilder}. It is not guaranteed that
|
||||
* a listener may be called, in the case of a {@link CommandException} being
|
||||
* thrown at any time before the appropriate listener or handler is called.
|
||||
* It is possible for a
|
||||
* {@link InvokeHandler#preInvoke(Object, Method, ParameterData[], Object[], CommandContext)} to
|
||||
* be called for a invocation handler, but not the associated
|
||||
* {@link InvokeHandler#postInvoke(Object, Method, ParameterData[], Object[], CommandContext)}.</p>
|
||||
*
|
||||
* <p>An example of an invocation listener is one to handle
|
||||
* {@link CommandPermissions}, by first checking to see if permission is available
|
||||
* in a {@link InvokeHandler#preInvoke(Object, Method, ParameterData[], Object[], CommandContext)}
|
||||
* call. If permission is not found, then an appropriate {@link CommandException}
|
||||
* can be thrown to cease invocation.</p>
|
||||
*
|
||||
* @param listener the listener
|
||||
* @see InvokeHandler the handler
|
||||
*/
|
||||
public void addInvokeListener(InvokeListener listener) {
|
||||
invokeListeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a list of commands from methods specially annotated with {@link Command}
|
||||
* (and other relevant annotations) and register them all with the given
|
||||
* {@link Dispatcher}.
|
||||
*
|
||||
* @param dispatcher the dispatcher to register commands with
|
||||
* @param object the object contain the methods
|
||||
* @throws ParametricException thrown if the commands cannot be registered
|
||||
*/
|
||||
public void registerMethodsAsCommands(Dispatcher dispatcher, Object object) throws ParametricException {
|
||||
registerMethodsAsCommands(dispatcher, object, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a list of commands from methods specially annotated with {@link Command}
|
||||
* (and other relevant annotations) and register them all with the given
|
||||
* {@link Dispatcher}.
|
||||
*
|
||||
* @param dispatcher the dispatcher to register commands with
|
||||
* @param object the object contain the methods
|
||||
* @throws com.sk89q.worldedit.util.command.parametric.ParametricException thrown if the commands cannot be registered
|
||||
*/
|
||||
public void registerMethodsAsCommands(Dispatcher dispatcher, Object object, CallableProcessor processor) throws ParametricException {
|
||||
for (Method method : object.getClass().getDeclaredMethods()) {
|
||||
registerMethodAsCommands(method, dispatcher, object, processor);
|
||||
}
|
||||
}
|
||||
|
||||
public void registerMethodAsCommands(Method method, Dispatcher dispatcher, Object object, CallableProcessor processor) throws ParametricException {
|
||||
Command definition = method.getAnnotation(Command.class);
|
||||
if (definition != null) {
|
||||
definition = Commands.translate(method.getDeclaringClass(), definition);
|
||||
CommandCallable callable = build(object, method, definition);
|
||||
if (processor != null) {
|
||||
callable = new ProcessedCallable(callable, processor);
|
||||
}
|
||||
else if (object instanceof CallableProcessor) {
|
||||
callable = new ProcessedCallable(callable, (CallableProcessor) object);
|
||||
}
|
||||
if (object instanceof MethodCommands) {
|
||||
((MethodCommands) object).register(method, callable, dispatcher);
|
||||
}
|
||||
dispatcher.registerCommand(callable, definition.aliases());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a {@link CommandCallable} for the given method.
|
||||
*
|
||||
* @param object the object to be invoked on
|
||||
* @param method the method to invoke
|
||||
* @param definition the command definition annotation
|
||||
* @return the command executor
|
||||
* @throws ParametricException thrown on an error
|
||||
*/
|
||||
private CommandCallable build(Object object, Method method, Command definition)
|
||||
throws ParametricException {
|
||||
try {
|
||||
return new ParametricCallable(this, object, method, definition);
|
||||
} catch (Throwable e) {
|
||||
if (e instanceof ParametricException) {
|
||||
throw (ParametricException) e;
|
||||
}
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the object used to get method names on Java versions before 8 (assuming
|
||||
* that Java 8 is given the ability to reliably reflect method names at runtime).
|
||||
*
|
||||
* @return the paranamer
|
||||
*/
|
||||
Paranamer getParanamer() {
|
||||
return paranamer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the map of bindings.
|
||||
*
|
||||
* @return the map of bindings
|
||||
*/
|
||||
public BindingMap getBindings() {
|
||||
return bindings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of invocation listeners.
|
||||
*
|
||||
* @return a list of invocation listeners
|
||||
*/
|
||||
List<InvokeListener> getInvokeListeners() {
|
||||
return invokeListeners;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the authorizer.
|
||||
*
|
||||
* @return the authorizer
|
||||
*/
|
||||
public Authorizer getAuthorizer() {
|
||||
return authorizer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the authorizer.
|
||||
*
|
||||
* @param authorizer the authorizer
|
||||
*/
|
||||
public void setAuthorizer(Authorizer authorizer) {
|
||||
checkNotNull(authorizer);
|
||||
this.authorizer = authorizer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default command suggestions provider that will be used if
|
||||
* no suggestions are available.
|
||||
*
|
||||
* @return the default command completer
|
||||
*/
|
||||
public CommandCompleter getDefaultCompleter() {
|
||||
return defaultCompleter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the default command suggestions provider that will be used if
|
||||
* no suggestions are available.
|
||||
*
|
||||
* @param defaultCompleter the default command completer
|
||||
*/
|
||||
public void setDefaultCompleter(CommandCompleter defaultCompleter) {
|
||||
checkNotNull(defaultCompleter);
|
||||
this.defaultCompleter = defaultCompleter;
|
||||
}
|
||||
|
||||
}
|
@ -1,362 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import com.google.common.primitives.Chars;
|
||||
import org.enginehub.piston.annotation.Command;
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissionsException;
|
||||
import com.sk89q.minecraft.util.commands.WrappedCommandException;
|
||||
import com.sk89q.worldedit.util.command.CommandCallable;
|
||||
import com.sk89q.worldedit.util.command.InvalidUsageException;
|
||||
import com.sk89q.worldedit.util.command.MissingParameterException;
|
||||
import com.sk89q.worldedit.util.command.Parameter;
|
||||
import com.sk89q.worldedit.util.command.SimpleDescription;
|
||||
import com.sk89q.worldedit.util.command.UnconsumedParameterException;
|
||||
import org.enginehub.piston.annotation.param.Switch;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* The implementation of a {@link CommandCallable} for the {@link ParametricBuilder}.
|
||||
*/
|
||||
public class ParametricCallable extends AParametricCallable {
|
||||
|
||||
private final ParametricBuilder builder;
|
||||
private final Object object;
|
||||
private final Method method;
|
||||
private final ParameterData[] parameters;
|
||||
private final Set<Character> valueFlags = new HashSet<>();
|
||||
private final boolean anyFlags;
|
||||
private final Set<Character> legacyFlags = new HashSet<>();
|
||||
private final SimpleDescription description = new SimpleDescription();
|
||||
private final CommandPermissions commandPermissions;
|
||||
private final Command definition;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param builder the parametric builder
|
||||
* @param object the object to invoke on
|
||||
* @param method the method to invoke
|
||||
* @param definition the command definition annotation
|
||||
* @throws ParametricException thrown on an error
|
||||
*/
|
||||
ParametricCallable(ParametricBuilder builder, Object object, Method method, Command definition) throws ParametricException {
|
||||
this.builder = builder;
|
||||
this.object = object;
|
||||
this.method = method;
|
||||
|
||||
Annotation[][] annotations = method.getParameterAnnotations();
|
||||
String[] names = builder.getParanamer().lookupParameterNames(method, false);
|
||||
Type[] types = method.getGenericParameterTypes();
|
||||
parameters = new ParameterData[types.length];
|
||||
List<Parameter> userParameters = new ArrayList<>();
|
||||
|
||||
// This helps keep tracks of @Nullables that appear in the middle of a list
|
||||
// of parameters
|
||||
int numOptional = 0;
|
||||
|
||||
// Set permission hint
|
||||
CommandPermissions permHint = method.getAnnotation(CommandPermissions.class);
|
||||
if (permHint != null) {
|
||||
description.setPermissions(Arrays.asList(permHint.value()));
|
||||
}
|
||||
|
||||
// Go through each parameter
|
||||
for (int i = 0; i < types.length; i++) {
|
||||
Type type = types[i];
|
||||
|
||||
ParameterData parameter = new ParameterData();
|
||||
parameter.setType(type);
|
||||
parameter.setModifiers(annotations[i]);
|
||||
|
||||
// Search for annotations
|
||||
for (Annotation annotation : annotations[i]) {
|
||||
if (annotation instanceof Switch) {
|
||||
parameter.setFlag(((Switch) annotation).value(), type != boolean.class);
|
||||
} else if (annotation instanceof Optional) {
|
||||
parameter.setOptional(true);
|
||||
String[] value = ((Optional) annotation).value();
|
||||
if (value.length > 0) {
|
||||
parameter.setDefaultValue(value);
|
||||
}
|
||||
// Special annotation bindings
|
||||
} else if (parameter.getBinding() == null) {
|
||||
parameter.setBinding(builder.getBindings());
|
||||
parameter.setClassifier(annotation);
|
||||
}
|
||||
}
|
||||
|
||||
parameter.setName(names.length > 0 ? names[i] : generateName(type, parameter.getClassifier(), i));
|
||||
|
||||
// Track all value flags
|
||||
if (parameter.isValueFlag()) {
|
||||
valueFlags.add(parameter.getFlag());
|
||||
}
|
||||
|
||||
// No special @annotation binding... let's check for the type
|
||||
if (parameter.getBinding() == null) {
|
||||
parameter.setBinding(builder.getBindings());
|
||||
|
||||
// Don't know how to parse for this type of value
|
||||
if (parameter.getBinding() == null) {
|
||||
throw new ParametricException("Don't know how to handle the parameter type '" + type + "' in\n" + method.toGenericString());
|
||||
}
|
||||
}
|
||||
|
||||
// Do some validation of this parameter
|
||||
parameter.validate(method, i + 1);
|
||||
|
||||
// Keep track of optional parameters
|
||||
if (parameter.isOptional() && parameter.getFlag() == null) {
|
||||
numOptional++;
|
||||
} else {
|
||||
if (numOptional > 0 && parameter.isNonFlagConsumer()) {
|
||||
if (parameter.getConsumedCount() < 0) {
|
||||
throw new ParametricException(
|
||||
"Found an parameter using the binding " +
|
||||
parameter.getBinding().getClass().getCanonicalName() +
|
||||
"\nthat does not know how many arguments it consumes, but " +
|
||||
"it follows an optional parameter\nMethod: " +
|
||||
method.toGenericString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parameters[i] = parameter;
|
||||
|
||||
// Make a list of "real" parameters
|
||||
if (parameter.isUserInput()) {
|
||||
userParameters.add(parameter);
|
||||
}
|
||||
}
|
||||
|
||||
// Gather legacy flags
|
||||
anyFlags = definition.anyFlags();
|
||||
legacyFlags.addAll(Chars.asList(definition.flags().toCharArray()));
|
||||
|
||||
// Finish description
|
||||
description.setDescription(!definition.desc().isEmpty() ? definition.desc() : null);
|
||||
description.setHelp(!definition.help().isEmpty() ? definition.help() : null);
|
||||
description.overrideUsage(!definition.usage().isEmpty() ? definition.usage() : null);
|
||||
|
||||
for (InvokeListener listener : builder.getInvokeListeners()) {
|
||||
listener.updateDescription(object, method, parameters, description);
|
||||
}
|
||||
|
||||
// Set parameters
|
||||
description.setParameters(userParameters);
|
||||
|
||||
// Get permissions annotation
|
||||
commandPermissions = method.getAnnotation(CommandPermissions.class);
|
||||
this.definition = definition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command getCommand() {
|
||||
return object.getClass().getAnnotation(Command.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Command getDefinition() {
|
||||
return definition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGroup() {
|
||||
return object.getClass().getSimpleName().replaceAll("Commands", "").replaceAll("Util$", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object call(String stringArguments, CommandLocals locals, String[] parentCommands) throws CommandException {
|
||||
// Test permission
|
||||
if (parentCommands.length != 0 && !testPermission(locals)) {
|
||||
throw new CommandPermissionsException();
|
||||
}
|
||||
locals.putIfAbsent(CommandCallable.class, this);
|
||||
|
||||
String calledCommand = parentCommands.length > 0 ? parentCommands[parentCommands.length - 1] : "_";
|
||||
String[] split = CommandContext.split(calledCommand + " " + stringArguments);
|
||||
CommandContext context = new CommandContext(split, getValueFlags(), false, locals);
|
||||
|
||||
// Provide help if -? is specified
|
||||
if (context.hasFlag('?')) {
|
||||
throw new InvalidUsageException(null, this, true);
|
||||
}
|
||||
|
||||
Object[] args = new Object[parameters.length];
|
||||
ContextArgumentStack arguments = new ContextArgumentStack(context);
|
||||
ParameterData parameter = null;
|
||||
|
||||
try {
|
||||
// preProcess handlers
|
||||
List<InvokeHandler> handlers = new ArrayList<>();
|
||||
for (InvokeListener listener : builder.getInvokeListeners()) {
|
||||
InvokeHandler handler = listener.createInvokeHandler();
|
||||
handlers.add(handler);
|
||||
handler.preProcess(object, method, parameters, context);
|
||||
}
|
||||
|
||||
// Collect parameters
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
parameter = parameters[i];
|
||||
|
||||
if (mayConsumeArguments(i, arguments)) {
|
||||
// Parse the user input into a method argument
|
||||
ArgumentStack usedArguments = getScopedContext(parameter, arguments);
|
||||
|
||||
try {
|
||||
usedArguments.mark();
|
||||
args[i] = parameter.getBinding().bind(parameter, usedArguments, false);
|
||||
} catch (ParameterException e) {
|
||||
// Not optional? Then we can't execute this command
|
||||
if (!parameter.isOptional()) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
usedArguments.reset();
|
||||
args[i] = getDefaultValue(i, arguments);
|
||||
}
|
||||
} else {
|
||||
args[i] = getDefaultValue(i, arguments);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for unused arguments
|
||||
checkUnconsumed(arguments);
|
||||
|
||||
// preInvoke handlers
|
||||
for (InvokeHandler handler : handlers) {
|
||||
handler.preInvoke(object, method, parameters, args, context);
|
||||
}
|
||||
|
||||
// Execute!
|
||||
Object result = method.invoke(object, args);
|
||||
|
||||
// postInvoke handlers
|
||||
for (InvokeHandler handler : handlers) {
|
||||
handler.postInvoke(handler, method, parameters, args, context);
|
||||
}
|
||||
return result;
|
||||
} catch (MissingParameterException e) {
|
||||
throw new InvalidUsageException("Too few parameters!", this);
|
||||
} catch (UnconsumedParameterException e) {
|
||||
throw new InvalidUsageException("Too many parameters! Unused parameters: " + e.getUnconsumed(), this);
|
||||
} catch (ParameterException e) {
|
||||
assert parameter != null;
|
||||
String name = parameter.getName();
|
||||
|
||||
throw new InvalidUsageException("For parameter '" + name + "': " + e.getMessage(), this);
|
||||
} catch (InvocationTargetException e) {
|
||||
if (e.getCause() instanceof CommandException) {
|
||||
throw (CommandException) e.getCause();
|
||||
}
|
||||
throw new WrappedCommandException(e);
|
||||
} catch (Throwable t) {
|
||||
throw new WrappedCommandException(t);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getObject() {
|
||||
return object;
|
||||
}
|
||||
|
||||
public Method getMethod() {
|
||||
return method;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParameterData[] getParameters() {
|
||||
return parameters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of value flags used by this command.
|
||||
*
|
||||
* @return a list of value flags
|
||||
*/
|
||||
public Set<Character> getValueFlags() {
|
||||
return valueFlags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<Character> getLegacyFlags() {
|
||||
return legacyFlags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SimpleDescription getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getPermissions() {
|
||||
return commandPermissions != null ? commandPermissions.value() : new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ParametricBuilder getBuilder() {
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean anyFlags() {
|
||||
return anyFlags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return method.toGenericString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a name for a parameter.
|
||||
*
|
||||
* @param type the type
|
||||
* @param classifier the classifier
|
||||
* @param index the index
|
||||
* @return a generated name
|
||||
*/
|
||||
private static String generateName(Type type, Annotation classifier, int index) {
|
||||
if (classifier != null) {
|
||||
return classifier.annotationType().getSimpleName().toLowerCase(Locale.ROOT);
|
||||
} else {
|
||||
if (type instanceof Class<?>) {
|
||||
return ((Class<?>) type).getSimpleName().toLowerCase(Locale.ROOT);
|
||||
} else {
|
||||
return "unknown" + index;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
/**
|
||||
* Thrown if the {@link ParametricBuilder} can't build commands from
|
||||
* an object for whatever reason.
|
||||
*/
|
||||
public class ParametricException extends RuntimeException {
|
||||
|
||||
public ParametricException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ParametricException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ParametricException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ParametricException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -1,155 +0,0 @@
|
||||
/*
|
||||
* 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 Lesser 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 Lesser General Public License
|
||||
* for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.command.parametric;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.util.StringUtil;
|
||||
import com.sk89q.worldedit.util.command.MissingParameterException;
|
||||
|
||||
/**
|
||||
* A virtual scope that does not actually read from the underlying
|
||||
* {@link CommandContext}.
|
||||
*/
|
||||
public class StringArgumentStack implements ArgumentStack {
|
||||
|
||||
private final boolean nonNullBoolean;
|
||||
private final CommandContext context;
|
||||
private final String[] arguments;
|
||||
private int markedIndex = 0;
|
||||
private int index = 0;
|
||||
|
||||
/**
|
||||
* Create a new instance using the given context.
|
||||
*
|
||||
* @param context the context
|
||||
* @param arguments a list of arguments
|
||||
* @param nonNullBoolean true to have {@link #nextBoolean()} return false instead of null
|
||||
*/
|
||||
public StringArgumentStack(
|
||||
CommandContext context, String[] arguments, boolean nonNullBoolean) {
|
||||
this.context = context;
|
||||
this.arguments = arguments;
|
||||
this.nonNullBoolean = nonNullBoolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance using the given context.
|
||||
*
|
||||
* @param context the context
|
||||
* @param arguments an argument string to be parsed
|
||||
* @param nonNullBoolean true to have {@link #nextBoolean()} return false instead of null
|
||||
*/
|
||||
public StringArgumentStack(
|
||||
CommandContext context, String arguments, boolean nonNullBoolean) {
|
||||
this.context = context;
|
||||
this.arguments = CommandContext.split(arguments);
|
||||
this.nonNullBoolean = nonNullBoolean;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String next() throws ParameterException {
|
||||
try {
|
||||
return arguments[index++];
|
||||
} catch (ArrayIndexOutOfBoundsException e) {
|
||||
throw new MissingParameterException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer nextInt() throws ParameterException {
|
||||
try {
|
||||
return Integer.parseInt(next());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ParameterException(
|
||||
"Expected a number, got '" + context.getString(index - 1) + "'");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double nextDouble() throws ParameterException {
|
||||
try {
|
||||
return Double.parseDouble(next());
|
||||
} catch (NumberFormatException e) {
|
||||
throw new ParameterException(
|
||||
"Expected a number, got '" + context.getString(index - 1) + "'");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean nextBoolean() throws ParameterException {
|
||||
try {
|
||||
return next().equalsIgnoreCase("true");
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
if (nonNullBoolean) { // Special case
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new MissingParameterException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String remaining() throws ParameterException {
|
||||
try {
|
||||
String value = StringUtil.joinString(arguments, " ", index);
|
||||
markConsumed();
|
||||
return value;
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
throw new MissingParameterException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markConsumed() {
|
||||
index = arguments.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandContext getContext() {
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mark the current position of the stack.
|
||||
*
|
||||
* <p>The marked position initially starts at 0.</p>
|
||||
*/
|
||||
@Override
|
||||
public void mark() {
|
||||
markedIndex = index;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset to the previously {@link #mark()}ed position of the stack, and return
|
||||
* the arguments that were consumed between this point and that previous point.
|
||||
*
|
||||
* <p>The marked position initially starts at 0.</p>
|
||||
*
|
||||
* @return the consumed arguments
|
||||
*/
|
||||
@Override
|
||||
public String reset() {
|
||||
String value = (index - 1 > markedIndex) ? context.getString(markedIndex, index - 1) : "";
|
||||
index = markedIndex;
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -19,7 +19,7 @@
|
||||
|
||||
package com.sk89q.worldedit.world;
|
||||
|
||||
import com.boydti.fawe.util.SetQueue;
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
@ -105,7 +105,7 @@ public interface SimpleWorld extends World {
|
||||
|
||||
@Override
|
||||
default boolean queueBlockBreakEffect(Platform server, BlockVector3 position, BlockType blockType, double priority) {
|
||||
SetQueue.IMP.addTask(() -> playEffect(position, 2001, blockType.getLegacyCombinedId() >> 4));
|
||||
Fawe.get().getQueueHandler().sync(() -> playEffect(position, 2001, blockType.getLegacyCombinedId() >> 4));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren