ops options for commands
This commit is contained in:
1 parent
c2f22a141a
commit
b52b5c335f
16 files changed
+133
-51
No files matched your search
@@ -25,6 +25,7 @@ import static carpet.settings.RuleCategory.FEATURE;
|
||||
import static carpet.settings.RuleCategory.OPTIMIZATION;
|
||||
import static carpet.settings.RuleCategory.SURVIVAL;
|
||||
import static carpet.settings.RuleCategory.TNT;
|
||||
import static carpet.settings.RuleCategory.DISPENSER;
|
||||
|
||||
public class CarpetSettings
|
||||
{
|
||||
@@ -108,7 +109,7 @@ public class CarpetSettings
|
||||
}
|
||||
}
|
||||
|
||||
@Rule( desc = "Sets the tnt random explosion range to a fixed value", category = TNT, options = "-1",
|
||||
@Rule( desc = "Sets the tnt random explosion range to a fixed value", category = TNT, options = "-1", strict = false,
|
||||
validate = {CheckOptimizedTntEnabledValidator.class, TNTRandomRangeValidator.class}, extra = "Set to -1 for default behavior")
|
||||
public static double tntRandomRange = -1;
|
||||
|
||||
@@ -124,7 +125,7 @@ public class CarpetSettings
|
||||
}
|
||||
}
|
||||
|
||||
@Rule( desc = "Sets the horizontal random angle on TNT for debugging of TNT contraptions", category = TNT, options = "-1",
|
||||
@Rule( desc = "Sets the horizontal random angle on TNT for debugging of TNT contraptions", category = TNT, options = "-1", strict = false,
|
||||
validate = TNTAngleValidator.class, extra = "Set to -1 for default behavior")
|
||||
public static double hardcodeTNTangle;
|
||||
|
||||
@@ -218,23 +219,20 @@ public class CarpetSettings
|
||||
public static boolean summonNaturalLightning = false;
|
||||
|
||||
@Rule(desc = "Enables /spawn command for spawn tracking", category = COMMAND)
|
||||
public static boolean commandSpawn = true;
|
||||
public static String commandSpawn = "true";
|
||||
|
||||
@Rule(desc = "Enables /tick command to control game clocks", category = COMMAND)
|
||||
public static boolean commandTick = true;
|
||||
public static String commandTick = "true";
|
||||
|
||||
@Rule(
|
||||
desc = "Enables /log command to monitor events in the game via chat and overlays",
|
||||
category = COMMAND//,
|
||||
//validate = Validator.WIP.class
|
||||
)
|
||||
public static boolean commandLog = true;
|
||||
@Rule(desc = "Enables /log command to monitor events via chat and overlays", category = COMMAND)
|
||||
public static String commandLog = "true";
|
||||
|
||||
@Rule(
|
||||
desc = "sets these loggers in their default configurations for all new players",
|
||||
extra = "use csv, like 'tps,mobcaps' for multiple loggers, none for nothing",
|
||||
category = {CREATIVE, SURVIVAL},
|
||||
options = {"none", "tps", "mobcaps,tps"}
|
||||
options = {"none", "tps", "mobcaps,tps"},
|
||||
strict = false
|
||||
)
|
||||
public static String defaultLoggers = "none";
|
||||
|
||||
@@ -243,7 +241,7 @@ public class CarpetSettings
|
||||
extra = "Also enables brown carpet placement action if 'carpets' rule is turned on as well",
|
||||
category = COMMAND
|
||||
)
|
||||
public static boolean commandDistance = true;
|
||||
public static String commandDistance = "true";
|
||||
|
||||
@Rule(
|
||||
desc = "Enables /info command for blocks",
|
||||
@@ -253,24 +251,24 @@ public class CarpetSettings
|
||||
},
|
||||
category = COMMAND
|
||||
)
|
||||
public static boolean commandInfo = true;
|
||||
public static String commandInfo = "true";
|
||||
|
||||
@Rule(
|
||||
desc = "Enables /c and /s commands to quickly switch between camera and survival modes",
|
||||
extra = "/c and /s commands are available to all players regardless of their permission levels",
|
||||
category = COMMAND
|
||||
)
|
||||
public static boolean commandCameramode = true;
|
||||
public static String commandCameramode = "true";
|
||||
|
||||
@Rule(
|
||||
desc = "Enables /perimeterinfo command",
|
||||
extra = "... that scans the area around the block for potential spawnable spots",
|
||||
category = COMMAND
|
||||
)
|
||||
public static boolean commandPerimeterInfo = true;
|
||||
public static String commandPerimeterInfo = "true";
|
||||
|
||||
@Rule(desc = "Enables /draw commands", extra = "... allows for drawing simple shapes", category = COMMAND)
|
||||
public static boolean commandDraw = true;
|
||||
public static String commandDraw = "true";
|
||||
|
||||
@Rule(desc = "Enables /script command", extra = "An in-game scripting API for Scarpet programming language", category = COMMAND)
|
||||
public static boolean commandScript = true;
|
||||
@@ -283,10 +281,10 @@ public class CarpetSettings
|
||||
public static boolean scriptsAutoload = false;
|
||||
|
||||
@Rule(desc = "Enables /player command to control/spawn players", category = COMMAND)
|
||||
public static boolean commandPlayer = true;
|
||||
public static String commandPlayer = "true";
|
||||
|
||||
@Rule(desc = "Allows to track mobs AI via /track command", category = COMMAND)
|
||||
public static boolean commandTrackAI = true;
|
||||
public static String commandTrackAI = "true";
|
||||
|
||||
@Rule(desc = "Placing carpets may issue carpet commands for non-op players", category = SURVIVAL)
|
||||
public static boolean carpets = false;
|
||||
@@ -308,7 +306,7 @@ public class CarpetSettings
|
||||
extra="Increases player allowed mining distance to 32 blocks",
|
||||
category = SURVIVAL
|
||||
)
|
||||
public static boolean miningGhostBlockFix;
|
||||
public static boolean miningGhostBlockFix = false;
|
||||
|
||||
private static class PushLimitLimits extends Validator<Integer> {
|
||||
@Override public Integer validate(ServerCommandSource source, ParsedRule<Integer> currentRule, Integer newValue, String string) {
|
||||
@@ -321,6 +319,7 @@ public class CarpetSettings
|
||||
desc = "Customizable piston push limit",
|
||||
options = {"10", "12", "14", "100"},
|
||||
category = CREATIVE,
|
||||
strict = false,
|
||||
validate = PushLimitLimits.class
|
||||
)
|
||||
public static int pushLimit = 12;
|
||||
@@ -329,6 +328,7 @@ public class CarpetSettings
|
||||
desc = "Customizable powered rail power range",
|
||||
options = {"9", "15", "30"},
|
||||
category = CREATIVE,
|
||||
strict = false,
|
||||
validate = PushLimitLimits.class
|
||||
)
|
||||
public static int railPowerLimit = 9;
|
||||
@@ -344,6 +344,7 @@ public class CarpetSettings
|
||||
desc = "Customizable fill/clone volume limit",
|
||||
options = {"32768", "250000", "1000000"},
|
||||
category = CREATIVE,
|
||||
strict = false,
|
||||
validate = FillLimitLimits.class
|
||||
)
|
||||
public static int fillLimit = 32768;
|
||||
@@ -352,17 +353,12 @@ public class CarpetSettings
|
||||
desc = "Customizable maximal entity collision limits, 0 for no limits",
|
||||
options = {"0", "1", "20"},
|
||||
category = OPTIMIZATION,
|
||||
strict = false,
|
||||
validate = Validator.NONNEGATIVE_NUMBER.class
|
||||
)
|
||||
public static int maxEntityCollisions = 0;
|
||||
|
||||
/*
|
||||
@Rule(
|
||||
desc = "Fix for piston ghost blocks",
|
||||
category = BUGFIX,
|
||||
validate = Validator.WIP.class
|
||||
)
|
||||
public static boolean pistonGhostBlocksFix = true;
|
||||
|
||||
@Rule(
|
||||
desc = "fixes water performance issues",
|
||||
@@ -379,11 +375,16 @@ public class CarpetSettings
|
||||
desc = "Sets a different motd message on client trying to connect to the server",
|
||||
extra = "use '_' to use the startup setting from server.properties",
|
||||
options = "_",
|
||||
strict = false,
|
||||
category = CREATIVE
|
||||
)
|
||||
public static String customMOTD = "_";
|
||||
|
||||
@Rule(desc = "Cactus in dispensers rotates blocks.", extra = "Rotates block anti-clockwise if possible", category = FEATURE)
|
||||
@Rule(
|
||||
desc = "Cactus in dispensers rotates blocks.",
|
||||
extra = "Rotates block anti-clockwise if possible",
|
||||
category = {FEATURE, DISPENSER}
|
||||
)
|
||||
public static boolean rotatorBlock = false;
|
||||
|
||||
private static class ViewDistanceValidator extends Validator<Integer>
|
||||
@@ -422,6 +423,7 @@ public class CarpetSettings
|
||||
extra = "Set to 0 to not override the value in server settings.",
|
||||
options = {"0", "12", "16", "32"},
|
||||
category = CREATIVE,
|
||||
strict = false,
|
||||
validate = ViewDistanceValidator.class
|
||||
)
|
||||
public static int viewDistance = 0;
|
||||
@@ -470,6 +472,7 @@ public class CarpetSettings
|
||||
desc = "limits growth limit of newly naturally generated kelp to this amount of blocks",
|
||||
options = {"0", "2", "25"},
|
||||
category = FEATURE,
|
||||
strict = false,
|
||||
validate = KelpLimit.class
|
||||
)
|
||||
public static int kelpGenerationGrowthLimit = 25;
|
||||
|
||||
@@ -3,6 +3,7 @@ package carpet.settings;
|
||||
import carpet.CarpetServer;
|
||||
import carpet.utils.Messenger;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Sets;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
@@ -38,25 +39,43 @@ public final class ParsedRule<T> implements Comparable<ParsedRule> {
|
||||
for (Class v : rule.validate())
|
||||
this.validators.add((Validator<T>) callConstructor(v));
|
||||
if (categories.contains(RuleCategory.COMMAND))
|
||||
{
|
||||
this.validators.add(callConstructor(Validator._COMMAND.class));
|
||||
if (this.type == String.class)
|
||||
{
|
||||
this.isStrict = false;
|
||||
this.validators.add((Validator<T>) callConstructor(Validator._COMMAND_LEVEL_VALIDATOR.class));
|
||||
}
|
||||
}
|
||||
this.defaultValue = get();
|
||||
this.defaultAsString = convertToString(this.defaultValue);
|
||||
if (this.type == boolean.class)
|
||||
if (rule.options().length > 0)
|
||||
{
|
||||
this.options = ImmutableList.copyOf(rule.options());
|
||||
}
|
||||
else if (this.type == boolean.class || (this.type == String.class && categories.contains(RuleCategory.COMMAND)))
|
||||
{
|
||||
this.isStrict = true; // it has no sense otherwise
|
||||
this.options = ImmutableList.of("true", "false");
|
||||
}
|
||||
else if (this.type.isEnum())
|
||||
{
|
||||
this.isStrict = true; // it has no sense otherwise
|
||||
this.options = Arrays.stream(this.type.getEnumConstants()).map(e -> ((Enum) e).name().toLowerCase(Locale.ROOT)).collect(ImmutableList.toImmutableList());
|
||||
}
|
||||
else
|
||||
{
|
||||
this.options = ImmutableList.copyOf(rule.options());
|
||||
this.options = ImmutableList.of();
|
||||
}
|
||||
if (isStrict && !this.options.isEmpty())
|
||||
{
|
||||
if (this.type == boolean.class || this.type == int.class || this.type == double.class || this.type == float.class)
|
||||
{
|
||||
this.validators.add(callConstructor(Validator._STRICT_IGNORECASE.class));
|
||||
}
|
||||
else
|
||||
{
|
||||
this.validators.add(callConstructor(Validator._STRICT.class));
|
||||
}
|
||||
}
|
||||
if (isStrict)
|
||||
this.validators.add(callConstructor(Validator._STRICT.class));
|
||||
}
|
||||
|
||||
private <T> T callConstructor(Class<T> cls)
|
||||
@@ -115,7 +134,8 @@ public final class ParsedRule<T> implements Comparable<ParsedRule> {
|
||||
if (value == null)
|
||||
{
|
||||
Messenger.m(source, "r Wrong value for " + name + ": " + stringValue);
|
||||
Messenger.m(source, "r " + validator.description());
|
||||
if (validator.description()!= null)
|
||||
Messenger.m(source, "r " + validator.description());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public @interface Rule
|
||||
* any of the options
|
||||
* For enums, its always strict, same for booleans - no need to set that for them.
|
||||
*/
|
||||
boolean strict() default false;
|
||||
boolean strict() default true;
|
||||
|
||||
/**
|
||||
* The class of the validator checked when the rule is changed.
|
||||
|
||||
@@ -185,6 +185,23 @@ public class SettingsManager
|
||||
}));
|
||||
}
|
||||
|
||||
public static boolean canUseCommand(ServerCommandSource source, String commandLevel)
|
||||
{
|
||||
switch (commandLevel)
|
||||
{
|
||||
case "true": return true;
|
||||
case "false": return false;
|
||||
case "ops": return source.hasPermissionLevel(2); // typical for other cheaty commands
|
||||
case "0":
|
||||
case "1":
|
||||
case "2":
|
||||
case "3":
|
||||
case "4":
|
||||
return source.hasPermissionLevel(Integer.parseInt(commandLevel));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void loadConfigurationFromConf()
|
||||
{
|
||||
for (ParsedRule<?> rule : rules.values()) rule.resetToDefault(server.getCommandSource());
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user