ItemChecks.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. package com.gmail.nossr50.util;
  2. import org.bukkit.DyeColor;
  3. import org.bukkit.Material;
  4. import org.bukkit.inventory.ItemStack;
  5. import com.gmail.nossr50.mcMMO;
  6. import com.gmail.nossr50.api.SpoutToolsAPI;
  7. import com.gmail.nossr50.config.Config;
  8. import com.gmail.nossr50.mods.config.CustomArmorConfig;
  9. import com.gmail.nossr50.mods.config.CustomToolsConfig;
  10. public class ItemChecks {
  11. private static Config configInstance = Config.getInstance();
  12. private static boolean customToolsEnabled = configInstance.getToolModsEnabled();
  13. private static boolean customArmorEnabled = configInstance.getArmorModsEnabled();
  14. /**
  15. * Checks if the item is a sword.
  16. *
  17. * @param is Item to check
  18. * @return true if the item is a sword, false otherwise
  19. */
  20. public static boolean isSword(ItemStack is) {
  21. switch (is.getType()) {
  22. case DIAMOND_SWORD:
  23. case GOLD_SWORD:
  24. case IRON_SWORD:
  25. case STONE_SWORD:
  26. case WOOD_SWORD:
  27. return true;
  28. default:
  29. if (customToolsEnabled && CustomToolsConfig.getInstance().customSwordIDs.contains(is.getTypeId())) {
  30. return true;
  31. }
  32. else if (mcMMO.spoutEnabled && SpoutToolsAPI.spoutSwords.contains(is)) {
  33. return true;
  34. }
  35. else {
  36. return false;
  37. }
  38. }
  39. }
  40. /**
  41. * Checks if the item is a hoe.
  42. *
  43. * @param is Item to check
  44. * @return true if the item is a hoe, false otherwise
  45. */
  46. public static boolean isHoe(ItemStack is) {
  47. switch (is.getType()) {
  48. case DIAMOND_HOE:
  49. case GOLD_HOE:
  50. case IRON_HOE:
  51. case STONE_HOE:
  52. case WOOD_HOE:
  53. return true;
  54. default:
  55. if (customToolsEnabled && CustomToolsConfig.getInstance().customHoeIDs.contains(is.getTypeId())) {
  56. return true;
  57. }
  58. else if (mcMMO.spoutEnabled && SpoutToolsAPI.spoutHoes.contains(is)) {
  59. return true;
  60. }
  61. else {
  62. return false;
  63. }
  64. }
  65. }
  66. /**
  67. * Checks if the item is a shovel.
  68. *
  69. * @param is Item to check
  70. * @return true if the item is a shovel, false otherwise
  71. */
  72. public static boolean isShovel(ItemStack is) {
  73. switch (is.getType()) {
  74. case DIAMOND_SPADE:
  75. case GOLD_SPADE:
  76. case IRON_SPADE:
  77. case STONE_SPADE:
  78. case WOOD_SPADE:
  79. return true;
  80. default:
  81. if (customToolsEnabled && CustomToolsConfig.getInstance().customShovelIDs.contains(is.getTypeId())) {
  82. return true;
  83. }
  84. else if (mcMMO.spoutEnabled && SpoutToolsAPI.spoutShovels.contains(is)) {
  85. return true;
  86. }
  87. else {
  88. return false;
  89. }
  90. }
  91. }
  92. /**
  93. * Checks if the item is an axe.
  94. *
  95. * @param is Item to check
  96. * @return true if the item is an axe, false otherwise
  97. */
  98. public static boolean isAxe(ItemStack is) {
  99. switch (is.getType()) {
  100. case DIAMOND_AXE:
  101. case GOLD_AXE:
  102. case IRON_AXE:
  103. case STONE_AXE:
  104. case WOOD_AXE:
  105. return true;
  106. default:
  107. if (customToolsEnabled && CustomToolsConfig.getInstance().customAxeIDs.contains(is.getTypeId())) {
  108. return true;
  109. }
  110. else if (mcMMO.spoutEnabled && SpoutToolsAPI.spoutAxes.contains(is)) {
  111. return true;
  112. }
  113. else {
  114. return false;
  115. }
  116. }
  117. }
  118. /**
  119. * Checks if the item is a pickaxe.
  120. *
  121. * @param is Item to check
  122. * @return true if the item is a pickaxe, false otherwise
  123. */
  124. public static boolean isPickaxe(ItemStack is) {
  125. switch (is.getType()) {
  126. case DIAMOND_PICKAXE:
  127. case GOLD_PICKAXE:
  128. case IRON_PICKAXE:
  129. case STONE_PICKAXE:
  130. case WOOD_PICKAXE:
  131. return true;
  132. default:
  133. if (customToolsEnabled && CustomToolsConfig.getInstance().customPickaxeIDs.contains(is.getTypeId())) {
  134. return true;
  135. }
  136. else if (mcMMO.spoutEnabled && SpoutToolsAPI.spoutPickaxes.contains(is)) {
  137. return true;
  138. }
  139. else {
  140. return false;
  141. }
  142. }
  143. }
  144. /**
  145. * Checks if the item is a helmet.
  146. *
  147. * @param is Item to check
  148. * @return true if the item is a helmet, false otherwise
  149. */
  150. public static boolean isHelmet(ItemStack is) {
  151. switch (is.getType()) {
  152. case DIAMOND_HELMET:
  153. case GOLD_HELMET:
  154. case IRON_HELMET:
  155. case LEATHER_HELMET:
  156. return true;
  157. default:
  158. if (customArmorEnabled && CustomArmorConfig.getInstance().customHelmetIDs.contains(is.getTypeId())) {
  159. return true;
  160. }
  161. return false;
  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. return false;
  182. }
  183. }
  184. /**
  185. * Checks if the item is a pair of pants.
  186. *
  187. * @param is Item to check
  188. * @return true if the item is a pair of pants, false otherwise
  189. */
  190. public static boolean isLeggings(ItemStack is) {
  191. switch (is.getType()) {
  192. case DIAMOND_LEGGINGS:
  193. case GOLD_LEGGINGS:
  194. case IRON_LEGGINGS:
  195. case LEATHER_LEGGINGS:
  196. return true;
  197. default:
  198. if (customArmorEnabled && CustomArmorConfig.getInstance().customLeggingIDs.contains(is.getTypeId())) {
  199. return true;
  200. }
  201. return false;
  202. }
  203. }
  204. /**
  205. * Checks if the item is a pair of boots.
  206. *
  207. * @param is Item to check
  208. * @return true if the item is a pair of boots, false otherwise
  209. */
  210. public static boolean isBoots(ItemStack is) {
  211. switch (is.getType()) {
  212. case DIAMOND_BOOTS:
  213. case GOLD_BOOTS:
  214. case IRON_BOOTS:
  215. case LEATHER_BOOTS:
  216. return true;
  217. default:
  218. if (customArmorEnabled && CustomArmorConfig.getInstance().customBootIDs.contains(is.getTypeId())) {
  219. return true;
  220. }
  221. return false;
  222. }
  223. }
  224. /**
  225. * Checks to see if an item is a wearable armor piece.
  226. *
  227. * @param is Item to check
  228. * @return true if the item is armor, false otherwise
  229. */
  230. public static boolean isArmor(ItemStack is) {
  231. return isHelmet(is) || isChestplate(is) || isLeggings(is) || isBoots(is);
  232. }
  233. /**
  234. * Checks to see if an item is a wearable armor piece.
  235. *
  236. * @param is Item to check
  237. * @return true if the item is armor, false otherwise
  238. */
  239. public static boolean isMinecraftArmor(ItemStack is) {
  240. return isDiamondArmor(is) || isGoldArmor(is) || isIronArmor(is) || isDiamondArmor(is);
  241. }
  242. /**
  243. * Checks to see if an item is a leather armor piece.
  244. *
  245. * @param is Item to check
  246. * @return true if the item is leather armor, false otherwise
  247. */
  248. public static boolean isLeatherArmor(ItemStack is) {
  249. switch (is.getType()) {
  250. case LEATHER_BOOTS:
  251. case LEATHER_CHESTPLATE:
  252. case LEATHER_HELMET:
  253. case LEATHER_LEGGINGS:
  254. return true;
  255. default:
  256. return false;
  257. }
  258. }
  259. /**
  260. * Checks to see if an item is a gold armor piece.
  261. *
  262. * @param is Item to check
  263. * @return true if the item is gold armor, false otherwise
  264. */
  265. public static boolean isGoldArmor(ItemStack is) {
  266. switch (is.getType()) {
  267. case GOLD_BOOTS:
  268. case GOLD_CHESTPLATE:
  269. case GOLD_HELMET:
  270. case GOLD_LEGGINGS:
  271. return true;
  272. default:
  273. return false;
  274. }
  275. }
  276. /**
  277. * Checks to see if an item is an iron armor piece.
  278. *
  279. * @param is Item to check
  280. * @return true if the item is iron armor, false otherwise
  281. */
  282. public static boolean isIronArmor(ItemStack is) {
  283. switch (is.getType()) {
  284. case IRON_BOOTS:
  285. case IRON_CHESTPLATE:
  286. case IRON_HELMET:
  287. case IRON_LEGGINGS:
  288. return true;
  289. default:
  290. return false;
  291. }
  292. }
  293. /**
  294. * Checks to see if an item is a diamond armor piece.
  295. *
  296. * @param is Item to check
  297. * @return true if the item is diamond armor, false otherwise
  298. */
  299. public static boolean isDiamondArmor(ItemStack is) {
  300. switch (is.getType()) {
  301. case DIAMOND_BOOTS:
  302. case DIAMOND_CHESTPLATE:
  303. case DIAMOND_HELMET:
  304. case DIAMOND_LEGGINGS:
  305. return true;
  306. default:
  307. return false;
  308. }
  309. }
  310. /**
  311. * Checks to see if an item is a tool.
  312. *
  313. * @param is Item to check
  314. * @return true if the item is a tool, false otherwise
  315. */
  316. public static boolean isMinecraftTool(ItemStack is) {
  317. return isStoneTool(is) || isWoodTool(is) || isGoldTool(is) || isIronTool(is) || isDiamondTool(is) || isStringTool(is);
  318. }
  319. /**
  320. * Checks to see if an item is a stone tool.
  321. *
  322. * @param is Item to check
  323. * @return true if the item is a stone tool, false otherwise
  324. */
  325. public static boolean isStoneTool(ItemStack is) {
  326. switch (is.getType()) {
  327. case STONE_AXE:
  328. case STONE_HOE:
  329. case STONE_PICKAXE:
  330. case STONE_SPADE:
  331. case STONE_SWORD:
  332. return true;
  333. default:
  334. return false;
  335. }
  336. }
  337. /**
  338. * Checks to see if an item is a wooden tool.
  339. *
  340. * @param is Item to check
  341. * @return true if the item is a wooden tool, false otherwise
  342. */
  343. public static boolean isWoodTool(ItemStack is) {
  344. switch (is.getType()) {
  345. case WOOD_AXE:
  346. case WOOD_HOE:
  347. case WOOD_PICKAXE:
  348. case WOOD_SPADE:
  349. case WOOD_SWORD:
  350. return true;
  351. default:
  352. return false;
  353. }
  354. }
  355. /**
  356. * Checks to see if an item is a string tool.
  357. *
  358. * @param is Item to check
  359. * @return true if the item is a string tool, false otherwise
  360. */
  361. public static boolean isStringTool(ItemStack is) {
  362. switch (is.getType()) {
  363. case BOW:
  364. case CARROT_STICK:
  365. case FISHING_ROD:
  366. return true;
  367. default:
  368. return false;
  369. }
  370. }
  371. /**
  372. * Checks to see if an item is a gold tool.
  373. *
  374. * @param is Item to check
  375. * @return true if the item is a stone tool, false otherwise
  376. */
  377. public static boolean isGoldTool(ItemStack is) {
  378. switch (is.getType()) {
  379. case GOLD_AXE:
  380. case GOLD_HOE:
  381. case GOLD_PICKAXE:
  382. case GOLD_SPADE:
  383. case GOLD_SWORD:
  384. return true;
  385. default:
  386. return false;
  387. }
  388. }
  389. /**
  390. * Checks to see if an item is an iron tool.
  391. *
  392. * @param is Item to check
  393. * @return true if the item is an iron tool, false otherwise
  394. */
  395. public static boolean isIronTool(ItemStack is) {
  396. switch (is.getType()) {
  397. case BUCKET:
  398. case FLINT_AND_STEEL:
  399. case IRON_AXE:
  400. case IRON_HOE:
  401. case IRON_PICKAXE:
  402. case IRON_SPADE:
  403. case IRON_SWORD:
  404. case SHEARS:
  405. return true;
  406. default:
  407. return false;
  408. }
  409. }
  410. /**
  411. * Checks to see if an item is a diamond tool.
  412. *
  413. * @param is Item to check
  414. * @return true if the item is a diamond tool, false otherwise
  415. */
  416. public static boolean isDiamondTool(ItemStack is) {
  417. switch (is.getType()) {
  418. case DIAMOND_AXE:
  419. case DIAMOND_HOE:
  420. case DIAMOND_PICKAXE:
  421. case DIAMOND_SPADE:
  422. case DIAMOND_SWORD:
  423. return true;
  424. default:
  425. return false;
  426. }
  427. }
  428. /**
  429. * Checks to see if an item is enchantable.
  430. *
  431. * @param is Item to check
  432. * @return true if the item is enchantable, false otherwise
  433. */
  434. public static boolean isEnchantable(ItemStack is) {
  435. Material type = is.getType();
  436. return isArmor(is) || isSword(is) || isAxe(is) || isShovel(is) || isPickaxe(is) ||
  437. type == Material.SHEARS || type == Material.FISHING_ROD || type == Material.CARROT_STICK ||
  438. type == Material.FLINT_AND_STEEL || type == Material.BOW;
  439. }
  440. public static boolean isSmeltable(ItemStack itemStack) {
  441. switch (itemStack.getType()) {
  442. case COAL_ORE:
  443. case DIAMOND_ORE:
  444. case GLOWING_REDSTONE_ORE:
  445. case GOLD_ORE:
  446. case IRON_ORE:
  447. case LAPIS_ORE:
  448. case REDSTONE_ORE:
  449. case EMERALD_ORE:
  450. return true;
  451. default:
  452. return false;
  453. }
  454. }
  455. public static boolean isSmelted(ItemStack itemStack) {
  456. switch (itemStack.getType()) {
  457. case COAL:
  458. case DIAMOND:
  459. case REDSTONE:
  460. case GOLD_INGOT:
  461. case IRON_INGOT:
  462. case EMERALD:
  463. return true;
  464. case INK_SACK:
  465. if (itemStack.getData().getData() == DyeColor.BLUE.getDyeData()) {
  466. return true;
  467. }
  468. return false;
  469. default:
  470. return false;
  471. }
  472. }
  473. /**
  474. * Check if an item is sharable.
  475. *
  476. * @param item Item that will get shared
  477. * @return True if the item can be shared.
  478. */
  479. public static boolean isShareable(ItemStack is) {
  480. return isMiningDrop(is) || isWoodcuttingDrop(is) || isMobDrop(is) || isHerbalismDrop(is);
  481. }
  482. /**
  483. * Checks to see if an item is a mining drop.
  484. *
  485. * @param is Item to check
  486. * @return true if the item is a mining drop, false otherwise
  487. */
  488. public static boolean isMiningDrop(ItemStack is) {
  489. switch (is.getType()) {
  490. case COAL:
  491. case COAL_ORE:
  492. case DIAMOND:
  493. case DIAMOND_ORE:
  494. case EMERALD:
  495. case EMERALD_ORE:
  496. case GOLD_ORE:
  497. case IRON_ORE:
  498. case LAPIS_ORE:
  499. case REDSTONE_ORE:
  500. case REDSTONE:
  501. case GLOWSTONE_DUST:
  502. return true;
  503. case INK_SACK:
  504. if (is.getData().getData() == DyeColor.BLUE.getDyeData()) {
  505. return true;
  506. }
  507. return false;
  508. default:
  509. return false;
  510. }
  511. }
  512. public static boolean isHerbalismDrop(ItemStack is) {
  513. switch (is.getType()) {
  514. case WHEAT:
  515. case SEEDS:
  516. case CARROT:
  517. case POTATO:
  518. case COCOA:
  519. case NETHER_WARTS:
  520. case APPLE:
  521. case BROWN_MUSHROOM:
  522. case RED_MUSHROOM:
  523. case RED_ROSE:
  524. case YELLOW_FLOWER:
  525. case CACTUS:
  526. case SUGAR_CANE:
  527. //TODO Add the rest
  528. return true;
  529. default:
  530. return false;
  531. }
  532. }
  533. public static boolean isMobDrop(ItemStack is) {
  534. switch (is.getType()) {
  535. case STRING:
  536. case FEATHER:
  537. case RAW_CHICKEN:
  538. case COOKED_CHICKEN:
  539. case LEATHER:
  540. case RAW_BEEF:
  541. case COOKED_BEEF:
  542. case PORK:
  543. case GRILLED_PORK:
  544. case WOOL:
  545. case RED_ROSE:
  546. case IRON_INGOT:
  547. case SNOW_BALL:
  548. case BLAZE_ROD:
  549. case SPIDER_EYE:
  550. case SULPHUR:
  551. case ENDER_PEARL:
  552. case GHAST_TEAR:
  553. case MAGMA_CREAM:
  554. case BONE:
  555. case ARROW:
  556. case SLIME_BALL:
  557. case NETHER_STAR:
  558. case COAL:
  559. case ROTTEN_FLESH:
  560. case GOLD_NUGGET:
  561. case EGG:
  562. return true;
  563. default:
  564. return false;
  565. }
  566. }
  567. public static boolean isWoodcuttingDrop(ItemStack is) {
  568. switch (is.getType()) {
  569. case LOG:
  570. case LEAVES:
  571. case SAPLING:
  572. return true;
  573. default:
  574. return false;
  575. }
  576. }
  577. }