3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-08 04:20:06 +01:00

Allow expand to be used by console. (#1264)

* Allow expand to be used by console.

Also fix direction converter requiring a player.

* Revert exception.

(cherry picked from commit b4d2db3dee01d6af4f49d6ee1ea015dbd685839c)
Dieser Commit ist enthalten in:
wizjany 2020-03-19 21:36:54 -04:00 committet von MattBDev
Ursprung 989680d159
Commit dabba81902
2 geänderte Dateien mit 13 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -93,29 +93,30 @@ public class ExpandCommands {
.action(parameters -> { .action(parameters -> {
expandVert( expandVert(
requireIV(Key.of(LocalSession.class), "localSession", parameters), requireIV(Key.of(LocalSession.class), "localSession", parameters),
requireIV(Key.of(Player.class), "localSession", parameters) requireIV(Key.of(Actor.class), "actor", parameters),
requireIV(Key.of(World.class), "world", parameters)
); );
return 1; return 1;
}) })
.build(); .build();
} }
private static void expandVert(LocalSession session, Player player) throws IncompleteRegionException { private static void expandVert(LocalSession session, Actor actor, World world) throws IncompleteRegionException {
Region region = session.getSelection(player.getWorld()); Region region = session.getSelection(world);
try { try {
int oldSize = region.getArea(); int oldSize = region.getArea();
region.expand( region.expand(
BlockVector3.at(0, (player.getWorld().getMaxY() + 1), 0), BlockVector3.at(0, (world.getMaxY() + 1), 0),
BlockVector3.at(0, -(player.getWorld().getMaxY() + 1), 0)); BlockVector3.at(0, -(world.getMaxY() + 1), 0));
session.getRegionSelector(player.getWorld()).learnChanges(); session.getRegionSelector(world).learnChanges();
int newSize = region.getArea(); int newSize = region.getArea();
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session); session.getRegionSelector(world).explainRegionAdjust(actor, session);
int changeSize = newSize - oldSize; int changeSize = newSize - oldSize;
player.printInfo( actor.printInfo(
TranslatableComponent.of("worldedit.expand.expanded.vert", TextComponent.of(changeSize)) TranslatableComponent.of("worldedit.expand.expanded.vert", TextComponent.of(changeSize))
); );
} catch (RegionOperationException e) { } catch (RegionOperationException e) {
player.printError(TextComponent.of(e.getMessage())); actor.printError(TextComponent.of(e.getMessage()));
} }
} }

Datei anzeigen

@ -25,6 +25,7 @@ import com.google.common.collect.ImmutableSet;
import com.sk89q.worldedit.UnknownDirectionException; import com.sk89q.worldedit.UnknownDirectionException;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.internal.annotation.Direction; import com.sk89q.worldedit.internal.annotation.Direction;
import com.sk89q.worldedit.internal.annotation.MultiDirection; import com.sk89q.worldedit.internal.annotation.MultiDirection;
import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.Component;
@ -92,7 +93,8 @@ public abstract class AbstractDirectionConverter<D> implements ArgumentConverter
@Override @Override
public ConversionResult<D> convert(String argument, InjectedValueAccess context) { public ConversionResult<D> convert(String argument, InjectedValueAccess context) {
Player player = context.injectedValue(Key.of(Player.class)).orElse(null); Player player = context.injectedValue(Key.of(Actor.class))
.filter(Player.class::isInstance).map(Player.class::cast).orElse(null);
try { try {
return SuccessfulConversion.fromSingle(convertDirection(argument, player, includeDiagonals)); return SuccessfulConversion.fromSingle(convertDirection(argument, player, includeDiagonals));
} catch (Exception e) { } catch (Exception e) {