Herbalism.java 11 KB

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