Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.binyon13.customenchants.listeners;
- import com.binyon13.customenchants.Main;
- import com.binyon13.customenchants.stats.Stats;
- import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Random;
- import java.util.UUID;
- import net.minecraft.server.v1_7_R4.EntityPlayer;
- import net.minecraft.server.v1_7_R4.PacketPlayOutWorldParticles;
- import net.minecraft.server.v1_7_R4.PlayerConnection;
- import org.bukkit.Bukkit;
- import org.bukkit.ChatColor;
- import org.bukkit.Location;
- import org.bukkit.Material;
- import org.bukkit.Server;
- import org.bukkit.block.Block;
- import org.bukkit.configuration.file.FileConfiguration;
- import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
- import org.bukkit.entity.Player;
- import org.bukkit.event.EventHandler;
- import org.bukkit.event.Listener;
- import org.bukkit.event.block.BlockBreakEvent;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.inventory.PlayerInventory;
- import org.bukkit.inventory.meta.ItemMeta;
- import org.bukkit.plugin.Plugin;
- import org.bukkit.plugin.PluginManager;
- import org.bukkit.potion.PotionEffect;
- import org.bukkit.potion.PotionEffectType;
- public class BlockBreak
- implements Listener
- {
- protected static Main plugin;
- public BlockBreak(Main pl)
- {
- plugin = pl;
- }
- @EventHandler
- public void onBlockBreak(BlockBreakEvent e)
- {
- Player p = e.getPlayer();
- if (!allowsBuilding(p, e.getBlock().getLocation())) {
- return;
- }
- ((Stats)Stats.players.get(p.getUniqueId().toString())).setBlocksBroken(((Stats)Stats.players.get(p.getUniqueId().toString())).getBlocksBroken() + 1);
- if (((Stats)Stats.players.get(p.getUniqueId().toString())).getBlocksBroken() % 25000 == 0) {
- for (String command : Main.config.getStringList("Commands")) {
- Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replace("{Player}", p.getName()));
- }
- }
- if ((p.getInventory().getItemInHand().getType() == Material.DIAMOND_PICKAXE) || (p.getInventory().getItemInHand().getType() == Material.GOLD_PICKAXE) || (p.getInventory().getItemInHand().getType() == Material.IRON_PICKAXE) || (p.getInventory().getItemInHand().getType() == Material.STONE_PICKAXE) || (p.getInventory().getItemInHand().getType() == Material.WOOD_PICKAXE))
- {
- if (p.getItemInHand().getItemMeta().getLore() == null) {
- return;
- }
- List<String> lore2 = p.getItemInHand().getItemMeta().getLore();
- for (String s : lore2)
- {
- String[] args = s.split(" ");
- if (ChatColor.stripColor(args[0]).equals("Haste"))
- {
- if (args[1].equals("1"))
- {
- double pecentage = Math.random() * 100.0D;
- if (pecentage > 75.0D) {
- p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 200, 2));
- }
- }
- else if (args[1].equals("2"))
- {
- double pecentage = Math.random() * 100.0D;
- if (pecentage > 60.0D) {
- p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 200, 2));
- }
- }
- else if (args[1].equals("3"))
- {
- double pecentage = Math.random() * 100.0D;
- if (pecentage > 45.0D) {
- p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 200, 2));
- }
- }
- }
- else if (ChatColor.stripColor(args[0]).equals("Nightvision"))
- {
- if (args[1].equals("1"))
- {
- double pecentage = Math.random() * 100.0D;
- if (pecentage > 75.0D) {
- p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 200, 2));
- }
- }
- else if (args[1].equals("2"))
- {
- double pecentage = Math.random() * 100.0D;
- if (pecentage > 60.0D) {
- p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 200, 2));
- }
- }
- else if (args[1].equals("3"))
- {
- double pecentage = Math.random() * 100.0D;
- if (pecentage > 45.0D) {
- p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 200, 2));
- }
- }
- }
- else if (ChatColor.stripColor(args[0]).equals("Explosive"))
- {
- double pecentage = Math.random() * 100.0D;
- if (pecentage > 45.0D) {
- createExplosion(e.getBlock().getLocation(), p, Integer.valueOf(args[1]).intValue());
- }
- }
- else if (ChatColor.stripColor(args[0]).equals("Speed"))
- {
- if (args[1].equals("1"))
- {
- double pecentage = Math.random() * 100.0D;
- if (pecentage > 75.0D) {
- p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200, 2));
- }
- }
- else if (args[1].equals("2"))
- {
- double pecentage = Math.random() * 100.0D;
- if (pecentage > 60.0D) {
- p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200, 2));
- }
- }
- else if (args[1].equals("3"))
- {
- double pecentage = Math.random() * 100.0D;
- if (pecentage > 45.0D) {
- p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200, 2));
- }
- }
- }
- }
- }
- }
- public void createExplosion(Location l, Player p, int amount)
- {
- ArrayList<Block> blocks = new ArrayList();
- int radius = 2;
- for (int x = -radius; x <= radius; x++) {
- for (int y = -radius; y <= radius; y++) {
- for (int z = -radius; z <= radius; z++)
- {
- Location loc = l.getBlock().getRelative(x, y, z).getLocation();
- loc.getBlock().getType();
- for (String s : Main.config.getStringList("ExplodableBlocks"))
- {
- Material m = Material.getMaterial(Integer.valueOf(s).intValue());
- if (loc.getBlock().getType() == m) {
- blocks.add(loc.getBlock());
- }
- }
- }
- }
- }
- for (int i = 0; i < amount / 5; i++) {
- try
- {
- Block b = (Block)blocks.get(new Random().nextInt(blocks.size()));
- if (allowsBuilding(p, b.getLocation()))
- {
- if (b.getType() == Material.DIAMOND_ORE) {
- p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.DIAMOND) });
- } else if (b.getType() == Material.IRON_ORE) {
- p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.IRON_INGOT) });
- } else if (b.getType() == Material.GOLD_ORE) {
- p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.GOLD_INGOT) });
- } else if (b.getType() == Material.COAL_ORE) {
- p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.COAL) });
- } else {
- p.getInventory().addItem(new ItemStack[] { new ItemStack(b.getType()) });
- }
- b.setType(Material.AIR);
- }
- }
- catch (Exception e)
- {
- return;
- }
- }
- for (Player online : Bukkit.getOnlinePlayers()) {
- ((CraftPlayer)online).getHandle().playerConnection.sendPacket(new PacketPlayOutWorldParticles(
- "largeexplode",
- (float)l.getX(),
- (float)l.getY(),
- (float)l.getZ(), 0.0F, 0.0F, 0.0F,
- 1.0F, 1));
- }
- }
- private WorldGuardPlugin getWorldGuard()
- {
- Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
- if ((plugin == null) || (!(plugin instanceof WorldGuardPlugin))) {
- return null;
- }
- return (WorldGuardPlugin)plugin;
- }
- private boolean allowsBuilding(Player player, Location l)
- {
- return getWorldGuard().canBuild(player, l);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement