mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-08 11:24:11 +01:00
Add API for getting and setting experience for BlockBreakEvent. Addresses BUKKIT-2033
By: feildmaster <admin@feildmaster.com>
This commit is contained in:
parent
390a562680
commit
626c347565
1 changed files with 30 additions and 3 deletions
|
@ -8,22 +8,31 @@ import org.bukkit.event.HandlerList;
|
||||||
/**
|
/**
|
||||||
* Called when a block is broken by a player.
|
* Called when a block is broken by a player.
|
||||||
* <p />
|
* <p />
|
||||||
|
* If you wish to have the block drop experience, you must set the experience value above 0.
|
||||||
|
* By default, experience will be set in the event if:
|
||||||
|
* <ol>
|
||||||
|
* <li />The player is not in creative or adventure mode
|
||||||
|
* <li />The player can loot the block (ie: does not destroy it completely, by using the correct tool)
|
||||||
|
* <li />The player does not have silk touch
|
||||||
|
* <li />The block drops experience in vanilla MineCraft
|
||||||
|
* </ol>
|
||||||
|
* <p />
|
||||||
* Note:
|
* Note:
|
||||||
* Plugins wanting to simulate a traditional block drop should set the block to air and utilise their own methods for determining
|
* Plugins wanting to simulate a traditional block drop should set the block to air and utilize their own methods for determining
|
||||||
* what the default drop for the block being broken is and what to do about it, if anything.
|
* what the default drop for the block being broken is and what to do about it, if anything.
|
||||||
* <p />
|
* <p />
|
||||||
* If a Block Break event is cancelled, the block will not break.
|
* If a Block Break event is cancelled, the block will not break and experience will not drop.
|
||||||
*/
|
*/
|
||||||
public class BlockBreakEvent extends BlockEvent implements Cancellable {
|
public class BlockBreakEvent extends BlockEvent implements Cancellable {
|
||||||
|
|
||||||
private static final HandlerList handlers = new HandlerList();
|
private static final HandlerList handlers = new HandlerList();
|
||||||
private final Player player;
|
private final Player player;
|
||||||
private boolean cancel;
|
private boolean cancel;
|
||||||
|
private int exp;
|
||||||
|
|
||||||
public BlockBreakEvent(final Block theBlock, final Player player) {
|
public BlockBreakEvent(final Block theBlock, final Player player) {
|
||||||
super(theBlock);
|
super(theBlock);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.cancel = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,6 +44,24 @@ public class BlockBreakEvent extends BlockEvent implements Cancellable {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the experience to drop after the block is broken.
|
||||||
|
*
|
||||||
|
* @return The experience to drop
|
||||||
|
*/
|
||||||
|
public int getExpToDrop() {
|
||||||
|
return exp;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the amount of experience to drop after the block is broken.
|
||||||
|
*
|
||||||
|
* @param exp 1 or higher to drop experience, or else nothing will drop
|
||||||
|
*/
|
||||||
|
public void setExpToDrop(int exp) {
|
||||||
|
this.exp = exp;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isCancelled() {
|
public boolean isCancelled() {
|
||||||
return cancel;
|
return cancel;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue