Search in sources :

Example 1 with Arrow

use of org.bukkit.entity.Arrow in project Minigames by AddstarMC.

the class Events method entityDamageEntity.

@EventHandler(priority = EventPriority.LOWEST)
private void entityDamageEntity(EntityDamageByEntityEvent event) {
    if (event.getEntity() instanceof Player && event.getDamager() instanceof Snowball) {
        MinigamePlayer ply = pdata.getMinigamePlayer((Player) event.getEntity());
        if (ply == null)
            return;
        Snowball sb = (Snowball) event.getDamager();
        if (ply.isInMinigame() && ply.getMinigame().hasPaintBallMode()) {
            if (sb.getShooter() instanceof Player) {
                MinigamePlayer shooter = pdata.getMinigamePlayer((Player) sb.getShooter());
                Minigame mgm = ply.getMinigame();
                if (shooter == null)
                    return;
                if (shooter.isInMinigame() && shooter.getMinigame().equals(ply.getMinigame())) {
                    if (!shooter.canPvP()) {
                        event.setCancelled(true);
                        return;
                    }
                    Team plyTeam = ply.getTeam();
                    Team atcTeam = shooter.getTeam();
                    if (!mgm.isTeamGame() || plyTeam != atcTeam) {
                        int damage = mgm.getPaintBallDamage();
                        event.setDamage(damage);
                    }
                }
            }
        }
    } else if (event.getEntity() instanceof Player && event.getDamager() instanceof Player) {
        MinigamePlayer ply = pdata.getMinigamePlayer((Player) event.getDamager());
        if (ply == null)
            return;
        if (ply.isInMinigame() && !ply.canPvP())
            event.setCancelled(true);
        else if (ply.isInMinigame() && ply.getMinigame().getState() == MinigameState.ENDED && GameOverModule.getMinigameModule(ply.getMinigame()).isHumiliationMode() && GameOverModule.getMinigameModule(ply.getMinigame()).getLosers().contains(ply)) {
            event.setCancelled(true);
        }
    } else if (event.getEntity() instanceof Player && event.getDamager() instanceof Arrow) {
        Arrow arrow = (Arrow) event.getDamager();
        if (arrow.getShooter() instanceof Player) {
            Player ply = (Player) arrow.getShooter();
            MinigamePlayer mgpl = pdata.getMinigamePlayer(ply);
            if (mgpl == null)
                return;
            if (mgpl.isInMinigame() && !mgpl.canPvP())
                event.setCancelled(true);
        }
    }
}
Also used : Arrow(org.bukkit.entity.Arrow) Snowball(org.bukkit.entity.Snowball) Player(org.bukkit.entity.Player) Team(au.com.mineauz.minigames.minigame.Team) Minigame(au.com.mineauz.minigames.minigame.Minigame) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Minigame (au.com.mineauz.minigames.minigame.Minigame)1 Team (au.com.mineauz.minigames.minigame.Team)1 Arrow (org.bukkit.entity.Arrow)1 Player (org.bukkit.entity.Player)1 Snowball (org.bukkit.entity.Snowball)1 EventHandler (org.bukkit.event.EventHandler)1