use of com.elmakers.mine.bukkit.api.item.ItemData in project MagicPlugin by elBukkit.
the class MagicController method getItemKey.
@Override
public String getItemKey(ItemStack item) {
if (item == null) {
return "";
}
if (Wand.isUpgrade(item)) {
return "upgrade:" + Wand.getWandTemplate(item);
}
if (Wand.isWand(item)) {
return "wand:" + Wand.getWandTemplate(item);
}
if (Wand.isSpell(item)) {
return "spell:" + Wand.getSpell(item);
}
if (Wand.isBrush(item)) {
return "brush:" + Wand.getBrush(item);
}
ItemData mappedItem = getItem(item);
if (mappedItem != null) {
return mappedItem.getKey();
}
if (item.getType() == Material.SKULL_ITEM) {
String url = InventoryUtils.getSkullURL(item);
if (url != null && url.length() > 0) {
return "skull_item:" + url;
}
}
MaterialAndData material = new MaterialAndData(item);
return material.getKey();
}
use of com.elmakers.mine.bukkit.api.item.ItemData in project MagicPlugin by elBukkit.
the class MagicController method createItem.
@Nullable
@Override
public ItemStack createItem(String magicItemKey, boolean brief) {
ItemStack itemStack = null;
if (magicItemKey == null) {
return null;
}
// Check for amounts
int amount = 1;
if (magicItemKey.contains("@")) {
String[] pieces = StringUtils.split(magicItemKey, '@');
magicItemKey = pieces[0];
try {
amount = Integer.parseInt(pieces[1]);
} catch (Exception ignored) {
}
}
// Handle : or | as delimiter
magicItemKey = magicItemKey.replace("|", ":");
try {
if (magicItemKey.contains("skull:") || magicItemKey.contains("skull_item:")) {
magicItemKey = magicItemKey.replace("skull:", "skull_item:");
MaterialAndData skullData = new MaterialAndData(magicItemKey);
itemStack = skullData.getItemStack(amount);
} else if (magicItemKey.contains("book:")) {
String bookCategory = magicItemKey.substring(5);
com.elmakers.mine.bukkit.api.spell.SpellCategory category = null;
if (!bookCategory.isEmpty() && !bookCategory.equalsIgnoreCase("all")) {
category = getCategory(bookCategory);
if (category == null) {
return null;
}
}
itemStack = getSpellBook(category, amount);
} else if (skillPointItemsEnabled && magicItemKey.contains("sp:")) {
String spAmount = magicItemKey.substring(3);
itemStack = InventoryUtils.getURLSkull(skillPointIcon);
ItemMeta meta = itemStack.getItemMeta();
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', messages.get("sp.name")).replace("$amount", spAmount));
String spDescription = messages.get("sp.description");
if (spDescription.length() > 0) {
List<String> lore = new ArrayList<>();
lore.add(ChatColor.translateAlternateColorCodes('&', spDescription));
meta.setLore(lore);
}
itemStack.setItemMeta(meta);
InventoryUtils.setMeta(itemStack, "sp", spAmount);
} else if (magicItemKey.contains("spell:")) {
String spellKey = magicItemKey.substring(6);
itemStack = createSpellItem(spellKey, brief);
} else if (magicItemKey.contains("wand:")) {
String wandKey = magicItemKey.substring(5);
com.elmakers.mine.bukkit.api.wand.Wand wand = createWand(wandKey);
if (wand != null) {
itemStack = wand.getItem();
}
} else if (magicItemKey.contains("upgrade:")) {
String wandKey = magicItemKey.substring(8);
com.elmakers.mine.bukkit.api.wand.Wand wand = createWand(wandKey);
if (wand != null) {
wand.makeUpgrade();
itemStack = wand.getItem();
}
} else if (magicItemKey.contains("brush:")) {
String brushKey = magicItemKey.substring(6);
itemStack = createBrushItem(brushKey);
} else if (magicItemKey.contains("item:")) {
String itemKey = magicItemKey.substring(5);
itemStack = createGenericItem(itemKey);
} else if (items != null) {
ItemData itemData = items.get(magicItemKey);
if (itemData != null) {
return itemData.getItemStack(amount);
}
MaterialAndData item = new MaterialAndData(magicItemKey);
if (item.isValid()) {
return item.getItemStack(amount);
}
com.elmakers.mine.bukkit.api.wand.Wand wand = createWand(magicItemKey);
if (wand != null) {
ItemStack wandItem = wand.getItem();
if (wandItem != null) {
wandItem.setAmount(amount);
}
return wandItem;
}
// Spells may be using the | delimiter for levels
// I am regretting overloading this delimiter!
String spellKey = magicItemKey.replace(":", "|");
itemStack = createSpellItem(spellKey, brief);
if (itemStack != null) {
itemStack.setAmount(amount);
return itemStack;
}
itemStack = createBrushItem(magicItemKey);
if (itemStack != null) {
itemStack.setAmount(amount);
}
}
} catch (Exception ex) {
getLogger().log(Level.WARNING, "Error creating item: " + magicItemKey, ex);
}
return itemStack;
}
use of com.elmakers.mine.bukkit.api.item.ItemData in project MagicPlugin by elBukkit.
the class MagicRecipe method getMatchType.
@SuppressWarnings("deprecation")
public MatchType getMatchType(ItemStack[] matrix) {
if (recipe == null || matrix.length < 9)
return MatchType.NONE;
boolean[] rows = new boolean[3];
boolean[] columns = new boolean[3];
for (int matrixRow = 0; matrixRow < 3; matrixRow++) {
for (int matrixColumn = 0; matrixColumn < 3; matrixColumn++) {
int i = matrixRow * 3 + matrixColumn;
ItemStack ingredient = matrix[i];
if (ingredient != null && ingredient.getType() != Material.AIR) {
rows[matrixRow] = true;
break;
}
}
}
for (int matrixColumn = 0; matrixColumn < 3; matrixColumn++) {
for (int matrixRow = 0; matrixRow < 3; matrixRow++) {
int i = matrixRow * 3 + matrixColumn;
ItemStack ingredient = matrix[i];
if (ingredient != null && ingredient.getType() != Material.AIR) {
columns[matrixColumn] = true;
break;
}
}
}
String[] shape = recipe.getShape();
if (shape == null || shape.length < 1)
return MatchType.NONE;
int shapeRow = 0;
for (int matrixRow = 0; matrixRow < 3; matrixRow++) {
if (!rows[matrixRow])
continue;
int shapeColumn = 0;
for (int matrixColumn = 0; matrixColumn < 3; matrixColumn++) {
if (!columns[matrixColumn])
continue;
if (shapeRow >= shape.length)
return MatchType.NONE;
String row = shape[shapeRow];
char charAt = ' ';
if (shapeColumn >= row.length()) {
return MatchType.NONE;
}
charAt = row.charAt(shapeColumn);
ItemData item = ingredients.get(charAt);
int i = matrixRow * 3 + matrixColumn;
ItemStack ingredient = matrix[i];
if (ingredient != null && ingredient.getType() == Material.AIR) {
ingredient = null;
}
if (item == null && ingredient == null) {
shapeColumn++;
continue;
}
if (item == null && ingredient != null)
return MatchType.NONE;
if (ingredient == null && item != null)
return MatchType.NONE;
if (ingredient.getType() != item.getType()) {
return MatchType.NONE;
}
if (ingredient.getDurability() != item.getMaterialData().getData()) {
return MatchType.NONE;
}
ItemMeta meta = item.getItemMeta();
if (meta != null) {
ItemMeta ingredientMeta = ingredient.getItemMeta();
if (ingredientMeta == null) {
return MatchType.PARTIAL;
}
if (meta.hasDisplayName() && (!ingredientMeta.hasDisplayName() || !meta.getDisplayName().equals(ingredientMeta.getDisplayName()))) {
return MatchType.PARTIAL;
}
if (meta.hasLore() && (!ingredientMeta.hasLore() || !meta.getLore().equals(ingredientMeta.getLore()))) {
return MatchType.PARTIAL;
}
}
shapeColumn++;
}
shapeRow++;
}
return MatchType.MATCH;
}
use of com.elmakers.mine.bukkit.api.item.ItemData in project MagicPlugin by elBukkit.
the class MagicController method getWorth.
@Nullable
@Override
public Double getWorth(ItemStack item) {
String spellKey = Wand.getSpell(item);
if (spellKey != null) {
SpellTemplate spell = getSpellTemplate(spellKey);
if (spell != null) {
return spell.getWorth();
}
}
int amount = item.getAmount();
item.setAmount(1);
ItemData configuredItem = items.get(item);
item.setAmount(amount);
if (configuredItem == null) {
return null;
}
return configuredItem.getWorth() * amount;
}
use of com.elmakers.mine.bukkit.api.item.ItemData in project MagicPlugin by elBukkit.
the class ArmorStandProjectileAction method prepare.
@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
super.prepare(context, parameters);
armorStandMarker = parameters.getBoolean("armor_stand_marker", true);
armorStandInvisible = parameters.getBoolean("armor_stand_invisible", true);
armorStandGravity = parameters.getBoolean("armor_stand_gravity", false);
showArmorStandArms = parameters.getBoolean("armor_stand_arms", true);
showArmorStandBaseplate = parameters.getBoolean("armor_stand_baseplate", false);
smallArmorStand = parameters.getBoolean("armor_stand_small", false);
adjustHeadPitch = parameters.getBoolean("orient_head", false);
adjustArmPitch = parameters.getBoolean("orient_right_arm", false);
unbreakableItems = parameters.getBoolean("unbreakable_items", false);
visibleDelayTicks = parameters.getInt("visible_delay_ticks", 1);
MageController controller = context.getController();
ItemData itemType = controller.getOrCreateItem(parameters.getString("right_arm_item"));
if (itemType != null) {
rightArmItem = itemType.getItemStack(1);
if (rightArmItem != null && unbreakableItems) {
InventoryUtils.makeUnbreakable(rightArmItem);
}
}
itemType = controller.getOrCreateItem(parameters.getString("helmet_item"));
if (itemType != null) {
helmetItem = itemType.getItemStack(1);
if (helmetItem != null && unbreakableItems) {
InventoryUtils.makeUnbreakable(InventoryUtils.makeReal(helmetItem));
}
}
itemType = controller.getOrCreateItem(parameters.getString("chestplate_item"));
if (itemType != null) {
chestplateItem = itemType.getItemStack(1);
if (chestplateItem != null && unbreakableItems) {
InventoryUtils.makeUnbreakable(InventoryUtils.makeReal(chestplateItem));
}
}
itemType = controller.getOrCreateItem(parameters.getString("leggings_item"));
if (itemType != null) {
leggingsItem = itemType.getItemStack(1);
if (leggingsItem != null && unbreakableItems) {
InventoryUtils.makeUnbreakable(InventoryUtils.makeReal(leggingsItem));
}
}
itemType = controller.getOrCreateItem(parameters.getString("boots_item"));
if (itemType != null) {
bootsItem = itemType.getItemStack(1);
if (bootsItem != null && unbreakableItems) {
InventoryUtils.makeUnbreakable(InventoryUtils.makeReal(bootsItem));
}
}
}
Aggregations