From 4595a700568f290f848e46a436cf4347343be6da Mon Sep 17 00:00:00 2001 From: Andrew Ardill Date: Tue, 29 Nov 2011 20:50:38 +1100 Subject: Extend EntityCombustEvent to allow setting combustion duration. Also extend with two new events that track the entity or block that caused the combustion. --- src/main/java/org/bukkit/entity/Projectile.java | 2 ++ .../event/entity/EntityCombustByBlockEvent.java | 24 +++++++++++++++++++++ .../event/entity/EntityCombustByEntityEvent.java | 21 ++++++++++++++++++ .../bukkit/event/entity/EntityCombustEvent.java | 25 +++++++++++++++++++--- .../org/bukkit/event/entity/EntityListener.java | 2 +- 5 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/bukkit/event/entity/EntityCombustByBlockEvent.java create mode 100644 src/main/java/org/bukkit/event/entity/EntityCombustByEntityEvent.java (limited to 'src') diff --git a/src/main/java/org/bukkit/entity/Projectile.java b/src/main/java/org/bukkit/entity/Projectile.java index 95aae5f9..c8212540 100644 --- a/src/main/java/org/bukkit/entity/Projectile.java +++ b/src/main/java/org/bukkit/entity/Projectile.java @@ -25,6 +25,8 @@ public interface Projectile extends Entity { /** * Determine if this projectile should bounce or not when it hits. * + * If a small fireball does not bounce it will set the target on fire. + * * @return true if it should bounce. */ public boolean doesBounce(); diff --git a/src/main/java/org/bukkit/event/entity/EntityCombustByBlockEvent.java b/src/main/java/org/bukkit/event/entity/EntityCombustByBlockEvent.java new file mode 100644 index 00000000..addb42fd --- /dev/null +++ b/src/main/java/org/bukkit/event/entity/EntityCombustByBlockEvent.java @@ -0,0 +1,24 @@ +package org.bukkit.event.entity; + +import org.bukkit.block.Block; +import org.bukkit.entity.Entity; + +public class EntityCombustByBlockEvent extends EntityCombustEvent { + + private Block combuster; + + public EntityCombustByBlockEvent(Block combuster, Entity combustee, int duration) { + super(combustee, duration); + this.combuster = combuster; + } + + /** + * The combuster can be lava or a block that is on fire. + * + * WARNING: block may be null. + * @return the Block that set the combustee alight. + */ + public Block getCombuster() { + return combuster; + } +} diff --git a/src/main/java/org/bukkit/event/entity/EntityCombustByEntityEvent.java b/src/main/java/org/bukkit/event/entity/EntityCombustByEntityEvent.java new file mode 100644 index 00000000..15ab75f1 --- /dev/null +++ b/src/main/java/org/bukkit/event/entity/EntityCombustByEntityEvent.java @@ -0,0 +1,21 @@ +package org.bukkit.event.entity; + +import org.bukkit.entity.Entity; + +public class EntityCombustByEntityEvent extends EntityCombustEvent { + + private Entity combuster; + + public EntityCombustByEntityEvent(Entity combuster, Entity combustee, int duration) { + super(combustee, duration); + this.combuster = combuster; + } + + /** + * The combuster can be a WeatherStorm a Blaze, or an Entity holding a FIRE_ASPECT enchanted item. + * @return the Entity that set the combustee alight. + */ + public Entity getCombuster() { + return combuster; + } +} diff --git a/src/main/java/org/bukkit/event/entity/EntityCombustEvent.java b/src/main/java/org/bukkit/event/entity/EntityCombustEvent.java index 0587576e..9b3f38f3 100644 --- a/src/main/java/org/bukkit/event/entity/EntityCombustEvent.java +++ b/src/main/java/org/bukkit/event/entity/EntityCombustEvent.java @@ -4,15 +4,17 @@ import org.bukkit.entity.Entity; import org.bukkit.event.Cancellable; /** - * Called when an entity combusts due to the sun. + * Called when an entity combusts. *

* If an Entity Combust event is cancelled, the entity will not combust. */ public class EntityCombustEvent extends EntityEvent implements Cancellable { + private int duration; private boolean cancel; - public EntityCombustEvent(Entity what) { - super(Type.ENTITY_COMBUST, what); + public EntityCombustEvent(Entity combustee, int duration) { + super(Type.ENTITY_COMBUST, combustee); + this.duration = duration; this.cancel = false; } @@ -23,4 +25,21 @@ public class EntityCombustEvent extends EntityEvent implements Cancellable { public void setCancelled(boolean cancel) { this.cancel = cancel; } + + /** + * @return the amount of time (in seconds) the combustee should be alight for + */ + public int getDuration() { + return duration; + } + + /** + * The number of seconds the combustee should be alight for. + * + * This value will only ever increase the combustion time, not decrease existing combustion times. + * @param duration the time in seconds to be alight for. + */ + public void setDuration(int duration) { + this.duration = duration; + } } diff --git a/src/main/java/org/bukkit/event/entity/EntityListener.java b/src/main/java/org/bukkit/event/entity/EntityListener.java index c325cb37..3e8db64e 100644 --- a/src/main/java/org/bukkit/event/entity/EntityListener.java +++ b/src/main/java/org/bukkit/event/entity/EntityListener.java @@ -27,7 +27,7 @@ public class EntityListener implements Listener { public void onItemSpawn(ItemSpawnEvent event) {} /** - * Called when an entity combusts due to the sun. + * Called when an entity combusts. *

* If an Entity Combust event is cancelled, the entity will not combust. * -- cgit v1.2.3