2011-01-01 01:40:07 +00:00
|
|
|
/*
|
2014-04-03 01:57:25 +00:00
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
2011-01-01 01:40:07 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* 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
|
2011-01-01 01:40:07 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* 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.
|
2011-01-01 01:40:07 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2011-01-01 01:40:07 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-04-03 01:57:25 +00:00
|
|
|
*/
|
2011-01-01 01:40:07 +00:00
|
|
|
|
|
|
|
package com.sk89q.worldedit;
|
|
|
|
|
2014-04-03 01:57:25 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.*;
|
2012-09-02 20:56:40 +00:00
|
|
|
import com.sk89q.minecraft.util.commands.Console;
|
2011-01-19 10:03:41 +00:00
|
|
|
import com.sk89q.util.StringUtil;
|
2011-10-24 23:03:37 +00:00
|
|
|
import com.sk89q.worldedit.CuboidClipboard.FlipDirection;
|
2014-04-04 00:52:53 +00:00
|
|
|
import com.sk89q.worldedit.blocks.BaseBlock;
|
|
|
|
import com.sk89q.worldedit.blocks.BlockType;
|
|
|
|
import com.sk89q.worldedit.blocks.ItemType;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.command.*;
|
2014-04-04 00:52:53 +00:00
|
|
|
import com.sk89q.worldedit.command.tool.*;
|
2014-04-03 01:57:25 +00:00
|
|
|
import com.sk89q.worldedit.event.extent.EditSessionEvent;
|
2014-04-04 00:52:53 +00:00
|
|
|
import com.sk89q.worldedit.extension.input.ParserContext;
|
|
|
|
import com.sk89q.worldedit.extension.registry.BlockRegistry;
|
|
|
|
import com.sk89q.worldedit.extension.registry.MaskRegistry;
|
|
|
|
import com.sk89q.worldedit.extension.registry.PatternRegistry;
|
|
|
|
import com.sk89q.worldedit.extent.inventory.BlockBag;
|
|
|
|
import com.sk89q.worldedit.function.mask.Masks;
|
|
|
|
import com.sk89q.worldedit.function.pattern.Patterns;
|
|
|
|
import com.sk89q.worldedit.masks.Mask;
|
|
|
|
import com.sk89q.worldedit.patterns.Pattern;
|
2014-04-04 02:50:05 +00:00
|
|
|
import com.sk89q.worldedit.regions.RegionSelector;
|
2012-09-02 20:56:40 +00:00
|
|
|
import com.sk89q.worldedit.scripting.CraftScriptContext;
|
|
|
|
import com.sk89q.worldedit.scripting.CraftScriptEngine;
|
|
|
|
import com.sk89q.worldedit.scripting.RhinoCraftScriptEngine;
|
2014-04-04 02:12:30 +00:00
|
|
|
import com.sk89q.worldedit.session.SessionManager;
|
2014-04-04 00:52:53 +00:00
|
|
|
import com.sk89q.worldedit.session.request.Request;
|
2014-04-03 02:08:50 +00:00
|
|
|
import com.sk89q.worldedit.util.LogFormat;
|
2014-04-03 01:57:25 +00:00
|
|
|
import com.sk89q.worldedit.util.eventbus.EventBus;
|
|
|
|
|
|
|
|
import javax.script.ScriptException;
|
|
|
|
import java.io.*;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.logging.FileHandler;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
2011-01-01 01:40:07 +00:00
|
|
|
|
|
|
|
/**
|
2014-04-03 01:57:25 +00:00
|
|
|
* The current instance of WorldEdit.
|
2011-01-01 01:40:07 +00:00
|
|
|
*/
|
2011-01-26 18:53:26 +00:00
|
|
|
public class WorldEdit {
|
2014-04-03 01:57:25 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
public static final Logger logger = Logger.getLogger("Minecraft.WorldEdit");
|
2012-12-27 16:45:37 +00:00
|
|
|
public final Logger commandLogger = Logger.getLogger("Minecraft.WorldEdit.CommandLogger");
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2012-10-18 10:34:09 +00:00
|
|
|
private static WorldEdit instance;
|
2011-01-31 08:58:29 +00:00
|
|
|
private static String version;
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2012-03-28 18:05:52 +00:00
|
|
|
private final ServerInterface server;
|
|
|
|
private final LocalConfiguration config;
|
|
|
|
private final CommandsManager<LocalPlayer> commands;
|
2014-04-03 01:57:25 +00:00
|
|
|
private final EventBus eventBus = new EventBus();
|
2014-04-04 03:48:42 +00:00
|
|
|
private final EditSessionFactory editSessionFactory = new EditSessionFactory.EditSessionFactoryImpl(eventBus);
|
2014-04-04 02:12:30 +00:00
|
|
|
private final SessionManager sessions = new SessionManager(this);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2014-04-04 00:52:53 +00:00
|
|
|
private final BlockRegistry blockRegistry = new BlockRegistry(this);
|
|
|
|
private final MaskRegistry maskRegistry = new MaskRegistry(this);
|
|
|
|
private final PatternRegistry patternRegistry = new PatternRegistry(this);
|
|
|
|
|
2011-01-31 08:58:29 +00:00
|
|
|
static {
|
|
|
|
getVersion();
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-01 01:40:07 +00:00
|
|
|
/**
|
2014-04-03 01:57:25 +00:00
|
|
|
* Construct an instance of WorldEdit.
|
2012-03-10 07:11:51 +00:00
|
|
|
*
|
2011-01-01 18:33:18 +00:00
|
|
|
* @param server
|
2011-01-02 05:50:31 +00:00
|
|
|
* @param config
|
2011-01-01 01:40:07 +00:00
|
|
|
*/
|
2011-08-08 12:40:02 +00:00
|
|
|
public WorldEdit(ServerInterface server, final LocalConfiguration config) {
|
2012-10-18 10:34:09 +00:00
|
|
|
instance = this;
|
2011-01-01 18:33:18 +00:00
|
|
|
this.server = server;
|
2011-01-02 05:50:31 +00:00
|
|
|
this.config = config;
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2012-12-27 16:45:37 +00:00
|
|
|
if (!config.logFile.equals("")) {
|
|
|
|
try {
|
|
|
|
FileHandler logFileHandler;
|
|
|
|
logFileHandler = new FileHandler(new File(config.getWorkingDirectory(),
|
|
|
|
config.logFile).getAbsolutePath(), true);
|
|
|
|
logFileHandler.setFormatter(new LogFormat());
|
|
|
|
commandLogger.addHandler(logFileHandler);
|
|
|
|
} catch (IOException e) {
|
|
|
|
logger.log(Level.WARNING, "Could not use command log file " + config.logFile + ": "
|
|
|
|
+ e.getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-25 00:39:23 +00:00
|
|
|
commands = new CommandsManager<LocalPlayer>() {
|
2011-12-15 12:26:59 +00:00
|
|
|
@Override
|
|
|
|
protected void checkPermission(LocalPlayer player, Method method) throws CommandException {
|
|
|
|
if (!player.isPlayer() && !method.isAnnotationPresent(Console.class)) {
|
|
|
|
throw new UnhandledCommandException();
|
|
|
|
}
|
|
|
|
|
|
|
|
super.checkPermission(player, method);
|
|
|
|
}
|
|
|
|
|
2011-02-25 00:39:23 +00:00
|
|
|
@Override
|
|
|
|
public boolean hasPermission(LocalPlayer player, String perm) {
|
|
|
|
return player.hasPermission(perm);
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-08-08 12:40:02 +00:00
|
|
|
@Override
|
|
|
|
public void invokeMethod(Method parent, String[] args,
|
|
|
|
LocalPlayer player, Method method, Object instance,
|
|
|
|
Object[] methodArgs, int level) throws CommandException {
|
|
|
|
if (config.logCommands) {
|
|
|
|
final Logging loggingAnnotation = method.getAnnotation(Logging.class);
|
|
|
|
|
|
|
|
final Logging.LogMode logMode;
|
2011-09-24 19:24:10 +00:00
|
|
|
if (loggingAnnotation == null) {
|
2011-08-08 12:40:02 +00:00
|
|
|
logMode = null;
|
2011-09-24 19:24:10 +00:00
|
|
|
} else {
|
2011-08-08 12:40:02 +00:00
|
|
|
logMode = loggingAnnotation.value();
|
2011-09-24 19:24:10 +00:00
|
|
|
}
|
2011-08-08 12:40:02 +00:00
|
|
|
|
2011-12-15 12:26:59 +00:00
|
|
|
String msg = "WorldEdit: " + player.getName();
|
|
|
|
if (player.isPlayer()) {
|
|
|
|
msg += " (in \"" + player.getWorld().getName() + "\")";
|
|
|
|
}
|
|
|
|
msg += ": " + StringUtil.joinString(args, " ");
|
|
|
|
if (logMode != null && player.isPlayer()) {
|
2011-08-08 12:40:02 +00:00
|
|
|
Vector position = player.getPosition();
|
|
|
|
final LocalSession session = getSession(player);
|
|
|
|
switch (logMode) {
|
|
|
|
case PLACEMENT:
|
|
|
|
try {
|
|
|
|
position = session.getPlacementPosition(player);
|
|
|
|
} catch (IncompleteRegionException e) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* FALL-THROUGH */
|
2011-08-08 23:13:57 +00:00
|
|
|
|
2011-08-08 12:40:02 +00:00
|
|
|
case POSITION:
|
2011-11-23 01:29:48 +00:00
|
|
|
msg += " - Position: " + position;
|
2011-08-08 12:40:02 +00:00
|
|
|
break;
|
2011-08-08 23:13:57 +00:00
|
|
|
|
|
|
|
case ALL:
|
2011-11-23 01:29:48 +00:00
|
|
|
msg += " - Position: " + position;
|
2011-08-08 23:13:57 +00:00
|
|
|
/* FALL-THROUGH */
|
|
|
|
|
|
|
|
case ORIENTATION_REGION:
|
2011-11-23 01:29:48 +00:00
|
|
|
msg += " - Orientation: " + player.getCardinalDirection().name();
|
2011-08-08 23:13:57 +00:00
|
|
|
/* FALL-THROUGH */
|
|
|
|
|
2011-08-08 12:40:02 +00:00
|
|
|
case REGION:
|
|
|
|
try {
|
2011-11-23 01:29:48 +00:00
|
|
|
msg += " - Region: " + session.getSelection(player.getWorld());
|
2011-08-08 12:40:02 +00:00
|
|
|
} catch (IncompleteRegionException e) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-12-27 16:45:37 +00:00
|
|
|
commandLogger.info(msg);
|
2011-08-08 12:40:02 +00:00
|
|
|
}
|
|
|
|
super.invokeMethod(parent, args, player, method, instance, methodArgs, level);
|
|
|
|
}
|
2011-02-25 00:39:23 +00:00
|
|
|
};
|
2012-03-10 07:11:51 +00:00
|
|
|
|
2011-12-18 07:45:12 +00:00
|
|
|
commands.setInjector(new SimpleInjector(this));
|
2011-01-29 10:05:22 +00:00
|
|
|
|
2012-03-28 18:05:52 +00:00
|
|
|
reg(BiomeCommands.class);
|
|
|
|
reg(ChunkCommands.class);
|
|
|
|
reg(ClipboardCommands.class);
|
|
|
|
reg(GeneralCommands.class);
|
|
|
|
reg(GenerationCommands.class);
|
|
|
|
reg(HistoryCommands.class);
|
|
|
|
reg(NavigationCommands.class);
|
|
|
|
reg(RegionCommands.class);
|
|
|
|
reg(ScriptingCommands.class);
|
|
|
|
reg(SelectionCommands.class);
|
|
|
|
reg(SnapshotUtilCommands.class);
|
|
|
|
reg(ToolUtilCommands.class);
|
|
|
|
reg(ToolCommands.class);
|
|
|
|
reg(UtilityCommands.class);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void reg(Class<?> clazz) {
|
|
|
|
server.onCommandRegistration(commands.registerAndReturn(clazz), commands);
|
2011-01-01 01:40:07 +00:00
|
|
|
}
|
2011-11-20 05:02:54 +00:00
|
|
|
|
2012-10-18 10:34:09 +00:00
|
|
|
/**
|
|
|
|
* Gets the current instance of this class
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static WorldEdit getInstance() {
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2014-04-03 01:57:25 +00:00
|
|
|
/**
|
|
|
|
* Get the event bus for WorldEdit.
|
|
|
|
*
|
|
|
|
* @return the event bus
|
|
|
|
*/
|
|
|
|
public EventBus getEventBus() {
|
|
|
|
return eventBus;
|
|
|
|
}
|
|
|
|
|
2014-04-04 00:52:53 +00:00
|
|
|
/**
|
|
|
|
* Get the block registry from which new {@link BaseBlock}s can be
|
|
|
|
* constructed.
|
|
|
|
*
|
|
|
|
* @return the block registry
|
|
|
|
*/
|
|
|
|
public BlockRegistry getBlockRegistry() {
|
|
|
|
return blockRegistry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the mask registry from which new {@link com.sk89q.worldedit.function.mask.Mask}s
|
|
|
|
* can be constructed.
|
|
|
|
*
|
|
|
|
* @return the mask registry
|
|
|
|
*/
|
|
|
|
public MaskRegistry getMaskRegistry() {
|
|
|
|
return maskRegistry;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the pattern registry from which new {@link com.sk89q.worldedit.function.pattern.Pattern}s
|
|
|
|
* can be constructed.
|
|
|
|
*
|
|
|
|
* @return the pattern registry
|
|
|
|
*/
|
|
|
|
public PatternRegistry getPatternRegistry() {
|
|
|
|
return patternRegistry;
|
|
|
|
}
|
|
|
|
|
2011-11-20 05:02:54 +00:00
|
|
|
/**
|
2014-04-04 02:12:30 +00:00
|
|
|
* Return the session manager.
|
2011-08-29 21:24:35 +00:00
|
|
|
*
|
2014-04-04 02:12:30 +00:00
|
|
|
* @return the session manager
|
|
|
|
*/
|
|
|
|
public SessionManager getSessionManager() {
|
|
|
|
return sessions;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated Use {@link #getSessionManager()}
|
2011-08-29 21:24:35 +00:00
|
|
|
*/
|
2014-04-04 02:12:30 +00:00
|
|
|
@Deprecated
|
2011-08-29 21:24:35 +00:00
|
|
|
public LocalSession getSession(String player) {
|
2014-04-04 02:12:30 +00:00
|
|
|
return sessions.findByName(player);
|
2011-08-29 21:24:35 +00:00
|
|
|
}
|
2011-01-01 01:40:07 +00:00
|
|
|
|
|
|
|
/**
|
2014-04-04 02:12:30 +00:00
|
|
|
* @deprecated use {@link #getSessionManager()}
|
2011-01-01 01:40:07 +00:00
|
|
|
*/
|
2014-04-04 02:12:30 +00:00
|
|
|
@Deprecated
|
2011-01-01 18:34:36 +00:00
|
|
|
public LocalSession getSession(LocalPlayer player) {
|
2014-04-04 02:12:30 +00:00
|
|
|
return sessions.get(player);
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2014-04-04 02:12:30 +00:00
|
|
|
/**
|
|
|
|
* @deprecated use {@link #getSessionManager()}
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public void removeSession(LocalPlayer player) {
|
|
|
|
sessions.remove(player);
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2014-04-04 02:12:30 +00:00
|
|
|
/**
|
|
|
|
* @deprecated use {@link #getSessionManager()}
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public void clearSessions() {
|
|
|
|
sessions.clear();
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
2011-01-01 01:40:07 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
/**
|
2014-04-04 02:12:30 +00:00
|
|
|
* @deprecated use {@link #getSessionManager()}
|
2011-01-29 10:05:22 +00:00
|
|
|
*/
|
2014-04-04 02:12:30 +00:00
|
|
|
@Deprecated
|
2011-01-29 10:05:22 +00:00
|
|
|
public boolean hasSession(LocalPlayer player) {
|
2014-04-04 02:12:30 +00:00
|
|
|
return sessions.contains(player);
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
2011-01-01 01:40:07 +00:00
|
|
|
|
2014-04-04 00:52:53 +00:00
|
|
|
/**
|
|
|
|
* @deprecated Use {@link #getBlockRegistry()} and {@link BlockRegistry#parseFromInput(String, ParserContext)}
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public BaseBlock getBlock(LocalPlayer player, String arg, boolean allAllowed) throws WorldEditException {
|
2011-09-18 04:50:06 +00:00
|
|
|
return getBlock(player, arg, allAllowed, false);
|
|
|
|
}
|
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
/**
|
2014-04-04 00:52:53 +00:00
|
|
|
* @deprecated Use {@link #getBlockRegistry()} and {@link BlockRegistry#parseFromInput(String, ParserContext)}
|
2011-01-29 10:05:22 +00:00
|
|
|
*/
|
2014-04-04 00:52:53 +00:00
|
|
|
@Deprecated
|
|
|
|
public BaseBlock getBlock(LocalPlayer player, String arg, boolean allAllowed, boolean allowNoData) throws WorldEditException {
|
|
|
|
ParserContext context = new ParserContext();
|
2014-04-05 00:54:14 +00:00
|
|
|
context.setActor(player);
|
2014-04-04 00:52:53 +00:00
|
|
|
context.setWorld(player.getWorld());
|
|
|
|
context.setSession(getSession(player));
|
|
|
|
context.setRestricted(!allAllowed);
|
|
|
|
context.setPreferringWildcard(allowNoData);
|
|
|
|
return getBlockRegistry().parseFromInput(arg, context);
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
2011-01-01 01:40:07 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
/**
|
2014-04-04 00:52:53 +00:00
|
|
|
* @deprecated Use {@link #getBlockRegistry()} and {@link BlockRegistry#parseFromInput(String, ParserContext)}
|
2011-01-29 10:05:22 +00:00
|
|
|
*/
|
2014-04-04 00:52:53 +00:00
|
|
|
@Deprecated
|
|
|
|
public BaseBlock getBlock(LocalPlayer player, String id) throws WorldEditException {
|
2011-01-29 10:05:22 +00:00
|
|
|
return getBlock(player, id, false);
|
|
|
|
}
|
2011-01-01 01:40:07 +00:00
|
|
|
|
2014-04-04 00:52:53 +00:00
|
|
|
/**
|
|
|
|
* @deprecated Use {@link #getBlockRegistry()} and {@link BlockRegistry#parseFromListInput(String, ParserContext)}
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public Set<BaseBlock> getBlocks(LocalPlayer player, String list, boolean allAllowed, boolean allowNoData) throws WorldEditException {
|
2011-08-29 06:57:07 +00:00
|
|
|
String[] items = list.split(",");
|
|
|
|
Set<BaseBlock> blocks = new HashSet<BaseBlock>();
|
|
|
|
for (String id : items) {
|
2011-09-18 04:50:06 +00:00
|
|
|
blocks.add(getBlock(player, id, allAllowed, allowNoData));
|
2011-08-29 06:57:07 +00:00
|
|
|
}
|
|
|
|
return blocks;
|
|
|
|
}
|
2011-09-18 04:50:06 +00:00
|
|
|
|
2014-04-04 00:52:53 +00:00
|
|
|
/**
|
|
|
|
* @deprecated Use {@link #getBlockRegistry()} and {@link BlockRegistry#parseFromInput(String, ParserContext)}
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public Set<BaseBlock> getBlocks(LocalPlayer player, String list, boolean allAllowed) throws WorldEditException {
|
2011-10-12 21:47:26 +00:00
|
|
|
return getBlocks(player, list, allAllowed, false);
|
2011-09-18 04:50:06 +00:00
|
|
|
}
|
2011-08-29 06:57:07 +00:00
|
|
|
|
2014-04-04 00:52:53 +00:00
|
|
|
/**
|
|
|
|
* @deprecated Use {@link #getBlockRegistry()} and {@link BlockRegistry#parseFromListInput(String, ParserContext)}
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public Set<BaseBlock> getBlocks(LocalPlayer player, String list) throws WorldEditException {
|
2011-08-29 06:57:07 +00:00
|
|
|
return getBlocks(player, list, false);
|
|
|
|
}
|
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
/**
|
2014-04-04 00:52:53 +00:00
|
|
|
* @deprecated Use {@link #getBlockRegistry()} and {@link BlockRegistry#parseFromListInput(String, ParserContext)}
|
2011-01-29 10:05:22 +00:00
|
|
|
*/
|
2014-04-04 00:52:53 +00:00
|
|
|
@Deprecated
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public Set<Integer> getBlockIDs(LocalPlayer player, String list, boolean allBlocksAllowed) throws WorldEditException {
|
|
|
|
String[] items = list.split(",");
|
|
|
|
Set<Integer> blocks = new HashSet<Integer>();
|
2011-01-29 10:05:22 +00:00
|
|
|
for (String s : items) {
|
2014-04-04 00:52:53 +00:00
|
|
|
blocks.add(getBlock(player, s, allBlocksAllowed).getType());
|
2011-01-01 01:40:07 +00:00
|
|
|
}
|
2014-04-04 00:52:53 +00:00
|
|
|
return blocks;
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
|
|
|
/**
|
2014-04-04 00:52:53 +00:00
|
|
|
* @deprecated Use {@link #getPatternRegistry()} and {@link BlockRegistry#parseFromInput(String, ParserContext)}
|
2011-02-18 23:14:43 +00:00
|
|
|
*/
|
2014-04-04 00:52:53 +00:00
|
|
|
@Deprecated
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public Pattern getBlockPattern(LocalPlayer player, String input) throws WorldEditException {
|
|
|
|
ParserContext context = new ParserContext();
|
2014-04-05 00:54:14 +00:00
|
|
|
context.setActor(player);
|
2014-04-04 00:52:53 +00:00
|
|
|
context.setWorld(player.getWorld());
|
|
|
|
context.setSession(getSession(player));
|
|
|
|
return Patterns.wrap(getPatternRegistry().parseFromInput(input, context));
|
2011-02-18 23:14:43 +00:00
|
|
|
}
|
2011-11-20 05:02:54 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
/**
|
2014-04-04 00:52:53 +00:00
|
|
|
* @deprecated Use {@link #getMaskRegistry()} ()} and {@link MaskRegistry#parseFromInput(String, ParserContext)}
|
2011-01-29 10:05:22 +00:00
|
|
|
*/
|
2014-04-04 00:52:53 +00:00
|
|
|
@Deprecated
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public Mask getBlockMask(LocalPlayer player, LocalSession session, String input) throws WorldEditException {
|
|
|
|
ParserContext context = new ParserContext();
|
2014-04-05 00:54:14 +00:00
|
|
|
context.setActor(player);
|
2014-04-04 00:52:53 +00:00
|
|
|
context.setWorld(player.getWorld());
|
|
|
|
context.setSession(session);
|
|
|
|
return Masks.wrap(getMaskRegistry().parseFromInput(input, context));
|
2011-01-29 10:05:22 +00:00
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-31 04:40:22 +00:00
|
|
|
/**
|
|
|
|
* Gets the path to a file. This method will check to see if the filename
|
|
|
|
* has valid characters and has an extension. It also prevents directory
|
|
|
|
* traversal exploits by checking the root directory and the file directory.
|
|
|
|
* On success, a <code>java.io.File</code> object will be returned.
|
2012-03-10 07:11:51 +00:00
|
|
|
*
|
|
|
|
* @param player
|
2011-01-31 04:40:22 +00:00
|
|
|
* @param dir sub-directory to look in
|
|
|
|
* @param filename filename (user-submitted)
|
|
|
|
* @param defaultExt append an extension if missing one, null to not use
|
2011-01-31 05:32:52 +00:00
|
|
|
* @param extensions list of extensions, null for any
|
2011-01-31 04:40:22 +00:00
|
|
|
* @return
|
|
|
|
* @throws FilenameException
|
|
|
|
*/
|
2011-01-31 05:32:52 +00:00
|
|
|
public File getSafeSaveFile(LocalPlayer player, File dir, String filename,
|
2011-11-27 04:29:49 +00:00
|
|
|
String defaultExt, String... extensions)
|
2011-01-31 05:32:52 +00:00
|
|
|
throws FilenameException {
|
|
|
|
return getSafeFile(player, dir, filename, defaultExt, extensions, true);
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-31 05:32:52 +00:00
|
|
|
/**
|
|
|
|
* Gets the path to a file. This method will check to see if the filename
|
|
|
|
* has valid characters and has an extension. It also prevents directory
|
|
|
|
* traversal exploits by checking the root directory and the file directory.
|
|
|
|
* On success, a <code>java.io.File</code> object will be returned.
|
2012-03-10 07:11:51 +00:00
|
|
|
*
|
|
|
|
* @param player
|
2011-01-31 05:32:52 +00:00
|
|
|
* @param dir sub-directory to look in
|
|
|
|
* @param filename filename (user-submitted)
|
|
|
|
* @param defaultExt append an extension if missing one, null to not use
|
|
|
|
* @param extensions list of extensions, null for any
|
|
|
|
* @return
|
|
|
|
* @throws FilenameException
|
|
|
|
*/
|
|
|
|
public File getSafeOpenFile(LocalPlayer player, File dir, String filename,
|
2011-11-27 04:29:49 +00:00
|
|
|
String defaultExt, String... extensions)
|
2011-01-31 05:32:52 +00:00
|
|
|
throws FilenameException {
|
|
|
|
return getSafeFile(player, dir, filename, defaultExt, extensions, false);
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-31 05:32:52 +00:00
|
|
|
/**
|
|
|
|
* Get a safe path to a file.
|
2012-03-10 07:11:51 +00:00
|
|
|
*
|
2011-01-31 05:32:52 +00:00
|
|
|
* @param player
|
|
|
|
* @param dir
|
|
|
|
* @param filename
|
|
|
|
* @param defaultExt
|
|
|
|
* @param extensions
|
|
|
|
* @param isSave
|
|
|
|
* @return
|
|
|
|
* @throws FilenameException
|
|
|
|
*/
|
|
|
|
private File getSafeFile(LocalPlayer player, File dir, String filename,
|
|
|
|
String defaultExt, String[] extensions, boolean isSave)
|
|
|
|
throws FilenameException {
|
2011-12-27 00:28:51 +00:00
|
|
|
if (extensions != null && (extensions.length == 1 && extensions[0] == null)) extensions = null;
|
2011-11-27 04:29:49 +00:00
|
|
|
|
2011-01-31 04:40:22 +00:00
|
|
|
File f;
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-31 04:40:22 +00:00
|
|
|
if (filename.equals("#")) {
|
2011-01-31 05:32:52 +00:00
|
|
|
if (isSave) {
|
|
|
|
f = player.openFileSaveDialog(extensions);
|
|
|
|
} else {
|
|
|
|
f = player.openFileOpenDialog(extensions);
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-31 04:40:22 +00:00
|
|
|
if (f == null) {
|
|
|
|
throw new FileSelectionAbortedException("No file selected");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (defaultExt != null && filename.lastIndexOf('.') == -1) {
|
|
|
|
filename += "." + defaultExt;
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-31 04:40:22 +00:00
|
|
|
if (!filename.matches("^[A-Za-z0-9_\\- \\./\\\\'\\$@~!%\\^\\*\\(\\)\\[\\]\\+\\{\\},\\?]+\\.[A-Za-z0-9]+$")) {
|
2011-09-24 19:24:10 +00:00
|
|
|
throw new InvalidFilenameException(filename, "Invalid characters or extension missing");
|
2011-01-31 04:40:22 +00:00
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-31 04:40:22 +00:00
|
|
|
f = new File(dir, filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
String filePath = f.getCanonicalPath();
|
|
|
|
String dirPath = dir.getCanonicalPath();
|
|
|
|
|
2012-12-25 23:08:03 +00:00
|
|
|
if (!filePath.substring(0, dirPath.length()).equals(dirPath) && !config.allowSymlinks) {
|
2011-01-31 06:06:06 +00:00
|
|
|
throw new FilenameResolutionException(filename,
|
2011-01-31 04:40:22 +00:00
|
|
|
"Path is outside allowable root");
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-31 04:40:22 +00:00
|
|
|
return f;
|
|
|
|
} catch (IOException e) {
|
2011-01-31 06:06:06 +00:00
|
|
|
throw new FilenameResolutionException(filename,
|
2011-01-31 04:40:22 +00:00
|
|
|
"Failed to resolve path");
|
|
|
|
}
|
|
|
|
}
|
2011-01-29 10:05:22 +00:00
|
|
|
|
2012-04-22 15:11:50 +00:00
|
|
|
public int getMaximumPolygonalPoints(LocalPlayer player) {
|
|
|
|
if (player.hasPermission("worldedit.limit.unrestricted") || config.maxPolygonalPoints < 0) {
|
|
|
|
return config.defaultMaxPolygonalPoints;
|
|
|
|
}
|
2013-11-29 22:35:06 +00:00
|
|
|
|
|
|
|
if (config.defaultMaxPolygonalPoints < 0) {
|
|
|
|
return config.maxPolygonalPoints;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Math.min(config.defaultMaxPolygonalPoints, config.maxPolygonalPoints);
|
2012-04-22 15:11:50 +00:00
|
|
|
}
|
|
|
|
|
2013-08-16 06:16:37 +00:00
|
|
|
public int getMaximumPolyhedronPoints(LocalPlayer player) {
|
|
|
|
if (player.hasPermission("worldedit.limit.unrestricted") || config.maxPolyhedronPoints < 0) {
|
|
|
|
return config.defaultMaxPolyhedronPoints;
|
|
|
|
}
|
2013-11-29 22:35:06 +00:00
|
|
|
|
|
|
|
if (config.defaultMaxPolyhedronPoints < 0) {
|
|
|
|
return config.maxPolyhedronPoints;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Math.min(config.defaultMaxPolyhedronPoints, config.maxPolyhedronPoints);
|
2013-08-16 06:16:37 +00:00
|
|
|
}
|
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
/**
|
|
|
|
* Checks to see if the specified radius is within bounds.
|
|
|
|
*
|
|
|
|
* @param radius
|
|
|
|
* @throws MaxRadiusException
|
|
|
|
*/
|
2011-08-15 12:35:21 +00:00
|
|
|
public void checkMaxRadius(double radius) throws MaxRadiusException {
|
2011-01-29 10:05:22 +00:00
|
|
|
if (config.maxRadius > 0 && radius > config.maxRadius) {
|
|
|
|
throw new MaxRadiusException();
|
|
|
|
}
|
2011-01-01 01:40:07 +00:00
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2013-08-03 01:33:11 +00:00
|
|
|
/**
|
|
|
|
* Checks to see if the specified brush radius is within bounds.
|
|
|
|
*
|
|
|
|
* @param radius
|
|
|
|
* @throws MaxBrushRadiusException
|
|
|
|
*/
|
|
|
|
public void checkMaxBrushRadius(double radius) throws MaxBrushRadiusException {
|
|
|
|
if (config.maxBrushRadius > 0 && radius > config.maxBrushRadius) {
|
|
|
|
throw new MaxBrushRadiusException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-29 18:14:04 +00:00
|
|
|
/**
|
|
|
|
* Get a file relative to the defined working directory. If the specified
|
|
|
|
* path is absolute, then the working directory is not used.
|
2012-03-10 07:11:51 +00:00
|
|
|
*
|
2011-01-29 18:14:04 +00:00
|
|
|
* @param path
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public File getWorkingDirectoryFile(String path) {
|
|
|
|
File f = new File(path);
|
|
|
|
if (f.isAbsolute()) {
|
|
|
|
return f;
|
|
|
|
}
|
2013-11-29 22:35:06 +00:00
|
|
|
|
|
|
|
return new File(config.getWorkingDirectory(), path);
|
2011-01-29 18:14:04 +00:00
|
|
|
}
|
2011-01-01 01:40:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Modulus, divisor-style.
|
2012-03-10 07:11:51 +00:00
|
|
|
*
|
2011-01-01 01:40:07 +00:00
|
|
|
* @param a
|
|
|
|
* @param n
|
|
|
|
* @return
|
|
|
|
*/
|
2011-01-29 10:05:22 +00:00
|
|
|
public static int divisorMod(int a, int n) {
|
2012-09-02 20:56:40 +00:00
|
|
|
return (int) (a - n * Math.floor(Math.floor(a) / n));
|
2011-01-01 01:40:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the direction vector for a player's direction. May return
|
|
|
|
* null if a direction could not be found.
|
2012-03-10 07:11:51 +00:00
|
|
|
*
|
2011-01-01 01:40:07 +00:00
|
|
|
* @param player
|
2012-03-10 07:11:51 +00:00
|
|
|
* @param dirStr
|
2011-01-01 01:40:07 +00:00
|
|
|
* @return
|
2012-03-10 07:11:51 +00:00
|
|
|
* @throws UnknownDirectionException
|
2011-01-01 01:40:07 +00:00
|
|
|
*/
|
2011-01-01 18:34:36 +00:00
|
|
|
public Vector getDirection(LocalPlayer player, String dirStr)
|
2011-01-01 01:40:07 +00:00
|
|
|
throws UnknownDirectionException {
|
2011-09-05 01:53:39 +00:00
|
|
|
|
2011-10-24 23:03:37 +00:00
|
|
|
dirStr = dirStr.toLowerCase();
|
2011-09-05 01:53:39 +00:00
|
|
|
|
2011-10-24 23:03:37 +00:00
|
|
|
final PlayerDirection dir = getPlayerDirection(player, dirStr);
|
2011-09-05 01:53:39 +00:00
|
|
|
|
2011-10-24 23:03:37 +00:00
|
|
|
switch (dir) {
|
|
|
|
case WEST:
|
|
|
|
case EAST:
|
|
|
|
case SOUTH:
|
|
|
|
case NORTH:
|
|
|
|
case UP:
|
|
|
|
case DOWN:
|
|
|
|
return dir.vector();
|
2011-09-05 01:53:39 +00:00
|
|
|
|
|
|
|
default:
|
2011-10-24 23:03:37 +00:00
|
|
|
throw new UnknownDirectionException(dir.name());
|
2011-09-05 01:53:39 +00:00
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
}
|
2011-03-21 14:01:15 +00:00
|
|
|
|
2011-10-24 23:03:37 +00:00
|
|
|
private PlayerDirection getPlayerDirection(LocalPlayer player, String dirStr) throws UnknownDirectionException {
|
|
|
|
final PlayerDirection dir;
|
2011-03-21 14:01:15 +00:00
|
|
|
|
2011-09-05 01:53:39 +00:00
|
|
|
switch (dirStr.charAt(0)) {
|
|
|
|
case 'w':
|
2011-10-24 23:03:37 +00:00
|
|
|
dir = PlayerDirection.WEST;
|
|
|
|
break;
|
2011-09-05 01:53:39 +00:00
|
|
|
|
|
|
|
case 'e':
|
2011-10-24 23:03:37 +00:00
|
|
|
dir = PlayerDirection.EAST;
|
|
|
|
break;
|
2011-09-05 01:53:39 +00:00
|
|
|
|
|
|
|
case 's':
|
|
|
|
if (dirStr.indexOf('w') > 0) {
|
2011-10-24 23:03:37 +00:00
|
|
|
return PlayerDirection.SOUTH_WEST;
|
2011-03-21 14:01:15 +00:00
|
|
|
}
|
|
|
|
|
2011-09-05 01:53:39 +00:00
|
|
|
if (dirStr.indexOf('e') > 0) {
|
2011-10-24 23:03:37 +00:00
|
|
|
return PlayerDirection.SOUTH_EAST;
|
2011-09-05 01:53:39 +00:00
|
|
|
}
|
2011-10-24 23:03:37 +00:00
|
|
|
dir = PlayerDirection.SOUTH;
|
|
|
|
break;
|
2011-09-05 01:53:39 +00:00
|
|
|
|
|
|
|
case 'n':
|
|
|
|
if (dirStr.indexOf('w') > 0) {
|
2011-10-24 23:03:37 +00:00
|
|
|
return PlayerDirection.NORTH_WEST;
|
2011-09-05 01:53:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (dirStr.indexOf('e') > 0) {
|
2011-10-24 23:03:37 +00:00
|
|
|
return PlayerDirection.NORTH_EAST;
|
2011-09-05 01:53:39 +00:00
|
|
|
}
|
2011-10-24 23:03:37 +00:00
|
|
|
dir = PlayerDirection.NORTH;
|
|
|
|
break;
|
2011-09-05 01:53:39 +00:00
|
|
|
|
|
|
|
case 'u':
|
2011-10-24 23:03:37 +00:00
|
|
|
dir = PlayerDirection.UP;
|
|
|
|
break;
|
2011-09-05 01:53:39 +00:00
|
|
|
|
|
|
|
case 'd':
|
2011-10-24 23:03:37 +00:00
|
|
|
dir = PlayerDirection.DOWN;
|
|
|
|
break;
|
|
|
|
|
2011-10-24 23:07:08 +00:00
|
|
|
case 'm': // me
|
|
|
|
case 'f': // forward
|
2011-10-24 23:03:37 +00:00
|
|
|
dir = player.getCardinalDirection(0);
|
|
|
|
break;
|
2011-09-05 01:53:39 +00:00
|
|
|
|
2011-10-24 23:07:08 +00:00
|
|
|
case 'b': // back
|
|
|
|
dir = player.getCardinalDirection(180);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l': // left
|
|
|
|
dir = player.getCardinalDirection(-90);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'r': // right
|
|
|
|
dir = player.getCardinalDirection(90);
|
|
|
|
break;
|
|
|
|
|
2011-09-05 01:53:39 +00:00
|
|
|
default:
|
|
|
|
throw new UnknownDirectionException(dirStr);
|
|
|
|
}
|
2011-10-24 23:03:37 +00:00
|
|
|
return dir;
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-10-24 23:03:37 +00:00
|
|
|
/**
|
|
|
|
* Get diagonal direction vector for a player's direction. May return
|
|
|
|
* null if a direction could not be found.
|
2012-03-10 07:11:51 +00:00
|
|
|
*
|
2011-10-24 23:03:37 +00:00
|
|
|
* @param player
|
2012-03-10 07:11:51 +00:00
|
|
|
* @param dirStr
|
2011-10-24 23:03:37 +00:00
|
|
|
* @return
|
2012-03-10 07:11:51 +00:00
|
|
|
* @throws UnknownDirectionException
|
2011-10-24 23:03:37 +00:00
|
|
|
*/
|
|
|
|
public Vector getDiagonalDirection(LocalPlayer player, String dirStr)
|
2011-11-23 01:29:48 +00:00
|
|
|
throws UnknownDirectionException {
|
2011-10-24 23:03:37 +00:00
|
|
|
|
|
|
|
return getPlayerDirection(player, dirStr.toLowerCase()).vector();
|
2011-03-21 14:01:15 +00:00
|
|
|
}
|
2011-01-01 01:40:07 +00:00
|
|
|
|
|
|
|
/**
|
2011-09-04 21:18:37 +00:00
|
|
|
* Get the flip direction for a player's direction.
|
2011-01-01 01:40:07 +00:00
|
|
|
*
|
|
|
|
* @param player
|
2012-03-10 07:11:51 +00:00
|
|
|
* @param dirStr
|
2011-01-01 01:40:07 +00:00
|
|
|
* @return
|
2012-03-10 07:11:51 +00:00
|
|
|
* @throws UnknownDirectionException
|
2011-01-01 01:40:07 +00:00
|
|
|
*/
|
2011-10-24 23:03:37 +00:00
|
|
|
public FlipDirection getFlipDirection(LocalPlayer player, String dirStr)
|
2011-01-01 01:40:07 +00:00
|
|
|
throws UnknownDirectionException {
|
|
|
|
|
2011-10-24 23:03:37 +00:00
|
|
|
final PlayerDirection dir = getPlayerDirection(player, dirStr);
|
|
|
|
switch (dir) {
|
|
|
|
case WEST:
|
|
|
|
case EAST:
|
|
|
|
return FlipDirection.WEST_EAST;
|
2011-09-04 21:18:37 +00:00
|
|
|
|
2011-10-24 23:03:37 +00:00
|
|
|
case NORTH:
|
|
|
|
case SOUTH:
|
|
|
|
return FlipDirection.NORTH_SOUTH;
|
2011-09-04 21:18:37 +00:00
|
|
|
|
2011-10-24 23:03:37 +00:00
|
|
|
case UP:
|
|
|
|
case DOWN:
|
|
|
|
return FlipDirection.UP_DOWN;
|
2011-09-04 21:18:37 +00:00
|
|
|
|
|
|
|
default:
|
2011-10-24 23:03:37 +00:00
|
|
|
throw new UnknownDirectionException(dir.name());
|
2011-01-01 01:40:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-19 10:03:41 +00:00
|
|
|
/**
|
|
|
|
* Flush a block bag's changes to a player.
|
2012-03-10 07:11:51 +00:00
|
|
|
*
|
2011-01-19 10:03:41 +00:00
|
|
|
* @param player
|
|
|
|
* @param editSession
|
|
|
|
*/
|
2011-01-29 10:05:22 +00:00
|
|
|
public void flushBlockBag(LocalPlayer player,
|
2011-01-19 10:03:41 +00:00
|
|
|
EditSession editSession) {
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-19 10:03:41 +00:00
|
|
|
BlockBag blockBag = editSession.getBlockBag();
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-19 10:03:41 +00:00
|
|
|
if (blockBag != null) {
|
|
|
|
blockBag.flushChanges();
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2012-12-29 00:26:57 +00:00
|
|
|
Map<Integer, Integer> missingBlocks = editSession.popMissingBlocks();
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-19 10:03:41 +00:00
|
|
|
if (missingBlocks.size() > 0) {
|
|
|
|
StringBuilder str = new StringBuilder();
|
|
|
|
str.append("Missing these blocks: ");
|
|
|
|
int size = missingBlocks.size();
|
|
|
|
int i = 0;
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2012-12-29 00:26:57 +00:00
|
|
|
for (Integer id : missingBlocks.keySet()) {
|
2011-01-19 10:03:41 +00:00
|
|
|
BlockType type = BlockType.fromID(id);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-19 10:03:41 +00:00
|
|
|
str.append(type != null
|
|
|
|
? type.getName() + " (" + id + ")"
|
2012-01-22 09:23:41 +00:00
|
|
|
: id.toString());
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2012-12-29 00:26:57 +00:00
|
|
|
str.append(" [Amt: " + missingBlocks.get(id) + "]");
|
|
|
|
|
2011-07-15 07:00:48 +00:00
|
|
|
++i;
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-19 10:03:41 +00:00
|
|
|
if (i != size) {
|
|
|
|
str.append(", ");
|
|
|
|
}
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-19 10:03:41 +00:00
|
|
|
player.printError(str.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the commands
|
|
|
|
*/
|
2011-01-29 10:05:22 +00:00
|
|
|
public Map<String, String> getCommands() {
|
|
|
|
return commands.getCommands();
|
2011-01-19 10:03:41 +00:00
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-12-13 08:23:21 +00:00
|
|
|
/**
|
|
|
|
* @return the commands
|
|
|
|
*/
|
|
|
|
public CommandsManager<LocalPlayer> getCommandsManager() {
|
|
|
|
return commands;
|
|
|
|
}
|
|
|
|
|
2011-01-01 01:40:07 +00:00
|
|
|
/**
|
2014-04-04 02:12:30 +00:00
|
|
|
* Handle a disconnection.
|
2011-01-01 01:40:07 +00:00
|
|
|
*
|
2014-04-04 02:12:30 +00:00
|
|
|
* @param player the player
|
2011-01-01 01:40:07 +00:00
|
|
|
*/
|
2011-05-02 00:37:05 +00:00
|
|
|
@Deprecated
|
2011-01-01 18:34:36 +00:00
|
|
|
public void handleDisconnect(LocalPlayer player) {
|
2011-05-02 00:37:05 +00:00
|
|
|
forgetPlayer(player);
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-05-02 00:37:05 +00:00
|
|
|
/**
|
2014-04-04 02:12:30 +00:00
|
|
|
* Mark for expiration of the session.
|
2011-05-02 00:37:05 +00:00
|
|
|
*
|
2014-04-04 02:12:30 +00:00
|
|
|
* @param player the player
|
2011-05-02 00:37:05 +00:00
|
|
|
*/
|
|
|
|
public void markExpire(LocalPlayer player) {
|
2014-04-04 02:12:30 +00:00
|
|
|
sessions.markforExpiration(player);
|
2011-05-02 00:37:05 +00:00
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-05-02 00:37:05 +00:00
|
|
|
/**
|
|
|
|
* Forget a player.
|
|
|
|
*
|
2014-04-04 02:12:30 +00:00
|
|
|
* @param player the player
|
2011-05-02 00:37:05 +00:00
|
|
|
*/
|
|
|
|
public void forgetPlayer(LocalPlayer player) {
|
2014-04-04 02:12:30 +00:00
|
|
|
sessions.remove(player);
|
2011-01-01 01:40:07 +00:00
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-05-02 00:37:05 +00:00
|
|
|
/*
|
|
|
|
* Flush expired sessions.
|
|
|
|
*/
|
|
|
|
public void flushExpiredSessions(SessionCheck checker) {
|
2014-04-04 02:12:30 +00:00
|
|
|
sessions.removeExpired(checker);
|
2011-05-02 00:37:05 +00:00
|
|
|
}
|
2011-01-01 01:40:07 +00:00
|
|
|
|
|
|
|
/**
|
2011-08-06 14:22:02 +00:00
|
|
|
* Called on arm swing.
|
2012-03-10 07:11:51 +00:00
|
|
|
*
|
2011-01-01 01:40:07 +00:00
|
|
|
* @param player
|
2012-03-10 07:11:51 +00:00
|
|
|
* @return
|
2011-01-01 01:40:07 +00:00
|
|
|
*/
|
2011-08-06 14:22:02 +00:00
|
|
|
public boolean handleArmSwing(LocalPlayer player) {
|
2011-11-20 00:45:25 +00:00
|
|
|
if (player.getItemInHand() == config.navigationWand) {
|
|
|
|
if (config.navigationWandMaxDistance <= 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-04-04 23:09:05 +00:00
|
|
|
if (!player.hasPermission("worldedit.navigation.jumpto.tool")) {
|
2011-11-20 00:45:25 +00:00
|
|
|
return false;
|
2011-08-10 19:02:02 +00:00
|
|
|
}
|
2011-11-20 00:45:25 +00:00
|
|
|
|
|
|
|
WorldVector pos = player.getSolidBlockTrace(config.navigationWandMaxDistance);
|
2011-03-12 07:38:11 +00:00
|
|
|
if (pos != null) {
|
|
|
|
player.findFreePosition(pos);
|
|
|
|
} else {
|
|
|
|
player.printError("No block in sight (or too far)!");
|
2011-01-26 18:52:53 +00:00
|
|
|
}
|
2011-08-10 19:02:02 +00:00
|
|
|
return true;
|
2011-01-26 18:52:53 +00:00
|
|
|
}
|
2011-08-06 14:22:02 +00:00
|
|
|
|
2011-11-20 00:45:25 +00:00
|
|
|
LocalSession session = getSession(player);
|
|
|
|
|
2011-08-06 14:22:02 +00:00
|
|
|
Tool tool = session.getTool(player.getItemInHand());
|
|
|
|
if (tool != null && tool instanceof DoubleActionTraceTool) {
|
|
|
|
if (tool.canUse(player)) {
|
|
|
|
((DoubleActionTraceTool) tool).actSecondary(server, config, player, session);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2011-11-20 00:45:25 +00:00
|
|
|
|
2011-01-26 18:52:53 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called on right click (not on a block).
|
2012-03-10 07:11:51 +00:00
|
|
|
*
|
2011-01-26 18:52:53 +00:00
|
|
|
* @param player
|
2012-03-10 07:11:51 +00:00
|
|
|
* @return
|
2011-01-26 18:52:53 +00:00
|
|
|
*/
|
|
|
|
public boolean handleRightClick(LocalPlayer player) {
|
2011-11-20 00:45:25 +00:00
|
|
|
if (player.getItemInHand() == config.navigationWand) {
|
|
|
|
if (config.navigationWandMaxDistance <= 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-12-24 06:42:55 +00:00
|
|
|
if (!player.hasPermission("worldedit.navigation.thru.tool")) {
|
2011-11-20 00:45:25 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-03-12 07:38:11 +00:00
|
|
|
|
|
|
|
if (!player.passThroughForwardWall(40)) {
|
|
|
|
player.printError("Nothing to pass through!");
|
2011-01-19 10:43:26 +00:00
|
|
|
}
|
2011-11-20 00:45:25 +00:00
|
|
|
|
2011-08-10 19:02:02 +00:00
|
|
|
return true;
|
2011-01-09 19:14:55 +00:00
|
|
|
}
|
2011-11-20 00:45:25 +00:00
|
|
|
|
|
|
|
LocalSession session = getSession(player);
|
|
|
|
|
2011-02-18 23:14:43 +00:00
|
|
|
Tool tool = session.getTool(player.getItemInHand());
|
|
|
|
if (tool != null && tool instanceof TraceTool) {
|
2011-05-02 00:06:40 +00:00
|
|
|
if (tool.canUse(player)) {
|
2011-08-06 14:22:02 +00:00
|
|
|
((TraceTool) tool).actPrimary(server, config, player, session);
|
2011-05-02 00:06:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-02-18 23:14:43 +00:00
|
|
|
}
|
2011-11-20 00:45:25 +00:00
|
|
|
|
2011-01-19 10:27:12 +00:00
|
|
|
return false;
|
2011-01-01 01:40:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called on right click.
|
|
|
|
*
|
|
|
|
* @param player
|
|
|
|
* @param clicked
|
|
|
|
* @return false if you want the action to go through
|
|
|
|
*/
|
2011-01-08 19:26:27 +00:00
|
|
|
public boolean handleBlockRightClick(LocalPlayer player, WorldVector clicked) {
|
2011-01-01 18:34:36 +00:00
|
|
|
LocalSession session = getSession(player);
|
2011-01-01 01:40:07 +00:00
|
|
|
|
2011-11-20 01:00:12 +00:00
|
|
|
if (player.getItemInHand() == config.wandItem) {
|
|
|
|
if (!session.isToolControlEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!player.hasPermission("worldedit.selection.pos")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-08-06 14:22:02 +00:00
|
|
|
RegionSelector selector = session.getRegionSelector(player.getWorld());
|
|
|
|
if (selector.selectSecondary(clicked)) {
|
|
|
|
selector.explainSecondarySelection(player, session, clicked);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2011-02-18 23:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Tool tool = session.getTool(player.getItemInHand());
|
|
|
|
if (tool != null && tool instanceof BlockTool) {
|
2011-05-02 00:06:40 +00:00
|
|
|
if (tool.canUse(player)) {
|
2011-11-23 01:29:48 +00:00
|
|
|
((BlockTool) tool).actPrimary(server, config, player, session, clicked);
|
2011-05-02 00:06:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-01-01 01:40:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called on left click.
|
|
|
|
*
|
|
|
|
* @param player
|
|
|
|
* @param clicked
|
|
|
|
* @return false if you want the action to go through
|
|
|
|
*/
|
2011-01-08 19:26:27 +00:00
|
|
|
public boolean handleBlockLeftClick(LocalPlayer player, WorldVector clicked) {
|
2011-01-01 18:34:36 +00:00
|
|
|
LocalSession session = getSession(player);
|
2011-01-01 01:40:07 +00:00
|
|
|
|
2011-08-06 14:22:02 +00:00
|
|
|
if (player.getItemInHand() == config.wandItem) {
|
2011-11-20 01:00:12 +00:00
|
|
|
if (!session.isToolControlEnabled()) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-08-06 14:22:02 +00:00
|
|
|
|
2011-11-20 01:00:12 +00:00
|
|
|
if (!player.hasPermission("worldedit.selection.pos")) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-08-06 14:22:02 +00:00
|
|
|
|
2011-11-20 01:00:12 +00:00
|
|
|
RegionSelector selector = session.getRegionSelector(player.getWorld());
|
|
|
|
if (selector.selectPrimary(clicked)) {
|
|
|
|
selector.explainPrimarySelection(player, session, clicked);
|
2011-08-06 14:22:02 +00:00
|
|
|
}
|
2011-11-20 01:00:12 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (player.isHoldingPickAxe() && session.hasSuperPickAxe()) {
|
|
|
|
final BlockTool superPickaxe = session.getSuperPickaxe();
|
|
|
|
if (superPickaxe != null && superPickaxe.canUse(player)) {
|
|
|
|
return superPickaxe.actPrimary(server, config, player, session, clicked);
|
2011-01-01 01:40:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-25 08:52:34 +00:00
|
|
|
Tool tool = session.getTool(player.getItemInHand());
|
|
|
|
if (tool != null && tool instanceof DoubleActionBlockTool) {
|
2011-05-02 00:06:40 +00:00
|
|
|
if (tool.canUse(player)) {
|
2011-11-23 01:29:48 +00:00
|
|
|
((DoubleActionBlockTool) tool).actSecondary(server, config, player, session, clicked);
|
2011-05-02 00:06:40 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-04-25 08:52:34 +00:00
|
|
|
}
|
|
|
|
|
2011-01-01 01:40:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-11-20 04:31:18 +00:00
|
|
|
private static final java.util.regex.Pattern numberFormatExceptionPattern = java.util.regex.Pattern.compile("^For input string: \"(.*)\"$");
|
|
|
|
|
2011-01-01 01:40:07 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param player
|
|
|
|
* @param split
|
|
|
|
* @return whether the command was processed
|
|
|
|
*/
|
2011-01-01 18:34:36 +00:00
|
|
|
public boolean handleCommand(LocalPlayer player, String[] split) {
|
2014-04-04 00:52:53 +00:00
|
|
|
Request.reset();
|
|
|
|
|
2011-01-01 01:40:07 +00:00
|
|
|
try {
|
2011-12-25 06:34:53 +00:00
|
|
|
split = commandDetection(split);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-22 07:15:19 +00:00
|
|
|
// No command found!
|
|
|
|
if (!commands.hasCommand(split[0])) {
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-22 07:15:19 +00:00
|
|
|
LocalSession session = getSession(player);
|
2011-06-04 17:30:45 +00:00
|
|
|
EditSession editSession = session.createEditSession(player);
|
2011-02-22 07:15:19 +00:00
|
|
|
editSession.enableQueue();
|
|
|
|
|
2011-06-04 17:30:45 +00:00
|
|
|
session.tellVersion(player);
|
|
|
|
|
2011-02-22 07:15:19 +00:00
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
|
|
|
try {
|
2011-12-18 07:45:12 +00:00
|
|
|
commands.execute(split, player, session, player, editSession);
|
2011-02-25 00:39:23 +00:00
|
|
|
} catch (CommandPermissionsException e) {
|
|
|
|
player.printError("You don't have permission to do this.");
|
|
|
|
} catch (MissingNestedCommandException e) {
|
|
|
|
player.printError(e.getUsage());
|
|
|
|
} catch (CommandUsageException e) {
|
|
|
|
player.printError(e.getMessage());
|
|
|
|
player.printError(e.getUsage());
|
2013-03-26 04:50:45 +00:00
|
|
|
} catch (PlayerNeededException e) {
|
|
|
|
player.printError(e.getMessage());
|
2011-02-25 00:39:23 +00:00
|
|
|
} catch (WrappedCommandException e) {
|
|
|
|
throw e.getCause();
|
|
|
|
} catch (UnhandledCommandException e) {
|
2011-12-27 00:28:51 +00:00
|
|
|
player.printError("Command could not be handled; invalid sender!");
|
2011-02-25 00:39:23 +00:00
|
|
|
return false;
|
2011-02-22 07:15:19 +00:00
|
|
|
} finally {
|
|
|
|
session.remember(editSession);
|
|
|
|
editSession.flushQueue();
|
|
|
|
|
|
|
|
if (config.profile) {
|
|
|
|
long time = System.currentTimeMillis() - start;
|
|
|
|
int changed = editSession.getBlockChangeCount();
|
|
|
|
if (time > 0) {
|
|
|
|
double throughput = changed / (time / 1000.0);
|
|
|
|
player.printDebug((time / 1000.0) + "s elapsed (history: "
|
|
|
|
+ changed + " changed; "
|
|
|
|
+ Math.round(throughput) + " blocks/sec).");
|
|
|
|
} else {
|
|
|
|
player.printDebug((time / 1000.0) + "s elapsed.");
|
2011-01-01 01:40:07 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-22 07:15:19 +00:00
|
|
|
flushBlockBag(player, editSession);
|
2011-01-01 01:40:07 +00:00
|
|
|
}
|
|
|
|
} catch (NumberFormatException e) {
|
2011-11-20 04:31:18 +00:00
|
|
|
final Matcher matcher = numberFormatExceptionPattern.matcher(e.getMessage());
|
|
|
|
|
|
|
|
if (matcher.matches()) {
|
2011-11-23 01:29:48 +00:00
|
|
|
player.printError("Number expected; string \"" + matcher.group(1) + "\" given.");
|
2011-11-20 04:31:18 +00:00
|
|
|
} else {
|
|
|
|
player.printError("Number expected; string given.");
|
|
|
|
}
|
2011-01-19 10:03:41 +00:00
|
|
|
} catch (IncompleteRegionException e) {
|
2011-01-23 18:11:12 +00:00
|
|
|
player.printError("Make a region selection first.");
|
2011-01-19 10:03:41 +00:00
|
|
|
} catch (UnknownItemException e) {
|
|
|
|
player.printError("Block name '" + e.getID() + "' was not recognized.");
|
|
|
|
} catch (InvalidItemException e) {
|
|
|
|
player.printError(e.getMessage());
|
|
|
|
} catch (DisallowedItemException e) {
|
|
|
|
player.printError("Block '" + e.getID() + "' not allowed (see WorldEdit configuration).");
|
|
|
|
} catch (MaxChangedBlocksException e) {
|
2011-01-01 01:40:07 +00:00
|
|
|
player.printError("Max blocks changed in an operation reached ("
|
2011-01-19 10:03:41 +00:00
|
|
|
+ e.getBlockLimit() + ").");
|
2013-08-03 01:33:11 +00:00
|
|
|
} catch (MaxBrushRadiusException e) {
|
2013-08-03 01:50:58 +00:00
|
|
|
player.printError("Maximum allowed brush size: " + config.maxBrushRadius);
|
2011-01-01 01:40:07 +00:00
|
|
|
} catch (MaxRadiusException e) {
|
2013-08-03 01:50:58 +00:00
|
|
|
player.printError("Maximum allowed size: " + config.maxRadius);
|
2011-01-19 10:03:41 +00:00
|
|
|
} catch (UnknownDirectionException e) {
|
|
|
|
player.printError("Unknown direction: " + e.getDirection());
|
|
|
|
} catch (InsufficientArgumentsException e) {
|
|
|
|
player.printError(e.getMessage());
|
|
|
|
} catch (EmptyClipboardException e) {
|
2011-01-23 18:11:12 +00:00
|
|
|
player.printError("Your clipboard is empty. Use //copy first.");
|
2011-01-31 04:40:22 +00:00
|
|
|
} catch (InvalidFilenameException e) {
|
|
|
|
player.printError("Filename '" + e.getFilename() + "' invalid: "
|
|
|
|
+ e.getMessage());
|
2011-01-31 06:06:06 +00:00
|
|
|
} catch (FilenameResolutionException e) {
|
|
|
|
player.printError("File '" + e.getFilename() + "' resolution error: "
|
2011-01-31 04:40:22 +00:00
|
|
|
+ e.getMessage());
|
2011-02-19 04:50:40 +00:00
|
|
|
} catch (InvalidToolBindException e) {
|
|
|
|
player.printError("Can't bind tool to "
|
|
|
|
+ ItemType.toHeldName(e.getItemId()) + ": " + e.getMessage());
|
2011-01-31 04:40:22 +00:00
|
|
|
} catch (FileSelectionAbortedException e) {
|
|
|
|
player.printError("File selection aborted.");
|
2011-01-19 10:03:41 +00:00
|
|
|
} catch (WorldEditException e) {
|
|
|
|
player.printError(e.getMessage());
|
2011-01-01 01:40:07 +00:00
|
|
|
} catch (Throwable excp) {
|
|
|
|
player.printError("Please report this error: [See console]");
|
|
|
|
player.printRaw(excp.getClass().getName() + ": " + excp.getMessage());
|
|
|
|
excp.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2012-03-10 07:11:51 +00:00
|
|
|
|
2011-12-25 06:34:53 +00:00
|
|
|
public String[] commandDetection(String[] split) {
|
2014-04-04 00:52:53 +00:00
|
|
|
Request.reset();
|
|
|
|
|
2011-12-25 06:34:53 +00:00
|
|
|
split[0] = split[0].substring(1);
|
|
|
|
|
|
|
|
// Quick script shortcut
|
|
|
|
if (split[0].matches("^[^/].*\\.js$")) {
|
|
|
|
String[] newSplit = new String[split.length + 1];
|
|
|
|
System.arraycopy(split, 0, newSplit, 1, split.length);
|
|
|
|
newSplit[0] = "cs";
|
|
|
|
newSplit[1] = newSplit[1];
|
|
|
|
split = newSplit;
|
|
|
|
}
|
|
|
|
|
|
|
|
String searchCmd = split[0].toLowerCase();
|
|
|
|
|
|
|
|
// Try to detect the command
|
|
|
|
if (commands.hasCommand(searchCmd)) {
|
|
|
|
} else if (config.noDoubleSlash && commands.hasCommand("/" + searchCmd)) {
|
|
|
|
split[0] = "/" + split[0];
|
|
|
|
} else if (split[0].length() >= 2 && split[0].charAt(0) == '/'
|
|
|
|
&& commands.hasCommand(searchCmd.substring(1))) {
|
|
|
|
split[0] = split[0].substring(1);
|
|
|
|
}
|
|
|
|
return split;
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-22 10:41:08 +00:00
|
|
|
/**
|
|
|
|
* Executes a WorldEdit script.
|
2012-03-10 07:11:51 +00:00
|
|
|
*
|
2011-01-22 10:41:08 +00:00
|
|
|
* @param player
|
2011-02-18 23:14:43 +00:00
|
|
|
* @param f
|
2011-01-22 10:41:08 +00:00
|
|
|
* @param args
|
2012-03-10 07:11:51 +00:00
|
|
|
* @throws WorldEditException
|
2011-01-22 10:41:08 +00:00
|
|
|
*/
|
2014-04-04 00:52:53 +00:00
|
|
|
public void runScript(LocalPlayer player, File f, String[] args) throws WorldEditException {
|
|
|
|
Request.reset();
|
|
|
|
|
2011-11-23 01:29:48 +00:00
|
|
|
String filename = f.getPath();
|
2011-01-22 10:41:08 +00:00
|
|
|
int index = filename.lastIndexOf(".");
|
|
|
|
String ext = filename.substring(index + 1, filename.length());
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-22 10:41:08 +00:00
|
|
|
if (!ext.equalsIgnoreCase("js")) {
|
|
|
|
player.printError("Only .js scripts are currently supported");
|
|
|
|
return;
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-22 10:41:08 +00:00
|
|
|
String script;
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-22 10:41:08 +00:00
|
|
|
try {
|
2011-01-22 21:34:05 +00:00
|
|
|
InputStream file;
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-22 21:34:05 +00:00
|
|
|
if (!f.exists()) {
|
2011-01-26 18:53:26 +00:00
|
|
|
file = WorldEdit.class.getResourceAsStream(
|
2011-01-22 21:34:05 +00:00
|
|
|
"craftscripts/" + filename);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-22 21:34:05 +00:00
|
|
|
if (file == null) {
|
|
|
|
player.printError("Script does not exist: " + filename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
file = new FileInputStream(f);
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-22 21:34:05 +00:00
|
|
|
DataInputStream in = new DataInputStream(file);
|
2011-01-22 10:41:08 +00:00
|
|
|
byte[] data = new byte[in.available()];
|
|
|
|
in.readFully(data);
|
2011-01-22 21:34:05 +00:00
|
|
|
in.close();
|
2011-01-22 10:41:08 +00:00
|
|
|
script = new String(data, 0, data.length, "utf-8");
|
|
|
|
} catch (IOException e) {
|
|
|
|
player.printError("Script read error: " + e.getMessage());
|
|
|
|
return;
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-22 21:34:05 +00:00
|
|
|
LocalSession session = getSession(player);
|
|
|
|
CraftScriptContext scriptContext =
|
2011-01-22 23:38:04 +00:00
|
|
|
new CraftScriptContext(this, server, config, session, player, args);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-22 21:34:05 +00:00
|
|
|
CraftScriptEngine engine = null;
|
2011-01-31 03:49:57 +00:00
|
|
|
|
2011-01-22 21:34:05 +00:00
|
|
|
try {
|
|
|
|
engine = new RhinoCraftScriptEngine();
|
|
|
|
} catch (NoClassDefFoundError e) {
|
2011-05-01 02:04:03 +00:00
|
|
|
player.printError("Failed to find an installed script engine.");
|
|
|
|
player.printError("Please see http://wiki.sk89q.com/wiki/WorldEdit/Installation");
|
|
|
|
return;
|
2011-01-22 10:41:08 +00:00
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 17:50:28 +00:00
|
|
|
engine.setTimeLimit(config.scriptTimeout);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-22 21:34:05 +00:00
|
|
|
Map<String, Object> vars = new HashMap<String, Object>();
|
|
|
|
vars.put("argv", args);
|
|
|
|
vars.put("context", scriptContext);
|
|
|
|
vars.put("player", player);
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-22 10:41:08 +00:00
|
|
|
try {
|
2011-01-22 21:34:05 +00:00
|
|
|
engine.evaluate(script, filename, vars);
|
2011-01-22 10:41:08 +00:00
|
|
|
} catch (ScriptException e) {
|
2011-11-23 01:29:48 +00:00
|
|
|
player.printError("Failed to execute:");
|
2011-01-22 21:34:05 +00:00
|
|
|
player.printRaw(e.getMessage());
|
2011-01-23 00:23:04 +00:00
|
|
|
e.printStackTrace();
|
2011-01-22 23:38:04 +00:00
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
throw e;
|
|
|
|
} catch (WorldEditException e) {
|
|
|
|
throw e;
|
|
|
|
} catch (Throwable e) {
|
2011-01-23 00:23:04 +00:00
|
|
|
player.printError("Failed to execute (see console):");
|
2011-01-22 23:38:04 +00:00
|
|
|
player.printRaw(e.getClass().getCanonicalName());
|
2011-01-23 00:23:04 +00:00
|
|
|
e.printStackTrace();
|
2011-01-22 10:41:08 +00:00
|
|
|
} finally {
|
2011-01-22 23:38:04 +00:00
|
|
|
for (EditSession editSession : scriptContext.getEditSessions()) {
|
2011-01-31 04:41:34 +00:00
|
|
|
editSession.flushQueue();
|
2011-01-22 10:41:08 +00:00
|
|
|
session.remember(editSession);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-29 10:05:22 +00:00
|
|
|
/**
|
|
|
|
* Get Worldedit's configuration.
|
2012-03-10 07:11:51 +00:00
|
|
|
*
|
2011-01-29 10:05:22 +00:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public LocalConfiguration getConfiguration() {
|
|
|
|
return config;
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-02-19 09:22:28 +00:00
|
|
|
/**
|
|
|
|
* Get the server interface.
|
2012-03-10 07:11:51 +00:00
|
|
|
*
|
2011-02-19 09:22:28 +00:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public ServerInterface getServer() {
|
|
|
|
return server;
|
|
|
|
}
|
2011-01-31 08:58:29 +00:00
|
|
|
|
2012-10-18 10:34:09 +00:00
|
|
|
/**
|
2014-04-03 01:57:25 +00:00
|
|
|
* Get a factory for {@link EditSession}s.
|
2012-10-18 10:34:09 +00:00
|
|
|
*/
|
|
|
|
public EditSessionFactory getEditSessionFactory() {
|
2014-04-03 01:57:25 +00:00
|
|
|
return editSessionFactory;
|
2012-10-18 10:34:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-04-03 01:57:25 +00:00
|
|
|
* @deprecated EditSessionFactories are no longer used. Please register an {@link EditSessionEvent} event
|
|
|
|
* with the event bus in order to override or catch changes to the world
|
2012-10-18 10:34:09 +00:00
|
|
|
*/
|
2014-04-03 01:57:25 +00:00
|
|
|
@Deprecated
|
2012-10-18 10:34:09 +00:00
|
|
|
public void setEditSessionFactory(EditSessionFactory factory) {
|
2014-04-03 01:57:25 +00:00
|
|
|
checkNotNull(factory);
|
|
|
|
logger.severe("Got request to set EditSessionFactory of type " +
|
|
|
|
factory.getClass().getName() + " from " + factory.getClass().getPackage().getName() +
|
|
|
|
" but EditSessionFactories have been removed in favor of extending EditSession's extents.\n\n" +
|
|
|
|
"This may mean that any block logger / intercepters addons/plugins/mods that you have installed will not " +
|
|
|
|
"intercept WorldEdit's changes! Please notify the maintainer of the other addon about this.");
|
2012-10-18 10:34:09 +00:00
|
|
|
}
|
|
|
|
|
2011-01-31 08:58:29 +00:00
|
|
|
/**
|
|
|
|
* Get the version.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static String getVersion() {
|
|
|
|
if (version != null) {
|
|
|
|
return version;
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-31 08:58:29 +00:00
|
|
|
Package p = WorldEdit.class.getPackage();
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-31 08:58:29 +00:00
|
|
|
if (p == null) {
|
|
|
|
p = Package.getPackage("com.sk89q.worldedit");
|
|
|
|
}
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-31 08:58:29 +00:00
|
|
|
if (p == null) {
|
|
|
|
version = "(unknown)";
|
|
|
|
} else {
|
|
|
|
version = p.getImplementationVersion();
|
2011-11-23 01:29:48 +00:00
|
|
|
|
2011-01-31 08:58:29 +00:00
|
|
|
if (version == null) {
|
|
|
|
version = "(unknown)";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return version;
|
|
|
|
}
|
2011-11-02 16:10:07 +00:00
|
|
|
|
|
|
|
public static void setVersion(String version) {
|
|
|
|
WorldEdit.version = version;
|
|
|
|
}
|
2011-01-01 01:40:07 +00:00
|
|
|
}
|