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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

222 lines
9.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
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2014-04-04 22:03:18 +00:00
*/
package com.sk89q.worldedit.command;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweVersion;
import com.boydti.fawe.config.Caption;
import com.boydti.fawe.config.Settings;
2020-12-19 16:18:57 +00:00
import com.intellectualsites.paster.IncendoPaster;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
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.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;
2019-06-06 22:39:51 +00:00
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extension.platform.PlatformManager;
2020-07-14 02:50:59 +00:00
import com.sk89q.worldedit.util.formatting.component.MessageBox;
import com.sk89q.worldedit.util.formatting.component.TextComponentProducer;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
2020-03-21 01:12:11 +00:00
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
2021-02-03 22:08:39 +00:00
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
2020-07-14 02:50:59 +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;
import org.enginehub.piston.annotation.param.Switch;
2020-12-19 16:18:57 +00:00
import java.io.File;
import java.io.IOException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.TextStyle;
import java.time.zone.ZoneRulesException;
2019-06-06 22:39:51 +00:00
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
2019-06-06 22:39:51 +00:00
import java.util.Map;
@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(
name = "version",
aliases = { "ver" },
2020-08-01 21:30:48 +00:00
desc = "Get the FAWE version"
)
@CommandPermissions(queued = false)
public void version(Actor actor) {
FaweVersion fVer = Fawe.get().getVersion();
2019-05-05 08:37:11 +00:00
String fVerStr = fVer == null ? "unknown" : "-" + fVer.build;
2020-07-13 11:13:43 +00:00
actor.print(TextComponent.of("FastAsyncWorldEdit" + fVerStr + " created by Empire92, MattBDev, IronApollo, dordsor21 and NotMyFault"));
if (fVer != null) {
FaweVersion version = Fawe.get().getVersion();
Date date = new GregorianCalendar(2000 + version.year, version.month - 1, version.day)
.getTime();
TextComponent dateArg = TextComponent.of(date.toLocaleString());
TextComponent commitArg = TextComponent.of(Integer.toHexString(version.hash));
TextComponent buildArg = TextComponent.of(version.build);
TextComponent platformArg = TextComponent.of(Settings.IMP.PLATFORM);
actor.print(Caption.of("worldedit.version.version", dateArg, commitArg, buildArg, platformArg));
}
2021-06-06 19:17:24 +00:00
actor.printInfo(TextComponent.of("Wiki: https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/wiki"));
PlatformManager pm = we.getPlatformManager();
2019-06-06 22:39:51 +00:00
TextComponentProducer producer = new TextComponentProducer();
for (Platform platform : pm.getPlatforms()) {
producer.append(
TextComponent.of("* ", TextColor.GRAY)
2021-02-03 22:08:39 +00:00
.append(TextComponent.of(platform.getPlatformName())
.hoverEvent(HoverEvent.showText(TextComponent.of(platform.getId()))))
.append(TextComponent.of("(" + platform.getPlatformVersion() + ")"))
).newline();
}
actor.print(new MessageBox("Platforms", producer, TextColor.GRAY).create());
producer.reset();
for (Capability capability : Capability.values()) {
Platform platform = pm.queryCapability(capability);
producer.append(
TextComponent.of(capability.name(), TextColor.GRAY)
.append(TextComponent.of(": ")
2021-02-03 22:08:39 +00:00
.append(TextComponent.of(platform != null ? platform.getPlatformName() : "none")))
).newline();
}
actor.print(new MessageBox("Capabilities", producer, TextColor.GRAY).create());
}
@Command(
name = "reload",
desc = "Reload configuration and translations"
)
@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()));
Fawe.get().setupConfigs();
actor.print(Caption.of("worldedit.reload.config"));
}
@Command(
name = "debugpaste",
2020-08-01 21:30:48 +00:00
desc = "Writes a report of latest.log, config.yml, config-legacy.yml, strings.json to https://athion.net/ISPaster/paste"
)
@CommandPermissions(value = {"worldedit.report", "worldedit.debugpaste"}, queued = false)
2020-03-02 22:49:51 +00:00
public void report(Actor actor) throws WorldEditException {
2020-03-21 01:12:11 +00:00
String dest;
2020-03-02 22:49:51 +00:00
try {
final File logFile = new File("logs/latest.log");
2020-12-19 16:18:57 +00:00
final File config = new File(Fawe.imp().getDirectory(), "config.yml");
final File legacyConfig = new File(Fawe.imp().getDirectory(), "config-legacy.yml");
dest = IncendoPaster.debugPaste(logFile, Fawe.imp().getDebugInfo(), config, legacyConfig);
2020-03-02 22:49:51 +00:00
} catch (IOException e) {
actor.printInfo(TextComponent.of(e.getMessage()));
2020-03-21 01:12:11 +00:00
return;
2020-03-02 22:49:51 +00:00
}
actor.print(Caption.of("worldedit.report.written", TextComponent.of(dest).clickEvent(
2020-03-21 01:12:11 +00:00
ClickEvent.openUrl(dest))));
}
@Command(
name = "threads",
desc = "Print all thread stacks"
)
@CommandPermissions(value = "worldedit.threads", queued = false)
public void threads(Actor actor) throws WorldEditException {
Map<Thread, StackTraceElement[]> stacks = Thread.getAllStackTraces();
for (Map.Entry<Thread, StackTraceElement[]> entry : stacks.entrySet()) {
Thread thread = entry.getKey();
actor.printDebug(TextComponent.of(
2021-04-04 17:56:57 +00:00
"--------------------------------------------------------------------------------------------"));
actor.printDebug("Thread: " + thread.getName() + " | Id: " + thread.getId() + " | Alive: " + thread.isAlive());
for (StackTraceElement elem : entry.getValue()) {
2021-04-12 17:32:17 +00:00
actor.printDebug(TextComponent.of(elem.toString()));
}
}
}
@Command(
name = "cui",
desc = "Complete CUI handshake (internal usage)"
)
2021-03-06 19:22:39 +00:00
@CommandPermissions(value = "worldedit.cui", queued = false)
public void cui(Player player, LocalSession session) {
session.setCUISupport(true);
session.dispatchCUISetup(player);
}
@Command(
name = "tz",
desc = "Set your timezone for snapshots"
)
2021-03-06 19:22:39 +00:00
@CommandPermissions(value = "worldedit.timezone", queued = false)
2019-08-06 15:29:49 +00:00
public void tz(Actor actor, LocalSession session,
@Arg(desc = "The timezone to set")
String timezone) {
try {
ZoneId tz = ZoneId.of(timezone);
session.setTimezone(tz);
actor.print(Caption.of("worldedit.timezone.set", TextComponent.of(tz.getDisplayName(
TextStyle.FULL, actor.getLocale()
))));
actor.print(Caption.of("worldedit.timezone.current",
TextComponent.of(dateFormat.withLocale(actor.getLocale()).format(ZonedDateTime.now(tz)))));
} catch (ZoneRulesException e) {
actor.print(Caption.of("worldedit.timezone.invalid"));
}
}
@Command(
name = "help",
2019-04-26 04:03:28 +00:00
desc = "Displays help for WorldEdit commands"
)
@CommandPermissions(value = "worldedit.help", queued = false)
public void help(Actor actor,
@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")
int page,
@Arg(desc = "The command to retrieve help for", def = "", variable = true)
2019-04-26 04:03:28 +00:00
List<String> command) throws WorldEditException {
PrintCommandHelp.help(command, page, listSubCommands,
we.getPlatformManager().getPlatformCommandManager().getCommandManager(), actor, "/worldedit help");
}
}