enabled some client side command interpretation.

This commit is contained in:
gnembon committed 2020-03-30 17:14:16 -03:00
1 parent f3093183ce
commit fe63334509
8 files changed
+74 -7

No files matched your search

+14 -5
View File
@@ -20,6 +20,7 @@ public final class ParsedRule<T> implements Comparable<ParsedRule> {
public final ImmutableList<String> categories;
public final ImmutableList<String> options;
public boolean isStrict;
public boolean isClient;
public final Class<T> type;
public final List<Validator<T>> validators;
public final T defaultValue;
@@ -46,6 +47,11 @@ public final class ParsedRule<T> implements Comparable<ParsedRule> {
this.validators.add((Validator<T>) callConstructor(Validator._COMMAND_LEVEL_VALIDATOR.class));
}
}
this.isClient = categories.contains(RuleCategory.CLIENT);
if (this.isClient)
{
this.validators.add(callConstructor(Validator._CLIENT.class));
}
this.defaultValue = get();
this.defaultAsString = convertToString(this.defaultValue);
if (rule.options().length > 0)
@@ -132,16 +138,19 @@ public final class ParsedRule<T> implements Comparable<ParsedRule> {
value = validator.validate(source, this, value, stringValue);
if (value == null)
{
Messenger.m(source, "r Wrong value for " + name + ": " + stringValue);
if (validator.description()!= null)
Messenger.m(source, "r " + validator.description());
if (source != null)
{
Messenger.m(source, "r Wrong value for " + name + ": " + stringValue);
if (validator.description() != null)
Messenger.m(source, "r " + validator.description());
}
return null;
}
}
if (!value.equals(get()))
if (!value.equals(get()) || source == null)
{
this.field.set(null, value);
CarpetServer.settingsManager.notifyRuleChanged(source, this, stringValue);
if (source != null) CarpetServer.settingsManager.notifyRuleChanged(source, this, stringValue);
}
}
catch (IllegalAccessException e)
@@ -12,5 +12,6 @@ public class RuleCategory
public static final String TNT = "tnt";
public static final String DISPENSER = "dispenser";
public static final String SCARPET = "scarpet";
public static final String CLIENT = "client";
}
@@ -558,4 +558,22 @@ public class SettingsManager
return 1;
}
public void inspectClientsideCommand(String string)
{
if (string.startsWith("/carpet "))
{
String[] res = string.split("\\s+", 3);
if (res.length == 3)
{
String setting = res[1];
String strOption = res[2];
if (rules.containsKey(setting) && rules.get(setting).isClient)
{
rules.get(setting).set(null, strOption);
}
}
}
}
}
@@ -41,6 +41,19 @@ public abstract class Validator<T>
public String description() { return "It has an accompanying command";}
}
public static class _CLIENT<T> extends Validator<T>
{
@Override
public T validate(ServerCommandSource source, ParsedRule<T> currentRule, T newValue, String string)
{
return newValue;
}
@Override
public String description() { return "Its a client command so can be issued when connecting to non-carpet servers. " +
"In client-server setting it will only affect the executing player, so each player needs to type it" +
" separately for the desired effect";}
}
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) {