2019-07-06 00:46:48 +00:00
|
|
|
/*
|
|
|
|
* WorldEdit, a Minecraft world manipulation toolkit
|
|
|
|
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
|
|
* Copyright (C) WorldEdit team and contributors
|
|
|
|
*
|
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
|
2019-07-06 00:46:48 +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.
|
2019-07-06 00:46:48 +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/>.
|
2019-07-06 00:46:48 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.sk89q.worldedit.command;
|
|
|
|
|
2021-07-01 20:16:25 +00:00
|
|
|
import com.fastasyncworldedit.core.Fawe;
|
|
|
|
import com.fastasyncworldedit.core.configuration.Caption;
|
2021-07-23 15:48:51 +00:00
|
|
|
import com.fastasyncworldedit.core.extent.ResettableExtent;
|
2021-07-01 20:16:25 +00:00
|
|
|
import com.fastasyncworldedit.core.util.CachedTextureUtil;
|
|
|
|
import com.fastasyncworldedit.core.util.CleanTextureUtil;
|
|
|
|
import com.fastasyncworldedit.core.util.MathMan;
|
|
|
|
import com.fastasyncworldedit.core.util.RandomTextureUtil;
|
|
|
|
import com.fastasyncworldedit.core.util.StringMan;
|
|
|
|
import com.fastasyncworldedit.core.util.TextureUtil;
|
2020-11-09 09:38:10 +00:00
|
|
|
import com.google.common.collect.ImmutableList;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.EditSession;
|
|
|
|
import com.sk89q.worldedit.LocalConfiguration;
|
|
|
|
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;
|
2019-09-05 05:50:14 +00:00
|
|
|
import com.sk89q.worldedit.command.util.HookMode;
|
2020-11-09 09:38:10 +00:00
|
|
|
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.entity.Player;
|
2019-07-25 18:44:10 +00:00
|
|
|
import com.sk89q.worldedit.extension.input.InputParseException;
|
2019-07-17 10:50:54 +00:00
|
|
|
import com.sk89q.worldedit.extension.input.ParserContext;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Actor;
|
2019-09-05 05:50:14 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Capability;
|
2021-04-10 09:15:41 +00:00
|
|
|
import com.sk89q.worldedit.extension.platform.Locatable;
|
2020-07-14 02:50:59 +00:00
|
|
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.function.mask.Mask;
|
2020-11-09 09:38:10 +00:00
|
|
|
import com.sk89q.worldedit.internal.command.CommandRegistrationHandler;
|
|
|
|
import com.sk89q.worldedit.internal.command.CommandUtil;
|
2021-07-23 15:48:51 +00:00
|
|
|
import com.sk89q.worldedit.internal.cui.ServerCUIHandler;
|
2020-03-08 06:09:36 +00:00
|
|
|
import com.sk89q.worldedit.util.SideEffect;
|
|
|
|
import com.sk89q.worldedit.util.SideEffectSet;
|
2021-04-04 17:56:57 +00:00
|
|
|
import com.sk89q.worldedit.util.auth.AuthorizationException;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.component.PaginationBox;
|
2020-03-08 06:09:36 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.component.SideEffectBox;
|
|
|
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
2019-10-13 11:47:26 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
2020-07-14 02:50:59 +00:00
|
|
|
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
2019-07-25 18:44:10 +00:00
|
|
|
import com.sk89q.worldedit.world.World;
|
2019-07-06 00:46:48 +00:00
|
|
|
import com.sk89q.worldedit.world.item.ItemType;
|
2020-11-09 09:38:10 +00:00
|
|
|
import org.enginehub.piston.CommandManager;
|
|
|
|
import org.enginehub.piston.CommandManagerService;
|
|
|
|
import org.enginehub.piston.CommandParameters;
|
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;
|
|
|
|
|
2019-07-17 10:50:54 +00:00
|
|
|
import java.io.FileNotFoundException;
|
2020-07-14 02:50:59 +00:00
|
|
|
import java.util.ArrayList;
|
2019-07-06 00:46:48 +00:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
import java.util.Map;
|
2020-11-09 09:38:10 +00:00
|
|
|
import java.util.Set;
|
2019-07-06 00:46:48 +00:00
|
|
|
import java.util.TreeMap;
|
|
|
|
import java.util.concurrent.Callable;
|
2020-11-09 09:38:10 +00:00
|
|
|
import java.util.stream.Collectors;
|
2020-07-14 02:50:59 +00:00
|
|
|
|
|
|
|
import static com.google.common.base.Preconditions.checkNotNull;
|
2019-07-06 00:46:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* General WorldEdit commands.
|
|
|
|
*/
|
|
|
|
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
|
|
|
|
public class GeneralCommands {
|
|
|
|
|
2021-08-16 09:03:06 +00:00
|
|
|
private final WorldEdit worldEdit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new instance.
|
|
|
|
*
|
|
|
|
* @param worldEdit reference to WorldEdit
|
|
|
|
*/
|
|
|
|
public GeneralCommands(WorldEdit worldEdit) {
|
|
|
|
checkNotNull(worldEdit);
|
|
|
|
this.worldEdit = worldEdit;
|
|
|
|
}
|
|
|
|
|
2021-07-24 15:34:05 +00:00
|
|
|
public static void register(
|
|
|
|
CommandRegistrationHandler registration,
|
|
|
|
CommandManager commandManager,
|
|
|
|
CommandManagerService commandManagerService,
|
|
|
|
WorldEdit worldEdit
|
|
|
|
) {
|
2020-11-09 09:38:10 +00:00
|
|
|
// Collect the tool commands
|
|
|
|
CommandManager collect = commandManagerService.newCommandManager();
|
|
|
|
|
|
|
|
registration.register(
|
2021-07-24 15:34:05 +00:00
|
|
|
collect,
|
|
|
|
GeneralCommandsRegistration.builder(),
|
|
|
|
new GeneralCommands(worldEdit)
|
2020-11-09 09:38:10 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
Set<org.enginehub.piston.Command> commands = collect.getAllCommands()
|
2021-07-24 15:34:05 +00:00
|
|
|
.collect(Collectors.toSet());
|
2020-11-09 09:38:10 +00:00
|
|
|
for (org.enginehub.piston.Command command : commands) {
|
2021-07-23 15:48:51 +00:00
|
|
|
/*FAWE start - if in FAWE, //fast will remain for now
|
2020-11-09 09:38:10 +00:00
|
|
|
(command.getName().equals("/fast")) {
|
|
|
|
|
|
|
|
// deprecate to `//perf`
|
|
|
|
commandManager.register(CommandUtil.deprecate(
|
|
|
|
command, "//fast duplicates //perf " +
|
|
|
|
"and will be removed in WorldEdit 8",
|
|
|
|
GeneralCommands::replaceFastForPerf
|
|
|
|
));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
commandManager.register(command);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-24 15:34:05 +00:00
|
|
|
private static Component replaceFastForPerf(
|
|
|
|
org.enginehub.piston.Command oldCmd,
|
|
|
|
CommandParameters oldParams
|
|
|
|
) {
|
2020-11-09 09:38:10 +00:00
|
|
|
if (oldParams.getMetadata() == null) {
|
|
|
|
return CommandUtil.createNewCommandReplacementText("//perf");
|
|
|
|
}
|
|
|
|
ImmutableList<String> args = oldParams.getMetadata().getArguments();
|
|
|
|
if (args.isEmpty()) {
|
|
|
|
return TextComponent.of("There is not yet a replacement for //fast" +
|
2021-07-24 15:34:05 +00:00
|
|
|
" with no arguments");
|
2020-11-09 09:38:10 +00:00
|
|
|
}
|
|
|
|
String arg0 = args.get(0).toLowerCase(Locale.ENGLISH);
|
|
|
|
String flipped;
|
|
|
|
switch (arg0) {
|
|
|
|
case "on":
|
|
|
|
flipped = "off";
|
|
|
|
break;
|
|
|
|
case "off":
|
|
|
|
flipped = "on";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return TextComponent.of("There is no replacement for //fast " + arg0);
|
|
|
|
}
|
|
|
|
return CommandUtil.createNewCommandReplacementText("//perf " + flipped);
|
|
|
|
}
|
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/limit",
|
|
|
|
desc = "Modify block change limit"
|
2019-07-06 00:46:48 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.limit")
|
2021-07-24 15:34:05 +00:00
|
|
|
public void limit(
|
|
|
|
Actor actor, LocalSession session,
|
|
|
|
@Arg(desc = "The limit to set", def = "")
|
|
|
|
Integer limit
|
|
|
|
) {
|
2019-07-06 00:46:48 +00:00
|
|
|
|
|
|
|
LocalConfiguration config = worldEdit.getConfiguration();
|
2019-09-02 19:22:43 +00:00
|
|
|
boolean mayDisable = actor.hasPermission("worldedit.limit.unrestricted");
|
2019-07-06 00:46:48 +00:00
|
|
|
|
|
|
|
limit = limit == null ? config.defaultChangeLimit : Math.max(-1, limit);
|
|
|
|
if (!mayDisable && config.maxChangeLimit > -1) {
|
|
|
|
if (limit > config.maxChangeLimit) {
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.limit.too-high", TextComponent.of(config.maxChangeLimit)));
|
2019-07-06 00:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
session.setBlockChangeLimit(limit);
|
2021-04-06 12:01:04 +00:00
|
|
|
Component component = TextComponent.empty().append(Caption.of("worldedit.limit.set", TextComponent.of(limit)));
|
2019-10-13 11:47:26 +00:00
|
|
|
if (limit != config.defaultChangeLimit) {
|
2021-04-06 12:01:04 +00:00
|
|
|
component.append(TextComponent.space()).append(Caption.of("worldedit.limit.return-to-default"));
|
2019-10-13 11:47:26 +00:00
|
|
|
}
|
2021-04-06 12:01:04 +00:00
|
|
|
actor.print(component);
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/timeout",
|
|
|
|
desc = "Modify evaluation timeout time."
|
2019-07-06 00:46:48 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.timeout")
|
2021-07-24 15:34:05 +00:00
|
|
|
public void timeout(
|
|
|
|
Actor actor, LocalSession session,
|
|
|
|
@Arg(desc = "The timeout time to set", def = "")
|
|
|
|
Integer limit
|
|
|
|
) {
|
2019-07-06 00:46:48 +00:00
|
|
|
LocalConfiguration config = worldEdit.getConfiguration();
|
2019-09-02 19:22:43 +00:00
|
|
|
boolean mayDisable = actor.hasPermission("worldedit.timeout.unrestricted");
|
2019-07-06 00:46:48 +00:00
|
|
|
|
|
|
|
limit = limit == null ? config.calculationTimeout : Math.max(-1, limit);
|
|
|
|
if (!mayDisable && config.maxCalculationTimeout > -1) {
|
|
|
|
if (limit > config.maxCalculationTimeout) {
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.timeout.too-high", TextComponent.of(config.maxCalculationTimeout)));
|
2019-07-06 00:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
session.setTimeout(limit);
|
2021-04-06 12:01:04 +00:00
|
|
|
Component component = TextComponent.empty().append(Caption.of("worldedit.timeout.set", TextComponent.of(limit)));
|
2019-10-13 11:47:26 +00:00
|
|
|
if (limit != config.calculationTimeout) {
|
2021-05-24 09:36:37 +00:00
|
|
|
component.append(Caption.of("worldedit.timeout.return-to-default"));
|
2019-10-13 11:47:26 +00:00
|
|
|
}
|
2021-04-06 12:01:04 +00:00
|
|
|
actor.print(component);
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
|
|
|
|
2020-11-09 09:38:10 +00:00
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/perf",
|
|
|
|
desc = "Toggle side effects for performance",
|
|
|
|
descFooter = "Note that this command is GOING to change in the future." +
|
|
|
|
" Do not depend on the exact format of this command yet."
|
2020-11-09 09:38:10 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.perf")
|
2021-07-24 15:34:05 +00:00
|
|
|
void perf(
|
|
|
|
Actor actor, LocalSession session,
|
|
|
|
@Arg(desc = "The side effect", def = "")
|
|
|
|
SideEffect sideEffect,
|
|
|
|
@Arg(desc = "The new side effect state", def = "")
|
|
|
|
SideEffect.State newState,
|
|
|
|
@Switch(name = 'h', desc = "Show the info box")
|
|
|
|
boolean showInfoBox
|
|
|
|
) throws WorldEditException {
|
2020-03-08 06:09:36 +00:00
|
|
|
if (sideEffect != null) {
|
|
|
|
SideEffect.State currentState = session.getSideEffectSet().getState(sideEffect);
|
|
|
|
if (newState != null && newState == currentState) {
|
|
|
|
if (!showInfoBox) {
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of(
|
2020-11-09 09:38:10 +00:00
|
|
|
"worldedit.perf.sideeffect.already-set",
|
2020-03-08 06:09:36 +00:00
|
|
|
TranslatableComponent.of(sideEffect.getDisplayName()),
|
|
|
|
TranslatableComponent.of(newState.getDisplayName())
|
|
|
|
));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newState != null) {
|
|
|
|
session.setSideEffectSet(session.getSideEffectSet().with(sideEffect, newState));
|
|
|
|
if (!showInfoBox) {
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of(
|
2020-11-09 09:38:10 +00:00
|
|
|
"worldedit.perf.sideeffect.set",
|
2020-03-08 06:09:36 +00:00
|
|
|
TranslatableComponent.of(sideEffect.getDisplayName()),
|
|
|
|
TranslatableComponent.of(newState.getDisplayName())
|
|
|
|
));
|
|
|
|
}
|
|
|
|
} else {
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of(
|
2020-11-09 09:38:10 +00:00
|
|
|
"worldedit.perf.sideeffect.get",
|
2020-03-08 06:09:36 +00:00
|
|
|
TranslatableComponent.of(sideEffect.getDisplayName()),
|
|
|
|
TranslatableComponent.of(currentState.getDisplayName())
|
|
|
|
));
|
|
|
|
}
|
|
|
|
} else if (newState != null) {
|
|
|
|
SideEffectSet applier = session.getSideEffectSet();
|
|
|
|
for (SideEffect sideEffectEntry : SideEffect.values()) {
|
|
|
|
applier = applier.with(sideEffectEntry, newState);
|
|
|
|
}
|
|
|
|
session.setSideEffectSet(applier);
|
|
|
|
if (!showInfoBox) {
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of(
|
2020-11-09 09:38:10 +00:00
|
|
|
"worldedit.perf.sideeffect.set-all",
|
2020-03-08 06:09:36 +00:00
|
|
|
TranslatableComponent.of(newState.getDisplayName())
|
|
|
|
));
|
|
|
|
}
|
2019-07-25 18:44:10 +00:00
|
|
|
}
|
2014-04-03 02:08:50 +00:00
|
|
|
|
2020-03-08 06:09:36 +00:00
|
|
|
if (sideEffect == null || showInfoBox) {
|
|
|
|
SideEffectBox sideEffectBox = new SideEffectBox(session.getSideEffectSet());
|
|
|
|
actor.print(sideEffectBox.create(1));
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/reorder",
|
|
|
|
desc = "Sets the reorder mode of WorldEdit"
|
2019-07-06 00:46:48 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.reorder")
|
2021-07-24 15:34:05 +00:00
|
|
|
public void reorderMode(
|
|
|
|
Actor actor, LocalSession session,
|
|
|
|
@Arg(desc = "The reorder mode", def = "")
|
|
|
|
EditSession.ReorderMode reorderMode
|
|
|
|
) {
|
2019-07-06 00:46:48 +00:00
|
|
|
if (reorderMode == null) {
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.reorder.current", TextComponent.of(session.getReorderMode().getDisplayName())));
|
2019-07-06 00:46:48 +00:00
|
|
|
} else {
|
|
|
|
session.setReorderMode(reorderMode);
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.reorder.set", TextComponent.of(session.getReorderMode().getDisplayName())));
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/drawsel",
|
|
|
|
desc = "Toggle drawing the current selection"
|
2019-07-06 00:46:48 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.drawsel")
|
2021-07-24 15:34:05 +00:00
|
|
|
public void drawSelection(
|
|
|
|
Player player, LocalSession session,
|
|
|
|
@Arg(desc = "The new draw selection state", def = "")
|
|
|
|
Boolean drawSelection
|
|
|
|
) throws WorldEditException {
|
2019-07-06 00:46:48 +00:00
|
|
|
if (!WorldEdit.getInstance().getConfiguration().serverSideCUI) {
|
2021-05-24 09:36:37 +00:00
|
|
|
throw new AuthorizationException(Caption.of("worldedit.error.disabled"));
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
|
|
|
boolean useServerCui = session.shouldUseServerCUI();
|
|
|
|
if (drawSelection != null && drawSelection == useServerCui) {
|
2021-04-05 17:54:49 +00:00
|
|
|
player.print(Caption.of("worldedit.drawsel." + (useServerCui ? "enabled" : "disabled") + ".already"));
|
2019-11-18 09:50:52 +00:00
|
|
|
|
2019-07-06 00:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (useServerCui) {
|
|
|
|
session.setUseServerCUI(false);
|
|
|
|
session.updateServerCUI(player);
|
2021-04-05 17:54:49 +00:00
|
|
|
player.print(Caption.of("worldedit.drawsel.disabled"));
|
2019-07-06 00:46:48 +00:00
|
|
|
} else {
|
|
|
|
session.setUseServerCUI(true);
|
|
|
|
session.updateServerCUI(player);
|
2021-07-23 15:48:51 +00:00
|
|
|
int maxSize = ServerCUIHandler.getMaxServerCuiSize();
|
2021-07-24 15:34:05 +00:00
|
|
|
player.print(Caption.of(
|
|
|
|
"worldedit.drawsel.enabled",
|
|
|
|
TextComponent.of(maxSize),
|
|
|
|
TextComponent.of(maxSize),
|
|
|
|
TextComponent.of(maxSize)
|
|
|
|
));
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-25 09:58:28 +00:00
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/world",
|
|
|
|
desc = "Sets the world override"
|
2019-08-25 09:58:28 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.world")
|
2021-07-24 15:34:05 +00:00
|
|
|
public void world(
|
|
|
|
Actor actor, LocalSession session,
|
|
|
|
@Arg(desc = "The world override", def = "") World world
|
|
|
|
) {
|
2019-08-25 09:58:28 +00:00
|
|
|
session.setWorldOverride(world);
|
|
|
|
if (world == null) {
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.world.remove"));
|
2019-08-25 09:58:28 +00:00
|
|
|
} else {
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.world.set", TextComponent.of(world.getId())));
|
2019-08-25 09:58:28 +00:00
|
|
|
}
|
|
|
|
}
|
2019-09-02 19:22:43 +00:00
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/watchdog",
|
|
|
|
desc = "Changes watchdog hook state.",
|
|
|
|
descFooter = "This is dependent on platform implementation. " +
|
|
|
|
"Not all platforms support watchdog hooks, or contain a watchdog."
|
2019-09-05 05:50:14 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.watchdog")
|
2021-07-24 15:34:05 +00:00
|
|
|
public void watchdog(
|
|
|
|
Actor actor, LocalSession session,
|
|
|
|
@Arg(desc = "The mode to set the watchdog hook to", def = "")
|
|
|
|
HookMode hookMode
|
|
|
|
) {
|
2019-09-05 05:50:14 +00:00
|
|
|
if (WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getWatchdog() == null) {
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.watchdog.no-hook"));
|
2019-09-05 05:50:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
boolean previousMode = session.isTickingWatchdog();
|
|
|
|
if (hookMode != null && (hookMode == HookMode.ACTIVE) == previousMode) {
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of(previousMode ? "worldedit.watchdog.active.already" : "worldedit.watchdog.inactive.already"));
|
2019-09-05 05:50:14 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
session.setTickingWatchdog(!previousMode);
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of(previousMode ? "worldedit.watchdog.inactive" : "worldedit.watchdog.active"));
|
2019-09-05 05:50:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "gmask",
|
|
|
|
aliases = {"/gmask"},
|
|
|
|
desc = "Set the global mask"
|
2019-07-06 00:46:48 +00:00
|
|
|
)
|
2014-04-03 02:08:50 +00:00
|
|
|
@CommandPermissions("worldedit.global-mask")
|
2021-07-24 15:34:05 +00:00
|
|
|
public void gmask(
|
|
|
|
Actor actor, LocalSession session,
|
|
|
|
@Arg(desc = "The mask to set", def = "")
|
|
|
|
Mask mask
|
|
|
|
) {
|
2019-09-02 19:22:43 +00:00
|
|
|
if (mask == null) {
|
2019-05-27 22:26:20 +00:00
|
|
|
session.setMask(null);
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.gmask.disabled"));
|
2019-07-06 00:46:48 +00:00
|
|
|
} else {
|
2014-04-03 02:08:50 +00:00
|
|
|
session.setMask(mask);
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.gmask.set"));
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "toggleplace",
|
|
|
|
aliases = {"/toggleplace"},
|
|
|
|
desc = "Switch between your position and pos1 for placement"
|
2019-07-06 00:46:48 +00:00
|
|
|
)
|
2020-11-13 20:08:57 +00:00
|
|
|
@CommandPermissions("worldedit.toggleplace")
|
2021-04-10 09:15:41 +00:00
|
|
|
public void togglePlace(Actor actor, LocalSession session) {
|
|
|
|
if (!(actor instanceof Locatable)) {
|
|
|
|
actor.print(Caption.of("worldedit.toggleplace.not-locatable"));
|
|
|
|
return;
|
|
|
|
}
|
2019-07-06 00:46:48 +00:00
|
|
|
if (session.togglePlacementPosition()) {
|
2021-04-10 09:15:41 +00:00
|
|
|
actor.print(Caption.of("worldedit.toggleplace.pos1"));
|
2019-07-06 00:46:48 +00:00
|
|
|
} else {
|
2021-04-10 09:15:41 +00:00
|
|
|
actor.print(Caption.of("worldedit.toggleplace.player"));
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "searchitem",
|
|
|
|
aliases = {"/searchitem", "/l", "/search"},
|
|
|
|
desc = "Search for an item"
|
2019-07-06 00:46:48 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.searchitem")
|
2021-07-24 15:34:05 +00:00
|
|
|
public void searchItem(
|
|
|
|
Actor actor,
|
|
|
|
@Switch(name = 'b', desc = "Only search for blocks")
|
|
|
|
boolean blocksOnly,
|
|
|
|
@Switch(name = 'i', desc = "Only search for items")
|
|
|
|
boolean itemsOnly,
|
|
|
|
@ArgFlag(name = 'p', desc = "Page of results to return", def = "1")
|
|
|
|
int page,
|
|
|
|
@Arg(desc = "Search query", variable = true)
|
|
|
|
List<String> query
|
|
|
|
) {
|
2019-07-06 00:46:48 +00:00
|
|
|
String search = String.join(" ", query);
|
|
|
|
if (search.length() <= 2) {
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.searchitem.too-short"));
|
2019-07-06 00:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (blocksOnly && itemsOnly) {
|
2021-04-05 17:54:49 +00:00
|
|
|
actor.print(Caption.of("worldedit.searchitem.either-b-or-i"));
|
2019-07-06 00:46:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-11-09 09:38:10 +00:00
|
|
|
WorldEditAsyncCommandBuilder.createAndSendMessage(actor, new ItemSearcher(search, blocksOnly, itemsOnly, page),
|
2021-07-24 15:34:05 +00:00
|
|
|
Caption.of("worldedit.searchitem.searching")
|
|
|
|
);
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|
|
|
|
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE start
|
2019-07-17 10:50:54 +00:00
|
|
|
@Command(
|
|
|
|
name = "/gtexture",
|
|
|
|
aliases = {"gtexture"},
|
2019-11-11 21:02:28 +00:00
|
|
|
descFooter = "The global destination mask applies to all edits you do and masks based on the destination blocks (i.e., the blocks in the world).",
|
2019-07-17 10:50:54 +00:00
|
|
|
desc = "Set the global mask"
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.global-texture")
|
2021-07-24 15:34:05 +00:00
|
|
|
public void gtexture(
|
|
|
|
Player player,
|
|
|
|
World worldArg,
|
|
|
|
LocalSession session,
|
|
|
|
EditSession editSession,
|
|
|
|
@Arg(name = "context", desc = "InjectedValueAccess", def = "") List<String> arguments
|
|
|
|
) throws WorldEditException, FileNotFoundException {
|
2019-07-22 09:05:14 +00:00
|
|
|
// gtexture <randomize> <min=0> <max=100>
|
|
|
|
// TODO NOT IMPLEMENTED convert this to an ArgumentConverter
|
|
|
|
if (arguments.isEmpty()) {
|
2019-07-17 10:50:54 +00:00
|
|
|
session.setTextureUtil(null);
|
2021-05-24 09:36:37 +00:00
|
|
|
player.print(Caption.of("fawe.worldedit.general.texture.disabled"));
|
2019-07-17 10:50:54 +00:00
|
|
|
} else {
|
2019-07-22 09:05:14 +00:00
|
|
|
String arg = arguments.get(0);
|
2019-07-25 18:44:10 +00:00
|
|
|
String argLower = arg.toLowerCase(Locale.ROOT);
|
2019-07-17 10:50:54 +00:00
|
|
|
|
|
|
|
TextureUtil util = Fawe.get().getTextureUtil();
|
|
|
|
int randomIndex = 1;
|
|
|
|
boolean checkRandomization = true;
|
2019-07-22 09:05:14 +00:00
|
|
|
if (arguments.size() >= 2 && MathMan.isInteger(arguments.get(0)) && MathMan.isInteger(arguments.get(1))) {
|
2019-07-17 10:50:54 +00:00
|
|
|
// complexity
|
2019-07-22 09:05:14 +00:00
|
|
|
int min = Integer.parseInt(arguments.get(0));
|
|
|
|
int max = Integer.parseInt(arguments.get(1));
|
2020-10-05 17:41:41 +00:00
|
|
|
if (min < 0 || max > 100) {
|
2021-05-24 09:36:37 +00:00
|
|
|
throw new InputParseException(Caption.of("fawe.error.too-simple"));
|
2020-10-05 17:41:41 +00:00
|
|
|
}
|
|
|
|
if (min != 0 || max != 100) {
|
|
|
|
util = new CleanTextureUtil(util, min, max);
|
|
|
|
}
|
2019-07-17 10:50:54 +00:00
|
|
|
|
|
|
|
randomIndex = 2;
|
2019-07-22 09:05:14 +00:00
|
|
|
} else if (arguments.size() == 1 && argLower.equals("true") || argLower.equals("false")) {
|
2020-10-05 17:41:41 +00:00
|
|
|
if (argLower.equals("true")) {
|
|
|
|
util = new RandomTextureUtil(util);
|
|
|
|
}
|
2019-07-17 10:50:54 +00:00
|
|
|
checkRandomization = false;
|
|
|
|
} else {
|
|
|
|
if (argLower.equals("#copy") || argLower.equals("#clipboard")) {
|
2019-07-28 19:26:44 +00:00
|
|
|
Clipboard clipboard = session.getClipboard().getClipboard();
|
2019-07-17 10:50:54 +00:00
|
|
|
util = TextureUtil.fromClipboard(clipboard);
|
|
|
|
} else if (argLower.equals("*") || argLower.equals("true")) {
|
|
|
|
util = Fawe.get().getTextureUtil();
|
|
|
|
} else {
|
|
|
|
ParserContext parserContext = new ParserContext();
|
2019-07-25 18:44:10 +00:00
|
|
|
parserContext.setActor(player);
|
2019-11-20 00:11:54 +00:00
|
|
|
parserContext.setWorld(worldArg);
|
2019-07-17 10:50:54 +00:00
|
|
|
parserContext.setSession(session);
|
|
|
|
parserContext.setExtent(editSession);
|
|
|
|
Mask mask = worldEdit.getMaskFactory().parseFromInput(arg, parserContext);
|
|
|
|
util = TextureUtil.fromMask(mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (checkRandomization) {
|
2019-07-22 09:05:14 +00:00
|
|
|
if (arguments.size() > randomIndex) {
|
|
|
|
boolean random = Boolean.parseBoolean(arguments.get(randomIndex));
|
2020-10-05 17:41:41 +00:00
|
|
|
if (random) {
|
|
|
|
util = new RandomTextureUtil(util);
|
|
|
|
}
|
2019-07-17 10:50:54 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-05 17:41:41 +00:00
|
|
|
if (!(util instanceof CachedTextureUtil)) {
|
|
|
|
util = new CachedTextureUtil(util);
|
|
|
|
}
|
2019-07-17 10:50:54 +00:00
|
|
|
session.setTextureUtil(util);
|
2020-10-05 17:41:41 +00:00
|
|
|
player.print(Caption.of("fawe.worldedit.general.texture.set", StringMan.join(arguments, " ")));
|
2019-07-17 10:50:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/gsmask",
|
|
|
|
aliases = {"gsmask", "globalsourcemask", "/globalsourcemask"},
|
|
|
|
desc = "Set the global source mask",
|
|
|
|
descFooter = "The global source mask applies to all edits you do and masks based on the source blocks (e.g., the blocks in your clipboard)"
|
2019-07-17 10:50:54 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions({"worldedit.global-mask", "worldedit.mask.global"})
|
2021-07-24 15:34:05 +00:00
|
|
|
public void gsmask(
|
|
|
|
Player player,
|
|
|
|
LocalSession session,
|
|
|
|
EditSession editSession,
|
|
|
|
@Arg(desc = "The mask to set", def = "") Mask maskOpt
|
|
|
|
) throws WorldEditException {
|
2019-08-06 20:18:44 +00:00
|
|
|
session.setSourceMask(maskOpt);
|
|
|
|
if (maskOpt == null) {
|
2021-05-24 09:36:37 +00:00
|
|
|
player.print(Caption.of("fawe.worldedit.general.source.mask.disabled"));
|
2019-07-17 10:50:54 +00:00
|
|
|
} else {
|
2021-05-24 09:36:37 +00:00
|
|
|
player.print(Caption.of("fawe.worldedit.general.source.mask"));
|
2019-07-17 10:50:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/gtransform",
|
|
|
|
aliases = {"gtransform"},
|
|
|
|
desc = "Set the global transform"
|
2019-07-17 10:50:54 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions({"worldedit.global-transform", "worldedit.transform.global"})
|
2021-08-16 09:03:06 +00:00
|
|
|
public void gtransform(
|
|
|
|
Player player,
|
|
|
|
EditSession editSession,
|
|
|
|
LocalSession session,
|
|
|
|
@Arg(desc = "The transform to set", def = "") ResettableExtent transform
|
|
|
|
) throws WorldEditException {
|
2019-07-21 11:39:36 +00:00
|
|
|
session.setTransform(transform);
|
|
|
|
if (transform == null) {
|
2021-05-24 09:36:37 +00:00
|
|
|
player.print(Caption.of("fawe.worldedit.general.transform.disabled"));
|
2019-07-17 10:50:54 +00:00
|
|
|
} else {
|
2021-05-24 09:36:37 +00:00
|
|
|
player.print(Caption.of("fawe.worldedit.general.transform"));
|
2019-07-17 10:50:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Command(
|
2021-07-24 15:34:05 +00:00
|
|
|
name = "/tips",
|
|
|
|
aliases = {"tips"},
|
|
|
|
desc = "Toggle FAWE tips"
|
2019-07-17 10:50:54 +00:00
|
|
|
)
|
|
|
|
@CommandPermissions("fawe.tips")
|
|
|
|
public void tips(Player player, LocalSession session) throws WorldEditException {
|
|
|
|
if (player.togglePermission("fawe.tips")) {
|
2021-05-24 09:36:37 +00:00
|
|
|
player.print(Caption.of("fawe.info.worldedit.toggle.tips.on"));
|
2019-07-17 10:50:54 +00:00
|
|
|
} else {
|
2021-05-24 09:36:37 +00:00
|
|
|
player.print(Caption.of("fawe.info.worldedit.toggle.tips.off"));
|
2019-07-17 10:50:54 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-23 15:48:51 +00:00
|
|
|
|
|
|
|
@Command(
|
|
|
|
name = "/fast",
|
|
|
|
desc = "Toggle fast mode"
|
|
|
|
)
|
|
|
|
@CommandPermissions("worldedit.fast")
|
|
|
|
@Deprecated
|
2021-07-24 15:34:05 +00:00
|
|
|
void fast(
|
|
|
|
Actor actor, LocalSession session,
|
|
|
|
@Arg(desc = "The new fast mode state", def = "")
|
|
|
|
Boolean fastMode
|
|
|
|
) {
|
2021-07-23 15:48:51 +00:00
|
|
|
boolean hasFastMode = session.hasFastMode();
|
|
|
|
if (fastMode != null && fastMode == hasFastMode) {
|
|
|
|
actor.print(Caption.of(fastMode ? "worldedit.fast.enabled.already" : "worldedit.fast.disabled.already"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasFastMode) {
|
|
|
|
session.setFastMode(false);
|
|
|
|
actor.print(Caption.of("worldedit.fast.disabled"));
|
|
|
|
} else {
|
|
|
|
session.setFastMode(true);
|
|
|
|
actor.print(Caption.of("worldedit.fast.enabled"));
|
|
|
|
}
|
|
|
|
}
|
2021-08-16 09:03:06 +00:00
|
|
|
|
|
|
|
private static class ItemSearcher implements Callable<Component> {
|
|
|
|
|
|
|
|
private final boolean blocksOnly;
|
|
|
|
private final boolean itemsOnly;
|
|
|
|
private final String search;
|
|
|
|
private final int page;
|
|
|
|
|
|
|
|
ItemSearcher(String search, boolean blocksOnly, boolean itemsOnly, int page) {
|
|
|
|
this.blocksOnly = blocksOnly;
|
|
|
|
this.itemsOnly = itemsOnly;
|
|
|
|
this.search = search;
|
|
|
|
this.page = page;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Component call() throws Exception {
|
|
|
|
String command = "/searchitem " + (blocksOnly ? "-b " : "") + (itemsOnly ? "-i " : "") + "-p %page% " + search;
|
|
|
|
Map<String, Component> results = new TreeMap<>();
|
|
|
|
String idMatch = search.replace(' ', '_');
|
|
|
|
String nameMatch = search.toLowerCase(Locale.ROOT);
|
|
|
|
for (ItemType searchType : ItemType.REGISTRY) {
|
|
|
|
if (blocksOnly && !searchType.hasBlockType()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemsOnly && searchType.hasBlockType()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
final String id = searchType.getId();
|
|
|
|
if (id.contains(idMatch)) {
|
|
|
|
Component name = searchType.getRichName();
|
|
|
|
results.put(id, TextComponent.builder()
|
|
|
|
.append(name)
|
|
|
|
.append(" (" + id + ")")
|
|
|
|
.build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<Component> list = new ArrayList<>(results.values());
|
|
|
|
return PaginationBox.fromComponents("Search results for '" + search + "'", command, list)
|
|
|
|
.create(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-07-23 15:48:51 +00:00
|
|
|
//FAWE end
|
2019-07-06 00:46:48 +00:00
|
|
|
}
|