Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-25 02:20:07 +01:00
Basic tab suggestions
Dieser Commit ist enthalten in:
Ursprung
5d47d1bce6
Commit
0cc0ee7f03
@ -10,7 +10,7 @@ database: false
|
|||||||
#softdepend: [WorldGuard, PlotSquared, MCore, Factions, GriefPrevention, Residence, Towny, PlotMe, PreciousStones]
|
#softdepend: [WorldGuard, PlotSquared, MCore, Factions, GriefPrevention, Residence, Towny, PlotMe, PreciousStones]
|
||||||
commands:
|
commands:
|
||||||
fcancel:
|
fcancel:
|
||||||
description: (FAWE) Cancel your edit
|
description: "Cancel your edit"
|
||||||
aliases: [fawecancel,/fcancel,/cancel,/fawecancel]
|
aliases: [fawecancel,/fcancel,/cancel,/fawecancel]
|
||||||
permissions:
|
permissions:
|
||||||
fawe.plotsquared:
|
fawe.plotsquared:
|
||||||
|
@ -34,6 +34,6 @@ public class MaskBinding extends FaweBinding {
|
|||||||
// List<String> blocks = BundledBlockData.getInstance().getBlockNames(split2[0]);
|
// List<String> blocks = BundledBlockData.getInstance().getBlockNames(split2[0]);
|
||||||
// return MainUtil.prepend(start, blocks);
|
// return MainUtil.prepend(start, blocks);
|
||||||
// }
|
// }
|
||||||
return new ArrayList<>();
|
return super.getSuggestions(parameter, prefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -3,6 +3,7 @@ package com.boydti.fawe.command;
|
|||||||
import com.sk89q.worldedit.WorldEdit;
|
import com.sk89q.worldedit.WorldEdit;
|
||||||
import com.sk89q.worldedit.util.command.parametric.ParameterData;
|
import com.sk89q.worldedit.util.command.parametric.ParameterData;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class PatternBinding extends FaweBinding {
|
public class PatternBinding extends FaweBinding {
|
||||||
@ -15,7 +16,7 @@ public class PatternBinding extends FaweBinding {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getSuggestions(ParameterData parameter, String prefix) {
|
public List<String> getSuggestions(ParameterData parameter, String prefix) {
|
||||||
return new ArrayList<>();
|
return super.getSuggestions(parameter, prefix);
|
||||||
// int index = prefix.lastIndexOf(",|%");
|
// int index = prefix.lastIndexOf(",|%");
|
||||||
// String start = index != -1 ? prefix.substring(0, index) : "";
|
// String start = index != -1 ? prefix.substring(0, index) : "";
|
||||||
// String current = index != -1 ? prefix.substring(index) : prefix;
|
// String current = index != -1 ? prefix.substring(index) : prefix;
|
||||||
|
@ -52,6 +52,13 @@ public class StringMan {
|
|||||||
return -1;
|
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) {
|
public static boolean isBracketForwards(char c) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '[':
|
case '[':
|
||||||
|
@ -5,10 +5,6 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface SuggestedRange {
|
public @interface SuggestedRange {
|
||||||
Class clazz() default Link.class;
|
|
||||||
String value();
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The minimum value that the number can be at, inclusive.
|
* The minimum value that the number can be at, inclusive.
|
||||||
*
|
*
|
||||||
|
@ -223,11 +223,13 @@ public abstract class AParametricCallable implements CommandCallable {
|
|||||||
prefix = "";
|
prefix = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// System.out.println("(0) Return get binding suggestions " + parameter + " | " + prefix);
|
||||||
return parameter.getBinding().getSuggestions(parameter, prefix);
|
return parameter.getBinding().getSuggestions(parameter, prefix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This should not happen
|
// This should not happen
|
||||||
|
// System.out.println("(1) This should not happen");
|
||||||
return new ArrayList<String>();
|
return new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -240,7 +242,6 @@ public abstract class AParametricCallable implements CommandCallable {
|
|||||||
if (parameter.getFlag() != null) {
|
if (parameter.getFlag() != null) {
|
||||||
continue; // We already handled flags
|
continue; // We already handled flags
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
scoped.mark();
|
scoped.mark();
|
||||||
parameter.getBinding().bind(parameter, scoped, true);
|
parameter.getBinding().bind(parameter, scoped, true);
|
||||||
@ -253,26 +254,32 @@ public abstract class AParametricCallable implements CommandCallable {
|
|||||||
// For /command value1 |value2
|
// For /command value1 |value2
|
||||||
// For /command |value1 value2
|
// For /command |value1 value2
|
||||||
if (suggestable.forHangingValue()) {
|
if (suggestable.forHangingValue()) {
|
||||||
|
// System.out.println("(2) Return get binding dangling " + parameter + " | " + "");
|
||||||
return parameter.getBinding().getSuggestions(parameter, "");
|
return parameter.getBinding().getSuggestions(parameter, "");
|
||||||
} else {
|
} else {
|
||||||
// For /command value1| value2
|
// For /command value1| value2
|
||||||
if (lastConsumer != null) {
|
if (lastConsumer != null) {
|
||||||
|
// System.out.println("(3) Return get consumed " + lastConsumer + " | " + lastConsumed);
|
||||||
return lastConsumer.getBinding().getSuggestions(lastConsumer, lastConsumed);
|
return lastConsumer.getBinding().getSuggestions(lastConsumer, lastConsumed);
|
||||||
// For /command| value1 value2
|
// For /command| value1 value2
|
||||||
// This should never occur
|
// This should never occur
|
||||||
} else {
|
} else {
|
||||||
|
// System.out.println("(4) Invalid suggestion context");
|
||||||
throw new RuntimeException("Invalid suggestion context");
|
throw new RuntimeException("Invalid suggestion context");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (ParameterException | InvocationTargetException e) {
|
} catch (ParameterException | InvocationTargetException e) {
|
||||||
SuggestInputParseException suggestion = SuggestInputParseException.get(e);
|
SuggestInputParseException suggestion = SuggestInputParseException.get(e);
|
||||||
if (suggestion != null) {
|
if (suggestion != null) {
|
||||||
|
// System.out.println("(5) Has suggestion " + suggestion.getSuggestions());
|
||||||
return suggestion.getSuggestions();
|
return suggestion.getSuggestions();
|
||||||
}
|
}
|
||||||
if (suggestable.forHangingValue()) {
|
if (suggestable.forHangingValue()) {
|
||||||
String name = getDescription().getParameters().get(consumerIndex).getName();
|
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);
|
throw new InvalidUsageException("For parameter '" + name + "': " + e.getMessage(), this);
|
||||||
} else {
|
} else {
|
||||||
|
// System.out.println("(7) HGet binding suggestions " + parameter + " | " + lastConsumed);
|
||||||
return parameter.getBinding().getSuggestions(parameter, "");
|
return parameter.getBinding().getSuggestions(parameter, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -281,13 +288,16 @@ public abstract class AParametricCallable implements CommandCallable {
|
|||||||
if (suggestable.forHangingValue()) {
|
if (suggestable.forHangingValue()) {
|
||||||
// There's nothing that we can suggest because there's no more parameters
|
// There's nothing that we can suggest because there's no more parameters
|
||||||
// to add on, and we can't change the previous parameter
|
// to add on, and we can't change the previous parameter
|
||||||
|
// System.out.println("(7.1) No more parameters");
|
||||||
return new ArrayList<String>();
|
return new ArrayList<String>();
|
||||||
} else {
|
} else {
|
||||||
// For /command value1 value2|
|
// For /command value1 value2|
|
||||||
if (lastConsumer != null) {
|
if (lastConsumer != null) {
|
||||||
|
// System.out.println("(8) Get binding suggestions " + lastConsumer + " | " + lastConsumed);
|
||||||
return lastConsumer.getBinding().getSuggestions(lastConsumer, lastConsumed);
|
return lastConsumer.getBinding().getSuggestions(lastConsumer, lastConsumed);
|
||||||
// This should never occur
|
// This should never occur
|
||||||
} else {
|
} else {
|
||||||
|
// System.out.println("(9) Invalid suggestion context");
|
||||||
throw new RuntimeException("Invalid suggestion context");
|
throw new RuntimeException("Invalid suggestion context");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,13 +19,16 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.util.command.parametric;
|
package com.sk89q.worldedit.util.command.parametric;
|
||||||
|
|
||||||
|
import com.boydti.fawe.util.StringMan;
|
||||||
import com.sk89q.minecraft.util.commands.CommandException;
|
import com.sk89q.minecraft.util.commands.CommandException;
|
||||||
|
import com.sk89q.worldedit.util.command.binding.Range;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -184,6 +187,25 @@ public class BindingHelper implements Binding {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getSuggestions(ParameterData parameter, String prefix) {
|
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<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ import com.sk89q.worldedit.util.command.binding.Text;
|
|||||||
|
|
||||||
import javax.xml.ws.Provider;
|
import javax.xml.ws.Provider;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
@ -119,6 +120,13 @@ public class ParameterData extends SimpleParameter {
|
|||||||
return modifiers;
|
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.
|
* Set the list of modifiers.
|
||||||
*
|
*
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren