use of org.bukkit.inventory.meta.ItemMeta in project Bukkit by Bukkit.
the class ItemStack method deserialize.
/**
* Required method for configuration serialization
*
* @param args map to deserialize
* @return deserialized item stack
* @see ConfigurationSerializable
*/
public static ItemStack deserialize(Map<String, Object> args) {
Material type = Material.getMaterial((String) args.get("type"));
short damage = 0;
int amount = 1;
if (args.containsKey("damage")) {
damage = ((Number) args.get("damage")).shortValue();
}
if (args.containsKey("amount")) {
amount = (Integer) args.get("amount");
}
ItemStack result = new ItemStack(type, amount, damage);
if (args.containsKey("enchantments")) {
// Backward compatiblity, @deprecated
Object raw = args.get("enchantments");
if (raw instanceof Map) {
Map<?, ?> map = (Map<?, ?>) raw;
for (Map.Entry<?, ?> entry : map.entrySet()) {
Enchantment enchantment = Enchantment.getByName(entry.getKey().toString());
if ((enchantment != null) && (entry.getValue() instanceof Integer)) {
result.addUnsafeEnchantment(enchantment, (Integer) entry.getValue());
}
}
}
} else if (args.containsKey("meta")) {
// We cannot and will not have meta when enchantments (pre-ItemMeta) exist
Object raw = args.get("meta");
if (raw instanceof ItemMeta) {
result.setItemMeta((ItemMeta) raw);
}
}
return result;
}
use of org.bukkit.inventory.meta.ItemMeta in project Denizen-For-Bukkit by DenizenScript.
the class HeadCommand method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
Element skin = scriptEntry.getElement("skin");
dMaterial material = scriptEntry.getdObject("material");
// Report to dB
dB.report(scriptEntry, getName(), aH.debugObj("entities", entities.toString()) + (skin != null ? skin.debug() : "") + (material != null ? material.debug() : ""));
ItemStack item = null;
// Create head item with chosen skin, or item/skin
if (skin != null) {
item = new ItemStack(Material.SKULL_ITEM, 1, (byte) 3);
ItemMeta itemMeta = item.getItemMeta();
((SkullMeta) itemMeta).setOwner(skin.asString().replaceAll("[pP]@", ""));
item.setItemMeta(itemMeta);
} else if (material != null) {
item = new ItemStack(material.getMaterial());
}
for (dEntity entity : entities) {
if (entity.isCitizensNPC()) {
if (!entity.getDenizenNPC().getCitizen().hasTrait(Equipment.class)) {
entity.getDenizenNPC().getCitizen().addTrait(Equipment.class);
}
Equipment trait = entity.getDenizenNPC().getCitizen().getTrait(Equipment.class);
trait.set(1, item);
} else if (entity.isPlayer()) {
entity.getPlayer().getInventory().setHelmet(item);
} else {
if (entity.isLivingEntity() && entity.getLivingEntity().getEquipment() != null) {
entity.getLivingEntity().getEquipment().setHelmet(item);
} else {
dB.echoError(scriptEntry.getResidingQueue(), entity.identify() + " is not a living entity!");
}
}
}
}
use of org.bukkit.inventory.meta.ItemMeta in project Denizen-For-Bukkit by DenizenScript.
the class ItemFirework method adjust.
@Override
public void adjust(Mechanism mechanism) {
if (mechanism.matches("firework")) {
dList fireworks = mechanism.getValue().asType(dList.class);
ItemMeta meta = item.getItemStack().getItemMeta();
for (String effect : fireworks) {
String[] data = effect.split(",");
if (data.length == 9) {
FireworkEffect.Builder builder = FireworkEffect.builder();
builder.trail(new Element(data[0]).asBoolean());
builder.flicker(new Element(data[1]).asBoolean());
if (new Element(data[2]).matchesEnum(FireworkEffect.Type.values())) {
builder.with(FireworkEffect.Type.valueOf(data[2].toUpperCase()));
} else {
dB.echoError("Invalid firework type '" + data[2] + "'");
}
builder.withColor(Color.fromRGB(new Element(data[3]).asInt(), new Element(data[4]).asInt(), new Element(data[5]).asInt()));
builder.withFade(Color.fromRGB(new Element(data[6]).asInt(), new Element(data[7]).asInt(), new Element(data[8]).asInt()));
FireworkEffect built = builder.build();
if (meta instanceof FireworkMeta) {
((FireworkMeta) meta).addEffect(built);
} else {
((FireworkEffectMeta) meta).setEffect(built);
}
} else if (data.length == 1) {
if (meta instanceof FireworkMeta) {
((FireworkMeta) meta).setPower(new Element(data[0]).asInt());
} else {
dB.echoError("Cannot set the power of a firework effect!");
}
} else {
dB.echoError("Invalid firework data '" + effect + "'");
}
}
item.getItemStack().setItemMeta(meta);
}
}
use of org.bukkit.inventory.meta.ItemMeta in project Denizen-For-Bukkit by DenizenScript.
the class ItemFlags method adjust.
@Override
public void adjust(Mechanism mechanism) {
if (mechanism.matches("flags")) {
ItemMeta meta = item.getItemStack().getItemMeta();
meta.removeItemFlags(ItemFlag.values());
dList new_flags = mechanism.getValue().asType(dList.class);
for (String str : new_flags) {
meta.addItemFlags(ItemFlag.valueOf(str.toUpperCase()));
}
item.getItemStack().setItemMeta(meta);
}
}
use of org.bukkit.inventory.meta.ItemMeta in project Denizen-For-Bukkit by DenizenScript.
the class ItemUnbreakable method adjust.
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("unbreakable") && mechanism.requireBoolean()) {
ItemStack itemStack = item.getItemStack().clone();
ItemMeta meta = itemStack.getItemMeta();
meta.spigot().setUnbreakable(mechanism.getValue().asBoolean());
itemStack.setItemMeta(meta);
item.setItemStack(itemStack);
}
}
Aggregations