mirror of
https://github.com/TotalFreedomMC/TF-PlotSquared.git
synced 2024-12-23 00:15:06 +00:00
Add suggestion for flags when invalid flag name was given :]
This commit is contained in:
parent
5b103d49c0
commit
472aadcd01
4 changed files with 28 additions and 2 deletions
|
@ -12,6 +12,7 @@ import com.intellectualcrafters.plot.object.Plot;
|
|||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.Permissions;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
import com.intellectualcrafters.plot.util.StringMan;
|
||||
import com.plotsquared.general.commands.CommandDeclaration;
|
||||
|
||||
|
@ -63,7 +64,18 @@ public class FlagCmd extends SubCommand {
|
|||
if (args.length > 1) {
|
||||
flag = FlagManager.getFlag(args[1]);
|
||||
if (flag == null || flag.isReserved()) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
boolean suggested = false;
|
||||
try {
|
||||
StringComparison<Flag<?>> stringComparison = new StringComparison<>(args[1], Flags.getFlags());
|
||||
String best = stringComparison.getBestMatch();
|
||||
if (best != null) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG_SUGGESTED, best);
|
||||
suggested = true;
|
||||
}
|
||||
} catch (final Exception ignored) { /* Happens sometimes because of mean code */ }
|
||||
if (!suggested) {
|
||||
MainUtil.sendMessage(player, C.NOT_VALID_FLAG);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -553,6 +553,7 @@ public enum C {
|
|||
FLAG_TYPE("$2Type: %s", "Flag"),
|
||||
FLAG_DESC("$2Desc: %s", "Flag"),
|
||||
NOT_VALID_FLAG("$2That is not a valid flag", "Flag"),
|
||||
NOT_VALID_FLAG_SUGGESTED("$2That is not a valid flag. Did you mean: $1%s", "Flag"),
|
||||
NOT_VALID_VALUE("$2Flag values must be alphanumerical", "Flag"),
|
||||
FLAG_NOT_IN_PLOT("$2The plot does not have that flag", "Flag"),
|
||||
FLAG_NOT_REMOVED("$2The flag could not be removed", "Flag"),
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package com.intellectualcrafters.plot.flag;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.util.StringComparison;
|
||||
|
||||
public abstract class Flag<V> {
|
||||
public abstract class Flag<V> implements StringComparison.StringComparable {
|
||||
|
||||
private final String name;
|
||||
private boolean reserved = false;
|
||||
|
@ -53,4 +54,9 @@ public abstract class Flag<V> {
|
|||
public boolean isSet(Plot plot) {
|
||||
return FlagManager.getPlotFlagRaw(plot, this) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getComparableString() {
|
||||
return getName();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -99,6 +99,9 @@ public class StringComparison<T> {
|
|||
}
|
||||
|
||||
public String getString(T o) {
|
||||
if (o instanceof StringComparable) {
|
||||
return ((StringComparable) o).getComparableString();
|
||||
}
|
||||
return o.toString();
|
||||
}
|
||||
|
||||
|
@ -147,4 +150,8 @@ public class StringComparison<T> {
|
|||
this.best = best;
|
||||
}
|
||||
}
|
||||
|
||||
public interface StringComparable {
|
||||
String getComparableString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue