Block has a method called getDrops(ItemStack) that gives the items that a block would drop if broken with the given item stack, is there anything like this for xp? Also, i'm having a problem because getDrops(ItemStack) doesn't seem to respect the enchantments of the tools, how can I fix it?
I think the only way is as Bjorno said. Use something like this... I don't know if it's a double or an integer, in doubt try both. I don't even know if it can be put in a method with a return, but you can try the same. Since I don't know what happens if the block doesn't drop experience. For security, add a check of not null Code (Java): @EventHandler public double breakEvent(BlockBreakEvent event){ return event.getExpToDrop(); }
Please don't comment on threads when you have no idea what you're doing. Event listeners do not work that way. Please learn about the api before giving code to other people.
To get this to a solution: You have to use NMS to get the exp below is an example code you should use Reflections to be version independent. Code (Text): Method getNMSBlockMethod = CraftBlock.class.getDeclaredMethod("getNMSBlock"); getNMSBlockMethod.setAccessible(true); net.minecraft.server.v1_8_R3.Block nmsBlock = (net.minecraft.server.v1_8_R3.Block) getNMSBlockMethod.invoke(block); int xp = nmsBlock.getExpDrop(((CraftWorld)block.getWorld()).getHandle(), nmsBlock.getBlockData(), bonusLevel); - 'block' is a normal bukkit Block. - 'bonusLevel' is the luck enchantment level of the pickaxe the breaker uses.