WoodCutting.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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.ChatColor;
  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 com.gmail.nossr50.Users;
  23. import com.gmail.nossr50.m;
  24. import com.gmail.nossr50.mcMMO;
  25. import com.gmail.nossr50.datatypes.PlayerProfile;
  26. import com.gmail.nossr50.datatypes.SkillType;
  27. import com.gmail.nossr50.locale.mcLocale;
  28. import com.gmail.nossr50.config.*;
  29. public class WoodCutting
  30. {
  31. static int w = 0;
  32. private static boolean isdone = false;
  33. public static void woodCuttingProcCheck(Player player, Block block)
  34. {
  35. PlayerProfile PP = Users.getProfile(player);
  36. byte type = block.getData();
  37. Material mat = Material.getMaterial(block.getTypeId());
  38. if(player != null)
  39. {
  40. if((Math.random() * 1000 <= PP.getSkillLevel(SkillType.WOODCUTTING)) || PP.getSkillLevel(SkillType.WOODCUTTING) > 1000)
  41. {
  42. ItemStack item = new ItemStack(mat, 1, (short) 0, type);
  43. m.mcDropItem(block.getLocation(), item);
  44. }
  45. }
  46. }
  47. public static void treeFellerCheck(Player player, Block block)
  48. {
  49. PlayerProfile PP = Users.getProfile(player);
  50. if(m.isAxes(player.getItemInHand()))
  51. {
  52. if(block != null)
  53. {
  54. if(!m.abilityBlockCheck(block))
  55. return;
  56. }
  57. /*
  58. * CHECK FOR AXE PREP MODE
  59. */
  60. if(PP.getAxePreparationMode())
  61. {
  62. PP.setAxePreparationMode(false);
  63. }
  64. int ticks = 2;
  65. int x = PP.getSkillLevel(SkillType.WOODCUTTING);
  66. while(x >= 50)
  67. {
  68. x-=50;
  69. ticks++;
  70. }
  71. if(!PP.getTreeFellerMode() && Skills.cooldownOver(player, (PP.getTreeFellerDeactivatedTimeStamp()*1000), LoadProperties.treeFellerCooldown))
  72. {
  73. player.sendMessage(mcLocale.getString("Skills.TreeFellerOn"));
  74. for(Player y : player.getWorld().getPlayers())
  75. {
  76. if(y != null && y != player && m.getDistance(player.getLocation(), y.getLocation()) < 10)
  77. y.sendMessage(mcLocale.getString("Skills.TreeFellerPlayer", new Object[] {player.getName()}));
  78. }
  79. PP.setTreeFellerActivatedTimeStamp(System.currentTimeMillis());
  80. PP.setTreeFellerDeactivatedTimeStamp(System.currentTimeMillis() + (ticks * 1000));
  81. PP.setTreeFellerMode(true);
  82. }
  83. if(!PP.getTreeFellerMode() && !Skills.cooldownOver(player, (PP.getTreeFellerDeactivatedTimeStamp()*1000), LoadProperties.treeFellerCooldown)){
  84. player.sendMessage(ChatColor.RED+"You are too tired to use that ability again."
  85. +ChatColor.YELLOW+" ("+Skills.calculateTimeLeft(player, (PP.getTreeFellerDeactivatedTimeStamp()*1000), LoadProperties.treeFellerCooldown)+"s)");
  86. }
  87. }
  88. }
  89. public static void treeFeller(Block block, Player player, mcMMO plugin){
  90. PlayerProfile PP = Users.getProfile(player);
  91. int radius = 1;
  92. if(PP.getSkillLevel(SkillType.WOODCUTTING) >= 500)
  93. radius++;
  94. if(PP.getSkillLevel(SkillType.WOODCUTTING) >= 950)
  95. radius++;
  96. ArrayList<Block> blocklist = new ArrayList<Block>();
  97. ArrayList<Block> toAdd = new ArrayList<Block>();
  98. if(block != null)
  99. blocklist.add(block);
  100. while(isdone == false){
  101. addBlocksToTreeFelling(blocklist, toAdd, radius);
  102. }
  103. //This needs to be a hashmap too!
  104. isdone = false;
  105. /*
  106. * Add blocks from the temporary 'toAdd' array list into the 'treeFeller' array list
  107. * We use this temporary list to prevent concurrent modification exceptions
  108. */
  109. for(Block x : toAdd)
  110. {
  111. if(!plugin.misc.treeFeller.contains(x))
  112. plugin.misc.treeFeller.add(x);
  113. }
  114. toAdd.clear();
  115. }
  116. public static void addBlocksToTreeFelling(ArrayList<Block> blocklist, ArrayList<Block> toAdd, Integer radius)
  117. {
  118. int u = 0;
  119. for (Block x : blocklist)
  120. {
  121. u++;
  122. if(toAdd.contains(x))
  123. continue;
  124. w = 0;
  125. Location loc = x.getLocation();
  126. int vx = x.getX();
  127. int vy = x.getY();
  128. int vz = x.getZ();
  129. /*
  130. * Run through the blocks around the broken block to see if they qualify to be 'felled'
  131. */
  132. for (int cx = -radius; cx <= radius; cx++) {
  133. for (int cy = -radius; cy <= radius; cy++) {
  134. for (int cz = -radius; cz <= radius; cz++) {
  135. Block blocktarget = loc.getWorld().getBlockAt(vx + cx, vy + cy, vz + cz);
  136. if (!blocklist.contains(blocktarget) && !toAdd.contains(blocktarget) && (blocktarget.getTypeId() == 17 || blocktarget.getTypeId() == 18)) {
  137. toAdd.add(blocktarget);
  138. w++;
  139. }
  140. }
  141. }
  142. }
  143. }
  144. /*
  145. * Add more blocks to blocklist so they can be 'felled'
  146. */
  147. for(Block xx : toAdd)
  148. {
  149. if(!blocklist.contains(xx))
  150. blocklist.add(xx);
  151. }
  152. if(u >= blocklist.size())
  153. {
  154. isdone = true;
  155. } else {
  156. isdone = false;
  157. }
  158. }
  159. public static void woodcuttingBlockCheck(Player player, Block block, mcMMO plugin)
  160. {
  161. PlayerProfile PP = Users.getProfile(player);
  162. int xp = 0;
  163. byte data = block.getData();
  164. if(plugin.misc.blockWatchList.contains(block))
  165. return;
  166. switch(data)
  167. {
  168. case 0:
  169. xp += LoadProperties.mpine;
  170. break;
  171. case 1:
  172. xp += LoadProperties.mspruce;
  173. break;
  174. case 2:
  175. xp += LoadProperties.mbirch;
  176. break;
  177. }
  178. if(block.getTypeId() == 17)
  179. WoodCutting.woodCuttingProcCheck(player, block);
  180. PP.addXP(SkillType.WOODCUTTING, xp, player);
  181. Skills.XpCheckSkill(SkillType.WOODCUTTING, player);
  182. }
  183. }