Merge branch 'master' into feature/mapping
Conflicts: src/bukkit/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java src/main/java/com/sk89q/worldedit/internal/LocalWorldAdapter.java src/main/java/com/sk89q/worldedit/util/TargetBlock.java
This commit is contained in:
@@ -24,6 +24,7 @@ import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.blocks.BaseItemStack;
|
||||
import com.sk89q.worldedit.entity.BaseEntity;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.operation.Operation;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
@@ -254,7 +255,7 @@ public class LocalWorldAdapter extends LocalWorld {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean queueBlockBreakEffect(ServerInterface server, Vector position, int blockId, double priority) {
|
||||
public boolean queueBlockBreakEffect(Platform server, Vector position, int blockId, double priority) {
|
||||
return world.queueBlockBreakEffect(server, position, blockId, priority);
|
||||
}
|
||||
|
||||
@@ -351,7 +352,7 @@ public class LocalWorldAdapter extends LocalWorld {
|
||||
return world.getEntities();
|
||||
}
|
||||
|
||||
public static LocalWorldAdapter wrap(World world) {
|
||||
public static LocalWorldAdapter adapt(World world) {
|
||||
return new LocalWorldAdapter(world);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
/*
|
||||
* 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.internal;
|
||||
|
||||
import com.sk89q.worldedit.BiomeTypes;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.ServerInterface;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
import com.sk89q.worldedit.extension.platform.Platform;
|
||||
import com.sk89q.worldedit.extension.platform.Preference;
|
||||
import com.sk89q.worldedit.util.command.Dispatcher;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Adapts {@link Platform}s into the legacy {@link ServerInterface}.
|
||||
*/
|
||||
public class ServerInterfaceAdapter extends ServerInterface {
|
||||
|
||||
private final Platform platform;
|
||||
|
||||
/**
|
||||
* Create a new adapter.
|
||||
*
|
||||
* @param platform the platform
|
||||
*/
|
||||
private ServerInterfaceAdapter(Platform platform) {
|
||||
checkNotNull(platform);
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int resolveItem(String name) {
|
||||
return platform.resolveItem(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValidMobType(String type) {
|
||||
return platform.isValidMobType(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reload() {
|
||||
platform.reload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BiomeTypes getBiomes() {
|
||||
return platform.getBiomes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int schedule(long delay, long period, Runnable task) {
|
||||
return platform.schedule(delay, period, task);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends World> getWorlds() {
|
||||
return platform.getWorlds();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Player matchPlayer(Player player) {
|
||||
return platform.matchPlayer(player);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public World matchWorld(World world) {
|
||||
return platform.matchWorld(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCommands(Dispatcher dispatcher) {
|
||||
platform.registerCommands(dispatcher);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerGameHooks() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalConfiguration getConfiguration() {
|
||||
return platform.getConfiguration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return platform.getVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlatformName() {
|
||||
return platform.getPlatformName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlatformVersion() {
|
||||
return platform.getPlatformVersion();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Capability, Preference> getCapabilities() {
|
||||
return platform.getCapabilities();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapt an {@link Platform} instance into a {@link ServerInterface}.
|
||||
*
|
||||
* @param platform the platform
|
||||
* @return the server interface
|
||||
*/
|
||||
public static ServerInterface adapt(Platform platform) {
|
||||
return new ServerInterfaceAdapter(platform);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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.internal.annotation;
|
||||
|
||||
import com.sk89q.worldedit.Vector;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Annotates a {@link Vector} parameter to inject a direction.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.PARAMETER)
|
||||
public @interface Direction {
|
||||
|
||||
public static final String AIM = "me";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* 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.internal.annotation;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Indicates that this value should come from the current selection.
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.PARAMETER)
|
||||
public @interface Selection {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.internal.command;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.util.auth.Authorizer;
|
||||
|
||||
/**
|
||||
* Implementation of an authorizer that uses {@link Actor#hasPermission(String)}.
|
||||
*/
|
||||
public class ActorAuthorizer implements Authorizer {
|
||||
|
||||
@Override
|
||||
public boolean testPermission(CommandLocals locals, String permission) {
|
||||
Actor sender = locals.get(Actor.class);
|
||||
if (sender == null) {
|
||||
throw new RuntimeException("Uh oh! No 'Actor' specified so that we can check permissions");
|
||||
} else {
|
||||
return sender.hasPermission(permission);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* 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.internal.command;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.Logging;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.util.command.parametric.AbstractInvokeListener;
|
||||
import com.sk89q.worldedit.util.command.parametric.InvokeHandler;
|
||||
import com.sk89q.worldedit.util.command.parametric.ParameterData;
|
||||
import com.sk89q.worldedit.util.command.parametric.ParameterException;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* Logs called commands to a logger.
|
||||
*/
|
||||
public class CommandLoggingHandler extends AbstractInvokeListener implements InvokeHandler, Closeable {
|
||||
|
||||
private final WorldEdit worldEdit;
|
||||
private final Logger logger;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param worldEdit an instance of WorldEdit
|
||||
* @param logger the logger to send messages to
|
||||
*/
|
||||
public CommandLoggingHandler(WorldEdit worldEdit, Logger logger) {
|
||||
checkNotNull(worldEdit);
|
||||
checkNotNull(logger);
|
||||
this.worldEdit = worldEdit;
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
@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 CommandException {
|
||||
Logging loggingAnnotation = method.getAnnotation(Logging.class);
|
||||
Logging.LogMode logMode;
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
if (loggingAnnotation == null) {
|
||||
logMode = null;
|
||||
} else {
|
||||
logMode = loggingAnnotation.value();
|
||||
}
|
||||
|
||||
Actor sender = context.getLocals().get(Actor.class);
|
||||
Player player;
|
||||
|
||||
if (sender == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (sender instanceof Player) {
|
||||
player = (Player) sender;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
builder.append("WorldEdit: ").append(sender.getName());
|
||||
if (sender.isPlayer()) {
|
||||
builder.append(" (in \"" + player.getWorld().getName() + "\")");
|
||||
}
|
||||
|
||||
builder.append(": ").append(context.getCommand());
|
||||
|
||||
if (context.argsLength() > 0) {
|
||||
builder.append(" ").append(context.getJoinedStrings(0));
|
||||
}
|
||||
|
||||
if (logMode != null && sender.isPlayer()) {
|
||||
Vector position = player.getPosition();
|
||||
LocalSession session = worldEdit.getSessionManager().get(player);
|
||||
|
||||
switch (logMode) {
|
||||
case PLACEMENT:
|
||||
try {
|
||||
position = session.getPlacementPosition(player);
|
||||
} catch (IncompleteRegionException e) {
|
||||
break;
|
||||
}
|
||||
/* FALL-THROUGH */
|
||||
|
||||
case POSITION:
|
||||
builder.append(" - Position: " + position);
|
||||
break;
|
||||
|
||||
case ALL:
|
||||
builder.append(" - Position: " + position);
|
||||
/* FALL-THROUGH */
|
||||
|
||||
case ORIENTATION_REGION:
|
||||
builder.append(" - Orientation: " + player.getCardinalDirection().name());
|
||||
/* FALL-THROUGH */
|
||||
|
||||
case REGION:
|
||||
try {
|
||||
builder.append(" - Region: ")
|
||||
.append(session.getSelection(player.getWorld()));
|
||||
} catch (IncompleteRegionException e) {
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
logger.info(builder.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInvoke(Object object, Method method, ParameterData[] parameters, Object[] args, CommandContext context) throws CommandException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InvokeHandler createInvokeHandler() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
for (Handler h : logger.getHandlers()) {
|
||||
h.close();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,296 @@
|
||||
/*
|
||||
* 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.internal.command;
|
||||
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.BaseBlock;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.input.NoMatchException;
|
||||
import com.sk89q.worldedit.extension.input.ParserContext;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.internal.annotation.Direction;
|
||||
import com.sk89q.worldedit.internal.annotation.Selection;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.TreeGenerator;
|
||||
import com.sk89q.worldedit.util.TreeGenerator.TreeType;
|
||||
import com.sk89q.worldedit.util.command.parametric.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Binds standard WorldEdit classes such as {@link Player} and {@link LocalSession}.
|
||||
*/
|
||||
public class WorldEditBinding extends BindingHelper {
|
||||
|
||||
private final WorldEdit worldEdit;
|
||||
|
||||
/**
|
||||
* Create a new instance.
|
||||
*
|
||||
* @param worldEdit the WorldEdit instance to bind to
|
||||
*/
|
||||
public WorldEditBinding(WorldEdit worldEdit) {
|
||||
this.worldEdit = worldEdit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a selection from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @param selection the annotation
|
||||
* @return a selection
|
||||
* @throws IncompleteRegionException if no selection is available
|
||||
* @throws ParameterException on other error
|
||||
*/
|
||||
@BindingMatch(classifier = Selection.class,
|
||||
type = Region.class,
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
public Object getSelection(ArgumentStack context, Selection selection) throws IncompleteRegionException, ParameterException {
|
||||
Player sender = getPlayer(context);
|
||||
LocalSession session = worldEdit.getSessionManager().get(sender);
|
||||
return session.getSelection(sender.getWorld());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link EditSession} from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return an edit session
|
||||
* @throws ParameterException on other error
|
||||
*/
|
||||
@BindingMatch(type = EditSession.class,
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
public EditSession getEditSession(ArgumentStack context) throws ParameterException {
|
||||
Player sender = getPlayer(context);
|
||||
LocalSession session = worldEdit.getSessionManager().get(sender);
|
||||
EditSession editSession = session.createEditSession(sender);
|
||||
editSession.enableQueue();
|
||||
context.getContext().getLocals().put(EditSession.class, editSession);
|
||||
session.tellVersion(sender);
|
||||
return editSession;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link LocalSession} from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return a local session
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = LocalSession.class,
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
public LocalSession getLocalSession(ArgumentStack context) throws ParameterException {
|
||||
Player sender = getPlayer(context);
|
||||
return worldEdit.getSessionManager().get(sender);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link Actor} from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return a local player
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = Actor.class,
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
public Actor getActor(ArgumentStack context) throws ParameterException {
|
||||
Actor sender = context.getContext().getLocals().get(Actor.class);
|
||||
if (sender == null) {
|
||||
throw new ParameterException("Missing 'Actor'");
|
||||
} else {
|
||||
return sender;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link Player} from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return a local player
|
||||
* @throws ParameterException on error
|
||||
*/
|
||||
@BindingMatch(type = Player.class,
|
||||
behavior = BindingBehavior.PROVIDES)
|
||||
public Player getPlayer(ArgumentStack context) throws ParameterException {
|
||||
Actor sender = context.getContext().getLocals().get(Actor.class);
|
||||
if (sender == null) {
|
||||
throw new ParameterException("No player to get a session for");
|
||||
} else if (sender instanceof Player) {
|
||||
return (Player) sender;
|
||||
} else {
|
||||
throw new ParameterException("Caller is not a player");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link BaseBlock} from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return a pattern
|
||||
* @throws ParameterException on error
|
||||
* @throws WorldEditException on error
|
||||
*/
|
||||
@BindingMatch(type = BaseBlock.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public BaseBlock getBaseBlock(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
Actor actor = context.getContext().getLocals().get(Actor.class);
|
||||
ParserContext parserContext = new ParserContext();
|
||||
parserContext.setActor(context.getContext().getLocals().get(Actor.class));
|
||||
if (actor instanceof Entity) {
|
||||
parserContext.setWorld(((Entity) actor).getWorld());
|
||||
}
|
||||
parserContext.setSession(worldEdit.getSessionManager().get(actor));
|
||||
try {
|
||||
return worldEdit.getBlockRegistry().parseFromInput(context.next(), parserContext);
|
||||
} catch (NoMatchException e) {
|
||||
throw new ParameterException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link Pattern} from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return a pattern
|
||||
* @throws ParameterException on error
|
||||
* @throws WorldEditException on error
|
||||
*/
|
||||
@BindingMatch(type = Pattern.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public Pattern getPattern(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
Actor actor = context.getContext().getLocals().get(Actor.class);
|
||||
ParserContext parserContext = new ParserContext();
|
||||
parserContext.setActor(context.getContext().getLocals().get(Actor.class));
|
||||
if (actor instanceof Entity) {
|
||||
parserContext.setWorld(((Entity) actor).getWorld());
|
||||
}
|
||||
parserContext.setSession(worldEdit.getSessionManager().get(actor));
|
||||
try {
|
||||
return worldEdit.getPatternRegistry().parseFromInput(context.next(), parserContext);
|
||||
} catch (NoMatchException e) {
|
||||
throw new ParameterException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link Mask} from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return a pattern
|
||||
* @throws ParameterException on error
|
||||
* @throws WorldEditException on error
|
||||
*/
|
||||
@BindingMatch(type = Mask.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public Mask getMask(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
Actor actor = context.getContext().getLocals().get(Actor.class);
|
||||
ParserContext parserContext = new ParserContext();
|
||||
parserContext.setActor(context.getContext().getLocals().get(Actor.class));
|
||||
if (actor instanceof Entity) {
|
||||
parserContext.setWorld(((Entity) actor).getWorld());
|
||||
}
|
||||
parserContext.setSession(worldEdit.getSessionManager().get(actor));
|
||||
try {
|
||||
return worldEdit.getMaskRegistry().parseFromInput(context.next(), parserContext);
|
||||
} catch (NoMatchException e) {
|
||||
throw new ParameterException(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a direction from the player.
|
||||
*
|
||||
* @param context the context
|
||||
* @param direction the direction annotation
|
||||
* @return a pattern
|
||||
* @throws ParameterException on error
|
||||
* @throws UnknownDirectionException on an unknown direction
|
||||
*/
|
||||
@BindingMatch(classifier = Direction.class,
|
||||
type = Vector.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public Vector getDirection(ArgumentStack context, Direction direction)
|
||||
throws ParameterException, UnknownDirectionException {
|
||||
Player sender = getPlayer(context);
|
||||
return worldEdit.getDirection(sender, context.next());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link TreeType} from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return a pattern
|
||||
* @throws ParameterException on error
|
||||
* @throws WorldEditException on error
|
||||
*/
|
||||
@BindingMatch(type = TreeType.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public TreeType getTreeType(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
String input = context.next();
|
||||
if (input != null) {
|
||||
TreeType type = TreeGenerator.lookup(input);
|
||||
if (type != null) {
|
||||
return type;
|
||||
} else {
|
||||
throw new ParameterException(
|
||||
String.format("Can't recognize tree type '%s' -- choose from: %s", input, Arrays.toString(TreeType.values())));
|
||||
}
|
||||
} else {
|
||||
return TreeType.TREE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an {@link BiomeType} from a {@link ArgumentStack}.
|
||||
*
|
||||
* @param context the context
|
||||
* @return a pattern
|
||||
* @throws ParameterException on error
|
||||
* @throws WorldEditException on error
|
||||
*/
|
||||
@BindingMatch(type = BiomeType.class,
|
||||
behavior = BindingBehavior.CONSUMES,
|
||||
consumedCount = 1)
|
||||
public BiomeType getBiomeType(ArgumentStack context) throws ParameterException, WorldEditException {
|
||||
String input = context.next();
|
||||
if (input != null) {
|
||||
BiomeType type = worldEdit.getServer().getBiomes().get(input);
|
||||
if (type != null) {
|
||||
return type;
|
||||
} else {
|
||||
throw new ParameterException(
|
||||
String.format("Can't recognize biome type '%s' -- use //biomelist to list available types", input));
|
||||
}
|
||||
} else {
|
||||
throw new ParameterException(
|
||||
"This command takes a 'default' biome if one is not set, except there is no particular " +
|
||||
"biome that should be 'default', so the command should not be taking a default biome");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,156 @@
|
||||
/*
|
||||
* 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.internal.command;
|
||||
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.worldedit.*;
|
||||
import com.sk89q.worldedit.blocks.ItemType;
|
||||
import com.sk89q.worldedit.command.InsufficientArgumentsException;
|
||||
import com.sk89q.worldedit.internal.expression.ExpressionException;
|
||||
import com.sk89q.worldedit.regions.RegionOperationException;
|
||||
import com.sk89q.worldedit.util.command.parametric.ExceptionConverterHelper;
|
||||
import com.sk89q.worldedit.util.command.parametric.ExceptionMatch;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
* converts WorldEdit exceptions and converts them into {@link CommandException}s.
|
||||
*/
|
||||
public class WorldEditExceptionConverter extends ExceptionConverterHelper {
|
||||
|
||||
private static final Pattern numberFormat = Pattern.compile("^For input string: \"(.*)\"$");
|
||||
private final WorldEdit worldEdit;
|
||||
|
||||
public WorldEditExceptionConverter(WorldEdit worldEdit) {
|
||||
checkNotNull(worldEdit);
|
||||
this.worldEdit = worldEdit;
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(PlayerNeededException e) throws CommandException {
|
||||
throw new CommandException(e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(NumberFormatException e) throws CommandException {
|
||||
final Matcher matcher = numberFormat.matcher(e.getMessage());
|
||||
|
||||
if (matcher.matches()) {
|
||||
throw new CommandException("Number expected; string \"" + matcher.group(1)
|
||||
+ "\" given.");
|
||||
} else {
|
||||
throw new CommandException("Number expected; string given.");
|
||||
}
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(IncompleteRegionException e) throws CommandException {
|
||||
throw new CommandException("Make a region selection first.");
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(UnknownItemException e) throws CommandException {
|
||||
throw new CommandException("Block name '" + e.getID() + "' was not recognized.");
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(InvalidItemException e) throws CommandException {
|
||||
throw new CommandException(e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(DisallowedItemException e) throws CommandException {
|
||||
throw new CommandException("Block '" + e.getID()
|
||||
+ "' not allowed (see WorldEdit configuration).");
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(MaxChangedBlocksException e) throws CommandException {
|
||||
throw new CommandException("Max blocks changed in an operation reached ("
|
||||
+ e.getBlockLimit() + ").");
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(MaxBrushRadiusException e) throws CommandException {
|
||||
throw new CommandException("Maximum brush radius (in configuration): " + worldEdit.getConfiguration().maxBrushRadius);
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(MaxRadiusException e) throws CommandException {
|
||||
throw new CommandException("Maximum radius (in configuration): " + worldEdit.getConfiguration().maxRadius);
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(UnknownDirectionException e) throws CommandException {
|
||||
throw new CommandException("Unknown direction: " + e.getDirection());
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(InsufficientArgumentsException e) throws CommandException {
|
||||
throw new CommandException(e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(RegionOperationException e) throws CommandException {
|
||||
throw new CommandException(e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(ExpressionException e) throws CommandException {
|
||||
throw new CommandException(e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(EmptyClipboardException e) throws CommandException {
|
||||
throw new CommandException("Your clipboard is empty. Use //copy first.");
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(InvalidFilenameException e) throws CommandException {
|
||||
throw new CommandException("Filename '" + e.getFilename() + "' invalid: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(FilenameResolutionException e) throws CommandException {
|
||||
throw new CommandException(
|
||||
"File '" + e.getFilename() + "' resolution error: " + e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(InvalidToolBindException e) throws CommandException {
|
||||
throw new CommandException("Can't bind tool to "
|
||||
+ ItemType.toHeldName(e.getItemId()) + ": " + e.getMessage());
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(FileSelectionAbortedException e) throws CommandException {
|
||||
throw new CommandException("File selection aborted.");
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(WorldEditException e) throws CommandException {
|
||||
throw new CommandException(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user