Repair.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. package com.gmail.nossr50.skills.repair;
  2. import java.util.Map;
  3. import java.util.Random;
  4. import java.util.Map.Entry;
  5. import org.bukkit.ChatColor;
  6. import org.bukkit.Material;
  7. import org.bukkit.enchantments.Enchantment;
  8. import org.bukkit.entity.Player;
  9. import org.bukkit.inventory.ItemStack;
  10. import org.bukkit.inventory.PlayerInventory;
  11. import org.getspout.spoutapi.SpoutManager;
  12. import org.getspout.spoutapi.player.SpoutPlayer;
  13. import com.gmail.nossr50.mcMMO;
  14. import com.gmail.nossr50.config.Config;
  15. import com.gmail.nossr50.spout.SpoutSounds;
  16. import com.gmail.nossr50.util.ItemChecks;
  17. import com.gmail.nossr50.util.Misc;
  18. import com.gmail.nossr50.util.ModChecks;
  19. import com.gmail.nossr50.util.Permissions;
  20. import com.gmail.nossr50.util.Skills;
  21. import com.gmail.nossr50.util.Users;
  22. import com.gmail.nossr50.datatypes.PlayerProfile;
  23. import com.gmail.nossr50.datatypes.SkillType;
  24. import com.gmail.nossr50.datatypes.mods.CustomItem;
  25. import com.gmail.nossr50.datatypes.mods.CustomTool;
  26. import com.gmail.nossr50.events.skills.McMMOPlayerRepairCheckEvent;
  27. import com.gmail.nossr50.locale.LocaleLoader;
  28. public class Repair {
  29. private static Random random = new Random();
  30. private static Config configInstance = Config.getInstance();
  31. private static Permissions permInstance = Permissions.getInstance();
  32. /**
  33. * Handle all the item repair checks.
  34. *
  35. * @param player Player repairing the item
  36. * @param is The item being repaired
  37. */
  38. public static void repairCheck(Player player, ItemStack is) {
  39. PlayerProfile PP = Users.getProfile(player);
  40. short durabilityBefore = is.getDurability();
  41. PlayerInventory inventory = player.getInventory();
  42. int skillLevel = PP.getSkillLevel(SkillType.REPAIR);
  43. if (durabilityBefore > 0 && is.getAmount() == 1) {
  44. /*
  45. * REPAIR ARMOR
  46. */
  47. if (ItemChecks.isArmor(is) && permInstance.armorRepair(player)) {
  48. if (ItemChecks.isDiamondArmor(is) && inventory.contains(configInstance.getRepairDiamondMaterial()) && skillLevel >= configInstance.getRepairDiamondLevelRequirement() && permInstance.diamondRepair(player)) {
  49. repairItem(player, is, new ItemStack(configInstance.getRepairDiamondMaterial()));
  50. xpHandler(player, PP, is, durabilityBefore, 6);
  51. }
  52. else if (ItemChecks.isIronArmor(is) && inventory.contains(configInstance.getRepairIronMaterial()) && skillLevel >= configInstance.getRepairIronLevelRequirement() && permInstance.ironRepair(player)) {
  53. repairItem(player, is, new ItemStack(configInstance.getRepairIronMaterial()));
  54. xpHandler(player, PP, is, durabilityBefore, 2);
  55. }
  56. else if (ItemChecks.isGoldArmor(is) && inventory.contains(configInstance.getRepairGoldMaterial()) && skillLevel >= configInstance.getRepairGoldLevelRequirement() && permInstance.goldRepair(player)) {
  57. repairItem(player, is, new ItemStack(configInstance.getRepairGoldMaterial()));
  58. xpHandler(player, PP, is, durabilityBefore, 4);
  59. }
  60. else if (ItemChecks.isLeatherArmor(is) && inventory.contains(configInstance.getRepairLeatherMaterial()) && permInstance.leatherRepair(player)) {
  61. repairItem(player, is, new ItemStack(configInstance.getRepairLeatherMaterial()));
  62. xpHandler(player, PP, is, durabilityBefore, 1);
  63. }
  64. else {
  65. needMoreVespeneGas(is, player); //UNABLE TO REPAIR
  66. }
  67. }
  68. /*
  69. * REPAIR TOOLS
  70. */
  71. else if (ItemChecks.isTool(is) && permInstance.toolRepair(player)) {
  72. if (ItemChecks.isStoneTool(is) && inventory.contains(configInstance.getRepairStoneMaterial()) && skillLevel >= configInstance.getRepairStoneLevelRequirement() && permInstance.stoneRepair(player)) {
  73. repairItem(player, is, new ItemStack(configInstance.getRepairStoneMaterial()));
  74. xpHandler(player, PP, is, durabilityBefore, .5);
  75. }
  76. else if (ItemChecks.isWoodTool(is) && inventory.contains(configInstance.getRepairWoodMaterial()) && permInstance.woodRepair(player)) {
  77. repairItem(player, is, new ItemStack(configInstance.getRepairWoodMaterial()));
  78. xpHandler(player, PP, is, durabilityBefore, .5);
  79. }
  80. else if (ItemChecks.isIronTool(is) && inventory.contains(configInstance.getRepairIronMaterial()) && skillLevel >= configInstance.getRepairIronLevelRequirement() && permInstance.ironRepair(player)) {
  81. repairItem(player, is, new ItemStack(configInstance.getRepairIronMaterial()));
  82. xpHandler(player, PP, is, durabilityBefore, 1);
  83. }
  84. else if (ItemChecks.isDiamondTool(is) && inventory.contains(configInstance.getRepairDiamondMaterial()) && skillLevel >= configInstance.getRepairDiamondLevelRequirement() && permInstance.diamondRepair(player)) {
  85. repairItem(player, is, new ItemStack(configInstance.getRepairDiamondMaterial()));
  86. xpHandler(player, PP, is, durabilityBefore, 1);
  87. }
  88. else if (ItemChecks.isGoldTool(is) && inventory.contains(configInstance.getRepairGoldMaterial()) && skillLevel >= configInstance.getRepairGoldLevelRequirement() && permInstance.goldRepair(player)) {
  89. repairItem(player, is, new ItemStack(configInstance.getRepairGoldMaterial()));
  90. xpHandler(player, PP, is, durabilityBefore, 8);
  91. }
  92. else if (ItemChecks.isStringTool(is) && inventory.contains(configInstance.getRepairStringMaterial()) && permInstance.stringRepair(player)){
  93. repairItem(player, is, new ItemStack(configInstance.getRepairStringMaterial()));
  94. xpHandler(player, PP, is, durabilityBefore, .5);
  95. }
  96. else {
  97. needMoreVespeneGas(is, player); //UNABLE TO REPAIR
  98. }
  99. }
  100. /*
  101. * REPAIR CUSTOM TOOLS
  102. */
  103. else if (ModChecks.isCustomTool(is) && permInstance.toolRepair(player)) {
  104. ItemStack repairMaterial = ModChecks.getToolFromItemStack(is).getRepairMaterial();
  105. if (inventory.contains(repairMaterial)) {
  106. repairCustomItem(player, is, repairMaterial);
  107. xpHandler(player, PP, is, durabilityBefore, 1);
  108. }
  109. else {
  110. needMoreVespeneGas(is, player);
  111. }
  112. }
  113. /*
  114. * REPAIR CUSTOM ARMOR
  115. */
  116. else if (ModChecks.isCustomArmor(is) && permInstance.armorRepair(player)) {
  117. ItemStack repairMaterial = ModChecks.getArmorFromItemStack(is).getRepairMaterial();
  118. if (inventory.contains(repairMaterial)) {
  119. repairCustomItem(player, is, repairMaterial);
  120. xpHandler(player, PP, is, durabilityBefore, 1);
  121. }
  122. else {
  123. needMoreVespeneGas(is, player);
  124. }
  125. }
  126. }
  127. else {
  128. player.sendMessage(LocaleLoader.getString("Repair.Skills.FullDurability"));
  129. }
  130. }
  131. /**
  132. * Handle the XP gain for repair events.
  133. *
  134. * @param player Player repairing the item
  135. * @param PP PlayerProfile of the repairing player
  136. * @param is Item being repaired
  137. * @param durabilityBefore Durability of the item before repair
  138. * @param modify Amount to modify the durability by
  139. * @param boost True if the modifier is a boost, false if the modifier is a reduction
  140. */
  141. private static void xpHandler(Player player, PlayerProfile PP, ItemStack is, short durabilityBefore, double modify) {
  142. short durabilityAfter = is.getDurability();
  143. short dif = (short) (durabilityBefore - durabilityAfter);
  144. dif = (short) (dif * modify);
  145. //TODO: What exactly is this for, and should we have it for armor as well?
  146. if (ItemChecks.isShovel(is)) {
  147. dif = (short) (dif / 3);
  148. }
  149. else if(ItemChecks.isSword(is)) {
  150. dif = (short) (dif / 2);
  151. }
  152. else if(ItemChecks.isHoe(is)) {
  153. dif = (short) (dif / 2);
  154. }
  155. PP.addXP(player, SkillType.REPAIR, dif * 10);
  156. Skills.XpCheckSkill(SkillType.REPAIR, player);
  157. //CLANG CLANG
  158. if (configInstance.spoutEnabled) {
  159. SpoutSounds.playRepairNoise(player, mcMMO.p);
  160. }
  161. }
  162. /**
  163. * Get current Arcane Forging rank.
  164. *
  165. * @param skillLevel The skill level of the player whose rank is being checked
  166. * @return The player's current Arcane Forging rank
  167. */
  168. public static int getArcaneForgingRank(PlayerProfile PP) {
  169. int skillLevel = PP.getSkillLevel(SkillType.REPAIR);
  170. if (skillLevel >= configInstance.getArcaneForgingRankLevels4()) {
  171. return 4;
  172. }
  173. else if (skillLevel >= configInstance.getArcaneForgingRankLevels3()) {
  174. return 3;
  175. }
  176. else if (skillLevel >= configInstance.getArcaneForgingRankLevels2()) {
  177. return 2;
  178. }
  179. else if (skillLevel >= configInstance.getArcaneForgingRankLevels1()) {
  180. return 1;
  181. }
  182. else {
  183. return 0;
  184. }
  185. }
  186. /**
  187. * Handles removing & downgrading enchants.
  188. *
  189. * @param player Player repairing the item
  190. * @param is Item being repaired
  191. */
  192. protected static void addEnchants(Player player, ItemStack is) {
  193. Map<Enchantment, Integer> enchants = is.getEnchantments();
  194. if (enchants.size() == 0) {
  195. return;
  196. }
  197. int rank = getArcaneForgingRank(Users.getProfile(player));
  198. if (rank == 0 || !permInstance.arcaneForging(player)) {
  199. for (Enchantment x : enchants.keySet()) {
  200. is.removeEnchantment(x);
  201. }
  202. player.sendMessage(LocaleLoader.getString("Repair.Arcane.Lost"));
  203. return;
  204. }
  205. boolean downgraded = false;
  206. for (Entry<Enchantment, Integer> enchant : enchants.entrySet()) {
  207. Enchantment enchantment = enchant.getKey();
  208. if (random.nextInt(100) <= getEnchantChance(rank)) {
  209. int enchantLevel = enchant.getValue();
  210. if (configInstance.getArcaneForgingDowngradeEnabled() && enchantLevel > 1) {
  211. if (random.nextInt(100) <= getDowngradeChance(rank)) {
  212. is.addEnchantment(enchantment, enchantLevel--);
  213. downgraded = true;
  214. }
  215. }
  216. }
  217. else {
  218. is.removeEnchantment(enchantment);
  219. }
  220. }
  221. Map<Enchantment, Integer> newEnchants = is.getEnchantments();
  222. if (newEnchants.isEmpty()) {
  223. player.sendMessage(LocaleLoader.getString("Repair.Arcane.Fail"));
  224. }
  225. else if (downgraded || newEnchants.size() < enchants.size()) {
  226. player.sendMessage(LocaleLoader.getString("Repair.Arcane.Downgrade"));
  227. }
  228. else {
  229. player.sendMessage(LocaleLoader.getString("Repair.Arcane.Perfect"));
  230. }
  231. }
  232. /**
  233. * Gets chance of keeping enchantment during repair.
  234. *
  235. * @param rank Arcane Forging rank
  236. * @return The chance of keeping the enchantment
  237. */
  238. public static int getEnchantChance(int rank) {
  239. switch (rank) {
  240. case 4:
  241. return configInstance.getArcaneForgingKeepEnchantsChanceRank4();
  242. case 3:
  243. return configInstance.getArcaneForgingKeepEnchantsChanceRank3();
  244. case 2:
  245. return configInstance.getArcaneForgingKeepEnchantsChanceRank2();
  246. case 1:
  247. return configInstance.getArcaneForgingKeepEnchantsChanceRank1();
  248. default:
  249. return 0;
  250. }
  251. }
  252. /**
  253. * Gets chance of enchantment being downgraded during repair.
  254. *
  255. * @param rank Arcane Forging rank
  256. * @return The chance of the enchantment being downgraded
  257. */
  258. public static int getDowngradeChance(int rank) {
  259. switch (rank) {
  260. case 4:
  261. return configInstance.getArcaneForgingDowngradeChanceRank4();
  262. case 3:
  263. return configInstance.getArcaneForgingDowngradeChanceRank3();
  264. case 2:
  265. return configInstance.getArcaneForgingDowngradeChanceRank2();
  266. case 1:
  267. return configInstance.getArcaneForgingDowngradeChanceRank1();
  268. default:
  269. return 100;
  270. }
  271. }
  272. /**
  273. * Computes repair bonuses.
  274. *
  275. * @param player The player repairing an item
  276. * @param durability The durability of the item being repaired
  277. * @param repairAmount The base amount of durability repaired to the item
  278. * @return The final amount of durability repaired to the item
  279. */
  280. private static short repairCalculate(Player player, short durability, int repairAmount) {
  281. int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.REPAIR);
  282. return repairCalculate(player, skillLevel, durability, repairAmount);
  283. }
  284. /**
  285. * Computes repair bonuses.
  286. *
  287. * @param player The player repairing an item
  288. * @param skillLevel the skillLevel of the player in Repair
  289. * @param durability The durability of the item being repaired
  290. * @param repairAmount The base amount of durability repaired to the item
  291. * @return The final amount of durability repaired to the item
  292. */
  293. protected static short repairCalculate(Player player, int skillLevel, short durability, int repairAmount) {
  294. float bonus = (float) skillLevel / 500;
  295. if (permInstance.repairMastery(player)) {
  296. bonus = (repairAmount * bonus);
  297. repairAmount += bonus;
  298. }
  299. if (checkPlayerProcRepair(player)) {
  300. repairAmount = (short) (repairAmount * 2);
  301. }
  302. durability -= repairAmount;
  303. if (durability < 0) {
  304. durability = 0;
  305. }
  306. return durability;
  307. }
  308. /**
  309. * Gets the base durability amount to repair an item.
  310. *
  311. * @param is The item being repaired
  312. * @param player The player repairing the item
  313. * @return The final amount of durability repaired to the item
  314. */
  315. private static short getRepairAmount(ItemStack is, Player player){
  316. short maxDurability = is.getType().getMaxDurability();
  317. int repairAmount = 0;
  318. if (ItemChecks.isShovel(is)) {
  319. repairAmount = maxDurability;
  320. }
  321. else if (ItemChecks.isHoe(is) || ItemChecks.isSword(is) || is.getType().equals(Material.SHEARS) || is.getType().equals(Material.FISHING_ROD)) {
  322. repairAmount = maxDurability / 2;
  323. }
  324. else if (ItemChecks.isAxe(is) || ItemChecks.isPickaxe(is) || is.getType().equals(Material.BOW)) {
  325. repairAmount = maxDurability / 3;
  326. }
  327. else if (ItemChecks.isBoots(is)) {
  328. repairAmount = maxDurability / 4;
  329. }
  330. else if (ItemChecks.isHelmet(is)) {
  331. repairAmount = maxDurability / 5;
  332. }
  333. else if (ItemChecks.isPants(is)) {
  334. repairAmount = maxDurability / 7;
  335. }
  336. else if (ItemChecks.isChestplate(is)) {
  337. repairAmount = maxDurability / 8;
  338. }
  339. return repairCalculate(player, is.getDurability(), repairAmount);
  340. }
  341. /**
  342. * Gets the base durability amount to repair a custom item.
  343. *
  344. * @param is The custom item being repaired
  345. * @param player The player repairing the custom item
  346. * @return The final amount of durability repaired to the custom item
  347. */
  348. private static short getCustomRepairAmount(ItemStack is, Player player) {
  349. short maxDurability = 0;
  350. int materialsRequired = 0;
  351. int repairAmount = 0;
  352. CustomTool tool = ModChecks.getToolFromItemStack(is);
  353. CustomItem armor = ModChecks.getArmorFromItemStack(is);
  354. if (tool != null) {
  355. maxDurability = tool.getDurability();
  356. materialsRequired = tool.getRepairQuantity();
  357. }
  358. else if (armor != null) {
  359. maxDurability = armor.getDurability();
  360. materialsRequired = armor.getRepairQuantity();
  361. }
  362. repairAmount = maxDurability / materialsRequired;
  363. return repairCalculate(player, is.getDurability(), repairAmount);
  364. }
  365. /**
  366. * Informs a player that the repair has failed.
  367. *
  368. * @param is The item being repaired
  369. * @param player The player repairing the item
  370. */
  371. private static void needMoreVespeneGas(ItemStack is, Player player) {
  372. int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.REPAIR);
  373. if (is.getAmount() != 1) {
  374. player.sendMessage(LocaleLoader.getString("Repair.Skills.StackedItems"));
  375. }
  376. else {
  377. if (ItemChecks.isDiamondTool(is) || ItemChecks.isDiamondArmor(is)) {
  378. if (skillLevel < configInstance.getRepairDiamondLevelRequirement()) {
  379. player.sendMessage(LocaleLoader.getString("Repair.Skills.AdeptDiamond"));
  380. }
  381. else {
  382. player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.BLUE + Misc.prettyItemString(configInstance.getRepairDiamondMaterial()));
  383. }
  384. }
  385. else if (ItemChecks.isIronTool(is) || ItemChecks.isIronArmor(is)) {
  386. if (skillLevel < configInstance.getRepairIronLevelRequirement()) {
  387. player.sendMessage(LocaleLoader.getString("Repair.Skills.AdeptIron"));
  388. }
  389. else {
  390. player.sendMessage(LocaleLoader.getString("Skills.NeedMore")+ " " + ChatColor.GRAY + Misc.prettyItemString(configInstance.getRepairIronMaterial()));
  391. }
  392. }
  393. else if (ItemChecks.isGoldTool(is) || ItemChecks.isGoldArmor(is)) {
  394. if (skillLevel < configInstance.getRepairGoldLevelRequirement()) {
  395. player.sendMessage(LocaleLoader.getString("Repair.Skills.AdeptGold"));
  396. }
  397. else {
  398. player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.GOLD + Misc.prettyItemString(configInstance.getRepairGoldMaterial()));
  399. }
  400. }
  401. else if (ItemChecks.isStoneTool(is)) {
  402. if (skillLevel < configInstance.getRepairStoneLevelRequirement()) {
  403. player.sendMessage(LocaleLoader.getString("Repair.Skills.AdeptStone"));
  404. }
  405. else {
  406. player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.GRAY + Misc.prettyItemString(configInstance.getRepairStoneMaterial()));
  407. }
  408. }
  409. else if (ItemChecks.isWoodTool(is)) {
  410. player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.DARK_GREEN + Misc.prettyItemString(configInstance.getRepairWoodMaterial()));
  411. }
  412. else if (ItemChecks.isLeatherArmor(is)) {
  413. player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.YELLOW + Misc.prettyItemString(configInstance.getRepairLeatherMaterial()));
  414. }
  415. else if (ItemChecks.isStringTool(is)) {
  416. player.sendMessage(LocaleLoader.getString("Skills.NeedMore") + " " + ChatColor.YELLOW + Misc.prettyItemString(configInstance.getRepairStringMaterial()));
  417. }
  418. else {
  419. player.sendMessage("You do not have the material needed to repair this item!"); //TODO: Use locale
  420. }
  421. }
  422. }
  423. /**
  424. * Checks for Super Repair bonus.
  425. *
  426. * @param player The player repairing an item
  427. * @return true if bonus granted, false otherwise
  428. */
  429. public static boolean checkPlayerProcRepair(Player player) {
  430. final int MAX_BONUS_LEVEL = 1000;
  431. int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.REPAIR);
  432. if ((skillLevel > MAX_BONUS_LEVEL || random.nextInt(1000) <= skillLevel) && permInstance.repairBonus(player)) {
  433. player.sendMessage(LocaleLoader.getString("Repair.Skills.FeltEasy"));
  434. return true;
  435. }
  436. return false;
  437. }
  438. /**
  439. * Repairs an item.
  440. *
  441. * @param player The player repairing an item
  442. * @param item The item being repaired
  443. * @param repairMaterial The repair reagent
  444. */
  445. private static void repairItem(Player player, ItemStack item, ItemStack repairMaterial) {
  446. short initialDurability = item.getDurability();
  447. short newDurability = getRepairAmount(item, player);
  448. PlayerInventory inventory = player.getInventory();
  449. McMMOPlayerRepairCheckEvent event = new McMMOPlayerRepairCheckEvent(player, (short) (initialDurability - newDurability), repairMaterial, item);
  450. mcMMO.p.getServer().getPluginManager().callEvent(event);
  451. if (event.isCancelled()) {
  452. return;
  453. }
  454. if (repairMaterial.getType().equals(Material.WOOD)) {
  455. removeWood(inventory);
  456. }
  457. else {
  458. inventory.removeItem(repairMaterial);
  459. }
  460. /* Handle the enchants */
  461. if (configInstance.getArcaneForgingEnchantLossEnabled() && !permInstance.arcaneBypass(player)) {
  462. addEnchants(player, item);
  463. }
  464. item.setDurability(newDurability);
  465. }
  466. /**
  467. * Repairs a custom item.
  468. *
  469. * @param player The player repairing an item
  470. * @param item The custom item being repaired
  471. * @param repairMaterial The repair reagent
  472. */
  473. private static void repairCustomItem(Player player, ItemStack item, ItemStack repairMaterial) {
  474. short initialDurability = item.getDurability();
  475. short newDurability = getCustomRepairAmount(item, player);
  476. PlayerInventory inventory = player.getInventory();
  477. McMMOPlayerRepairCheckEvent event = new McMMOPlayerRepairCheckEvent(player, (short) (initialDurability - newDurability), repairMaterial, item);
  478. mcMMO.p.getServer().getPluginManager().callEvent(event);
  479. if (event.isCancelled()) {
  480. return;
  481. }
  482. inventory.removeItem(repairMaterial);
  483. if (configInstance.getArcaneForgingEnchantLossEnabled() && !permInstance.arcaneBypass(player)) {
  484. addEnchants(player, item);
  485. }
  486. item.setDurability(newDurability);
  487. }
  488. /**
  489. * Handles notifications for placing an anvil.
  490. *
  491. * @param player The player placing the anvil
  492. * @param anvilID The item ID of the anvil block
  493. */
  494. public static void placedAnvilCheck(Player player, int anvilID) {
  495. PlayerProfile PP = Users.getProfile(player);
  496. if (!PP.getPlacedAnvil()) {
  497. if (configInstance.spoutEnabled) {
  498. SpoutPlayer sPlayer = SpoutManager.getPlayer(player);
  499. if (sPlayer.isSpoutCraftEnabled()) {
  500. sPlayer.sendNotification("[mcMMO] Anvil Placed", "Right click to repair!", Material.getMaterial(anvilID)); //TODO: Use Locale
  501. }
  502. }
  503. else {
  504. player.sendMessage(LocaleLoader.getString("Repair.Listener.Anvil"));
  505. }
  506. PP.togglePlacedAnvil();
  507. }
  508. }
  509. /**
  510. * Removes wood from a player's inventory on repair. Needed due to wood having multiple possible data values.
  511. *
  512. * @param inventory The inventory to remove wood from
  513. */
  514. private static void removeWood(PlayerInventory inventory) {
  515. //TODO: Make this less hackish once there's a better way to do it...
  516. int slot = inventory.first(Material.WOOD);
  517. ItemStack item = inventory.getItem(slot);
  518. item.setAmount(item.getAmount() - 1);
  519. inventory.setItem(slot, item);
  520. }
  521. }