More upstream compatibility fixes

This commit is contained in:
MattBDev 2019-09-03 13:40:20 -04:00
parent e88adea066
commit cafb4120ef
8 changed files with 232 additions and 207 deletions

View File

@ -76,6 +76,15 @@ public class ToolCommands {
this.we = we;
}
@Command(
name = "none",
desc = "Unbind a bound tool from your current item"
)
public void none(Player player, LocalSession session) throws WorldEditException {
session.setTool(player.getItemInHand(HandSide.MAIN_HAND).getType(), null);
player.print("Tool unbound from your current item.");
}
@Command(
name = "/selwand",
aliases = "selwand",

View File

@ -191,7 +191,7 @@ public class UtilityCommands {
)
@CommandPermissions("worldedit.fill")
@Logging(PLACEMENT)
public int fill(Player player, LocalSession session, EditSession editSession,
public int fill(Actor actor, LocalSession session, EditSession editSession,
@Arg(desc = "The blocks to fill with")
Pattern pattern,
@Range(min=1) @Arg(desc = "The radius to fill in")
@ -204,9 +204,9 @@ public class UtilityCommands {
we.checkMaxRadius(radius);
depth = Math.max(1, depth);
BlockVector3 pos = session.getPlacementPosition(player);
BlockVector3 pos = session.getPlacementPosition(actor);
int affected = editSession.fillDirection(pos, pattern, radius, depth, direction);
player.print(affected + " block(s) have been created.");
actor.print(affected + " block(s) have been created.");
return affected;
}
@ -287,7 +287,7 @@ public class UtilityCommands {
)
@CommandPermissions("worldedit.fill.recursive")
@Logging(PLACEMENT)
public int fillr(Player player, LocalSession session, EditSession editSession,
public int fillr(Actor actor, LocalSession session, EditSession editSession,
@Arg(desc = "The blocks to fill with")
Pattern pattern,
@Range(min=1) @Arg(desc = "The radius to fill in")
@ -300,9 +300,9 @@ public class UtilityCommands {
depth = depth == null ? Integer.MAX_VALUE : Math.max(1, depth);
we.checkMaxRadius(radius);
BlockVector3 pos = session.getPlacementPosition(player);
BlockVector3 pos = session.getPlacementPosition(actor);
int affected = editSession.fillXZ(pos, pattern, radius, depth, true);
player.print(affected + " block(s) have been created.");
actor.print(affected + " block(s) have been created.");
return affected;
}
@ -312,7 +312,7 @@ public class UtilityCommands {
)
@CommandPermissions("worldedit.drain")
@Logging(PLACEMENT)
public int drain(Player player, LocalSession session, EditSession editSession,
public int drain(Actor actor, LocalSession session, EditSession editSession,
@Range(min=0) @Arg(desc = "The radius to drain")
Expression radiusExp,
@Switch(name = 'w', desc = "Also un-waterlog blocks")
@ -321,8 +321,8 @@ public class UtilityCommands {
radius = Math.max(0, radius);
we.checkMaxRadius(radius);
int affected = editSession.drainArea(
session.getPlacementPosition(player), radius, waterlogged);
player.print(affected + " block(s) have been changed.");
session.getPlacementPosition(actor), radius, waterlogged);
actor.print(affected + " block(s) have been changed.");
return affected;
}
@ -333,14 +333,14 @@ public class UtilityCommands {
)
@CommandPermissions("worldedit.fixlava")
@Logging(PLACEMENT)
public int fixLava(Player player, LocalSession session, EditSession editSession,
public int fixLava(Actor actor, LocalSession session, EditSession editSession,
@Range(min=0) @Arg(desc = "The radius to fix in")
Expression radiusExp) throws WorldEditException, EvaluationException {
double radius = radiusExp.evaluate();
radius = Math.max(0, radius);
we.checkMaxRadius(radius);
int affected = editSession.fixLiquid(session.getPlacementPosition(player), radius, BlockTypes.LAVA);
player.print(affected + " block(s) have been changed.");
int affected = editSession.fixLiquid(session.getPlacementPosition(actor), radius, BlockTypes.LAVA);
actor.print(affected + " block(s) have been changed.");
return affected;
}
@ -351,14 +351,14 @@ public class UtilityCommands {
)
@CommandPermissions("worldedit.fixwater")
@Logging(PLACEMENT)
public int fixWater(Player player, LocalSession session, EditSession editSession,
public int fixWater(Actor actor, LocalSession session, EditSession editSession,
@Range(min=0) @Arg(desc = "The radius to fix in")
Expression radiusExp) throws WorldEditException, EvaluationException {
double radius = radiusExp.evaluate();
radius = Math.max(0, radius);
we.checkMaxRadius(radius);
int affected = editSession.fixLiquid(session.getPlacementPosition(player), radius, BlockTypes.WATER);
BBC.VISITOR_BLOCK.send(player, affected);
int affected = editSession.fixLiquid(session.getPlacementPosition(actor), radius, BlockTypes.WATER);
BBC.VISITOR_BLOCK.send(actor, affected);
return affected;
}
@ -369,17 +369,16 @@ public class UtilityCommands {
)
@CommandPermissions("worldedit.removeabove")
@Logging(PLACEMENT)
public int removeAbove(Player player, LocalSession session, EditSession editSession,
public int removeAbove(Actor actor, World world, LocalSession session, EditSession editSession,
@Range(min=1) @Arg(name = "size", desc = "The apothem of the square to remove from", def = "1")
int sizeOpt,
int size,
@Arg(desc = "The maximum height above you to remove from", def = "")
Integer height) throws WorldEditException {
sizeOpt = Math.max(1, sizeOpt);
we.checkMaxRadius(sizeOpt);
World world = player.getWorld();
size = Math.max(1, size);
we.checkMaxRadius(size);
height = height != null ? Math.min((world.getMaxY() + 1), height + 1) : (world.getMaxY() + 1);
int affected = editSession.removeAbove(session.getPlacementPosition(player), sizeOpt, height);
BBC.VISITOR_BLOCK.send(player, affected);
int affected = editSession.removeAbove(session.getPlacementPosition(actor), size, height);
BBC.VISITOR_BLOCK.send(actor, affected);
return affected;
}
@ -390,18 +389,17 @@ public class UtilityCommands {
)
@CommandPermissions("worldedit.removebelow")
@Logging(PLACEMENT)
public int removeBelow(Player player, LocalSession session, EditSession editSession,
public int removeBelow(Actor actor, World world, LocalSession session, EditSession editSession,
@Arg(name = "size", desc = "The apothem of the square to remove from", def = "1")
int sizeOpt,
int size,
@Arg(desc = "The maximum height below you to remove from", def = "")
Integer height) throws WorldEditException {
sizeOpt = Math.max(1, sizeOpt);
we.checkMaxRadius(sizeOpt);
World world = player.getWorld();
size = Math.max(1, size);
we.checkMaxRadius(size);
height = height != null ? Math.min((world.getMaxY() + 1), height + 1) : (world.getMaxY() + 1);
int affected = editSession.removeBelow(session.getPlacementPosition(player), sizeOpt, height);
BBC.VISITOR_BLOCK.send(player, affected);
int affected = editSession.removeBelow(session.getPlacementPosition(actor), size, height);
BBC.VISITOR_BLOCK.send(actor, affected);
return affected;
}
@ -412,7 +410,7 @@ public class UtilityCommands {
)
@CommandPermissions("worldedit.removenear")
@Logging(PLACEMENT)
public int removeNear(Player player, LocalSession session, EditSession editSession,
public int removeNear(Actor actor, LocalSession session, EditSession editSession,
@Arg(desc = "The mask of blocks to remove")
Mask mask,
@Range(min=1) @Arg(desc = "The radius of the square to remove from", def = "50")
@ -420,8 +418,8 @@ public class UtilityCommands {
radius = Math.max(1, radius);
we.checkMaxRadius(radius);
int affected = editSession.removeNear(session.getPlacementPosition(player), mask, radius);
BBC.VISITOR_BLOCK.send(player, affected);
int affected = editSession.removeNear(session.getPlacementPosition(actor), mask, radius);
BBC.VISITOR_BLOCK.send(actor, affected);
return affected;
}
@ -432,7 +430,7 @@ public class UtilityCommands {
)
@CommandPermissions("worldedit.replacenear")
@Logging(PLACEMENT)
public int replaceNear(Player player, LocalSession session, EditSession editSession,
public int replaceNear(Actor actor, World world, LocalSession session, EditSession editSession,
@Range(min=1) @Arg(desc = "The radius of the square to remove in")
int radius,
@Arg(desc = "The mask matching blocks to remove", def = "")
@ -442,17 +440,17 @@ public class UtilityCommands {
radius = Math.max(1, radius);
we.checkMaxRadius(radius);
BlockVector3 base = session.getPlacementPosition(player);
BlockVector3 base = session.getPlacementPosition(actor);
BlockVector3 min = base.subtract(radius, radius, radius);
BlockVector3 max = base.add(radius, radius, radius);
Region region = new CuboidRegion(player.getWorld(), min, max);
Region region = new CuboidRegion(world, min, max);
if (from == null) {
from = new ExistingBlockMask(editSession);
}
int affected = editSession.replaceBlocks(region, from, to);
BBC.VISITOR_BLOCK.send(player, affected);
BBC.VISITOR_BLOCK.send(actor, affected);
return affected;
}
@ -463,14 +461,14 @@ public class UtilityCommands {
)
@CommandPermissions("worldedit.snow")
@Logging(PLACEMENT)
public int snow(Player player, LocalSession session, EditSession editSession,
public int snow(Actor actor, LocalSession session, EditSession editSession,
@Range(min=1) @Arg(desc = "The radius of the circle to snow in", def = "10")
double sizeOpt) throws WorldEditException {
sizeOpt = Math.max(1, sizeOpt);
we.checkMaxRadius(sizeOpt);
double size) throws WorldEditException {
size = Math.max(1, size);
we.checkMaxRadius(size);
int affected = editSession.simulateSnow(session.getPlacementPosition(player), sizeOpt);
player.print(affected + " surface(s) covered. Let it snow~");
int affected = editSession.simulateSnow(session.getPlacementPosition(actor), size);
actor.print(affected + " surface(s) covered. Let it snow~");
return affected;
}
@ -481,14 +479,14 @@ public class UtilityCommands {
)
@CommandPermissions("worldedit.thaw")
@Logging(PLACEMENT)
public int thaw(Player player, LocalSession session, EditSession editSession,
public int thaw(Actor actor, LocalSession session, EditSession editSession,
@Range(min=1) @Arg(desc = "The radius of the circle to thaw in", def = "10")
double sizeOpt) throws WorldEditException {
sizeOpt = Math.max(1, sizeOpt);
we.checkMaxRadius(sizeOpt);
double size) throws WorldEditException {
size = Math.max(1, size);
we.checkMaxRadius(size);
int affected = editSession.thaw(session.getPlacementPosition(player), sizeOpt);
player.print(affected + " surface(s) thawed.");
int affected = editSession.thaw(session.getPlacementPosition(actor), size);
actor.print(affected + " surface(s) thawed.");
return affected;
}
@ -499,17 +497,17 @@ public class UtilityCommands {
)
@CommandPermissions("worldedit.green")
@Logging(PLACEMENT)
public int green(Player player, LocalSession session, EditSession editSession,
public int green(Actor actor, LocalSession session, EditSession editSession,
@Range(min=1) @Arg(desc = "The radius of the circle to convert in", def = "10")
double sizeOpt,
double size,
@Switch(name = 'f', desc = "Also convert coarse dirt")
boolean convertCoarse) throws WorldEditException {
sizeOpt = Math.max(1, sizeOpt);
we.checkMaxRadius(sizeOpt);
size = Math.max(1, size);
we.checkMaxRadius(size);
final boolean onlyNormalDirt = !convertCoarse;
final int affected = editSession.green(session.getPlacementPosition(player), sizeOpt, onlyNormalDirt);
BBC.VISITOR_BLOCK.send(player, affected);
final int affected = editSession.green(session.getPlacementPosition(actor), size, onlyNormalDirt);
BBC.VISITOR_BLOCK.send(actor, affected);
return affected;
}
@ -520,7 +518,7 @@ public class UtilityCommands {
)
@CommandPermissions("worldedit.extinguish")
@Logging(PLACEMENT)
public void extinguish(Player player, LocalSession session, EditSession editSession,
public void extinguish(Actor actor, LocalSession session, EditSession editSession,
@Range(min=1) @Arg(desc = "The radius of the square to remove in", def = "")
Integer radius) throws WorldEditException {
@ -531,8 +529,8 @@ public class UtilityCommands {
we.checkMaxRadius(size);
Mask mask = new BlockTypeMask(editSession, BlockTypes.FIRE);
int affected = editSession.removeNear(session.getPlacementPosition(player), mask, size);
BBC.VISITOR_BLOCK.send(player, affected);
int affected = editSession.removeNear(session.getPlacementPosition(actor), mask, size);
BBC.VISITOR_BLOCK.send(actor, affected);
}
@Command(
@ -561,7 +559,6 @@ public class UtilityCommands {
@Switch(name = 'r', desc = "Also destroy armor stands")
boolean killArmorStands) throws WorldEditException {
LocalConfiguration config = we.getConfiguration();
Player player = actor instanceof Player ? (Player) actor : null;
if (radius == null) {
radius = config.butcherDefaultRadius;
@ -587,7 +584,7 @@ public class UtilityCommands {
flags.or(CreatureButcher.Flags.TAGGED, killWithName, "worldedit.butcher.tagged");
flags.or(CreatureButcher.Flags.ARMOR_STAND, killArmorStands, "worldedit.butcher.armorstands");
int killed = killMatchingEntities(radius, player, flags::createFunction);
int killed = killMatchingEntities(radius, actor, flags::createFunction);
actor.print("Killed " + killed + (killed != 1 ? " mobs" : " mob") + (radius < 0 ? "" : " in a radius of " + radius) + ".");
@ -606,43 +603,32 @@ public class UtilityCommands {
EntityRemover remover,
@Range(min=-1) @Arg(desc = "The radius of the cuboid to remove from")
int radius) throws WorldEditException {
Player player = actor instanceof Player ? (Player) actor : null;
if (radius < -1) {
actor.printError("Use -1 to remove all entities in loaded chunks");
return 0;
}
int removed = killMatchingEntities(radius, player, remover::createFunction);
int removed = killMatchingEntities(radius, actor, remover::createFunction);
actor.print("Marked " + removed + (removed != 1 ? " entities" : " entity") + " for removal.");
return removed;
}
private int killMatchingEntities(Integer radius, Player player, Supplier<EntityFunction> func) throws IncompleteRegionException, MaxChangedBlocksException {
private int killMatchingEntities(Integer radius, Actor actor, Supplier<EntityFunction> func) throws IncompleteRegionException, MaxChangedBlocksException {
List<EntityVisitor> visitors = new ArrayList<>();
LocalSession session = null;
EditSession editSession = null;
if (player != null) {
session = we.getSessionManager().get(player);
BlockVector3 center = session.getPlacementPosition(player);
editSession = session.createEditSession(player);
List<? extends Entity> entities;
if (radius >= 0) {
CylinderRegion region = CylinderRegion.createRadius(editSession, center, radius);
entities = editSession.getEntities(region);
} else {
entities = editSession.getEntities();
}
visitors.add(new EntityVisitor(entities.iterator(), func.get()));
LocalSession session = we.getSessionManager().get(actor);
BlockVector3 center = session.getPlacementPosition(actor);
EditSession editSession = session.createEditSession(actor);
List<? extends Entity> entities;
if (radius >= 0) {
CylinderRegion region = CylinderRegion.createRadius(editSession, center, radius);
entities = editSession.getEntities(region);
} else {
Platform platform = we.getPlatformManager().queryCapability(Capability.WORLD_EDITING);
for (World world : platform.getWorlds()) {
List<? extends Entity> entities = world.getEntities();
visitors.add(new EntityVisitor(entities.iterator(), func.get()));
}
entities = editSession.getEntities();
}
visitors.add(new EntityVisitor(entities.iterator(), func.get()));
int killed = 0;
for (EntityVisitor visitor : visitors) {
@ -650,12 +636,10 @@ public class UtilityCommands {
killed += visitor.getAffected();
}
BBC.KILL_SUCCESS.send(player, killed, radius);
BBC.KILL_SUCCESS.send(actor, killed, radius);
if (editSession != null) {
session.remember(editSession);
editSession.flushSession();
}
session.remember(editSession);
editSession.flushSession();
return killed;
}

View File

@ -0,0 +1,47 @@
package com.sk89q.worldedit.command.argument;
import com.google.common.collect.ImmutableSetMultimap;
import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.internal.expression.runtime.EvaluationException;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.world.World;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.converter.ArgumentConverter;
import org.enginehub.piston.converter.ConversionResult;
import org.enginehub.piston.converter.FailedConversion;
import org.enginehub.piston.converter.MultiKeyConverter;
import org.enginehub.piston.converter.SimpleArgumentConverter;
import org.enginehub.piston.converter.SuccessfulConversion;
import org.enginehub.piston.inject.InjectedValueAccess;
import org.enginehub.piston.inject.Key;
public class ExpressionConverter implements ArgumentConverter<Expression> {
public static void register(CommandManager commandManager) {
commandManager.registerConverter(Key.of(Expression.class), new ExpressionConverter());
}
@Override
public Component describeAcceptableArguments() {
return TextComponent.of("TODO");
}
@Override
public ConversionResult<Expression> convert(String s, InjectedValueAccess injectedValueAccess) {
Expression expression;
try {
expression = new Expression(Double.parseDouble(s));
} catch (NumberFormatException e1) {
try {
expression = Expression.compile(s);
expression.optimize();
return SuccessfulConversion.fromSingle(expression);
} catch (Exception e) {
return FailedConversion.from(e);
}
}
return SuccessfulConversion.fromSingle(expression);
}
}

View File

@ -19,6 +19,8 @@
package com.sk89q.worldedit.extension.platform;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.command.AnvilCommands;
import com.boydti.fawe.command.AnvilCommandsRegistration;
@ -35,8 +37,10 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import com.google.common.reflect.TypeToken;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MissingWorldException;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.command.ApplyBrushCommands;
import com.sk89q.worldedit.command.BiomeCommands;
@ -92,6 +96,7 @@ import com.sk89q.worldedit.command.argument.DirectionConverter;
import com.sk89q.worldedit.command.argument.DirectionVectorConverter;
import com.sk89q.worldedit.command.argument.EntityRemoverConverter;
import com.sk89q.worldedit.command.argument.EnumConverter;
import com.sk89q.worldedit.command.argument.ExpressionConverter;
import com.sk89q.worldedit.command.argument.FactoryConverter;
import com.sk89q.worldedit.command.argument.RegionFactoryConverter;
import com.sk89q.worldedit.command.argument.RegistryConverter;
@ -106,17 +111,16 @@ import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
import com.sk89q.worldedit.extension.platform.binding.AnnotatedBindings;
import com.sk89q.worldedit.extension.platform.binding.CommandBindings;
import com.sk89q.worldedit.extension.platform.binding.ConsumeBindings;
import com.sk89q.worldedit.extension.platform.binding.ProvideBindings;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.internal.annotation.Selection;
import com.sk89q.worldedit.internal.command.CommandArgParser;
import com.sk89q.worldedit.internal.command.CommandLoggingHandler;
import com.sk89q.worldedit.internal.command.CommandRegistrationHandler;
import com.sk89q.worldedit.internal.command.exception.ExceptionConverter;
import com.sk89q.worldedit.internal.command.exception.WorldEditExceptionConverter;
import com.sk89q.worldedit.internal.expression.Expression;
import com.sk89q.worldedit.internal.util.Substring;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.auth.AuthorizationException;
@ -127,6 +131,24 @@ import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.util.logging.DynamicStreamHandler;
import com.sk89q.worldedit.util.logging.LogFormat;
import com.sk89q.worldedit.world.World;
import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Nullable;
import org.enginehub.piston.Command;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.TextConfig;
@ -152,28 +174,6 @@ import org.enginehub.piston.util.ValueProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import java.io.File;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Handles the registration and invocation of commands.
@ -228,7 +228,6 @@ public final class PlatformCommandManager {
}
private void initialize() {
System.out.println("========== INITIALIZE");
// Register this instance for command events
worldEdit.getEventBus().register(this);
@ -260,47 +259,90 @@ public final class PlatformCommandManager {
EntityRemoverConverter.register(commandManager);
RegionFactoryConverter.register(commandManager);
WorldConverter.register(commandManager);
ExpressionConverter.register(commandManager);
}
public void registerAlwaysInjectedValues() {
globalInjectedValues.injectValue(Key.of(InjectedValueAccess.class), Optional::of);
registerBinding(new AnnotatedBindings(worldEdit));
registerBinding(new CommandBindings(worldEdit));
registerBinding(new ConsumeBindings(worldEdit));
registerBinding(new ProvideBindings(worldEdit));
registerBinding(new ProvideBindings(worldEdit));
private void registerAlwaysInjectedValues() {
globalInjectedValues.injectValue(Key.of(Region.class, Selection.class),
context -> {
LocalSession localSession = context.injectedValue(Key.of(LocalSession.class))
.orElseThrow(() -> new IllegalStateException("No LocalSession"));
return context.injectedValue(Key.of(World.class))
.map(world -> {
try {
return localSession.getSelection(world);
} catch (IncompleteRegionException e) {
exceptionConverter.convert(e);
throw new AssertionError("Should have thrown a new exception.", e);
}
});
});
globalInjectedValues.injectValue(Key.of(EditSession.class),
context -> {
LocalSession localSession = context.injectedValue(Key.of(LocalSession.class))
.orElseThrow(() -> new IllegalStateException("No LocalSession"));
return context.injectedValue(Key.of(Actor.class))
.map(actor -> {
EditSession editSession = localSession.createEditSession(actor);
editSession.enableStandardMode();
return editSession;
});
});
globalInjectedValues.injectValue(Key.of(World.class),
context -> {
LocalSession localSession = context.injectedValue(Key.of(LocalSession.class))
.orElseThrow(() -> new IllegalStateException("No LocalSession"));
return context.injectedValue(Key.of(Actor.class))
.map(actor -> {
try {
if (localSession.hasWorldOverride()) {
return localSession.getWorldOverride();
} else if (actor instanceof Locatable && ((Locatable) actor).getExtent() instanceof World) {
return (World) ((Locatable) actor).getExtent();
} else {
throw new MissingWorldException();
}
public void registerBinding(Object classWithMethods) {
// TODO NOT IMPLEMENTED - register the following using a custom processor / annotations
} catch (MissingWorldException e) {
exceptionConverter.convert(e);
throw new AssertionError("Should have thrown a new exception.", e);
}
});
});
}
public <CI> void registerSubCommands(String name, List<String> aliases, String desc, CommandManager commandManager, Consumer<BiConsumer<CommandRegistration,CI>> handlerInstance) {
private <CI> void registerSubCommands(String name, List<String> aliases, String desc,
CommandManager commandManager,
Consumer<BiConsumer<CommandRegistration, CI>> handlerInstance) {
registerSubCommands(name, aliases, desc, commandManager, handlerInstance, m -> {});
}
public <CI> void registerSubCommands(String name, List<String> aliases, String desc, CommandManager commandManager, Consumer<BiConsumer<CommandRegistration,CI>> handlerInstance, Consumer<CommandManager> additionalConfig) {
commandManager.register(name, builder -> {
builder.aliases(aliases);
builder.description(TextComponent.of(desc));
builder.action(org.enginehub.piston.Command.Action.NULL_ACTION);
private <CI> void registerSubCommands(String name, List<String> aliases, String desc,
CommandManager commandManager,
Consumer<BiConsumer<CommandRegistration, CI>> handlerInstance,
Consumer<CommandManager> additionalConfig) {
commandManager.register(name, cmd -> {
cmd.aliases(aliases);
cmd.description(TextComponent.of(desc));
cmd.action(Command.Action.NULL_ACTION);
CommandManager manager = commandManagerService.newCommandManager();
handlerInstance.accept((handler, instance) -> registration.register(
handlerInstance.accept((handler, instance) ->
this.registration.register(
manager,
handler,
instance
));
final List<Command> subCommands = manager.getAllCommands().collect(Collectors.toList());
builder.addPart(SubCommandPart.builder(TranslatableComponent.of("worldedit.argument.action"),
cmd.addPart(SubCommandPart.builder(TranslatableComponent.of("worldedit.argument.action"),
TextComponent.of("Sub-command to run."))
.withCommands(subCommands)
.required()
.build());
builder.condition(new SubCommandPermissionCondition.Generator(subCommands).build());
cmd.condition(new SubCommandPermissionCondition.Generator(subCommands).build());
});
}
@ -309,10 +351,6 @@ public final class PlatformCommandManager {
registerSubCommands(name, aliases, desc, commandManager, c -> c.accept(registration, instance));
}
public <CI> void registerSubCommands(String name, List<String> aliases, String desc, Consumer<BiConsumer<CommandRegistration,CI>> handlerInstance) {
registerSubCommands(name, aliases, desc, commandManager, handlerInstance);
}
public void registerAllCommands() {
if (Settings.IMP.ENABLED_COMPONENTS.COMMANDS) {
registerSubCommands(
@ -463,66 +501,9 @@ public final class PlatformCommandManager {
UtilityCommandsRegistration.builder(),
new UtilityCommands(worldEdit)
);
System.out.println("========== REGISTERED COMMANDS");
}
}
// /**
// * Initialize the dispatcher
// */
// public synchronized void setupDispatcher() {
// if (Settings.IMP.ENABLED_COMPONENTS.COMMANDS) {
// DispatcherNode graph = new CommandGraph().builder(builder).commands();
//
// for (Map.Entry<Object, String[]> entry : methodMap.entrySet()) {
// // add command
// String[] aliases = entry.getValue();
// if (aliases.length == 0) {
// graph = graph.registerMethods(entry.getKey());
// } else {
// graph = graph.group(aliases).registerMethods(entry.getKey()).parent();
// }
// }
//
// for (Map.Entry<CommandCallable, String[][]> entry : commandMap.entrySet()) {
// String[][] aliases = entry.getValue();
// CommandCallable callable = entry.getKey();
// if (aliases[0].length == 0) {
// graph = graph.register(callable, aliases[1]);
// } else {
// graph = graph.group(aliases[0]).register(callable, aliases[1]).parent();
// }
// }
//
// commandMap.clear();
// methodMap.clear();
//
// dispatcher = graph
// .group("/anvil")
// .describeAs("Anvil command")
// .registerMethods(new AnvilCommands(worldEdit)).parent()
// .registerMethods(new CFICommand(worldEdit, builder))
// .registerMethods(new OptionsCommands(worldEdit))
// .registerMethods(new BrushOptionsCommands(worldEdit))
// .registerMethods(new BrushOptionsCommands(worldEdit))
// .register(adapt(new ShapedBrushCommand(new DeformCommand(), "worldedit.brush.deform")), "deform")
// .register(adapt(new ShapedBrushCommand(new ApplyCommand(new ReplaceParser(), "Set all blocks within region"), "worldedit.brush.set")), "set")
// .register(adapt(new ShapedBrushCommand(new PaintCommand(), "worldedit.brush.paint")), "paint")
// .register(adapt(new ShapedBrushCommand(new ApplyCommand(), "worldedit.brush.apply")), "apply")
// .register(adapt(new ShapedBrushCommand(new PaintCommand(new TreeGeneratorParser("treeType")), "worldedit.brush.forest")), "forest")
// .register(adapt(new ShapedBrushCommand(ProvidedValue.create(new Deform("y-=1", Mode.RAW_COORD), "Raise one block"), "worldedit.brush.raise")), "raise")
// .register(adapt(new ShapedBrushCommand(ProvidedValue.create(new Deform("y+=1", Mode.RAW_COORD), "Lower one block"), "worldedit.brush.lower")), "lower")
// .parent()
// .group("superpickaxe", "pickaxe", "sp").describeAs("Super-pickaxe commands")
// .registerMethods(new SuperPickaxeCommands(worldEdit))
// .parent().graph().getDispatcher();
//
// if (platform != null) {
// platform.registerCommands(dispatcher);
// }
// }
// }
public static PlatformCommandManager getInstance() {
return INSTANCE;
}
@ -572,7 +553,7 @@ public final class PlatformCommandManager {
dynamicHandler.setHandler(null);
}
public Stream<Substring> parseArgs(String input) {
private Stream<Substring> parseArgs(String input) {
return new CommandArgParser(CommandArgParser.spaceSplit(input)).parseArgs();
}

View File

@ -61,7 +61,7 @@ public interface Clipboard extends Extent {
/**
* Returns true if the clipboard has biome data. This can be checked since {@link Extent#getBiome(BlockVector2)}
* strongly suggests returning {@link com.sk89q.worldedit.world.biome.BiomeTypes.OCEAN} instead of {@code null}
* strongly suggests returning {@link com.sk89q.worldedit.world.biome.BiomeTypes#OCEAN} instead of {@code null}
* if biomes aren't present. However, it might not be desired to set areas to ocean if the clipboard is defaulting
* to ocean, instead of having biomes explicitly set.
*

View File

@ -61,6 +61,7 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.function.BiConsumer;
import net.jpountz.lz4.LZ4BlockInputStream;
@ -303,7 +304,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
throw new IOException("Biome palette size does not match expected size.");
}
for (Map.Entry<String, Tag> palettePart : paletteTag.getValue().entrySet()) {
for (Entry<String, Tag> palettePart : paletteTag.getValue().entrySet()) {
String key = palettePart.getKey();
if (fixer != null) {
key = fixer.fixUp(DataFixer.FixTypes.BIOME, key, dataVersion);

View File

@ -27,6 +27,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;
@ -71,18 +72,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());
@ -92,14 +93,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;
}
@ -120,7 +122,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;
}

View File

@ -24,6 +24,7 @@ import com.sk89q.worldedit.function.mask.BlockMask;
import com.sk89q.worldedit.blocks.BaseItem;
import com.sk89q.worldedit.blocks.BaseItemStack;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.function.mask.BlockTypeMask;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.math.BlockVector2;
@ -70,7 +71,7 @@ public abstract class AbstractWorld implements World {
@Override
public Mask createLiquidMask() {
return new BlockMask(this).add(BlockTypes.LAVA, BlockTypes.WATER);
return new BlockTypeMask(this, BlockTypes.LAVA, BlockTypes.WATER);
}
@Override