Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue parsing BlockPositionArgument + RawStringArgument #13

Open
inxomnyaa opened this issue Jun 5, 2019 · 6 comments
Open

Issue parsing BlockPositionArgument + RawStringArgument #13

inxomnyaa opened this issue Jun 5, 2019 · 6 comments

Comments

@inxomnyaa
Copy link
Collaborator

inxomnyaa commented Jun 5, 2019

My command:

    /**
     * This is where all the arguments, permissions, sub-commands, etc would be registered
     * @throws \CortexPE\Commando\exception\ArgumentOrderException
     */
    protected function prepare(): void
    {
        $this->registerArgument(0, new BlockPositionArgument("position", false));
        $this->registerArgument(1, new RawStringArgument("block", false));
    }

    /**
     * @param CommandSender $sender
     * @param string $aliasUsed
     * @param BaseArgument[] $args
     */
    public function onRun(CommandSender $sender, string $aliasUsed, array $args): void
    {
        if (isset($args["position"]) && isset($args["block"])) {
            /**
             * @var Vector3 $position
             * @var string $block
             */
            $position = $args["position"];
            $block = $args["block"];
            $sender->sendMessage(strval(extract($args)));
            $sender->sendMessage(strval($position) . strval($block));
        } else {
            $this->sendUsage();
        }
    }

With some tests, i got these results:

block
[12:17:44] [Server thread/INFO]: Usage: /block <position:x y z> <block:string>
block 1
[12:17:45] [Server thread/INFO]: Invalid value '1' for argument #1
block 1 1
[12:17:46] [Server thread/INFO]: Invalid value '1' for argument #1
block 1 1 1
[12:17:49] [Server thread/INFO]: 2
[12:17:49] [Server thread/INFO]: Vector3(x=1,y=1,z=1)
block 1 1 1 tnt
[12:18:03] [Server thread/INFO]: 2
[12:18:03] [Server thread/INFO]: Vector3(x=1,y=1,z=1)tnt

IMO block 1 1 should say

Invalid value '1 1' for argument #1

block 1 1 1 Should still fail, since $block is not optional. isset returns true though.
block 1 1 1 tnt is the only correct syntax and correctly parsed

@CortexPE
Copy link
Owner

CortexPE commented Jun 5, 2019 via email

@CortexPE CortexPE closed this as completed Jun 5, 2019
@inxomnyaa
Copy link
Collaborator Author

But that was not the question/issue at all.

@inxomnyaa
Copy link
Collaborator Author

I realized that !empty($args["block"]) is more reliable in RawStringArgument, as for some reason it allows empty strings

@CortexPE
Copy link
Owner

CortexPE commented Jun 6, 2019 via email

@CortexPE
Copy link
Owner

CortexPE commented Jun 6, 2019 via email

@CortexPE CortexPE reopened this Jun 6, 2019
@lukeeey
Copy link

lukeeey commented Jun 6, 2019

@CortexPE TextArgument also accepts no input which isnt really ideal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants