Repair.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  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.Material;
  16. import org.bukkit.ChatColor;
  17. import org.bukkit.block.Block;
  18. import org.bukkit.enchantments.Enchantment;
  19. import org.bukkit.entity.Player;
  20. import org.bukkit.inventory.ItemStack;
  21. import com.gmail.nossr50.Users;
  22. import com.gmail.nossr50.m;
  23. import com.gmail.nossr50.mcPermissions;
  24. import com.gmail.nossr50.config.LoadProperties;
  25. import com.gmail.nossr50.spout.SpoutStuff;
  26. import com.gmail.nossr50.datatypes.PlayerProfile;
  27. import com.gmail.nossr50.datatypes.SkillType;
  28. import com.gmail.nossr50.locale.mcLocale;
  29. public class Repair {
  30. /*
  31. * Repair requirements for each material
  32. */
  33. private static int rGold = LoadProperties.rGold;
  34. private static String nGold = LoadProperties.nGold;
  35. private static int rStone = LoadProperties.rStone;
  36. private static String nStone = LoadProperties.nStone;
  37. private static int rWood = LoadProperties.rWood;
  38. private static String nWood = LoadProperties.nWood;
  39. private static int rDiamond = LoadProperties.rDiamond;
  40. private static String nDiamond = LoadProperties.nDiamond;
  41. private static int rIron = LoadProperties.rIron;
  42. private static String nIron = LoadProperties.nIron;
  43. private static int rString = LoadProperties.rString;
  44. private static String nString = LoadProperties.nString;
  45. private static int rLeather = LoadProperties.rLeather;
  46. private static String nLeather = LoadProperties.nLeather;
  47. public static void repairCheck(Player player, ItemStack is, Block block){
  48. PlayerProfile PP = Users.getProfile(player);
  49. short durabilityBefore = player.getItemInHand().getDurability();
  50. short durabilityAfter = 0;
  51. short dif = 0;
  52. //Stuff for keeping enchants
  53. Enchantment[] enchants = new Enchantment[is.getEnchantments().size()];
  54. int[] enchantsLevel = new int[is.getEnchantments().size()];
  55. int pos = 0;
  56. for(Enchantment x : is.getEnchantments().keySet())
  57. {
  58. enchants[pos] = x;
  59. enchantsLevel[pos] = is.getEnchantmentLevel(x);
  60. pos++;
  61. }
  62. if(block != null && mcPermissions.getInstance().repair(player)){
  63. if(player.getItemInHand().getDurability() > 0 && player.getItemInHand().getAmount() < 2){
  64. /*
  65. * REPAIR ARMOR
  66. */
  67. if(isArmor(is)){
  68. //DIAMOND ARMOR
  69. if(isDiamondArmor(is) && hasItem(player, rDiamond) && PP.getSkillLevel(SkillType.REPAIR) >= LoadProperties.repairdiamondlevel){
  70. removeItem(player, rDiamond);
  71. repairItem(player, enchants, enchantsLevel);
  72. durabilityAfter = player.getItemInHand().getDurability();
  73. dif = (short) (durabilityBefore - durabilityAfter);
  74. dif = (short) (dif * 6); //Boost XP
  75. PP.addXP(SkillType.REPAIR, dif*10, player);
  76. //CLANG CLANG
  77. if(LoadProperties.spoutEnabled)
  78. SpoutStuff.playRepairNoise(player);
  79. }
  80. //IRON ARMOR
  81. else if (isIronArmor(is) && hasItem(player, rIron)){
  82. removeItem(player, rIron);
  83. repairItem(player, enchants, enchantsLevel);
  84. durabilityAfter = player.getItemInHand().getDurability();
  85. dif = (short) (durabilityBefore - durabilityAfter);
  86. dif = (short) (dif * 2); //Boost XP
  87. PP.addXP(SkillType.REPAIR, dif*10, player);
  88. //CLANG CLANG
  89. if(LoadProperties.spoutEnabled)
  90. SpoutStuff.playRepairNoise(player);
  91. }
  92. //GOLD ARMOR
  93. else if (isGoldArmor(is) && hasItem(player, rGold)){
  94. removeItem(player, rGold);
  95. repairItem(player, enchants, enchantsLevel);
  96. durabilityAfter = player.getItemInHand().getDurability();
  97. dif = (short) (durabilityBefore - durabilityAfter);
  98. dif = (short) (dif * 4); //Boost XP
  99. PP.addXP(SkillType.REPAIR, dif*10, player);
  100. //CLANG CLANG
  101. if(LoadProperties.spoutEnabled)
  102. SpoutStuff.playRepairNoise(player);
  103. }
  104. //LEATHER ARMOR
  105. else if (isLeatherArmor(is) && hasItem(player, rLeather)){
  106. removeItem(player, rLeather);
  107. repairItem(player, enchants, enchantsLevel);
  108. durabilityAfter = player.getItemInHand().getDurability();
  109. dif = (short) (durabilityBefore - durabilityAfter);
  110. dif = (short) (dif * 1); //Boost XP
  111. PP.addXP(SkillType.REPAIR, dif*10, player);
  112. //CLANG CLANG
  113. if(LoadProperties.spoutEnabled)
  114. SpoutStuff.playRepairNoise(player);
  115. }
  116. //UNABLE TO REPAIR
  117. else {
  118. needMoreVespeneGas(is, player);
  119. }
  120. }
  121. /*
  122. * REPAIR TOOLS
  123. */
  124. if(isTools(is)){
  125. //STONE TOOLS
  126. if(isStoneTools(is) && hasItem(player, rStone)){
  127. removeItem(player, rStone);
  128. repairItem(player, enchants, enchantsLevel);
  129. durabilityAfter = player.getItemInHand().getDurability();
  130. dif = (short) (durabilityBefore - durabilityAfter);
  131. if(m.isShovel(is))
  132. dif = (short) (dif / 3);
  133. if(m.isSwords(is))
  134. dif = (short) (dif / 2);
  135. if(m.isHoe(is))
  136. dif = (short) (dif / 2);
  137. //STONE NERF
  138. dif = (short) (dif / 2);
  139. PP.addXP(SkillType.REPAIR, dif*10, player);
  140. }
  141. //WOOD TOOLS
  142. else if(isWoodTools(is) && hasItem(player,rWood)){
  143. removeItem(player,rWood);
  144. repairItem(player, enchants, enchantsLevel);
  145. durabilityAfter = player.getItemInHand().getDurability();
  146. dif = (short) (durabilityBefore - durabilityAfter);
  147. if(m.isShovel(is))
  148. dif = (short) (dif / 3);
  149. if(m.isSwords(is))
  150. dif = (short) (dif / 2);
  151. if(m.isHoe(is))
  152. dif = (short) (dif / 2);
  153. //WOOD NERF
  154. dif = (short) (dif / 2);
  155. PP.addXP(SkillType.REPAIR, dif*10, player);
  156. }
  157. //IRON TOOLS
  158. else if(isIronTools(is) && hasItem(player, rIron)){
  159. removeItem(player, rIron);
  160. repairItem(player, enchants, enchantsLevel);
  161. durabilityAfter = player.getItemInHand().getDurability();
  162. dif = (short) (durabilityBefore - durabilityAfter);
  163. if(m.isShovel(is))
  164. dif = (short) (dif / 3);
  165. if(m.isSwords(is))
  166. dif = (short) (dif / 2);
  167. if(m.isHoe(is))
  168. dif = (short) (dif / 2);
  169. PP.addXP(SkillType.REPAIR, dif*10, player);
  170. //CLANG CLANG
  171. if(LoadProperties.spoutEnabled)
  172. SpoutStuff.playRepairNoise(player);
  173. }
  174. //DIAMOND TOOLS
  175. else if (isDiamondTools(is) && hasItem(player, rDiamond) && PP.getSkillLevel(SkillType.REPAIR) >= LoadProperties.repairdiamondlevel){
  176. removeItem(player, rDiamond);
  177. repairItem(player, enchants, enchantsLevel);
  178. durabilityAfter = player.getItemInHand().getDurability();
  179. dif = (short) (durabilityBefore - durabilityAfter);
  180. if(m.isShovel(is))
  181. dif = (short) (dif / 3);
  182. if(m.isSwords(is))
  183. dif = (short) (dif / 2);
  184. if(m.isHoe(is))
  185. dif = (short) (dif / 2);
  186. PP.addXP(SkillType.REPAIR, dif*10, player);
  187. //CLANG CLANG
  188. if(LoadProperties.spoutEnabled)
  189. SpoutStuff.playRepairNoise(player);
  190. }
  191. //GOLD TOOLS
  192. else if(isGoldTools(is) && hasItem(player, rGold)){
  193. removeItem(player, rGold);
  194. repairItem(player, enchants, enchantsLevel);
  195. durabilityAfter = player.getItemInHand().getDurability();
  196. dif = (short) (durabilityBefore - durabilityAfter);
  197. dif = (short) (dif * 7.6); //Boost XP for Gold to that of around Iron
  198. if(m.isShovel(is))
  199. dif = (short) (dif / 3);
  200. if(m.isSwords(is))
  201. dif = (short) (dif / 2);
  202. if(m.isHoe(is))
  203. dif = (short) (dif / 2);
  204. PP.addXP(SkillType.REPAIR, dif*10, player);
  205. //CLANG CLANG
  206. if(LoadProperties.spoutEnabled)
  207. SpoutStuff.playRepairNoise(player);
  208. }
  209. //BOW
  210. else if(isBow(is) && hasItem(player, rString)){
  211. removeItem(player, rString);
  212. repairItem(player, enchants, enchantsLevel);
  213. durabilityAfter = player.getItemInHand().getDurability();
  214. dif = (short) (durabilityBefore - durabilityAfter);
  215. //STRING NERF
  216. dif = (short) (dif / 2);
  217. PP.addXP(SkillType.REPAIR, dif*10, player);
  218. //CLANG CLANG
  219. if(LoadProperties.spoutEnabled)
  220. SpoutStuff.playRepairNoise(player);
  221. }
  222. //UNABLE TO REPAIR
  223. else {
  224. needMoreVespeneGas(is, player);
  225. }
  226. }
  227. }
  228. else {
  229. player.sendMessage(mcLocale.getString("Skills.FullDurability"));
  230. }
  231. /*
  232. * GIVE SKILL IF THERE IS ENOUGH XP
  233. */
  234. Skills.XpCheckSkill(SkillType.REPAIR, player);
  235. }
  236. }
  237. public static int getArcaneForgingRank(PlayerProfile PP){
  238. int rank = 0;
  239. if(PP.getSkillLevel(SkillType.REPAIR) >= 750)
  240. rank = 4;
  241. else if (PP.getSkillLevel(SkillType.REPAIR) >= 500)
  242. rank = 3;
  243. else if(PP.getSkillLevel(SkillType.REPAIR) >= 250)
  244. rank = 2;
  245. else if (PP.getSkillLevel(SkillType.REPAIR) >= 100)
  246. rank = 1;
  247. return rank;
  248. }
  249. public static void addEnchants(ItemStack is, Enchantment[] enchants, int[] enchantsLvl, PlayerProfile PP, Player player){
  250. if(is.getEnchantments().keySet().size() == 0)
  251. return;
  252. int pos = 0;
  253. int rank = getArcaneForgingRank(PP);
  254. if(rank == 0)
  255. {
  256. if(LoadProperties.mayLoseEnchants)
  257. {
  258. player.sendMessage(mcLocale.getString("Repair.LostEnchants"));
  259. for(Enchantment x : enchants)
  260. {
  261. is.removeEnchantment(x);
  262. }
  263. }
  264. return;
  265. }
  266. boolean failure = false, downgrade = false;
  267. if(LoadProperties.mayLoseEnchants)
  268. {
  269. for(Enchantment x : enchants)
  270. {
  271. //Remove enchant
  272. is.removeEnchantment(x);
  273. if(x.canEnchantItem(is))
  274. {
  275. if(Math.random() * 100 <= getEnchantChance(rank))
  276. {
  277. if(enchantsLvl[pos] > 1)
  278. {
  279. if(LoadProperties.mayDowngradeEnchants)
  280. {
  281. if(Math.random() * 100 <= getDowngradeChance(rank))
  282. {
  283. is.addEnchantment(x, enchantsLvl[pos]-1);
  284. downgrade = true;
  285. } else
  286. {
  287. is.addEnchantment(x, enchantsLvl[pos]);
  288. }
  289. }
  290. }
  291. else {
  292. is.addEnchantment(x, enchantsLvl[pos]);
  293. }
  294. } else {
  295. failure = true;
  296. }
  297. }
  298. pos++;
  299. }
  300. }
  301. if(failure == false && downgrade == false)
  302. {
  303. player.sendMessage(mcLocale.getString("Repair.ArcanePerfect"));
  304. } else {
  305. if(failure == true)
  306. player.sendMessage(mcLocale.getString("Repair.ArcaneFailed"));
  307. if(downgrade == true)
  308. player.sendMessage(mcLocale.getString("Repair.Downgraded"));
  309. }
  310. }
  311. public static int getEnchantChance(int rank){
  312. switch(rank)
  313. {
  314. case 4:
  315. return LoadProperties.keepEnchantsRank4;
  316. case 3:
  317. return LoadProperties.keepEnchantsRank3;
  318. case 2:
  319. return LoadProperties.keepEnchantsRank2;
  320. case 1:
  321. return LoadProperties.keepEnchantsRank1;
  322. default:
  323. return 0;
  324. }
  325. }
  326. public static int getDowngradeChance(int rank)
  327. {
  328. switch(rank)
  329. {
  330. case 4:
  331. return LoadProperties.downgradeRank4;
  332. case 3:
  333. return LoadProperties.downgradeRank3;
  334. case 2:
  335. return LoadProperties.downgradeRank2;
  336. case 1:
  337. return LoadProperties.downgradeRank1;
  338. default:
  339. return 100;
  340. }
  341. }
  342. public static boolean isArmor(ItemStack is){
  343. return is.getTypeId() == 306 || is.getTypeId() == 307 ||is.getTypeId() == 308 ||is.getTypeId() == 309 || //IRON
  344. is.getTypeId() == 310 ||is.getTypeId() == 311 ||is.getTypeId() == 312 ||is.getTypeId() == 313 || //DIAMOND
  345. is.getTypeId() == 314 || is.getTypeId() == 315 || is.getTypeId() == 316 || is.getTypeId() == 317 || //GOLD
  346. is.getTypeId() == 298 || is.getTypeId() == 299 || is.getTypeId() == 300 || is.getTypeId() == 301; //LEATHER
  347. }
  348. public static boolean isLeatherArmor(ItemStack is){
  349. return is.getTypeId() == 298 || is.getTypeId() == 299 || is.getTypeId() == 300 || is.getTypeId() == 301;
  350. }
  351. public static boolean isGoldArmor(ItemStack is){
  352. return is.getTypeId() == 314 || is.getTypeId() == 315 || is.getTypeId() == 316 || is.getTypeId() == 317;
  353. }
  354. public static boolean isIronArmor(ItemStack is){
  355. return is.getTypeId() == 306 || is.getTypeId() == 307 || is.getTypeId() == 308 || is.getTypeId() == 309;
  356. }
  357. public static boolean isDiamondArmor(ItemStack is){
  358. return is.getTypeId() == 310 || is.getTypeId() == 311 || is.getTypeId() == 312 || is.getTypeId() == 313;
  359. }
  360. public static boolean isTools(ItemStack is)
  361. {
  362. return is.getTypeId() == 359 || is.getTypeId() == 256 || is.getTypeId() == 257 || is.getTypeId() == 258 || is.getTypeId() == 267 || is.getTypeId() == 292 || //IRON
  363. is.getTypeId() == 276 || is.getTypeId() == 277 || is.getTypeId() == 278 || is.getTypeId() == 279 || is.getTypeId() == 293 || //DIAMOND
  364. is.getTypeId() == 283 || is.getTypeId() == 285 || is.getTypeId() == 286 || is.getTypeId() == 284 || is.getTypeId() == 294 || //GOLD
  365. is.getTypeId() == 268 || is.getTypeId() == 269 || is.getTypeId() == 270 || is.getTypeId() == 271 || is.getTypeId() == 290 ||//WOOD
  366. is.getTypeId() == 272 || is.getTypeId() == 273 || is.getTypeId() == 274 || is.getTypeId() == 275|| is.getTypeId() == 291 || //STONE
  367. is.getTypeId() == 261; //BOW
  368. }
  369. public static boolean isStoneTools(ItemStack is){
  370. return is.getTypeId() == 272 || is.getTypeId() == 273 || is.getTypeId() == 274 || is.getTypeId() == 275 || is.getTypeId() == 291;
  371. }
  372. public static boolean isWoodTools(ItemStack is){
  373. return is.getTypeId() == 268 || is.getTypeId() == 269 || is.getTypeId() == 270 || is.getTypeId() == 271 || is.getTypeId() == 290;
  374. }
  375. public static boolean isGoldTools(ItemStack is){
  376. return is.getTypeId() == 283 || is.getTypeId() == 285 || is.getTypeId() == 286 || is.getTypeId() == 284 || is.getTypeId() == 294;
  377. }
  378. public static boolean isIronTools(ItemStack is){
  379. return is.getTypeId() == 359 || is.getTypeId() == 256 || is.getTypeId() == 257 || is.getTypeId() == 258 || is.getTypeId() == 267 || is.getTypeId() == 292;
  380. }
  381. public static boolean isDiamondTools(ItemStack is){
  382. return is.getTypeId() == 276 || is.getTypeId() == 277 || is.getTypeId() == 278 || is.getTypeId() == 279 || is.getTypeId() == 293;
  383. }
  384. public static boolean isBow(ItemStack is){
  385. return is.getTypeId() == 261;
  386. }
  387. public static void removeItem(Player player, int typeid)
  388. {
  389. ItemStack[] inventory = player.getInventory().getContents();
  390. for(ItemStack x : inventory){
  391. if(x != null && x.getTypeId() == typeid){
  392. if(x.getAmount() == 1){
  393. x.setTypeId(0);
  394. x.setAmount(0);
  395. player.getInventory().setContents(inventory);
  396. } else{
  397. x.setAmount(x.getAmount() - 1);
  398. player.getInventory().setContents(inventory);
  399. }
  400. return;
  401. }
  402. }
  403. }
  404. public static boolean hasItem(Player player, int typeid){
  405. ItemStack[] inventory = player.getInventory().getContents();
  406. for(ItemStack x : inventory){
  407. if(x != null && x.getTypeId() == typeid){
  408. return true;
  409. }
  410. }
  411. return false;
  412. }
  413. public static short repairCalculate(Player player, short durability, int ramt){
  414. PlayerProfile PP = Users.getProfile(player);
  415. float bonus = (float)(PP.getSkillLevel(SkillType.REPAIR)) / 500;
  416. bonus = (ramt * bonus);
  417. ramt+=bonus;
  418. if(checkPlayerProcRepair(player)){
  419. ramt = (short) (ramt * 2);
  420. }
  421. durability-=ramt;
  422. if(durability < 0){
  423. durability = 0;
  424. }
  425. return durability;
  426. }
  427. public static short getRepairAmount(ItemStack is, Player player){
  428. short durability = is.getDurability();
  429. int ramt = 0;
  430. switch(is.getTypeId())
  431. {
  432. /*
  433. * TOOLS
  434. */
  435. //SHEARS
  436. case 359:
  437. ramt = Material.SHEARS.getMaxDurability() / 2;
  438. break;
  439. //BOW
  440. case 261:
  441. ramt = Material.BOW.getMaxDurability() / 3;
  442. break;
  443. /* WOOD TOOLS */
  444. //WOOD SWORD
  445. case 268:
  446. ramt = Material.WOOD_SWORD.getMaxDurability() / 2;
  447. break;
  448. //WOOD SHOVEL
  449. case 269:
  450. ramt = Material.WOOD_SPADE.getMaxDurability();
  451. break;
  452. //WOOD PICKAXE
  453. case 270:
  454. ramt = Material.WOOD_PICKAXE.getMaxDurability() / 3;
  455. break;
  456. //WOOD AXE
  457. case 271:
  458. ramt = Material.WOOD_AXE.getMaxDurability() / 3;
  459. break;
  460. //WOOD HOE
  461. case 290:
  462. ramt = Material.WOOD_HOE.getMaxDurability() / 2;
  463. break;
  464. /* STONE TOOLS */
  465. //STONE SWORD
  466. case 272:
  467. ramt = Material.STONE_SWORD.getMaxDurability() / 2;
  468. break;
  469. //STONE SHOVEL
  470. case 273:
  471. ramt = Material.STONE_SPADE.getMaxDurability();
  472. break;
  473. //STONE PICKAXE
  474. case 274:
  475. ramt = Material.STONE_PICKAXE.getMaxDurability() / 3;
  476. break;
  477. //STONE AXE
  478. case 275:
  479. ramt = Material.STONE_AXE.getMaxDurability() / 3;
  480. break;
  481. //STONE HOE
  482. case 291:
  483. ramt = Material.STONE_HOE.getMaxDurability() / 2;
  484. break;
  485. /* IRON TOOLS */
  486. //IRON SWORD
  487. case 267:
  488. ramt = Material.IRON_SWORD.getMaxDurability() / 2;
  489. break;
  490. //IRON SHOVEL
  491. case 256:
  492. ramt = Material.IRON_SPADE.getMaxDurability();
  493. break;
  494. //IRON PICK
  495. case 257:
  496. ramt = Material.IRON_PICKAXE.getMaxDurability() / 3;
  497. break;
  498. //IRON AXE
  499. case 258:
  500. ramt = Material.IRON_AXE.getMaxDurability() / 3;
  501. break;
  502. //IRON HOE
  503. case 292:
  504. ramt = Material.IRON_HOE.getMaxDurability() / 2;
  505. break;
  506. /* DIAMOND TOOLS */
  507. //DIAMOND SWORD
  508. case 276:
  509. ramt = Material.DIAMOND_SWORD.getMaxDurability() / 2;
  510. break;
  511. //DIAMOND SHOVEL
  512. case 277:
  513. ramt = Material.DIAMOND_SPADE.getMaxDurability();
  514. break;
  515. //DIAMOND PICK
  516. case 278:
  517. ramt = Material.DIAMOND_PICKAXE.getMaxDurability() / 3;
  518. break;
  519. //DIAMOND AXE
  520. case 279:
  521. ramt = Material.DIAMOND_AXE.getMaxDurability() / 3;
  522. break;
  523. //DIAMOND HOE
  524. case 293:
  525. ramt = Material.DIAMOND_HOE.getMaxDurability() / 2;
  526. break;
  527. /* GOLD TOOLS */
  528. //GOLD SWORD
  529. case 283:
  530. ramt = Material.GOLD_SWORD.getMaxDurability() / 2;
  531. break;
  532. //GOLD SHOVEL
  533. case 284:
  534. ramt = Material.GOLD_SPADE.getMaxDurability();
  535. break;
  536. //GOLD PICK
  537. case 285:
  538. ramt = Material.GOLD_PICKAXE.getMaxDurability() / 3;
  539. break;
  540. //GOLD AXE
  541. case 286:
  542. ramt = Material.GOLD_AXE.getMaxDurability() / 3;
  543. break;
  544. //GOLD HOE
  545. case 294:
  546. ramt = Material.GOLD_HOE.getMaxDurability() / 2;
  547. break;
  548. /*
  549. * ARMOR
  550. */
  551. /* IRON ARMOR */
  552. //IRON HELMET
  553. case 306:
  554. ramt = Material.IRON_HELMET.getMaxDurability() / 5;
  555. break;
  556. //IRON CHESTPLATE
  557. case 307:
  558. ramt = Material.IRON_CHESTPLATE.getMaxDurability() / 8;
  559. break;
  560. //IRON LEGGINGS
  561. case 308:
  562. ramt = Material.IRON_LEGGINGS.getMaxDurability() / 7;
  563. break;
  564. //IRON BOOTS
  565. case 309:
  566. ramt = Material.IRON_BOOTS.getMaxDurability() / 4;
  567. break;
  568. /* DIAMOND ARMOR */
  569. //DIAMOND HELMET
  570. case 310:
  571. ramt = Material.DIAMOND_HELMET.getMaxDurability() / 5;
  572. break;
  573. //DIAMOND CHESTPLATE
  574. case 311:
  575. ramt = Material.DIAMOND_CHESTPLATE.getMaxDurability() / 8;
  576. break;
  577. //DIAMOND LEGGINGS
  578. case 312:
  579. ramt = Material.DIAMOND_LEGGINGS.getMaxDurability() / 7;
  580. break;
  581. //DIAMOND BOOTS
  582. case 313:
  583. ramt = Material.DIAMOND_BOOTS.getMaxDurability() / 4;
  584. break;
  585. /* GOLD ARMOR */
  586. //GOLD HELMET
  587. case 314:
  588. ramt = Material.GOLD_HELMET.getMaxDurability() / 5;
  589. break;
  590. //GOLD CHESTPLATE
  591. case 315:
  592. ramt = Material.GOLD_CHESTPLATE.getMaxDurability() / 8;
  593. break;
  594. //GOLD LEGGINGS
  595. case 316:
  596. ramt = Material.GOLD_LEGGINGS.getMaxDurability() / 7;
  597. break;
  598. //GOLD BOOTS
  599. case 317:
  600. ramt = Material.GOLD_BOOTS.getMaxDurability() / 4;
  601. break;
  602. /* LEATHER ARMOR */
  603. //LEATHER HELMET
  604. case 298:
  605. ramt = Material.LEATHER_HELMET.getMaxDurability() / 5;
  606. break;
  607. //LEATHER CHESTPLATE
  608. case 299:
  609. ramt = Material.LEATHER_CHESTPLATE.getMaxDurability() / 8;
  610. break;
  611. //LEATHER LEGGINGS
  612. case 300:
  613. ramt = Material.LEATHER_LEGGINGS.getMaxDurability() / 7;
  614. break;
  615. //LEATHER BOOTS
  616. case 301:
  617. ramt = Material.LEATHER_BOOTS.getMaxDurability() / 4;
  618. break;
  619. }
  620. return repairCalculate(player, durability, ramt);
  621. }
  622. public static void needMoreVespeneGas(ItemStack is, Player player)
  623. {
  624. PlayerProfile PP = Users.getProfile(player);
  625. if ((isDiamondTools(is) || isDiamondArmor(is)) && PP.getSkillLevel(SkillType.REPAIR) < LoadProperties.repairdiamondlevel)
  626. {
  627. player.sendMessage(mcLocale.getString("Skills.AdeptDiamond"));
  628. } else if (isDiamondTools(is) && !hasItem(player, rDiamond) || isIronTools(is) && !hasItem(player, rIron) || isGoldTools(is) && !hasItem(player, rGold)){
  629. if(isDiamondTools(is) && !hasItem(player, rDiamond))
  630. player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.BLUE+ nDiamond);
  631. if(isIronTools(is) && !hasItem(player, rIron))
  632. player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.GRAY+ nIron);
  633. if(isGoldTools(is) && !hasItem(player, rGold))
  634. player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.GOLD+nGold);
  635. if(isWoodTools(is) && !hasItem(player,rWood))
  636. player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.DARK_GREEN+ nWood);
  637. if(isStoneTools(is) && !hasItem(player, rStone))
  638. player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.GRAY+nStone);
  639. } else if (isDiamondArmor(is) && !hasItem(player, rDiamond)){
  640. player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.BLUE+ nDiamond);
  641. } else if (isIronArmor(is) && !hasItem(player, rIron)){
  642. player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.GRAY+ nIron);
  643. } else if (isGoldArmor(is) && !hasItem(player, rGold)){
  644. player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.GOLD+ nGold);
  645. } else if (isLeatherArmor(is) && !hasItem(player, rLeather)){
  646. player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.YELLOW+ nLeather);
  647. } else if (isBow(is) && !hasItem(player, rString)){
  648. player.sendMessage(mcLocale.getString("Skills.NeedMore")+" "+ChatColor.YELLOW+ nString);
  649. } else if (is.getAmount() > 1)
  650. player.sendMessage(mcLocale.getString("Skills.StackedItems"));
  651. }
  652. public static boolean checkPlayerProcRepair(Player player)
  653. {
  654. PlayerProfile PP = Users.getProfile(player);
  655. if(player != null)
  656. {
  657. if(Math.random() * 1000 <= PP.getSkillLevel(SkillType.REPAIR))
  658. {
  659. player.sendMessage(mcLocale.getString("Skills.FeltEasy"));
  660. return true;
  661. }
  662. }
  663. return false;
  664. }
  665. public static void repairItem(Player player, Enchantment[] enchants, int[] enchantsLevel)
  666. {
  667. PlayerProfile PP = Users.getProfile(player);
  668. ItemStack is = player.getItemInHand();
  669. //Handle the enchantments
  670. addEnchants(player.getItemInHand(), enchants, enchantsLevel, PP, player);
  671. player.getItemInHand().setDurability(getRepairAmount(is, player));
  672. }
  673. }