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;
|
|
|
|
|
2018-12-18 09:28:55 +00:00
|
|
|
import com.google.common.io.Files;
|
2018-07-30 13:26:06 +00:00
|
|
|
import com.sk89q.worldedit.LocalSession;
|
|
|
|
import com.sk89q.worldedit.WorldEdit;
|
|
|
|
import com.sk89q.worldedit.WorldEditException;
|
2019-04-26 04:03:28 +00:00
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissions;
|
|
|
|
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
|
|
|
import com.sk89q.worldedit.command.util.PrintCommandHelp;
|
2014-06-28 08:01:49 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
2014-07-28 03:44:05 +00:00
|
|
|
import com.sk89q.worldedit.event.platform.ConfigurationLoadEvent;
|
2014-06-28 00:55:39 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Actor;
|
2014-06-27 20:14:55 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Capability;
|
2014-04-06 06:27:10 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Platform;
|
|
|
|
import com.sk89q.worldedit.extension.platform.PlatformManager;
|
2018-12-18 09:28:55 +00:00
|
|
|
import com.sk89q.worldedit.util.paste.ActorCallbackPaste;
|
|
|
|
import com.sk89q.worldedit.util.report.ConfigReport;
|
|
|
|
import com.sk89q.worldedit.util.report.ReportList;
|
|
|
|
import com.sk89q.worldedit.util.report.SystemInfoReport;
|
2019-04-26 04:03:28 +00:00
|
|
|
import org.enginehub.piston.annotation.Command;
|
|
|
|
import org.enginehub.piston.annotation.CommandContainer;
|
|
|
|
import org.enginehub.piston.annotation.param.Arg;
|
|
|
|
import org.enginehub.piston.annotation.param.Switch;
|
2014-04-06 06:27:10 +00:00
|
|
|
|
2018-12-18 09:28:55 +00:00
|
|
|
import java.io.File;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.charset.Charset;
|
2019-04-24 06:47:22 +00:00
|
|
|
import java.time.ZoneId;
|
|
|
|
import java.time.ZonedDateTime;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import java.time.format.TextStyle;
|
2019-04-26 04:03:28 +00:00
|
|
|
import java.util.List;
|
2019-04-24 06:47:22 +00:00
|
|
|
import java.util.Locale;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2019-04-26 04:03:28 +00:00
|
|
|
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
|
2014-04-03 02:08:50 +00:00
|
|
|
public class WorldEditCommands {
|
2019-04-24 06:47:22 +00:00
|
|
|
private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
|
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
private final WorldEdit we;
|
2019-04-24 06:47:22 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
public WorldEditCommands(WorldEdit we) {
|
|
|
|
this.we = we;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-26 04:03:28 +00:00
|
|
|
name = "version",
|
|
|
|
aliases = { "ver" },
|
|
|
|
desc = "Get WorldEdit version"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
2014-06-28 00:55:39 +00:00
|
|
|
public void version(Actor actor) throws WorldEditException {
|
|
|
|
actor.print("WorldEdit version " + WorldEdit.getVersion());
|
|
|
|
actor.print("https://github.com/sk89q/worldedit/");
|
2014-04-06 06:27:10 +00:00
|
|
|
|
|
|
|
PlatformManager pm = we.getPlatformManager();
|
|
|
|
|
2014-06-28 00:55:39 +00:00
|
|
|
actor.printDebug("----------- Platforms -----------");
|
2014-04-06 06:27:10 +00:00
|
|
|
for (Platform platform : pm.getPlatforms()) {
|
2014-06-28 00:55:39 +00:00
|
|
|
actor.printDebug(String.format("* %s (%s)", platform.getPlatformName(), platform.getPlatformVersion()));
|
2014-06-27 20:14:55 +00:00
|
|
|
}
|
|
|
|
|
2014-06-28 00:55:39 +00:00
|
|
|
actor.printDebug("----------- Capabilities -----------");
|
2014-06-27 20:14:55 +00:00
|
|
|
for (Capability capability : Capability.values()) {
|
|
|
|
Platform platform = pm.queryCapability(capability);
|
2014-06-28 00:55:39 +00:00
|
|
|
actor.printDebug(String.format("%s: %s", capability.name(), platform != null ? platform.getPlatformName() : "NONE"));
|
2014-04-06 06:27:10 +00:00
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-26 04:03:28 +00:00
|
|
|
name = "reload",
|
|
|
|
desc = "Reload configuration"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.reload")
|
2014-06-28 00:55:39 +00:00
|
|
|
public void reload(Actor actor) throws WorldEditException {
|
2018-06-17 12:04:35 +00:00
|
|
|
we.getPlatformManager().queryCapability(Capability.CONFIGURATION).reload();
|
2014-07-28 03:44:05 +00:00
|
|
|
we.getEventBus().post(new ConfigurationLoadEvent(we.getPlatformManager().queryCapability(Capability.CONFIGURATION).getConfiguration()));
|
2014-06-28 00:55:39 +00:00
|
|
|
actor.print("Configuration reloaded!");
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
2019-04-26 04:03:28 +00:00
|
|
|
@Command(
|
|
|
|
name = "report",
|
|
|
|
desc = "Writes a report on WorldEdit"
|
|
|
|
)
|
2018-12-18 09:28:55 +00:00
|
|
|
@CommandPermissions({"worldedit.report"})
|
2019-04-26 04:03:28 +00:00
|
|
|
public void report(Actor actor,
|
|
|
|
@Switch(name = 'p', desc = "Pastebins the report")
|
|
|
|
boolean pastebin) throws WorldEditException {
|
2018-12-18 09:28:55 +00:00
|
|
|
ReportList report = new ReportList("Report");
|
|
|
|
report.add(new SystemInfoReport());
|
|
|
|
report.add(new ConfigReport());
|
|
|
|
String result = report.toString();
|
|
|
|
|
|
|
|
try {
|
|
|
|
File dest = new File(we.getWorkingDirectoryFile(we.getConfiguration().saveDir), "report.txt");
|
|
|
|
Files.write(result, dest, Charset.forName("UTF-8"));
|
|
|
|
actor.print("WorldEdit report written to " + dest.getAbsolutePath());
|
|
|
|
} catch (IOException e) {
|
|
|
|
actor.printError("Failed to write report: " + e.getMessage());
|
|
|
|
}
|
|
|
|
|
2019-04-26 04:03:28 +00:00
|
|
|
if (pastebin) {
|
2018-12-18 09:28:55 +00:00
|
|
|
actor.checkPermission("worldedit.report.pastebin");
|
2018-12-21 07:31:27 +00:00
|
|
|
ActorCallbackPaste.pastebin(
|
|
|
|
we.getSupervisor(), actor, result, "WorldEdit report: %s.report",
|
2019-04-15 08:21:15 +00:00
|
|
|
WorldEdit.getInstance().getPlatformManager().getPlatformCommandMananger().getExceptionConverter()
|
2018-12-21 07:31:27 +00:00
|
|
|
);
|
2018-12-18 09:28:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
@Command(
|
2019-04-26 04:03:28 +00:00
|
|
|
name = "cui",
|
|
|
|
desc = "Complete CUI handshake (internal usage)"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
2019-03-16 23:04:24 +00:00
|
|
|
public void cui(Player player, LocalSession session) throws WorldEditException {
|
2014-04-03 02:08:50 +00:00
|
|
|
session.setCUISupport(true);
|
|
|
|
session.dispatchCUISetup(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-26 04:03:28 +00:00
|
|
|
name = "tz",
|
|
|
|
desc = "Set your timezone for snapshots"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
2019-04-26 04:03:28 +00:00
|
|
|
public void tz(Player player, LocalSession session,
|
|
|
|
@Arg(desc = "The timezone to set")
|
|
|
|
String timezone) throws WorldEditException {
|
|
|
|
ZoneId tz = ZoneId.of(timezone);
|
2014-04-03 02:08:50 +00:00
|
|
|
session.setTimezone(tz);
|
2019-04-24 06:47:22 +00:00
|
|
|
player.print("Timezone set for this session to: " + tz.getDisplayName(
|
|
|
|
TextStyle.FULL, Locale.ENGLISH
|
|
|
|
));
|
2014-04-03 02:08:50 +00:00
|
|
|
player.print("The current time in that timezone is: "
|
2019-04-24 06:47:22 +00:00
|
|
|
+ dateFormat.format(ZonedDateTime.now(tz)));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2019-04-26 04:03:28 +00:00
|
|
|
name = "help",
|
|
|
|
desc = "Displays help for WorldEdit commands"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.help")
|
2019-04-26 04:03:28 +00:00
|
|
|
public void help(Actor actor,
|
|
|
|
@Arg(desc = "The page to retrieve", def = "1")
|
|
|
|
int page,
|
|
|
|
@Arg(desc = "The command to retrieve help for", def = "", variable = true)
|
|
|
|
List<String> command) throws WorldEditException {
|
|
|
|
PrintCommandHelp.help(command, page, we, actor);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
}
|