command-framework
command-framework copied to clipboard
Add command patterns
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>