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

Solved Help on Plugin

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

  1. Th3Ang3lo

    Th3Ang3lo Spider Jockey

    Messages:
    32
    GitHub:
    Th3Ang3lo
    Error:
    [14:55:29] [Server thread/CRITICAL]: Unhandled exception executing command 'home a' in home: Call to undefined method WNCORE\Plugins\Homes\HomeTeleport::getServer()
    [14:55:29] [Server thread/CRITICAL]: Error: "Call to undefined method WNCORE\Plugins\Homes\HomeTeleport::getServer()" (EXCEPTION) in "/WhinterCore/src/WNCORE/Plugins/Homes/HomeTeleport" at line 29

    CODE:

    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 HomeTeleport extends Command{
    11. public function __construct(Loader $plugin){
    12. $this->pl = $plugin;
    13. parent::__construct('home', 'Teletransporte entre homes');
    14. }

    15. public function execute(CommandSender $sender, $label, array $args){
    16. if(!isset($args[0])){
    17. $sender->sendMessage("§7[§9!§7] Use §e/home <nome>");
    18. return true;
    19. }
    20. $player = strtolower($sender->getName());
    21. $sql = $this->pl->db->query("SELECT * FROM homes WHERE player = '$player';");
    22. while($result = $sql->fetchArray(SQLITE3_ASSOC)){
    23. if($args[0] == $result['home']){
    24. $level = $this->getServer()->getLevelByName($result['world']);
    25. $pos = new Position($result['x'], $result['y'], $result['z'], $level);
    26. $sender->teleport($pos);
    27. $sender->sendMessage("§7[§9!§7] Você se teletransportou para a home §e{$result['home']}");
    28. }
    29. }
    30. }
    31. }
     
  2. radondev

    radondev Silverfish

    Messages:
    21
    GitHub:
    radondev
    You have to get the server from your main class
     
  3. Th3Ang3lo

    Th3Ang3lo Spider Jockey

    Messages:
    32
    GitHub:
    Th3Ang3lo
    Thank You :)
     
  4. Th3Ang3lo

    Th3Ang3lo Spider Jockey

    Messages:
    32
    GitHub:
    Th3Ang3lo
    edit line 29 to

    $level = $this->pl->getServer()->getLevelByName($result['world']);
     
  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.