Plugin error, help me

Discussion in 'Development' started by Th3Ang3lo, Nov 17, 2018.

  1. Th3Ang3lo

    Th3Ang3lo Silverfish

    Messages:
    17
    Good night of the PMMP forum, my mistake is this: I do not know if it is an error since my plugin runs without any error in pocketmine localhost, but when I send the same to a dedicated server the plugin starts everything correctly but when I try execute some command, it gives an error ... I'm sorry for my bad English, I'm Brazilian.

    My error is as follows:
    (2) .phar / src / WNCORE / Plugins / Homes / Homes.php on. line 21
    17.11 20:10:56 [Server] Server thread / CRITICAL Unhandled exception executing command 'homes' in homes: Call to a member function query () on null
    17.11 20:10:56 [Server] Server thread / CRITICAL Error: "Call to a member function query () on null" (EXCEPTION) in "/ WhinterCore PL (2) .phar / src / WNCORE / Plugins / Homes / Homes "at line 21

    My code is this:

    1. <?php

    2. namespace WNCORE\Plugins\Homes;

    3. use pocketmine\command\{Command, CommandSender};
    4. use pocketmine\Player;
    5. use pocketmine\plugin\PluginBase;
    6. use pocketmine\Server;
    7. use pocketmine\level\Level;
    8. use pocketmine\level\Position;
    9. use WNCORE\Loader;

    10. class Homes extends Command{
    11. public function __construct(Loader $plugin){
    12. $this->pl = $plugin;
    13. parent::__construct('homes', 'Veja a lista de homes');
    14. }

    15. public function execute(CommandSender $sender, $label, array $args){
    16. $player = strtolower($sender->getName());
    17. $sql = $this->pl->db->query("SELECT * FROM homes WHERE player = '$player';");
    18. $result = $sql->fetchArray(SQLITE3_ASSOC);

    19. if($result['player'] == NULL){
    20. $sender->sendMessage("§7[§9!§7] Você não possui nenhuma home!");
    21. return true;
    22. }
    23. $sender->sendMessage("§7[§9!§7] Lista de homes §7[§9!§7]");
    24. while($home = $sql->fetchArray(SQLITE3_ASSOC)){
    25. $sender->sendMessage("§8- §e{$home['home']}");
    26. }
    27. }
    28. }

    From what I understand, the error is in the part of:
    public function __construct(Loader $plugin){
    $this->pl = $plugin;
    parent::__construct('homes', 'Veja a lista de homes');
    }

    that the plugin can not call the $this->pl function that is calling the class Main (Loader.php)
     
  2. XenialDan

    XenialDan Baby Zombie

    Messages:
    132
    GitHub:
    thebigsmilexd
    The $db in Loader is not defined or not a database
     
  3. Th3Ang3lo

    Th3Ang3lo Silverfish

    Messages:
    17
    Loader is:
    public function onEnable(){
    $this->db = new \SQLite3($this->getDataFolder()."homes.sqlite3");
    }

    Is database!
     
  4. XenialDan

    XenialDan Baby Zombie

    Messages:
    132
    GitHub:
    thebigsmilexd
    File is not found or invalid. So or so, the db becomes or stays null, so the database connection is not found.

    Is sqlite enabled in php.ini?
     
  5. Th3Ang3lo

    Th3Ang3lo Silverfish

    Messages:
    17
    The sqlite is enabled yes, in pocketmine everything works normal but when it is in hosting it sends the error shown ... From what I know it should be in $this->pl because when I tried calling a config function it gave the same thing. ..
     
  6. HeyDeniis_

    HeyDeniis_ Spider

    Messages:
    12
    Cria Uma Função Para Pegar A Database Invés De Usar $this->pl ;
     
  7. XenialDan

    XenialDan Baby Zombie

    Messages:
    132
    GitHub:
    thebigsmilexd
    Please talk in english
     
  8. HeyDeniis_

    HeyDeniis_ Spider

    Messages:
    12
    I Said In English Why The Guy Who Has Doubt Also And Brazilian, And It Makes It Easier To Know
     
  9. HeyDeniis_

    HeyDeniis_ Spider

    Messages:
    12
    in Main :
    public function getDataBase(){
    @mkdir($this->getDataFolder());
    $this->db = new \SQLite3($this->getDataFolder()."homes.sqlite3");
    return $this->db;
    }
    In Homes :
    $db = $this->plugin->getDataBase();
    $sql = $db->query("SELECT * FROM homes WHERE player = '$player';");
     

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.