Hey I'm Currently working on BlockFortune Plugin which works perfectly fine other than item durability when mining a block that is naturally placed (player placed works fine) it shows the durability depleting but when I click on the item in the inventory or I drop it and pick it back up the pickaxe durability has not gone down I cannot seem to figure out why this is the class where I believe something is wrong Code: import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.inventory.ItemStack; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedRegion; public class BlockListener implements Listener { @EventHandler public void onBreak(BlockBreakEvent e) { @SuppressWarnings("unused") Player p = e.getPlayer(); Block b = e.getBlock(); WorldGuardPlugin wg = Main.getWG(); RegionManager regionManager = wg.getRegionManager(b.getWorld()); boolean inMine = false; for (ProtectedRegion region : regionManager.getApplicableRegions(b.getLocation())) { if (region.getId().contains("fortune")) { inMine = true; break; } } if (inMine) { if (e.isCancelled()) return; if (e.getPlayer().getGameMode() != GameMode.SURVIVAL) return; if (Main.getMain().wasPlaced(e.getBlock().getLocation())) return; Material mat = e.getBlock().getType(); if (!Main.containsMat(mat)) return; e.setCancelled(true); e.getBlock().setType(Material.AIR); e.getBlock().getLocation().getWorld().dropItemNaturally(e.getBlock().getLocation(), new ItemStack(mat, getBlocks(e.getPlayer().getItemInHand().getEnchantmentLevel(Enchantment.LOOT_BONUS_BLOCKS)))); e.getPlayer().getItemInHand().setDurability((short) (e.getPlayer().getItemInHand().getDurability() + 0.25)); } } @EventHandler public void onPlace(BlockPlaceEvent e) { Material mat = e.getBlock().getType(); if (!Main.containsMat(mat)) return; Main.getMain().addPlaced(e.getBlock().getLocation()); } private int getBlocks(Integer integer) { if ((integer.intValue() >= 10) && (integer.intValue() < 20)) { return 3; } if (integer.intValue() >= 20) { return (int)Math.floor((integer.intValue() - 10) / 10) + 2; } return 2; } }
Edit I Fixed It Seems Code: e.getBlock().setType(Material.AIR); was causing my problem not sure why thanks anyway
What is Code: e.getPlayer().getItemInHand().setDurability((short)(e.getPlayer().getItemInHand().getDurability()+0.25)); for?