Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @EventHandler
- // Call this event when a block is broken.
- public void onBlockBreak(BlockBreakEvent e) {
- // Get the player.
- Player p = e.getPlayer();
- // A switch statement is basically a large if statement,
- // so the switch gets the type, and then "case DIAMOND_SWORD" means
- // "if (p.getItemInHand().getType().equals(Material.DIAMOND_SWORD)) {}".
- switch (p.getItemInHand().getType()) {
- // If it's a diamond sword then do stuff.
- case DIAMOND_SWORD:
- // Do that stuff here
- // Don't forget your break; so that it won't continue the in switch statement after it finds the correct one (or default at the bottom there).
- break;
- case IRON_SWORD:
- // Do stuff here if it's an iron sword, you can add as many cases as you'd like.
- break;
- // The "default" is what happens if none of the above cases are correct,
- // so if they broke a block and were holding sponge you want to put what you want to happen here.
- // In this case it just breaks out and does nothing.
- default:
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement