Advertisement
Guest User

Event Example by Ocean

a guest
Sep 12th, 2015
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.06 KB | None | 0 0
  1.     @EventHandler
  2.     // Call this event when a block is broken.
  3.     public void onBlockBreak(BlockBreakEvent e) {
  4.        
  5.         // Get the player.
  6.         Player p = e.getPlayer();
  7.        
  8.         // A switch statement is basically a large if statement,
  9.         // so the switch gets the type, and then "case DIAMOND_SWORD" means
  10.         // "if (p.getItemInHand().getType().equals(Material.DIAMOND_SWORD)) {}".
  11.        
  12.         switch (p.getItemInHand().getType())  {
  13.         //  If it's a diamond sword then do stuff.
  14.             case DIAMOND_SWORD:
  15.                 // Do  that stuff here
  16.                
  17.                 // 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).
  18.                 break;
  19.            
  20.             case IRON_SWORD:
  21.                 // Do stuff here if it's an iron sword, you can add as many cases as you'd like.
  22.                 break;
  23.                
  24.                 // The "default" is what happens if none of the above cases are correct,
  25.                 // so if they broke a block and were holding sponge you want to put what you want to happen here.
  26.                 // In this case it just breaks out and does nothing.
  27.             default:
  28.                 break;
  29.         }
  30.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement