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
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* 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
|
2014-04-03 02:08:50 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2020-08-25 01:31:47 +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 General Public License for more details.
|
2014-04-03 02:08:50 +00:00
|
|
|
*
|
2020-08-25 01:31:47 +00:00
|
|
|
* 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
|
|
|
*/
|
2014-04-03 02:08:50 +00:00
|
|
|
|
|
|
|
package com.sk89q.worldedit.command;
|
|
|
|
|
2021-07-01 20:16:25 +00:00
|
|
|
import com.fastasyncworldedit.core.Fawe;
|
|
|
|
import com.fastasyncworldedit.core.FaweVersion;
|
|
|
|
import com.fastasyncworldedit.core.configuration.Caption;
|
|
|
|
import com.fastasyncworldedit.core.configuration.Settings;
|
2021-10-23 17:36:59 +00:00
|
|
|
import com.fastasyncworldedit.core.util.UpdateNotification;
|
2020-12-19 16:18:57 +00:00
|
|
|
import com.intellectualsites.paster.IncendoPaster;
|
2018-07-30 13:26:06 +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;
|
2021-09-19 20:02:41 +00:00
|
|
|
import com.sk89q.worldedit.command.util.HookMode;
|
2019-07-06 00:46:48 +00:00
|
|
|
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;
|
2018-12-18 09:28:55 +00:00
|
|
|
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;
|
2019-10-13 11:47:26 +00:00
|
|
|
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;
|
2018-12-18 09:28:55 +00:00
|
|
|
import java.io.IOException;
|
2019-07-06 00:46:48 +00:00
|
|
|
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;
|
2019-07-06 00:46:48 +00:00
|
|
|
import java.util.List;
|
2019-06-06 22:39:51 +00:00
|
|
|
import java.util.Map;
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2020-01-05 06:35:19 +00:00
|
|
|
@CommandContainer(superTypes = {CommandPermissionsConditionGenerator.Registration.class})
|
2014-04-03 02:08:50 +00:00
|
|
|
public class WorldEditCommands {
|
2021-07-24 15:34:05 +00:00
|
|
|
|
2019-04-24 06:47:22 +00:00
|
|
|
private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
private final WorldEdit we;
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
public WorldEditCommands(WorldEdit we) {
|
|
|
|
this.we = we;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "version",
|
|
|
|
aliases = {"ver"},
|
|
|
|
desc = "Get the FAWE version"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
2020-01-05 06:35:19 +00:00
|
|
|
@CommandPermissions(queued = false)
|
2019-07-06 00:46:48 +00:00
|
|
|
public void version(Actor actor) {
|
2021-11-29 21:15:41 +00:00
|
|
|
//FAWE start - use own, minimized message that doesn't print "Platforms" and "Capabilities"
|
2018-08-12 14:03:07 +00:00
|
|
|
FaweVersion fVer = Fawe.get().getVersion();
|
2019-05-05 08:37:11 +00:00
|
|
|
String fVerStr = fVer == null ? "unknown" : "-" + fVer.build;
|
2021-11-29 21:15:41 +00:00
|
|
|
actor.print(TextComponent.of("FastAsyncWorldEdit" + fVerStr));
|
|
|
|
actor.print(TextComponent.of("Authors: Empire92, MattBDev, IronApollo, dordsor21 and NotMyFault"));
|
|
|
|
actor.print(TextComponent.of("Wiki: https://git.io/JMEPa")
|
|
|
|
.clickEvent(ClickEvent.openUrl("https://github.com/IntellectualSites/FastAsyncWorldEdit-Documentation/wiki")));
|
|
|
|
actor.print(TextComponent.of("Discord: https://discord.gg/intellectualsites")
|
|
|
|
.clickEvent(ClickEvent.openUrl("https://discord.gg/intellectualsites")));
|
2021-10-23 17:36:59 +00:00
|
|
|
UpdateNotification.doUpdateNotification(actor);
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE end
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "reload",
|
|
|
|
desc = "Reload configuration and translations"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.reload")
|
2019-07-06 00:46:48 +00:00
|
|
|
public void reload(Actor actor) {
|
2018-06-17 12:04:35 +00:00
|
|
|
we.getPlatformManager().queryCapability(Capability.CONFIGURATION).reload();
|
2021-07-24 15:34:05 +00:00
|
|
|
we.getEventBus().post(new ConfigurationLoadEvent(we
|
|
|
|
.getPlatformManager()
|
|
|
|
.queryCapability(Capability.CONFIGURATION)
|
|
|
|
.getConfiguration()));
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE start
|
2018-08-12 14:03:07 +00:00
|
|
|
Fawe.get().setupConfigs();
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE end
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.reload.config"));
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE start
|
2018-08-12 14:03:07 +00:00
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "debugpaste",
|
2021-12-20 21:12:04 +00:00
|
|
|
desc = "Writes a report of latest.log, config.yml, worldedit-config.yml, strings.json to https://athion.net/ISPaster/paste"
|
2018-08-12 14:03:07 +00:00
|
|
|
)
|
2020-01-05 06:35:19 +00:00
|
|
|
@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 {
|
2021-04-09 20:12:52 +00:00
|
|
|
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");
|
2021-12-20 21:12:04 +00:00
|
|
|
final File worldeditConfig = new File(Fawe.imp().getDirectory(), "worldedit-config.yml");
|
|
|
|
dest = IncendoPaster.debugPaste(logFile, Fawe.imp().getDebugInfo(), config, worldeditConfig);
|
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
|
|
|
}
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.report.written", TextComponent.of(dest).clickEvent(
|
2021-07-24 15:34:05 +00:00
|
|
|
ClickEvent.openUrl(dest))));
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "threads",
|
|
|
|
desc = "Print all thread stacks"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
2020-01-05 06:35:19 +00:00
|
|
|
@CommandPermissions(value = "worldedit.threads", queued = false)
|
2018-08-12 14:03:07 +00:00
|
|
|
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();
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.printDebug(TextComponent.of(
|
2021-07-24 15:34:05 +00:00
|
|
|
"--------------------------------------------------------------------------------------------"));
|
2021-04-04 17:56:57 +00:00
|
|
|
actor.printDebug("Thread: " + thread.getName() + " | Id: " + thread.getId() + " | Alive: " + thread.isAlive());
|
2018-08-12 14:03:07 +00:00
|
|
|
for (StackTraceElement elem : entry.getValue()) {
|
2021-04-12 17:32:17 +00:00
|
|
|
actor.printDebug(TextComponent.of(elem.toString()));
|
2018-08-12 14:03:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE end
|
2018-08-12 14:03:07 +00:00
|
|
|
|
2021-09-19 20:02:41 +00:00
|
|
|
@Command(
|
|
|
|
name = "trace",
|
|
|
|
desc = "Toggles trace hook"
|
|
|
|
)
|
2021-10-23 17:36:59 +00:00
|
|
|
@CommandPermissions(value = "worldedit.trace", queued = false)
|
2021-09-19 20:02:41 +00:00
|
|
|
void trace(
|
|
|
|
Actor actor, LocalSession session,
|
|
|
|
@Arg(desc = "The mode to set the trace hook to", def = "")
|
|
|
|
HookMode hookMode
|
|
|
|
) {
|
|
|
|
boolean previousMode = session.isTracingActions();
|
|
|
|
boolean newMode;
|
|
|
|
if (hookMode != null) {
|
|
|
|
newMode = hookMode == HookMode.ACTIVE;
|
|
|
|
if (newMode == previousMode) {
|
2021-10-17 12:50:42 +00:00
|
|
|
actor.print(Caption.of(previousMode
|
2021-09-19 20:02:41 +00:00
|
|
|
? "worldedit.trace.active.already"
|
|
|
|
: "worldedit.trace.inactive.already"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
newMode = !previousMode;
|
|
|
|
}
|
|
|
|
session.setTracingActions(newMode);
|
2021-10-17 12:50:42 +00:00
|
|
|
actor.print(Caption.of(newMode ? "worldedit.trace.active" : "worldedit.trace.inactive"));
|
2021-09-19 20:02:41 +00:00
|
|
|
}
|
|
|
|
|
2018-08-12 14:03:07 +00:00
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "cui",
|
|
|
|
desc = "Complete CUI handshake (internal usage)"
|
2018-08-12 14:03:07 +00:00
|
|
|
)
|
2021-03-06 19:22:39 +00:00
|
|
|
@CommandPermissions(value = "worldedit.cui", queued = false)
|
2019-07-06 00:46:48 +00:00
|
|
|
public void cui(Player player, LocalSession session) {
|
2014-04-03 02:08:50 +00:00
|
|
|
session.setCUISupport(true);
|
|
|
|
session.dispatchCUISetup(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "tz",
|
|
|
|
desc = "Set your timezone for snapshots"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
2021-03-06 19:22:39 +00:00
|
|
|
@CommandPermissions(value = "worldedit.timezone", queued = false)
|
2021-07-24 15:34:05 +00:00
|
|
|
public void tz(
|
|
|
|
Actor actor, LocalSession session,
|
|
|
|
@Arg(desc = "The timezone to set")
|
|
|
|
String timezone
|
|
|
|
) {
|
2019-07-06 00:46:48 +00:00
|
|
|
try {
|
|
|
|
ZoneId tz = ZoneId.of(timezone);
|
|
|
|
session.setTimezone(tz);
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.timezone.set", TextComponent.of(tz.getDisplayName(
|
2019-10-13 11:47:26 +00:00
|
|
|
TextStyle.FULL, actor.getLocale()
|
|
|
|
))));
|
2021-07-24 15:34:05 +00:00
|
|
|
actor.print(Caption.of(
|
|
|
|
"worldedit.timezone.current",
|
|
|
|
TextComponent.of(dateFormat.withLocale(actor.getLocale()).format(ZonedDateTime.now(tz)))
|
|
|
|
));
|
2019-07-06 00:46:48 +00:00
|
|
|
} catch (ZoneRulesException e) {
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.timezone.invalid"));
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "help",
|
|
|
|
desc = "Displays help for WorldEdit commands"
|
2014-04-03 02:08:50 +00:00
|
|
|
)
|
2020-01-05 06:35:19 +00:00
|
|
|
@CommandPermissions(value = "worldedit.help", queued = false)
|
2021-07-24 15:34:05 +00:00
|
|
|
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)
|
|
|
|
List<String> command
|
|
|
|
) throws WorldEditException {
|
2019-07-27 04:35:38 +00:00
|
|
|
PrintCommandHelp.help(command, page, listSubCommands,
|
2021-07-24 15:34:05 +00:00
|
|
|
we.getPlatformManager().getPlatformCommandManager().getCommandManager(), actor, "/worldedit help"
|
|
|
|
);
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|
2021-07-24 15:34:05 +00:00
|
|
|
|
2014-04-03 02:08:50 +00:00
|
|
|
}
|