2011-05-15 19:33:03 +02:00
|
|
|
package com.Acrobot.ChestShop.Items;
|
2011-05-15 18:16:25 +02:00
|
|
|
|
2011-05-21 19:55:55 +02:00
|
|
|
import com.Acrobot.ChestShop.Utils.Numerical;
|
2011-05-15 18:16:25 +02:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Acrobot
|
2011-05-29 13:25:25 +02:00
|
|
|
* Manages ItemStack names and ID's
|
2011-05-15 18:16:25 +02:00
|
|
|
*/
|
2011-05-21 19:55:55 +02:00
|
|
|
public class Items {
|
2011-05-29 13:25:25 +02:00
|
|
|
|
|
|
|
public static String getItemName(ItemStack itemStack) {
|
2011-05-15 18:16:25 +02:00
|
|
|
return getItemName(itemStack.getType().name());
|
|
|
|
}
|
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
public static String getItemName(String itemName) {
|
|
|
|
return getMat(itemName).name();
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
public static Material getMat(String itemName) {
|
2011-05-15 18:16:25 +02:00
|
|
|
int length = 256;
|
|
|
|
Material finalMat = null;
|
2011-05-29 13:25:25 +02:00
|
|
|
itemName = itemName.toLowerCase().replace("_", "").replace(" ", "");
|
|
|
|
for (Material m : Material.values()) {
|
|
|
|
String matName = m.name().toLowerCase().replace("_", "").replace(" ", "");
|
|
|
|
if (matName.startsWith(itemName) && (matName.length() < length)) {
|
2011-05-15 18:16:25 +02:00
|
|
|
length = matName.length();
|
|
|
|
finalMat = m;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return finalMat;
|
|
|
|
}
|
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
public static int getItemID(String itemName) {
|
|
|
|
return getMat(itemName).getId();
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|
2011-05-21 19:55:55 +02:00
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
public static ItemStack getItemStack(String itemName) {
|
|
|
|
if (Odd.isInitialized()) {
|
2011-05-21 19:55:55 +02:00
|
|
|
ItemStack odd = Odd.returnItemStack(itemName.replace(":", ";"));
|
2011-05-29 13:25:25 +02:00
|
|
|
if (odd != null) {
|
2011-05-21 19:55:55 +02:00
|
|
|
return odd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String[] split = itemName.split(":");
|
|
|
|
itemName = split[0];
|
|
|
|
short dataValue = (short) (split.length > 1 && Numerical.isInteger(split[1]) ? Integer.parseInt(split[1]) : 0);
|
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
if (Numerical.isInteger(itemName)) {
|
|
|
|
Material mat = Material.getMaterial(Integer.parseInt(itemName));
|
|
|
|
return mat == null ? null : new ItemStack(mat, 1, dataValue);
|
2011-05-21 19:55:55 +02:00
|
|
|
}
|
|
|
|
|
2011-05-29 13:25:25 +02:00
|
|
|
Material mat = getMat(itemName);
|
2011-05-21 19:55:55 +02:00
|
|
|
|
|
|
|
return (mat != null ? new ItemStack(mat, 1, dataValue) : null);
|
|
|
|
}
|
2011-05-29 13:25:25 +02:00
|
|
|
|
|
|
|
public static Material getMaterial(String name) {
|
|
|
|
ItemStack is = getItemStack(name);
|
|
|
|
return is != null ? is.getType() : null;
|
|
|
|
}
|
2011-05-15 18:16:25 +02:00
|
|
|
}
|