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

Unable to call PurePerms API

Discussion in 'Development' started by InspectorGadget, Sep 22, 2017.

  1. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Hi, i'm cracking my head for this one "instance" method, if anyone know how and why. Please explain and teach :)

    PHP:
    <?php
    /**
    * Created by PhpStorm.
    * User: RTG
    * Date: 22/9/2017
    * Time: 7:28 PM
    */

    namespace RTG\TransferMyRank;

    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;

    class 
    Main extends PluginBase {

        public 
    $pp;

        public function 
    onEnable() {

            
    $this->pp $this->getServer()->getPluginManager()->getPlugin("PurePerms");

            if (!
    $this->pp) {
                
    $this->getLogger()->warning("Ermmm, unable to spot PurePerms");
            } else {
                
    $this->getLogger()->warning("Successfully connected to PurePerms");
            }

        }

        public function 
    onTransfer($sender$target$destination) {

            if (
    $target instanceof Player && $destination instanceof Player) {

                
    $api $this->getServer()->getPluginManager()->getPlugin("PurePerms");
                
    $grp $api->getUserDataMgr()->getGroup($target);

                
    $sender->sendMessage($grp " !");

            }

        }

        public function 
    onCommand(CommandSender $senderCommand $commandstring $label, array $args): bool {

            switch (
    $command->getName()) {

                case 
    "transfer":

                    if (isset(
    $args[0])) {

                        if (isset(
    $args[1])) {
                            
    $this->onTransfer($sender$args[0], $args[1]);
                        } else {
                            
    $sender->sendMessage("Done, rank transferred!");
                        }

                    } else {
                            
    $sender->sendMessage("[Usage] /transfer {target} {target}");
                    }

                    return 
    true;
                break;

            }

        }

    }
    Error:

    Code:
    [21:04:28] [Server thread/INFO]: An unknown error occurred while attempting to perform this command
    [21:04:28] [Server thread/CRITICAL]: Unhandled exception executing command 'transfer Steve AirySaturn21283' in transfer: Argument 1 passed to _64FF00\PurePerms\data\UserDataManager::__construct() must
     be an instance of _64FF00\PurePerms\PurePerms, string given, called in C:\Users\RTG\Documents\Tester Unit\plugins\TransferMyRank\src\RTG\TransferMyRank\Main.php on line 34
    [21:04:28] [Server thread/CRITICAL]: TypeError: "Argument 1 passed to _64FF00\PurePerms\data\UserDataManager::__construct() must be an instance of _64FF00\PurePerms\PurePerms, string given, called in
    C:\Users\RTG\Documents\Tester Unit\plugins\TransferMyRank\src\RTG\TransferMyRank\Main.php on line 34" (EXCEPTION) in "PurePerms/src/_64FF00/PurePerms/data/UserDataManager" at line 29
    
    I don't understand the error.

    Thanks
     
    Last edited: Sep 22, 2017
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
     
  3. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Actually, i don't know how to call the 'instance'. Can you help?
     
  4. BluetigerESW

    BluetigerESW Spider

    Messages:
    6
    GitHub:
    bluetigeresw
    You need to add a use statement for PurePerms.

    Add:
    Code:
    use _64FF00\PurePerms\PurePerms;
    and it should be good :)
     
    iiFlamiinBlaze likes this.
  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    It is totally irrelevant.
     
  6. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Try add

    PHP:
    if($api instanceof \_64FF00\PurePerms\PurePerms) {
    }
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    I don't know why you stored $this->pp in onEnable() but try to fetch the plugin again through PluginManager.
     
  8. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    I've fixed it, thanks for you help.
     
  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.