use of org.bukkit.event.entity.EntityDamageEvent in project Denizen-For-Bukkit by DenizenScript.
the class HurtCommand method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
dEntity source = (dEntity) scriptEntry.getObject("source");
Element amountElement = scriptEntry.getElement("amount");
Element cause = scriptEntry.getElement("cause");
dB.report(scriptEntry, getName(), amountElement.debug() + aH.debugList("entities", entities) + (cause == null ? "" : cause.debug()) + (source == null ? "" : source.debug()));
double amount = amountElement.asDouble();
for (dEntity entity : entities) {
if (entity.getLivingEntity() == null) {
dB.echoDebug(scriptEntry, entity + " is not a living entity!");
continue;
}
if (cause == null) {
if (source == null) {
entity.getLivingEntity().damage(amount);
} else {
entity.getLivingEntity().damage(amount, source.getBukkitEntity());
}
} else {
EntityDamageEvent ede = source == null ? new EntityDamageEvent(entity.getBukkitEntity(), EntityDamageEvent.DamageCause.valueOf(cause.asString().toUpperCase()), amount) : new EntityDamageByEntityEvent(source.getBukkitEntity(), entity.getBukkitEntity(), EntityDamageEvent.DamageCause.valueOf(cause.asString().toUpperCase()), amount);
Bukkit.getPluginManager().callEvent(ede);
if (!ede.isCancelled()) {
if (source == null) {
entity.getLivingEntity().damage(ede.getFinalDamage());
} else {
entity.getLivingEntity().damage(ede.getFinalDamage(), source.getBukkitEntity());
}
}
}
}
}
use of org.bukkit.event.entity.EntityDamageEvent in project Essentials by drtshock.
the class Commandsuicide method run.
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
EntityDamageEvent ede = new EntityDamageEvent(user.getBase(), EntityDamageEvent.DamageCause.SUICIDE, Short.MAX_VALUE);
server.getPluginManager().callEvent(ede);
ede.getEntity().setLastDamageCause(ede);
user.getBase().damage(Short.MAX_VALUE);
if (user.getBase().getHealth() > 0) {
user.getBase().setHealth(0);
}
user.sendMessage(tl("suicideMessage"));
user.setDisplayNick();
ess.broadcastMessage(user, tl("suicideSuccess", user.getDisplayName()));
}
use of org.bukkit.event.entity.EntityDamageEvent in project Essentials by drtshock.
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, Short.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.damage(Short.MAX_VALUE);
if (matchPlayer.getHealth() > 0) {
matchPlayer.setHealth(0);
}
sender.sendMessage(tl("kill", matchPlayer.getDisplayName()));
}
use of org.bukkit.event.entity.EntityDamageEvent in project NoCheatPlus by NoCheatPlus.
the class NoFall method dealFallDamage.
private void dealFallDamage(final Player player, final double damage) {
if (mcAccess.getHandle().dealFallDamageFiresAnEvent().decide()) {
// TODO: Better decideOptimistically?
mcAccess.getHandle().dealFallDamage(player, damage);
} else {
final EntityDamageEvent event = BridgeHealth.getEntityDamageEvent(player, DamageCause.FALL, damage);
Bukkit.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
// TODO: account for no damage ticks etc.
player.setLastDamageCause(event);
mcAccess.getHandle().dealFallDamage(player, BridgeHealth.getRawDamage(event));
}
}
// Currently resetting is done from within the damage event handler.
// TODO: MUST detect if event fired at all (...) and override, if necessary. Best probe once per class (with YES).
// data.clearNoFallData();
player.setFallDistance(0);
}
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, Short.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.damage(Short.MAX_VALUE);
if (matchPlayer.getHealth() > 0) {
matchPlayer.setHealth(0);
}
sender.sendMessage(tl("kill", matchPlayer.getDisplayName()));
}
Aggregations