Port generation commands

Dieser Commit ist enthalten in:
Kenzie Togami 2019-04-23 10:11:54 -07:00
Ursprung 51be16ad81
Commit 31486cd473
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 5D200B325E157A81
7 geänderte Dateien mit 321 neuen und 174 gelöschten Zeilen

Datei anzeigen

@ -19,35 +19,39 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.worldedit.command.util.Logging.LogMode.ALL;
import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT;
import static com.sk89q.worldedit.command.util.Logging.LogMode.POSITION;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandPermissions;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.command.util.Logging;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.internal.annotation.Radii;
import com.sk89q.worldedit.internal.annotation.Selection; import com.sk89q.worldedit.internal.annotation.Selection;
import com.sk89q.worldedit.internal.expression.ExpressionException; import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.TreeGenerator.TreeType; import com.sk89q.worldedit.util.TreeGenerator.TreeType;
import com.sk89q.worldedit.util.command.binding.Range;
import com.sk89q.worldedit.util.command.binding.Switch;
import com.sk89q.worldedit.util.command.binding.Text;
import com.sk89q.worldedit.util.command.parametric.Optional;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg;
import org.enginehub.piston.annotation.param.Switch;
import java.util.List;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.worldedit.command.util.Logging.LogMode.ALL;
import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT;
import static com.sk89q.worldedit.command.util.Logging.LogMode.POSITION;
/** /**
* Commands for the generation of shapes and other objects. * Commands for the generation of shapes and other objects.
*/ */
@CommandContainer(superTypes = CommandPermissionsConditionGenerator.Registration.class)
public class GenerationCommands { public class GenerationCommands {
private final WorldEdit worldEdit; private final WorldEdit worldEdit;
@ -63,54 +67,52 @@ public class GenerationCommands {
} }
@Command( @Command(
aliases = { "/hcyl" }, name = "/hcyl",
usage = "<pattern> <radius>[,<radius>] [height]", desc = "Generates a hollow cylinder."
desc = "Generates a hollow cylinder.",
help =
"Generates a hollow cylinder.\n" +
"By specifying 2 radii, separated by a comma,\n" +
"you can generate elliptical cylinders.\n" +
"The 1st radius is north/south, the 2nd radius is east/west.",
min = 2,
max = 3
) )
@CommandPermissions("worldedit.generation.cylinder") @CommandPermissions("worldedit.generation.cylinder")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void hcyl(Player player, LocalSession session, EditSession editSession, Pattern pattern, String radiusString, @Optional("1") int height) throws WorldEditException { public int hcyl(Player player, LocalSession session, EditSession editSession,
cyl(player, session, editSession, pattern, radiusString, height, true); @Arg(desc = "The pattern of blocks to generate")
Pattern pattern,
@Arg(desc = "The radii of the cylinder. 1st is N/S, 2nd is E/W")
@Radii(2)
List<Double> radii,
@Arg(desc = "The height of the cylinder", def = "1")
int height) throws WorldEditException {
return cyl(player, session, editSession, pattern, radii, height, true);
} }
@Command( @Command(
aliases = { "/cyl" }, name = "/cyl",
usage = "<block> <radius>[,<radius>] [height]", desc = "Generates a cylinder."
flags = "h",
desc = "Generates a cylinder.",
help =
"Generates a cylinder.\n" +
"By specifying 2 radii, separated by a comma,\n" +
"you can generate elliptical cylinders.\n" +
"The 1st radius is north/south, the 2nd radius is east/west.",
min = 2,
max = 3
) )
@CommandPermissions("worldedit.generation.cylinder") @CommandPermissions("worldedit.generation.cylinder")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void cyl(Player player, LocalSession session, EditSession editSession, Pattern pattern, String radiusString, @Optional("1") int height, @Switch('h') boolean hollow) throws WorldEditException { public int cyl(Player player, LocalSession session, EditSession editSession,
String[] radii = radiusString.split(","); @Arg(desc = "The pattern of blocks to generate")
Pattern pattern,
@Arg(desc = "The radii of the cylinder. 1st is N/S, 2nd is E/W")
@Radii(2)
List<Double> radii,
@Arg(desc = "The height of the cylinder", def = "1")
int height,
@Switch(name = 'h', desc = "Make a hollow cylinder")
boolean hollow) throws WorldEditException {
final double radiusX, radiusZ; final double radiusX, radiusZ;
switch (radii.length) { switch (radii.size()) {
case 1: case 1:
radiusX = radiusZ = Math.max(1, Double.parseDouble(radii[0])); radiusX = radiusZ = Math.max(1, radii.get(0));
break; break;
case 2: case 2:
radiusX = Math.max(1, Double.parseDouble(radii[0])); radiusX = Math.max(1, radii.get(0));
radiusZ = Math.max(1, Double.parseDouble(radii[1])); radiusZ = Math.max(1, radii.get(1));
break; break;
default: default:
player.printError("You must either specify 1 or 2 radius values."); player.printError("You must either specify 1 or 2 radius values.");
return; return 0;
} }
worldEdit.checkMaxRadius(radiusX); worldEdit.checkMaxRadius(radiusX);
@ -120,58 +122,57 @@ public class GenerationCommands {
BlockVector3 pos = session.getPlacementPosition(player); BlockVector3 pos = session.getPlacementPosition(player);
int affected = editSession.makeCylinder(pos, pattern, radiusX, radiusZ, height, !hollow); int affected = editSession.makeCylinder(pos, pattern, radiusX, radiusZ, height, !hollow);
player.print(affected + " block(s) have been created."); player.print(affected + " block(s) have been created.");
return affected;
} }
@Command( @Command(
aliases = { "/hsphere" }, name = "/hsphere",
usage = "<block> <radius>[,<radius>,<radius>] [raised?]", desc = "Generates a hollow sphere."
desc = "Generates a hollow sphere.",
help =
"Generates a hollow sphere.\n" +
"By specifying 3 radii, separated by commas,\n" +
"you can generate an ellipsoid. The order of the ellipsoid radii\n" +
"is north/south, up/down, east/west.",
min = 2,
max = 3
) )
@CommandPermissions("worldedit.generation.sphere") @CommandPermissions("worldedit.generation.sphere")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void hsphere(Player player, LocalSession session, EditSession editSession, Pattern pattern, String radiusString, @Optional("false") boolean raised) throws WorldEditException { public int hsphere(Player player, LocalSession session, EditSession editSession,
sphere(player, session, editSession, pattern, radiusString, raised, true); @Arg(desc = "The pattern of blocks to generate")
Pattern pattern,
@Arg(desc = "The radii of the sphere. Order is N/S, U/D, E/W")
@Radii(3)
List<Double> radii,
@Switch(name = 'r', desc = "Raise the bottom of the sphere to the placement position")
boolean raised) throws WorldEditException {
return sphere(player, session, editSession, pattern, radii, raised, true);
} }
@Command( @Command(
aliases = { "/sphere" }, name = "/sphere",
usage = "<block> <radius>[,<radius>,<radius>] [raised?]", desc = "Generates a filled sphere."
flags = "h",
desc = "Generates a filled sphere.",
help =
"Generates a filled sphere.\n" +
"By specifying 3 radii, separated by commas,\n" +
"you can generate an ellipsoid. The order of the ellipsoid radii\n" +
"is north/south, up/down, east/west.",
min = 2,
max = 3
) )
@CommandPermissions("worldedit.generation.sphere") @CommandPermissions("worldedit.generation.sphere")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void sphere(Player player, LocalSession session, EditSession editSession, Pattern pattern, String radiusString, @Optional("false") boolean raised, @Switch('h') boolean hollow) throws WorldEditException { public int sphere(Player player, LocalSession session, EditSession editSession,
String[] radii = radiusString.split(","); @Arg(desc = "The pattern of blocks to generate")
Pattern pattern,
@Arg(desc = "The radii of the sphere. Order is N/S, U/D, E/W")
@Radii(3)
List<Double> radii,
@Switch(name = 'r', desc = "Raise the bottom of the sphere to the placement position")
boolean raised,
@Switch(name = 'h', desc = "Make a hollow sphere")
boolean hollow) throws WorldEditException {
final double radiusX, radiusY, radiusZ; final double radiusX, radiusY, radiusZ;
switch (radii.length) { switch (radii.size()) {
case 1: case 1:
radiusX = radiusY = radiusZ = Math.max(1, Double.parseDouble(radii[0])); radiusX = radiusY = radiusZ = Math.max(1, radii.get(0));
break; break;
case 3: case 3:
radiusX = Math.max(1, Double.parseDouble(radii[0])); radiusX = Math.max(1, radii.get(0));
radiusY = Math.max(1, Double.parseDouble(radii[1])); radiusY = Math.max(1, radii.get(1));
radiusZ = Math.max(1, Double.parseDouble(radii[2])); radiusZ = Math.max(1, radii.get(2));
break; break;
default: default:
player.printError("You must either specify 1 or 3 radius values."); player.printError("You must either specify 1 or 3 radius values.");
return; return 0;
} }
worldEdit.checkMaxRadius(radiusX); worldEdit.checkMaxRadius(radiusX);
@ -186,98 +187,102 @@ public class GenerationCommands {
int affected = editSession.makeSphere(pos, pattern, radiusX, radiusY, radiusZ, !hollow); int affected = editSession.makeSphere(pos, pattern, radiusX, radiusY, radiusZ, !hollow);
player.findFreePosition(); player.findFreePosition();
player.print(affected + " block(s) have been created."); player.print(affected + " block(s) have been created.");
return affected;
} }
@Command( @Command(
aliases = { "forestgen" }, name = "forestgen",
usage = "[size] [type] [density]", desc = "Generate a forest"
desc = "Generate a forest",
min = 0,
max = 3
) )
@CommandPermissions("worldedit.generation.forest") @CommandPermissions("worldedit.generation.forest")
@Logging(POSITION) @Logging(POSITION)
public void forestGen(Player player, LocalSession session, EditSession editSession, @Optional("10") int size, public int forestGen(Player player, LocalSession session, EditSession editSession,
@Optional("tree") TreeType type, @Optional("5") @Range(min = 0, max = 100) double density) throws WorldEditException { @Arg(desc = "The size of the forest, in blocks", def = "10")
int size,
@Arg(desc = "The type of forest", def = "tree")
TreeType type,
@Arg(desc = "The density of the forest, between 0 and 100", def = "5")
double density) throws WorldEditException {
if (density < 0 || density > 100) {
throw new IllegalArgumentException("Density must be between 0 and 100");
}
density = density / 100; density = density / 100;
int affected = editSession.makeForest(session.getPlacementPosition(player), size, density, type); int affected = editSession.makeForest(session.getPlacementPosition(player), size, density, type);
player.print(affected + " trees created."); player.print(affected + " trees created.");
return affected;
} }
@Command( @Command(
aliases = { "pumpkins" }, name = "pumpkins",
usage = "[size]", desc = "Generate pumpkin patches"
desc = "Generate pumpkin patches",
min = 0,
max = 1
) )
@CommandPermissions("worldedit.generation.pumpkins") @CommandPermissions("worldedit.generation.pumpkins")
@Logging(POSITION) @Logging(POSITION)
public void pumpkins(Player player, LocalSession session, EditSession editSession, @Optional("10") int apothem) throws WorldEditException { public int pumpkins(Player player, LocalSession session, EditSession editSession,
int affected = editSession.makePumpkinPatches(session.getPlacementPosition(player), apothem); @Arg(desc = "The size of the patch", def = "10")
int size) throws WorldEditException {
int affected = editSession.makePumpkinPatches(session.getPlacementPosition(player), size);
player.print(affected + " pumpkin patches created."); player.print(affected + " pumpkin patches created.");
return affected;
} }
@Command( @Command(
aliases = { "/hpyramid" }, name = "/hpyramid",
usage = "<block> <size>", desc = "Generate a hollow pyramid"
desc = "Generate a hollow pyramid",
min = 2,
max = 2
) )
@CommandPermissions("worldedit.generation.pyramid") @CommandPermissions("worldedit.generation.pyramid")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void hollowPyramid(Player player, LocalSession session, EditSession editSession, Pattern pattern, @Range(min = 1) int size) throws WorldEditException { public int hollowPyramid(Player player, LocalSession session, EditSession editSession,
pyramid(player, session, editSession, pattern, size, true); @Arg(desc = "The pattern of blocks to set")
Pattern pattern,
@Arg(desc = "The size of the pyramid")
int size) throws WorldEditException {
return pyramid(player, session, editSession, pattern, size, true);
} }
@Command( @Command(
aliases = { "/pyramid" }, name = "/pyramid",
usage = "<block> <size>", desc = "Generate a filled pyramid"
flags = "h",
desc = "Generate a filled pyramid",
min = 2,
max = 2
) )
@CommandPermissions("worldedit.generation.pyramid") @CommandPermissions("worldedit.generation.pyramid")
@Logging(PLACEMENT) @Logging(PLACEMENT)
public void pyramid(Player player, LocalSession session, EditSession editSession, Pattern pattern, @Range(min = 1) int size, @Switch('h') boolean hollow) throws WorldEditException { public int pyramid(Player player, LocalSession session, EditSession editSession,
@Arg(desc = "The pattern of blocks to set")
Pattern pattern,
@Arg(desc = "The size of the pyramid")
int size,
@Switch(name = 'h', desc = "Make a hollow pyramid")
boolean hollow) throws WorldEditException {
BlockVector3 pos = session.getPlacementPosition(player); BlockVector3 pos = session.getPlacementPosition(player);
worldEdit.checkMaxRadius(size); worldEdit.checkMaxRadius(size);
int affected = editSession.makePyramid(pos, pattern, size, !hollow); int affected = editSession.makePyramid(pos, pattern, size, !hollow);
player.findFreePosition(); player.findFreePosition();
player.print(affected + " block(s) have been created."); player.print(affected + " block(s) have been created.");
return affected;
} }
@Command( @Command(
aliases = { "/generate", "/gen", "/g" }, name = "/generate",
usage = "<block> <expression>", aliases = { "/gen", "/g" },
desc = "Generates a shape according to a formula.", desc = "Generates a shape according to a formula.",
help = descFooter = "See also https://tinyurl.com/wesyntax."
"Generates a shape according to a formula that is expected to\n" +
"return positive numbers (true) if the point is inside the shape\n" +
"Optionally set type/data to the desired block.\n" +
"Flags:\n" +
" -h to generate a hollow shape\n" +
" -r to use raw minecraft coordinates\n" +
" -o is like -r, except offset from placement.\n" +
" -c is like -r, except offset selection center.\n" +
"If neither -r nor -o is given, the selection is mapped to -1..1\n" +
"See also tinyurl.com/wesyntax.",
flags = "hroc",
min = 2,
max = -1
) )
@CommandPermissions("worldedit.generation.shape") @CommandPermissions("worldedit.generation.shape")
@Logging(ALL) @Logging(ALL)
public void generate(Player player, LocalSession session, EditSession editSession, public int generate(Player player, LocalSession session, EditSession editSession,
@Selection Region region, @Selection Region region,
Pattern pattern, @Arg(desc = "The pattern of blocks to set")
@Text String expression, Pattern pattern,
@Switch('h') boolean hollow, @Arg(desc = "Expression to test block placement locations and set block type")
@Switch('r') boolean useRawCoords, String expression,
@Switch('o') boolean offset, @Switch(name = 'h', desc = "Generate a hollow shape")
@Switch('c') boolean offsetCenter) throws WorldEditException { boolean hollow,
@Switch(name = 'r', desc = "Use the game's coordinate origin")
boolean useRawCoords,
@Switch(name = 'o', desc = "Use the placement's coordinate origin")
boolean offset,
@Switch(name = 'c', desc = "Use the selection's center as origin")
boolean offsetCenter) throws WorldEditException {
final Vector3 zero; final Vector3 zero;
Vector3 unit; Vector3 unit;
@ -310,40 +315,35 @@ public class GenerationCommands {
final int affected = editSession.makeShape(region, zero, unit, pattern, expression, hollow, session.getTimeout()); final int affected = editSession.makeShape(region, zero, unit, pattern, expression, hollow, session.getTimeout());
player.findFreePosition(); player.findFreePosition();
player.print(affected + " block(s) have been created."); player.print(affected + " block(s) have been created.");
return affected;
} catch (ExpressionException e) { } catch (ExpressionException e) {
player.printError(e.getMessage()); player.printError(e.getMessage());
return 0;
} }
} }
@Command( @Command(
aliases = { "/generatebiome", "/genbiome", "/gb" }, name = "/generatebiome",
usage = "<biome> <expression>", aliases = { "/genbiome", "/gb" },
desc = "Sets biome according to a formula.", desc = "Sets biome according to a formula.",
help = descFooter = "See also https://tinyurl.com/wesyntax."
"Generates a shape according to a formula that is expected to\n" +
"return positive numbers (true) if the point is inside the shape\n" +
"Sets the biome of blocks in that shape.\n" +
"Flags:\n" +
" -h to generate a hollow shape\n" +
" -r to use raw minecraft coordinates\n" +
" -o is like -r, except offset from placement.\n" +
" -c is like -r, except offset selection center.\n" +
"If neither -r nor -o is given, the selection is mapped to -1..1\n" +
"See also tinyurl.com/wesyntax.",
flags = "hroc",
min = 2,
max = -1
) )
@CommandPermissions("worldedit.generation.shape.biome") @CommandPermissions("worldedit.generation.shape.biome")
@Logging(ALL) @Logging(ALL)
public void generateBiome(Player player, LocalSession session, EditSession editSession, public int generateBiome(Player player, LocalSession session, EditSession editSession,
@Selection Region region, @Selection Region region,
BiomeType target, @Arg(desc = "The biome type to set")
@Text String expression, BiomeType target,
@Switch('h') boolean hollow, @Arg(desc = "Expression to test block placement locations and set biome type")
@Switch('r') boolean useRawCoords, String expression,
@Switch('o') boolean offset, @Switch(name = 'h', desc = "Generate a hollow shape")
@Switch('c') boolean offsetCenter) throws WorldEditException { boolean hollow,
@Switch(name = 'r', desc = "Use the game's coordinate origin")
boolean useRawCoords,
@Switch(name = 'o', desc = "Use the placement's coordinate origin")
boolean offset,
@Switch(name = 'c', desc = "Use the selection's center as origin")
boolean offsetCenter) throws WorldEditException {
final Vector3 zero; final Vector3 zero;
Vector3 unit; Vector3 unit;
@ -375,8 +375,10 @@ public class GenerationCommands {
final int affected = editSession.makeBiomeShape(region, zero, unit, target, expression, hollow, session.getTimeout()); final int affected = editSession.makeBiomeShape(region, zero, unit, target, expression, hollow, session.getTimeout());
player.findFreePosition(); player.findFreePosition();
player.print("" + affected + " columns affected."); player.print("" + affected + " columns affected.");
return affected;
} catch (ExpressionException e) { } catch (ExpressionException e) {
player.printError(e.getMessage()); player.printError(e.getMessage());
return 0;
} }
} }

Datei anzeigen

@ -0,0 +1,68 @@
package com.sk89q.worldedit.command.argument;
import com.google.common.base.Splitter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import org.enginehub.piston.converter.ArgumentConverter;
import org.enginehub.piston.converter.ConversionResult;
import org.enginehub.piston.converter.SuccessfulConversion;
import org.enginehub.piston.inject.InjectedValueAccess;
import java.util.List;
import static com.google.common.base.Preconditions.checkArgument;
public class CommaSeparatedValuesConverter<T> implements ArgumentConverter<T> {
public static <T> CommaSeparatedValuesConverter<T> wrap(ArgumentConverter<T> delegate) {
return wrapAndLimit(delegate, -1);
}
public static <T> CommaSeparatedValuesConverter<T> wrapAndLimit(ArgumentConverter<T> delegate, int maximum) {
return new CommaSeparatedValuesConverter<>(delegate, maximum);
}
private static final Splitter COMMA = Splitter.on(',');
private final ArgumentConverter<T> delegate;
private final int maximum;
private CommaSeparatedValuesConverter(ArgumentConverter<T> delegate, int maximum) {
checkArgument(maximum == -1 || maximum > 1,
"Maximum must be bigger than 1, or exactly -1");
this.delegate = delegate;
this.maximum = maximum;
}
@Override
public String describeAcceptableArguments() {
StringBuilder result = new StringBuilder();
if (maximum > -1) {
result.append("up to ").append(maximum).append(' ');
}
result.append("comma separated values of ")
.append(delegate.describeAcceptableArguments());
result.setCharAt(0, Character.toUpperCase(result.charAt(0)));
return result.toString();
}
@Override
public List<String> getSuggestions(String input) {
String lastInput = Iterables.getLast(COMMA.split(input));
return delegate.getSuggestions(lastInput);
}
@Override
public ConversionResult<T> convert(String argument, InjectedValueAccess context) {
ImmutableList.Builder<T> result = ImmutableList.builder();
for (String input : COMMA.split(argument)) {
ConversionResult<T> temp = delegate.convert(input, context);
if (!temp.isSuccessful()) {
return temp;
}
result.addAll(temp.get());
}
return SuccessfulConversion.from(result.build());
}
}

Datei anzeigen

@ -19,8 +19,6 @@
package com.sk89q.worldedit.command.argument; package com.sk89q.worldedit.command.argument;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.minecraft.util.commands.CommandLocals;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
@ -29,23 +27,30 @@ import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.util.command.argument.CommandArgs;
import com.sk89q.worldedit.util.command.composition.SimpleCommand;
import com.sk89q.worldedit.world.World; 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.SuccessfulConversion;
import org.enginehub.piston.inject.InjectedValueAccess;
import org.enginehub.piston.inject.Key;
public class PatternParser extends SimpleCommand<Pattern> { public class PatternConverter implements ArgumentConverter<Pattern> {
private final StringParser stringParser; public static void register(WorldEdit worldEdit, CommandManager commandManager) {
commandManager.registerConverter(Key.of(Pattern.class), new PatternConverter(worldEdit));
}
public PatternParser(String name) { private final WorldEdit worldEdit;
stringParser = addParameter(new StringParser(name, "The pattern"));
private PatternConverter(WorldEdit worldEdit) {
this.worldEdit = worldEdit;
} }
@Override @Override
public Pattern call(CommandArgs args, CommandLocals locals) throws CommandException { public ConversionResult<Pattern> convert(String argument, InjectedValueAccess context) {
String patternString = stringParser.call(args, locals); Actor actor = context.injectedValue(Key.of(Actor.class))
.orElseThrow(() -> new IllegalStateException("No actor"));
Actor actor = locals.get(Actor.class);
LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor); LocalSession session = WorldEdit.getInstance().getSessionManager().get(actor);
ParserContext parserContext = new ParserContext(); ParserContext parserContext = new ParserContext();
@ -59,20 +64,16 @@ public class PatternParser extends SimpleCommand<Pattern> {
parserContext.setSession(session); parserContext.setSession(session);
try { try {
return WorldEdit.getInstance().getPatternFactory().parseFromInput(patternString, parserContext); return SuccessfulConversion.fromSingle(
worldEdit.getPatternFactory().parseFromInput(argument, parserContext)
);
} catch (InputParseException e) { } catch (InputParseException e) {
throw new CommandException(e.getMessage(), e); throw new IllegalArgumentException(e);
} }
} }
@Override @Override
public String getDescription() { public String describeAcceptableArguments() {
return "Choose a pattern"; return "any pattern";
} }
@Override
public boolean testPermission0(CommandLocals locals) {
return true;
}
} }

Datei anzeigen

@ -35,12 +35,14 @@ import com.sk89q.worldedit.util.command.composition.SimpleCommand;
public class ReplaceParser extends SimpleCommand<Contextual<? extends RegionFunction>> { public class ReplaceParser extends SimpleCommand<Contextual<? extends RegionFunction>> {
private final PatternParser fillArg = addParameter(new PatternParser("fillPattern")); // TODO rewrite for new system
// private final PatternParser fillArg = addParameter(new PatternParser("fillPattern"));
@Override @Override
public Contextual<RegionFunction> call(CommandArgs args, CommandLocals locals) throws CommandException { public Contextual<RegionFunction> call(CommandArgs args, CommandLocals locals) throws CommandException {
Pattern fill = fillArg.call(args, locals); // Pattern fill = fillArg.call(args, locals);
return new ReplaceFactory(fill); // return new ReplaceFactory(fill);
return null;
} }
@Override @Override

Datei anzeigen

@ -0,0 +1,16 @@
package com.sk89q.worldedit.extension.platform;
import com.google.auto.value.AutoAnnotation;
import com.sk89q.worldedit.internal.annotation.Radii;
/**
* Holder for generated annotation classes.
*/
class Annotations {
@AutoAnnotation
static Radii radii(int value) {
return new AutoAnnotation_Annotations_radii(value);
}
}

Datei anzeigen

@ -20,6 +20,7 @@
package com.sk89q.worldedit.extension.platform; package com.sk89q.worldedit.extension.platform;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
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.IncompleteRegionException;
import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalConfiguration;
@ -35,11 +36,15 @@ import com.sk89q.worldedit.command.ClipboardCommands;
import com.sk89q.worldedit.command.ClipboardCommandsRegistration; import com.sk89q.worldedit.command.ClipboardCommandsRegistration;
import com.sk89q.worldedit.command.GeneralCommands; import com.sk89q.worldedit.command.GeneralCommands;
import com.sk89q.worldedit.command.GeneralCommandsRegistration; import com.sk89q.worldedit.command.GeneralCommandsRegistration;
import com.sk89q.worldedit.command.GenerationCommands;
import com.sk89q.worldedit.command.GenerationCommandsRegistration;
import com.sk89q.worldedit.command.SchematicCommands; import com.sk89q.worldedit.command.SchematicCommands;
import com.sk89q.worldedit.command.SchematicCommandsRegistration; import com.sk89q.worldedit.command.SchematicCommandsRegistration;
import com.sk89q.worldedit.command.argument.Arguments; import com.sk89q.worldedit.command.argument.Arguments;
import com.sk89q.worldedit.command.argument.CommaSeparatedValuesConverter;
import com.sk89q.worldedit.command.argument.DirectionConverter; import com.sk89q.worldedit.command.argument.DirectionConverter;
import com.sk89q.worldedit.command.argument.MaskConverter; import com.sk89q.worldedit.command.argument.MaskConverter;
import com.sk89q.worldedit.command.argument.PatternConverter;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.PermissionCondition; import com.sk89q.worldedit.command.util.PermissionCondition;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
@ -65,6 +70,7 @@ import com.sk89q.worldedit.world.World;
import org.enginehub.piston.Command; import org.enginehub.piston.Command;
import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandManager;
import org.enginehub.piston.DefaultCommandManagerService; import org.enginehub.piston.DefaultCommandManagerService;
import org.enginehub.piston.converter.ArgumentConverters;
import org.enginehub.piston.exception.CommandException; import org.enginehub.piston.exception.CommandException;
import org.enginehub.piston.exception.CommandExecutionException; import org.enginehub.piston.exception.CommandExecutionException;
import org.enginehub.piston.exception.ConditionFailedException; import org.enginehub.piston.exception.ConditionFailedException;
@ -171,6 +177,14 @@ public final class PlatformCommandMananger {
private void registerArgumentConverters() { private void registerArgumentConverters() {
DirectionConverter.register(worldEdit, commandManager); DirectionConverter.register(worldEdit, commandManager);
MaskConverter.register(worldEdit, commandManager); MaskConverter.register(worldEdit, commandManager);
PatternConverter.register(worldEdit, commandManager);
for (int count = 2; count <= 3; count++) {
commandManager.registerConverter(Key.of(double.class, Annotations.radii(count)),
CommaSeparatedValuesConverter.wrapAndLimit(ArgumentConverters.get(
TypeToken.of(double.class)
), count)
);
}
} }
private void registerAlwaysInjectedValues() { private void registerAlwaysInjectedValues() {
@ -258,13 +272,17 @@ public final class PlatformCommandMananger {
GeneralCommandsRegistration.builder(), GeneralCommandsRegistration.builder(),
new GeneralCommands(worldEdit) new GeneralCommands(worldEdit)
); );
register(
commandManager,
GenerationCommandsRegistration.builder(),
new GenerationCommands(worldEdit)
);
// Unported commands are below. Delete once they're added to the main manager above. // Unported commands are below. Delete once they're added to the main manager above.
/* /*
dispatcher = new CommandGraph() dispatcher = new CommandGraph()
.builder(builder) .builder(builder)
.commands() .commands()
.registerMethods(new GenerationCommands(worldEdit))
.registerMethods(new HistoryCommands(worldEdit)) .registerMethods(new HistoryCommands(worldEdit))
.registerMethods(new NavigationCommands(worldEdit)) .registerMethods(new NavigationCommands(worldEdit))
.registerMethods(new RegionCommands(worldEdit)) .registerMethods(new RegionCommands(worldEdit))

Datei anzeigen

@ -0,0 +1,40 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by the
* Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit.internal.annotation;
import org.enginehub.piston.inject.InjectAnnotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotates a {@code double} parameter to inject multiple radii values.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
@InjectAnnotation
public @interface Radii {
/**
* Number of radii values to inject at maximum. May inject less.
*/
int value();
}