command-framework icon indicating copy to clipboard operation
command-framework copied to clipboard

Add command patterns

Open aripiprazole opened this issue 4 years ago • 0 comments

Command patterns

Make easier to treat command arguments, like in functional languages(elixir, haskell, idris):


command :: String -> Int -> IO ()
command "some string" 0 = putStrLn "first match!"
command "some string" i = putStrLn $ "second match! " ++ show i
command s i = putStrLn $ "third match! " ++ s ++ " " ++ show i

You will be able to make:


@Command(
  name = "command", 
  aliases = {"nice"}, 
  target = CommandTarget.CONSOLE, 
  pattern = "msg <target> <message>"
)
public void handleCommand(
    Context<ConsoleCommandSender> context, 
    Player target, 
    String[] message
) {
    
  target.sendMessage("Console sent you: %s", String.join(" ", message));
}

@Command(
  name = "command", 
  aliases = {"nice"},
  target = CommandTarget.CONSOLE, 
  pattern = "msg <target>"
)
public void handleCommand(
    Context<ConsoleCommandSender> context, 
    Player target 
 ) {
  target.sendMessage("Console sent you:  Message from second function!");
}

And if you execute:

  • command msg <target> - will send to target: Console sent you: Message from second function!
  • command msg <target> <message> - will send to target: Console sent you: <message>

aripiprazole avatar Mar 21 '21 01:03 aripiprazole