2014-04-03 02:08:50 +00:00
|
|
|
/*
|
2014-04-04 22:03:18 +00:00
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
2014-04-03 02:08:50 +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
|
2014-04-03 02:08:50 +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.
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2014-04-04 22:03:18 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-04-03 02:08:50 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2014-04-04 22:03:18 +00:00
|
|
|
*/
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
package com.sk89q.worldedit.command;
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
|
|
|
import static com.sk89q.worldedit.command.util.Logging.LogMode.ALL;
|
|
|
|
|
2019-04-06 23:13:23 +00:00
|
|
|
import com.boydti.fawe.config.BBC;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.LocalSession;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissions;
|
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
|
|
|
import com.sk89q.worldedit.command.util.Logging;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.stream.Stream;
|
|
|
|
import org.enginehub.piston.annotation.Command;
|
|
|
|
import org.enginehub.piston.annotation.CommandContainer;
|
|
|
|
import org.enginehub.piston.annotation.param.Arg;
|
2019-09-14 03:05:16 +00:00
|
|
|
import org.enginehub.piston.inject.InjectedValueAccess;
|
2014-06-28 08:01:49 +00:00
|
|
|
|
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
/**
|
2014-06-28 08:01:49 +00:00
|
|
|
* Commands related to scripting.
|
2014-04-03 02:08:50 +00:00
|
|
|
*/
|
2019-07-06 00:46:48 +00:00
|
|
|
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
|
2014-04-03 02:08:50 +00:00
|
|
|
public class ScriptingCommands {
|
|
|
|
|
2014-06-28 08:01:49 +00:00
|
|
|
private final WorldEdit worldEdit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
*
|
|
|
|
* @param worldEdit reference to WorldEdit
|
|
|
|
*/
|
2019-07-06 00:46:48 +00:00
|
|
|
public ScriptingCommands(WorldEdit worldEdit) {
|
2014-06-28 08:01:49 +00:00
|
|
|
checkNotNull(worldEdit);
|
|
|
|
this.worldEdit = worldEdit;
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-07-06 00:46:48 +00:00
|
|
|
name = "setupdispatcher",
|
|
|
|
desc = ""
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
2019-06-12 22:48:40 +00:00
|
|
|
@CommandPermissions("fawe.setupdispatcher")
|
2019-09-14 03:05:16 +00:00
|
|
|
public void setupdispatcher(Player player, LocalSession session, InjectedValueAccess args) throws WorldEditException {
|
2019-07-22 06:02:51 +00:00
|
|
|
PlatformCommandManager.getInstance().registerAllCommands();
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
@Command(
|
2019-07-22 06:02:51 +00:00
|
|
|
name = "cs",
|
|
|
|
desc = "Execute a CraftScript"
|
2019-07-06 00:46:48 +00:00
|
|
|
)
|
2014-04-03 02:08:50 +00:00
|
|
|
@CommandPermissions("worldedit.scripting.execute")
|
|
|
|
@Logging(ALL)
|
2019-07-22 06:02:51 +00:00
|
|
|
public void execute(Player player, LocalSession session,
|
|
|
|
@Arg(desc = "Filename of the CraftScript to load")
|
2019-07-22 02:49:08 +00:00
|
|
|
String filename,
|
2019-07-22 06:02:51 +00:00
|
|
|
@Arg(desc = "Arguments to the CraftScript", def = "", variable = true)
|
2019-08-06 15:32:05 +00:00
|
|
|
List<String> commandStr) throws WorldEditException {
|
2019-07-06 00:46:48 +00:00
|
|
|
if (!player.hasPermission("worldedit.scripting.execute." + filename)) {
|
2019-09-14 03:05:16 +00:00
|
|
|
player.printError(BBC.SCRIPTING_NO_PERM.s());
|
2014-04-03 02:08:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
session.setLastScript(filename);
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir);
|
|
|
|
File f = worldEdit.getSafeOpenFile(player, dir, filename, "js", "js");
|
2019-07-22 06:02:51 +00:00
|
|
|
|
2019-08-06 15:32:05 +00:00
|
|
|
worldEdit.runScript(player, f, Stream.concat(Stream.of(filename), commandStr.stream())
|
2019-07-22 06:02:51 +00:00
|
|
|
.toArray(String[]::new));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
@Command(
|
2019-07-22 06:02:51 +00:00
|
|
|
name = ".s",
|
|
|
|
desc = "Execute last CraftScript"
|
2019-07-06 00:46:48 +00:00
|
|
|
)
|
2014-04-03 02:08:50 +00:00
|
|
|
@CommandPermissions("worldedit.scripting.execute")
|
|
|
|
@Logging(ALL)
|
2019-07-06 00:46:48 +00:00
|
|
|
public void executeLast(Player player, LocalSession session,
|
|
|
|
@Arg(desc = "Arguments to the CraftScript", def = "", variable = true)
|
2019-08-06 15:32:05 +00:00
|
|
|
List<String> commandStr) throws WorldEditException {
|
2019-06-12 21:12:12 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
String lastScript = session.getLastScript();
|
|
|
|
|
|
|
|
if (!player.hasPermission("worldedit.scripting.execute." + lastScript)) {
|
2019-09-14 03:05:16 +00:00
|
|
|
player.printError(BBC.SCRIPTING_NO_PERM.s());
|
2014-04-03 02:08:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastScript == null) {
|
2019-09-14 03:05:16 +00:00
|
|
|
player.printError(BBC.SCRIPTING_CS.s());
|
2014-04-03 02:08:50 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().scriptsDir);
|
|
|
|
File f = worldEdit.getSafeOpenFile(player, dir, lastScript, "js", "js");
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2019-08-06 15:32:05 +00:00
|
|
|
worldEdit.runScript(player, f, Stream.concat(Stream.of(lastScript), commandStr.stream())
|
2019-07-22 06:02:51 +00:00
|
|
|
.toArray(String[]::new));
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|