Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public void onPlayerInteract(PlayerInteractEvent event){
- Block tobreak = event.getClickedBlock(); //get the block the player interacted with
- if (event.getAction() == Action.LEFT_CLICK_BLOCK) {
- boolean breakblock = false; //sets whether or not to break the block
- if (tobreak != null) {
- //Place the block types as the format below
- if (tobreak.getType() == Material.BEDROCK) breakblock = true;
- }
- if (breakblock) {
- ItemStack item = event.getItem();
- if (item != null) {
- item.setDurability((short) (item.getDurability() - 10));
- }
- Player p = event.getPlayer();
- World w = p.getWorld();
- //Generate the itemstack to drop
- ItemStack tospawn = new ItemStack(tobreak.getType(), 1);
- //Set the clicked block to air (0)
- tobreak.setTypeId(0);
- //Drop the item
- w.dropItemNaturally(tobreak.getLocation(), tospawn);
- }
- }
- }
Add Comment
Please, Sign In to add comment