Snowiiii / Pumpkin

Empowering everyone to host fast and efficient Minecraft servers.
https://snowiiii.github.io/Pumpkin/
MIT License
3.35k stars 123 forks source link

Good Command system design #147

Open Snowiiii opened 1 month ago

Snowiiii commented 1 month ago

I'm thinking of improving the current design of our Command System which looks like this image

One Problem for example is to no able to use Async Closures (yet).

Please let me know how do you think a Command System should look like?

van-sprundel commented 1 month ago

Would attribute macro's be something you'd be okay with? that's kind of the thing I would go for.

Something like

#[command(
    names = ["kick"],
    description = "Kicks the player from the server."
)]
struct KickCommand {
    target: PlayerName,
    reason: String,
}

impl CommandHandler for KickCommand {
    pub fn init_command_tree<'a>(...) -> CommandTree<'a> {
        ...
    }
}
AnonymousBit0111 commented 1 month ago

What exactly is the use of the Command tree struct? I think we could just have the command handler execute the command and be done with it no?

Snowiiii commented 1 month ago

What exactly is the use of the Command tree struct? I think we could just have the command handler execute the command and be done with it no?

Its pretty useful for tab completion and also a quick and easy way to check permission etc. Look at Mojang's Brigadier API

AnonymousBit0111 commented 1 month ago

Yeah I see it now, I think if we use macros we'll need to have a way to handle arguments that require more arguments aswell, it needs to be evaluated in a chain before we execute anything

AnonymousBit0111 commented 1 month ago

Maybe we could have a CommandArg struct which has the argument and a bool dictating whether more arguments are required, then in the command tree we could pass in a custom struct for each command , which comes from the deserialised JSON of all the arguments

suprohub commented 1 month ago

Macro rules good too like

command!{
names = ["kick"]
desc = "Kicks player"
{when goes comand tree
}
}