cant use getserver

Discussion in 'Development' started by hexmor, Oct 30, 2018.

  1. hexmor

    hexmor Baby Zombie

    Messages:
    129
    hi guys
    i cant use getserver in scheduleRepeatingTask
    Why and How Can I Fix This ?
    Error :
    Code:
    19:19:28] [Server thread/CRITICAL]: Could not pass event 'pocketmine\event\player\PlayerInteractEvent' to 'CobaltGuns v1.2.0': Call to undefined method CobaltGuns\ProgressBar::getServer() on CobaltGuns\Main
    [19:19:28] [Server thread/CRITICAL]: Error: "Call to undefined method CobaltGuns\ProgressBar::getServer()" (EXCEPTION) in "CobaltGuns_v1.2.0/src/CobaltGuns/ProgressBar" at line 22
    [19:19:28] [Server thread/DEBUG]: #0 CobaltGuns_v1.2.0/src/CobaltGuns/Main(346): CobaltGuns\ProgressBar->__construct(CobaltGuns\Main object, pocketmine\Player object, integer 20)
    [19:19:28] [Server thread/DEBUG]: #1 src/pocketmine/plugin/MethodEventExecutor(38): CobaltGuns\Main->onShoot(pocketmine\event\player\PlayerInteractEvent object)
    [19:19:28] [Server thread/DEBUG]: #2 src/pocketmine/plugin/RegisteredListener(98): pocketmine\plugin\MethodEventExecutor->execute(CobaltGuns\Main object, pocketmine\event\player\PlayerInteractEvent object)
    [19:19:28] [Server thread/DEBUG]: #3 src/pocketmine/plugin/PluginManager(702): pocketmine\plugin\RegisteredListener->callEvent(pocketmine\event\player\PlayerInteractEvent object)
    [19:19:28] [Server thread/DEBUG]: #4 src/pocketmine/Player(2450): pocketmine\plugin\PluginManager->callEvent(pocketmine\event\player\PlayerInteractEvent object)
    [19:19:28] [Server thread/DEBUG]: #5 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(136): pocketmine\Player->handleInventoryTransaction(pocketmine\network\mcpe\protocol\InventoryTransactionPacket object)
    [19:19:28] [Server thread/DEBUG]: #6 src/pocketmine/network/mcpe/protocol/InventoryTransactionPacket(155): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleInventoryTransaction(pocketmine\network\mcpe\protocol\InventoryTransactionPacket object)
    [19:19:28] [Server thread/DEBUG]: #7 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(96): pocketmine\network\mcpe\protocol\InventoryTransactionPacket->handle(pocketmine\network\mcpe\PlayerNetworkSessionAdapter object)
    [19:19:28] [Server thread/DEBUG]: #8 src/pocketmine/network/mcpe/protocol/BatchPacket(114): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\InventoryTransactionPacket object)
    [19:19:28] [Server thread/DEBUG]: #9 src/pocketmine/network/mcpe/PlayerNetworkSessionAdapter(96): pocketmine\network\mcpe\protocol\BatchPacket->handle(pocketmine\network\mcpe\PlayerNetworkSessionAdapter object)
    [19:19:28] [Server thread/DEBUG]: #10 src/pocketmine/Player(3056): pocketmine\network\mcpe\PlayerNetworkSessionAdapter->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object)
    [19:19:28] [Server thread/DEBUG]: #11 src/pocketmine/network/mcpe/RakLibInterface(161): pocketmine\Player->handleDataPacket(pocketmine\network\mcpe\protocol\BatchPacket object)
    [19:19:28] [Server thread/DEBUG]: #12 vendor/pocketmine/raklib/src/server/ServerHandler(98): pocketmine\network\mcpe\RakLibInterface->handleEncapsulated(string 192.168.0.100 55493, raklib\protocol\EncapsulatedPacket object, integer 0)
    [19:19:28] [Server thread/DEBUG]: #13 src/pocketmine/network/mcpe/RakLibInterface(102): raklib\server\ServerHandler->handlePacket()
    [19:19:28] [Server thread/DEBUG]: #14 src/pocketmine/network/Network(94): pocketmine\network\mcpe\RakLibInterface->process()
    [19:19:28] [Server thread/DEBUG]: #15 src/pocketmine/network/mcpe/RakLibInterface(92): pocketmine\network\Network->processInterface(pocketmine\network\mcpe\RakLibInterface object)
    [19:19:28] [Server thread/DEBUG]: #16 vendor/pocketmine/snooze/src/SleeperHandler(120): pocketmine\network\mcpe\RakLibInterface->pocketmine\network\mcpe\{closure}()
    [19:19:28] [Server thread/DEBUG]: #17 vendor/pocketmine/snooze/src/SleeperHandler(82): pocketmine\snooze\SleeperHandler->processNotifications()
    [19:19:28] [Server thread/DEBUG]: #18 src/pocketmine/Server(2259): pocketmine\snooze\SleeperHandler->sleepUntil(double 1540914568.085)
    [19:19:28] [Server thread/DEBUG]: #19 src/pocketmine/Server(2134): pocketmine\Server->tickProcessor()
    [19:19:28] [Server thread/DEBUG]: #20 src/pocketmine/Server(1700): pocketmine\Server->start()
    [19:19:28] [Server thread/DEBUG]: #21 src/pocketmine/PocketMine(249): pocketmine\Server->__construct(BaseClassLoader object, pocketmine\utils\MainLogger object, string C:\Users\Mahan\Desktop\New folder (6)\, string C:\Users\Mahan\Desktop\New folder (6)\plugins\)
    [19:19:28] [Server thread/DEBUG]: #22 C:/Users/Mahan/Desktop/New folder (6)/PocketMine-MP.phar(1): require(string phar://C:/Users/Mahan/Desktop/New folder (6)/PocketMine-MP.phar/src/pocketmine/PocketMine.php)
    
    and The Progress Bar :
    PHP:
    <?php

    namespace CobaltGuns;

    use 
    pocketmine\scheduler\Task;
    use 
    pocketmine\utils\TextFormat as T;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\plugin\PluginBase;

    class 
    ProgressBar extends Task
    {

        private 
    $plugin$player$cd$m;

        public function 
    __construct(Main $pluginPlayer $playerint $cd)
        {
            
    $this->plugin $plugin;
            
    $this->player $player;
            
    $this->cd $cd;
            
    $this->$cd;
            
    $this->pp $this->getServer()->getPluginManager()->getPlugin("PureChat");
            
    $this->ppa $this->pp->getNametag($player);
        }

        
        
        public function 
    onRun(int $currentTick)
        {
            
                
    $this->player->setXpLevel($this->cd);
                
    $this->player->addTitle(""str_repeat(T::GREEN "|"$this->$this->cd) . str_repeat(T::RED "|"$this->cd));
                
    $this->player->setXpProgress("0." $this->cd);
                
    $this->player->sendPopup(T::GOLD "Energy Status \n" T::BOLD str_repeat(T::GREEN "|"$this->$this->cd) . str_repeat(T::RED "|"$this->cd));
                
    $this->player->setNameTag($this->ppa "\n" str_repeat(T::GREEN "|"$this->$this->cd) . str_repeat(T::RED "|"$this->cd));
                
                
    $this->cd--;
                if(
    $this->cd 10)
                    {
                
    $this->player->setXpProgress("0.0" $this->cd);
                    }
                if(
    $this->cd === 0)
                {
                    
    $this->player->setXpLevel(0);
                    
    $this->player->setXpProgress(1);
                    
    $this->player->sendPopup("");
                    
    $this->plugin->toggleTagged($this->player->getName());
                    
    $this->plugin->getScheduler()->cancelTask($this->getTaskId());
                    
    $this->player->addTitle("");
                }
        }

    }
     
  2. GamakCZ

    GamakCZ Baby Zombie

    Messages:
    151
    GitHub:
    GamakCZ
    You cannot use methods from PluginBase class in Task, if you want use PluginBase methods in Task's constructor, you must use $plugin instead of $this
     
  3. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    627
    GitHub:
    xXNiceYT
    He could use Server::getInstance() Too
     
    AkmalFairuz and jasonwynn10 like this.
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin Noobiest member in the PMMP Team

    Messages:
    1,716
    GitHub:
    sof3
    That's like saying "I don't know how to solve 1+1, but my pocket calculator told me it is 2". You just evaded the problem. You haven't fixed anything.
     
  5. Thunder33345

    Thunder33345 Moderator Staff Member Verified

    Messages:
    2,129
    GitHub:
    Thunder33345
    you should call your pluginbase::getServer()
    which apparently was conveniently already passed into task
     
  6. AkmalFairuz

    AkmalFairuz Spider Jockey

    Messages:
    25
    GitHub:
    akmalfairuz
    Change this:
    PHP:
    $this->pp $this->getServer()->getPluginManager()->getPlugin("PureChat");
    To:
    PHP:
    $this->pp = \pocketmine\Server::getInstance()->getPluginManager()->getPlugin("PureChat");
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin Noobiest member in the PMMP Team

    Messages:
    1,716
    GitHub:
    sof3
    :facepalm:
     
    Last edited: Nov 3, 2018

Share This Page

  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.