Excavation.java 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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 org.bukkit.Location;
  17. import org.bukkit.Material;
  18. import org.bukkit.block.Block;
  19. import org.bukkit.entity.Player;
  20. import org.bukkit.inventory.ItemStack;
  21. import com.gmail.nossr50.locale.mcLocale;
  22. import com.gmail.nossr50.Users;
  23. import com.gmail.nossr50.m;
  24. import com.gmail.nossr50.config.LoadProperties;
  25. import com.gmail.nossr50.datatypes.PlayerProfile;
  26. import com.gmail.nossr50.datatypes.SkillType;
  27. public class Excavation
  28. {
  29. public static void gigaDrillBreakerActivationCheck(Player player, Block block)
  30. {
  31. PlayerProfile PP = Users.getProfile(player);
  32. if(m.isShovel(player.getItemInHand()))
  33. {
  34. if(block != null)
  35. {
  36. if(!m.abilityBlockCheck(block))
  37. return;
  38. }
  39. if(PP.getShovelPreparationMode())
  40. {
  41. PP.setShovelPreparationMode(false);
  42. }
  43. int ticks = 2;
  44. int x = PP.getSkillLevel(SkillType.EXCAVATION);
  45. while(x >= 50)
  46. {
  47. x-=50;
  48. ticks++;
  49. }
  50. if(!PP.getGigaDrillBreakerMode() && PP.getGigaDrillBreakerDeactivatedTimeStamp() < System.currentTimeMillis())
  51. {
  52. player.sendMessage(mcLocale.getString("Skills.GigaDrillBreakerOn"));
  53. for(Player y : player.getWorld().getPlayers())
  54. {
  55. if(y != null && y != player && m.getDistance(player.getLocation(), y.getLocation()) < 10)
  56. y.sendMessage(mcLocale.getString("Skills.GigaDrillBreakerPlayer", new Object[] {player.getName()}));
  57. }
  58. PP.setGigaDrillBreakerActivatedTimeStamp(System.currentTimeMillis());
  59. PP.setGigaDrillBreakerDeactivatedTimeStamp(System.currentTimeMillis() + (ticks * 1000));
  60. PP.setGigaDrillBreakerMode(true);
  61. }
  62. }
  63. }
  64. public static boolean canBeGigaDrillBroken(Block block)
  65. {
  66. return block.getType() == Material.DIRT || block.getType() == Material.GRASS || block.getType() == Material.SAND || block.getType() == Material.GRAVEL || block.getType() == Material.CLAY;
  67. }
  68. public static void excavationProcCheck(byte data, Material type, Location loc, Player player)
  69. {
  70. if(LoadProperties.excavationRequiresShovel && !m.isShovel(player.getItemInHand()))
  71. return;
  72. PlayerProfile PP = Users.getProfile(player);
  73. ArrayList<ItemStack> is = new ArrayList<ItemStack>();
  74. int xp = 0;
  75. switch(type)
  76. {
  77. case GRASS:
  78. if(PP.getSkillLevel(SkillType.EXCAVATION) >= 250)
  79. {
  80. //CHANCE TO GET EGGS
  81. if(LoadProperties.eggs == true && Math.random() * 100 > 99)
  82. {
  83. xp+= LoadProperties.meggs;
  84. is.add(new ItemStack(Material.EGG, 1, (byte)0, (byte)0));
  85. }
  86. //CHANCE TO GET APPLES
  87. if(LoadProperties.apples == true && Math.random() * 100 > 99)
  88. {
  89. xp+= LoadProperties.mapple;
  90. is.add(new ItemStack(Material.APPLE, 1, (byte)0, (byte)0));
  91. }
  92. }
  93. break;
  94. case GRAVEL:
  95. //CHANCE TO GET NETHERRACK
  96. if(LoadProperties.netherrack == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 850 && Math.random() * 200 > 199)
  97. {
  98. xp+= LoadProperties.mnetherrack;
  99. is.add(new ItemStack(Material.NETHERRACK, 1, (byte)0, (byte)0));
  100. }
  101. //CHANCE TO GET SULPHUR
  102. if(LoadProperties.sulphur == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 75)
  103. {
  104. if(Math.random() * 10 > 9)
  105. {
  106. xp+= LoadProperties.msulphur;
  107. is.add(new ItemStack(Material.SULPHUR, 1, (byte)0, (byte)0));
  108. }
  109. }
  110. //CHANCE TO GET BONES
  111. if(LoadProperties.bones == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 175)
  112. {
  113. if(Math.random() * 10 > 9)
  114. {
  115. xp+= LoadProperties.mbones;
  116. is.add(new ItemStack(Material.BONE, 1, (byte)0, (byte)0));
  117. }
  118. }
  119. break;
  120. case SAND:
  121. //CHANCE TO GET GLOWSTONE
  122. if(LoadProperties.glowstone == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 50 && Math.random() * 100 > 95)
  123. {
  124. xp+= LoadProperties.mglowstone2;
  125. is.add(new ItemStack(Material.GLOWSTONE_DUST, 1, (byte)0, (byte)0));
  126. }
  127. //CHANCE TO GET SOUL SAND
  128. if(LoadProperties.slowsand == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 650 && Math.random() * 200 > 199)
  129. {
  130. xp+= LoadProperties.mslowsand;
  131. is.add(new ItemStack(Material.SOUL_SAND, 1, (byte)0, (byte)0));
  132. }
  133. break;
  134. case CLAY:
  135. if(LoadProperties.slimeballs && PP.getSkillLevel(SkillType.EXCAVATION) >= 50)
  136. {
  137. if(Math.random() * 20 > 19)
  138. {
  139. xp+= LoadProperties.mslimeballs;
  140. is.add(new ItemStack(Material.SLIME_BALL, 1, (byte)0, (byte)0));
  141. }
  142. }
  143. if(LoadProperties.string && PP.getSkillLevel(SkillType.EXCAVATION) >= 250)
  144. {
  145. if(Math.random() * 20 > 19)
  146. {
  147. xp+= LoadProperties.mstring;
  148. is.add(new ItemStack(Material.STRING, 1, (byte)0, (byte)0));
  149. }
  150. }
  151. if(LoadProperties.watch && PP.getSkillLevel(SkillType.EXCAVATION) >= 500)
  152. {
  153. if(Math.random() * 100 > 99)
  154. {
  155. xp+= LoadProperties.mwatch;
  156. is.add(new ItemStack(Material.WATCH, 1, (byte)0));
  157. }
  158. }
  159. if(LoadProperties.bucket && PP.getSkillLevel(SkillType.EXCAVATION) >= 500)
  160. {
  161. if(Math.random() * 100 > 99)
  162. {
  163. xp+= LoadProperties.mbucket;
  164. is.add(new ItemStack(Material.BUCKET, 1, (byte)0, (byte)0));
  165. }
  166. }
  167. if(LoadProperties.web && PP.getSkillLevel(SkillType.EXCAVATION) >= 750)
  168. {
  169. if(Math.random() * 20 > 19)
  170. {
  171. xp+= LoadProperties.mweb;
  172. is.add(new ItemStack(Material.WEB, 1, (byte)0, (byte)0));
  173. }
  174. }
  175. break;
  176. }
  177. //DIRT SAND OR GRAVEL
  178. if(type == Material.GRASS || type == Material.DIRT || type == Material.GRAVEL || type == Material.SAND || type == Material.CLAY)
  179. {
  180. xp+= LoadProperties.mbase;
  181. if(PP.getSkillLevel(SkillType.EXCAVATION) >= 750)
  182. {
  183. //CHANCE TO GET CAKE
  184. if(LoadProperties.cake == true && Math.random() * 2000 > 1999)
  185. {
  186. xp+= LoadProperties.mcake;
  187. is.add(new ItemStack(Material.CAKE, 1, (byte)0, (byte)0));
  188. }
  189. }
  190. if(PP.getSkillLevel(SkillType.EXCAVATION) >= 350)
  191. {
  192. //CHANCE TO GET DIAMOND
  193. if(LoadProperties.diamond == true && Math.random() * 750 > 749)
  194. {
  195. xp+= LoadProperties.mdiamond2;
  196. is.add(new ItemStack(Material.DIAMOND, 1, (byte)0, (byte)0));
  197. }
  198. }
  199. if(PP.getSkillLevel(SkillType.EXCAVATION) >= 250)
  200. {
  201. //CHANCE TO GET YELLOW MUSIC
  202. if(LoadProperties.music == true && Math.random() * 2000 > 1999)
  203. {
  204. xp+= LoadProperties.mmusic;
  205. is.add(new ItemStack(Material.GOLD_RECORD, 1, (byte)0, (byte)0));
  206. }
  207. }
  208. if(PP.getSkillLevel(SkillType.EXCAVATION) >= 350)
  209. {
  210. //CHANCE TO GET GREEN MUSIC
  211. if(LoadProperties.music == true && Math.random() * 2000 > 1999)
  212. {
  213. xp+= LoadProperties.mmusic;
  214. is.add(new ItemStack(Material.GREEN_RECORD, 1, (byte)0, (byte)0));
  215. }
  216. }
  217. }
  218. //GRASS OR DIRT
  219. if(type == Material.DIRT || type == Material.GRASS)
  220. {
  221. if(PP.getSkillLevel(SkillType.EXCAVATION) >= 50)
  222. {
  223. //CHANCE FOR COCOA BEANS
  224. if(LoadProperties.cocoabeans == true && Math.random() * 75 > 74)
  225. {
  226. xp+= LoadProperties.mcocoa;
  227. is.add(new ItemStack(Material.getMaterial(351), 1, (byte)0, (byte)3));
  228. }
  229. }
  230. //CHANCE FOR SHROOMS
  231. if(LoadProperties.mushrooms == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 500 && Math.random() * 200 > 199)
  232. {
  233. xp+= LoadProperties.mmushroom2;
  234. switch((int) Math.random() * 1)
  235. {
  236. case 0:
  237. is.add(new ItemStack(Material.BROWN_MUSHROOM, 1, (byte)0, (byte)0));
  238. break;
  239. case 1:
  240. is.add(new ItemStack(Material.RED_MUSHROOM, 1, (byte)0, (byte)0));
  241. break;
  242. }
  243. }
  244. //CHANCE TO GET GLOWSTONE
  245. if(LoadProperties.glowstone == true && PP.getSkillLevel(SkillType.EXCAVATION) >= 25 && Math.random() * 100 > 95)
  246. {
  247. xp+= LoadProperties.mglowstone2;
  248. is.add(new ItemStack(Material.GLOWSTONE_DUST, 1, (byte)0, (byte)0));
  249. }
  250. }
  251. //Drop items
  252. for(ItemStack x : is)
  253. {
  254. if(x != null)
  255. m.mcDropItem(loc, x);
  256. }
  257. //Handle XP related tasks
  258. PP.addXP(SkillType.EXCAVATION, xp, player);
  259. Skills.XpCheckSkill(SkillType.EXCAVATION, player);
  260. }
  261. }