Advertisement
Guest User

BlockBreak.java

a guest
Oct 24th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.89 KB | None | 0 0
  1. package com.binyon13.customenchants.listeners;
  2.  
  3. import com.binyon13.customenchants.Main;
  4. import com.binyon13.customenchants.stats.Stats;
  5. import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
  6. import java.util.ArrayList;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Random;
  10. import java.util.UUID;
  11. import net.minecraft.server.v1_7_R4.EntityPlayer;
  12. import net.minecraft.server.v1_7_R4.PacketPlayOutWorldParticles;
  13. import net.minecraft.server.v1_7_R4.PlayerConnection;
  14. import org.bukkit.Bukkit;
  15. import org.bukkit.ChatColor;
  16. import org.bukkit.Location;
  17. import org.bukkit.Material;
  18. import org.bukkit.Server;
  19. import org.bukkit.block.Block;
  20. import org.bukkit.configuration.file.FileConfiguration;
  21. import org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer;
  22. import org.bukkit.entity.Player;
  23. import org.bukkit.event.EventHandler;
  24. import org.bukkit.event.Listener;
  25. import org.bukkit.event.block.BlockBreakEvent;
  26. import org.bukkit.inventory.ItemStack;
  27. import org.bukkit.inventory.PlayerInventory;
  28. import org.bukkit.inventory.meta.ItemMeta;
  29. import org.bukkit.plugin.Plugin;
  30. import org.bukkit.plugin.PluginManager;
  31. import org.bukkit.potion.PotionEffect;
  32. import org.bukkit.potion.PotionEffectType;
  33.  
  34. public class BlockBreak
  35. implements Listener
  36. {
  37. protected static Main plugin;
  38.  
  39. public BlockBreak(Main pl)
  40. {
  41. plugin = pl;
  42. }
  43.  
  44. @EventHandler
  45. public void onBlockBreak(BlockBreakEvent e)
  46. {
  47. Player p = e.getPlayer();
  48. if (!allowsBuilding(p, e.getBlock().getLocation())) {
  49. return;
  50. }
  51. ((Stats)Stats.players.get(p.getUniqueId().toString())).setBlocksBroken(((Stats)Stats.players.get(p.getUniqueId().toString())).getBlocksBroken() + 1);
  52. if (((Stats)Stats.players.get(p.getUniqueId().toString())).getBlocksBroken() % 25000 == 0) {
  53. for (String command : Main.config.getStringList("Commands")) {
  54. Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replace("{Player}", p.getName()));
  55. }
  56. }
  57. 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))
  58. {
  59. if (p.getItemInHand().getItemMeta().getLore() == null) {
  60. return;
  61. }
  62. List<String> lore2 = p.getItemInHand().getItemMeta().getLore();
  63. for (String s : lore2)
  64. {
  65. String[] args = s.split(" ");
  66. if (ChatColor.stripColor(args[0]).equals("Haste"))
  67. {
  68. if (args[1].equals("1"))
  69. {
  70. double pecentage = Math.random() * 100.0D;
  71. if (pecentage > 75.0D) {
  72. p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 200, 2));
  73. }
  74. }
  75. else if (args[1].equals("2"))
  76. {
  77. double pecentage = Math.random() * 100.0D;
  78. if (pecentage > 60.0D) {
  79. p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 200, 2));
  80. }
  81. }
  82. else if (args[1].equals("3"))
  83. {
  84. double pecentage = Math.random() * 100.0D;
  85. if (pecentage > 45.0D) {
  86. p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, 200, 2));
  87. }
  88. }
  89. }
  90. else if (ChatColor.stripColor(args[0]).equals("Nightvision"))
  91. {
  92. if (args[1].equals("1"))
  93. {
  94. double pecentage = Math.random() * 100.0D;
  95. if (pecentage > 75.0D) {
  96. p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 200, 2));
  97. }
  98. }
  99. else if (args[1].equals("2"))
  100. {
  101. double pecentage = Math.random() * 100.0D;
  102. if (pecentage > 60.0D) {
  103. p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 200, 2));
  104. }
  105. }
  106. else if (args[1].equals("3"))
  107. {
  108. double pecentage = Math.random() * 100.0D;
  109. if (pecentage > 45.0D) {
  110. p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, 200, 2));
  111. }
  112. }
  113. }
  114. else if (ChatColor.stripColor(args[0]).equals("Explosive"))
  115. {
  116. double pecentage = Math.random() * 100.0D;
  117. if (pecentage > 45.0D) {
  118. createExplosion(e.getBlock().getLocation(), p, Integer.valueOf(args[1]).intValue());
  119. }
  120. }
  121. else if (ChatColor.stripColor(args[0]).equals("Speed"))
  122. {
  123. if (args[1].equals("1"))
  124. {
  125. double pecentage = Math.random() * 100.0D;
  126. if (pecentage > 75.0D) {
  127. p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200, 2));
  128. }
  129. }
  130. else if (args[1].equals("2"))
  131. {
  132. double pecentage = Math.random() * 100.0D;
  133. if (pecentage > 60.0D) {
  134. p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200, 2));
  135. }
  136. }
  137. else if (args[1].equals("3"))
  138. {
  139. double pecentage = Math.random() * 100.0D;
  140. if (pecentage > 45.0D) {
  141. p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, 200, 2));
  142. }
  143. }
  144. }
  145. }
  146. }
  147. }
  148.  
  149. public void createExplosion(Location l, Player p, int amount)
  150. {
  151. ArrayList<Block> blocks = new ArrayList();
  152.  
  153. int radius = 2;
  154. for (int x = -radius; x <= radius; x++) {
  155. for (int y = -radius; y <= radius; y++) {
  156. for (int z = -radius; z <= radius; z++)
  157. {
  158. Location loc = l.getBlock().getRelative(x, y, z).getLocation();
  159.  
  160. loc.getBlock().getType();
  161. for (String s : Main.config.getStringList("ExplodableBlocks"))
  162. {
  163. Material m = Material.getMaterial(Integer.valueOf(s).intValue());
  164. if (loc.getBlock().getType() == m) {
  165. blocks.add(loc.getBlock());
  166. }
  167. }
  168. }
  169. }
  170. }
  171. for (int i = 0; i < amount / 5; i++) {
  172. try
  173. {
  174. Block b = (Block)blocks.get(new Random().nextInt(blocks.size()));
  175. if (allowsBuilding(p, b.getLocation()))
  176. {
  177. if (b.getType() == Material.DIAMOND_ORE) {
  178. p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.DIAMOND) });
  179. } else if (b.getType() == Material.IRON_ORE) {
  180. p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.IRON_INGOT) });
  181. } else if (b.getType() == Material.GOLD_ORE) {
  182. p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.GOLD_INGOT) });
  183. } else if (b.getType() == Material.COAL_ORE) {
  184. p.getInventory().addItem(new ItemStack[] { new ItemStack(Material.COAL) });
  185. } else {
  186. p.getInventory().addItem(new ItemStack[] { new ItemStack(b.getType()) });
  187. }
  188. b.setType(Material.AIR);
  189. }
  190. }
  191. catch (Exception e)
  192. {
  193. return;
  194. }
  195. }
  196. for (Player online : Bukkit.getOnlinePlayers()) {
  197. ((CraftPlayer)online).getHandle().playerConnection.sendPacket(new PacketPlayOutWorldParticles(
  198. "largeexplode",
  199. (float)l.getX(),
  200. (float)l.getY(),
  201. (float)l.getZ(), 0.0F, 0.0F, 0.0F,
  202. 1.0F, 1));
  203. }
  204. }
  205.  
  206. private WorldGuardPlugin getWorldGuard()
  207. {
  208. Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
  209. if ((plugin == null) || (!(plugin instanceof WorldGuardPlugin))) {
  210. return null;
  211. }
  212. return (WorldGuardPlugin)plugin;
  213. }
  214.  
  215. private boolean allowsBuilding(Player player, Location l)
  216. {
  217. return getWorldGuard().canBuild(player, l);
  218. }
  219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement