Herbalism.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  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 org.bukkit.Location;
  16. import org.bukkit.Material;
  17. import org.bukkit.World;
  18. import org.bukkit.block.Block;
  19. import org.bukkit.entity.Player;
  20. import org.bukkit.event.block.BlockBreakEvent;
  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.config.LoadProperties;
  26. import com.gmail.nossr50.datatypes.PlayerProfile;
  27. import com.gmail.nossr50.datatypes.SkillType;
  28. import com.gmail.nossr50.locale.mcLocale;
  29. public class Herbalism
  30. {
  31. public static void greenTerraCheck(Player player, Block block)
  32. {
  33. PlayerProfile PP = Users.getProfile(player);
  34. if(m.isHoe(player.getItemInHand()))
  35. {
  36. if(block != null)
  37. {
  38. if(!m.abilityBlockCheck(block))
  39. return;
  40. }
  41. if(PP.getHoePreparationMode())
  42. {
  43. PP.setHoePreparationMode(false);
  44. }
  45. int ticks = 2;
  46. int x = PP.getSkillLevel(SkillType.HERBALISM);
  47. while(x >= 50)
  48. {
  49. x-=50;
  50. ticks++;
  51. }
  52. if(!PP.getGreenTerraMode() && Skills.cooldownOver(player, PP.getGreenTerraDeactivatedTimeStamp(), LoadProperties.greenTerraCooldown))
  53. {
  54. player.sendMessage(mcLocale.getString("Skills.GreenTerraOn"));
  55. for(Player y : player.getWorld().getPlayers())
  56. {
  57. if(y != null && y != player && m.getDistance(player.getLocation(), y.getLocation()) < 10)
  58. y.sendMessage(mcLocale.getString("Skills.GreenTerraPlayer", new Object[] {player.getName()}));
  59. }
  60. PP.setGreenTerraActivatedTimeStamp(System.currentTimeMillis());
  61. PP.setGreenTerraDeactivatedTimeStamp(System.currentTimeMillis() + (ticks * 1000));
  62. PP.setGreenTerraMode(true);
  63. }
  64. }
  65. }
  66. public static void greenTerraWheat(Player player, Block block, BlockBreakEvent event, mcMMO plugin)
  67. {
  68. if(block.getType() == Material.WHEAT && block.getData() == (byte) 0x07)
  69. {
  70. event.setCancelled(true);
  71. PlayerProfile PP = Users.getProfile(player);
  72. Material mat = Material.getMaterial(296);
  73. Location loc = block.getLocation();
  74. ItemStack is = new ItemStack(mat, 1, (byte)0, (byte)0);
  75. PP.addXP(SkillType.HERBALISM, LoadProperties.mwheat, player);
  76. m.mcDropItem(loc, is);
  77. //DROP SOME SEEDS
  78. mat = Material.SEEDS;
  79. is = new ItemStack(mat, 1, (byte)0, (byte)0);
  80. m.mcDropItem(loc, is);
  81. herbalismProcCheck(block, player, event, plugin);
  82. herbalismProcCheck(block, player, event, plugin);
  83. block.setData((byte) 0x03);
  84. }
  85. }
  86. public static void greenTerra(Player player, Block block){
  87. if(block.getType() == Material.COBBLESTONE || block.getType() == Material.DIRT){
  88. if(!hasSeeds(player))
  89. player.sendMessage("You need more seeds to spread Green Terra");
  90. if(hasSeeds(player) && block.getType() != Material.WHEAT)
  91. {
  92. removeSeeds(player);
  93. if(block.getType() == Material.SMOOTH_BRICK)
  94. block.setData((byte)1);
  95. if(block.getType() == Material.DIRT)
  96. block.setType(Material.GRASS);
  97. if(LoadProperties.enableCobbleToMossy && block.getType() == Material.COBBLESTONE)
  98. block.setType(Material.MOSSY_COBBLESTONE);
  99. }
  100. }
  101. }
  102. public static Boolean canBeGreenTerra(Block block){
  103. int t = block.getTypeId();
  104. if(t == 103 || t == 4 || t == 3 || t == 59 || t == 81 || t == 83 || t == 91 || t == 86 || t == 39 || t == 46 || t == 37 || t == 38){
  105. return true;
  106. } else {
  107. return false;
  108. }
  109. }
  110. public static boolean hasSeeds(Player player){
  111. ItemStack[] inventory = player.getInventory().getContents();
  112. for(ItemStack x : inventory){
  113. if(x != null && x.getTypeId() == 295){
  114. return true;
  115. }
  116. }
  117. return false;
  118. }
  119. public static void removeSeeds(Player player){
  120. ItemStack[] inventory = player.getInventory().getContents();
  121. for(ItemStack x : inventory){
  122. if(x != null && x.getTypeId() == 295){
  123. if(x.getAmount() == 1){
  124. x.setTypeId(0);
  125. x.setAmount(0);
  126. player.getInventory().setContents(inventory);
  127. } else{
  128. x.setAmount(x.getAmount() - 1);
  129. player.getInventory().setContents(inventory);
  130. }
  131. return;
  132. }
  133. }
  134. }
  135. public static void herbalismProcCheck(Block block, Player player, BlockBreakEvent event, mcMMO plugin)
  136. {
  137. PlayerProfile PP = Users.getProfile(player);
  138. int type = block.getTypeId();
  139. Location loc = block.getLocation();
  140. ItemStack is = null;
  141. Material mat = null;
  142. if(plugin.misc.blockWatchList.contains(block))
  143. {
  144. return;
  145. }
  146. if(type == 59 && block.getData() == (byte) 0x7)
  147. {
  148. mat = Material.getMaterial(296);
  149. is = new ItemStack(mat, 1, (byte)0, (byte)0);
  150. PP.addXP(SkillType.HERBALISM, LoadProperties.mwheat, player);
  151. if(player != null)
  152. {
  153. if(Math.random() * 1000 <= PP.getSkillLevel(SkillType.HERBALISM))
  154. {
  155. m.mcDropItem(loc, is);
  156. }
  157. }
  158. //GREEN THUMB
  159. if(Math.random() * 1500 <= PP.getSkillLevel(SkillType.HERBALISM))
  160. {
  161. event.setCancelled(true);
  162. m.mcDropItem(loc, is);
  163. //DROP SOME SEEDS
  164. mat = Material.SEEDS;
  165. is = new ItemStack(mat, 1, (byte)0, (byte)0);
  166. m.mcDropItem(loc, is);
  167. block.setData((byte) 0x1); //Change it to first stage
  168. //Setup the bonuses
  169. int bonus = 0;
  170. if(PP.getSkillLevel(SkillType.HERBALISM) >= 200)
  171. bonus++;
  172. if(PP.getSkillLevel(SkillType.HERBALISM) >= 400)
  173. bonus++;
  174. if(PP.getSkillLevel(SkillType.HERBALISM) >= 600)
  175. bonus++;
  176. //Change wheat to be whatever stage based on the bonus
  177. if(bonus == 1)
  178. block.setData((byte) 0x2);
  179. if(bonus == 2)
  180. block.setData((byte) 0x3);
  181. if(bonus == 3)
  182. block.setData((byte) 0x4);
  183. }
  184. }
  185. /*
  186. * We need to check not-wheat stuff for if it was placed by the player or not
  187. */
  188. if(block.getData() != (byte) 5)
  189. {
  190. //Cactus
  191. if(type == 81){
  192. //Setup the loop
  193. World world = block.getWorld();
  194. Block[] blockArray = new Block[3];
  195. blockArray[0] = block;
  196. blockArray[1] = world.getBlockAt(block.getX(), block.getY()+1, block.getZ());
  197. blockArray[2] = world.getBlockAt(block.getX(), block.getY()+2, block.getZ());
  198. Material[] materialArray = new Material[3];
  199. materialArray[0] = blockArray[0].getType();
  200. materialArray[1] = blockArray[1].getType();
  201. materialArray[2] = blockArray[2].getType();
  202. byte[] byteArray = new byte[3];
  203. byteArray[0] = blockArray[0].getData();
  204. byteArray[1] = blockArray[0].getData();
  205. byteArray[2] = blockArray[0].getData();
  206. int x = 0;
  207. for(Block target : blockArray)
  208. {
  209. if(materialArray[x] == Material.CACTUS)
  210. {
  211. is = new ItemStack(Material.CACTUS, 1, (byte)0, (byte)0);
  212. if(byteArray[x] != (byte) 5)
  213. {
  214. if(Math.random() * 1000 <= PP.getSkillLevel(SkillType.HERBALISM))
  215. {
  216. m.mcDropItem(target.getLocation(), is);
  217. }
  218. PP.addXP(SkillType.HERBALISM, LoadProperties.mcactus, player);
  219. }
  220. }
  221. x++;
  222. }
  223. }
  224. //Sugar Canes
  225. if(type == 83)
  226. {
  227. //Setup the loop
  228. World world = block.getWorld();
  229. Block[] blockArray = new Block[3];
  230. blockArray[0] = block;
  231. blockArray[1] = world.getBlockAt(block.getX(), block.getY()+1, block.getZ());
  232. blockArray[2] = world.getBlockAt(block.getX(), block.getY()+2, block.getZ());
  233. Material[] materialArray = new Material[3];
  234. materialArray[0] = blockArray[0].getType();
  235. materialArray[1] = blockArray[1].getType();
  236. materialArray[2] = blockArray[2].getType();
  237. byte[] byteArray = new byte[3];
  238. byteArray[0] = blockArray[0].getData();
  239. byteArray[1] = blockArray[0].getData();
  240. byteArray[2] = blockArray[0].getData();
  241. int x = 0;
  242. for(Block target : blockArray)
  243. {
  244. if(materialArray[x] == Material.SUGAR_CANE_BLOCK)
  245. {
  246. is = new ItemStack(Material.SUGAR_CANE, 1, (byte)0, (byte)0);
  247. //Check for being placed by the player
  248. if(byteArray[x] != (byte) 5)
  249. {
  250. if(Math.random() * 1000 <= PP.getSkillLevel(SkillType.HERBALISM))
  251. {
  252. m.mcDropItem(target.getLocation(), is);
  253. }
  254. PP.addXP(SkillType.HERBALISM, LoadProperties.msugar, player);
  255. }
  256. }
  257. x++;
  258. }
  259. }
  260. //Pumpkins
  261. if((type == 91 || type == 86))
  262. {
  263. mat = Material.getMaterial(block.getTypeId());
  264. is = new ItemStack(mat, 1, (byte)0, (byte)0);
  265. if(player != null)
  266. {
  267. if(Math.random() * 1000 <= PP.getSkillLevel(SkillType.HERBALISM))
  268. {
  269. m.mcDropItem(loc, is);
  270. }
  271. }
  272. PP.addXP(SkillType.HERBALISM, LoadProperties.mpumpkin, player);
  273. }
  274. //Melon
  275. if(type == 103)
  276. {
  277. mat = Material.getMaterial(block.getTypeId());
  278. is = new ItemStack(mat, 1, (byte)0, (byte)0);
  279. if(Math.random() * 1000 <= PP.getSkillLevel(SkillType.HERBALISM))
  280. {
  281. m.mcDropItem(loc, is);
  282. }
  283. PP.addXP(SkillType.HERBALISM, LoadProperties.mmelon, player);
  284. }
  285. //Mushroom
  286. if(type == 39 || type == 40)
  287. {
  288. mat = Material.getMaterial(block.getTypeId());
  289. is = new ItemStack(mat, 1, (byte)0, (byte)0);
  290. if(player != null)
  291. {
  292. if(Math.random() * 1000 <= PP.getSkillLevel(SkillType.HERBALISM))
  293. {
  294. m.mcDropItem(loc, is);
  295. }
  296. }
  297. PP.addXP(SkillType.HERBALISM, LoadProperties.mmushroom, player);
  298. }
  299. //Flower
  300. if(type == 37 || type == 38){
  301. mat = Material.getMaterial(block.getTypeId());
  302. is = new ItemStack(mat, 1, (byte)0, (byte)0);
  303. if(player != null){
  304. if(Math.random() * 1000 <= PP.getSkillLevel(SkillType.HERBALISM)){
  305. m.mcDropItem(loc, is);
  306. }
  307. }
  308. PP.addXP(SkillType.HERBALISM, LoadProperties.mflower, player);
  309. }
  310. }
  311. Skills.XpCheckSkill(SkillType.HERBALISM, player);
  312. }
  313. }