3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-12-26 02:50:06 +01:00

More upstream compatibility fixes

Dieser Commit ist enthalten in:
MattBDev 2019-09-03 13:40:20 -04:00
Ursprung e88adea066
Commit cafb4120ef
8 geänderte Dateien mit 232 neuen und 207 gelöschten Zeilen

Datei anzeigen

@ -76,6 +76,15 @@ public class ToolCommands {
this.we = we; 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( @Command(
name = "/selwand", name = "/selwand",
aliases = "selwand", aliases = "selwand",

Datei anzeigen

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

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -19,6 +19,8 @@
package com.sk89q.worldedit.extension.platform; package com.sk89q.worldedit.extension.platform;
import static com.google.common.base.Preconditions.checkNotNull;
import com.boydti.fawe.Fawe; import com.boydti.fawe.Fawe;
import com.boydti.fawe.command.AnvilCommands; import com.boydti.fawe.command.AnvilCommands;
import com.boydti.fawe.command.AnvilCommandsRegistration; 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.collect.ImmutableSet;
import com.google.common.reflect.TypeToken; import com.google.common.reflect.TypeToken;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MissingWorldException;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.command.ApplyBrushCommands; import com.sk89q.worldedit.command.ApplyBrushCommands;
import com.sk89q.worldedit.command.BiomeCommands; 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.DirectionVectorConverter;
import com.sk89q.worldedit.command.argument.EntityRemoverConverter; import com.sk89q.worldedit.command.argument.EntityRemoverConverter;
import com.sk89q.worldedit.command.argument.EnumConverter; 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.FactoryConverter;
import com.sk89q.worldedit.command.argument.RegionFactoryConverter; import com.sk89q.worldedit.command.argument.RegionFactoryConverter;
import com.sk89q.worldedit.command.argument.RegistryConverter; 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.entity.Player;
import com.sk89q.worldedit.event.platform.CommandEvent; import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent; 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.extent.Extent;
import com.sk89q.worldedit.internal.annotation.Selection;
import com.sk89q.worldedit.internal.command.CommandArgParser; import com.sk89q.worldedit.internal.command.CommandArgParser;
import com.sk89q.worldedit.internal.command.CommandLoggingHandler; import com.sk89q.worldedit.internal.command.CommandLoggingHandler;
import com.sk89q.worldedit.internal.command.CommandRegistrationHandler; import com.sk89q.worldedit.internal.command.CommandRegistrationHandler;
import com.sk89q.worldedit.internal.command.exception.ExceptionConverter; import com.sk89q.worldedit.internal.command.exception.ExceptionConverter;
import com.sk89q.worldedit.internal.command.exception.WorldEditExceptionConverter; 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.internal.util.Substring;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.session.SessionKey;
import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.session.request.Request;
import com.sk89q.worldedit.util.auth.AuthorizationException; 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.DynamicStreamHandler;
import com.sk89q.worldedit.util.logging.LogFormat; import com.sk89q.worldedit.util.logging.LogFormat;
import com.sk89q.worldedit.world.World; 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.Command;
import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandManager;
import org.enginehub.piston.TextConfig; import org.enginehub.piston.TextConfig;
@ -152,28 +174,6 @@ import org.enginehub.piston.util.ValueProvider;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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. * Handles the registration and invocation of commands.
@ -228,7 +228,6 @@ public final class PlatformCommandManager {
} }
private void initialize() { private void initialize() {
System.out.println("========== INITIALIZE");
// Register this instance for command events // Register this instance for command events
worldEdit.getEventBus().register(this); worldEdit.getEventBus().register(this);
@ -260,47 +259,90 @@ public final class PlatformCommandManager {
EntityRemoverConverter.register(commandManager); EntityRemoverConverter.register(commandManager);
RegionFactoryConverter.register(commandManager); RegionFactoryConverter.register(commandManager);
WorldConverter.register(commandManager); WorldConverter.register(commandManager);
ExpressionConverter.register(commandManager);
} }
public void registerAlwaysInjectedValues() { private void registerAlwaysInjectedValues() {
globalInjectedValues.injectValue(Key.of(InjectedValueAccess.class), Optional::of); globalInjectedValues.injectValue(Key.of(Region.class, Selection.class),
registerBinding(new AnnotatedBindings(worldEdit)); context -> {
registerBinding(new CommandBindings(worldEdit)); LocalSession localSession = context.injectedValue(Key.of(LocalSession.class))
registerBinding(new ConsumeBindings(worldEdit)); .orElseThrow(() -> new IllegalStateException("No LocalSession"));
registerBinding(new ProvideBindings(worldEdit)); return context.injectedValue(Key.of(World.class))
registerBinding(new ProvideBindings(worldEdit)); .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) { } catch (MissingWorldException e) {
// TODO NOT IMPLEMENTED - register the following using a custom processor / annotations 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 -> {}); 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) { private <CI> void registerSubCommands(String name, List<String> aliases, String desc,
commandManager.register(name, builder -> { CommandManager commandManager,
builder.aliases(aliases); Consumer<BiConsumer<CommandRegistration, CI>> handlerInstance,
builder.description(TextComponent.of(desc)); Consumer<CommandManager> additionalConfig) {
builder.action(org.enginehub.piston.Command.Action.NULL_ACTION); commandManager.register(name, cmd -> {
cmd.aliases(aliases);
cmd.description(TextComponent.of(desc));
cmd.action(Command.Action.NULL_ACTION);
CommandManager manager = commandManagerService.newCommandManager(); CommandManager manager = commandManagerService.newCommandManager();
handlerInstance.accept((handler, instance) -> registration.register( handlerInstance.accept((handler, instance) ->
this.registration.register(
manager, manager,
handler, handler,
instance instance
)); ));
final List<Command> subCommands = manager.getAllCommands().collect(Collectors.toList()); 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.")) TextComponent.of("Sub-command to run."))
.withCommands(subCommands) .withCommands(subCommands)
.required() .required()
.build()); .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)); 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() { public void registerAllCommands() {
if (Settings.IMP.ENABLED_COMPONENTS.COMMANDS) { if (Settings.IMP.ENABLED_COMPONENTS.COMMANDS) {
registerSubCommands( registerSubCommands(
@ -463,66 +501,9 @@ public final class PlatformCommandManager {
UtilityCommandsRegistration.builder(), UtilityCommandsRegistration.builder(),
new UtilityCommands(worldEdit) 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() { public static PlatformCommandManager getInstance() {
return INSTANCE; return INSTANCE;
} }
@ -572,7 +553,7 @@ public final class PlatformCommandManager {
dynamicHandler.setHandler(null); dynamicHandler.setHandler(null);
} }
public Stream<Substring> parseArgs(String input) { private Stream<Substring> parseArgs(String input) {
return new CommandArgParser(CommandArgParser.spaceSplit(input)).parseArgs(); return new CommandArgParser(CommandArgParser.spaceSplit(input)).parseArgs();
} }

Datei anzeigen

@ -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)} * 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 * 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. * to ocean, instead of having biomes explicitly set.
* *

Datei anzeigen

@ -61,6 +61,7 @@ import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID; import java.util.UUID;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import net.jpountz.lz4.LZ4BlockInputStream; 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."); 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(); String key = palettePart.getKey();
if (fixer != null) { if (fixer != null) {
key = fixer.fixUp(DataFixer.FixTypes.BIOME, key, dataVersion); key = fixer.fixUp(DataFixer.FixTypes.BIOME, key, dataVersion);

Datei anzeigen

@ -27,6 +27,7 @@ import com.sk89q.worldedit.command.util.Logging;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.world.World;
import org.enginehub.piston.CommandParameters; import org.enginehub.piston.CommandParameters;
import org.enginehub.piston.gen.CommandCallListener; import org.enginehub.piston.gen.CommandCallListener;
import org.enginehub.piston.inject.Key; import org.enginehub.piston.inject.Key;
@ -71,18 +72,18 @@ public class CommandLoggingHandler implements CommandCallListener, AutoCloseable
logMode = loggingAnnotation.value(); logMode = loggingAnnotation.value();
} }
Optional<Player> playerOpt = parameters.injectedValue(Key.of(Actor.class)) Optional<Actor> playerOpt = parameters.injectedValue(Key.of(Actor.class));
.filter(Player.class::isInstance) Optional<World> worldOpt = parameters.injectedValue(Key.of(World.class));
.map(Player.class::cast);
if (!playerOpt.isPresent()) { if (!playerOpt.isPresent() || !worldOpt.isPresent()) {
return; return;
} }
Player player = playerOpt.get(); Actor actor = playerOpt.get();
World world = worldOpt.get();
builder.append("WorldEdit: ").append(player.getName()); builder.append("WorldEdit: ").append(actor.getName());
builder.append(" (in \"").append(player.getWorld().getName()).append("\")"); builder.append(" (in \"").append(world.getName()).append("\")");
builder.append(": ").append(parameters.getMetadata().getCalledName()); builder.append(": ").append(parameters.getMetadata().getCalledName());
@ -92,14 +93,15 @@ public class CommandLoggingHandler implements CommandCallListener, AutoCloseable
parameters.getMetadata().getArguments().stream() parameters.getMetadata().getArguments().stream()
).collect(Collectors.joining(" "))); ).collect(Collectors.joining(" ")));
if (logMode != null) { if (logMode != null && actor instanceof Player) {
Player player = (Player) actor;
Vector3 position = player.getLocation().toVector(); Vector3 position = player.getLocation().toVector();
LocalSession session = worldEdit.getSessionManager().get(player); LocalSession session = worldEdit.getSessionManager().get(actor);
switch (logMode) { switch (logMode) {
case PLACEMENT: case PLACEMENT:
try { try {
position = session.getPlacementPosition(player).toVector3(); position = session.getPlacementPosition(actor).toVector3();
} catch (IncompleteRegionException e) { } catch (IncompleteRegionException e) {
break; break;
} }
@ -120,7 +122,7 @@ public class CommandLoggingHandler implements CommandCallListener, AutoCloseable
case REGION: case REGION:
try { try {
builder.append(" - Region: ") builder.append(" - Region: ")
.append(session.getSelection(player.getWorld())); .append(session.getSelection(world));
} catch (IncompleteRegionException e) { } catch (IncompleteRegionException e) {
break; break;
} }

Datei anzeigen

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