Excavation.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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.Bukkit;
  17. import org.bukkit.Location;
  18. import org.bukkit.Material;
  19. import org.bukkit.block.Block;
  20. import org.bukkit.entity.Player;
  21. import org.bukkit.inventory.ItemStack;
  22. import org.bukkit.enchantments.Enchantment;
  23. import org.bukkit.event.player.PlayerAnimationEvent;
  24. import com.gmail.nossr50.locale.mcLocale;
  25. import com.gmail.nossr50.spout.SpoutStuff;
  26. import com.gmail.nossr50.Users;
  27. import com.gmail.nossr50.m;
  28. import com.gmail.nossr50.config.LoadProperties;
  29. import com.gmail.nossr50.datatypes.AbilityType;
  30. import com.gmail.nossr50.datatypes.PlayerProfile;
  31. import com.gmail.nossr50.datatypes.SkillType;
  32. import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
  33. import org.getspout.spoutapi.sound.SoundEffect;
  34. public class Excavation
  35. {
  36. public static void gigaDrillBreakerActivationCheck(Player player)
  37. {
  38. PlayerProfile PP = Users.getProfile(player);
  39. if(m.isShovel(player.getItemInHand()))
  40. {
  41. if(PP.getShovelPreparationMode())
  42. PP.setShovelPreparationMode(false);
  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.getSkillDATS(AbilityType.GIGA_DRILL_BREAKER) < 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.setSkillDATS(AbilityType.GIGA_DRILL_BREAKER, System.currentTimeMillis()+(ticks*1000));
  59. PP.setGigaDrillBreakerMode(true);
  60. }
  61. }
  62. }
  63. public static boolean canBeGigaDrillBroken(Block block)
  64. {
  65. Material t = block.getType();
  66. return t == Material.DIRT || t == Material.GRASS || t == Material.SAND || t == Material.GRAVEL || t == Material.CLAY || t == Material.MYCEL || t == Material.SOUL_SAND;
  67. }
  68. public static void excavationProcCheck(Block block, Player player)
  69. {
  70. Material type = block.getType();
  71. Location loc = block.getLocation();
  72. PlayerProfile PP = Users.getProfile(player);
  73. int skillLevel = PP.getSkillLevel(SkillType.EXCAVATION);
  74. ArrayList<ItemStack> is = new ArrayList<ItemStack>();
  75. int xp = LoadProperties.mbase;
  76. switch(type)
  77. {
  78. case DIRT:
  79. for(ExcavationTreasure treasure : LoadProperties.excavationFromDirt)
  80. {
  81. if(skillLevel >= treasure.getDropLevel())
  82. {
  83. if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
  84. {
  85. xp += treasure.getXp();
  86. is.add(treasure.getDrop());
  87. }
  88. }
  89. }
  90. break;
  91. case GRASS:
  92. for(ExcavationTreasure treasure : LoadProperties.excavationFromGrass)
  93. {
  94. if(skillLevel >= treasure.getDropLevel())
  95. {
  96. if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
  97. {
  98. xp += treasure.getXp();
  99. is.add(treasure.getDrop());
  100. }
  101. }
  102. }
  103. break;
  104. case SAND:
  105. for(ExcavationTreasure treasure : LoadProperties.excavationFromSand)
  106. {
  107. if(skillLevel >= treasure.getDropLevel())
  108. {
  109. if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
  110. {
  111. xp += treasure.getXp();
  112. is.add(treasure.getDrop());
  113. }
  114. }
  115. }
  116. break;
  117. case GRAVEL:
  118. for(ExcavationTreasure treasure : LoadProperties.excavationFromGravel)
  119. {
  120. if(skillLevel >= treasure.getDropLevel())
  121. {
  122. if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
  123. {
  124. xp += treasure.getXp();
  125. is.add(treasure.getDrop());
  126. }
  127. }
  128. }
  129. break;
  130. case CLAY:
  131. for(ExcavationTreasure treasure : LoadProperties.excavationFromClay)
  132. {
  133. if(skillLevel >= treasure.getDropLevel())
  134. {
  135. if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
  136. {
  137. xp += treasure.getXp();
  138. is.add(treasure.getDrop());
  139. }
  140. }
  141. }
  142. break;
  143. case MYCEL:
  144. for(ExcavationTreasure treasure : LoadProperties.excavationFromMycel)
  145. {
  146. if(skillLevel >= treasure.getDropLevel())
  147. {
  148. if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
  149. {
  150. xp += treasure.getXp();
  151. is.add(treasure.getDrop());
  152. }
  153. }
  154. }
  155. break;
  156. case SOUL_SAND:
  157. for(ExcavationTreasure treasure : LoadProperties.excavationFromSoulSand)
  158. {
  159. if(skillLevel >= treasure.getDropLevel())
  160. {
  161. if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
  162. {
  163. xp += treasure.getXp();
  164. is.add(treasure.getDrop());
  165. }
  166. }
  167. }
  168. break;
  169. }
  170. //Drop items
  171. for(ItemStack x : is)
  172. {
  173. if(x != null)
  174. m.mcDropItem(loc, x);
  175. }
  176. //Handle XP related tasks
  177. PP.addXP(SkillType.EXCAVATION, xp, player);
  178. Skills.XpCheckSkill(SkillType.EXCAVATION, player);
  179. }
  180. public static void gigaDrillBreaker(Player player, Block block)
  181. {
  182. if(LoadProperties.toolsLoseDurabilityFromAbilities)
  183. {
  184. if(!player.getItemInHand().containsEnchantment(Enchantment.DURABILITY))
  185. {
  186. short durability = player.getItemInHand().getDurability();
  187. durability += LoadProperties.abilityDurabilityLoss;
  188. player.getItemInHand().setDurability(durability);
  189. }
  190. }
  191. if(block.getData() != (byte)5)
  192. {
  193. PlayerAnimationEvent armswing = new PlayerAnimationEvent(player);
  194. Bukkit.getPluginManager().callEvent(armswing);
  195. Excavation.excavationProcCheck(block, player);
  196. Excavation.excavationProcCheck(block, player);
  197. Excavation.excavationProcCheck(block, player);
  198. }
  199. if(LoadProperties.spoutEnabled)
  200. SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
  201. }
  202. }