BlockChecks.java 9.8 KB

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