mirror of
https://github.com/EngineHub/WorldEdit.git
synced 2025-01-24 12:44:56 +08: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.
This commit is contained in:
parent
47db40f957
commit
b4d2db3dee
@ -93,29 +93,30 @@ private static Command createVertCommand(CommandManager commandManager) {
|
||||
.action(parameters -> {
|
||||
expandVert(
|
||||
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;
|
||||
})
|
||||
.build();
|
||||
}
|
||||
|
||||
private static void expandVert(LocalSession session, Player player) throws IncompleteRegionException {
|
||||
Region region = session.getSelection(player.getWorld());
|
||||
private static void expandVert(LocalSession session, Actor actor, World world) throws IncompleteRegionException {
|
||||
Region region = session.getSelection(world);
|
||||
try {
|
||||
int oldSize = region.getArea();
|
||||
region.expand(
|
||||
BlockVector3.at(0, (player.getWorld().getMaxY() + 1), 0),
|
||||
BlockVector3.at(0, -(player.getWorld().getMaxY() + 1), 0));
|
||||
session.getRegionSelector(player.getWorld()).learnChanges();
|
||||
BlockVector3.at(0, (world.getMaxY() + 1), 0),
|
||||
BlockVector3.at(0, -(world.getMaxY() + 1), 0));
|
||||
session.getRegionSelector(world).learnChanges();
|
||||
int newSize = region.getArea();
|
||||
session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);
|
||||
session.getRegionSelector(world).explainRegionAdjust(actor, session);
|
||||
int changeSize = newSize - oldSize;
|
||||
player.printInfo(
|
||||
actor.printInfo(
|
||||
TranslatableComponent.of("worldedit.expand.expanded.vert", TextComponent.of(changeSize))
|
||||
);
|
||||
} catch (RegionOperationException e) {
|
||||
player.printError(TextComponent.of(e.getMessage()));
|
||||
actor.printError(TextComponent.of(e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
import com.sk89q.worldedit.UnknownDirectionException;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
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.MultiDirection;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
@ -92,7 +93,8 @@ protected AbstractDirectionConverter(WorldEdit worldEdit, boolean includeDiagona
|
||||
|
||||
@Override
|
||||
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 {
|
||||
return SuccessfulConversion.fromSingle(convertDirection(argument, player, includeDiagonals));
|
||||
} catch (Exception e) {
|
||||
|
@ -107,8 +107,6 @@
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import org.enginehub.piston.Command;
|
||||
import org.enginehub.piston.CommandManager;
|
||||
import org.enginehub.piston.config.ConfigHolder;
|
||||
import org.enginehub.piston.config.TextConfig;
|
||||
import org.enginehub.piston.converter.ArgumentConverters;
|
||||
import org.enginehub.piston.exception.CommandException;
|
||||
import org.enginehub.piston.exception.CommandExecutionException;
|
||||
|
Loading…
Reference in New Issue
Block a user