SHARE
TWEET

Untitled

a guest Aug 13th, 2017 38 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package me.Ghappy.CastMine;
  2. import java.util.Random;
  3.  
  4. import java.util.ArrayList;
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.Location;
  7. import org.bukkit.Material;
  8. import org.bukkit.block.Block;
  9. import org.bukkit.block.BlockFace;
  10. import org.bukkit.entity.Player;
  11. import org.bukkit.event.block.BlockBreakEvent;
  12. import org.bukkit.event.block.BlockDamageEvent;
  13. import org.bukkit.event.block.BlockListener;
  14. import org.bukkit.inventory.ItemStack;
  15. import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
  16. import net.minecraft.server.Item;
  17. import org.bukkit.material.MaterialData;
  18.  
  19. class CMBlockListener extends BlockListener{
  20. public static CastMine plugin;
  21. public ArrayList<Block> vein = new ArrayList<Block>();
  22. public int intMaxSize = 12;
  23. BlockFace[] faces = {BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST, BlockFace.UP, BlockFace.NORTH_EAST, BlockFace.NORTH_WEST, BlockFace.SOUTH_EAST, BlockFace.SOUTH_WEST};
  24. public CMBlockListener(CastMine instance) {
  25.         plugin = instance;
  26.     }
  27.     @Override
  28.     public void onBlockDamage(BlockDamageEvent event){
  29.         Block theBlock = event.getBlock();
  30.         Player sender = event.getPlayer();
  31.         if(plugin.worldguard.canBuild(sender, (int)theBlock.getLocation().getX(), (int)theBlock.getLocation().getY(), (int)theBlock.getLocation().getZ())){
  32.         if(!plugin.CMEnabled(sender)) return;
  33.         if(sender.getItemInHand().getType() != (Material.GOLD_PICKAXE)){
  34.             sender.sendMessage(ChatColor.RED + "You need a Gold Pickaxe to do this");
  35.             plugin.ToggleCM(sender);
  36.             return;
  37.         }
  38.         if(!theBlock.getType().equals(Material.IRON_ORE) && !theBlock.getType().equals(Material.COAL_ORE) && !theBlock.getType().equals(Material.GOLD_ORE) && !theBlock.getType().equals(Material.DIAMOND_ORE) && !theBlock.getType().equals(Material.REDSTONE_ORE) && !theBlock.getType().equals(Material.getMaterial(74))){
  39.             sender.sendMessage(ChatColor.RED + "This is not a supported vein");
  40.             plugin.ToggleCM(sender);
  41.             return;
  42.         }
  43.         vein.add(theBlock);
  44.         for(int i = 0; i < faces.length; i++){
  45.             Block tmpBlock = theBlock.getFace(faces[i]);
  46.                 if(theBlock.getType().equals(Material.REDSTONE_ORE) || theBlock.getType().equals(Material.getMaterial(74))){
  47.                     if(tmpBlock.getTypeId() == 74 || tmpBlock.getTypeId() == 73){
  48.                         if(!vein.contains(tmpBlock)) vein.add(tmpBlock);
  49.                     }
  50.                 } else if(tmpBlock.getType().equals(theBlock.getType())){
  51.                     if(!vein.contains(tmpBlock)) vein.add(tmpBlock);
  52.                 }
  53.         }
  54.         if(vein.size() > 1){
  55.             for(int d = 0; d < vein.size(); d++){
  56.                 for(int i = 0; i < faces.length; i++){
  57.                     if(vein.size() > (intMaxSize - 1)) break;
  58.                     Block tmpBlock = vein.get(d).getFace(faces[i]);
  59.                     if(theBlock.getType().equals(Material.REDSTONE_ORE) || theBlock.getType().equals(Material.getMaterial(74))){
  60.                         if(tmpBlock.getTypeId() == 74 || tmpBlock.getTypeId() == 73){
  61.                             if(!vein.contains(tmpBlock)) vein.add(tmpBlock);
  62.                         }
  63.                     } else if(tmpBlock.getType().equals(theBlock.getType())){
  64.                         if(!vein.contains(tmpBlock)) vein.add(tmpBlock);
  65.                     }
  66.                 }
  67.             }
  68.         }
  69.         Material drop;
  70.         Random rand = new Random();
  71.         if(theBlock.getType() == Material.IRON_ORE){
  72.             intMaxSize = 12;
  73.             drop = Material.IRON_INGOT;
  74.         } else if(theBlock.getType() == Material.COAL_ORE){
  75.             intMaxSize = 22;
  76.             drop = Material.COAL;
  77.         } else if(theBlock.getType() == Material.GOLD_ORE){
  78.             intMaxSize = 12;
  79.             drop = Material.GOLD_INGOT;
  80.         } else if(theBlock.getType() == Material.REDSTONE_ORE || theBlock.getTypeId() == 74){
  81.             intMaxSize = 12;
  82.             drop = Material.REDSTONE;
  83.         } else if(theBlock.getType() == Material.DIAMOND_ORE){
  84.             intMaxSize = 12;
  85.             drop = Material.DIAMOND;
  86.         } else {
  87.             drop = Material.AIR;
  88.         }
  89.             for(int i = 0; i < vein.size(); i++){
  90.                 Block tmpBlock2 = vein.get(i);
  91.                 int iTmp = rand.nextInt(100);
  92.                 int amount = 1;
  93.                 if(theBlock.getType() == Material.DIAMOND_ORE){
  94.                     if(plugin.exc){
  95.                         if(iTmp < 30) amount = 2;
  96.                     } else amount = 1;
  97.                 } else if(tmpBlock2.getType() == Material.REDSTONE_ORE || tmpBlock2.getTypeId() == 74){
  98.                     if(iTmp < 30){
  99.                         amount = rand.nextInt(3) + 8;
  100.                     } else {
  101.                         amount = rand.nextInt(3) + 4;
  102.                     }
  103.                 } else {
  104.                     if(iTmp < 30){
  105.                         amount = 2;
  106.                     } else amount = 1;
  107.                 }
  108.                 tmpBlock2.setType(Material.AIR);
  109.                 for (int d = 0; d < amount; d++){
  110.                     tmpBlock2.getWorld().dropItem(tmpBlock2.getLocation(), new ItemStack(drop, 1));
  111.                 }
  112.                
  113.             }
  114.             sender.getItemInHand().setDurability((short)(sender.getItemInHand().getDurability() + 1));
  115.             if(sender.getItemInHand().getDurability() >= 33){
  116.                 event.getPlayer().setItemInHand(null);
  117.             }
  118.             vein.clear();
  119.             plugin.ToggleCM(sender);
  120.         } else {
  121.             sender.sendMessage(ChatColor.RED + "This area is protected");
  122.             if(plugin.CMEnabled(sender)){
  123.                 plugin.ToggleCM(sender);
  124.             }
  125.         }
  126.     }
  127. }
RAW Paste Data
Top