Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

KnockBack

Comments in 'Plugin Development' started by Skullex, Feb 5, 2016.

  1. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    I have recently coded this. My first time dealing with KnockBack in a plugin. And everytime I start up the server it gets disabled :(. I need someone to point out my errors and help me correct them.

    PHP:
    <?php

    namespace KB;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\level\sound\BlazeShootSound;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;

    class 
    KnockBack extends PluginBase implements Listener{

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

        public function 
    onLoad(){
            
    $this->getLogger()->info("KnockBack §aenabled");
        }

        public function 
    onDamage(EntityDamageByEntityEvent $event){
            
    $entity $event->getEntity();
            
    $fizz = new BlazeShootSound($entity);
            
    $entity->getLevel()->addSound($fizz);
            
    $entity->knockBack($entity0101);
        }

        public function 
    onDisable(){
            
    $this->getLogger()->info("KnockBack §cdisabled.");
            return 
    true;
        }
    }
    Thanks in advance :)
    Muqsit likes this.
  2. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Any console errors?
  3. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    Er, let me check again
  4. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    Yep, sorry for late reply
    Code:
    Pocketmine\utils\PluginException: "pocketmine\event\entity\EntituDamageByEntityEvent does not have a handler list "(EXCEPTION) in "src/pocketmine/plugin/PluginManager " at line 764
    
  5. CaptainKenji17
    Offline

    CaptainKenji17 Active Member

    Joined:
    Apr 22, 2014
    Posts:
    252
    Minecraft User:
    CaptainKenji17
    $event->setKnockBack(knockback number);

    0.5 = normal

    numbers like 1 or 2 is pretty strong



    my bad dont mind this ur code is correct maybe just misinh things such as EntityDamageEvent
    Skullex likes this.
  6. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    You have to use EntityDamageEvent.
    Skullex likes this.
  7. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Try this
    PHP:
    public function onDamage(EntityDamageEvent $event){
      
    $entity $event->getEntity();
      if(
    $event instanceof EntityDamageByEntityEvent){
        
    $fizz = new BlazeShootSound($entity);
        
    $entity->getLevel()->addSound($fizz);
        
    $entity->knockBack($entity0101);
      }
    }
    MyNameIsTriXz and Skullex like this.
  8. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    On it
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Default is 0.4

    It is more practical to use it relatively.
    PHP:
    $event->setKnockback($event->getKnockback() * 1.5);
    Increase knockback by 50%.
    luca28pet and Skullex like this.
  10. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    TY SO MUCH, IT WORKS :D
  11. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    OK now I've added onto the plugin, and doing so brought this new problem. Parsing Errors, I need more corrections on my code :(

    Screenshot_2016-02-05-17-33-38.png
    PHP:
    <?php

    namespace KB;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\level\sound\BlazeShootSound;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\event\entity\EntityDamageEvent;

    class 
    KnockBack extends PluginBase implements Listener{

      public function 
    onEnable(){
      
    $this->getServer()->getPluginManager()->registerEvents($this$this);
      } 
    // Registers the events listed above and used below

    public function onLoad(){
    $this->getLogger()->info("KnockBack §aenabled");
    // Sends a message to console to Alert you that the plugin has been loaded

      
    public function onDamage(EntityDamageEvent $event){
      
    $entity $event->getEntity();
      if(
    $event instanceof EntityDamageByEntityEvent){
      
    $fizz = new BlazeShootSound($entity);
      
    $entity->getLevel()->addSound($fizz);
      
    $entity->knockBack($entity0101);
      } 
    // KnockBack in PVP
    }

      public function 
    onDamage(EntityDamageByBlockEvent $event){
      
    $entity $event->getEntity();
      if(
    $event instanceof EntityDamageByEntityEvent){
      
    $entity->knockBack($entity0101);
      } 
    // KnockBack from block damage, not explosion friendly because you'll fly away
    }

      public function 
    onDisable(){
      
    $this->getLogger()->info("KnockBack §cdisabled.");
      return 
    true;
    // Sends a message to console to Alert you that the plugin has been disabled
    }
  12. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    Which line 29?
  13. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    Yeah
  14. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    I ask 'where the line 29'?
  15. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    Oh, hold on :3
  16. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    It looks like this one
    PHP:
    public function onDamage(EntityDamageByBlockEvent $event){$entity $event->getEntity();
    if(
    $event instanceof EntityDamageByEntityEvent){$entity->knockBack($entity0101);
    // KnockBack from block damage, not explosion friendly because you'll fly away}
  17. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    You forgot one '}'
    Skullex likes this.
  18. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    This looks easier
  19. Skullex
    Offline

    Skullex Active Member

    Joined:
    Nov 14, 2015
    Posts:
    212
    Minecraft User:
    Skullex
    IT'S ALWAYS THOSE BRACKETS!!!! :D
  20. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
    That's why better to use IDE instead of Text editor
    CraftYourBukkit and Skullex like this.

Share This Page

Advertisement