mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 03:56:41 +00:00
comments / minor compiling
This commit is contained in:
@ -1,11 +1,13 @@
|
||||
package com.sk89q.worldedit.extension.factory;
|
||||
|
||||
import com.boydti.fawe.command.FaweParser;
|
||||
import com.boydti.fawe.command.SuggestInputParseException;
|
||||
import com.boydti.fawe.object.extent.MultiTransform;
|
||||
import com.boydti.fawe.object.extent.RandomTransform;
|
||||
import com.boydti.fawe.object.extent.ResettableExtent;
|
||||
import com.boydti.fawe.object.random.TrueRandom;
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.command.TransformCommands;
|
||||
@ -22,16 +24,7 @@ import java.util.Map;
|
||||
public class DefaultTransformParser extends FaweParser<ResettableExtent> {
|
||||
|
||||
public DefaultTransformParser(WorldEdit worldEdit) {
|
||||
super(worldEdit);
|
||||
this.register(new TransformCommands());
|
||||
}
|
||||
|
||||
|
||||
public void register(Object clazz) {
|
||||
ParametricBuilder builder = new ParametricBuilder();
|
||||
builder.setAuthorizer(new ActorAuthorizer());
|
||||
builder.addBinding(new WorldEditBinding(worldEdit));
|
||||
builder.registerMethodsAsCommands(dispatcher, clazz);
|
||||
super(worldEdit, ResettableExtent.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -57,49 +50,54 @@ public class DefaultTransformParser extends FaweParser<ResettableExtent> {
|
||||
double chance = 1;
|
||||
if (command.isEmpty()) {
|
||||
transform = parseFromInput(StringMan.join(entry.getValue(), ','), context);
|
||||
} else if (dispatcher.get(command) == null) {
|
||||
// Legacy syntax
|
||||
int percentIndex = command.indexOf('%');
|
||||
if (percentIndex != -1) { // Legacy percent pattern
|
||||
chance = Expression.compile(command.substring(0, percentIndex)).evaluate();
|
||||
command = command.substring(percentIndex + 1);
|
||||
if (!entry.getValue().isEmpty()) {
|
||||
if (!command.isEmpty()) command += " ";
|
||||
command += StringMan.join(entry.getValue(), " ");
|
||||
}
|
||||
transform = parseFromInput(command, context);
|
||||
} else {
|
||||
throw new NoMatchException("See: //transforms");
|
||||
}
|
||||
} else {
|
||||
List<String> args = entry.getValue();
|
||||
if (!args.isEmpty()) {
|
||||
command += " " + StringMan.join(args, " ");
|
||||
String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
|
||||
try {
|
||||
transform = Iterables.getFirst(parse(cmdArgs, actor), null);
|
||||
} catch (SuggestInputParseException rethrow) {
|
||||
throw rethrow;
|
||||
} catch (Throwable e) {
|
||||
throw new NoMatchException("See: //transforms");
|
||||
}
|
||||
transform = (ResettableExtent) dispatcher.call(command, locals, new String[0]);
|
||||
}
|
||||
if (pe.and) { // &
|
||||
intersectionChances.add(chance);
|
||||
intersection.add(transform);
|
||||
} else {
|
||||
if (!intersection.isEmpty()) {
|
||||
if (intersection.size() == 1) {
|
||||
throw new InputParseException("Error, floating &");
|
||||
if (transform == null) {
|
||||
// Legacy syntax
|
||||
int percentIndex = command.indexOf('%');
|
||||
if (percentIndex != -1) { // Legacy percent pattern
|
||||
chance = Expression.compile(command.substring(0, percentIndex)).evaluate();
|
||||
command = command.substring(percentIndex + 1);
|
||||
if (!entry.getValue().isEmpty()) {
|
||||
if (!command.isEmpty()) command += " ";
|
||||
command += StringMan.join(entry.getValue(), " ");
|
||||
}
|
||||
transform = parseFromInput(command, context);
|
||||
} else {
|
||||
throw new NoMatchException("See: //transforms");
|
||||
}
|
||||
MultiTransform multi = new MultiTransform();
|
||||
double total = 0;
|
||||
for (int i = 0; i < intersection.size(); i++) {
|
||||
Double value = intersectionChances.get(i);
|
||||
total += value;
|
||||
multi.add(intersection.get(i), value);
|
||||
}
|
||||
union.add(multi);
|
||||
unionChances.add(total);
|
||||
intersection.clear();
|
||||
intersectionChances.clear();
|
||||
}
|
||||
unionChances.add(chance);
|
||||
union.add(transform);
|
||||
if (pe.and) { // &
|
||||
intersectionChances.add(chance);
|
||||
intersection.add(transform);
|
||||
} else {
|
||||
if (!intersection.isEmpty()) {
|
||||
if (intersection.size() == 1) {
|
||||
throw new InputParseException("Error, floating &");
|
||||
}
|
||||
MultiTransform multi = new MultiTransform();
|
||||
double total = 0;
|
||||
for (int i = 0; i < intersection.size(); i++) {
|
||||
Double value = intersectionChances.get(i);
|
||||
total += value;
|
||||
multi.add(intersection.get(i), value);
|
||||
}
|
||||
union.add(multi);
|
||||
unionChances.add(total);
|
||||
intersection.clear();
|
||||
intersectionChances.clear();
|
||||
}
|
||||
unionChances.add(chance);
|
||||
union.add(transform);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
|
@ -48,8 +48,8 @@ import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class DefaultMaskParser extends FaweParser<Mask> {
|
||||
public DefaultMaskParser(WorldEdit worldEdit, PlatformCommandManager manager) {
|
||||
super(worldEdit, manager, Mask.class);
|
||||
public DefaultMaskParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, Mask.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -73,12 +73,40 @@ public class DefaultMaskParser extends FaweParser<Mask> {
|
||||
ParseEntry pe = entry.getKey();
|
||||
final String command = pe.input;
|
||||
String full = pe.full;
|
||||
Mask mask;
|
||||
Mask mask = null;
|
||||
if (command.isEmpty()) {
|
||||
mask = parseFromInput(StringMan.join(entry.getValue(), ','), context);
|
||||
} else {
|
||||
mask = Iterables.getFirst(parse(input, actor), null);
|
||||
SuggestInputParseException suggestion = null; // TODO NOT IMPLEMENTED suggestion
|
||||
List<String> args = entry.getValue();
|
||||
String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
|
||||
try {
|
||||
mask = Iterables.getFirst(parse(cmdArgs, actor), null);
|
||||
} catch (SuggestInputParseException rethrow) {
|
||||
throw rethrow;
|
||||
} catch (Throwable e) {
|
||||
// TODO NOT IMPLEMENTED
|
||||
// throw SuggestInputParseException.of(e, full, () -> {
|
||||
// try {
|
||||
// List<String> suggestions = dispatcher.get(command).getCallable().getSuggestions(cmdArgs, locals);
|
||||
// if (suggestions.size() <= 2) {
|
||||
// for (int i = 0; i < suggestions.size(); i++) {
|
||||
// String suggestion = suggestions.get(i);
|
||||
// if (suggestion.indexOf(' ') != 0) {
|
||||
// String[] split = suggestion.split(" ");
|
||||
// suggestion = "[" + StringMan.join(split, "][") + "]";
|
||||
// suggestions.set(i, suggestion);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return suggestions;
|
||||
// } catch (CommandException e1) {
|
||||
// throw new InputParseException(e1.getMessage());
|
||||
// } catch (Throwable e2) {
|
||||
// e2.printStackTrace();
|
||||
// throw new InputParseException(e2.getMessage());
|
||||
// }
|
||||
// });
|
||||
}
|
||||
if (mask == null) {
|
||||
// Legacy patterns
|
||||
char char0 = command.charAt(0);
|
||||
@ -87,7 +115,7 @@ public class DefaultMaskParser extends FaweParser<Mask> {
|
||||
return parseFromInput(char0 + "[" + input.substring(1) + "]", context);
|
||||
}
|
||||
if (char0 == '#' || char0 == '?') {
|
||||
throw suggestion;
|
||||
// TODO NOT IMPLEMENTED
|
||||
// throw new SuggestInputParseException(new NoMatchException("Unknown mask: " + full + ", See: //masks"), full,
|
||||
// () -> {
|
||||
// if (full.length() == 1) return new ArrayList<>(dispatcher.getPrimaryAliases());
|
||||
@ -150,37 +178,6 @@ public class DefaultMaskParser extends FaweParser<Mask> {
|
||||
}
|
||||
}
|
||||
}
|
||||
// else {
|
||||
// List<String> args = entry.getValue();
|
||||
// String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
|
||||
// try {
|
||||
// mask = (Mask) dispatcher.call(command + cmdArgs, locals, new String[0]);
|
||||
// } catch (SuggestInputParseException rethrow) {
|
||||
// throw rethrow;
|
||||
// } catch (Throwable e) {
|
||||
// throw SuggestInputParseException.of(e, full, () -> {
|
||||
// try {
|
||||
// List<String> suggestions = dispatcher.get(command).getCallable().getSuggestions(cmdArgs, locals);
|
||||
// if (suggestions.size() <= 2) {
|
||||
// for (int i = 0; i < suggestions.size(); i++) {
|
||||
// String suggestion = suggestions.get(i);
|
||||
// if (suggestion.indexOf(' ') != 0) {
|
||||
// String[] split = suggestion.split(" ");
|
||||
// suggestion = "[" + StringMan.join(split, "][") + "]";
|
||||
// suggestions.set(i, suggestion);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return suggestions;
|
||||
// } catch (CommandException e1) {
|
||||
// throw new InputParseException(e1.getMessage());
|
||||
// } catch (Throwable e2) {
|
||||
// e2.printStackTrace();
|
||||
// throw new InputParseException(e2.getMessage());
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
if (pe.and) {
|
||||
masks.add(new ArrayList<>());
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import com.boydti.fawe.command.SuggestInputParseException;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.object.random.TrueRandom;
|
||||
import com.boydti.fawe.util.StringMan;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.minecraft.util.commands.CommandLocals;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
@ -47,8 +48,8 @@ import java.util.stream.Stream;
|
||||
|
||||
public class DefaultPatternParser extends FaweParser<Pattern> {
|
||||
|
||||
public DefaultPatternParser(WorldEdit worldEdit, PlatformCommandManager commandManager) {
|
||||
super(worldEdit, commandManager, Pattern.class);
|
||||
public DefaultPatternParser(WorldEdit worldEdit) {
|
||||
super(worldEdit, Pattern.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -72,90 +73,93 @@ public class DefaultPatternParser extends FaweParser<Pattern> {
|
||||
double chance = 1;
|
||||
if (command.isEmpty()) {
|
||||
pattern = parseFromInput(StringMan.join(entry.getValue(), ','), context);
|
||||
} else if (dispatcher.get(command) == null) {
|
||||
// Legacy patterns
|
||||
char char0 = command.charAt(0);
|
||||
boolean charMask = input.length() > 1 && input.charAt(1) != '[';
|
||||
if (charMask && input.charAt(0) == '=') {
|
||||
return parseFromInput(char0 + "[" + input.substring(1) + "]", context);
|
||||
}
|
||||
if (char0 == '#') {
|
||||
throw new SuggestInputParseException(new NoMatchException("Unknown pattern: " + full + ", See: //patterns"), full,
|
||||
() -> {
|
||||
if (full.length() == 1) return new ArrayList<>(dispatcher.getPrimaryAliases());
|
||||
return dispatcher.getAliases().stream().filter(
|
||||
s -> s.startsWith(command.toLowerCase(Locale.ROOT))
|
||||
).collect(Collectors.toList());
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if (charMask) {
|
||||
if (char0 == '$') {
|
||||
String value = command.substring(1) + ((entry.getValue().isEmpty()) ? ""
|
||||
: "[" + StringMan.join(entry.getValue(), "][") + "]");
|
||||
if (value.contains(":")) {
|
||||
if (value.charAt(0) == ':') {
|
||||
value.replaceFirst(":", "");
|
||||
}
|
||||
value = value.replaceAll(":", "][");
|
||||
}
|
||||
pattern = parseFromInput(char0 + "[" + value + "]", context);
|
||||
}
|
||||
}
|
||||
if (pattern == null) {
|
||||
if (command.startsWith("[")) {
|
||||
int end = command.lastIndexOf(']');
|
||||
pattern = parseFromInput(command.substring(1, end == -1 ? command.length() : end), context);
|
||||
} else {
|
||||
int percentIndex = command.indexOf('%');
|
||||
if (percentIndex != -1) { // Legacy percent pattern
|
||||
chance = Expression.compile(command.substring(0, percentIndex)).evaluate();
|
||||
String value = command.substring(percentIndex + 1);
|
||||
if (!entry.getValue().isEmpty()) {
|
||||
if (!value.isEmpty()) value += " ";
|
||||
value += StringMan.join(entry.getValue(), " ");
|
||||
}
|
||||
pattern = parseFromInput(value, context);
|
||||
} else { // legacy block pattern
|
||||
try {
|
||||
pattern = worldEdit.getBlockFactory().parseFromInput(pe.full, context);
|
||||
} catch (NoMatchException e) {
|
||||
throw new NoMatchException(e.getMessage() + " See: //patterns");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
List<String> args = entry.getValue();
|
||||
String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " "));
|
||||
try {
|
||||
pattern = (Pattern) dispatcher.call(command + cmdArgs, locals, new String[0]);
|
||||
pattern = Iterables.getFirst(parse(cmdArgs, actor), null);
|
||||
} catch (SuggestInputParseException rethrow) {
|
||||
throw rethrow;
|
||||
} catch (Throwable e) {
|
||||
throw SuggestInputParseException.of(e, full, () -> {
|
||||
try {
|
||||
List<String> suggestions = dispatcher.get(command).getCallable().getSuggestions(cmdArgs, locals);
|
||||
if (suggestions.size() <= 2) {
|
||||
for (int i = 0; i < suggestions.size(); i++) {
|
||||
String suggestion = suggestions.get(i);
|
||||
if (suggestion.indexOf(' ') != 0) {
|
||||
String[] split = suggestion.split(" ");
|
||||
suggestion = "[" + StringMan.join(split, "][") + "]";
|
||||
suggestions.set(i, suggestion);
|
||||
}
|
||||
// TODO NOT IMPLEMENTED
|
||||
// throw SuggestInputParseException.of(e, full, () -> {
|
||||
// try {
|
||||
// List<String> suggestions = dispatcher.get(command).getCallable().getSuggestions(cmdArgs, locals);
|
||||
// if (suggestions.size() <= 2) {
|
||||
// for (int i = 0; i < suggestions.size(); i++) {
|
||||
// String suggestion = suggestions.get(i);
|
||||
// if (suggestion.indexOf(' ') != 0) {
|
||||
// String[] split = suggestion.split(" ");
|
||||
// suggestion = "[" + StringMan.join(split, "][") + "]";
|
||||
// suggestions.set(i, suggestion);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return suggestions;
|
||||
// } catch (CommandException e1) {
|
||||
// throw new InputParseException(e1.getMessage());
|
||||
// } catch (Throwable e2) {
|
||||
// e2.printStackTrace();
|
||||
// throw new InputParseException(e2.getMessage());
|
||||
// }
|
||||
// });
|
||||
}
|
||||
if (pattern == null) {
|
||||
// Legacy patterns
|
||||
char char0 = command.charAt(0);
|
||||
boolean charMask = input.length() > 1 && input.charAt(1) != '[';
|
||||
if (charMask && input.charAt(0) == '=') {
|
||||
return parseFromInput(char0 + "[" + input.substring(1) + "]", context);
|
||||
}
|
||||
if (char0 == '#') {
|
||||
// TODO NOT IMPLEMENTED
|
||||
// throw new SuggestInputParseException(new NoMatchException("Unknown pattern: " + full + ", See: //patterns"), full,
|
||||
// () -> {
|
||||
// if (full.length() == 1) return new ArrayList<>(dispatcher.getPrimaryAliases());
|
||||
// return dispatcher.getAliases().stream().filter(
|
||||
// s -> s.startsWith(command.toLowerCase(Locale.ROOT))
|
||||
// ).collect(Collectors.toList());
|
||||
// }
|
||||
// );
|
||||
}
|
||||
|
||||
|
||||
if (charMask) {
|
||||
if (char0 == '$') {
|
||||
String value = command.substring(1) + ((entry.getValue().isEmpty()) ? ""
|
||||
: "[" + StringMan.join(entry.getValue(), "][") + "]");
|
||||
if (value.contains(":")) {
|
||||
if (value.charAt(0) == ':') {
|
||||
value.replaceFirst(":", "");
|
||||
}
|
||||
value = value.replaceAll(":", "][");
|
||||
}
|
||||
pattern = parseFromInput(char0 + "[" + value + "]", context);
|
||||
}
|
||||
}
|
||||
if (pattern == null) {
|
||||
if (command.startsWith("[")) {
|
||||
int end = command.lastIndexOf(']');
|
||||
pattern = parseFromInput(command.substring(1, end == -1 ? command.length() : end), context);
|
||||
} else {
|
||||
int percentIndex = command.indexOf('%');
|
||||
if (percentIndex != -1) { // Legacy percent pattern
|
||||
chance = Expression.compile(command.substring(0, percentIndex)).evaluate();
|
||||
String value = command.substring(percentIndex + 1);
|
||||
if (!entry.getValue().isEmpty()) {
|
||||
if (!value.isEmpty()) value += " ";
|
||||
value += StringMan.join(entry.getValue(), " ");
|
||||
}
|
||||
pattern = parseFromInput(value, context);
|
||||
} else { // legacy block pattern
|
||||
try {
|
||||
pattern = worldEdit.getBlockFactory().parseFromInput(pe.full, context);
|
||||
} catch (NoMatchException e) {
|
||||
throw new NoMatchException(e.getMessage() + " See: //patterns");
|
||||
}
|
||||
}
|
||||
return suggestions;
|
||||
} catch (CommandException e1) {
|
||||
throw new InputParseException(e1.getMessage());
|
||||
} catch (Throwable e2) {
|
||||
e2.printStackTrace();
|
||||
throw new InputParseException(e2.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pattern != null) {
|
||||
|
Reference in New Issue
Block a user