Moonflower-Mods / allium

Lua script loader and API for easy Minecraft modding
MIT License
44 stars 9 forks source link

allium.command function #8

Closed hugeblank closed 2 years ago

hugeblank commented 2 years ago

Registers a command using a similar format to allium.onEvent:

allium.command("help", function(player, arg1, arg2, ...)
  chat.say(player, "no.") -- assuming chat API looks like this
end
)

Would register a command that could get called as /test:help please?. player would be the player that executed the command, or nil if it was run by a server. arg1 would be "please?", and arg2 (and the rest of the arguments) would be nil.

Patbox commented 2 years ago

Commands could benefit from being a builder rather single function + arg. Would allow for higher flexibility and easier way of using all functionality of brigardier (sugestions, arg types, etc). Also not sure prefixing with plugin id, it can rather limit what can you do

hugeblank commented 2 years ago

We could use the plugin id as the command name in game, and then have the first command argument be the specific command? so in the example above it would instead be /test help please?

We'd have to get creative with plugin names that match existing command names, though.

Patbox commented 2 years ago

I think just overriding commands will be fine. We could also try adding it without namespace if it doesn't exist or with one otherwise (with way to force override it ofc)

Ocawesome101 commented 2 years ago

I agree that the builder idea fits this better. The way you initially described doesn't have a good way to do argument type checking during command autocompletion.

hugeblank commented 2 years ago

Command api fully implemented as of ed0696096cfc6d59d3ae3921a7f780dda9a2bd60. Register a command using command.register, and use the argument types provided by the game by indexing command.arguments.<argument-id>. argument-id is one of the ids in ArgumentTypes, or one of the brigadier argument types, with brigadier: cut off. An example of how it works can be found in the hangman example script as of f71db1c62af8cb89077a581942e9b79da6582cae.