Search in sources :

Example 11 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project primplugin by Fangoboyo.

the class playerDamageListener method PlayerDamageEvent.

@EventHandler
public void PlayerDamageEvent(EntityDamageEvent e) {
    if (e.getEntity().getType().isAlive()) {
        EntityDamageEvent event = (EntityDamageEvent) e;
        // defines damage and entities
        int finalDamage = e.getDamage();
        int reflectedDamage = 0;
        LivingEntity entityVictim = (LivingEntity) e.getEntity();
        LivingEntity entityDamager = (LivingEntity) entityVictim.getLastDamageCause().getEntity();
        // Entity damageCause checker
        if (e.getCause() == DamageCause.ENTITY_ATTACK) {
            // victim player checker
            if (entityVictim instanceof Player) {
                Player playerVictim = (Player) entityVictim;
                // define the 2 final damage stuff things
                defenseManager d = new defenseManager();
                getDamage dmg = new getDamage();
                // gets the attackers armor damage and weapon damage && handles factions stuff
                if (entityDamager instanceof Player) {
                    Player playerDamager = (Player) entityDamager;
                    // --------- Factions stuff -----------
                    UPlayer uPlayerDamager = UPlayer.get(playerDamager);
                    UPlayer uPlayerVictim = UPlayer.get(playerVictim);
                    if (uPlayerVictim.getFaction().equals(uPlayerDamager.getFaction())) {
                        e.setCancelled(true);
                        return;
                    }
                    // --------------------------------------
                    // ----------- Set bonus manager ---------------------
                    setBonuses set = new setBonuses();
                    // Cactus set bonus manager
                    if (set.getPlayerSetBonus(playerVictim).equals("cac")) {
                        reflectedDamage = e.getDamage() / 3;
                    }
                    // ------------------ Victim defense calculator ------------------
                    int playerDefense = d.getdefense(playerVictim);
                    int playerDefPerc = Math.round((100 * (playerDefense)) / ((100 * (playerDefense)) + 100));
                    int def = playerDefPerc / 100;
                    finalDamage = finalDamage + d.getArmorDamage(playerDamager) + dmg.getItemDamage(playerDamager.getItemInHand());
                }
            // TODO: finish revamping the rest of thsi stuff
            // Does the final damage
            }
        }
        // --------------- Magic Damage Calculator (WIP) -----------------
        if (event.getCause() == DamageCause.ENTITY_EXPLOSION && event.getEntity() instanceof TNTPrimed) {
            TNTPrimed tnt = (TNTPrimed) event.getEntity();
            magicDamageManager m = new magicDamageManager();
            // and adds it to the finalDamage int
            if (m.checkTNTContains(tnt)) {
                finalDamage = finalDamage + m.getActiveTNT(tnt);
                m.removeTNT(tnt);
            }
        }
        e.setCancelled(true);
        entityVictim.setHealth(entityVictim.getHealth() - finalDamage);
        if (entityVictim instanceof Player) {
            Player p = (Player) entityVictim;
            p.sendMessage("works yayy");
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) tech.nully.primplug.damageManager.getDamage(tech.nully.primplug.damageManager.getDamage) tech.nully.primplug.playerStatManagers.magicDamageManager.magicDamageManager(tech.nully.primplug.playerStatManagers.magicDamageManager.magicDamageManager) UPlayer(com.massivecraft.factions.entity.UPlayer) Player(org.bukkit.entity.Player) UPlayer(com.massivecraft.factions.entity.UPlayer) tech.nully.primplug.playerStatManagers.defenseManager.defenseManager(tech.nully.primplug.playerStatManagers.defenseManager.defenseManager) TNTPrimed(org.bukkit.entity.TNTPrimed) Armor.setBonuses(tech.nully.primplug.Armor.setBonuses) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) EventHandler(org.bukkit.event.EventHandler)

Example 12 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project primplugin by Fangoboyo.

the class toolAbilities method onHit.

@EventHandler
public void onHit(EntityDamageEvent e) {
    EntityDamageEvent event = (EntityDamageEvent) e;
    // checks if the event damage cause is an entity attack
    if (event.getCause() == DamageCause.ENTITY_ATTACK) {
        Player p = (Player) event.getEntity();
        // checks if the last damage cause is a player
        if (p.getLastDamageCause().getEntity() instanceof Player) {
            Player damager = (Player) p.getLastDamageCause().getEntity();
            if (damager.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("Thunderbolt of Zeus")) {
                World world = p.getWorld();
                // creates an explosion at the location of the damaged player that has a power of 1 and cannot damage blocks
                world.createExplosion(p.getLocation().getX(), p.getLocation().getY(), p.getLocation().getZ(), 1, true, false);
                world.strikeLightning(p.getLocation());
            }
            if (damager.getItemInHand().getItemMeta().getDisplayName().equalsIgnoreCase("Bloodthirsty Blade")) {
                ItemStack Idamage = damager.getItemInHand();
                Idamage.setDurability((short) -3);
                getDamage dmg = new getDamage();
                dmg.setDamage(Idamage, 3);
            }
        }
    }
}
Also used : tech.nully.primplug.damageManager.getDamage(tech.nully.primplug.damageManager.getDamage) Player(org.bukkit.entity.Player) World(org.bukkit.World) ItemStack(org.bukkit.inventory.ItemStack) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) EventHandler(org.bukkit.event.EventHandler)

