EntityDamageByEntity Event & Projectiles

Discussion in 'Plugin Development' started by Valexio, Sep 24, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Valexio

    Hello, so I have this issue that I just can't seem to solve.

    I am creating a CombatTag plugin and the player hit detection works perfectly. However, I'm having issues with trying to get the shooter and damaged player when hit by an arrow and fishing rod. Here is what I have so far:
    Code:
    @EventHandler
        public void onDamage(EntityDamageByEntityEvent e) {
    
            if ((e.getEntity() instanceof Player) && ((e.getDamager() instanceof Player))) {
    
            final Player e1 = (Player) e.getEntity();
            final Player e2 = ((Player) e.getDamager());
    
                WorldGuardPlugin worldGuard = getWorldGuard();
                Vector pt = toVector(e1.getLocation());
                RegionManager regionManager = worldGuard.getRegionManager(e1.getWorld());
                ApplicableRegionSet set = regionManager.getApplicableRegions(pt);
    
                if (!set.allows(DefaultFlag.PVP)) {
                    return;
                } else {
                    if ((!CombatLog.contains(e1.getName())) && (!CombatLog.contains(e2.getName()))) {
                        CombatLog.add(e1.getName());
                        CombatLog.add(e2.getName());
                        e1.sendMessage(MessageApi.combat + "§7You are in combat with §c" + e2.getName() + "§7!" + " §c§lDO NOT LOG OUT§7!");
                        e2.sendMessage(MessageApi.combat + "§7You are in combat with §c" + e1.getName() + "§7!" + " §c§lDO NOT LOG OUT§7!");
                    } else {
                        if (e.getDamager() instanceof Arrow){
                            final Arrow arrow = (Arrow) e.getDamager();
    
                            if (arrow.getShooter() instanceof Player) {
                                if (e.getEntity() instanceof Player) {
    
                                    Player player = (Player) e.getEntity();
                                    Player shooter = (Player) arrow.getShooter();
    
                                    if ((!CombatLog.contains(player.getName())) && (!CombatLog.contains(shooter.getName()))) {
                                        CombatLog.add(player.getName());
                                        CombatLog.add(shooter.getName());
                                        player.sendMessage(MessageApi.combat + "§7You are in combat with §c" + shooter.getName() + "§7!" + " §c§lDO NOT LOG OUT§7!");
                                        shooter.sendMessage(MessageApi.combat + "§7You are in combat with §c" + player.getName() + "§7!" + " §c§lDO NOT LOG OUT§7!");
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    My event is registered, no messages come up in chat, and no error come up in the console.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @Valexio If it is an projectile then the first check returns false.
     
Thread Status:
Not open for further replies.

Share This Page