Commits

Scetra authored and md_5 committed c62b9cd3e2c
Add support for preventing block drops in BreakEvent
No tags

src/main/java/org/bukkit/event/block/BlockBreakEvent.java

Modified
21 21 * Note:
22 22 * Plugins wanting to simulate a traditional block drop should set the block
23 23 * to air and utilize their own methods for determining what the default drop
24 24 * for the block being broken is and what to do about it, if anything.
25 25 * <p>
26 26 * If a Block Break event is cancelled, the block will not break and
27 27 * experience will not drop.
28 28 */
29 29 public class BlockBreakEvent extends BlockExpEvent implements Cancellable {
30 30 private final Player player;
31 + private boolean dropItems;
31 32 private boolean cancel;
32 33
33 34 public BlockBreakEvent(final Block theBlock, final Player player) {
34 35 super(theBlock, 0);
35 36
36 37 this.player = player;
38 + this.dropItems = true; // Defaults to dropping items as it normally would
37 39 }
38 40
39 41 /**
40 42 * Gets the Player that is breaking the block involved in this event.
41 43 *
42 44 * @return The Player that is breaking the block involved in this event
43 45 */
44 46 public Player getPlayer() {
45 47 return player;
46 48 }
47 49
50 + /**
51 + * Sets whether or not the block will drop items as it normally would.
52 + *
53 + * @param dropItems Whether or not the block will drop items
54 + */
55 + public void setDropItems(boolean dropItems) {
56 + this.dropItems = dropItems;
57 + }
58 +
59 + /**
60 + * Gets whether or not the block will drop items.
61 + *
62 + * @return Whether or not the block will drop items
63 + */
64 + public boolean isDropItems() {
65 + return this.dropItems;
66 + }
67 +
48 68 public boolean isCancelled() {
49 69 return cancel;
50 70 }
51 71
52 72 public void setCancelled(boolean cancel) {
53 73 this.cancel = cancel;
54 74 }
55 75 }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut