geforkt von Mirrors/FastAsyncWorldEdit
Port scripting commands
Dieser Commit ist enthalten in:
Ursprung
f81ffdde0c
Commit
c95fc06b82
@ -19,23 +19,28 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.command;
|
package com.sk89q.worldedit.command;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
import static com.sk89q.worldedit.command.util.Logging.LogMode.ALL;
|
|
||||||
|
|
||||||
import com.sk89q.minecraft.util.commands.Command;
|
|
||||||
import com.sk89q.minecraft.util.commands.CommandContext;
|
|
||||||
import com.sk89q.minecraft.util.commands.CommandPermissions;
|
|
||||||
import com.sk89q.worldedit.LocalSession;
|
import com.sk89q.worldedit.LocalSession;
|
||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import com.sk89q.worldedit.WorldEditException;
|
import com.sk89q.worldedit.WorldEditException;
|
||||||
|
import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||||
|
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
||||||
import com.sk89q.worldedit.command.util.Logging;
|
import com.sk89q.worldedit.command.util.Logging;
|
||||||
import com.sk89q.worldedit.entity.Player;
|
import com.sk89q.worldedit.entity.Player;
|
||||||
|
import org.enginehub.piston.annotation.Command;
|
||||||
|
import org.enginehub.piston.annotation.CommandContainer;
|
||||||
|
import org.enginehub.piston.annotation.param.Arg;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.ALL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commands related to scripting.
|
* Commands related to scripting.
|
||||||
*/
|
*/
|
||||||
|
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
|
||||||
public class ScriptingCommands {
|
public class ScriptingCommands {
|
||||||
|
|
||||||
private final WorldEdit worldEdit;
|
private final WorldEdit worldEdit;
|
||||||
@ -51,42 +56,39 @@ public class ScriptingCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "cs" },
|
name = "cs",
|
||||||
usage = "<filename> [args...]",
|
desc = "Execute a CraftScript"
|
||||||
desc = "Execute a CraftScript",
|
|
||||||
min = 1,
|
|
||||||
max = -1
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.scripting.execute")
|
@CommandPermissions("worldedit.scripting.execute")
|
||||||
@Logging(ALL)
|
@Logging(ALL)
|
||||||
public void execute(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
public void execute(Player player, LocalSession session,
|
||||||
|
@Arg(desc = "Filename of the CraftScript to load")
|
||||||
String[] scriptArgs = args.getSlice(1);
|
String filename,
|
||||||
String name = args.getString(0);
|
@Arg(desc = "Arguments to the CraftScript", def = "", variable = true)
|
||||||
|
List<String> args) throws WorldEditException {
|
||||||
if (!player.hasPermission("worldedit.scripting.execute." + name)) {
|
if (!player.hasPermission("worldedit.scripting.execute." + filename)) {
|
||||||
player.printError("You don't have permission to use that script.");
|
player.printError("You don't have permission to use that script.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
session.setLastScript(name);
|
session.setLastScript(filename);
|
||||||
|
|
||||||
File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir);
|
File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir);
|
||||||
File f = worldEdit.getSafeOpenFile(player, dir, name, "js", "js");
|
File f = worldEdit.getSafeOpenFile(player, dir, filename, "js", "js");
|
||||||
|
|
||||||
worldEdit.runScript(player, f, scriptArgs);
|
worldEdit.runScript(player, f, Stream.concat(Stream.of(filename), args.stream())
|
||||||
|
.toArray(String[]::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { ".s" },
|
name = ".s",
|
||||||
usage = "[args...]",
|
desc = "Execute last CraftScript"
|
||||||
desc = "Execute last CraftScript",
|
|
||||||
min = 0,
|
|
||||||
max = -1
|
|
||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.scripting.execute")
|
@CommandPermissions("worldedit.scripting.execute")
|
||||||
@Logging(ALL)
|
@Logging(ALL)
|
||||||
public void executeLast(Player player, LocalSession session, CommandContext args) throws WorldEditException {
|
public void executeLast(Player player, LocalSession session,
|
||||||
|
@Arg(desc = "Arguments to the CraftScript", def = "", variable = true)
|
||||||
|
List<String> args) throws WorldEditException {
|
||||||
|
|
||||||
String lastScript = session.getLastScript();
|
String lastScript = session.getLastScript();
|
||||||
|
|
||||||
@ -100,11 +102,10 @@ public class ScriptingCommands {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] scriptArgs = args.getSlice(0);
|
|
||||||
|
|
||||||
File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir);
|
File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir);
|
||||||
File f = worldEdit.getSafeOpenFile(player, dir, lastScript, "js", "js");
|
File f = worldEdit.getSafeOpenFile(player, dir, lastScript, "js", "js");
|
||||||
|
|
||||||
worldEdit.runScript(player, f, scriptArgs);
|
worldEdit.runScript(player, f, Stream.concat(Stream.of(lastScript), args.stream())
|
||||||
|
.toArray(String[]::new));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,8 @@ import com.sk89q.worldedit.command.RegionCommands;
|
|||||||
import com.sk89q.worldedit.command.RegionCommandsRegistration;
|
import com.sk89q.worldedit.command.RegionCommandsRegistration;
|
||||||
import com.sk89q.worldedit.command.SchematicCommands;
|
import com.sk89q.worldedit.command.SchematicCommands;
|
||||||
import com.sk89q.worldedit.command.SchematicCommandsRegistration;
|
import com.sk89q.worldedit.command.SchematicCommandsRegistration;
|
||||||
|
import com.sk89q.worldedit.command.ScriptingCommands;
|
||||||
|
import com.sk89q.worldedit.command.ScriptingCommandsRegistration;
|
||||||
import com.sk89q.worldedit.command.argument.Arguments;
|
import com.sk89q.worldedit.command.argument.Arguments;
|
||||||
import com.sk89q.worldedit.command.argument.CommaSeparatedValuesConverter;
|
import com.sk89q.worldedit.command.argument.CommaSeparatedValuesConverter;
|
||||||
import com.sk89q.worldedit.command.argument.DirectionConverter;
|
import com.sk89q.worldedit.command.argument.DirectionConverter;
|
||||||
@ -298,13 +300,17 @@ public final class PlatformCommandMananger {
|
|||||||
RegionCommandsRegistration.builder(),
|
RegionCommandsRegistration.builder(),
|
||||||
new RegionCommands()
|
new RegionCommands()
|
||||||
);
|
);
|
||||||
|
register(
|
||||||
|
commandManager,
|
||||||
|
ScriptingCommandsRegistration.builder(),
|
||||||
|
new ScriptingCommands(worldEdit)
|
||||||
|
);
|
||||||
|
|
||||||
// Unported commands are below. Delete once they're added to the main manager above.
|
// Unported commands are below. Delete once they're added to the main manager above.
|
||||||
/*
|
/*
|
||||||
dispatcher = new CommandGraph()
|
dispatcher = new CommandGraph()
|
||||||
.builder(builder)
|
.builder(builder)
|
||||||
.commands()
|
.commands()
|
||||||
.registerMethods(new ScriptingCommands(worldEdit))
|
|
||||||
.registerMethods(new SelectionCommands(worldEdit))
|
.registerMethods(new SelectionCommands(worldEdit))
|
||||||
.registerMethods(new SnapshotUtilCommands(worldEdit))
|
.registerMethods(new SnapshotUtilCommands(worldEdit))
|
||||||
.registerMethods(new ToolUtilCommands(worldEdit))
|
.registerMethods(new ToolUtilCommands(worldEdit))
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren