Excavation.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. /*
  2. This file is part of mcMMO.
  3. mcMMO is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. mcMMO is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with mcMMO. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. package com.gmail.nossr50.skills;
  15. import java.util.ArrayList;
  16. import java.util.List;
  17. import org.bukkit.Bukkit;
  18. import org.bukkit.Location;
  19. import org.bukkit.Material;
  20. import org.bukkit.block.Block;
  21. import org.bukkit.entity.Player;
  22. import org.bukkit.inventory.ItemStack;
  23. import org.bukkit.enchantments.Enchantment;
  24. import org.bukkit.event.player.PlayerAnimationEvent;
  25. import com.gmail.nossr50.locale.mcLocale;
  26. import com.gmail.nossr50.spout.SpoutStuff;
  27. import com.gmail.nossr50.Users;
  28. import com.gmail.nossr50.m;
  29. import com.gmail.nossr50.config.LoadProperties;
  30. import com.gmail.nossr50.datatypes.AbilityType;
  31. import com.gmail.nossr50.datatypes.PlayerProfile;
  32. import com.gmail.nossr50.datatypes.SkillType;
  33. import org.getspout.spoutapi.sound.SoundEffect;
  34. public class Excavation
  35. {
  36. public static void gigaDrillBreakerActivationCheck(Player player, Block block)
  37. {
  38. PlayerProfile PP = Users.getProfile(player);
  39. if(m.isShovel(player.getItemInHand()))
  40. {
  41. if(block != null)
  42. {
  43. if(!m.abilityBlockCheck(block))
  44. return;
  45. }
  46. if(PP.getShovelPreparationMode())
  47. {
  48. PP.setShovelPreparationMode(false);
  49. }
  50. int ticks = 2;
  51. int x = PP.getSkillLevel(SkillType.EXCAVATION);
  52. while(x >= 50)
  53. {
  54. x-=50;
  55. ticks++;
  56. }
  57. if(!PP.getGigaDrillBreakerMode() && PP.getSkillDATS(AbilityType.GIGA_DRILL_BREAKER) < System.currentTimeMillis())
  58. {
  59. player.sendMessage(mcLocale.getString("Skills.GigaDrillBreakerOn"));
  60. for(Player y : player.getWorld().getPlayers())
  61. {
  62. if(y != null && y != player && m.getDistance(player.getLocation(), y.getLocation()) < 10)
  63. y.sendMessage(mcLocale.getString("Skills.GigaDrillBreakerPlayer", new Object[] {player.getName()}));
  64. }
  65. PP.setSkillDATS(AbilityType.GIGA_DRILL_BREAKER, System.currentTimeMillis()+(ticks*1000));
  66. PP.setGigaDrillBreakerMode(true);
  67. }
  68. }
  69. }
  70. public static boolean canBeGigaDrillBroken(Block block)
  71. {
  72. Material t = block.getType();
  73. return t == Material.DIRT || t == Material.GRASS || t == Material.SAND || t == Material.GRAVEL || t == Material.CLAY || t == Material.MYCEL || t == Material.SOUL_SAND;
  74. }
  75. public static void excavationProcCheck(Material type, Location loc, Player player)
  76. {
  77. if(LoadProperties.excavationRequiresShovel && !m.isShovel(player.getItemInHand()))
  78. return;
  79. PlayerProfile PP = Users.getProfile(player);
  80. int skillLevel = PP.getSkillLevel(SkillType.EXCAVATION);
  81. ArrayList<ItemStack> is = new ArrayList<ItemStack>();
  82. int xp = 0;
  83. //Custom Excavation Drops
  84. List<Integer> idValues = LoadProperties.excavationIDs;
  85. List<Integer> dataValues = LoadProperties.excavationDatas;
  86. List<Integer> xpValues = LoadProperties.excavationXPs;
  87. List<Integer> amounts = LoadProperties.excavationAmounts;
  88. List<Double> dropChances = LoadProperties.excavationDropChances;
  89. List<Integer> dropLevels = LoadProperties.excavationDropLevels;
  90. List<Boolean> dirt = LoadProperties.excavationFromDirt;
  91. List<Boolean> grass = LoadProperties.excavationFromGrass;
  92. List<Boolean> sand = LoadProperties.excavationFromSand;
  93. List<Boolean> gravel = LoadProperties.excavationFromGravel;
  94. List<Boolean> clay = LoadProperties.excavationFromClay;
  95. List<Boolean> mycel = LoadProperties.excavationFromMycel;
  96. List<Boolean> soulSand = LoadProperties.excavationFromSoulSand;
  97. switch(type)
  98. {
  99. case DIRT:
  100. for(int i = 0; i < dirt.size(); i++)
  101. {
  102. if(dirt.get(i))
  103. {
  104. if(skillLevel >= dropLevels.get(i))
  105. {
  106. if(Math.random() * 100 > (100.00 - dropChances.get(i)))
  107. {
  108. xp += xpValues.get(i);
  109. is.add(new ItemStack(idValues.get(i), amounts.get(i), (byte)0, dataValues.get(i).byteValue()));
  110. }
  111. }
  112. }
  113. }
  114. break;
  115. case GRASS:
  116. for(int i = 0; i < grass.size(); i++)
  117. {
  118. if(grass.get(i))
  119. {
  120. if(skillLevel >= dropLevels.get(i))
  121. {
  122. if(Math.random() * 100 > (100.00 - dropChances.get(i)))
  123. {
  124. xp += xpValues.get(i);
  125. is.add(new ItemStack(idValues.get(i), amounts.get(i), (byte)0, dataValues.get(i).byteValue()));
  126. }
  127. }
  128. }
  129. }
  130. break;
  131. case SAND:
  132. for(int i = 0; i < sand.size(); i++)
  133. {
  134. if(sand.get(i))
  135. {
  136. if(skillLevel >= dropLevels.get(i))
  137. {
  138. if(Math.random() * 100 > (100.00 - dropChances.get(i)))
  139. {
  140. xp += xpValues.get(i);
  141. is.add(new ItemStack(idValues.get(i), amounts.get(i), (byte)0, dataValues.get(i).byteValue()));
  142. }
  143. }
  144. }
  145. }
  146. break;
  147. case GRAVEL:
  148. for(int i = 0; i < gravel.size(); i++)
  149. {
  150. if(gravel.get(i))
  151. {
  152. if(skillLevel >= dropLevels.get(i))
  153. {
  154. if(Math.random() * 100 > (100.00 - dropChances.get(i)))
  155. {
  156. xp += xpValues.get(i);
  157. is.add(new ItemStack(idValues.get(i), amounts.get(i), (byte)0, dataValues.get(i).byteValue()));
  158. }
  159. }
  160. }
  161. }
  162. break;
  163. case CLAY:
  164. for(int i = 0; i < clay.size(); i++)
  165. {
  166. if(clay.get(i))
  167. {
  168. if(skillLevel >= dropLevels.get(i))
  169. {
  170. if(Math.random() * 100 > (100.00 - dropChances.get(i)))
  171. {
  172. xp += xpValues.get(i);
  173. is.add(new ItemStack(idValues.get(i), amounts.get(i), (byte)0, dataValues.get(i).byteValue()));
  174. }
  175. }
  176. }
  177. }
  178. break;
  179. case MYCEL:
  180. for(int i = 0; i < mycel.size(); i++)
  181. {
  182. if(mycel.get(i))
  183. {
  184. if(skillLevel >= dropLevels.get(i))
  185. {
  186. if(Math.random() * 100 > (100.00 - dropChances.get(i)))
  187. {
  188. xp += xpValues.get(i);
  189. is.add(new ItemStack(idValues.get(i), amounts.get(i), (byte)0, dataValues.get(i).byteValue()));
  190. }
  191. }
  192. }
  193. }
  194. break;
  195. case SOUL_SAND:
  196. for(int i = 0; i < soulSand.size(); i++)
  197. {
  198. if(soulSand.get(i))
  199. {
  200. if(skillLevel >= dropLevels.get(i))
  201. {
  202. if(Math.random() * 100 > (100.00 - dropChances.get(i)))
  203. {
  204. xp += xpValues.get(i);
  205. is.add(new ItemStack(idValues.get(i), amounts.get(i), (byte)0, dataValues.get(i).byteValue()));
  206. }
  207. }
  208. }
  209. }
  210. break;
  211. }
  212. // switch(type)
  213. // {
  214. // case GRASS:
  215. // if(skillLevel >= 250)
  216. // {
  217. // //CHANCE TO GET EGGS
  218. // if(LoadProperties.eggs && Math.random() * 100 > 99)
  219. // {
  220. // xp+= LoadProperties.meggs;
  221. // is.add(new ItemStack(Material.EGG, 1, (byte)0, (byte)0));
  222. // }
  223. // //CHANCE TO GET APPLES
  224. // if(LoadProperties.apples && Math.random() * 100 > 99)
  225. // {
  226. // xp+= LoadProperties.mapple;
  227. // is.add(new ItemStack(Material.APPLE, 1, (byte)0, (byte)0));
  228. // }
  229. // }
  230. // break;
  231. // case GRAVEL:
  232. // //CHANCE TO GET NETHERRACK
  233. // if(LoadProperties.netherrack && skillLevel >= 850 && Math.random() * 200 > 199)
  234. // {
  235. // xp+= LoadProperties.mnetherrack;
  236. // is.add(new ItemStack(Material.NETHERRACK, 1, (byte)0, (byte)0));
  237. //
  238. // }
  239. // //CHANCE TO GET SULPHUR
  240. // if(LoadProperties.sulphur && skillLevel >= 75 && Math.random() * 10 > 9)
  241. // {
  242. // xp+= LoadProperties.msulphur;
  243. // is.add(new ItemStack(Material.SULPHUR, 1, (byte)0, (byte)0));
  244. // }
  245. // //CHANCE TO GET BONES
  246. // if(LoadProperties.bones && skillLevel >= 175 && Math.random() * 10 > 9)
  247. // {
  248. // xp+= LoadProperties.mbones;
  249. // is.add(new ItemStack(Material.BONE, 1, (byte)0, (byte)0));
  250. // }
  251. // break;
  252. // case SAND:
  253. // //CHANCE TO GET GLOWSTONE
  254. // if(LoadProperties.glowstone && skillLevel >= 50 && Math.random() * 100 > 95)
  255. // {
  256. // xp+= LoadProperties.mglowstone2;
  257. // is.add(new ItemStack(Material.GLOWSTONE_DUST, 1, (byte)0, (byte)0));
  258. //
  259. // }
  260. // //CHANCE TO GET SOUL SAND
  261. // if(LoadProperties.slowsand && skillLevel >= 650 && Math.random() * 200 > 199)
  262. // {
  263. // xp+= LoadProperties.mslowsand;
  264. // is.add(new ItemStack(Material.SOUL_SAND, 1, (byte)0, (byte)0));
  265. // }
  266. // break;
  267. // case CLAY:
  268. // //CHANCE TO GET SLIMEBALLS
  269. // if(LoadProperties.slimeballs && skillLevel >= 50 && Math.random() * 20 > 19)
  270. // {
  271. // xp+= LoadProperties.mslimeballs;
  272. // is.add(new ItemStack(Material.SLIME_BALL, 1, (byte)0, (byte)0));
  273. // }
  274. // //CHANCE TO GET STRING
  275. // if(LoadProperties.string && skillLevel >= 250 && Math.random() * 20 > 19)
  276. // {
  277. // xp+= LoadProperties.mstring;
  278. // is.add(new ItemStack(Material.STRING, 1, (byte)0, (byte)0));
  279. // }
  280. // if(skillLevel >= 500)
  281. // {
  282. // //CHANCE TO GET CLOCK
  283. // if(LoadProperties.watch && Math.random() * 100 > 99)
  284. // {
  285. // xp+= LoadProperties.mwatch;
  286. // is.add(new ItemStack(Material.WATCH, 1, (byte)0));
  287. //
  288. // }
  289. // //CHANCE TO GET BUCKET
  290. // if(LoadProperties.bucket && Math.random() * 100 > 99)
  291. // {
  292. // xp+= LoadProperties.mbucket;
  293. // is.add(new ItemStack(Material.BUCKET, 1, (byte)0, (byte)0));
  294. // }
  295. // }
  296. // //CHANCE TO GET COBWEB
  297. // if(LoadProperties.web && skillLevel >= 750 && Math.random() * 20 > 19)
  298. // {
  299. // xp+= LoadProperties.mweb;
  300. // is.add(new ItemStack(Material.WEB, 1, (byte)0, (byte)0));
  301. // }
  302. // break;
  303. // }
  304. //
  305. // //ALL MATERIALS
  306. // if(type == Material.GRASS || type == Material.DIRT || type == Material.GRAVEL || type == Material.SAND || type == Material.CLAY || type == Material.MYCEL || type == Material.SOUL_SAND)
  307. // {
  308. // xp+= LoadProperties.mbase;
  309. // //CHANCE TO GET CAKE
  310. // if(LoadProperties.cake && skillLevel >= 750 && Math.random() * 2000 > 1999)
  311. // {
  312. // xp+= LoadProperties.mcake;
  313. // is.add(new ItemStack(Material.CAKE, 1, (byte)0, (byte)0));
  314. // }
  315. // if(skillLevel >= 350)
  316. // {
  317. // //CHANCE TO GET DIAMOND
  318. // if(LoadProperties.diamond && Math.random() * 750 > 749)
  319. // {
  320. // xp+= LoadProperties.mdiamond2;
  321. // is.add(new ItemStack(Material.DIAMOND, 1, (byte)0, (byte)0));
  322. // }
  323. // //CHANCE TO GET GREEN MUSIC
  324. // if(LoadProperties.music && Math.random() * 2000 > 1999)
  325. // {
  326. // xp+= LoadProperties.mmusic;
  327. // is.add(new ItemStack(Material.GREEN_RECORD, 1, (byte)0, (byte)0));
  328. // }
  329. // }
  330. // //CHANCE TO GET YELLOW MUSIC
  331. // if(LoadProperties.music && skillLevel >= 250 && Math.random() * 2000 > 1999)
  332. // {
  333. // xp+= LoadProperties.mmusic;
  334. // is.add(new ItemStack(Material.GOLD_RECORD, 1, (byte)0, (byte)0));
  335. // }
  336. // }
  337. //
  338. // //GRASS OR DIRT OR MYCEL
  339. // if(type == Material.DIRT || type == Material.GRASS || type == Material.MYCEL)
  340. // {
  341. // //CHANCE FOR COCOA BEANS
  342. // if(LoadProperties.cocoabeans && skillLevel >= 50 && Math.random() * 75 > 74)
  343. // {
  344. // xp+= LoadProperties.mcocoa;
  345. // is.add(new ItemStack(Material.getMaterial(351), 1, (byte)0, (byte)3));
  346. // }
  347. // //CHANCE FOR SHROOMS
  348. // if(LoadProperties.mushrooms && skillLevel >= 500 && Math.random() * 200 > 199)
  349. // {
  350. // xp+= LoadProperties.mmushroom2;
  351. // switch((int)(Math.random() * 2))
  352. // {
  353. // case 0:
  354. // is.add(new ItemStack(Material.BROWN_MUSHROOM, 1, (byte)0, (byte)0));
  355. // break;
  356. // case 1:
  357. // is.add(new ItemStack(Material.RED_MUSHROOM, 1, (byte)0, (byte)0));
  358. // break;
  359. // }
  360. //
  361. // }
  362. // //CHANCE TO GET GLOWSTONE
  363. // if(LoadProperties.glowstone && skillLevel >= 25 && Math.random() * 100 > 95)
  364. // {
  365. // xp+= LoadProperties.mglowstone2;
  366. // is.add(new ItemStack(Material.GLOWSTONE_DUST, 1, (byte)0, (byte)0));
  367. // }
  368. // }
  369. //Drop items
  370. for(ItemStack x : is)
  371. {
  372. if(x != null)
  373. m.mcDropItem(loc, x);
  374. }
  375. //Handle XP related tasks
  376. PP.addXP(SkillType.EXCAVATION, xp, player);
  377. Skills.XpCheckSkill(SkillType.EXCAVATION, player);
  378. }
  379. public static void gigaDrillBreaker(Player player, Block block)
  380. {
  381. if(LoadProperties.toolsLoseDurabilityFromAbilities)
  382. {
  383. if(!player.getItemInHand().containsEnchantment(Enchantment.DURABILITY))
  384. m.damageTool(player, (short) LoadProperties.abilityDurabilityLoss);
  385. }
  386. if(block.getData() != (byte)5)
  387. {
  388. PlayerAnimationEvent armswing = new PlayerAnimationEvent(player);
  389. Bukkit.getPluginManager().callEvent(armswing);
  390. Excavation.excavationProcCheck(block.getType(), block.getLocation(), player);
  391. Excavation.excavationProcCheck(block.getType(), block.getLocation(), player);
  392. Excavation.excavationProcCheck(block.getType(), block.getLocation(), player);
  393. }
  394. if(LoadProperties.spoutEnabled)
  395. SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
  396. }
  397. }