Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.Ghappy.CastMine;
- import java.util.Random;
- import java.util.ArrayList;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.block.Block;
- import org.bukkit.block.BlockFace;
- import org.bukkit.entity.Player;
- import org.bukkit.event.block.BlockBreakEvent;
- import org.bukkit.event.block.BlockDamageEvent;
- import org.bukkit.event.block.BlockListener;
- import org.bukkit.inventory.ItemStack;
- import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
- import net.minecraft.server.Item;
- import org.bukkit.material.MaterialData;
- class CMBlockListener extends BlockListener{
- public static CastMine plugin;
- public ArrayList<Block> vein = new ArrayList<Block>();
- public int intMaxSize = 12;
- 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};
- public CMBlockListener(CastMine instance) {
- plugin = instance;
- }
- @Override
- public void onBlockDamage(BlockDamageEvent event){
- Block theBlock = event.getBlock();
- Player sender = event.getPlayer();
- if(plugin.worldguard.canBuild(sender, (int)theBlock.getLocation().getX(), (int)theBlock.getLocation().getY(), (int)theBlock.getLocation().getZ())){
- if(!plugin.CMEnabled(sender)) return;
- if(sender.getItemInHand().getType() != (Material.GOLD_PICKAXE)){
- sender.sendMessage(ChatColor.RED + "You need a Gold Pickaxe to do this");
- plugin.ToggleCM(sender);
- return;
- }
- 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))){
- sender.sendMessage(ChatColor.RED + "This is not a supported vein");
- plugin.ToggleCM(sender);
- return;
- }
- vein.add(theBlock);
- for(int i = 0; i < faces.length; i++){
- Block tmpBlock = theBlock.getFace(faces[i]);
- if(theBlock.getType().equals(Material.REDSTONE_ORE) || theBlock.getType().equals(Material.getMaterial(74))){
- if(tmpBlock.getTypeId() == 74 || tmpBlock.getTypeId() == 73){
- if(!vein.contains(tmpBlock)) vein.add(tmpBlock);
- }
- } else if(tmpBlock.getType().equals(theBlock.getType())){
- if(!vein.contains(tmpBlock)) vein.add(tmpBlock);
- }
- }
- if(vein.size() > 1){
- for(int d = 0; d < vein.size(); d++){
- for(int i = 0; i < faces.length; i++){
- if(vein.size() > (intMaxSize - 1)) break;
- Block tmpBlock = vein.get(d).getFace(faces[i]);
- if(theBlock.getType().equals(Material.REDSTONE_ORE) || theBlock.getType().equals(Material.getMaterial(74))){
- if(tmpBlock.getTypeId() == 74 || tmpBlock.getTypeId() == 73){
- if(!vein.contains(tmpBlock)) vein.add(tmpBlock);
- }
- } else if(tmpBlock.getType().equals(theBlock.getType())){
- if(!vein.contains(tmpBlock)) vein.add(tmpBlock);
- }
- }
- }
- }
- Material drop;
- Random rand = new Random();
- if(theBlock.getType() == Material.IRON_ORE){
- intMaxSize = 12;
- drop = Material.IRON_INGOT;
- } else if(theBlock.getType() == Material.COAL_ORE){
- intMaxSize = 22;
- drop = Material.COAL;
- } else if(theBlock.getType() == Material.GOLD_ORE){
- intMaxSize = 12;
- drop = Material.GOLD_INGOT;
- } else if(theBlock.getType() == Material.REDSTONE_ORE || theBlock.getTypeId() == 74){
- intMaxSize = 12;
- drop = Material.REDSTONE;
- } else if(theBlock.getType() == Material.DIAMOND_ORE){
- intMaxSize = 12;
- drop = Material.DIAMOND;
- } else {
- drop = Material.AIR;
- }
- for(int i = 0; i < vein.size(); i++){
- Block tmpBlock2 = vein.get(i);
- int iTmp = rand.nextInt(100);
- int amount = 1;
- if(theBlock.getType() == Material.DIAMOND_ORE){
- if(plugin.exc){
- if(iTmp < 30) amount = 2;
- } else amount = 1;
- } else if(tmpBlock2.getType() == Material.REDSTONE_ORE || tmpBlock2.getTypeId() == 74){
- if(iTmp < 30){
- amount = rand.nextInt(3) + 8;
- } else {
- amount = rand.nextInt(3) + 4;
- }
- } else {
- if(iTmp < 30){
- amount = 2;
- } else amount = 1;
- }
- tmpBlock2.setType(Material.AIR);
- for (int d = 0; d < amount; d++){
- tmpBlock2.getWorld().dropItem(tmpBlock2.getLocation(), new ItemStack(drop, 1));
- }
- }
- sender.getItemInHand().setDurability((short)(sender.getItemInHand().getDurability() + 1));
- if(sender.getItemInHand().getDurability() >= 33){
- event.getPlayer().setItemInHand(null);
- }
- vein.clear();
- plugin.ToggleCM(sender);
- } else {
- sender.sendMessage(ChatColor.RED + "This area is protected");
- if(plugin.CMEnabled(sender)){
- plugin.ToggleCM(sender);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement