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()));
}
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);
}
}
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;
}
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;
}
}
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);
}
Aggregations