From 066ccf6062f47c04ed751df29160aa240612a511 Mon Sep 17 00:00:00 2001 From: Celtic Minstrel Date: Sun, 14 Aug 2011 22:34:13 -0400 Subject: [Bleeding] Added getting and setting drops to all appropriate events. Fixes BUKKIT-397 and fixes BUKKIT-1252 --- .../java/org/bukkit/event/block/BlockBreakEvent.java | 17 ++++++++++++++++- .../java/org/bukkit/event/entity/EntityDeathEvent.java | 3 ++- .../event/painting/PaintingBreakByEntityEvent.java | 7 +++++-- .../org/bukkit/event/painting/PaintingBreakEvent.java | 15 ++++++++++++++- .../org/bukkit/event/player/PlayerShearEntityEvent.java | 16 +++++++++++++++- .../org/bukkit/event/vehicle/VehicleDestroyEvent.java | 17 ++++++++++++++++- 6 files changed, 68 insertions(+), 7 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/bukkit/event/block/BlockBreakEvent.java b/src/main/java/org/bukkit/event/block/BlockBreakEvent.java index 606957f4..413155bc 100644 --- a/src/main/java/org/bukkit/event/block/BlockBreakEvent.java +++ b/src/main/java/org/bukkit/event/block/BlockBreakEvent.java @@ -1,9 +1,12 @@ package org.bukkit.event.block; +import java.util.List; + import org.bukkit.block.Block; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; /** * Called when a block is broken by a player. @@ -19,11 +22,13 @@ public class BlockBreakEvent extends BlockEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private final Player player; private boolean cancel; + private List drops; - public BlockBreakEvent(final Block theBlock, final Player player) { + public BlockBreakEvent(final Block theBlock, final Player player, List drops) { super(theBlock); this.player = player; this.cancel = false; + this.drops = drops; } /** @@ -35,6 +40,16 @@ public class BlockBreakEvent extends BlockEvent implements Cancellable { return player; } + /** + * Gets a list of items that should drop from this block. Modifying this list will modify the items drop. + * If the block is a container, the contents of the container will not be included in this list. You can + * get the contents of the container by casting the block's state. + * @return A list of drops + */ + public List getDrops() { + return drops; + } + public boolean isCancelled() { return cancel; } diff --git a/src/main/java/org/bukkit/event/entity/EntityDeathEvent.java b/src/main/java/org/bukkit/event/entity/EntityDeathEvent.java index d39596f6..9e7a622f 100644 --- a/src/main/java/org/bukkit/event/entity/EntityDeathEvent.java +++ b/src/main/java/org/bukkit/event/entity/EntityDeathEvent.java @@ -53,7 +53,8 @@ public class EntityDeathEvent extends EntityEvent { } /** - * Gets all the items which will drop when the entity dies + * Gets all the items which will drop when the entity dies. Modifying this list will + * modify what's actually dropped. * * @return Items to drop when the entity dies */ diff --git a/src/main/java/org/bukkit/event/painting/PaintingBreakByEntityEvent.java b/src/main/java/org/bukkit/event/painting/PaintingBreakByEntityEvent.java index d7f0bb16..6b594719 100644 --- a/src/main/java/org/bukkit/event/painting/PaintingBreakByEntityEvent.java +++ b/src/main/java/org/bukkit/event/painting/PaintingBreakByEntityEvent.java @@ -1,7 +1,10 @@ package org.bukkit.event.painting; +import java.util.List; + import org.bukkit.entity.Entity; import org.bukkit.entity.Painting; +import org.bukkit.inventory.ItemStack; /** * Triggered when a painting is removed by an entity @@ -9,8 +12,8 @@ import org.bukkit.entity.Painting; public class PaintingBreakByEntityEvent extends PaintingBreakEvent { private final Entity remover; - public PaintingBreakByEntityEvent(final Painting painting, final Entity remover) { - super(painting, RemoveCause.ENTITY); + public PaintingBreakByEntityEvent(final Painting painting, final Entity remover, List drops) { + super(painting, RemoveCause.ENTITY, drops); this.remover = remover; } diff --git a/src/main/java/org/bukkit/event/painting/PaintingBreakEvent.java b/src/main/java/org/bukkit/event/painting/PaintingBreakEvent.java index edf3559c..140846bd 100644 --- a/src/main/java/org/bukkit/event/painting/PaintingBreakEvent.java +++ b/src/main/java/org/bukkit/event/painting/PaintingBreakEvent.java @@ -1,8 +1,11 @@ package org.bukkit.event.painting; +import java.util.List; + import org.bukkit.entity.Painting; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; /** * Triggered when a painting is removed @@ -11,10 +14,12 @@ public class PaintingBreakEvent extends PaintingEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean cancelled; private final RemoveCause cause; + private List drops; - public PaintingBreakEvent(final Painting painting, final RemoveCause cause) { + public PaintingBreakEvent(final Painting painting, final RemoveCause cause, List drops) { super(painting); this.cause = cause; + this.drops = drops; } /** @@ -34,6 +39,14 @@ public class PaintingBreakEvent extends PaintingEvent implements Cancellable { this.cancelled = cancel; } + /** + * Gets the list of items to be dropped. Modifying this list will modify what's actually dropped. + * @return A list of drops + */ + public List getDrops() { + return drops; + } + /** * An enum to specify the cause of the removal */ diff --git a/src/main/java/org/bukkit/event/player/PlayerShearEntityEvent.java b/src/main/java/org/bukkit/event/player/PlayerShearEntityEvent.java index 38afb3ce..4fe6bb1a 100644 --- a/src/main/java/org/bukkit/event/player/PlayerShearEntityEvent.java +++ b/src/main/java/org/bukkit/event/player/PlayerShearEntityEvent.java @@ -1,9 +1,12 @@ package org.bukkit.event.player; +import java.util.List; + import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; /** * Called when a player shears an entity @@ -12,11 +15,13 @@ public class PlayerShearEntityEvent extends PlayerEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private boolean cancel; private final Entity what; + private final List items; - public PlayerShearEntityEvent(final Player who, final Entity what) { + public PlayerShearEntityEvent(final Player who, final Entity what, final List drops) { super(who); this.cancel = false; this.what = what; + this.items = drops; } public boolean isCancelled() { @@ -36,6 +41,15 @@ public class PlayerShearEntityEvent extends PlayerEvent implements Cancellable { return what; } + /** + * Get the items that will drop as a result of the shearing. To change the + * items dropped, change the contents of this list. + * @return The list of items. + */ + public List getDrops() { + return items; + } + @Override public HandlerList getHandlers() { return handlers; diff --git a/src/main/java/org/bukkit/event/vehicle/VehicleDestroyEvent.java b/src/main/java/org/bukkit/event/vehicle/VehicleDestroyEvent.java index 7a481d3a..3351a89c 100644 --- a/src/main/java/org/bukkit/event/vehicle/VehicleDestroyEvent.java +++ b/src/main/java/org/bukkit/event/vehicle/VehicleDestroyEvent.java @@ -1,9 +1,12 @@ package org.bukkit.event.vehicle; +import java.util.List; + import org.bukkit.entity.Entity; import org.bukkit.entity.Vehicle; import org.bukkit.event.Cancellable; import org.bukkit.event.HandlerList; +import org.bukkit.inventory.ItemStack; /** * Raised when a vehicle is destroyed, which could be caused by either a player @@ -14,10 +17,12 @@ public class VehicleDestroyEvent extends VehicleEvent implements Cancellable { private static final HandlerList handlers = new HandlerList(); private final Entity attacker; private boolean cancelled; + private List drops; - public VehicleDestroyEvent(final Vehicle vehicle, final Entity attacker) { + public VehicleDestroyEvent(final Vehicle vehicle, final Entity attacker, List drops) { super(vehicle); this.attacker = attacker; + this.drops = drops; } /** @@ -45,4 +50,14 @@ public class VehicleDestroyEvent extends VehicleEvent implements Cancellable { public static HandlerList getHandlerList() { return handlers; } + + /** + * Gets a list of drops that this vehicle should drop when broken. Changes to this list will + * affect what is actually dropped. This list does not include the contents of the inventory + * if this is a storage minecart; if that's needed, it can be fetched by casting. + * @return A list of drops + */ + public List getDrops() { + return drops; + } } -- cgit v1.2.3