Class CommandPolicy
java.lang.Object
eu.mrapik.minecraftservermcp.config.CommandPolicy
Restricts console commands using
ToolAccessConfig.commandWhitelist() and ToolAccessConfig.commandBlacklist().
Only the first token of the command line (the root command name) is checked, without a leading slash, lowercased.
Example: say hello → say; /stop → stop. If a whitelist is present and non-empty,
the root must appear in it. If a blacklist is present and non-empty, the root must not appear in it.
-
Constructor Summary
ConstructorsConstructorDescriptionCommandPolicy(@Nullable List<String> commandWhitelist, @Nullable List<String> commandBlacklist) Creates a policy; list entries are trimmed and lowercased for matching. -
Method Summary
Modifier and TypeMethodDescriptionbooleanallowsCommand(String commandLine) Whether the command line is allowed given whitelist/blacklist rules on the root command name.static StringcommandRoot(String commandLine) First word of the command, lowercased, without a leading/.static CommandPolicyBuilds a policy from command whitelist/blacklist fields incfg.
-
Constructor Details
-
CommandPolicy
public CommandPolicy(@Nullable @Nullable List<String> commandWhitelist, @Nullable @Nullable List<String> commandBlacklist) Creates a policy; list entries are trimmed and lowercased for matching.- Parameters:
commandWhitelist- if non-null, only these root commands (lowercase) are allowed when non-emptycommandBlacklist- if non-null and non-empty, these root commands are denied
-
-
Method Details
-
fromToolConfig
Builds a policy from command whitelist/blacklist fields incfg.- Parameters:
cfg- tool access section (typicallyserver_command)- Returns:
- policy for evaluating console command lines
-
allowsCommand
Whether the command line is allowed given whitelist/blacklist rules on the root command name.- Parameters:
commandLine- full line as sent to the server (may include leading slash)- Returns:
- true if allowed
-
commandRoot
First word of the command, lowercased, without a leading/.- Parameters:
commandLine- raw command line- Returns:
- root command token used for list matching
-