2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.util;
|
|
|
|
|
|
|
|
import org.bukkit.block.BlockState;
|
|
|
|
import org.bukkit.entity.Entity;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.config.Config;
|
|
|
|
import com.gmail.nossr50.config.mods.CustomArmorConfig;
|
|
|
|
import com.gmail.nossr50.config.mods.CustomBlockConfig;
|
|
|
|
import com.gmail.nossr50.config.mods.CustomEntityConfig;
|
|
|
|
import com.gmail.nossr50.config.mods.CustomToolConfig;
|
|
|
|
import com.gmail.nossr50.datatypes.mods.CustomBlock;
|
|
|
|
import com.gmail.nossr50.datatypes.mods.CustomEntity;
|
|
|
|
import com.gmail.nossr50.datatypes.mods.CustomTool;
|
|
|
|
|
|
|
|
public final class ModUtils {
|
|
|
|
private static Config configInstance = Config.getInstance();
|
|
|
|
|
|
|
|
private static boolean customToolsEnabled = configInstance.getToolModsEnabled();
|
|
|
|
private static boolean customArmorEnabled = configInstance.getArmorModsEnabled();
|
|
|
|
private static boolean customBlocksEnabled = configInstance.getBlockModsEnabled();
|
|
|
|
private static boolean customEntitiesEnabled = configInstance.getEntityModsEnabled();
|
|
|
|
|
|
|
|
private ModUtils() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the custom tool associated with an item.
|
|
|
|
*
|
|
|
|
* @param item The item to check
|
|
|
|
* @return the tool if it exists, null otherwise
|
|
|
|
*/
|
|
|
|
public static CustomTool getToolFromItemStack(ItemStack item) {
|
2013-09-22 17:31:54 +02:00
|
|
|
return CustomToolConfig.getInstance().customToolMap.get(item.getType());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the custom block associated with an block.
|
|
|
|
*
|
|
|
|
* @param blockState The block to check
|
|
|
|
* @return the block if it exists, null otherwise
|
|
|
|
*/
|
|
|
|
public static CustomBlock getCustomBlock(BlockState blockState) {
|
2013-09-24 15:10:33 +02:00
|
|
|
return CustomBlockConfig.getInstance().customBlockMap.get(blockState.getData());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static CustomEntity getCustomEntity(Entity entity) {
|
|
|
|
if (!CustomEntityConfig.getInstance().customEntityIds.contains(entity.getEntityId()) && !CustomEntityConfig.getInstance().customEntityTypes.contains(entity.getType())) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (CustomEntity customEntity : CustomEntityConfig.getInstance().customEntities) {
|
|
|
|
if ((customEntity.getEntityID() == entity.getEntityId()) && (customEntity.getEntityType() == entity.getType())) {
|
|
|
|
return customEntity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a custom block is a woodcutting block.
|
|
|
|
*
|
2013-08-10 20:10:45 +02:00
|
|
|
* @param blockState The BlockState of the block to check
|
2013-09-24 15:10:33 +02:00
|
|
|
* @return true if the block represents a custom woodcutting block, false otherwise
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
|
|
|
public static boolean isCustomWoodcuttingBlock(BlockState blockState) {
|
2013-09-24 15:10:33 +02:00
|
|
|
return customBlocksEnabled && CustomBlockConfig.getInstance().customWoodcuttingBlocks.contains(blockState.getData());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a custom block should not activate abilites.
|
|
|
|
*
|
2013-08-10 20:10:45 +02:00
|
|
|
* @param blockState The BlockState of the block to check
|
2013-03-01 06:52:01 +01:00
|
|
|
* @return true if the block represents an ability block, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isCustomAbilityBlock(BlockState blockState) {
|
2013-09-24 15:10:33 +02:00
|
|
|
return customBlocksEnabled && CustomBlockConfig.getInstance().customAbilityBlocks.contains(blockState.getData());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a custom block is a mining block.
|
|
|
|
*
|
2013-08-10 20:10:45 +02:00
|
|
|
* @param blockState The BlockState of the block to check
|
2013-09-24 15:10:33 +02:00
|
|
|
* @return true if the block represents a custom mining block, false otherwise
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
|
|
|
public static boolean isCustomMiningBlock(BlockState blockState) {
|
2013-09-24 15:10:33 +02:00
|
|
|
return customBlocksEnabled && CustomBlockConfig.getInstance().customMiningBlocks.contains(blockState.getData());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a custom block is an excavation block.
|
|
|
|
*
|
2013-08-10 20:10:45 +02:00
|
|
|
* @param blockState The BlockState of the block to check
|
2013-09-24 15:10:33 +02:00
|
|
|
* @return true if the block represents a custom excavation block, false otherwise
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
|
|
|
public static boolean isCustomExcavationBlock(BlockState blockState) {
|
2013-09-24 15:10:33 +02:00
|
|
|
return customBlocksEnabled && CustomBlockConfig.getInstance().customExcavationBlocks.contains(blockState.getData());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a custom block is an herbalism block.
|
|
|
|
*
|
2013-09-24 15:10:33 +02:00
|
|
|
* @param blockState The BlockState of the block to check
|
|
|
|
* @return true if the block represents a custom herbalism block, false otherwise
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
|
|
|
public static boolean isCustomHerbalismBlock(BlockState blockState) {
|
2013-09-24 15:10:33 +02:00
|
|
|
return customBlocksEnabled && CustomBlockConfig.getInstance().customHerbalismBlocks.contains(blockState.getData());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a custom block is a leaf block.
|
|
|
|
*
|
2013-08-10 20:10:45 +02:00
|
|
|
* @param blockState The BlockState of the block to check
|
2013-03-01 06:52:01 +01:00
|
|
|
* @return true if the block represents leaves, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isCustomLeafBlock(BlockState blockState) {
|
2013-09-24 15:10:33 +02:00
|
|
|
return customBlocksEnabled && CustomBlockConfig.getInstance().customLeaves.contains(blockState.getData());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a custom block is a log block.
|
|
|
|
*
|
2013-08-10 20:10:45 +02:00
|
|
|
* @param blockState The BlockState of the block to check
|
2013-03-01 06:52:01 +01:00
|
|
|
* @return true if the block represents a log, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isCustomLogBlock(BlockState blockState) {
|
2013-09-24 15:10:33 +02:00
|
|
|
return customBlocksEnabled && CustomBlockConfig.getInstance().customLogs.contains(blockState.getData());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a custom block is an ore block.
|
|
|
|
*
|
2013-09-24 15:10:33 +02:00
|
|
|
* @param blockState The BlockState of the block to check
|
2013-03-01 06:52:01 +01:00
|
|
|
* @return true if the block represents an ore, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isCustomOreBlock(BlockState blockState) {
|
2013-09-24 15:10:33 +02:00
|
|
|
return customBlocksEnabled && CustomBlockConfig.getInstance().customOres.contains(blockState.getData());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if an item is a custom tool.
|
|
|
|
*
|
|
|
|
* @param item Item to check
|
|
|
|
* @return true if the item is a custom tool, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isCustomTool(ItemStack item) {
|
2013-09-24 15:10:33 +02:00
|
|
|
return customToolsEnabled && CustomToolConfig.getInstance().customTool.contains(item.getType());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if an item is custom armor.
|
|
|
|
*
|
|
|
|
* @param item Item to check
|
|
|
|
* @return true if the item is custom armor, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isCustomArmor(ItemStack item) {
|
2013-09-24 15:10:33 +02:00
|
|
|
return customArmorEnabled && CustomArmorConfig.getInstance().customArmor.contains(item.getType());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isCustomEntity(Entity entity) {
|
2013-09-24 15:10:33 +02:00
|
|
|
return customEntitiesEnabled && CustomEntityConfig.getInstance().customEntityIds.contains(entity.getEntityId());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2013-06-28 13:36:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a custom entity is a boss.
|
|
|
|
*
|
|
|
|
* @param entity The entity to check
|
|
|
|
* @return true if the entity represents a boss, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isCustomBossEntity(Entity entity) {
|
|
|
|
//TODO: Finish this method
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|