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

Bug in subcommands #20

Open
HakanBabus opened this issue Feb 12, 2024 · 7 comments
Open

Bug in subcommands #20

HakanBabus opened this issue Feb 12, 2024 · 7 comments

Comments

@HakanBabus
Copy link

Issue description

  • Expected result: Subcommands appear correctly as in vanilla
  • Actual result: Subcommands in some commands do not appear correctly (see screenshot). It looks like an argument when it should appear as a subcommand.

OS and versions

  • Plugin Version: Lastest (3.1.0)
  • PocketMine-MP: Lastest (5.11.0)
  • PHP: 8.1
  • Game version: Win10

Console error, backtrace or other files

Expected:
image

Actual:
image

@jasonw4331
Copy link
Owner

Is Generate PocketMine Command Autofill set to true in your config?

@HakanBabus
Copy link
Author

HakanBabus commented Feb 12, 2024

Yes, there is also this. I "think" the problem is in generateGenericCommandData
image

@HakanBabus
Copy link
Author

HakanBabus commented Feb 13, 2024

I did some testing and realized that this is where the sub command parts come into play.

public function generateGenericCommandData(string $name, array $aliases, string $description, string $usage, bool $hasPermission = false) : CommandData{
            ...
            ...
            for($argNumber = 0; $argumentCount >= 0 && $argNumber <= $argumentCount; ++$argNumber){
                if($matches[1][$argNumber] === '' || $matches[3][$argNumber] === ''){
                    $paramName = mb_strtolower($matches[2][$argNumber]);
                    $softEnums = $this->getSoftEnums();
                    var_dump($commandString, $paramName);
                    if(isset($softEnums[$paramName])){
                        $enum = $softEnums[$paramName];
                    }else{
                        $this->addSoftEnum($enum = new CommandEnum($paramName, [$paramName], true), false);
                    }
                    $treeOverloads[$argNumber] = CommandParameter::enum($paramName, $enum, CommandParameter::FLAG_FORCE_COLLAPSE_ENUM, false); // collapse and assume required because no $optional identifier exists in usage message
                    continue;
                }

var_dump result:

string(8) "/banlist"
string(10) "ipsplayers"
string(7) "/effect"
string(5) "clear"
string(5) "/time"
string(3) "add"
string(5) "/time"
string(3) "set"
string(5) "/time"
string(3) "set"
string(5) "/time"
string(5) "start"
string(5) "/time"
string(4) "stop"
string(5) "/time"
string(5) "query"
string(8) "/timings"
string(2) "on"
string(8) "/timings"
string(3) "off"
string(8) "/timings"
string(5) "paste"
string(8) "/timings"
string(5) "reset"
string(8) "/timings"
string(6) "report"
string(6) "/title"
string(5) "clear"
string(10) "/whitelist"
string(3) "add"
string(10) "/whitelist"
string(6) "remove"
string(10) "/whitelist"
string(2) "on"
string(10) "/whitelist"
string(3) "off"
string(10) "/whitelist"
string(4) "list"
string(10) "/whitelist"
string(6) "reload"

If you look you can see all the sub commands. i think The bug must be here. I will look into it some more

@jasonw4331
Copy link
Owner

Update your install. I changed some strings for parsing

@HakanBabus
Copy link
Author

Yes, there is also this. I "think" the problem is in generateGenericCommandData image

The issue here has been resolved, but the bug still persists with subcommands appearing as an argument.

image

@HakanBabus
Copy link
Author

After a long time, I think I found the problem. Enums that will be subcommand must be hardcoded enums
I opened a test server and tested.

Code:

public function onDataPacketSendEvent(DataPacketSendEvent $event)
    {
        $packs = $event->getPackets();
        foreach ($packs as $pack) {
            if($pack instanceof AvailableCommandsPacket){
                $overloads = [];
                $overloads[] = new CommandOverload(false, [
                    0 => (CommandParameter::enum("subcmd", new CommandEnum("subcmd", ["subcmd"]), 0)), //default "isSoft" value is false
                    1 => (CommandParameter::standard("argumentTest", AvailableCommandsPacket::ARG_TYPE_INT, 0, false))
                ]);
                $pack->commandData = [];
                $pack->commandData["testcmd"] = new CommandData("testcmd", "test desc", 0, 1, null, $overloads, []);
            }
        }
    }

Result:
2

But if you set the isSoft of CommandEnum in parameter 0 to true:

                    0 => (CommandParameter::enum("subcmd", new CommandEnum("subcmd", ["subcmd"], true), 0)), //isSoft value is currently true

Result:
Screenshot 2024-02-14 190911

However, since your plugin seemed complicated to me, I could not adapt it. Please take this message into consideration. Thank you from now.

jasonw4331 added a commit that referenced this issue Feb 16, 2024
@jasonw4331
Copy link
Owner

Does the mentioned commit resolve your issue?

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

2 participants