Excavation.java 9.3 KB

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