use of org.bukkit.inventory.meta.ItemMeta in project MagicPlugin by elBukkit.
the class MagicController method getEntityName.
protected String getEntityName(Entity target, boolean display) {
if (target == null) {
return "Unknown";
}
if (target instanceof Player) {
return display ? ((Player) target).getDisplayName() : ((Player) target).getName();
}
if (isElemental(target)) {
return "Elemental";
}
if (display) {
if (target instanceof LivingEntity) {
LivingEntity li = (LivingEntity) target;
String customName = li.getCustomName();
if (customName != null && customName.length() > 0) {
return customName;
}
} else if (target instanceof Item) {
Item item = (Item) target;
ItemStack itemStack = item.getItemStack();
if (itemStack.hasItemMeta()) {
ItemMeta meta = itemStack.getItemMeta();
if (meta.hasDisplayName()) {
return meta.getDisplayName();
}
}
MaterialAndData material = new MaterialAndData(itemStack);
return material.getName();
}
}
return target.getType().name().toLowerCase().replace('_', ' ');
}
use of org.bukkit.inventory.meta.ItemMeta 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 org.bukkit.inventory.meta.ItemMeta in project MagicPlugin by elBukkit.
the class MagicController method getSkull.
@Override
@Nonnull
public ItemStack getSkull(Entity entity, String itemName) {
byte data = 3;
String ownerName = null;
switch(entity.getType()) {
case CREEPER:
data = 4;
break;
case ZOMBIE:
data = 2;
break;
case SKELETON:
Skeleton skeleton = (Skeleton) entity;
data = (byte) (skeleton.getSkeletonType() == Skeleton.SkeletonType.NORMAL ? 0 : 1);
break;
case PLAYER:
ownerName = entity.getName();
break;
default:
ownerName = getMobSkin(entity.getType());
}
ItemStack skull = new ItemStack(Material.SKULL_ITEM, 1, (short) 0, data);
ItemMeta meta = skull.getItemMeta();
if (itemName != null) {
meta.setDisplayName(itemName);
}
if (meta instanceof SkullMeta && ownerName != null) {
SkullMeta skullData = (SkullMeta) meta;
skullData.setOwner(ownerName);
}
skull.setItemMeta(meta);
return skull;
}
use of org.bukkit.inventory.meta.ItemMeta in project MagicPlugin by elBukkit.
the class MagicController method createGenericItem.
@Nullable
@Override
public ItemStack createGenericItem(String key) {
ConfigurationSection template = getWandTemplateConfiguration(key);
if (template == null || !template.contains("icon")) {
return null;
}
MaterialAndData icon = ConfigurationUtils.toMaterialAndData(template.getString("icon"));
ItemStack item = icon.getItemStack(1);
ItemMeta meta = item.getItemMeta();
if (template.contains("name")) {
meta.setDisplayName(template.getString("name"));
} else {
String name = messages.get("wands." + key + ".name");
if (name != null && !name.isEmpty()) {
meta.setDisplayName(name);
}
}
List<String> lore = new ArrayList<>();
if (template.contains("description")) {
lore.add(template.getString("description"));
} else {
String description = messages.get("wands." + key + ".description");
if (description != null && !description.isEmpty()) {
lore.add(description);
}
}
meta.setLore(lore);
item.setItemMeta(meta);
return item;
}
use of org.bukkit.inventory.meta.ItemMeta 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;
}
Aggregations