ItemChecks.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. package com.gmail.nossr50.util;
  2. import org.bukkit.inventory.ItemStack;
  3. import org.bukkit.Material;
  4. import com.gmail.nossr50.mcMMO;
  5. import com.gmail.nossr50.api.SpoutToolsAPI;
  6. import com.gmail.nossr50.config.Config;
  7. import com.gmail.nossr50.config.mods.CustomArmorConfig;
  8. import com.gmail.nossr50.config.mods.CustomToolsConfig;
  9. public class ItemChecks {
  10. private static Config configInstance = Config.getInstance();
  11. private static boolean customToolsEnabled = configInstance.getToolModsEnabled();
  12. private static boolean customArmorEnabled = configInstance.getArmorModsEnabled();
  13. /**
  14. * Checks if the item is a sword.
  15. *
  16. * @param is Item to check
  17. * @return true if the item is a sword, false otherwise
  18. */
  19. public static boolean isSword(ItemStack is) {
  20. switch (is.getType()) {
  21. case DIAMOND_SWORD:
  22. case GOLD_SWORD:
  23. case IRON_SWORD:
  24. case STONE_SWORD:
  25. case WOOD_SWORD:
  26. return true;
  27. default:
  28. if (customToolsEnabled && CustomToolsConfig.getInstance().customSwordIDs.contains(is.getTypeId())) {
  29. return true;
  30. }
  31. else if (mcMMO.spoutEnabled && SpoutToolsAPI.spoutSwords.contains(is)) {
  32. return true;
  33. }
  34. else {
  35. return false;
  36. }
  37. }
  38. }
  39. /**
  40. * Checks if the item is a hoe.
  41. *
  42. * @param is Item to check
  43. * @return true if the item is a hoe, false otherwise
  44. */
  45. public static boolean isHoe(ItemStack is) {
  46. switch (is.getType()) {
  47. case DIAMOND_HOE:
  48. case GOLD_HOE:
  49. case IRON_HOE:
  50. case STONE_HOE:
  51. case WOOD_HOE:
  52. return true;
  53. default:
  54. if (customToolsEnabled && CustomToolsConfig.getInstance().customHoeIDs.contains(is.getTypeId())) {
  55. return true;
  56. }
  57. else if (mcMMO.spoutEnabled && SpoutToolsAPI.spoutHoes.contains(is)) {
  58. return true;
  59. }
  60. else {
  61. return false;
  62. }
  63. }
  64. }
  65. /**
  66. * Checks if the item is a shovel.
  67. *
  68. * @param is Item to check
  69. * @return true if the item is a shovel, false otherwise
  70. */
  71. public static boolean isShovel(ItemStack is) {
  72. switch (is.getType()) {
  73. case DIAMOND_SPADE:
  74. case GOLD_SPADE:
  75. case IRON_SPADE:
  76. case STONE_SPADE:
  77. case WOOD_SPADE:
  78. return true;
  79. default:
  80. if (customToolsEnabled && CustomToolsConfig.getInstance().customShovelIDs.contains(is.getTypeId())) {
  81. return true;
  82. }
  83. else if (mcMMO.spoutEnabled && SpoutToolsAPI.spoutShovels.contains(is)) {
  84. return true;
  85. }
  86. else {
  87. return false;
  88. }
  89. }
  90. }
  91. /**
  92. * Checks if the item is an axe.
  93. *
  94. * @param is Item to check
  95. * @return true if the item is an axe, false otherwise
  96. */
  97. public static boolean isAxe(ItemStack is) {
  98. switch (is.getType()) {
  99. case DIAMOND_AXE:
  100. case GOLD_AXE:
  101. case IRON_AXE:
  102. case STONE_AXE:
  103. case WOOD_AXE:
  104. return true;
  105. default:
  106. if (customToolsEnabled && CustomToolsConfig.getInstance().customAxeIDs.contains(is.getTypeId())) {
  107. return true;
  108. }
  109. else if (mcMMO.spoutEnabled && SpoutToolsAPI.spoutAxes.contains(is)) {
  110. return true;
  111. }
  112. else {
  113. return false;
  114. }
  115. }
  116. }
  117. /**
  118. * Checks if the item is a pickaxe.
  119. *
  120. * @param is Item to check
  121. * @return true if the item is a pickaxe, false otherwise
  122. */
  123. public static boolean isPickaxe(ItemStack is) {
  124. switch (is.getType()) {
  125. case DIAMOND_PICKAXE:
  126. case GOLD_PICKAXE:
  127. case IRON_PICKAXE:
  128. case STONE_PICKAXE:
  129. case WOOD_PICKAXE:
  130. return true;
  131. default:
  132. if (customToolsEnabled && CustomToolsConfig.getInstance().customPickaxeIDs.contains(is.getTypeId())) {
  133. return true;
  134. }
  135. else if (mcMMO.spoutEnabled && SpoutToolsAPI.spoutPickaxes.contains(is)) {
  136. return true;
  137. }
  138. else {
  139. return false;
  140. }
  141. }
  142. }
  143. /**
  144. * Checks if the item is a helmet.
  145. *
  146. * @param is Item to check
  147. * @return true if the item is a helmet, false otherwise
  148. */
  149. public static boolean isHelmet(ItemStack is) {
  150. switch (is.getType()) {
  151. case DIAMOND_HELMET:
  152. case GOLD_HELMET:
  153. case IRON_HELMET:
  154. case LEATHER_HELMET:
  155. return true;
  156. default:
  157. if (customArmorEnabled && CustomArmorConfig.getInstance().customHelmetIDs.contains(is.getTypeId())) {
  158. return true;
  159. }
  160. else {
  161. return false;
  162. }
  163. }
  164. }
  165. /**
  166. * Checks if the item is a chestplate.
  167. *
  168. * @param is Item to check
  169. * @return true if the item is a chestplate, false otherwise
  170. */
  171. public static boolean isChestplate(ItemStack is) {
  172. switch (is.getType()) {
  173. case DIAMOND_CHESTPLATE:
  174. case GOLD_CHESTPLATE:
  175. case IRON_CHESTPLATE:
  176. case LEATHER_CHESTPLATE:
  177. return true;
  178. default:
  179. if (customArmorEnabled && CustomArmorConfig.getInstance().customChestplateIDs.contains(is.getTypeId())) {
  180. return true;
  181. }
  182. else {
  183. return false;
  184. }
  185. }
  186. }
  187. /**
  188. * Checks if the item is a pair of pants.
  189. *
  190. * @param is Item to check
  191. * @return true if the item is a pair of pants, false otherwise
  192. */
  193. public static boolean isPants(ItemStack is) {
  194. switch (is.getType()) {
  195. case DIAMOND_LEGGINGS:
  196. case GOLD_LEGGINGS:
  197. case IRON_LEGGINGS:
  198. case LEATHER_LEGGINGS:
  199. return true;
  200. default:
  201. if (customArmorEnabled && CustomArmorConfig.getInstance().customLeggingIDs.contains(is.getTypeId())) {
  202. return true;
  203. }
  204. else {
  205. return false;
  206. }
  207. }
  208. }
  209. /**
  210. * Checks if the item is a pair of boots.
  211. *
  212. * @param is Item to check
  213. * @return true if the item is a pair of boots, false otherwise
  214. */
  215. public static boolean isBoots(ItemStack is) {
  216. switch (is.getType()) {
  217. case DIAMOND_BOOTS:
  218. case GOLD_BOOTS:
  219. case IRON_BOOTS:
  220. case LEATHER_BOOTS:
  221. return true;
  222. default:
  223. if (customArmorEnabled && CustomArmorConfig.getInstance().customBootIDs.contains(is.getTypeId())) {
  224. return true;
  225. }
  226. else {
  227. return false;
  228. }
  229. }
  230. }
  231. /**
  232. * Checks to see if an item is a wearable armor piece.
  233. *
  234. * @param is Item to check
  235. * @return true if the item is armor, false otherwise
  236. */
  237. public static boolean isArmor(ItemStack is) {
  238. return isLeatherArmor(is) || isGoldArmor(is) || isIronArmor(is) || isDiamondArmor(is);
  239. }
  240. /**
  241. * Checks to see if an item is a leather armor piece.
  242. *
  243. * @param is Item to check
  244. * @return true if the item is leather armor, false otherwise
  245. */
  246. public static boolean isLeatherArmor(ItemStack is) {
  247. switch (is.getType()) {
  248. case LEATHER_BOOTS:
  249. case LEATHER_CHESTPLATE:
  250. case LEATHER_HELMET:
  251. case LEATHER_LEGGINGS:
  252. return true;
  253. default:
  254. return false;
  255. }
  256. }
  257. /**
  258. * Checks to see if an item is a gold armor piece.
  259. *
  260. * @param is Item to check
  261. * @return true if the item is gold armor, false otherwise
  262. */
  263. public static boolean isGoldArmor(ItemStack is) {
  264. switch (is.getType()) {
  265. case GOLD_BOOTS:
  266. case GOLD_CHESTPLATE:
  267. case GOLD_HELMET:
  268. case GOLD_LEGGINGS:
  269. return true;
  270. default:
  271. return false;
  272. }
  273. }
  274. /**
  275. * Checks to see if an item is an iron armor piece.
  276. *
  277. * @param is Item to check
  278. * @return true if the item is iron armor, false otherwise
  279. */
  280. public static boolean isIronArmor(ItemStack is) {
  281. switch (is.getType()) {
  282. case IRON_BOOTS:
  283. case IRON_CHESTPLATE:
  284. case IRON_HELMET:
  285. case IRON_LEGGINGS:
  286. return true;
  287. default:
  288. return false;
  289. }
  290. }
  291. /**
  292. * Checks to see if an item is a diamond armor piece.
  293. *
  294. * @param is Item to check
  295. * @return true if the item is diamond armor, false otherwise
  296. */
  297. public static boolean isDiamondArmor(ItemStack is) {
  298. switch (is.getType()) {
  299. case DIAMOND_BOOTS:
  300. case DIAMOND_CHESTPLATE:
  301. case DIAMOND_HELMET:
  302. case DIAMOND_LEGGINGS:
  303. return true;
  304. default:
  305. return false;
  306. }
  307. }
  308. /**
  309. * Checks to see if an item is a tool.
  310. *
  311. * @param is Item to check
  312. * @return true if the item is a tool, false otherwise
  313. */
  314. public static boolean isTool(ItemStack is) {
  315. return isStoneTool(is) || isWoodTool(is) || isGoldTool(is) || isIronTool(is) || isDiamondTool(is) || isStringTool(is);
  316. }
  317. /**
  318. * Checks to see if an item is a stone tool.
  319. *
  320. * @param is Item to check
  321. * @return true if the item is a stone tool, false otherwise
  322. */
  323. public static boolean isStoneTool(ItemStack is) {
  324. switch (is.getType()) {
  325. case STONE_AXE:
  326. case STONE_HOE:
  327. case STONE_PICKAXE:
  328. case STONE_SPADE:
  329. case STONE_SWORD:
  330. return true;
  331. default:
  332. return false;
  333. }
  334. }
  335. /**
  336. * Checks to see if an item is a wooden tool.
  337. *
  338. * @param is Item to check
  339. * @return true if the item is a wooden tool, false otherwise
  340. */
  341. public static boolean isWoodTool(ItemStack is) {
  342. switch (is.getType()) {
  343. case WOOD_AXE:
  344. case WOOD_HOE:
  345. case WOOD_PICKAXE:
  346. case WOOD_SPADE:
  347. case WOOD_SWORD:
  348. return true;
  349. default:
  350. return false;
  351. }
  352. }
  353. /**
  354. * Checks to see if an item is a string tool.
  355. *
  356. * @param is Item to check
  357. * @return true if the item is a string tool, false otherwise
  358. */
  359. public static boolean isStringTool(ItemStack is) {
  360. switch (is.getType()) {
  361. case BOW:
  362. case FISHING_ROD:
  363. return true;
  364. default:
  365. return false;
  366. }
  367. }
  368. /**
  369. * Checks to see if an item is a gold tool.
  370. *
  371. * @param is Item to check
  372. * @return true if the item is a stone tool, false otherwise
  373. */
  374. public static boolean isGoldTool(ItemStack is) {
  375. switch (is.getType()) {
  376. case GOLD_AXE:
  377. case GOLD_HOE:
  378. case GOLD_PICKAXE:
  379. case GOLD_SPADE:
  380. case GOLD_SWORD:
  381. return true;
  382. default:
  383. return false;
  384. }
  385. }
  386. /**
  387. * Checks to see if an item is an iron tool.
  388. *
  389. * @param is Item to check
  390. * @return true if the item is an iron tool, false otherwise
  391. */
  392. public static boolean isIronTool(ItemStack is) {
  393. switch (is.getType()) {
  394. case IRON_AXE:
  395. case IRON_HOE:
  396. case IRON_PICKAXE:
  397. case IRON_SPADE:
  398. case IRON_SWORD:
  399. case SHEARS:
  400. return true;
  401. default:
  402. return false;
  403. }
  404. }
  405. /**
  406. * Checks to see if an item is a diamond tool.
  407. *
  408. * @param is Item to check
  409. * @return true if the item is a diamond tool, false otherwise
  410. */
  411. public static boolean isDiamondTool(ItemStack is) {
  412. switch (is.getType()) {
  413. case DIAMOND_AXE:
  414. case DIAMOND_HOE:
  415. case DIAMOND_PICKAXE:
  416. case DIAMOND_SPADE:
  417. case DIAMOND_SWORD:
  418. return true;
  419. default:
  420. return false;
  421. }
  422. }
  423. /**
  424. * Checks to see if an item is enchantable.
  425. *
  426. * @param is Item to check
  427. * @return true if the item is enchantable, false otherwise
  428. */
  429. public static boolean isEnchantable(ItemStack is) {
  430. return isArmor(is) || isSword(is) || isAxe(is) || isShovel(is) || isPickaxe(is) || (is.getType() == Material.BOW);
  431. }
  432. /**
  433. * Get the maximum durability of an armor type.
  434. *
  435. * @param is Item to check
  436. * @return maximum durability value.
  437. */
  438. public static int getMaxDurabilityArmor(ItemStack is) {
  439. int durability = 0;
  440. if (isDiamondArmor(is)) {
  441. if (isHelmet(is)) durability = 364;
  442. else if (isChestplate(is)) durability = 529;
  443. else if (isPants(is)) durability = 496;
  444. else if (isBoots(is)) durability = 430;
  445. }
  446. else if (isIronArmor(is)) {
  447. if (isHelmet(is)) durability = 166;
  448. else if (isChestplate(is)) durability = 242;
  449. else if (isPants(is)) durability = 226;
  450. else if (isBoots(is)) durability = 196;
  451. }
  452. else if (isGoldArmor(is)) {
  453. if (isHelmet(is)) durability = 78;
  454. else if (isChestplate(is)) durability = 114;
  455. else if (isPants(is)) durability = 106;
  456. else if (isBoots(is)) durability = 92;
  457. }
  458. else if (isLeatherArmor(is)) {
  459. if (isHelmet(is)) durability = 56;
  460. else if (isChestplate(is)) durability = 82;
  461. else if (isPants(is)) durability = 76;
  462. else if (isBoots(is)) durability = 66;
  463. }
  464. return durability;
  465. }
  466. }