2
0

BlockChecks.java 7.5 KB

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