ItemChecks.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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. return false;
  161. }
  162. }
  163. /**
  164. * Checks if the item is a chestplate.
  165. *
  166. * @param is Item to check
  167. * @return true if the item is a chestplate, false otherwise
  168. */
  169. public static boolean isChestplate(ItemStack is) {
  170. switch (is.getType()) {
  171. case DIAMOND_CHESTPLATE:
  172. case GOLD_CHESTPLATE:
  173. case IRON_CHESTPLATE:
  174. case LEATHER_CHESTPLATE:
  175. return true;
  176. default:
  177. if (customArmorEnabled && CustomArmorConfig.getInstance().customChestplateIDs.contains(is.getTypeId())) {
  178. return true;
  179. }
  180. return false;
  181. }
  182. }
  183. /**
  184. * Checks if the item is a pair of pants.
  185. *
  186. * @param is Item to check
  187. * @return true if the item is a pair of pants, false otherwise
  188. */
  189. public static boolean isPants(ItemStack is) {
  190. switch (is.getType()) {
  191. case DIAMOND_LEGGINGS:
  192. case GOLD_LEGGINGS:
  193. case IRON_LEGGINGS:
  194. case LEATHER_LEGGINGS:
  195. return true;
  196. default:
  197. if (customArmorEnabled && CustomArmorConfig.getInstance().customLeggingIDs.contains(is.getTypeId())) {
  198. return true;
  199. }
  200. return false;
  201. }
  202. }
  203. /**
  204. * Checks if the item is a pair of boots.
  205. *
  206. * @param is Item to check
  207. * @return true if the item is a pair of boots, false otherwise
  208. */
  209. public static boolean isBoots(ItemStack is) {
  210. switch (is.getType()) {
  211. case DIAMOND_BOOTS:
  212. case GOLD_BOOTS:
  213. case IRON_BOOTS:
  214. case LEATHER_BOOTS:
  215. return true;
  216. default:
  217. if (customArmorEnabled && CustomArmorConfig.getInstance().customBootIDs.contains(is.getTypeId())) {
  218. return true;
  219. }
  220. return false;
  221. }
  222. }
  223. /**
  224. * Checks to see if an item is a wearable armor piece.
  225. *
  226. * @param is Item to check
  227. * @return true if the item is armor, false otherwise
  228. */
  229. public static boolean isArmor(ItemStack is) {
  230. return isLeatherArmor(is) || isGoldArmor(is) || isIronArmor(is) || isDiamondArmor(is);
  231. }
  232. /**
  233. * Checks to see if an item is a leather armor piece.
  234. *
  235. * @param is Item to check
  236. * @return true if the item is leather armor, false otherwise
  237. */
  238. public static boolean isLeatherArmor(ItemStack is) {
  239. switch (is.getType()) {
  240. case LEATHER_BOOTS:
  241. case LEATHER_CHESTPLATE:
  242. case LEATHER_HELMET:
  243. case LEATHER_LEGGINGS:
  244. return true;
  245. default:
  246. return false;
  247. }
  248. }
  249. /**
  250. * Checks to see if an item is a gold armor piece.
  251. *
  252. * @param is Item to check
  253. * @return true if the item is gold armor, false otherwise
  254. */
  255. public static boolean isGoldArmor(ItemStack is) {
  256. switch (is.getType()) {
  257. case GOLD_BOOTS:
  258. case GOLD_CHESTPLATE:
  259. case GOLD_HELMET:
  260. case GOLD_LEGGINGS:
  261. return true;
  262. default:
  263. return false;
  264. }
  265. }
  266. /**
  267. * Checks to see if an item is an iron armor piece.
  268. *
  269. * @param is Item to check
  270. * @return true if the item is iron armor, false otherwise
  271. */
  272. public static boolean isIronArmor(ItemStack is) {
  273. switch (is.getType()) {
  274. case IRON_BOOTS:
  275. case IRON_CHESTPLATE:
  276. case IRON_HELMET:
  277. case IRON_LEGGINGS:
  278. return true;
  279. default:
  280. return false;
  281. }
  282. }
  283. /**
  284. * Checks to see if an item is a diamond armor piece.
  285. *
  286. * @param is Item to check
  287. * @return true if the item is diamond armor, false otherwise
  288. */
  289. public static boolean isDiamondArmor(ItemStack is) {
  290. switch (is.getType()) {
  291. case DIAMOND_BOOTS:
  292. case DIAMOND_CHESTPLATE:
  293. case DIAMOND_HELMET:
  294. case DIAMOND_LEGGINGS:
  295. return true;
  296. default:
  297. return false;
  298. }
  299. }
  300. /**
  301. * Checks to see if an item is a tool.
  302. *
  303. * @param is Item to check
  304. * @return true if the item is a tool, false otherwise
  305. */
  306. public static boolean isTool(ItemStack is) {
  307. return isStoneTool(is) || isWoodTool(is) || isGoldTool(is) || isIronTool(is) || isDiamondTool(is) || isStringTool(is);
  308. }
  309. /**
  310. * Checks to see if an item is a stone tool.
  311. *
  312. * @param is Item to check
  313. * @return true if the item is a stone tool, false otherwise
  314. */
  315. public static boolean isStoneTool(ItemStack is) {
  316. switch (is.getType()) {
  317. case STONE_AXE:
  318. case STONE_HOE:
  319. case STONE_PICKAXE:
  320. case STONE_SPADE:
  321. case STONE_SWORD:
  322. return true;
  323. default:
  324. return false;
  325. }
  326. }
  327. /**
  328. * Checks to see if an item is a wooden tool.
  329. *
  330. * @param is Item to check
  331. * @return true if the item is a wooden tool, false otherwise
  332. */
  333. public static boolean isWoodTool(ItemStack is) {
  334. switch (is.getType()) {
  335. case WOOD_AXE:
  336. case WOOD_HOE:
  337. case WOOD_PICKAXE:
  338. case WOOD_SPADE:
  339. case WOOD_SWORD:
  340. return true;
  341. default:
  342. return false;
  343. }
  344. }
  345. /**
  346. * Checks to see if an item is a string tool.
  347. *
  348. * @param is Item to check
  349. * @return true if the item is a string tool, false otherwise
  350. */
  351. public static boolean isStringTool(ItemStack is) {
  352. switch (is.getType()) {
  353. case BOW:
  354. case FISHING_ROD:
  355. return true;
  356. default:
  357. return false;
  358. }
  359. }
  360. /**
  361. * Checks to see if an item is a gold tool.
  362. *
  363. * @param is Item to check
  364. * @return true if the item is a stone tool, false otherwise
  365. */
  366. public static boolean isGoldTool(ItemStack is) {
  367. switch (is.getType()) {
  368. case GOLD_AXE:
  369. case GOLD_HOE:
  370. case GOLD_PICKAXE:
  371. case GOLD_SPADE:
  372. case GOLD_SWORD:
  373. return true;
  374. default:
  375. return false;
  376. }
  377. }
  378. /**
  379. * Checks to see if an item is an iron tool.
  380. *
  381. * @param is Item to check
  382. * @return true if the item is an iron tool, false otherwise
  383. */
  384. public static boolean isIronTool(ItemStack is) {
  385. switch (is.getType()) {
  386. case IRON_AXE:
  387. case IRON_HOE:
  388. case IRON_PICKAXE:
  389. case IRON_SPADE:
  390. case IRON_SWORD:
  391. case SHEARS:
  392. return true;
  393. default:
  394. return false;
  395. }
  396. }
  397. /**
  398. * Checks to see if an item is a diamond tool.
  399. *
  400. * @param is Item to check
  401. * @return true if the item is a diamond tool, false otherwise
  402. */
  403. public static boolean isDiamondTool(ItemStack is) {
  404. switch (is.getType()) {
  405. case DIAMOND_AXE:
  406. case DIAMOND_HOE:
  407. case DIAMOND_PICKAXE:
  408. case DIAMOND_SPADE:
  409. case DIAMOND_SWORD:
  410. return true;
  411. default:
  412. return false;
  413. }
  414. }
  415. /**
  416. * Checks to see if an item is enchantable.
  417. *
  418. * @param is Item to check
  419. * @return true if the item is enchantable, false otherwise
  420. */
  421. public static boolean isEnchantable(ItemStack is) {
  422. return isArmor(is) || isSword(is) || isAxe(is) || isShovel(is) || isPickaxe(is) || (is.getType() == Material.BOW);
  423. }
  424. }