mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 02:46:41 +00:00
some bindings
This commit is contained in:
@ -30,7 +30,6 @@ import com.sk89q.worldedit.function.mask.Mask;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
import com.sk89q.worldedit.util.HandSide;
|
||||
import com.sk89q.worldedit.internal.annotation.Range;
|
||||
import com.sk89q.worldedit.util.command.parametric.Optional;
|
||||
import org.enginehub.piston.annotation.param.Arg;
|
||||
import org.enginehub.piston.annotation.param.Switch;
|
||||
|
||||
@ -48,7 +47,7 @@ import java.util.zip.GZIPInputStream;
|
||||
* Tool commands.
|
||||
*/
|
||||
|
||||
@Command(aliases = {"brush", "br", "/b"}, desc = "Tool commands")
|
||||
//@Command(aliases = {"brush", "br", "/b"}, desc = "Tool commands")
|
||||
public class BrushOptionsCommands extends MethodCommands {
|
||||
|
||||
public BrushOptionsCommands(WorldEdit we) {
|
||||
|
@ -35,24 +35,26 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Command(aliases = {"patterns"},
|
||||
desc = "Help for the various patterns. [More Info](https://git.io/vSPmA)",
|
||||
descFooter = "Patterns determine what blocks are placed\n" +
|
||||
" - Use [brackets] for arguments\n" +
|
||||
" - Use , to OR multiple\n" +
|
||||
"e.g. #surfacespread[10][#existing],andesite\n" +
|
||||
"More Info: https://git.io/vSPmA"
|
||||
)
|
||||
//@Command(aliases = {"patterns"},
|
||||
// desc = "Help for the various patterns. [More Info](https://git.io/vSPmA)",
|
||||
// descFooter = "Patterns determine what blocks are placed\n" +
|
||||
// " - Use [brackets] for arguments\n" +
|
||||
// " - Use , to OR multiple\n" +
|
||||
// "e.g. #surfacespread[10][#existing],andesite\n" +
|
||||
// "More Info: https://git.io/vSPmA"
|
||||
//)
|
||||
public class PatternCommands extends MethodCommands {
|
||||
private final WorldEdit worldEdit;
|
||||
|
||||
public PatternCommands(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
this.worldEdit = worldEdit;
|
||||
}
|
||||
|
||||
@Command(
|
||||
name = "#existing",
|
||||
aliases = {"#*", "*", ".*"},
|
||||
desc = "Use the block that is already there",
|
||||
usage = "[properties]"
|
||||
descFooter = "[properties]"
|
||||
)
|
||||
public Pattern existing(Extent extent, @Arg(name = "properties", desc = "String", def = "") String properties) { // TODO FIXME , @Arg(name = "properties", desc = "String", def = "") String properties
|
||||
if (properties == null) return new ExistingPattern(extent);
|
||||
@ -73,7 +75,7 @@ public class PatternCommands extends MethodCommands {
|
||||
name = "#simplex",
|
||||
desc = "Use simplex noise to randomize blocks. Tutorial: https://imgur.com/a/rwVAE"
|
||||
)
|
||||
public Pattern simplex(@Arg() double scale, Pattern other) {
|
||||
public Pattern simplex(@Arg(desc = "scale factor") double scale, Pattern other) {
|
||||
if (other instanceof RandomPattern) {
|
||||
scale = (1d / Math.max(1, scale));
|
||||
RandomCollection<Pattern> collection = ((RandomPattern) other).getCollection();
|
||||
@ -282,8 +284,7 @@ public class PatternCommands extends MethodCommands {
|
||||
desc = "Apply a pattern depending on a mask"
|
||||
)
|
||||
public Pattern mask(Actor actor, LocalSession session, Mask mask, Pattern pass, Pattern fail) {
|
||||
PatternExtent extent = new PatternExtent(pass);
|
||||
return new MaskedPattern(mask, extent, fail);
|
||||
return new MaskedPattern(mask, pass, fail);
|
||||
}
|
||||
|
||||
@Command(
|
||||
|
@ -81,111 +81,20 @@ public class ScriptingCommands {
|
||||
)
|
||||
@CommandPermissions("fawe.setupdispatcher")
|
||||
public void setupdispatcher(Player player, LocalSession session, final InjectedValueAccess args) throws WorldEditException {
|
||||
PlatformCommandManager.getInstance().setupDispatcher();
|
||||
}
|
||||
|
||||
public static <T> T runScript(Player player, File f, String[] args) throws WorldEditException {
|
||||
return runScript(player, f, args, null);
|
||||
}
|
||||
|
||||
public static <T> T runScript(Actor actor, File f, String[] args, @Nullable Function<String, String> processor) throws WorldEditException {
|
||||
String filename = f.getPath();
|
||||
int index = filename.lastIndexOf(".");
|
||||
String ext = filename.substring(index + 1, filename.length());
|
||||
|
||||
if (!ext.equalsIgnoreCase("js")) {
|
||||
actor.printError("Only .js scripts are currently supported");
|
||||
return null;
|
||||
}
|
||||
|
||||
String script;
|
||||
|
||||
try {
|
||||
InputStream file;
|
||||
|
||||
if (!f.exists()) {
|
||||
file = WorldEdit.class.getResourceAsStream("craftscripts/" + filename);
|
||||
|
||||
if (file == null) {
|
||||
actor.printError("Script does not exist: " + filename);
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
file = new FileInputStream(f);
|
||||
}
|
||||
|
||||
DataInputStream in = new DataInputStream(file);
|
||||
byte[] data = new byte[in.available()];
|
||||
in.readFully(data);
|
||||
in.close();
|
||||
script = new String(data, 0, data.length, StandardCharsets.UTF_8);
|
||||
} catch (IOException e) {
|
||||
actor.printError("Script read error: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
if (processor != null) {
|
||||
script = processor.apply(script);
|
||||
}
|
||||
|
||||
WorldEdit worldEdit = WorldEdit.getInstance();
|
||||
LocalSession session = worldEdit.getSessionManager().get(actor);
|
||||
|
||||
CraftScriptEngine engine = null;
|
||||
|
||||
Object result = null;
|
||||
try {
|
||||
|
||||
engine = new RhinoCraftScriptEngine();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
actor.printError("Failed to find an installed script engine.");
|
||||
actor.printError("Download: https://github.com/downloads/mozilla/rhino/rhino1_7R4.zip");
|
||||
actor.printError("Extract: `js.jar` to `plugins` or `mods` directory`");
|
||||
actor.printError("More info: https://github.com/boy0001/CraftScripts/");
|
||||
return null;
|
||||
}
|
||||
|
||||
engine.setTimeLimit(worldEdit.getConfiguration().scriptTimeout);
|
||||
|
||||
Player player = actor instanceof Player ? (Player) actor : null;
|
||||
CraftScriptContext scriptContext = new CraftScriptContext(worldEdit, WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.USER_COMMANDS),
|
||||
WorldEdit.getInstance().getConfiguration(), session, player, args);
|
||||
|
||||
Map<String, Object> vars = new HashMap<>();
|
||||
vars.put("argv", args);
|
||||
vars.put("context", scriptContext);
|
||||
vars.put("actor", actor);
|
||||
vars.put("player", player);
|
||||
|
||||
try {
|
||||
result = engine.evaluate(script, filename, vars);
|
||||
} catch (ScriptException e) {
|
||||
e.printStackTrace();
|
||||
actor.printError("Failed to execute:");
|
||||
actor.printRaw(e.getMessage());
|
||||
} catch (NumberFormatException | WorldEditException e) {
|
||||
throw e;
|
||||
} catch (Throwable e) {
|
||||
actor.printError("Failed to execute (see console):");
|
||||
actor.printRaw(e.getClass().getCanonicalName());
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (result instanceof NativeJavaObject) {
|
||||
return (T) ((NativeJavaObject) result).unwrap();
|
||||
}
|
||||
return (T) result;
|
||||
PlatformCommandManager.getInstance().registerAllCommands();
|
||||
}
|
||||
|
||||
@Command(
|
||||
name = "cs",
|
||||
desc = "Execute a CraftScript"
|
||||
name = "cs",
|
||||
desc = "Execute a CraftScript"
|
||||
)
|
||||
@CommandPermissions("worldedit.scripting.execute")
|
||||
@Logging(ALL)
|
||||
public void execute(Player player, LocalSession session, InjectedValueAccess args) throws WorldEditException {
|
||||
final String[] scriptArgs = args.getSlice(1);
|
||||
final String filename = args.getString(0);
|
||||
|
||||
public void execute(Player player, LocalSession session,
|
||||
@Arg(desc = "Filename of the CraftScript to load")
|
||||
String filename,
|
||||
@Arg(desc = "Arguments to the CraftScript", def = "", variable = true)
|
||||
List<String> args) throws WorldEditException {
|
||||
if (!player.hasPermission("worldedit.scripting.execute." + filename)) {
|
||||
BBC.SCRIPTING_NO_PERM.send(player);
|
||||
return;
|
||||
@ -195,27 +104,20 @@ public class ScriptingCommands {
|
||||
|
||||
File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir);
|
||||
File f = worldEdit.getSafeOpenFile(player, dir, filename, "js", "js");
|
||||
try {
|
||||
new RhinoCraftScriptEngine();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
player.printError("Failed to find an installed script engine.");
|
||||
player.printError("Download: https://github.com/downloads/mozilla/rhino/rhino1_7R4.zip");
|
||||
player.printError("Extract: `js.jar` to `plugins` or `mods` directory`");
|
||||
player.printError("More info: https://github.com/boy0001/CraftScripts/");
|
||||
return;
|
||||
}
|
||||
runScript(LocationMaskedPlayerWrapper.unwrap(player), f, scriptArgs);
|
||||
|
||||
worldEdit.runScript(player, f, Stream.concat(Stream.of(filename), args.stream())
|
||||
.toArray(String[]::new));
|
||||
}
|
||||
|
||||
@Command(
|
||||
name = ".s",
|
||||
desc = "Execute last CraftScript"
|
||||
name = ".s",
|
||||
desc = "Execute last CraftScript"
|
||||
)
|
||||
@CommandPermissions("worldedit.scripting.execute")
|
||||
@Logging(ALL)
|
||||
public void executeLast(Player player, LocalSession session,
|
||||
@Arg(desc = "Arguments to the CraftScript", def = "", variable = true)
|
||||
List<String> args) throws WorldEditException {
|
||||
List<String> args) throws WorldEditException {
|
||||
|
||||
String lastScript = session.getLastScript();
|
||||
|
||||
@ -233,6 +135,6 @@ public class ScriptingCommands {
|
||||
File f = worldEdit.getSafeOpenFile(player, dir, lastScript, "js", "js");
|
||||
|
||||
worldEdit.runScript(player, f, Stream.concat(Stream.of(lastScript), args.stream())
|
||||
.toArray(String[]::new));
|
||||
.toArray(String[]::new));
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ import java.util.List;
|
||||
* Snapshot commands.
|
||||
*/
|
||||
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
|
||||
@Command(aliases = {"snapshot", "snap"}, desc = "List, load and view information related to snapshots")
|
||||
//@Command(aliases = {"snapshot", "snap"}, desc = "List, load and view information related to snapshots")
|
||||
public class SnapshotCommands {
|
||||
|
||||
private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
|
||||
@ -205,7 +205,7 @@ public class SnapshotCommands {
|
||||
|
||||
if (snapshot == null) {
|
||||
player.printError("Couldn't find a snapshot before "
|
||||
+ dateFormat.withZone(session.getTimeZone().toZoneId()).format(date) + ".");
|
||||
+ dateFormat.withZone(session.getTimeZone()).format(date) + ".");
|
||||
} else {
|
||||
session.setSnapshot(snapshot);
|
||||
BBC.SNAPSHOT_SET.send(player, snapshot.getName());
|
||||
@ -235,7 +235,7 @@ public class SnapshotCommands {
|
||||
Snapshot snapshot = config.snapshotRepo.getSnapshotAfter(date, player.getWorld().getName());
|
||||
if (snapshot == null) {
|
||||
player.printError("Couldn't find a snapshot after "
|
||||
+ dateFormat.withZone(session.getTimeZone().toZoneId()).format(date) + ".");
|
||||
+ dateFormat.withZone(session.getTimeZone()).format(date) + ".");
|
||||
} else {
|
||||
session.setSnapshot(snapshot);
|
||||
BBC.SNAPSHOT_SET.send(player, snapshot.getName());
|
||||
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.command;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import org.enginehub.piston.annotation.Command;
|
||||
import org.enginehub.piston.annotation.param.Arg;
|
||||
import org.enginehub.piston.inject.InjectedValueAccess;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
@ -32,7 +33,7 @@ import com.sk89q.worldedit.command.tool.RecursivePickaxe;
|
||||
import com.sk89q.worldedit.command.tool.SinglePickaxe;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
|
||||
@Command(aliases = {"superpickaxe", "pickaxe", "sp"}, desc = "Super-pickaxe commands: [More Info](https://goo.gl/aBtGHo)")
|
||||
//@Command(aliases = {"superpickaxe", "pickaxe", "sp"}, desc = "Super-pickaxe commands: [More Info](https://goo.gl/aBtGHo)")
|
||||
public class SuperPickaxeCommands {
|
||||
private final WorldEdit we;
|
||||
|
||||
@ -56,10 +57,11 @@ public class SuperPickaxeCommands {
|
||||
desc = "Enable the area super pickaxe pickaxe mode"
|
||||
)
|
||||
@CommandPermissions("worldedit.superpickaxe.area")
|
||||
public void area(Player player, LocalSession session, InjectedValueAccess args) throws WorldEditException {
|
||||
public void area(Player player, LocalSession session,
|
||||
@Arg(desc = "The range of the area pickaxe")
|
||||
int range) throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
int range = args.getInteger(0);
|
||||
|
||||
if (range > config.maxSuperPickaxeSize) {
|
||||
BBC.TOOL_RANGE_ERROR.send(player, config.maxSuperPickaxeSize);
|
||||
@ -77,10 +79,11 @@ public class SuperPickaxeCommands {
|
||||
desc = "Enable the recursive super pickaxe pickaxe mode"
|
||||
)
|
||||
@CommandPermissions("worldedit.superpickaxe.recursive")
|
||||
public void recursive(Player player, LocalSession session, InjectedValueAccess args) throws WorldEditException {
|
||||
public void recursive(Player player, LocalSession session,
|
||||
@Arg(desc = "The range of the recursive pickaxe")
|
||||
double range) throws WorldEditException {
|
||||
|
||||
LocalConfiguration config = we.getConfiguration();
|
||||
double range = args.getDouble(0);
|
||||
|
||||
if (range > config.maxSuperPickaxeSize) {
|
||||
BBC.TOOL_RANGE_ERROR.send(player, config.maxSuperPickaxeSize);
|
||||
|
Reference in New Issue
Block a user