jasonw4331 / EasyCommandAutofill

A PocketMine plugin which adds commands to the client's autofill system by parsing usage messages
GNU Lesser General Public License v3.0
13 stars 5 forks source link

Bug in subcommands #20

Open HakanBabus opened 7 months ago

HakanBabus commented 7 months ago

Issue description

OS and versions

Console error, backtrace or other files

Expected: image

Actual: image

jasonw4331 commented 7 months ago

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

HakanBabus commented 7 months ago

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

HakanBabus commented 7 months ago

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 commented 7 months ago

Update your install. I changed some strings for parsing

HakanBabus commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

Does the mentioned commit resolve your issue?