Class CommandPolicy

java.lang.Object
eu.mrapik.minecraftservermcp.config.CommandPolicy

public final class CommandPolicy extends Object
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 hellosay; /stopstop. 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 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-empty
      commandBlacklist - if non-null and non-empty, these root commands are denied
  • Method Details

    • fromToolConfig

      public static CommandPolicy fromToolConfig(ToolAccessConfig cfg)
      Builds a policy from command whitelist/blacklist fields in cfg.
      Parameters:
      cfg - tool access section (typically server_command)
      Returns:
      policy for evaluating console command lines
    • allowsCommand

      public boolean allowsCommand(String commandLine)
      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

      public static String commandRoot(String commandLine)
      First word of the command, lowercased, without a leading /.
      Parameters:
      commandLine - raw command line
      Returns:
      root command token used for list matching