BlockChecks.java 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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.MaterialData;
  7. import com.gmail.nossr50.config.Config;
  8. import com.gmail.nossr50.config.mods.CustomBlocksConfig;
  9. public class BlockChecks {
  10. private static Config configInstance = Config.getInstance();
  11. private static boolean customBlocksEnabled = configInstance.getBlockModsEnabled();
  12. /**
  13. * Checks to see if a block type awards XP.
  14. *
  15. * @param block Block to check
  16. * @return true if the block type awards XP, false otherwise
  17. */
  18. public static boolean shouldBeWatched(Block block) {
  19. switch (block.getType()) {
  20. case BROWN_MUSHROOM:
  21. case CACTUS:
  22. case CLAY:
  23. case COAL_ORE:
  24. case DIAMOND_ORE:
  25. case DIRT:
  26. case ENDER_STONE:
  27. case GLOWING_REDSTONE_ORE:
  28. case GLOWSTONE:
  29. case GOLD_ORE:
  30. case GRASS:
  31. case GRAVEL:
  32. case IRON_ORE:
  33. case LAPIS_ORE:
  34. case LOG:
  35. case MELON_BLOCK:
  36. case MOSSY_COBBLESTONE:
  37. case MYCEL:
  38. case NETHERRACK:
  39. case OBSIDIAN:
  40. case PUMPKIN:
  41. case RED_MUSHROOM:
  42. case RED_ROSE:
  43. case REDSTONE_ORE:
  44. case SAND:
  45. case SANDSTONE:
  46. case SOUL_SAND:
  47. case STONE:
  48. case SUGAR_CANE_BLOCK:
  49. case VINE:
  50. case WATER_LILY:
  51. case YELLOW_FLOWER:
  52. case COCOA:
  53. case EMERALD_ORE:
  54. case CARROT:
  55. case POTATO:
  56. return true;
  57. default:
  58. ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
  59. if (customBlocksEnabled && CustomBlocksConfig.getInstance().customItems.contains(item)) {
  60. return true;
  61. }
  62. else {
  63. return false;
  64. }
  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 abilityBlockCheck(Block block) {
  74. ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
  75. if (customBlocksEnabled && 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. else {
  108. return true;
  109. }
  110. }
  111. }
  112. /**
  113. * Check if a block type is an ore.
  114. *
  115. * @param block Block to check
  116. * @return true if the Block is an ore, false otherwise
  117. */
  118. public static boolean isOre(Block block) {
  119. switch (block.getType()) {
  120. case COAL_ORE:
  121. case DIAMOND_ORE:
  122. case GLOWING_REDSTONE_ORE:
  123. case GOLD_ORE:
  124. case IRON_ORE:
  125. case LAPIS_ORE:
  126. case REDSTONE_ORE:
  127. case EMERALD_ORE:
  128. return true;
  129. default:
  130. if (customBlocksEnabled && ModChecks.isCustomOreBlock(block)) {
  131. return true;
  132. }
  133. else {
  134. return false;
  135. }
  136. }
  137. }
  138. /**
  139. * Check if a block can be made mossy.
  140. *
  141. * @param block The block to check
  142. * @return true if the block can be made mossy, false otherwise
  143. */
  144. public static boolean makeMossy(Block block) {
  145. switch (block.getType()) {
  146. case COBBLESTONE:
  147. case DIRT:
  148. return true;
  149. case SMOOTH_BRICK:
  150. case COBBLE_WALL:
  151. if (block.getData() == 0) {
  152. return true;
  153. }
  154. default:
  155. return false;
  156. }
  157. }
  158. /**
  159. * Check if a block is affected by Herbalism abilities.
  160. *
  161. * @param block Block to check
  162. * @return true if the block is affected, false otherwise
  163. */
  164. public static boolean canBeGreenTerra(Block block){
  165. switch (block.getType()) {
  166. case BROWN_MUSHROOM:
  167. case CACTUS:
  168. case MELON_BLOCK:
  169. case NETHER_WARTS:
  170. case PUMPKIN:
  171. case RED_MUSHROOM:
  172. case RED_ROSE:
  173. case SUGAR_CANE_BLOCK:
  174. case VINE:
  175. case WATER_LILY:
  176. case YELLOW_FLOWER:
  177. case COCOA:
  178. case CARROT:
  179. case POTATO:
  180. return true;
  181. case CROPS:
  182. if (block.getData() == CropState.RIPE.getData()) {
  183. return true;
  184. }
  185. else {
  186. return false;
  187. }
  188. default:
  189. ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
  190. if (customBlocksEnabled && CustomBlocksConfig.getInstance().customHerbalismBlocks.contains(item)) {
  191. return true;
  192. }
  193. else {
  194. return false;
  195. }
  196. }
  197. }
  198. /**
  199. * Check to see if a block is broken by Super Breaker.
  200. *
  201. * @param block Block to check
  202. * @return true if the block would be broken by Super Breaker, false otherwise
  203. */
  204. public static Boolean canBeSuperBroken(Block block) {
  205. switch (block.getType()) {
  206. case COAL_ORE:
  207. case DIAMOND_ORE:
  208. case ENDER_STONE:
  209. case GLOWING_REDSTONE_ORE:
  210. case GLOWSTONE:
  211. case GOLD_ORE:
  212. case IRON_ORE:
  213. case LAPIS_ORE:
  214. case MOSSY_COBBLESTONE:
  215. case NETHERRACK:
  216. case OBSIDIAN:
  217. case REDSTONE_ORE:
  218. case SANDSTONE:
  219. case STONE:
  220. case EMERALD_ORE:
  221. return true;
  222. default:
  223. ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
  224. if (customBlocksEnabled && CustomBlocksConfig.getInstance().customMiningBlocks.contains(item)) {
  225. return true;
  226. }
  227. else {
  228. return false;
  229. }
  230. }
  231. }
  232. /**
  233. * Check to see if a block can be broken by Giga Drill Breaker.
  234. *
  235. * @param block Block to check
  236. * @return true if the block can be broken by Giga Drill Breaker, false otherwise
  237. */
  238. public static boolean canBeGigaDrillBroken(Block block) {
  239. switch (block.getType()) {
  240. case CLAY:
  241. case DIRT:
  242. case GRASS:
  243. case GRAVEL:
  244. case MYCEL:
  245. case SAND:
  246. case SOUL_SAND:
  247. return true;
  248. default:
  249. ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
  250. if (customBlocksEnabled && CustomBlocksConfig.getInstance().customExcavationBlocks.contains(item)) {
  251. return true;
  252. }
  253. else {
  254. return false;
  255. }
  256. }
  257. }
  258. /**
  259. * Checks if the block is affected by Tree Feller.
  260. *
  261. * @param block Block to check
  262. * @return true if the block is affected by Tree Feller, false otherwise
  263. */
  264. public static boolean treeFellerCompatible(Block block) {
  265. switch (block.getType()) {
  266. case LOG:
  267. case LEAVES:
  268. case AIR:
  269. return true;
  270. default:
  271. ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
  272. if (customBlocksEnabled && CustomBlocksConfig.getInstance().customWoodcuttingBlocks.contains(item)) {
  273. return true;
  274. }
  275. else {
  276. return false;
  277. }
  278. }
  279. }
  280. public static boolean isLog (Block block){
  281. if (block.getType().equals(Material.LOG) || (customBlocksEnabled && ModChecks.isCustomLogBlock(block))) {
  282. return true;
  283. }
  284. else {
  285. return false;
  286. }
  287. }
  288. }