ItemChecks.java 12 KB

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