Skip to content

Commit

Permalink
#13 feat: BlockBreakEvent and BlockDamageEvent now print the item in …
Browse files Browse the repository at this point in the history
…use to debug.
  • Loading branch information
Chafficui committed May 2, 2022
1 parent b669554 commit 3829b1e
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

Expand All @@ -37,7 +38,12 @@ public void onBlockDamage(final BlockDamageEvent event) {
miningPlayer.showMessage(LEVEL_NEEDED, ChatColor.RED, level.getName());
event.setCancelled(true);
} else {
if (isMiningItem(event.getItemInHand().getType())) {
ItemStack itemInUse = event.getPlayer().getItemInUse();
if(itemInUse == null) {
sendDebug(event.getPlayer(), "BlockDamageEvent: " + "Item in use is null.");
return;
}
if (isMiningItem(itemInUse.getType())) {
if (miningPlayer.getLevel().getHasteLevel() > 0) {
sendDebug(event.getPlayer(), "BlockDamageEvent: " + "Haste level: " + miningPlayer.getLevel().getHasteLevel());
event.getPlayer().addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 5 * 20, miningPlayer.getLevel().getHasteLevel()));
Expand All @@ -47,7 +53,7 @@ public void onBlockDamage(final BlockDamageEvent event) {
event.setInstaBreak(true); //Insta break
}
} else {
sendDebug(event.getPlayer(), "BlockDamageEvent: " + "The held item is not a mining item.");
sendDebug(event.getPlayer(), "BlockDamageEvent: " + "The held item " + itemInUse.getType() + " is not a mining item.");
}
}
} else {
Expand Down Expand Up @@ -85,8 +91,13 @@ public void onBlockBreak(final BlockBreakEvent event) {

miningPlayer.alterXp(block.getXp());
MiningLevel level = miningPlayer.getLevel();
if (event.getPlayer().getItemInUse() == null || !isMiningItem(event.getPlayer().getItemInUse().getType())) {
sendDebug(event.getPlayer(), "BlockBreakEvent: " + "The held item is not a mining item.");
ItemStack itemInUse = event.getPlayer().getItemInUse();
if(itemInUse == null) {
sendDebug(event.getPlayer(), "BlockBreakEvent: " + "Item in use is null.");
return;
}
if (event.getPlayer().getItemInUse() == null || !isMiningItem(itemInUse.getType())) {
sendDebug(event.getPlayer(), "BlockBreakEvent: " + "The held " + itemInUse.getType() + " item is not a mining item.");
return;
}

Expand Down

0 comments on commit 3829b1e

Please sign in to comment.