Snowiiii / Pumpkin

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

Commands: Fix Bug, Refactor Arguments, Add /tp #227

Closed user622628252416 closed 2 weeks ago

user622628252416 commented 2 weeks ago

Description

Testing

ran commands and evaluated their effects a lot (especially affected commands: help/tp/worldborder)

Checklist

Snowiiii commented 2 weeks ago

I would prefer to have all arguments in a folder like the commands, makes it much cleaner

user622628252416 commented 2 weeks ago

I would prefer to have all arguments in a folder like the commands, makes it much cleaner

I've already been working on that actually, but before I can commit that I need another issue to be resolved: IMO ArgumentConsumer's consume function should just return an Option instead of a Result<String, Option>. As discussed in the comment in CommandDispatcher, we can really use these optional error strings anyways, at least not without a lot of complexity that will slow us down.

See dispatcher.rs

is_fitting_path being Err only means that THIS path does not fit Do not break/return here or else other paths aren't even tried! I don't really know what to do with this _error string, because there will be one error for every path that was tried. Since there are sometimes many possible paths, aggregating these errors and showing them all to the user probably does not make sense. We can't really know which path the user intended, and just show the error for that one path, either. (we could guess but that'd be hard). IMO is_fitting_path should therefore just be a bool.

Removing this Error in favor of just using an option makes the Argument Consumers much much cleaner too.

Additionally, the aforementioned CommandArgument would be an enum that has a variant for each arguments type: This way we can simply store parsed data in the HashMap, instead of converting consumed data back to a String and having a second parse step.

Snowiiii commented 2 weeks ago

I would prefer to have all arguments in a folder like the commands, makes it much cleaner

I've already been working on that actually, but before I can commit that I need another issue to be resolved: IMO ArgumentConsumer's consume function should just return an Option instead of a Result<String, Option>. As discussed in the comment in CommandDispatcher, we can really use these optional error strings anyways, at least not without a lot of complexity that will slow us down.

See dispatcher.rs

is_fitting_path being Err only means that THIS path does not fit Do not break/return here or else other paths aren't even tried! I don't really know what to do with this _error string, because there will be one error for every path that was tried. Since there are sometimes many possible paths, aggregating these errors and showing them all to the user probably does not make sense. We can't really know which path the user intended, and just show the error for that one path, either. (we could guess but that'd be hard). IMO is_fitting_path should therefore just be a bool.

Removing this Error in favor of just using an option makes the Argument Consumers much much cleaner too.

Additionally, the aforementioned CommandArgument would be an enum that has a variant for each arguments type: This way we can simply store parsed data in the HashMap, instead of converting consumed data back to a String and having a second parse step.

Sure, We can use an Option. But i would like to have proper "Error Handling" in some way. I don't want to just give the player back "Wrong Argument", This is confusing.

user622628252416 commented 2 weeks ago

We could go through all possible paths, and find the path that we can traverse the furthest before consuption of an argument fails. I believe that's what Minecraft does. Then we could print the syntax of that path up to that point. This will have to wait tho, as it depends on being able to print possible continuations from any node in a path. This might also be related to command suggestions

Snowiiii commented 2 weeks ago

We could go through all possible paths, and find the path that we can traverse the furthest before consuption of an argument fails. I believe that's what Minecraft does. Then we could print the syntax of that path up to that point. This will have to wait tho, as it depends on being able to print possible continuations from any node in a path. This might also be related to command suggestions

I belive this is what we did before i made custom error reporting. Im not totally against this. But for "not experienced players". An proper error message like "Player not Found". Is more clear than " wrong Argument" or something like that

user622628252416 commented 2 weeks ago

But for "not experienced players". An proper error message like "Player not Found". Is more clear than " wrong Argument" or something like that

I honestly think when #94 is implemented this is not really a problem, or at least relatively low priority. If you think this is important you could open a seperate issue for that

Snowiiii commented 2 weeks ago

btw you have a typo you wrote arg_postition_2d.rs

Snowiiii commented 2 weeks ago

Is this ready for merge ?

user622628252416 commented 2 weeks ago

I just did some last testing, I think it's ready 👍

Snowiiii commented 2 weeks ago

Big Thanks @user622628252416. Really appreciate your work :D