Herbalism.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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.AbilityType;
  27. import com.gmail.nossr50.datatypes.PlayerProfile;
  28. import com.gmail.nossr50.datatypes.SkillType;
  29. import com.gmail.nossr50.locale.mcLocale;
  30. public class Herbalism
  31. {
  32. public static void greenTerraCheck(Player player, Block block)
  33. {
  34. PlayerProfile PP = Users.getProfile(player);
  35. if(m.isHoe(player.getItemInHand()))
  36. {
  37. if(block != null)
  38. {
  39. if(!m.abilityBlockCheck(block))
  40. return;
  41. }
  42. if(PP.getHoePreparationMode())
  43. {
  44. PP.setHoePreparationMode(false);
  45. }
  46. int ticks = 2;
  47. int x = PP.getSkillLevel(SkillType.HERBALISM);
  48. while(x >= 50)
  49. {
  50. x-=50;
  51. ticks++;
  52. }
  53. if(!PP.getGreenTerraMode() && Skills.cooldownOver(player, PP.getSkillDATS(AbilityType.GREEN_TERRA), LoadProperties.greenTerraCooldown))
  54. {
  55. player.sendMessage(mcLocale.getString("Skills.GreenTerraOn"));
  56. for(Player y : player.getWorld().getPlayers())
  57. {
  58. if(y != null && y != player && m.getDistance(player.getLocation(), y.getLocation()) < 10)
  59. y.sendMessage(mcLocale.getString("Skills.GreenTerraPlayer", new Object[] {player.getName()}));
  60. }
  61. PP.setSkillDATS(AbilityType.GREEN_TERRA, 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. return 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. }
  106. public static boolean hasSeeds(Player player){
  107. ItemStack[] inventory = player.getInventory().getContents();
  108. for(ItemStack x : inventory){
  109. if(x != null && x.getTypeId() == 295){
  110. return true;
  111. }
  112. }
  113. return false;
  114. }
  115. public static void removeSeeds(Player player){
  116. ItemStack[] inventory = player.getInventory().getContents();
  117. for(ItemStack x : inventory){
  118. if(x != null && x.getTypeId() == 295){
  119. if(x.getAmount() == 1){
  120. x.setTypeId(0);
  121. x.setAmount(0);
  122. player.getInventory().setContents(inventory);
  123. } else{
  124. x.setAmount(x.getAmount() - 1);
  125. player.getInventory().setContents(inventory);
  126. }
  127. return;
  128. }
  129. }
  130. }
  131. public static void herbalismProcCheck(Block block, Player player, BlockBreakEvent event, mcMMO plugin)
  132. {
  133. PlayerProfile PP = Users.getProfile(player);
  134. int herbLevel = PP.getSkillLevel(SkillType.HERBALISM);
  135. int type = block.getTypeId();
  136. Location loc = block.getLocation();
  137. ItemStack is = null;
  138. Material mat = null;
  139. if(plugin.misc.blockWatchList.contains(block))
  140. {
  141. return;
  142. }
  143. //Wheat
  144. if(type == 59 && block.getData() == (byte) 0x7)
  145. {
  146. mat = Material.getMaterial(296);
  147. is = new ItemStack(mat, 1, (byte)0, (byte)0);
  148. PP.addXP(SkillType.HERBALISM, LoadProperties.mwheat, player);
  149. if(player != null)
  150. {
  151. if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
  152. m.mcDropItem(loc, is);
  153. }
  154. //GREEN THUMB
  155. if(!PP.getGreenTerraMode() && (herbLevel > 1500 || (Math.random() * 1500 <= herbLevel)))
  156. {
  157. System.out.println("DEBUG: GREEN THUMB ACTIVATED");
  158. event.setCancelled(true);
  159. m.mcDropItem(loc, is);
  160. //DROP SOME SEEDS
  161. mat = Material.SEEDS;
  162. is = new ItemStack(mat, 1, (byte)0, (byte)0);
  163. m.mcDropItem(loc, is);
  164. //This replants the wheat at a certain stage in development based on Herbalism Skill
  165. if(PP.getSkillLevel(SkillType.HERBALISM) >= 600)
  166. block.setData((byte) 0x4);
  167. else if(PP.getSkillLevel(SkillType.HERBALISM) >= 400)
  168. block.setData((byte) 0x3);
  169. else if(PP.getSkillLevel(SkillType.HERBALISM) >= 200)
  170. block.setData((byte) 0x2);
  171. else
  172. block.setData((byte) 0x1);
  173. }
  174. }
  175. //Nether Wart
  176. if(type == 115 && block.getData() == (byte) 0x3)
  177. {
  178. mat = Material.getMaterial(372);
  179. is = new ItemStack(mat, 1, (byte)0, (byte)0);
  180. PP.addXP(SkillType.HERBALISM, LoadProperties.mnetherwart, player);
  181. if(player != null)
  182. {
  183. if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
  184. {
  185. m.mcDropItem(loc, is);
  186. m.mcDropItem(loc, is);
  187. if(Math.random() * 10 > 5)
  188. m.mcDropItem(loc, is);
  189. if(Math.random() * 10 > 5)
  190. m.mcDropItem(loc, is);
  191. if(Math.random() * 10 > 5)
  192. m.mcDropItem(loc, is);
  193. }
  194. }
  195. }
  196. /*
  197. * We need to check not-wheat and not-netherwart stuff for if it was placed by the player or not
  198. */
  199. if(block.getData() != (byte) 5)
  200. {
  201. //Cactus
  202. if(type == 81){
  203. //Setup the loop
  204. World world = block.getWorld();
  205. Block[] blockArray = new Block[3];
  206. blockArray[0] = block;
  207. blockArray[1] = world.getBlockAt(block.getX(), block.getY()+1, block.getZ());
  208. blockArray[2] = world.getBlockAt(block.getX(), block.getY()+2, block.getZ());
  209. Material[] materialArray = new Material[3];
  210. materialArray[0] = blockArray[0].getType();
  211. materialArray[1] = blockArray[1].getType();
  212. materialArray[2] = blockArray[2].getType();
  213. byte[] byteArray = new byte[3];
  214. byteArray[0] = blockArray[0].getData();
  215. byteArray[1] = blockArray[0].getData();
  216. byteArray[2] = blockArray[0].getData();
  217. int x = 0;
  218. for(Block target : blockArray)
  219. {
  220. if(materialArray[x] == Material.CACTUS)
  221. {
  222. is = new ItemStack(Material.CACTUS, 1, (byte)0, (byte)0);
  223. if(byteArray[x] != (byte) 5)
  224. {
  225. if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
  226. {
  227. m.mcDropItem(target.getLocation(), is);
  228. }
  229. PP.addXP(SkillType.HERBALISM, LoadProperties.mcactus, player);
  230. }
  231. }
  232. x++;
  233. }
  234. }
  235. //Sugar Canes
  236. if(type == 83)
  237. {
  238. //Setup the loop
  239. World world = block.getWorld();
  240. Block[] blockArray = new Block[3];
  241. blockArray[0] = block;
  242. blockArray[1] = world.getBlockAt(block.getX(), block.getY()+1, block.getZ());
  243. blockArray[2] = world.getBlockAt(block.getX(), block.getY()+2, block.getZ());
  244. Material[] materialArray = new Material[3];
  245. materialArray[0] = blockArray[0].getType();
  246. materialArray[1] = blockArray[1].getType();
  247. materialArray[2] = blockArray[2].getType();
  248. byte[] byteArray = new byte[3];
  249. byteArray[0] = blockArray[0].getData();
  250. byteArray[1] = blockArray[0].getData();
  251. byteArray[2] = blockArray[0].getData();
  252. int x = 0;
  253. for(Block target : blockArray)
  254. {
  255. if(materialArray[x] == Material.SUGAR_CANE_BLOCK)
  256. {
  257. is = new ItemStack(Material.SUGAR_CANE, 1, (byte)0, (byte)0);
  258. //Check for being placed by the player
  259. if(byteArray[x] != (byte) 5)
  260. {
  261. if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
  262. {
  263. m.mcDropItem(target.getLocation(), is);
  264. }
  265. PP.addXP(SkillType.HERBALISM, LoadProperties.msugar, player);
  266. }
  267. }
  268. x++;
  269. }
  270. }
  271. //Pumpkins
  272. if((type == 91 || type == 86))
  273. {
  274. mat = Material.getMaterial(block.getTypeId());
  275. is = new ItemStack(mat, 1, (byte)0, (byte)0);
  276. if(player != null)
  277. {
  278. if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
  279. {
  280. m.mcDropItem(loc, is);
  281. }
  282. }
  283. PP.addXP(SkillType.HERBALISM, LoadProperties.mpumpkin, player);
  284. }
  285. //Melon
  286. if(type == 103)
  287. {
  288. mat = Material.getMaterial(360);
  289. is = new ItemStack(mat, 1, (byte)0, (byte)0);
  290. if(player != null)
  291. {
  292. if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
  293. {
  294. m.mcDropItem(loc, is);
  295. m.mcDropItem(loc, is);
  296. m.mcDropItem(loc, is);
  297. if(Math.random() * 10 > 5)
  298. m.mcDropItem(loc, is);
  299. if(Math.random() * 10 > 5)
  300. m.mcDropItem(loc, is);
  301. if(Math.random() * 10 > 5)
  302. m.mcDropItem(loc, is);
  303. if(Math.random() * 10 > 5)
  304. m.mcDropItem(loc, is);
  305. }
  306. }
  307. PP.addXP(SkillType.HERBALISM, LoadProperties.mmelon, player);
  308. }
  309. //Mushroom
  310. if(type == 39 || type == 40)
  311. {
  312. mat = Material.getMaterial(block.getTypeId());
  313. is = new ItemStack(mat, 1, (byte)0, (byte)0);
  314. if(player != null)
  315. {
  316. if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
  317. {
  318. m.mcDropItem(loc, is);
  319. }
  320. }
  321. PP.addXP(SkillType.HERBALISM, LoadProperties.mmushroom, player);
  322. }
  323. //Flower
  324. if(type == 37 || type == 38){
  325. mat = Material.getMaterial(block.getTypeId());
  326. is = new ItemStack(mat, 1, (byte)0, (byte)0);
  327. if(player != null){
  328. if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
  329. m.mcDropItem(loc, is);
  330. }
  331. PP.addXP(SkillType.HERBALISM, LoadProperties.mflower, player);
  332. }
  333. //Lily Pads
  334. if(type == 111)
  335. {
  336. mat = Material.getMaterial(block.getTypeId());
  337. is = new ItemStack(mat, 1, (byte)0, (byte)0);
  338. if(player != null){
  339. if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
  340. m.mcDropItem(loc, is);
  341. }
  342. PP.addXP(SkillType.HERBALISM, LoadProperties.mlilypad, player);
  343. }
  344. //Vines
  345. if(type == 106){
  346. mat = Material.getMaterial(block.getTypeId());
  347. is = new ItemStack(mat, 1, (byte)0, (byte)0);
  348. if(player != null){
  349. if(herbLevel > 1000 || (Math.random() * 1000 <= herbLevel))
  350. m.mcDropItem(loc, is);
  351. }
  352. PP.addXP(SkillType.HERBALISM, LoadProperties.mvines, player);
  353. }
  354. }
  355. Skills.XpCheckSkill(SkillType.HERBALISM, player);
  356. }
  357. }