Excavation.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. switch(block.getType()){
  66. case CLAY:
  67. case DIRT:
  68. case GRASS:
  69. case GRAVEL:
  70. case MYCEL:
  71. case SAND:
  72. case SOUL_SAND:
  73. return true;
  74. }
  75. return false;
  76. }
  77. public static void excavationProcCheck(Block block, Player player)
  78. {
  79. Material type = block.getType();
  80. Location loc = block.getLocation();
  81. PlayerProfile PP = Users.getProfile(player);
  82. int skillLevel = PP.getSkillLevel(SkillType.EXCAVATION);
  83. ArrayList<ItemStack> is = new ArrayList<ItemStack>();
  84. int xp = LoadProperties.mbase;
  85. switch(type)
  86. {
  87. case DIRT:
  88. for(ExcavationTreasure treasure : LoadProperties.excavationFromDirt)
  89. {
  90. if(skillLevel >= treasure.getDropLevel())
  91. {
  92. if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
  93. {
  94. xp += treasure.getXp();
  95. is.add(treasure.getDrop());
  96. }
  97. }
  98. }
  99. break;
  100. case GRASS:
  101. for(ExcavationTreasure treasure : LoadProperties.excavationFromGrass)
  102. {
  103. if(skillLevel >= treasure.getDropLevel())
  104. {
  105. if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
  106. {
  107. xp += treasure.getXp();
  108. is.add(treasure.getDrop());
  109. }
  110. }
  111. }
  112. break;
  113. case SAND:
  114. for(ExcavationTreasure treasure : LoadProperties.excavationFromSand)
  115. {
  116. if(skillLevel >= treasure.getDropLevel())
  117. {
  118. if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
  119. {
  120. xp += treasure.getXp();
  121. is.add(treasure.getDrop());
  122. }
  123. }
  124. }
  125. break;
  126. case GRAVEL:
  127. for(ExcavationTreasure treasure : LoadProperties.excavationFromGravel)
  128. {
  129. if(skillLevel >= treasure.getDropLevel())
  130. {
  131. if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
  132. {
  133. xp += treasure.getXp();
  134. is.add(treasure.getDrop());
  135. }
  136. }
  137. }
  138. break;
  139. case CLAY:
  140. for(ExcavationTreasure treasure : LoadProperties.excavationFromClay)
  141. {
  142. if(skillLevel >= treasure.getDropLevel())
  143. {
  144. if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
  145. {
  146. xp += treasure.getXp();
  147. is.add(treasure.getDrop());
  148. }
  149. }
  150. }
  151. break;
  152. case MYCEL:
  153. for(ExcavationTreasure treasure : LoadProperties.excavationFromMycel)
  154. {
  155. if(skillLevel >= treasure.getDropLevel())
  156. {
  157. if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
  158. {
  159. xp += treasure.getXp();
  160. is.add(treasure.getDrop());
  161. }
  162. }
  163. }
  164. break;
  165. case SOUL_SAND:
  166. for(ExcavationTreasure treasure : LoadProperties.excavationFromSoulSand)
  167. {
  168. if(skillLevel >= treasure.getDropLevel())
  169. {
  170. if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
  171. {
  172. xp += treasure.getXp();
  173. is.add(treasure.getDrop());
  174. }
  175. }
  176. }
  177. break;
  178. }
  179. //Drop items
  180. for(ItemStack x : is)
  181. {
  182. if(x != null)
  183. m.mcDropItem(loc, x);
  184. }
  185. //Handle XP related tasks
  186. PP.addXP(SkillType.EXCAVATION, xp, player);
  187. Skills.XpCheckSkill(SkillType.EXCAVATION, player);
  188. }
  189. public static void gigaDrillBreaker(Player player, Block block)
  190. {
  191. if(LoadProperties.toolsLoseDurabilityFromAbilities)
  192. {
  193. if(!player.getItemInHand().containsEnchantment(Enchantment.DURABILITY))
  194. {
  195. short durability = player.getItemInHand().getDurability();
  196. durability += LoadProperties.abilityDurabilityLoss;
  197. player.getItemInHand().setDurability(durability);
  198. }
  199. }
  200. if(block.getData() != (byte)5)
  201. {
  202. PlayerAnimationEvent armswing = new PlayerAnimationEvent(player);
  203. Bukkit.getPluginManager().callEvent(armswing);
  204. Excavation.excavationProcCheck(block, player);
  205. Excavation.excavationProcCheck(block, player);
  206. Excavation.excavationProcCheck(block, player);
  207. }
  208. if(LoadProperties.spoutEnabled)
  209. SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
  210. }
  211. }