Plex-FAWE/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java

170 lines
6.6 KiB
Java
Raw Normal View History

/*
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-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
* (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-04 22:03:18 +00:00
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2014-04-04 22:03:18 +00:00
*/
package com.sk89q.worldedit.command;
import com.google.common.io.Files;
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;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.ConfigurationLoadEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extension.platform.PlatformManager;
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.ArgFlag;
2019-04-26 04:03:28 +00:00
import org.enginehub.piston.annotation.param.Switch;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
2019-04-27 06:46:13 +00:00
import java.time.zone.ZoneRulesException;
2019-04-26 04:03:28 +00:00
import java.util.List;
import java.util.Locale;
2019-04-26 04:03:28 +00:00
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
public class WorldEditCommands {
private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
private final WorldEdit we;
public WorldEditCommands(WorldEdit we) {
this.we = we;
}
@Command(
2019-04-26 04:03:28 +00:00
name = "version",
aliases = { "ver" },
desc = "Get WorldEdit version"
)
public void version(Actor actor) {
actor.print("WorldEdit version " + WorldEdit.getVersion());
2019-04-27 06:46:13 +00:00
actor.print("https://github.com/EngineHub/worldedit/");
PlatformManager pm = we.getPlatformManager();
actor.printDebug("----------- Platforms -----------");
for (Platform platform : pm.getPlatforms()) {
actor.printDebug(String.format("* %s (%s)", platform.getPlatformName(), platform.getPlatformVersion()));
}
actor.printDebug("----------- Capabilities -----------");
for (Capability capability : Capability.values()) {
Platform platform = pm.queryCapability(capability);
actor.printDebug(String.format("%s: %s", capability.name(), platform != null ? platform.getPlatformName() : "NONE"));
}
}
@Command(
2019-04-26 04:03:28 +00:00
name = "reload",
desc = "Reload configuration"
)
@CommandPermissions("worldedit.reload")
public void reload(Actor actor) {
2018-06-17 12:04:35 +00:00
we.getPlatformManager().queryCapability(Capability.CONFIGURATION).reload();
we.getEventBus().post(new ConfigurationLoadEvent(we.getPlatformManager().queryCapability(Capability.CONFIGURATION).getConfiguration()));
actor.print("Configuration reloaded!");
}
2019-04-26 04:03:28 +00:00
@Command(
name = "report",
desc = "Writes a report on WorldEdit"
)
@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 {
ReportList report = new ReportList("Report");
report.add(new SystemInfoReport());
report.add(new ConfigReport());
String result = report.toString();
try {
2019-05-12 20:01:22 +00:00
File dest = new File(we.getConfiguration().getWorkingDirectory(), "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) {
actor.checkPermission("worldedit.report.pastebin");
ActorCallbackPaste.pastebin(we.getSupervisor(), actor, result, "WorldEdit report: %s.report");
}
}
@Command(
2019-04-26 04:03:28 +00:00
name = "cui",
desc = "Complete CUI handshake (internal usage)"
)
public void cui(Player player, LocalSession session) {
session.setCUISupport(true);
session.dispatchCUISetup(player);
}
@Command(
2019-04-26 04:03:28 +00:00
name = "tz",
desc = "Set your timezone for snapshots"
)
2019-04-26 04:03:28 +00:00
public void tz(Player player, LocalSession session,
@Arg(desc = "The timezone to set")
String timezone) {
2019-04-27 06:46:13 +00:00
try {
ZoneId tz = ZoneId.of(timezone);
session.setTimezone(tz);
player.print("Timezone set for this session to: " + tz.getDisplayName(
TextStyle.FULL, Locale.ENGLISH
));
player.print("The current time in that timezone is: " + dateFormat.format(ZonedDateTime.now(tz)));
} catch (ZoneRulesException e) {
player.printError("Invalid timezone");
}
}
@Command(
2019-04-26 04:03:28 +00:00
name = "help",
desc = "Displays help for WorldEdit commands"
)
@CommandPermissions("worldedit.help")
2019-04-26 04:03:28 +00:00
public void help(Actor actor,
2019-05-18 05:24:14 +00:00
@Switch(name = 's', desc = "List sub-commands of the given command, if applicable")
boolean listSubCommands,
@ArgFlag(name = 'p', desc = "The page to retrieve", def = "1")
2019-04-26 04:03:28 +00:00
int page,
@Arg(desc = "The command to retrieve help for", def = "", variable = true)
List<String> command) throws WorldEditException {
2019-05-18 05:24:14 +00:00
PrintCommandHelp.help(command, page, listSubCommands, we, actor);
}
}