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

onAttack

Discussion in 'Plugin Help' started by TheWalkingDrift, Jun 19, 2019.

  1. TheWalkingDrift

    TheWalkingDrift Silverfish

    Messages:
    23
    I got this Problem with my plugin when I Start my Server:
    [11:34:25] [Server thread/CRITICAL]: ParseError: "syntax error, unexpected 'public function onAttack' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)" (EXCEPTION) in "plugins/command/src/hunger/hunger" at line 12

    This is my Code:

    <?php

    namespace hunger;

    use pocketmine\entity\Entity;
    use pocketmine\event\entity\EntityDamageByEntityEvent;
    use pocketmine\event\entity\EntityDamageEvent;
    use pocketmine\event\Listener;

    class onAttack extends PluginBase implements Listener{

    public function onAttack(\pocketmine\event\entity\EntityDamageEvent $e)
    {
    if($e instanceof \pocketmine\event\entity\EntityDamageByEntityEvent){
    if($event->getEntity() instanceof Player && $event->getDamager() instanceof Player){
    if($e->getDamager()->getInventory()->getItemInHand()->getId() == 1){
    $e->getEntity()->sendMessage("You have been spotted with a stone");
    $e->getDamager()->sendMessage("You spot a player with stone!");
    }
    }
    }
    }
    }
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    I don't think that error comes from the code you sent there, I ran it through a syntax checker and it shows no errors.
     
  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.