EntityDamageEvent doesnt trigger

Discussion in 'Spigot Plugin Help' started by bnnschn, May 15, 2017.

  1. My following code doesnt trigger EntityDamageEvent or EntityDamageByEntityEvent. I put up two EventHandlers that broadcast a message. They work if i hit a player but not with this, why?

    Code (Text):
        public static void damage(ProjectileSource damager, Damageable todamage, double damage) {
            Projectile p = todamage.getWorld().spawn(todamage.getLocation().add(0, 5, 0), CraftArrow.class);
            p.setShooter(damager);
            todamage.damage(damage, p);
            new BukkitRunnable() {

                @Override
                public void run() {
                    p.remove();
                }

            }.runTaskLater(main.plugin, 2);
        }
     
  2. You want to got damage by Arrow ?
     
  3. Yes
     
  4. Hmm try that !

    Code (Text):
    if(event.getDamager() instanceof Arrow){
                final Arrow arrow = (Arrow) event.getDamager();
                if(arrow.getShooter() instanceof Player){
                    new Thread(new Runnable(){
                        @Override
                        public void run(){
                    Player damager = (Player) arrow.getShooter();
                    Bukkit.broadcastMessage("" + player.getName() + " shot by " + damager.getName());
                        }
                    }).start();
                }
            }
     
  5. No event gets triggered since the following code doesnt broadcast anything.
    Code (Text):
        @EventHandler
        public void on(EntityDamageEvent e) {
            Debug.log(e.getEntity().getClass().getSimpleName());
        }
    Code (Text):

        public static void log(String msg) {
            msg = msg == null ? "null" : msg;
            Bukkit.broadcastMessage("§e[DEBUG] §f" + msg);
        }

        public static void log(Object o) {
            if (o == null) {
                log("null");
            }
            log(o.toString());
        }
     
     
  6. Hmm, i'm losted o_O
    Explain me what you want to do ^^
    ( Sorry it's late )