2012-04-27 11:47:11 +02:00
|
|
|
package com.gmail.nossr50.util;
|
|
|
|
|
2012-05-18 17:15:30 +02:00
|
|
|
import org.bukkit.CropState;
|
|
|
|
import org.bukkit.Material;
|
2012-05-10 15:54:29 +02:00
|
|
|
import org.bukkit.block.Block;
|
2012-05-17 06:24:33 +02:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2012-12-25 07:01:10 +01:00
|
|
|
import org.bukkit.material.MaterialData;
|
2012-04-27 11:47:11 +02:00
|
|
|
|
|
|
|
import com.gmail.nossr50.config.Config;
|
2012-05-17 06:24:33 +02:00
|
|
|
import com.gmail.nossr50.config.mods.CustomBlocksConfig;
|
2012-04-27 11:47:11 +02:00
|
|
|
|
|
|
|
public class BlockChecks {
|
2012-05-17 06:24:33 +02:00
|
|
|
private static Config configInstance = Config.getInstance();
|
|
|
|
private static boolean customBlocksEnabled = configInstance.getBlockModsEnabled();
|
2012-04-27 11:47:11 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if a block type awards XP.
|
|
|
|
*
|
2012-05-10 15:54:29 +02:00
|
|
|
* @param block Block to check
|
2012-04-27 11:47:11 +02:00
|
|
|
* @return true if the block type awards XP, false otherwise
|
|
|
|
*/
|
2012-05-17 06:24:33 +02:00
|
|
|
public static boolean shouldBeWatched(Block block) {
|
|
|
|
switch (block.getType()) {
|
2012-04-27 11:47:11 +02:00
|
|
|
case BROWN_MUSHROOM:
|
|
|
|
case CACTUS:
|
|
|
|
case CLAY:
|
|
|
|
case COAL_ORE:
|
|
|
|
case DIAMOND_ORE:
|
|
|
|
case DIRT:
|
|
|
|
case ENDER_STONE:
|
|
|
|
case GLOWING_REDSTONE_ORE:
|
|
|
|
case GLOWSTONE:
|
|
|
|
case GOLD_ORE:
|
|
|
|
case GRASS:
|
|
|
|
case GRAVEL:
|
|
|
|
case IRON_ORE:
|
|
|
|
case LAPIS_ORE:
|
|
|
|
case LOG:
|
|
|
|
case MELON_BLOCK:
|
|
|
|
case MOSSY_COBBLESTONE:
|
|
|
|
case MYCEL:
|
|
|
|
case NETHERRACK:
|
|
|
|
case OBSIDIAN:
|
|
|
|
case PUMPKIN:
|
|
|
|
case RED_MUSHROOM:
|
|
|
|
case RED_ROSE:
|
|
|
|
case REDSTONE_ORE:
|
|
|
|
case SAND:
|
|
|
|
case SANDSTONE:
|
|
|
|
case SOUL_SAND:
|
|
|
|
case STONE:
|
|
|
|
case SUGAR_CANE_BLOCK:
|
|
|
|
case VINE:
|
|
|
|
case WATER_LILY:
|
|
|
|
case YELLOW_FLOWER:
|
2012-10-18 06:26:16 +02:00
|
|
|
case COCOA:
|
|
|
|
case EMERALD_ORE:
|
2012-10-29 04:53:03 +01:00
|
|
|
case CARROT:
|
|
|
|
case POTATO:
|
2012-04-27 11:47:11 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2012-12-29 21:59:18 +01:00
|
|
|
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
2012-12-25 07:01:10 +01:00
|
|
|
|
|
|
|
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customItems.contains(item)) {
|
2012-05-17 06:24:33 +02:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return false;
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a block should allow for the activation of abilities.
|
|
|
|
*
|
2012-05-10 15:54:29 +02:00
|
|
|
* @param block Block to check
|
2012-04-27 11:47:11 +02:00
|
|
|
* @return true if the block should allow ability activation, false otherwise
|
|
|
|
*/
|
2012-05-10 15:54:29 +02:00
|
|
|
public static boolean abilityBlockCheck(Block block) {
|
2012-12-29 21:59:18 +01:00
|
|
|
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
2012-12-25 07:01:10 +01:00
|
|
|
|
|
|
|
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customAbilityBlocks.contains(item)) {
|
2012-07-03 03:05:55 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-05-10 15:54:29 +02:00
|
|
|
switch (block.getType()) {
|
2012-04-27 11:47:11 +02:00
|
|
|
case BED_BLOCK:
|
|
|
|
case BREWING_STAND:
|
|
|
|
case BOOKSHELF:
|
|
|
|
case BURNING_FURNACE:
|
|
|
|
case CAKE_BLOCK:
|
|
|
|
case CHEST:
|
|
|
|
case DISPENSER:
|
|
|
|
case ENCHANTMENT_TABLE:
|
2012-09-30 18:48:20 +02:00
|
|
|
case ENDER_CHEST:
|
2012-04-27 11:47:11 +02:00
|
|
|
case FENCE_GATE:
|
|
|
|
case FURNACE:
|
|
|
|
case IRON_DOOR_BLOCK:
|
|
|
|
case JUKEBOX:
|
|
|
|
case LEVER:
|
|
|
|
case NOTE_BLOCK:
|
|
|
|
case STONE_BUTTON:
|
2012-12-25 15:35:12 +01:00
|
|
|
case WOOD_BUTTON:
|
2012-04-27 11:47:11 +02:00
|
|
|
case TRAP_DOOR:
|
|
|
|
case WALL_SIGN:
|
|
|
|
case WOODEN_DOOR:
|
|
|
|
case WORKBENCH:
|
2012-10-29 04:53:03 +01:00
|
|
|
case BEACON:
|
|
|
|
case ANVIL:
|
2012-04-27 11:47:11 +02:00
|
|
|
return false;
|
2012-07-03 01:26:40 +02:00
|
|
|
|
|
|
|
default:
|
2012-11-13 22:14:26 +01:00
|
|
|
if (block.getTypeId() == Config.getInstance().getRepairAnvilId() || block.getTypeId() == Config.getInstance().getSalvageAnvilId()) {
|
2012-07-03 03:05:55 +02:00
|
|
|
return false;
|
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return true;
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a block type is an ore.
|
|
|
|
*
|
2012-05-10 15:54:29 +02:00
|
|
|
* @param block Block to check
|
2012-04-27 11:47:11 +02:00
|
|
|
* @return true if the Block is an ore, false otherwise
|
|
|
|
*/
|
2012-05-10 15:54:29 +02:00
|
|
|
public static boolean isOre(Block block) {
|
|
|
|
switch (block.getType()) {
|
2012-04-27 11:47:11 +02:00
|
|
|
case COAL_ORE:
|
|
|
|
case DIAMOND_ORE:
|
|
|
|
case GLOWING_REDSTONE_ORE:
|
|
|
|
case GOLD_ORE:
|
|
|
|
case IRON_ORE:
|
|
|
|
case LAPIS_ORE:
|
|
|
|
case REDSTONE_ORE:
|
2012-10-18 06:26:16 +02:00
|
|
|
case EMERALD_ORE:
|
2012-04-27 11:47:11 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2012-05-17 23:03:56 +02:00
|
|
|
if (customBlocksEnabled && ModChecks.isCustomOreBlock(block)) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return false;
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|
|
|
|
}
|
2012-05-01 07:14:32 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a block can be made mossy.
|
|
|
|
*
|
2012-05-10 15:54:29 +02:00
|
|
|
* @param block The block to check
|
2012-05-01 07:14:32 +02:00
|
|
|
* @return true if the block can be made mossy, false otherwise
|
|
|
|
*/
|
2012-05-10 15:54:29 +02:00
|
|
|
public static boolean makeMossy(Block block) {
|
|
|
|
switch (block.getType()) {
|
2012-05-01 07:14:32 +02:00
|
|
|
case COBBLESTONE:
|
|
|
|
case DIRT:
|
|
|
|
return true;
|
2012-05-10 15:54:29 +02:00
|
|
|
case SMOOTH_BRICK:
|
2012-11-05 01:06:33 +01:00
|
|
|
case COBBLE_WALL:
|
2012-05-10 15:54:29 +02:00
|
|
|
if (block.getData() == 0) {
|
|
|
|
return true;
|
|
|
|
}
|
2012-05-01 07:14:32 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a block is affected by Herbalism abilities.
|
|
|
|
*
|
2012-05-10 15:54:29 +02:00
|
|
|
* @param block Block to check
|
2012-05-01 07:14:32 +02:00
|
|
|
* @return true if the block is affected, false otherwise
|
|
|
|
*/
|
2013-01-10 05:03:17 +01:00
|
|
|
public static boolean canBeGreenTerra(Block block) {
|
2012-05-10 15:54:29 +02:00
|
|
|
switch (block.getType()) {
|
2012-05-01 07:14:32 +02:00
|
|
|
case BROWN_MUSHROOM:
|
|
|
|
case CACTUS:
|
|
|
|
case MELON_BLOCK:
|
|
|
|
case NETHER_WARTS:
|
|
|
|
case PUMPKIN:
|
|
|
|
case RED_MUSHROOM:
|
|
|
|
case RED_ROSE:
|
|
|
|
case SUGAR_CANE_BLOCK:
|
|
|
|
case VINE:
|
|
|
|
case WATER_LILY:
|
|
|
|
case YELLOW_FLOWER:
|
2012-10-18 06:26:16 +02:00
|
|
|
case COCOA:
|
2012-10-29 04:53:03 +01:00
|
|
|
case CARROT:
|
|
|
|
case POTATO:
|
2012-05-01 07:14:32 +02:00
|
|
|
return true;
|
|
|
|
|
2012-05-18 17:15:30 +02:00
|
|
|
case CROPS:
|
|
|
|
if (block.getData() == CropState.RIPE.getData()) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return false;
|
2012-05-18 17:15:30 +02:00
|
|
|
|
2012-05-01 07:14:32 +02:00
|
|
|
default:
|
2012-12-29 21:59:18 +01:00
|
|
|
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
2012-12-25 07:01:10 +01:00
|
|
|
|
|
|
|
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customHerbalismBlocks.contains(item)) {
|
2012-05-17 06:24:33 +02:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return false;
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if a block is broken by Super Breaker.
|
|
|
|
*
|
2012-05-10 15:54:29 +02:00
|
|
|
* @param block Block to check
|
2012-05-01 07:14:32 +02:00
|
|
|
* @return true if the block would be broken by Super Breaker, false otherwise
|
|
|
|
*/
|
2012-05-10 15:54:29 +02:00
|
|
|
public static Boolean canBeSuperBroken(Block block) {
|
|
|
|
switch (block.getType()) {
|
2012-05-01 07:14:32 +02:00
|
|
|
case COAL_ORE:
|
|
|
|
case DIAMOND_ORE:
|
|
|
|
case ENDER_STONE:
|
|
|
|
case GLOWING_REDSTONE_ORE:
|
|
|
|
case GLOWSTONE:
|
|
|
|
case GOLD_ORE:
|
|
|
|
case IRON_ORE:
|
|
|
|
case LAPIS_ORE:
|
|
|
|
case MOSSY_COBBLESTONE:
|
|
|
|
case NETHERRACK:
|
|
|
|
case OBSIDIAN:
|
|
|
|
case REDSTONE_ORE:
|
|
|
|
case SANDSTONE:
|
|
|
|
case STONE:
|
2012-10-18 06:26:16 +02:00
|
|
|
case EMERALD_ORE:
|
2012-05-01 07:14:32 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2012-12-29 21:59:18 +01:00
|
|
|
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
2012-12-25 07:01:10 +01:00
|
|
|
|
|
|
|
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customMiningBlocks.contains(item)) {
|
2012-05-17 06:24:33 +02:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return false;
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if a block can be broken by Giga Drill Breaker.
|
|
|
|
*
|
2012-05-10 15:54:29 +02:00
|
|
|
* @param block Block to check
|
|
|
|
* @return true if the block can be broken by Giga Drill Breaker, false otherwise
|
2012-05-01 07:14:32 +02:00
|
|
|
*/
|
2012-05-10 15:54:29 +02:00
|
|
|
public static boolean canBeGigaDrillBroken(Block block) {
|
|
|
|
switch (block.getType()) {
|
2012-05-01 07:14:32 +02:00
|
|
|
case CLAY:
|
|
|
|
case DIRT:
|
|
|
|
case GRASS:
|
|
|
|
case GRAVEL:
|
|
|
|
case MYCEL:
|
|
|
|
case SAND:
|
|
|
|
case SOUL_SAND:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2012-12-29 21:59:18 +01:00
|
|
|
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
2012-12-25 07:01:10 +01:00
|
|
|
|
|
|
|
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customExcavationBlocks.contains(item)) {
|
2012-05-17 06:24:33 +02:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return false;
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the block is affected by Tree Feller.
|
|
|
|
*
|
|
|
|
* @param block Block to check
|
|
|
|
* @return true if the block is affected by Tree Feller, false otherwise
|
|
|
|
*/
|
2012-05-10 15:54:29 +02:00
|
|
|
public static boolean treeFellerCompatible(Block block) {
|
|
|
|
switch (block.getType()) {
|
2012-05-01 07:14:32 +02:00
|
|
|
case LOG:
|
|
|
|
case LEAVES:
|
|
|
|
case AIR:
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2012-12-29 21:59:18 +01:00
|
|
|
ItemStack item = (new MaterialData(block.getTypeId(), block.getData())).toItemStack(1);
|
2012-12-25 07:01:10 +01:00
|
|
|
|
|
|
|
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customWoodcuttingBlocks.contains(item)) {
|
2012-05-17 06:24:33 +02:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return false;
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
}
|
2012-05-18 17:15:30 +02:00
|
|
|
|
2013-01-10 05:03:17 +01:00
|
|
|
public static boolean isLog (Block block) {
|
2012-05-18 17:15:30 +02:00
|
|
|
if (block.getType().equals(Material.LOG) || (customBlocksEnabled && ModChecks.isCustomLogBlock(block))) {
|
|
|
|
return true;
|
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return false;
|
2012-05-18 17:15:30 +02:00
|
|
|
}
|
2012-04-27 11:47:11 +02:00
|
|
|
}
|