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

Code Error

Discussion in 'Development' started by XxCodeRedxX, Oct 7, 2017.

  1. XxCodeRedxX

    XxCodeRedxX Witch

    Messages:
    68
    I keep getting this crash dump when I load this plugin. What did I do wrong here?

    PocketMine-MP Crash Dump Fri Oct 6 21:18:49 EDT 2017

    Error: Declaration of MenuSystem\Commands\BaseCommand::getPlugin() must be compatible with pocketmine\command\PluginIdentifiableCommand::getPlugin(): pocketmine\plugin\Plugin
    File: MenuSystem-master/src/MenuSystem/Commands/BaseCommand
    Line: 11
    Type: E_COMPILE_ERROR

    THIS CRASH WAS CAUSED BY A PLUGIN
    BAD PLUGIN: MenuSystem v3.0.0

    Code:
    [2]
    [3] namespace MenuSystem\Commands;
    [4]
    [5] use MenuSystem\Main;
    [6]
    [7] use pocketmine\command\Command;
    [8] use pocketmine\command\CommandSender;
    [9] use pocketmine\command\PluginIdentifiableCommand;
    [10]
    [11] class BaseCommand extends Command implements PluginIdentifiableCommand
    [12] {
    [13] private $plugin;
    [14] public function __construct(Main $plugin, $name, $description, $usageMessage, $aliases)
    [15] {
    [16] parent::__construct($name, $description, $usageMessage, $aliases);
    [17] $this->plugin = $plugin;
    [18] }
    [19] public function execute(CommandSender $sender, $commandLabel, array $args)
    [20] {
    [21] if ($this->testPermission($sender)) {
     
  2. XxCodeRedxX

    XxCodeRedxX Witch

    Messages:
    68
    Wait, what line should I replace that with? And no.
     
  3. XxCodeRedxX

    XxCodeRedxX Witch

    Messages:
    68
    <?php

    namespace LobbySystem\Commands;

    use LobbySystem\Main;

    use pocketmine\command\Command;
    use pocketmine\command\CommandSender;
    use pocketmine\command\PluginIdentifiableCommand;

    class BaseCommand extends Command implements PluginIdentifiableCommand
    {
    private $plugin;
    public function __construct(Main $plugin, $name, $description, $usageMessage, $aliases)
    {
    parent::__construct($name, $description, $usageMessage, $aliases);
    $this->plugin = $plugin;
    }
    ppublic function execute(CommandSender $sender, $commandLabel, array $args)
    {
    if ($this->testPermission($sender)) {
    $result = $this->onExecute($sender, $args);
    if (is_string($result)) {
    $sender->sendMessage($result);
    }
    return true;
    }
    return false;
    }
    public function onExecute(CommandSender $sender, array $args)
    {
    }
    public function getPlugin()
    {
    return $this->plugin;
    }
    }

    Current Code
     
  4. iiFlamiinBlaze

    iiFlamiinBlaze Witch

    Messages:
    59
    GitHub:
    iiflamiinblaze
    The bolded things in the code should fix the errors (try it and see if it is fixed)
     
    Last edited: Oct 8, 2017
    XCodeMCPE likes this.
  5. themestl

    themestl Spider Jockey

    Messages:
    39
    GitHub:
    themestl
    public function getPlugin(): Plugin{
    return $this->plugin;
    }
     
    jasonwynn10 likes this.
  6. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Use CODE tags!
     
    jasonwynn10 likes this.
  7. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    That's COMPLETELY incorrect
     
    Levi likes this.
  8. iiFlamiinBlaze

    iiFlamiinBlaze Witch

    Messages:
    59
    GitHub:
    iiflamiinblaze
    I changed it in the 2nd post :p read before you speak lol
     
    XCodeMCPE likes this.
  9. iiFlamiinBlaze

    iiFlamiinBlaze Witch

    Messages:
    59
    GitHub:
    iiflamiinblaze
    it would be

    public function getPlugin(): BaseCommand{
    return $this->plugin;
    }

    not just Plugin :p
     
  10. themestl

    themestl Spider Jockey

    Messages:
    39
    GitHub:
    themestl
    Are you sure?
     
    Levi likes this.
  11. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Read the error:
    Code:
    Declaration of MenuSystem\Commands\BaseCommand::getPlugin() must be compatible with pocketmine\command\PluginIdentifiableCommand::getPlugin(): pocketmine\plugin\Plugin
    It says that there is something wrong with the getPlugin() function in your BaseCommand.php file. It must be compatible with:
    pocketmine\command\PluginIdentifiableCommand::getPlugin(): pocketmine\plugin\Plugin

    The getPlugin() functions needs to return a Plugin object, that means you need to change public function getPlugin() to public function getPlugin(): Plugin. Don't forget to add the Plugin class with the use keyword.
     
    iiFlamiinBlaze and jasonwynn10 like this.
  12. iiFlamiinBlaze

    iiFlamiinBlaze Witch

    Messages:
    59
    GitHub:
    iiflamiinblaze
    Yes I’m sure, I have had to fix the error many times :p
     
  13. XxCodeRedxX

    XxCodeRedxX Witch

    Messages:
    68
    So what's the right code?
     
  14. iiFlamiinBlaze

    iiFlamiinBlaze Witch

    Messages:
    59
    GitHub:
    iiflamiinblaze
    public function getPlugin(): BaseCommand{
    return $this->plugin;
    }
     
  15. XxCodeRedxX

    XxCodeRedxX Witch

    Messages:
    68
    Like where do I put it?
     
  16. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    Where does the error say that getPlugin() should return a BaseCommand?

    @WinterBuild7074 and @themestl already answered this correctly above so please don't add wrong information. When overriding a core class you must respect the types for both the arguments passed, and the return type (here the function getPlugin() must return... a Plugin object) as specified after a colon : and just before the opening curly brace { of your function.

    That said, it looks like there's a whole load of other problems with this code (ppublic function??), although without using code blocks it's impossible to read :-/ Why not contact the developer instead of asking people here to fix it for you? It's fine asking for help, but if you don't understand what a 'return type' is then you'll be unable to fix it yourself even if we tell you how.
     
    Last edited: Oct 10, 2017
    jasonwynn10 likes this.
  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.