ops options for commands

This commit is contained in:
gnembon committed 2019-12-01 01:04:58 -04:00
1 parent c2f22a141a
commit b52b5c335f
16 files changed
+133 -51

No files matched your search

+33 -1
View File
@@ -2,9 +2,11 @@ package carpet.settings;
import carpet.CarpetServer;
import carpet.utils.Messenger;
import com.google.common.collect.ImmutableList;
import net.minecraft.server.command.ServerCommandSource;
import java.util.Locale;
import java.util.stream.Collectors;
public abstract class Validator<T>
{
@@ -39,6 +41,21 @@ public abstract class Validator<T>
public String description() { return "It has an accompanying command";}
}
public static class _COMMAND_LEVEL_VALIDATOR extends Validator<String> {
private static ImmutableList<String> OPTIONS = ImmutableList.of("true", "false", "ops", "0", "1", "2", "3", "4");
@Override public String validate(ServerCommandSource source, ParsedRule<String> currentRule, String newValue, String userString) {
if (!OPTIONS.contains(userString.toLowerCase(Locale.ROOT)))
{
Messenger.m(source, "r Valid options for command type rules is 'true' or 'false'");
Messenger.m(source, "r Optionally you can choose 'ops' to only allow operators");
Messenger.m(source, "r or provide a custom required permission level");
return null;
}
return userString.toLowerCase(Locale.ROOT);
}
public String description() { return "Can be limited to 'ops' only, or a custom permission level";}
}
public static class WIP<T> extends Validator<T>
{
@Override
@@ -55,7 +72,7 @@ public abstract class Validator<T>
@Override
public T validate(ServerCommandSource source, ParsedRule<T> currentRule, T newValue, String string)
{
if (!currentRule.options.contains(string.toLowerCase(Locale.ROOT)))
if (!currentRule.options.contains(string))
{
Messenger.m(source, "r Valid options: " + currentRule.options.toString());
return null;
@@ -64,6 +81,21 @@ public abstract class Validator<T>
}
}
public static class _STRICT_IGNORECASE<T> extends Validator<T>
{
@Override
public T validate(ServerCommandSource source, ParsedRule<T> currentRule, T newValue, String string)
{
if (!currentRule.options.stream().map(s->s.toLowerCase(Locale.ROOT)).collect(Collectors.toSet())
.contains(string.toLowerCase(Locale.ROOT)))
{
Messenger.m(source, "r Valid options (case insensitive): " + currentRule.options.toString());
return null;
}
return newValue;
}
}
public static class NONNEGATIVE_NUMBER <T extends Number> extends Validator<T>
{
@Override