Search in sources :

Example 36 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project Essentials by EssentialsX.

the class Commandkill method updatePlayer.

@Override
protected void updatePlayer(final Server server, final CommandSource sender, final User user, final String[] args) throws PlayerExemptException {
    final Player matchPlayer = user.getBase();
    if (sender.isPlayer() && user.isAuthorized("essentials.kill.exempt") && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.kill.force")) {
        throw new PlayerExemptException(tl("killExempt", matchPlayer.getDisplayName()));
    }
    final EntityDamageEvent ede = new EntityDamageEvent(matchPlayer, sender.isPlayer() && sender.getPlayer().getName().equals(matchPlayer.getName()) ? EntityDamageEvent.DamageCause.SUICIDE : EntityDamageEvent.DamageCause.CUSTOM, Float.MAX_VALUE);
    server.getPluginManager().callEvent(ede);
    if (ede.isCancelled() && sender.isPlayer() && !ess.getUser(sender.getPlayer()).isAuthorized("essentials.kill.force")) {
        return;
    }
    ede.getEntity().setLastDamageCause(ede);
    matchPlayer.setHealth(0);
    sender.sendMessage(tl("kill", matchPlayer.getDisplayName()));
}
Also used : Player(org.bukkit.entity.Player) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 37 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project ElementalStones by lennertsoffers.

the class PassiveHandler method shockwave.

// EARTHBENDING STONE
/**
 * <b>Shockwave</b>
 * <p>
 *     Creates a shockwave around the player when he falls<br>
 *     Activates when the player should normally get fall damage (no fall damage is taken)<br>
 *     This wave knocks up entities<br>
 *     The size and the knockup height depends on the fall distance of the player<br>
 *     <ul>
 *         <li><b>PotionEffect:</b> Slowness (duration: 2s, amplifier: 1)</li>
 *     </ul>
 * </p>
 *
 * @param activePlayer the activeplayer for whom this move is executed
 * @param event the EntityDamageEvent from the event listener
 */
public static void shockwave(ActivePlayer activePlayer, EntityDamageEvent event) {
    Player player = activePlayer.getPlayer();
    if (!Collections.disjoint(Arrays.asList(player.getInventory().getContents()), ItemStones.earthBendingStones)) {
        World world = player.getWorld();
        float fallDistance;
        if (player.getFallDistance() < 20) {
            fallDistance = player.getFallDistance();
        } else {
            fallDistance = 20;
        }
        List<PotionEffect> potionEffects = new ArrayList<>();
        potionEffects.add(new PotionEffect(PotionEffectType.SLOW, 40, 1, false, false, false));
        Vector velocity = new Vector(0, 0.2, 0);
        event.setCancelled(true);
        List<Block> rings = new ArrayList<>();
        new BukkitRunnable() {

            int range = 2;

            @Override
            public void run() {
                for (int i = 0; i < 360; i += 1) {
                    Location locationOnCircle = CheckLocationTools.getClosestAirBlockLocation(MathTools.locationOnCircle(player.getLocation(), range, i, world));
                    if (locationOnCircle != null) {
                        locationOnCircle.add(0, -1, 0);
                        Block block = world.getBlockAt(locationOnCircle);
                        if (rings.stream().noneMatch(b -> b.getX() == block.getX() && b.getZ() == block.getZ())) {
                            rings.add(block);
                            BlockData blockData = block.getBlockData();
                            block.setType(Material.AIR);
                            FallingBlock fallingBlock = world.spawnFallingBlock(block.getLocation().add(0.5, 0, 0.5), blockData);
                            fallingBlock.setDropItem(true);
                            fallingBlock.setVelocity(velocity);
                            double amountY = (fallDistance - range - 2) / 10;
                            if (amountY < 0.4) {
                                amountY = 0.4;
                            }
                            NearbyEntityTools.damageNearbyEntities(player, block.getLocation(), 0, 1, 2, 1, new Vector(0, amountY, 0), potionEffects);
                        }
                    }
                }
                range++;
                if (range > fallDistance - 2) {
                    this.cancel();
                }
            }
        }.runTaskTimer(StaticVariables.plugin, 0L, 1L);
    }
}
Also used : ItemFlag(org.bukkit.inventory.ItemFlag) ItemStones(com.lennertsoffers.elementalstones.items.ItemStones) Arrays(java.util.Arrays) Enchantment(org.bukkit.enchantments.Enchantment) ItemMeta(org.bukkit.inventory.meta.ItemMeta) org.bukkit(org.bukkit) ArrayList(java.util.ArrayList) Block(org.bukkit.block.Block) FireworkTools(com.lennertsoffers.elementalstones.customClasses.tools.FireworkTools) CheckLocationTools(com.lennertsoffers.elementalstones.customClasses.tools.CheckLocationTools) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) org.bukkit.entity(org.bukkit.entity) NearbyEntityTools(com.lennertsoffers.elementalstones.customClasses.tools.NearbyEntityTools) BlockData(org.bukkit.block.data.BlockData) MathTools(com.lennertsoffers.elementalstones.customClasses.tools.MathTools) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) PlayerToggleFlightEvent(org.bukkit.event.player.PlayerToggleFlightEvent) ItemStack(org.bukkit.inventory.ItemStack) PotionEffect(org.bukkit.potion.PotionEffect) Vector(org.bukkit.util.Vector) List(java.util.List) StaticVariables(com.lennertsoffers.elementalstones.customClasses.StaticVariables) ActivePlayer(com.lennertsoffers.elementalstones.customClasses.models.mechanics.ActivePlayer) EntityExplodeEvent(org.bukkit.event.entity.EntityExplodeEvent) Collections(java.util.Collections) PotionEffectType(org.bukkit.potion.PotionEffectType) WordUtils(org.apache.commons.lang.WordUtils) ActivePlayer(com.lennertsoffers.elementalstones.customClasses.models.mechanics.ActivePlayer) PotionEffect(org.bukkit.potion.PotionEffect) ArrayList(java.util.ArrayList) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Block(org.bukkit.block.Block) BlockData(org.bukkit.block.data.BlockData) Vector(org.bukkit.util.Vector)

