BlockChecks.java 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. package com.gmail.nossr50.util;
  2. import org.bukkit.CropState;
  3. import org.bukkit.Material;
  4. import org.bukkit.block.Block;
  5. import org.bukkit.inventory.ItemStack;
  6. import org.bukkit.material.CocoaPlant;
  7. import org.bukkit.material.MaterialData;
  8. import org.bukkit.material.CocoaPlant.CocoaPlantSize;
  9. import com.gmail.nossr50.config.Config;
  10. import com.gmail.nossr50.config.mods.CustomBlocksConfig;
  11. public final class BlockChecks {
  12. private static Config configInstance = Config.getInstance();
  13. private BlockChecks() {}
  14. /**
  15. * Checks to see if a block type awards XP.
  16. *
  17. * @param block Block to check
  18. * @return true if the block type awards XP, false otherwise
  19. */
  20. public static boolean shouldBeWatched(Block block) {
  21. switch (block.getType()) {
  22. case BROWN_MUSHROOM:
  23. case CACTUS:
  24. case CLAY:
  25. case COAL_ORE:
  26. case DIAMOND_ORE:
  27. case DIRT:
  28. case ENDER_STONE:
  29. case GLOWING_REDSTONE_ORE:
  30. case GLOWSTONE:
  31. case GOLD_ORE:
  32. case GRASS:
  33. case GRAVEL:
  34. case IRON_ORE:
  35. case LAPIS_ORE:
  36. case LOG:
  37. case MELON_BLOCK:
  38. case MOSSY_COBBLESTONE:
  39. case MYCEL:
  40. case NETHERRACK:
  41. case OBSIDIAN:
  42. case PUMPKIN:
  43. case RED_MUSHROOM:
  44. case RED_ROSE:
  45. case REDSTONE_ORE:
  46. case SAND:
  47. case SANDSTONE:
  48. case SOUL_SAND:
  49. case STONE:
  50. case SUGAR_CANE_BLOCK:
  51. case VINE:
  52. case WATER_LILY:
  53. case YELLOW_FLOWER:
  54. case COCOA:
  55. case EMERALD_ORE:
  56. case CARROT:
  57. case POTATO:
  58. return true;
  59. default:
  60. ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
  61. if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customItems.contains(item)) {
  62. return true;
  63. }
  64. return false;
  65. }
  66. }
  67. /**
  68. * Check if a block should allow for the activation of abilities.
  69. *
  70. * @param block Block to check
  71. * @return true if the block should allow ability activation, false otherwise
  72. */
  73. public static boolean canActivateAbilities(Block block) {
  74. ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
  75. if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customAbilityBlocks.contains(item)) {
  76. return false;
  77. }
  78. switch (block.getType()) {
  79. case BED_BLOCK:
  80. case BREWING_STAND:
  81. case BOOKSHELF:
  82. case BURNING_FURNACE:
  83. case CAKE_BLOCK:
  84. case CHEST:
  85. case DISPENSER:
  86. case ENCHANTMENT_TABLE:
  87. case ENDER_CHEST:
  88. case FENCE_GATE:
  89. case FURNACE:
  90. case IRON_DOOR_BLOCK:
  91. case JUKEBOX:
  92. case LEVER:
  93. case NOTE_BLOCK:
  94. case STONE_BUTTON:
  95. case WOOD_BUTTON:
  96. case TRAP_DOOR:
  97. case WALL_SIGN:
  98. case WOODEN_DOOR:
  99. case WORKBENCH:
  100. case BEACON:
  101. case ANVIL:
  102. return false;
  103. default:
  104. if (block.getTypeId() == Config.getInstance().getRepairAnvilId() || block.getTypeId() == Config.getInstance().getSalvageAnvilId()) {
  105. return false;
  106. }
  107. return true;
  108. }
  109. }
  110. /**
  111. * Check if a block type is an ore.
  112. *
  113. * @param block Block to check
  114. * @return true if the Block is an ore, false otherwise
  115. */
  116. public static boolean isOre(Block block) {
  117. switch (block.getType()) {
  118. case COAL_ORE:
  119. case DIAMOND_ORE:
  120. case GLOWING_REDSTONE_ORE:
  121. case GOLD_ORE:
  122. case IRON_ORE:
  123. case LAPIS_ORE:
  124. case REDSTONE_ORE:
  125. case EMERALD_ORE:
  126. return true;
  127. default:
  128. if (configInstance.getBlockModsEnabled() && ModChecks.isCustomOreBlock(block)) {
  129. return true;
  130. }
  131. return false;
  132. }
  133. }
  134. /**
  135. * Check if a block can be made mossy.
  136. *
  137. * @param block The block to check
  138. * @return true if the block can be made mossy, false otherwise
  139. */
  140. public static boolean canMakeMossy(Block block) {
  141. switch (block.getType()) {
  142. case COBBLESTONE:
  143. case DIRT:
  144. return true;
  145. case SMOOTH_BRICK:
  146. case COBBLE_WALL:
  147. if (block.getData() == 0) {
  148. return true;
  149. }
  150. default:
  151. return false;
  152. }
  153. }
  154. /**
  155. * Check if a block is affected by Herbalism abilities.
  156. *
  157. * @param block Block to check
  158. * @return true if the block is affected, false otherwise
  159. */
  160. public static boolean canBeGreenTerra(Block block) {
  161. switch (block.getType()) {
  162. case BROWN_MUSHROOM:
  163. case CACTUS:
  164. case MELON_BLOCK:
  165. case PUMPKIN:
  166. case RED_MUSHROOM:
  167. case RED_ROSE:
  168. case SUGAR_CANE_BLOCK:
  169. case VINE:
  170. case WATER_LILY:
  171. case YELLOW_FLOWER:
  172. return true;
  173. case CARROT:
  174. case CROPS:
  175. case POTATO:
  176. if (block.getData() == CropState.RIPE.getData()) {
  177. return true;
  178. }
  179. return false;
  180. case NETHER_WARTS:
  181. if (block.getData() == (byte) 0x3) {
  182. return true;
  183. }
  184. return false;
  185. case COCOA:
  186. CocoaPlant plant = (CocoaPlant) block.getState().getData();
  187. if (plant.getSize() == CocoaPlantSize.LARGE) {
  188. return true;
  189. }
  190. return false;
  191. default:
  192. ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
  193. if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customHerbalismBlocks.contains(item)) {
  194. return true;
  195. }
  196. return false;
  197. }
  198. }
  199. /**
  200. * Check to see if a block is broken by Super Breaker.
  201. *
  202. * @param block Block to check
  203. * @return true if the block would be broken by Super Breaker, false otherwise
  204. */
  205. public static Boolean canBeSuperBroken(Block block) {
  206. switch (block.getType()) {
  207. case COAL_ORE:
  208. case DIAMOND_ORE:
  209. case ENDER_STONE:
  210. case GLOWING_REDSTONE_ORE:
  211. case GLOWSTONE:
  212. case GOLD_ORE:
  213. case IRON_ORE:
  214. case LAPIS_ORE:
  215. case MOSSY_COBBLESTONE:
  216. case NETHERRACK:
  217. case OBSIDIAN:
  218. case REDSTONE_ORE:
  219. case SANDSTONE:
  220. case STONE:
  221. case EMERALD_ORE:
  222. return true;
  223. default:
  224. ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
  225. if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customMiningBlocks.contains(item)) {
  226. return true;
  227. }
  228. return false;
  229. }
  230. }
  231. /**
  232. * Check to see if a block can be broken by Giga Drill Breaker.
  233. *
  234. * @param block Block to check
  235. * @return true if the block can be broken by Giga Drill Breaker, false otherwise
  236. */
  237. public static boolean canBeGigaDrillBroken(Block block) {
  238. switch (block.getType()) {
  239. case CLAY:
  240. case DIRT:
  241. case GRASS:
  242. case GRAVEL:
  243. case MYCEL:
  244. case SAND:
  245. case SOUL_SAND:
  246. return true;
  247. default:
  248. ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
  249. if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customExcavationBlocks.contains(item)) {
  250. return true;
  251. }
  252. return false;
  253. }
  254. }
  255. /**
  256. * Checks if the block is affected by Tree Feller.
  257. *
  258. * @param block Block to check
  259. * @return true if the block is affected by Tree Feller, false otherwise
  260. */
  261. public static boolean treeFellerCompatible(Block block) {
  262. switch (block.getType()) {
  263. case LOG:
  264. case LEAVES:
  265. return true;
  266. default:
  267. ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
  268. if (configInstance.getBlockModsEnabled() && CustomBlocksConfig.getInstance().customWoodcuttingBlocks.contains(item)) {
  269. return true;
  270. }
  271. return false;
  272. }
  273. }
  274. public static boolean isLog(Block block) {
  275. if (block.getType().equals(Material.LOG) || (configInstance.getBlockModsEnabled() && ModChecks.isCustomLogBlock(block))) {
  276. return true;
  277. }
  278. return false;
  279. }
  280. public static boolean isLeaves(Block block) {
  281. if (block.getType().equals(Material.LEAVES) || (configInstance.getBlockModsEnabled() && ModChecks.isCustomLeafBlock(block))) {
  282. return true;
  283. }
  284. return false;
  285. }
  286. public static boolean canBeFluxMined(Block block) {
  287. switch (block.getType()) {
  288. case IRON_ORE:
  289. case GOLD_ORE:
  290. return true;
  291. default:
  292. return false;
  293. }
  294. }
  295. public static boolean canActivateHerbalism(Block block) {
  296. switch (block.getType()) {
  297. case DIRT:
  298. case GRASS:
  299. case SOIL:
  300. return false;
  301. default:
  302. return true;
  303. }
  304. }
  305. }