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

Error with my first plugin help!

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

  1. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    Error
    22.09 16:54:39 [Server] INFO Fatal error: Declaration of KnockbackM\Main::eek:nCommand(KnockbackM\Command $cmd, KnockbackM\CommandSender $sender, array $args, $label) must be compatible with pocketmine\command\CommandExecutor::eek:nCommand(pocketmine\command\CommandSender $sender, pocketmine\command\Command $command, string $label, array $args): bool in /plugins/KnockbackM/src/KnockbackM/Main.php on line 12


    LINE 12 =
    PHP:
    class Main extends PluginBase implements Listener{
    Code
    PHP:
    <?php
    namespace KnockbackM;

    use 
    pocketmine\event\Event;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;

    class 
    Main extends PluginBase implements Listener{

      public function 
    onEnable() {
        
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
      }

      public 
    $knockback 0.4;

      public function 
    onCommand(Command $cmdCommandSender $sender, array $args$label) {
        if(
    $cmd->getName() == "kb") {
          
    $event->setKnockback($args[0]);
          
    $sender->sendMessage("Knockback Set!");
        }
      }

      public function 
    onDamage(EntityDamageEvent $event) {
        if(
    $event instanceof EntityDamageByEntityEvent){
          
    $event->setKnockback(1.0);
        }
      }
    }
     
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
  3. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    Sorry, like I said im new to this. This is my first real plugin. Didnt know that I didnt just have to change api in plugin.yml. Thanks
     
  4. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    cheers, either ways you should try google it first
    or learn to read the error that would help you out
     
    OnTheVerge likes this.
  5. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Read the thread Thunder gave you. Beginners should understand it. If you don't, here's how to fix it:

    Find the line in your code:
    PHP:
    public function onCommand(Command $cmdCommandSender $sender, array $args$label)
    It must be compatible with:
    PHP:
    public function onCommand(pocketmine\command\CommandSender $senderpocketmine\command\Command $cmdstring $label, array $args): bool
    That means, your line needs to exactly look like this (if you used the use keyword on the CommandSender and Command class, you can remove the pocketmine\command\ in-front of those).
    Look here to get an idea.
     
    Last edited: Sep 23, 2017
  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.