Example 13 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project MiniGameWorld by MiniGameWorlds.

the class MiniGameCustomOption method processEvent.

/**
 * Process event related with custom option before pass to a minigame<br>
 *
 * @param event Event to set cancel or not with options
 */
public void processEvent(Event event) {
    if (event instanceof AsyncPlayerChatEvent) {
        ((AsyncPlayerChatEvent) event).setCancelled(!(boolean) get(Option.CHAT));
    } else if (event instanceof BlockBreakEvent) {
        ((BlockBreakEvent) event).setCancelled(!(boolean) this.get(Option.BLOCK_BREAK));
    } else if (event instanceof BlockPlaceEvent) {
        ((BlockPlaceEvent) event).setCancelled(!(boolean) this.get(Option.BLOCK_PLACE));
    } else if (event instanceof PlayerDeathEvent) {
        PlayerDeathEvent e = (PlayerDeathEvent) event;
        if ((boolean) this.get(Option.INVENTORY_SAVE)) {
            // keep inv
            e.setKeepInventory(true);
            // remove drops
            e.getDrops().clear();
        } else {
            e.setKeepInventory(false);
        }
    } else if (event instanceof PlayerRespawnEvent) {
        if ((boolean) this.get(Option.MINIGAME_RESPAWN)) {
            PlayerRespawnEvent e = (PlayerRespawnEvent) event;
            e.setRespawnLocation(this.minigame.getLocation());
        }
    } else if (event instanceof FoodLevelChangeEvent) {
        FoodLevelChangeEvent e = (FoodLevelChangeEvent) event;
        e.setCancelled(!(boolean) get(Option.FOOD_LEVEL_CHANGE));
    } else if (event instanceof EntityDamageEvent) {
        /*
			 * PLAYER_HURT
			 */
        EntityDamageEvent damageEvent = (EntityDamageEvent) event;
        if (damageEvent.getEntity() instanceof Player) {
            damageEvent.setCancelled(!(boolean) get(Option.PLAYER_HURT));
        }
        if (event instanceof EntityDamageByEntityEvent) {
            // cancel damage by entity (
            // when victim == minigame player && damager == minigame player
            EntityDamageByEntityEvent e = (EntityDamageByEntityEvent) event;
            // PVP
            processPVP(e);
            // PVE
            processPVE(e);
        }
    }
}
Also used : Player(org.bukkit.entity.Player) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) PlayerRespawnEvent(org.bukkit.event.player.PlayerRespawnEvent) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) PlayerDeathEvent(org.bukkit.event.entity.PlayerDeathEvent) AsyncPlayerChatEvent(org.bukkit.event.player.AsyncPlayerChatEvent) FoodLevelChangeEvent(org.bukkit.event.entity.FoodLevelChangeEvent) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 14 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project MiniGameWorld by MiniGameWorlds.