Example 38 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project CombatLogX by SirBlobman.

the class ListenerLootProtection method checkVoidKill.

private boolean checkVoidKill(EntityDeathEvent e) {
    LivingEntity entity = e.getEntity();
    EntityDamageEvent lastDamageEvent = entity.getLastDamageCause();
    if (lastDamageEvent == null) {
        return false;
    }
    DamageCause lastDamageCause = lastDamageEvent.getCause();
    if (lastDamageCause != DamageCause.VOID) {
        return false;
    }
    ConfigurationManager configurationManager = getExpansionConfigurationManager();
    YamlConfiguration configuration = configurationManager.get("config.yml");
    if (configuration.getBoolean("return-void-items", true)) {
        UUID entityId = entity.getUniqueId();
        UUID enemyId = this.enemyMap.get(entityId);
        if (enemyId == null) {
            return true;
        }
        Entity enemy = Bukkit.getEntity(enemyId);
        if (!(enemy instanceof Player)) {
            return true;
        }
        Player enemyPlayer = (Player) enemy;
        World enemyWorld = enemy.getWorld();
        Location enemyLocation = enemy.getLocation();
        List<ItemStack> dropList = e.getDrops();
        ItemStack[] dropArray = dropList.toArray(new ItemStack[0]);
        PlayerInventory enemyInventory = enemyPlayer.getInventory();
        Map<Integer, ItemStack> leftoverDrops = enemyInventory.addItem(dropArray);
        leftoverDrops.forEach((slot, drop) -> enemyWorld.dropItem(enemyLocation, drop, itemEntity -> {
            ProtectedItem protectedItem = new ProtectedItem(enemyLocation, drop);
            protectedItem.setItemUUID(itemEntity.getUniqueId());
            protectedItem.setOwnerUUID(enemyId);
            this.protectedItemMap.put(protectedItem.getItemUUID(), protectedItem);
        }));
        dropList.clear();
        return true;
    }
    return false;
}
Also used : PlayerDataManager(com.github.sirblobman.api.configuration.PlayerDataManager) InventoryPickupItemEvent(org.bukkit.event.inventory.InventoryPickupItemEvent) Item(org.bukkit.entity.Item) WorldXYZ(com.github.sirblobman.api.object.WorldXYZ) ConfigurationManager(com.github.sirblobman.api.configuration.ConfigurationManager) ExpansionListener(com.github.sirblobman.combatlogx.api.expansion.ExpansionListener) ItemSpawnEvent(org.bukkit.event.entity.ItemSpawnEvent) Player(org.bukkit.entity.Player) EntityPickupItemEvent(org.bukkit.event.entity.EntityPickupItemEvent) EventHandler(org.bukkit.event.EventHandler) EntityDeathEvent(org.bukkit.event.entity.EntityDeathEvent) IDeathListener(com.github.sirblobman.combatlogx.api.listener.IDeathListener) QueryPickupEvent(combatlogx.expansion.loot.protection.event.QueryPickupEvent) Location(org.bukkit.Location) Replacer(com.github.sirblobman.api.language.Replacer) World(org.bukkit.World) Map(java.util.Map) PlayerInventory(org.bukkit.inventory.PlayerInventory) ProtectedItem(combatlogx.expansion.loot.protection.object.ProtectedItem) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Bukkit(org.bukkit.Bukkit) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) PlayerPunishEvent(com.github.sirblobman.combatlogx.api.event.PlayerPunishEvent) Entity(org.bukkit.entity.Entity) PlayerUntagEvent(com.github.sirblobman.combatlogx.api.event.PlayerUntagEvent) ExpiringMap(net.jodah.expiringmap.ExpiringMap) Set(java.util.Set) UUID(java.util.UUID) LivingEntity(org.bukkit.entity.LivingEntity) Expansion(com.github.sirblobman.combatlogx.api.expansion.Expansion) ICombatLogX(com.github.sirblobman.combatlogx.api.ICombatLogX) ItemStack(org.bukkit.inventory.ItemStack) TimeUnit(java.util.concurrent.TimeUnit) UntagReason(com.github.sirblobman.combatlogx.api.object.UntagReason) List(java.util.List) EventPriority(org.bukkit.event.EventPriority) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) Collections(java.util.Collections) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) ProtectedItem(combatlogx.expansion.loot.protection.object.ProtectedItem) PlayerInventory(org.bukkit.inventory.PlayerInventory) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) World(org.bukkit.World) LivingEntity(org.bukkit.entity.LivingEntity) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) UUID(java.util.UUID) ItemStack(org.bukkit.inventory.ItemStack) ConfigurationManager(com.github.sirblobman.api.configuration.ConfigurationManager) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) Location(org.bukkit.Location)

