geforkt von Mirrors/FastAsyncWorldEdit
Removed scripting support.
Dieser Commit ist enthalten in:
Ursprung
a4eb7727cb
Commit
aea64916e3
@ -1,3 +1,3 @@
|
|||||||
Manifest-Version: 1.0
|
Manifest-Version: 1.0
|
||||||
Class-Path: smalljs.jar jnbt.jar
|
Class-Path: jnbt.jar
|
||||||
|
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
// $Id$
|
|
||||||
/*
|
|
||||||
* WorldEdit
|
|
||||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
|
||||||
public class ScriptContext {
|
|
||||||
public ScriptPlayer player;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs the context. A player object has to be passed.
|
|
||||||
*
|
|
||||||
* @param player
|
|
||||||
*/
|
|
||||||
public ScriptContext(ScriptPlayer player) {
|
|
||||||
this.player = player;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints a message to the player.
|
|
||||||
*
|
|
||||||
* @param msg
|
|
||||||
*/
|
|
||||||
public void print(String msg) {
|
|
||||||
player.print(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints an error message to the player.
|
|
||||||
*
|
|
||||||
* @param msg
|
|
||||||
*/
|
|
||||||
public void error(String msg) {
|
|
||||||
player.error(msg);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,65 +0,0 @@
|
|||||||
|
|
||||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
|
||||||
|
|
||||||
// $Id$
|
|
||||||
/*
|
|
||||||
* WorldEdit
|
|
||||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Albert
|
|
||||||
*/
|
|
||||||
public class ScriptMinecraftContext {
|
|
||||||
private EditSession editSession;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Construct this Minecraft object with an EditSession.
|
|
||||||
*
|
|
||||||
* @param editSession
|
|
||||||
*/
|
|
||||||
public ScriptMinecraftContext(EditSession editSession) {
|
|
||||||
this.editSession = editSession;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the block at position x, y, z with a block type.
|
|
||||||
*
|
|
||||||
* @param x
|
|
||||||
* @param y
|
|
||||||
* @param z
|
|
||||||
* @param blockType
|
|
||||||
* @throws MaxChangedBlocksException
|
|
||||||
* @return whether the block was changed
|
|
||||||
*/
|
|
||||||
public boolean setBlock(int x, int y, int z, int blockType)
|
|
||||||
throws MaxChangedBlocksException {
|
|
||||||
return editSession.setBlock(x, y, z, blockType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the block type at a position x, y, z.
|
|
||||||
*
|
|
||||||
* @param x
|
|
||||||
* @param y
|
|
||||||
* @param z
|
|
||||||
* @return block type ID
|
|
||||||
*/
|
|
||||||
public int getBlock(int x, int y, int z) {
|
|
||||||
return editSession.getBlock(x, y, z);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,75 +0,0 @@
|
|||||||
// $Id$
|
|
||||||
/*
|
|
||||||
* WorldEdit
|
|
||||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import com.sk89q.worldedit.Point;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author sk89q
|
|
||||||
*/
|
|
||||||
public class ScriptPlayer {
|
|
||||||
private WorldEditPlayer player;
|
|
||||||
|
|
||||||
public String name;
|
|
||||||
public double pitch;
|
|
||||||
public double yaw;
|
|
||||||
public double x;
|
|
||||||
public double y;
|
|
||||||
public double z;
|
|
||||||
public int blockX;
|
|
||||||
public int blockY;
|
|
||||||
public int blockZ;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs the player instance.
|
|
||||||
*
|
|
||||||
* @param player
|
|
||||||
*/
|
|
||||||
public ScriptPlayer(WorldEditPlayer player) {
|
|
||||||
this.player = player;
|
|
||||||
name = player.getName();
|
|
||||||
pitch = player.getPitch();
|
|
||||||
yaw = player.getYaw();
|
|
||||||
Point pos = player.getPosition();
|
|
||||||
x = pos.getX();
|
|
||||||
y = pos.getY();
|
|
||||||
z = pos.getZ();
|
|
||||||
blockX = pos.getBlockX();
|
|
||||||
blockY = pos.getBlockY();
|
|
||||||
blockZ = pos.getBlockZ();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints a message to the player.
|
|
||||||
*
|
|
||||||
* @param msg
|
|
||||||
*/
|
|
||||||
public void print(String msg) {
|
|
||||||
player.print(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints an error message to the player.
|
|
||||||
*
|
|
||||||
* @param msg
|
|
||||||
*/
|
|
||||||
public void error(String msg) {
|
|
||||||
player.printError(msg);
|
|
||||||
}
|
|
||||||
}
|
|
@ -22,7 +22,6 @@ import java.util.logging.Level;
|
|||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import org.mozilla.javascript.*;
|
|
||||||
import com.sk89q.worldedit.*;
|
import com.sk89q.worldedit.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,7 +42,6 @@ public class WorldEdit extends Plugin {
|
|||||||
private PropertiesFile properties;
|
private PropertiesFile properties;
|
||||||
private String[] allowedBlocks;
|
private String[] allowedBlocks;
|
||||||
private int defaultMaxBlocksChanged;
|
private int defaultMaxBlocksChanged;
|
||||||
private boolean mapScriptCommands = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an instance of the plugin.
|
* Construct an instance of the plugin.
|
||||||
@ -74,7 +72,6 @@ public class WorldEdit extends Plugin {
|
|||||||
commands.put("/editsave", "[Filename] - Save clipboard to .schematic");
|
commands.put("/editsave", "[Filename] - Save clipboard to .schematic");
|
||||||
commands.put("/editfill", "[ID] [Radius] <Depth> - Fill a hole");
|
commands.put("/editfill", "[ID] [Radius] <Depth> - Fill a hole");
|
||||||
commands.put("/editdrain", "[Radius] - Drain nearby water/lava pools");
|
commands.put("/editdrain", "[Radius] - Drain nearby water/lava pools");
|
||||||
commands.put("/editscript", "[Filename] <Args...> - Run a WorldEdit script");
|
|
||||||
commands.put("/editlimit", "[Num] - See documentation");
|
commands.put("/editlimit", "[Num] - See documentation");
|
||||||
commands.put("/unstuck", "Go up to the first free spot");
|
commands.put("/unstuck", "Go up to the first free spot");
|
||||||
}
|
}
|
||||||
@ -186,7 +183,6 @@ public class WorldEdit extends Plugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
allowedBlocks = properties.getString("allowed-blocks", DEFAULT_ALLOWED_BLOCKS).split(",");
|
allowedBlocks = properties.getString("allowed-blocks", DEFAULT_ALLOWED_BLOCKS).split(",");
|
||||||
mapScriptCommands = properties.getBoolean("map-script-commands", true);
|
|
||||||
defaultMaxBlocksChanged =
|
defaultMaxBlocksChanged =
|
||||||
Math.max(-1, properties.getInt("max-blocks-changed", -1));
|
Math.max(-1, properties.getInt("max-blocks-changed", -1));
|
||||||
|
|
||||||
@ -287,28 +283,6 @@ public class WorldEdit extends Plugin {
|
|||||||
editSession.flushQueue();
|
editSession.flushQueue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// See if there is a script by the same name
|
|
||||||
if (mapScriptCommands && modPlayer.canUseCommand("/editscript")) {
|
|
||||||
WorldEditPlayer player = new WorldEditPlayer(modPlayer);
|
|
||||||
WorldEditSession session = getSession(player);
|
|
||||||
EditSession editSession =
|
|
||||||
new EditSession(session.getBlockChangeLimit());
|
|
||||||
editSession.enableQueue();
|
|
||||||
|
|
||||||
String filename = split[0].substring(1) + ".js";
|
|
||||||
String[] args = new String[split.length - 1];
|
|
||||||
System.arraycopy(split, 1, args, 0, split.length - 1);
|
|
||||||
|
|
||||||
try {
|
|
||||||
return runScript(player, session, editSession, filename, args);
|
|
||||||
} catch (NoSuchScriptException nse) {
|
|
||||||
return false;
|
|
||||||
} finally {
|
|
||||||
session.remember(editSession);
|
|
||||||
editSession.flushQueue();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -540,18 +514,7 @@ public class WorldEdit extends Plugin {
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Run a script
|
// Get size
|
||||||
} else if (split[0].equalsIgnoreCase("/editscript")) {
|
|
||||||
checkArgs(split, 1, -1, split[0]);
|
|
||||||
String filename = split[1].replace("\0", "") + ".js";
|
|
||||||
String[] args = new String[split.length - 2];
|
|
||||||
System.arraycopy(split, 2, args, 0, split.length - 2);
|
|
||||||
try {
|
|
||||||
runScript(player, session, editSession, filename, args);
|
|
||||||
} catch (NoSuchScriptException e) {
|
|
||||||
player.printError("Script file does not exist.");
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else if (split[0].equalsIgnoreCase("/editsize")) {
|
} else if (split[0].equalsIgnoreCase("/editsize")) {
|
||||||
player.print("# of blocks: " + session.getRegion().getSize());
|
player.print("# of blocks: " + session.getRegion().getSize());
|
||||||
return true;
|
return true;
|
||||||
@ -675,87 +638,6 @@ public class WorldEdit extends Plugin {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute a script.
|
|
||||||
*
|
|
||||||
* @param player
|
|
||||||
* @param filename
|
|
||||||
* @param args
|
|
||||||
* @return Whether the file was attempted execution
|
|
||||||
*/
|
|
||||||
private boolean runScript(WorldEditPlayer player, WorldEditSession session,
|
|
||||||
EditSession editSession, String filename, String[] args) throws
|
|
||||||
NoSuchScriptException {
|
|
||||||
File dir = new File("editscripts");
|
|
||||||
File f = new File("editscripts", filename);
|
|
||||||
|
|
||||||
try {
|
|
||||||
String filePath = f.getCanonicalPath();
|
|
||||||
String dirPath = dir.getCanonicalPath();
|
|
||||||
|
|
||||||
if (!filePath.substring(0, dirPath.length()).equals(dirPath)) {
|
|
||||||
throw new NoSuchScriptException();
|
|
||||||
} else if (!f.exists()) {
|
|
||||||
throw new NoSuchScriptException();
|
|
||||||
} else {
|
|
||||||
// Read file
|
|
||||||
StringBuffer buffer = new StringBuffer();
|
|
||||||
FileInputStream stream = new FileInputStream(f);
|
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(stream, "UTF-8"));
|
|
||||||
int c;
|
|
||||||
while ((c = in.read()) > -1) {
|
|
||||||
buffer.append((char)c);
|
|
||||||
}
|
|
||||||
in.close();
|
|
||||||
String code = buffer.toString();
|
|
||||||
|
|
||||||
// Evaluate
|
|
||||||
ScriptContextFactory factory = new ScriptContextFactory();
|
|
||||||
Context cx = factory.enterContext();
|
|
||||||
try {
|
|
||||||
ScriptableObject scope = cx.initStandardObjects();
|
|
||||||
|
|
||||||
// Add args
|
|
||||||
ScriptableObject.putProperty(scope, "args",
|
|
||||||
Context.javaToJS(args, scope));
|
|
||||||
|
|
||||||
// Add context
|
|
||||||
ScriptPlayer scriptPlayer = new ScriptPlayer(player);
|
|
||||||
ScriptContext context = new ScriptContext(
|
|
||||||
scriptPlayer);
|
|
||||||
ScriptableObject.putProperty(scope, "context",
|
|
||||||
Context.javaToJS(context, scope));
|
|
||||||
ScriptableObject.putProperty(scope, "player",
|
|
||||||
Context.javaToJS(scriptPlayer, scope));
|
|
||||||
|
|
||||||
// Add Minecraft context
|
|
||||||
ScriptMinecraftContext minecraft =
|
|
||||||
new ScriptMinecraftContext(editSession);
|
|
||||||
ScriptableObject.putProperty(scope, "minecraft",
|
|
||||||
Context.javaToJS(minecraft, scope));
|
|
||||||
|
|
||||||
logger.log(Level.INFO, player.getName() + ": executing " + filename + "...");
|
|
||||||
cx.evaluateString(scope, code, filename, 1, null);
|
|
||||||
logger.log(Level.INFO, player.getName() + ": script " + filename + " executed successfully.");
|
|
||||||
player.print(filename + " executed successfully.");
|
|
||||||
} catch (RhinoException re) {
|
|
||||||
player.printError(filename + ": JS error: " + re.getMessage());
|
|
||||||
re.printStackTrace();
|
|
||||||
} catch (Error err) {
|
|
||||||
player.printError(filename + ": execution error: " + err.getMessage());
|
|
||||||
} finally {
|
|
||||||
Context.exit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
} catch (IOException e) {
|
|
||||||
player.printError("Script could not read or it does not exist.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the block type at a position x, y, z. Use an instance of
|
* Gets the block type at a position x, y, z. Use an instance of
|
||||||
* EditSession if possible.
|
* EditSession if possible.
|
||||||
|
@ -1,69 +0,0 @@
|
|||||||
// $Id$
|
|
||||||
/*
|
|
||||||
* WorldEdit
|
|
||||||
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.sk89q.worldedit;
|
|
||||||
|
|
||||||
import org.mozilla.javascript.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Context factory for the JavaScript engine.
|
|
||||||
*
|
|
||||||
* @author Albert
|
|
||||||
*/
|
|
||||||
public class ScriptContextFactory extends ContextFactory {
|
|
||||||
/**
|
|
||||||
* Context that will be used to store start time.
|
|
||||||
*/
|
|
||||||
private static class ScriptContext extends Context {
|
|
||||||
long startTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
static {
|
|
||||||
ContextFactory.initGlobal(new ScriptContextFactory());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Context makeContext()
|
|
||||||
{
|
|
||||||
ScriptContext ctx = new ScriptContext();
|
|
||||||
ctx.setInstructionObserverThreshold(10000);
|
|
||||||
return ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void observeInstructionCount(Context ctx, int instructionCount)
|
|
||||||
{
|
|
||||||
ScriptContext sctx = (ScriptContext)ctx;
|
|
||||||
long currentTime = System.currentTimeMillis();
|
|
||||||
if (currentTime - sctx.startTime > 3 * 1000) {
|
|
||||||
throw new Error("Exceeded 3 seconds");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Object doTopCall(Callable callable,
|
|
||||||
Context ctx, Scriptable scope,
|
|
||||||
Scriptable thisObj, Object[] args)
|
|
||||||
{
|
|
||||||
ScriptContext sctx = (ScriptContext)ctx;
|
|
||||||
sctx.startTime = System.currentTimeMillis();
|
|
||||||
return super.doTopCall(callable, ctx, scope, thisObj, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren