mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 02:46:41 +00:00
feature(cli): Added a CLI version of WorldEdit, and allowed most commands to be run from console (#508)
* Re-do commits to avoid awful rebase * You can load and save a schematic file now. Still gotta setup ability to use commands as a console actor. * Add a world override concept to LocalSession, and allow a lot more commands to be performed by actors. * Fixed commands, and set the loaded schematic as the world override in CLI * Properly load tags * Added 1.14.4 data values * Allow a majority of commands to be performed by the console. * Fixed a lot of PR requested changes * Added a Locatable interface and use that for getting the location of the player in commands. * Added script support. Currently requires a newline at the end of the script. * Shade everything to allow this to run locally - should probably minimize this to an extent later. * Actually hook up the version * Added a //world command to set the override * Fixed a missed checkstyle issue * Added CommandBlock support to Bukkit * Make command block support configurable * Minor cleanup and implementing a few of the final functions * Fixed most issues from PR * Improve UX, saving is now automatic and unknown command messages show * Better save docs and support any clipboard format * Include the entire formats list * Arrays.copyOf * Clear the world override if the selector is called on another world. * Update logging extent to allow basic logging with non-player actors
This commit is contained in:
@ -26,6 +26,7 @@ import com.sk89q.worldedit.command.util.Logging;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.math.Vector3;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import org.enginehub.piston.CommandParameters;
|
||||
import org.enginehub.piston.gen.CommandCallListener;
|
||||
import org.enginehub.piston.inject.Key;
|
||||
@ -72,18 +73,18 @@ public class CommandLoggingHandler implements CommandCallListener, AutoCloseable
|
||||
logMode = loggingAnnotation.value();
|
||||
}
|
||||
|
||||
Optional<Player> playerOpt = parameters.injectedValue(Key.of(Actor.class))
|
||||
.filter(Player.class::isInstance)
|
||||
.map(Player.class::cast);
|
||||
Optional<Actor> playerOpt = parameters.injectedValue(Key.of(Actor.class));
|
||||
Optional<World> worldOpt = parameters.injectedValue(Key.of(World.class));
|
||||
|
||||
if (!playerOpt.isPresent()) {
|
||||
if (!playerOpt.isPresent() || !worldOpt.isPresent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = playerOpt.get();
|
||||
Actor actor = playerOpt.get();
|
||||
World world = worldOpt.get();
|
||||
|
||||
builder.append("WorldEdit: ").append(player.getName());
|
||||
builder.append(" (in \"").append(player.getWorld().getName()).append("\")");
|
||||
builder.append("WorldEdit: ").append(actor.getName());
|
||||
builder.append(" (in \"").append(world.getName()).append("\")");
|
||||
|
||||
builder.append(": ").append(parameters.getMetadata().getCalledName());
|
||||
|
||||
@ -93,14 +94,15 @@ public class CommandLoggingHandler implements CommandCallListener, AutoCloseable
|
||||
parameters.getMetadata().getArguments().stream()
|
||||
).collect(Collectors.joining(" ")));
|
||||
|
||||
if (logMode != null) {
|
||||
if (logMode != null && actor instanceof Player) {
|
||||
Player player = (Player) actor;
|
||||
Vector3 position = player.getLocation().toVector();
|
||||
LocalSession session = worldEdit.getSessionManager().get(player);
|
||||
LocalSession session = worldEdit.getSessionManager().get(actor);
|
||||
|
||||
switch (logMode) {
|
||||
case PLACEMENT:
|
||||
try {
|
||||
position = session.getPlacementPosition(player).toVector3();
|
||||
position = session.getPlacementPosition(actor).toVector3();
|
||||
} catch (IncompleteRegionException e) {
|
||||
break;
|
||||
}
|
||||
@ -121,7 +123,7 @@ public class CommandLoggingHandler implements CommandCallListener, AutoCloseable
|
||||
case REGION:
|
||||
try {
|
||||
builder.append(" - Region: ")
|
||||
.append(session.getSelection(player.getWorld()));
|
||||
.append(session.getSelection(world));
|
||||
} catch (IncompleteRegionException e) {
|
||||
break;
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ import com.sk89q.worldedit.InvalidItemException;
|
||||
import com.sk89q.worldedit.MaxBrushRadiusException;
|
||||
import com.sk89q.worldedit.MaxChangedBlocksException;
|
||||
import com.sk89q.worldedit.MaxRadiusException;
|
||||
import com.sk89q.worldedit.MissingWorldException;
|
||||
import com.sk89q.worldedit.UnknownDirectionException;
|
||||
import com.sk89q.worldedit.UnknownItemException;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
@ -81,6 +82,11 @@ public class WorldEditExceptionConverter extends ExceptionConverterHelper {
|
||||
throw newCommandException("Make a region selection first.", e);
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(MissingWorldException e) throws CommandException {
|
||||
throw newCommandException("You need to provide a world (Try //world)", e);
|
||||
}
|
||||
|
||||
@ExceptionMatch
|
||||
public void convert(UnknownItemException e) throws CommandException {
|
||||
throw newCommandException("Block name '" + e.getID() + "' was not recognized.", e);
|
||||
|
Reference in New Issue
Block a user