Example 39 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project Denizen by DenizenScript.

the class EntityHelperImpl method damage.

@Override
public void damage(LivingEntity target, float amount, Entity source, EntityDamageEvent.DamageCause cause) {
    if (target == null) {
        return;
    }
    net.minecraft.world.entity.LivingEntity nmsTarget = ((CraftLivingEntity) target).getHandle();
    net.minecraft.world.entity.Entity nmsSource = source == null ? null : ((CraftEntity) source).getHandle();
    CraftEventFactory.entityDamage = nmsSource;
    try {
        DamageSource src = getSourceFor(nmsSource, cause);
        if (src instanceof FakeDamageSrc) {
            src = ((FakeDamageSrc) src).real;
            EntityDamageEvent ede = fireFakeDamageEvent(target, source, cause, amount);
            if (ede.isCancelled()) {
                return;
            }
        }
        nmsTarget.hurt(src, amount);
    } finally {
        CraftEventFactory.entityDamage = null;
    }
}
Also used : DamageSource(net.minecraft.world.damagesource.DamageSource) org.bukkit.entity(org.bukkit.entity) net.minecraft.world.entity(net.minecraft.world.entity) org.bukkit.craftbukkit.v1_19_R1.entity(org.bukkit.craftbukkit.v1_19_R1.entity) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 40 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project Denizen by DenizenScript.

the class EntityDeathScriptEvent method onEntityDeath.

@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
    LivingEntity livingEntity = event.getEntity();
    EntityTag.rememberEntity(livingEntity);
    entity = new EntityTag(livingEntity);
    cause = null;
    damager = null;
    EntityDamageEvent lastDamage = entity.getBukkitEntity().getLastDamageCause();
    if (lastDamage != null) {
        cause = new ElementTag(event.getEntity().getLastDamageCause().getCause().toString());
        if (lastDamage instanceof EntityDamageByEntityEvent) {
            EntityTag damageEntity = new EntityTag(((EntityDamageByEntityEvent) lastDamage).getDamager());
            EntityTag shooter = damageEntity.getShooter();
            if (shooter != null) {
                damager = shooter;
            } else {
                damager = damageEntity;
            }
        } else if (livingEntity.getKiller() != null) {
            damager = new EntityTag(livingEntity.getKiller());
        }
    }
    cancelled = false;
    this.event = event;
    fire(event);
    EntityTag.forgetEntity(livingEntity);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) EntityDamageByEntityEvent(org.bukkit.event.entity.EntityDamageByEntityEvent) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) EventHandler(org.bukkit.event.EventHandler)

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