mirror of
https://github.com/BentoBoxWorld/AcidIsland.git
synced 2024-11-25 20:25:37 +01:00
Fixes #150 EntityDamageByAcidEvent should be cancellable
This commit is contained in:
parent
1058b5fbc1
commit
e32e0df220
@ -1,21 +1,23 @@
|
||||
package world.bentobox.acidisland.events;
|
||||
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* Fired when an entity (items excluded) receives damage from acid
|
||||
* @author Poslovitch
|
||||
* @author Poslovitch, tastybento
|
||||
* @since 1.0
|
||||
*/
|
||||
public class EntityDamageByAcidEvent extends Event {
|
||||
public class EntityDamageByAcidEvent extends Event implements Cancellable {
|
||||
|
||||
private final Entity entity;
|
||||
private double damage;
|
||||
|
||||
public enum Acid { RAIN, WATER }
|
||||
private final Acid cause;
|
||||
private boolean cancelled;
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
@Override
|
||||
@ -64,4 +66,15 @@ public class EntityDamageByAcidEvent extends Event {
|
||||
public Acid getCause() {
|
||||
return cause;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -187,11 +187,13 @@ public class AcidEffect implements Listener {
|
||||
.addPotionEffect(new PotionEffect(t, addon.getSettings().getRainEffectDuation() * 20, 1)));
|
||||
// Apply damage if there is any
|
||||
if (event.getRainDamage() > 0D) {
|
||||
player.damage(event.getRainDamage());
|
||||
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
|
||||
EntityDamageByAcidEvent e = new EntityDamageByAcidEvent(player, event.getRainDamage(), Acid.RAIN);
|
||||
// Fire event
|
||||
Bukkit.getPluginManager().callEvent(e);
|
||||
if (!e.isCancelled()) {
|
||||
player.damage(event.getRainDamage());
|
||||
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -212,11 +214,13 @@ public class AcidEffect implements Listener {
|
||||
.addPotionEffect(new PotionEffect(t, addon.getSettings().getAcidEffectDuation() * 20, 1)));
|
||||
// Apply damage if there is any
|
||||
if (event.getTotalDamage() > 0D) {
|
||||
player.damage(event.getTotalDamage());
|
||||
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
|
||||
EntityDamageByAcidEvent e = new EntityDamageByAcidEvent(player, event.getTotalDamage(), Acid.WATER);
|
||||
// Fire event
|
||||
Bukkit.getPluginManager().callEvent(e);
|
||||
if (!e.isCancelled()) {
|
||||
player.damage(event.getTotalDamage());
|
||||
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_CREEPER_PRIMED, 3F, 3F);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,10 +86,12 @@ public class AcidTask {
|
||||
void applyDamage(Entity e, long damage) {
|
||||
if (e instanceof LivingEntity) {
|
||||
double actualDamage = Math.max(0, damage - damage * AcidEffect.getDamageReduced((LivingEntity)e));
|
||||
((LivingEntity)e).damage(actualDamage);
|
||||
EntityDamageByAcidEvent event = new EntityDamageByAcidEvent(e, actualDamage, Acid.WATER);
|
||||
// Fire event
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
((LivingEntity)e).damage(actualDamage);
|
||||
}
|
||||
} else if (addon.getSettings().getAcidDestroyItemTime() > 0 && e instanceof Item){
|
||||
// Item
|
||||
if (e.getLocation().getBlock().getType().equals(Material.WATER)) {
|
||||
|
Loading…
Reference in New Issue
Block a user