the class MiniGameManager method passEventToViewManager.

private boolean passEventToViewManager(Event event) {
    Player p = null;
    if (event instanceof AsyncPlayerChatEvent) {
        p = ((AsyncPlayerChatEvent) event).getPlayer();
    } else if (event instanceof PlayerRespawnEvent) {
        p = ((PlayerRespawnEvent) event).getPlayer();
    } else if (event instanceof EntityDamageEvent) {
        EntityDamageEvent e = (EntityDamageEvent) event;
        if (e.getEntity() instanceof Player) {
            p = (Player) e.getEntity();
        }
    }
    // check null
    if (p == null) {
        return false;
    }
    // check player is a viewer
    if (!isViewingMiniGame(p)) {
        return false;
    }
    // pass event to view manager
    MiniGame minigame = getViewingMiniGame(p);
    minigame.getViewManager().processEvent(event);
    return true;
}
Also used : Player(org.bukkit.entity.Player) PlayerRespawnEvent(org.bukkit.event.player.PlayerRespawnEvent) AsyncPlayerChatEvent(org.bukkit.event.player.AsyncPlayerChatEvent) MiniGame(com.worldbiomusic.minigameworld.minigameframes.MiniGame) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 15 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project Nokaut by smaks6.

the class Main method onDisable.

@Override
public void onDisable() {
    for (Player player : Bukkit.getServer().getOnlinePlayers()) {
        if (!PlayerUtility.isNull(player)) {
            if (Main.getInstance().getConfig().getString("DeathOnEnd").equals("true")) {
                EntityDamageEvent lastDamageCause = player.getLastDamageCause();
                if (lastDamageCause instanceof EntityDamageByEntityEvent) {
                    EntityDamageByEntityEvent damageByEntityEvent = (EntityDamageByEntityEvent) lastDamageCause;
                    Entity damager = damageByEntityEvent.getDamager();
                    player.damage(500, damager);
                    PoseUtility.stop(player);
                } else {
                    player.setHealth(0);
                }
                PoseUtility.stop(player);
            } else {
                PoseUtility.stop(player);
                player.removePotionEffect(PotionEffectType.BLINDNESS);
            }
        }
    }
    for (World world : Bukkit.getWorlds()) {
        for (Entity entity : world.getEntities()) {
            if (ArmorStandNokaut.isNokautArmorStand(entity))
                entity.remove();
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) Player(org.bukkit.entity.Player) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) World(org.bukkit.World) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Aggregations

EntityDamageEvent (org.bukkit.event.entity.EntityDamageEvent)109 Player (org.bukkit.entity.Player)43 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)40 Entity (org.bukkit.entity.Entity)30 LivingEntity (org.bukkit.entity.LivingEntity)25 EventHandler (org.bukkit.event.EventHandler)24 Projectile (org.bukkit.entity.Projectile)15 ItemStack (org.bukkit.inventory.ItemStack)13 Test (org.junit.Test)11 Function (com.google.common.base.Function)8 ProjectileSource (org.bukkit.projectiles.ProjectileSource)8 Location (org.bukkit.Location)7 EntityDamageByBlockEvent (org.bukkit.event.entity.EntityDamageByBlockEvent)7 DamageCause (org.bukkit.event.entity.EntityDamageEvent.DamageCause)7 EntityDeathEvent (org.bukkit.event.entity.EntityDeathEvent)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 World (org.bukkit.World)6 Block (org.bukkit.block.Block)6