mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 09:47:38 +00:00
Add more variable args for expressions, quoting
This commit is contained in:
parent
d4fce65abc
commit
82c4846436
@ -273,8 +273,8 @@ public class GenerationCommands {
|
|||||||
@Selection Region region,
|
@Selection Region region,
|
||||||
@Arg(desc = "The pattern of blocks to set")
|
@Arg(desc = "The pattern of blocks to set")
|
||||||
Pattern pattern,
|
Pattern pattern,
|
||||||
@Arg(desc = "Expression to test block placement locations and set block type")
|
@Arg(desc = "Expression to test block placement locations and set block type", variable = true)
|
||||||
String expression,
|
List<String> expression,
|
||||||
@Switch(name = 'h', desc = "Generate a hollow shape")
|
@Switch(name = 'h', desc = "Generate a hollow shape")
|
||||||
boolean hollow,
|
boolean hollow,
|
||||||
@Switch(name = 'r', desc = "Use the game's coordinate origin")
|
@Switch(name = 'r', desc = "Use the game's coordinate origin")
|
||||||
@ -312,7 +312,7 @@ public class GenerationCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final int affected = editSession.makeShape(region, zero, unit, pattern, expression, hollow, session.getTimeout());
|
final int affected = editSession.makeShape(region, zero, unit, pattern, String.join(" ", 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;
|
return affected;
|
||||||
@ -334,8 +334,8 @@ public class GenerationCommands {
|
|||||||
@Selection Region region,
|
@Selection Region region,
|
||||||
@Arg(desc = "The biome type to set")
|
@Arg(desc = "The biome type to set")
|
||||||
BiomeType target,
|
BiomeType target,
|
||||||
@Arg(desc = "Expression to test block placement locations and set biome type")
|
@Arg(desc = "Expression to test block placement locations and set biome type", variable = true)
|
||||||
String expression,
|
List<String> expression,
|
||||||
@Switch(name = 'h', desc = "Generate a hollow shape")
|
@Switch(name = 'h', desc = "Generate a hollow shape")
|
||||||
boolean hollow,
|
boolean hollow,
|
||||||
@Switch(name = 'r', desc = "Use the game's coordinate origin")
|
@Switch(name = 'r', desc = "Use the game's coordinate origin")
|
||||||
@ -372,7 +372,7 @@ public class GenerationCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final int affected = editSession.makeBiomeShape(region, zero, unit, target, expression, hollow, session.getTimeout());
|
final int affected = editSession.makeBiomeShape(region, zero, unit, target, String.join(" ", expression), hollow, session.getTimeout());
|
||||||
player.findFreePosition();
|
player.findFreePosition();
|
||||||
player.print("" + affected + " columns affected.");
|
player.print("" + affected + " columns affected.");
|
||||||
return affected;
|
return affected;
|
||||||
|
@ -382,8 +382,8 @@ public class RegionCommands {
|
|||||||
@Logging(ALL)
|
@Logging(ALL)
|
||||||
public int deform(Player player, LocalSession session, EditSession editSession,
|
public int deform(Player player, LocalSession session, EditSession editSession,
|
||||||
@Selection Region region,
|
@Selection Region region,
|
||||||
@Arg(desc = "The expression to use")
|
@Arg(desc = "The expression to use", variable = true)
|
||||||
String expression,
|
List<String> expression,
|
||||||
@Switch(name = 'r', desc = "Use the game's coordinate origin")
|
@Switch(name = 'r', desc = "Use the game's coordinate origin")
|
||||||
boolean useRawCoords,
|
boolean useRawCoords,
|
||||||
@Switch(name = 'o', desc = "Use the selection's center as origin")
|
@Switch(name = 'o', desc = "Use the selection's center as origin")
|
||||||
@ -410,7 +410,7 @@ public class RegionCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final int affected = editSession.deformRegion(region, zero, unit, expression, session.getTimeout());
|
final int affected = editSession.deformRegion(region, zero, unit, String.join(" ", expression), session.getTimeout());
|
||||||
player.findFreePosition();
|
player.findFreePosition();
|
||||||
player.print(affected + " block(s) have been deformed.");
|
player.print(affected + " block(s) have been deformed.");
|
||||||
return affected;
|
return affected;
|
||||||
|
@ -492,10 +492,10 @@ public class UtilityCommands {
|
|||||||
)
|
)
|
||||||
@CommandPermissions("worldedit.calc")
|
@CommandPermissions("worldedit.calc")
|
||||||
public void calc(Actor actor,
|
public void calc(Actor actor,
|
||||||
@Arg(desc = "Expression to evaluate")
|
@Arg(desc = "Expression to evaluate", variable = true)
|
||||||
String input) {
|
List<String> input) {
|
||||||
try {
|
try {
|
||||||
Expression expression = Expression.compile(input);
|
Expression expression = Expression.compile(String.join(" ", input));
|
||||||
double result = expression.evaluate(
|
double result = expression.evaluate(
|
||||||
new double[]{}, WorldEdit.getInstance().getSessionManager().get(actor).getTimeout());
|
new double[]{}, WorldEdit.getInstance().getSessionManager().get(actor).getTimeout());
|
||||||
String formatted = formatter.format(result);
|
String formatted = formatter.format(result);
|
||||||
|
@ -89,12 +89,12 @@ import com.sk89q.worldedit.internal.command.CommandLoggingHandler;
|
|||||||
import com.sk89q.worldedit.internal.command.WorldEditExceptionConverter;
|
import com.sk89q.worldedit.internal.command.WorldEditExceptionConverter;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.session.request.Request;
|
import com.sk89q.worldedit.session.request.Request;
|
||||||
|
import com.sk89q.worldedit.util.command.CommandArgParser;
|
||||||
import com.sk89q.worldedit.util.command.CommandRegistrationHandler;
|
import com.sk89q.worldedit.util.command.CommandRegistrationHandler;
|
||||||
import com.sk89q.worldedit.util.command.parametric.ExceptionConverter;
|
import com.sk89q.worldedit.util.command.parametric.ExceptionConverter;
|
||||||
import com.sk89q.worldedit.util.eventbus.Subscribe;
|
import com.sk89q.worldedit.util.eventbus.Subscribe;
|
||||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
||||||
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
|
|
||||||
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
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;
|
||||||
@ -439,12 +439,16 @@ public final class PlatformCommandManager {
|
|||||||
return split;
|
return split;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String[] parseArgs(String input) {
|
||||||
|
return new CommandArgParser(input).parseArgs().toArray(String[]::new);
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void handleCommand(CommandEvent event) {
|
public void handleCommand(CommandEvent event) {
|
||||||
Request.reset();
|
Request.reset();
|
||||||
|
|
||||||
Actor actor = platformManager.createProxyActor(event.getActor());
|
Actor actor = platformManager.createProxyActor(event.getActor());
|
||||||
String[] split = commandDetection(event.getArguments().substring(1).split(" "));
|
String[] split = commandDetection(parseArgs(event.getArguments().substring(1)));
|
||||||
|
|
||||||
// No command found!
|
// No command found!
|
||||||
if (!commandManager.containsCommand(split[0])) {
|
if (!commandManager.containsCommand(split[0])) {
|
||||||
|
@ -0,0 +1,85 @@
|
|||||||
|
package com.sk89q.worldedit.util.command;
|
||||||
|
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
public class CommandArgParser {
|
||||||
|
|
||||||
|
private enum State {
|
||||||
|
NORMAL,
|
||||||
|
QUOTE
|
||||||
|
}
|
||||||
|
|
||||||
|
private final Stream.Builder<String> args = Stream.builder();
|
||||||
|
private final StringBuilder currentArg = new StringBuilder();
|
||||||
|
private final String input;
|
||||||
|
private int index = 0;
|
||||||
|
private State state = State.NORMAL;
|
||||||
|
|
||||||
|
public CommandArgParser(String input) {
|
||||||
|
this.input = input;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stream<String> parseArgs() {
|
||||||
|
for (; index < input.length(); index++) {
|
||||||
|
char c = input.charAt(index);
|
||||||
|
switch (state) {
|
||||||
|
case NORMAL:
|
||||||
|
handleNormal(c);
|
||||||
|
break;
|
||||||
|
case QUOTE:
|
||||||
|
handleQuote(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finishArg(true);
|
||||||
|
return args.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleNormal(char c) {
|
||||||
|
switch (c) {
|
||||||
|
case '"':
|
||||||
|
state = State.QUOTE;
|
||||||
|
break;
|
||||||
|
case ' ':
|
||||||
|
finishArg(true);
|
||||||
|
break;
|
||||||
|
case '\\':
|
||||||
|
if (index + 1 < input.length()) {
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
appendChar(input.charAt(index));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
appendChar(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleQuote(char c) {
|
||||||
|
switch (c) {
|
||||||
|
case '"':
|
||||||
|
state = State.NORMAL;
|
||||||
|
finishArg(false);
|
||||||
|
break;
|
||||||
|
case '\\':
|
||||||
|
if (index + 1 < input.length()) {
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
appendChar(input.charAt(index));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
appendChar(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void finishArg(boolean requireText) {
|
||||||
|
if (currentArg.length() == 0 && requireText) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
args.add(currentArg.toString());
|
||||||
|
currentArg.setLength(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void appendChar(char c) {
|
||||||
|
currentArg.append(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user