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-17 06:24:33 +02:00
|
|
|
import com.gmail.nossr50.config.mods.CustomBlocksConfig;
|
2012-05-15 22:12:59 +02:00
|
|
|
import com.gmail.nossr50.config.mods.LoadCustomArmor;
|
2012-05-15 19:44:39 +02:00
|
|
|
import com.gmail.nossr50.config.mods.LoadCustomTools;
|
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-15 22:12:59 +02:00
|
|
|
private static LoadCustomTools toolInstance = LoadCustomTools.getInstance();
|
|
|
|
private static LoadCustomArmor armorInstance = LoadCustomArmor.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
|
|
|
|
* @return the ay if it exists, null otherwise
|
|
|
|
*/
|
|
|
|
public static CustomItem getArmorFromItemStack(ItemStack item) {
|
|
|
|
int id = item.getTypeId();
|
|
|
|
|
|
|
|
if (!armorInstance.customIDs.contains(id)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (CustomItem armor : armorInstance.customItems) {
|
|
|
|
if (armor.getItemID() == id) {
|
|
|
|
return armor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2012-05-15 20:21:21 +02:00
|
|
|
/**
|
|
|
|
* Get the custom tool associated with an item.
|
|
|
|
*
|
|
|
|
* @param item The item to check
|
2012-05-15 22:12:59 +02:00
|
|
|
* @return the armor if it exists, null otherwise
|
2012-05-15 20:21:21 +02:00
|
|
|
*/
|
|
|
|
public static CustomTool getToolFromItemStack(ItemStack item) {
|
2012-05-15 22:12:59 +02:00
|
|
|
int id = item.getTypeId();
|
|
|
|
|
|
|
|
if (!toolInstance.customIDs.contains(id)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (CustomItem tool : toolInstance.customItems) {
|
|
|
|
if (tool.getItemID() == id) {
|
|
|
|
return (CustomTool) tool;
|
2012-05-15 20:21:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
2012-05-17 06:24:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the custom block associated with an block.
|
|
|
|
*
|
|
|
|
* @param block The block to check
|
|
|
|
* @return the armor if it exists, null otherwise
|
|
|
|
*/
|
|
|
|
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-15 19:44:39 +02:00
|
|
|
}
|