mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-12 04:28:34 +00:00
Basic tab suggestions
This commit is contained in:
@ -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");
|
||||
}
|
||||
|
||||
|
@ -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<>();
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
*
|
||||
|
Reference in New Issue
Block a user