1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

ServerAuth Update to 3.0.0-ALPHA7

Discussion in 'Development' started by FiberglassCivic, Aug 28, 2017.

  1. FiberglassCivic

    FiberglassCivic Spider Jockey

    Messages:
    39
    GitHub:
    95civicsi
    I'm starting this thread to help @Megalunchbox in attempting to update ServerAuth2.13. After updating the plugin API version in plugin.yml the following error is occuring:

    Code:
    Error: Declaration of ServerAuth\Commands\Commands::onCommand(ServerAuth\Commands\pocketmine\command\CommandSender $sender, ServerAuth\Commands\pocketmine\command\Command $command, $label, array $args) must be compatible with pocketmine\command\CommandExecutor::onCommand(pocketmine\command\CommandSender $sender, pocketmine\command\Command $command, string $label, array $args): bool
    
    
    PocketMine-MP version: 1.6.2dev #0 [Protocol 113; API 3.0.0-ALPHA7]
    Git commit: 0000000000000000000000000000000000000000
    uname -a: Windows NT DESKTOP-SCT4QBB 10.0 build 15063 (Windows 10) AMD64
    PHP Version: 7.0.3
    Zend version: 3.0.0
    OS : WINNT, win
    
    Loaded plugins:
    PurePerms 1.4.1-dev2 by 64FF00 & ProjectInfinity for API(s) 3.0.0-ALPHA7
    ServerAuth 2.13 by EvolSoft for API(s) 1.11.0, 3.0.0-ALPHA7
    PureChat 1.4.10-dev2 by 64FF00 for API(s) 3.0.0-ALPHA7
    This may not be the exact error as I'm copying and pasting from another thread where code tags were not used but should relay the error well enough to point out the problem.

    Thunder33345 has provided some info that should be helpful.

    Breaking the error down:

    Code:
    Error: Declaration of ServerAuth\Commands\Commands::onCommand(ServerAuth\Commands\pocketmine\command\CommandSender $sender, ServerAuth\Commands\pocketmine\command\Command $command, $label, array $args)
    This tells us that the function declaration for onCommand() in

    plugins/ServerAuth/src/ServerAuth/Commands/Commands.php

    is where we are having a problem.


    Code:
    must be compatible with pocketmine\command\CommandExecutor::onCommand(pocketmine\command\CommandSender $sender, pocketmine\command\Command $command, string $label, array $args): bool
    This part tells us what the problem is. The server API expects for the onCommand() function declaration to match the onCommand function declaration found in

    src/pocketmine/command/CommandExecutor.php

    If you don't have a copy of the source, you can look at that file on GitHub here:
    https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/command/CommandExecutor.php

    While it's useful to look at the code, the error message actually tells us what the declaration is supposed to look like. To be 100%, we're going to look at the declaration from the source:

    PHP:
    public function onCommand(CommandSender $senderCommand $commandstring $label, array $args) : bool;
    If we look at the source for the Commands.php file in ServerAuth (found here) we find the problem on line 30:
    PHP:
    public function onCommand(CommandSender $senderCommand $cmd$label, array $args) {
    For those not familiar with object-oriented programming (or programming in general) there are some things of importance to note before solving this problem. The words that start with a '$' are variable names and do not need to match exactly. Just before each variable name we find another word which determines what the variable will store (data type). Each variable is separated with a comma.

    We can see that the $label variable does not have a data type in the ServerAuth file but it has a string data type in the PocketMine CommandExecutor.php file. So the ServerAuth file needs to be changed to have the string data type. The next part of importance is at the end of the declaration. The PocketMine CommandExecutor.php file has
    Code:
    : bool
    at the end. This is called a 'return type' and is not present in the ServerAuth code. This needs to be updated as well.


    For those of you who are getting very observant at this point, you will notice that the PocketMine file has one more difference from the ServerAuth file. The PocketMine file ends with a semi-colon ( ; ) while the ServerAuth file ends with an opening curling brace ( { ). This is because the code in the PocketMine file is strictly a 'function declaration' while the code in the ServerAuth file is a 'function definition'.

    Once you have made these changes to the ServerAuth Commands.php file, every other file in the Commands folder will need the same changes.
     
    Last edited: Aug 28, 2017
  2. Megalunchbox

    Megalunchbox Spider

    Messages:
    7
    Thank you, I just need to fix the return type. Would i have to do anything with the fact that the data-type of $label was changed to string?
     
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    What's wrong with forking ServerAuth directly? Why spend so much time writing this post, when we already have a similar one in the Resources forum, and all you write here can be converted to a simple pull request to ServerAuth?
     
    SalmonDE and Muqsit like this.
  4. FiberglassCivic

    FiberglassCivic Spider Jockey

    Messages:
    39
    GitHub:
    95civicsi
    You're right that I could just fork it and submit a pull request with all the fixes but the actual details wouldn't be explained for people who may need some further help understanding. While this was started to help @Megalunchbox, I'm sure that other people will benefit from the shared information. Additionally, it seems that we're going to have more changes like this and that the ALPHA-7 API won't be around for much longer. That means we're going to have lots of people looking for this kind of thing again.

    My friend, if you're going to get into doing this kind of thing, you've got to pay more attention which is essentially the entire point of my post. I've already answered your question.
     
  5. Megalunchbox

    Megalunchbox Spider

    Messages:
    7
    I like to be 100% sure about what i am doing.
     
  6. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    There is already such a thread in the Resources forum.
     
  7. FiberglassCivic

    FiberglassCivic Spider Jockey

    Messages:
    39
    GitHub:
    95civicsi
  8. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.