Skip to content

Commit

Permalink
Limit durability in Break Item Event cancelling
Browse files Browse the repository at this point in the history
Without this, durability (usage count) just keeps rising until it throws
an error... this will keep it where it's supposed to be.
  • Loading branch information
mcmonkey4eva committed Dec 27, 2013
1 parent c03da0e commit ad3c037
Showing 1 changed file with 4 additions and 2 deletions.
Expand Up @@ -3068,7 +3068,7 @@ else if (dScript.matches(determination)) {
// <context.item> returns the item that broke.
//
// @Determine
// "CANCELLED" to prevent the item from breaking.
// "CANCELLED" to prevent the item from breaking, restoring it with one usage left.
// -->
@EventHandler
public void playerBreakItem(PlayerItemBreakEvent event) {
Expand All @@ -3091,10 +3091,12 @@ public void playerBreakItem(PlayerItemBreakEvent event) {
// The event automatically resets durability to 0... instead,
// let's delay a tick and set it back to what it was before.
final short durability = itemstack.getDurability();
final Player player = event.getPlayer();
new BukkitRunnable() {
@Override
public void run() {
itemstack.setDurability(durability);
itemstack.setDurability(itemstack.getType().getMaxDurability());
player.updateInventory();
}
}.runTaskLater(DenizenAPI.getCurrentInstance(), 1);
}
Expand Down

0 comments on commit ad3c037

Please sign in to comment.