ModChecks.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. package com.gmail.nossr50.util;
  2. import org.bukkit.block.Block;
  3. import org.bukkit.inventory.ItemStack;
  4. import com.gmail.nossr50.config.mods.CustomBlocksConfig;
  5. import com.gmail.nossr50.config.mods.LoadCustomArmor;
  6. import com.gmail.nossr50.config.mods.LoadCustomTools;
  7. import com.gmail.nossr50.datatypes.mods.CustomBlock;
  8. import com.gmail.nossr50.datatypes.mods.CustomItem;
  9. import com.gmail.nossr50.datatypes.mods.CustomTool;
  10. public class ModChecks {
  11. private static LoadCustomTools toolInstance = LoadCustomTools.getInstance();
  12. private static LoadCustomArmor armorInstance = LoadCustomArmor.getInstance();
  13. private static CustomBlocksConfig blocksInstance = CustomBlocksConfig.getInstance();
  14. /**
  15. * Get the custom armor associated with an item.
  16. *
  17. * @param item The item to check
  18. * @return the ay if it exists, null otherwise
  19. */
  20. public static CustomItem getArmorFromItemStack(ItemStack item) {
  21. int id = item.getTypeId();
  22. if (!armorInstance.customIDs.contains(id)) {
  23. return null;
  24. }
  25. for (CustomItem armor : armorInstance.customItems) {
  26. if (armor.getItemID() == id) {
  27. return armor;
  28. }
  29. }
  30. return null;
  31. }
  32. /**
  33. * Get the custom tool associated with an item.
  34. *
  35. * @param item The item to check
  36. * @return the armor if it exists, null otherwise
  37. */
  38. public static CustomTool getToolFromItemStack(ItemStack item) {
  39. int id = item.getTypeId();
  40. if (!toolInstance.customIDs.contains(id)) {
  41. return null;
  42. }
  43. for (CustomItem tool : toolInstance.customItems) {
  44. if (tool.getItemID() == id) {
  45. return (CustomTool) tool;
  46. }
  47. }
  48. return null;
  49. }
  50. /**
  51. * Get the custom block associated with an block.
  52. *
  53. * @param block The block to check
  54. * @return the armor if it exists, null otherwise
  55. */
  56. public static CustomBlock getCustomBlock(Block block) {
  57. if (!blocksInstance.customItems.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
  58. return null;
  59. }
  60. for (CustomBlock b : blocksInstance.customBlocks) {
  61. if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
  62. return b;
  63. }
  64. }
  65. return null;
  66. }
  67. }