Basic tab suggestions

Dieser Commit ist enthalten in:
Jesse Boyd 2018-08-18 01:37:35 +10:00
Ursprung 5d47d1bce6
Commit 0cc0ee7f03
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 59F1DE6293AF6E1F
8 geänderte Dateien mit 53 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -10,7 +10,7 @@ database: false
#softdepend: [WorldGuard, PlotSquared, MCore, Factions, GriefPrevention, Residence, Towny, PlotMe, PreciousStones]
commands:
fcancel:
description: (FAWE) Cancel your edit
description: "Cancel your edit"
aliases: [fawecancel,/fcancel,/cancel,/fawecancel]
permissions:
fawe.plotsquared:

Datei anzeigen

@ -34,6 +34,6 @@ public class MaskBinding extends FaweBinding {
// List<String> blocks = BundledBlockData.getInstance().getBlockNames(split2[0]);
// return MainUtil.prepend(start, blocks);
// }
return new ArrayList<>();
return super.getSuggestions(parameter, prefix);
}
}
}

Datei anzeigen

@ -3,6 +3,7 @@ package com.boydti.fawe.command;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.util.command.parametric.ParameterData;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class PatternBinding extends FaweBinding {
@ -15,7 +16,7 @@ public class PatternBinding extends FaweBinding {
@Override
public List<String> getSuggestions(ParameterData parameter, String prefix) {
return new ArrayList<>();
return super.getSuggestions(parameter, prefix);
// int index = prefix.lastIndexOf(",|%");
// String start = index != -1 ? prefix.substring(0, index) : "";
// String current = index != -1 ? prefix.substring(index) : prefix;

Datei anzeigen

@ -52,6 +52,13 @@ public class StringMan {
return -1;
}
public static String prettyFormat(double d) {
if (d == Double.MIN_VALUE) return "-∞";
if (d == Double.MAX_VALUE) return "";
if(d == (long) d) return String.format("%d",(long)d);
else return String.format("%s",d);
}
public static boolean isBracketForwards(char c) {
switch (c) {
case '[':

Datei anzeigen

@ -5,10 +5,6 @@ import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface SuggestedRange {
Class clazz() default Link.class;
String value();
/**
* The minimum value that the number can be at, inclusive.
*

Datei anzeigen

@ -223,11 +223,13 @@ public abstract class AParametricCallable implements CommandCallable {
prefix = "";
}
// System.out.println("(0) Return get binding suggestions " + parameter + " | " + prefix);
return parameter.getBinding().getSuggestions(parameter, prefix);
}
}
// This should not happen
// System.out.println("(1) This should not happen");
return new ArrayList<String>();
}
@ -240,7 +242,6 @@ public abstract class AParametricCallable implements CommandCallable {
if (parameter.getFlag() != null) {
continue; // We already handled flags
}
try {
scoped.mark();
parameter.getBinding().bind(parameter, scoped, true);
@ -253,26 +254,32 @@ public abstract class AParametricCallable implements CommandCallable {
// For /command value1 |value2
// For /command |value1 value2
if (suggestable.forHangingValue()) {
// System.out.println("(2) Return get binding dangling " + parameter + " | " + "");
return parameter.getBinding().getSuggestions(parameter, "");
} else {
// For /command value1| value2
if (lastConsumer != null) {
// System.out.println("(3) Return get consumed " + lastConsumer + " | " + lastConsumed);
return lastConsumer.getBinding().getSuggestions(lastConsumer, lastConsumed);
// For /command| value1 value2
// This should never occur
} else {
// System.out.println("(4) Invalid suggestion context");
throw new RuntimeException("Invalid suggestion context");
}
}
} catch (ParameterException | InvocationTargetException e) {
SuggestInputParseException suggestion = SuggestInputParseException.get(e);
if (suggestion != null) {
// System.out.println("(5) Has suggestion " + suggestion.getSuggestions());
return suggestion.getSuggestions();
}
if (suggestable.forHangingValue()) {
String name = getDescription().getParameters().get(consumerIndex).getName();
// System.out.println("(6) Has dangling invalid " + name + " | " + e.getMessage());
throw new InvalidUsageException("For parameter '" + name + "': " + e.getMessage(), this);
} else {
// System.out.println("(7) HGet binding suggestions " + parameter + " | " + lastConsumed);
return parameter.getBinding().getSuggestions(parameter, "");
}
}
@ -281,13 +288,16 @@ public abstract class AParametricCallable implements CommandCallable {
if (suggestable.forHangingValue()) {
// There's nothing that we can suggest because there's no more parameters
// to add on, and we can't change the previous parameter
// System.out.println("(7.1) No more parameters");
return new ArrayList<String>();
} else {
// For /command value1 value2|
if (lastConsumer != null) {
// System.out.println("(8) Get binding suggestions " + lastConsumer + " | " + lastConsumed);
return lastConsumer.getBinding().getSuggestions(lastConsumer, lastConsumed);
// This should never occur
} else {
// System.out.println("(9) Invalid suggestion context");
throw new RuntimeException("Invalid suggestion context");
}

Datei anzeigen

@ -19,13 +19,16 @@
package com.sk89q.worldedit.util.command.parametric;
import com.boydti.fawe.util.StringMan;
import com.sk89q.minecraft.util.commands.CommandException;
import com.sk89q.worldedit.util.command.binding.Range;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
@ -184,6 +187,25 @@ public class BindingHelper implements Binding {
@Override
public List<String> getSuggestions(ParameterData parameter, String prefix) {
if (prefix.isEmpty()) {
char bracket = parameter.isOptional() ? '[' : '<';
char endBracket = StringMan.getMatchingBracket(bracket);
StringBuilder result = new StringBuilder();
result.append(bracket);
if (parameter.getFlag() != null) {
result.append('-').append(parameter.getFlag()).append(' ');
}
result.append(parameter.getName());
if (parameter.getDefaultValue() != null) {
result.append('=').append(StringMan.join(parameter.getDefaultValue(), " "));
}
Range range = parameter.getModifier(Range.class);
if (range != null) {
result.append('|').append(StringMan.prettyFormat(range.min())).append(",").append(StringMan.prettyFormat(range.max()));
}
result.append(endBracket);
return Collections.singletonList(result.toString());
}
return new ArrayList<>();
}

Datei anzeigen

@ -26,6 +26,7 @@ import com.sk89q.worldedit.util.command.binding.Text;
import javax.xml.ws.Provider;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.concurrent.Callable;
@ -119,6 +120,13 @@ public class ParameterData extends SimpleParameter {
return modifiers;
}
public <T extends Annotation> T getModifier(Class<T> annotatedType) {
for (Annotation annotation : getModifiers()) {
if (annotation.getClass() == annotatedType) return (T) annotation;
}
return null;
}
/**
* Set the list of modifiers.
*