2012-05-15 19:44:39 +02:00
|
|
|
package com.gmail.nossr50.util;
|
|
|
|
|
2012-05-17 06:24:33 +02:00
|
|
|
import org.bukkit.block.Block;
|
2012-05-15 19:44:39 +02:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2012-05-18 20:29:53 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2012-05-17 16:26:21 +02:00
|
|
|
import com.gmail.nossr50.config.mods.CustomArmorConfig;
|
2012-06-05 16:13:10 +02:00
|
|
|
import com.gmail.nossr50.config.mods.CustomBlocksConfig;
|
2012-05-17 16:26:21 +02:00
|
|
|
import com.gmail.nossr50.config.mods.CustomToolsConfig;
|
2012-05-17 06:24:33 +02:00
|
|
|
import com.gmail.nossr50.datatypes.mods.CustomBlock;
|
2012-05-15 22:12:59 +02:00
|
|
|
import com.gmail.nossr50.datatypes.mods.CustomItem;
|
2012-05-15 19:44:39 +02:00
|
|
|
import com.gmail.nossr50.datatypes.mods.CustomTool;
|
|
|
|
|
|
|
|
public 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();
|
2012-05-18 20:29:53 +02:00
|
|
|
|
2012-05-17 16:26:21 +02:00
|
|
|
private static CustomToolsConfig toolInstance = CustomToolsConfig.getInstance();
|
|
|
|
private static CustomArmorConfig armorInstance = CustomArmorConfig.getInstance();
|
2012-05-17 06:24:33 +02:00
|
|
|
private static CustomBlocksConfig blocksInstance = CustomBlocksConfig.getInstance();
|
2012-05-15 20:21:21 +02:00
|
|
|
|
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) {
|
2012-05-18 20:29:53 +02:00
|
|
|
return armorInstance.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) {
|
2012-05-18 20:29:53 +02:00
|
|
|
return toolInstance.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) {
|
|
|
|
if (!blocksInstance.customItems.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (CustomBlock b : blocksInstance.customBlocks) {
|
|
|
|
if ((b.getItemID() == block.getTypeId()) && (b.getDataValue() == block.getData())) {
|
|
|
|
return b;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2012-05-17 23:03:56 +02:00
|
|
|
|
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) {
|
|
|
|
if (customBlocksEnabled && blocksInstance.customMiningBlocks.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
if (blocksInstance.customLeaves.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
if (blocksInstance.customLogs.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
|
|
|
if (blocksInstance.customOres.contains(new ItemStack(block.getTypeId(), 1, (short) 0, block.getData()))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-05-18 20:29:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if an item is a custom tool.
|
|
|
|
*
|
|
|
|
* @param is Item to check
|
|
|
|
* @return true if the item is a custom tool, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isCustomTool(ItemStack item) {
|
|
|
|
if (customToolsEnabled && toolInstance.customTools.containsKey(item.getTypeId())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks to see if an item is custom armor.
|
|
|
|
*
|
|
|
|
* @param is Item to check
|
|
|
|
* @return true if the item is custom armor, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean isCustomArmor(ItemStack item) {
|
|
|
|
if (customArmorEnabled && armorInstance.customArmor.containsKey(item.getTypeId())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-05-15 19:44:39 +02:00
|
|
|
}
|