SHARE
TWEET

Untitled

a guest Apr 21st, 2017 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. COBBLESTONE:
  2. package me.drbooker.breakevent.listeners;
  3.  
  4. import org.bukkit.Material;
  5. import org.bukkit.block.Block;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.event.EventHandler;
  8. import org.bukkit.event.Listener;
  9. import org.bukkit.event.block.BlockBreakEvent;
  10. import org.bukkit.inventory.ItemStack;
  11.  
  12. public class BreakEventCobblestone implements Listener {
  13.    
  14.     ItemStack cobble = new ItemStack(Material.COBBLESTONE, 1);
  15.    
  16.     @EventHandler
  17.     public void onBreak(BlockBreakEvent event) {
  18.         Player p = event.getPlayer();
  19.         final Block blok = event.getBlock();
  20.         if(blok.getType() == Material.COBBLESTONE) {
  21.             if(p.getItemInHand() != null && p.getItemInHand().getType().toString().contains("PICKAXE")) {
  22.                 p.getInventory().addItem(cobble);
  23.                 event.getBlock().getDrops().clear();
  24.             }
  25.         }
  26.     }
  27. }
  28.  
  29. STONE:package me.drbooker.breakevent.listeners;
  30.  
  31. import org.bukkit.Material;
  32. import org.bukkit.block.Block;
  33. import org.bukkit.enchantments.Enchantment;
  34. import org.bukkit.entity.Player;
  35. import org.bukkit.event.EventHandler;
  36. import org.bukkit.event.Listener;
  37. import org.bukkit.event.block.BlockBreakEvent;
  38. import org.bukkit.inventory.ItemStack;
  39.  
  40. public class BreakEventStone implements Listener {
  41.    
  42.     ItemStack stone = new ItemStack(Material.STONE, 1);
  43.     ItemStack cobble = new ItemStack(Material.COBBLESTONE, 1);
  44.    
  45.     @EventHandler
  46.     public void onBreak(BlockBreakEvent event) {
  47.         Player p = event.getPlayer();
  48.         final Block blok = event.getBlock();
  49.         if(blok.getType() == Material.COBBLESTONE) {
  50.             if(p.getItemInHand() != null || p.getItemInHand().getType().toString().contains("PICKAXE") && p.getItemInHand().containsEnchantment(Enchantment.SILK_TOUCH)) {
  51.                 p.getInventory().addItem(stone);
  52.                 event.getBlock().getDrops().clear();
  53.             }
  54.             if(p.getItemInHand() != null || p.getItemInHand().getType().toString().contains("PICKAXE")) {
  55.                 p.getInventory().addItem(cobble);
  56.                 event.getBlock().getDrops().clear();
  57.             }
  58.         }
  59.     }
  60. }
  61.  
  62. MAIN:
  63. package me.drbooker.breakevent;
  64.  
  65. import org.bukkit.Bukkit;
  66. import org.bukkit.plugin.Plugin;
  67. import org.bukkit.plugin.PluginManager;
  68. import org.bukkit.plugin.java.JavaPlugin;
  69.  
  70. import me.drbooker.breakevent.listeners.BreakEventCobblestone;
  71. import me.drbooker.breakevent.listeners.BreakEventStone;
  72.  
  73. public class Main extends JavaPlugin {
  74.    
  75.     public static Plugin pl;
  76.    
  77.     @Override
  78.     public void onEnable() {
  79.         pl = this;
  80.         System.out.println("BookBreakEvent");
  81.         System.out.println("Author: Booker");
  82.         registerEvents();
  83.     }
  84.    
  85.     @Override
  86.     public void onDisable() {
  87.         pl = null;
  88.         System.out.println("BookBreakEvent");
  89.         System.out.println("Author: Booker");
  90.     }
  91.    
  92.     public static Plugin getInst() {
  93.         return pl;
  94.     }
  95.    
  96.     private void registerEvents() {
  97.         PluginManager pm = Bukkit.getPluginManager();
  98.         pm.registerEvents(new BreakEventCobblestone(), this);
  99.         pm.registerEvents(new BreakEventStone(), this);
  100.     }
  101. }
RAW Paste Data
Want to get better at Java?
Learn to code Java in 2017
Top