2013-01-30 17:35:33 +01:00
|
|
|
package com.gmail.nossr50.mods;
|
2012-05-15 19:44:39 +02:00
|
|
|
|
2012-05-17 06:24:33 +02:00
|
|
|
import org.bukkit.block.Block;
|
2013-02-06 04:40:19 +01:00
|
|
|
import org.bukkit.entity.Entity;
|
2012-05-15 19:44:39 +02:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2012-12-25 07:01:10 +01:00
|
|
|
import org.bukkit.material.MaterialData;
|
2012-05-15 19:44:39 +02:00
|
|
|
|
2012-05-18 20:29:53 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-01-30 17:35:33 +01:00
|
|
|
import com.gmail.nossr50.mods.config.CustomArmorConfig;
|
|
|
|
import com.gmail.nossr50.mods.config.CustomBlocksConfig;
|
2013-02-06 04:40:19 +01:00
|
|
|
import com.gmail.nossr50.mods.config.CustomEntityConfig;
|
2013-01-30 17:35:33 +01:00
|
|
|
import com.gmail.nossr50.mods.config.CustomToolsConfig;
|
|
|
|
import com.gmail.nossr50.mods.datatypes.CustomBlock;
|
2013-02-06 04:40:19 +01:00
|
|
|
import com.gmail.nossr50.mods.datatypes.CustomEntity;
|
2013-01-30 17:35:33 +01:00
|
|
|
import com.gmail.nossr50.mods.datatypes.CustomItem;
|
|
|
|
import com.gmail.nossr50.mods.datatypes.CustomTool;
|
2012-05-15 19:44:39 +02:00
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
public final class ModChecks {
|
2012-05-18 20:29:53 +02:00
|
|
|
private static Config configInstance = Config.getInstance();
|
|
|
|
private static boolean customToolsEnabled = configInstance.getToolModsEnabled();
|
|
|
|
private static boolean customArmorEnabled = configInstance.getArmorModsEnabled();
|
2012-05-22 05:41:11 +02:00
|
|
|
private static boolean customBlocksEnabled = configInstance.getBlockModsEnabled();
|
2013-02-06 04:40:19 +01:00
|
|
|
private static boolean customEntitiesEnabled = configInstance.getEntityModsEnabled();
|
2012-05-15 20:21:21 +02:00
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
private ModChecks() {}
|
|
|
|
|
2012-05-15 22:12:59 +02:00
|
|
|
/**
|
|
|
|
* Get the custom armor associated with an item.
|
|
|
|
*
|
|
|
|
* @param item The item to check
|
2012-05-18 20:29:53 +02:00
|
|
|
* @return the armor if it exists, null otherwise
|
2012-05-15 22:12:59 +02:00
|
|
|
*/
|
|
|
|
public static CustomItem getArmorFromItemStack(ItemStack item) {
|
2013-01-27 22:21:02 +01:00
|
|
|
return CustomArmorConfig.getInstance().customArmor.get(item.getTypeId());
|
2012-05-15 22:12:59 +02:00
|
|
|
}
|
|
|
|
|
2012-05-15 20:21:21 +02:00
|
|
|
/**
|
|
|
|
* Get the custom tool associated with an item.
|
|
|
|
*
|
|
|
|
* @param item The item to check
|
2012-05-18 20:29:53 +02:00
|
|
|
* @return the tool if it exists, null otherwise
|
2012-05-15 20:21:21 +02:00
|
|
|
*/
|
|
|
|
public static CustomTool getToolFromItemStack(ItemStack item) {
|
2013-01-27 22:21:02 +01:00
|
|
|
return CustomToolsConfig.getInstance().customTools.get(item.getTypeId());
|
2012-05-15 20:21:21 +02:00
|
|
|
}
|
2012-05-17 06:24:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the custom block associated with an block.
|
|
|
|
*
|
|
|
|
* @param block The block to check
|
2012-07-04 16:12:10 +02:00
|
|
|
* @return the block if it exists, null otherwise
|
2012-05-17 06:24:33 +02:00
|
|
|
*/
|
|
|
|
public static CustomBlock getCustomBlock(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
|
|
|
|
2013-01-27 22:21:02 +01:00
|
|
|
if (!CustomBlocksConfig.getInstance().customItems.contains(item)) {
|
2012-05-17 06:24:33 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-01-27 22:21:02 +01:00
|
|
|
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) {
|
2012-05-17 06:24:33 +02:00
|
|
|
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2012-05-17 23:03:56 +02:00
|
|
|
|
2013-02-06 04:40:19 +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;
|
|
|
|
}
|
2012-05-22 05:41:11 +02:00
|
|
|
/**
|
|
|
|
* Check if a custom block is a custom block.
|
|
|
|
*
|
|
|
|
* @param block The block to check
|
|
|
|
* @return true if the block is custom, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isCustomMiningBlock(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
|
|
|
|
2013-01-27 22:21:02 +01:00
|
|
|
if (customBlocksEnabled && CustomBlocksConfig.getInstance().customMiningBlocks.contains(item)) {
|
|
|
|
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) {
|
2012-12-29 06:11:22 +01:00
|
|
|
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-05-22 05:41:11 +02:00
|
|
|
}
|
2012-12-29 06:11:22 +01:00
|
|
|
|
|
|
|
return false;
|
2012-05-22 05:41:11 +02:00
|
|
|
}
|
|
|
|
|
2012-05-17 23:03:56 +02:00
|
|
|
/**
|
|
|
|
* Check if a custom block is a leaf block.
|
|
|
|
*
|
|
|
|
* @param block The block to check
|
|
|
|
* @return true if the block represents leaves, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isCustomLeafBlock(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
|
|
|
|
2013-01-27 22:21:02 +01:00
|
|
|
if (CustomBlocksConfig.getInstance().customLeaves.contains(item)) {
|
|
|
|
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) {
|
2012-12-29 06:11:22 +01:00
|
|
|
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-05-17 23:03:56 +02:00
|
|
|
}
|
2012-12-29 06:11:22 +01:00
|
|
|
|
|
|
|
return false;
|
2012-05-17 23:03:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a custom block is a log block.
|
|
|
|
*
|
|
|
|
* @param block The block to check
|
|
|
|
* @return true if the block represents a log, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isCustomLogBlock(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
|
|
|
|
2013-01-27 22:21:02 +01:00
|
|
|
if (CustomBlocksConfig.getInstance().customLogs.contains(item)) {
|
|
|
|
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) {
|
2012-12-29 06:11:22 +01:00
|
|
|
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-05-17 23:03:56 +02:00
|
|
|
}
|
2012-12-29 06:11:22 +01:00
|
|
|
|
|
|
|
return false;
|
2012-05-17 23:03:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a custom block is an ore block.
|
|
|
|
*
|
|
|
|
* @param block The block to check
|
|
|
|
* @return true if the block represents an ore, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isCustomOreBlock(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
|
|
|
|
2013-01-27 22:21:02 +01:00
|
|
|
if (CustomBlocksConfig.getInstance().customOres.contains(item)) {
|
|
|
|
for (CustomBlock b : CustomBlocksConfig.getInstance().customBlocks) {
|
2012-12-29 06:11:22 +01:00
|
|
|
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2012-05-17 23:03:56 +02:00
|
|
|
}
|
2012-12-29 06:11:22 +01:00
|
|
|
|
|
|
|
return false;
|
2012-05-17 23:03:56 +02:00
|
|
|
}
|
2012-05-18 20:29:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if an item is a custom tool.
|
|
|
|
*
|
2013-01-31 01:42:40 +01:00
|
|
|
* @param item Item to check
|
2012-05-18 20:29:53 +02:00
|
|
|
* @return true if the item is a custom tool, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isCustomTool(ItemStack item) {
|
2013-01-27 22:21:02 +01:00
|
|
|
if (customToolsEnabled && CustomToolsConfig.getInstance().customTools.containsKey(item.getTypeId())) {
|
2012-05-18 20:29:53 +02:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return false;
|
2012-05-18 20:29:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if an item is custom armor.
|
|
|
|
*
|
2013-01-31 01:42:40 +01:00
|
|
|
* @param item Item to check
|
2012-05-18 20:29:53 +02:00
|
|
|
* @return true if the item is custom armor, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isCustomArmor(ItemStack item) {
|
2013-01-27 22:21:02 +01:00
|
|
|
if (customArmorEnabled && CustomArmorConfig.getInstance().customArmor.containsKey(item.getTypeId())) {
|
2012-05-18 20:29:53 +02:00
|
|
|
return true;
|
|
|
|
}
|
2013-01-10 04:43:21 +01:00
|
|
|
|
|
|
|
return false;
|
2012-05-18 20:29:53 +02:00
|
|
|
}
|
2013-02-06 04:40:19 +01:00
|
|
|
|
|
|
|
public static boolean isCustomEntity(Entity entity) {
|
|
|
|
if (customEntitiesEnabled && CustomEntityConfig.getInstance().customEntityIds.contains(entity.getEntityId())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-15 19:44:39 +02:00
|
|
|
}
|