use of org.bukkit.inventory.meta.LeatherArmorMeta in project Denizen-For-Bukkit by DenizenScript.
the class LeatherColorer method colorArmor.
public static void colorArmor(dItem item, String colorArg) {
if (item == null) {
return;
}
if (dColor.matches(colorArg)) {
try {
LeatherArmorMeta meta = (LeatherArmorMeta) item.getItemStack().getItemMeta();
meta.setColor(dColor.valueOf(colorArg).getColor());
item.getItemStack().setItemMeta(meta);
} catch (Exception e) {
dB.echoError("Unable to color '" + item.identify() + "'.");
}
}
}
use of org.bukkit.inventory.meta.LeatherArmorMeta in project Prism-Bukkit by prism.
the class ItemStackAction method setItemStackFromNewDataFormat.
/**
*
*/
protected void setItemStackFromNewDataFormat() {
if (data == null || !data.startsWith("{"))
return;
actionData = gson.fromJson(data, ItemStackActionData.class);
item = new ItemStack(this.block_id, actionData.amt, (short) this.block_subid);
// Restore enchantment
if (actionData.enchs != null && actionData.enchs.length > 0) {
for (final String ench : actionData.enchs) {
final String[] enchArgs = ench.split(":");
final Enchantment enchantment = Enchantment.getById(Integer.parseInt(enchArgs[0]));
// Restore book enchantment
if (item.getType().equals(Material.ENCHANTED_BOOK)) {
final EnchantmentStorageMeta bookEnchantments = (EnchantmentStorageMeta) item.getItemMeta();
bookEnchantments.addStoredEnchant(enchantment, Integer.parseInt(enchArgs[1]), false);
item.setItemMeta(bookEnchantments);
} else // Restore item enchantment
{
item.addUnsafeEnchantment(enchantment, Integer.parseInt(enchArgs[1]));
}
}
}
// Leather color
if (item.getType().name().contains("LEATHER_") && actionData.color > 0) {
final LeatherArmorMeta lam = (LeatherArmorMeta) item.getItemMeta();
lam.setColor(Color.fromRGB(actionData.color));
item.setItemMeta(lam);
} else // Skulls
if (item.getType().equals(Material.SKULL_ITEM) && actionData.owner != null) {
final SkullMeta meta = (SkullMeta) item.getItemMeta();
meta.setOwner(actionData.owner);
item.setItemMeta(meta);
} else // Written books
if (item.getItemMeta() instanceof BookMeta) {
final BookMeta bookMeta = (BookMeta) item.getItemMeta();
bookMeta.setAuthor(actionData.by);
bookMeta.setTitle(actionData.title);
bookMeta.setPages(actionData.content);
item.setItemMeta(bookMeta);
}
// Fireworks
if (block_id == 402 && actionData.effectColors != null && actionData.effectColors.length > 0) {
final FireworkEffectMeta fireworkMeta = (FireworkEffectMeta) item.getItemMeta();
final Builder effect = FireworkEffect.builder();
if (actionData.effectColors != null) {
for (int i = 0; i < actionData.effectColors.length; i++) {
effect.withColor(Color.fromRGB(actionData.effectColors[i]));
}
fireworkMeta.setEffect(effect.build());
}
if (actionData.fadeColors != null) {
for (int i = 0; i < actionData.fadeColors.length; i++) {
effect.withFade(Color.fromRGB(actionData.fadeColors[i]));
}
fireworkMeta.setEffect(effect.build());
}
if (actionData.hasFlicker) {
effect.flicker(true);
}
if (actionData.hasTrail) {
effect.trail(true);
}
fireworkMeta.setEffect(effect.build());
item.setItemMeta(fireworkMeta);
}
// Item display names
final ItemMeta meta = item.getItemMeta();
if (actionData.name != null) {
meta.setDisplayName(actionData.name);
}
if (actionData.lore != null) {
meta.setLore(Arrays.asList(actionData.lore));
}
item.setItemMeta(meta);
}
use of org.bukkit.inventory.meta.LeatherArmorMeta in project Prism-Bukkit by prism.
the class ItemStackAction method setItem.
/**
*
* @param action_type
* @param block
* @param player
*/
public void setItem(ItemStack item, int quantity, int slot, Map<Enchantment, Integer> enchantments) {
actionData = new ItemStackActionData();
if (enchantments != null) {
this.enchantments = enchantments;
}
if (item == null || item.getAmount() <= 0) {
this.setCanceled(true);
return;
}
this.item = item;
if (enchantments == null) {
this.enchantments = item.getEnchantments();
}
// Set basics
this.block_id = item.getTypeId();
this.block_subid = item.getDurability();
actionData.amt = quantity;
if (slot >= 0) {
actionData.slot = slot;
}
// Set additional data all items may have
final ItemMeta meta = item.getItemMeta();
if (meta != null && meta.getDisplayName() != null) {
actionData.name = meta.getDisplayName();
}
// Leather Coloring
if (meta != null && item.getType().name().contains("LEATHER_")) {
final LeatherArmorMeta lam = (LeatherArmorMeta) meta;
if (lam.getColor() != null) {
actionData.color = lam.getColor().asRGB();
}
} else // Skull Owner
if (meta != null && item.getType().equals(Material.SKULL_ITEM)) {
final SkullMeta skull = (SkullMeta) meta;
if (skull.hasOwner()) {
actionData.owner = skull.getOwner();
}
}
// Written books
if (meta != null && meta instanceof BookMeta) {
final BookMeta bookMeta = (BookMeta) meta;
actionData.by = bookMeta.getAuthor();
actionData.title = bookMeta.getTitle();
actionData.content = bookMeta.getPages().toArray(new String[0]);
}
// Lore
if (meta != null && meta.getLore() != null) {
actionData.lore = meta.getLore().toArray(new String[0]);
}
// Enchantments
if (!this.enchantments.isEmpty()) {
final String[] enchs = new String[this.enchantments.size()];
int i = 0;
for (final Entry<Enchantment, Integer> ench : this.enchantments.entrySet()) {
enchs[i] = ench.getKey().getId() + ":" + ench.getValue();
i++;
}
actionData.enchs = enchs;
} else // Book enchantments
if (meta != null && item.getType().equals(Material.ENCHANTED_BOOK)) {
final EnchantmentStorageMeta bookEnchantments = (EnchantmentStorageMeta) meta;
if (bookEnchantments.hasStoredEnchants()) {
if (bookEnchantments.getStoredEnchants().size() > 0) {
final String[] enchs = new String[bookEnchantments.getStoredEnchants().size()];
int i = 0;
for (final Entry<Enchantment, Integer> ench : bookEnchantments.getStoredEnchants().entrySet()) {
enchs[i] = ench.getKey().getId() + ":" + ench.getValue();
i++;
}
actionData.enchs = enchs;
}
}
}
// Fireworks
if (meta != null && block_id == 402) {
final FireworkEffectMeta fireworkMeta = (FireworkEffectMeta) meta;
if (fireworkMeta.hasEffect()) {
final FireworkEffect effect = fireworkMeta.getEffect();
if (!effect.getColors().isEmpty()) {
final int[] effectColors = new int[effect.getColors().size()];
int i = 0;
for (final Color effectColor : effect.getColors()) {
effectColors[i] = effectColor.asRGB();
i++;
}
actionData.effectColors = effectColors;
}
if (!effect.getFadeColors().isEmpty()) {
final int[] fadeColors = new int[effect.getColors().size()];
final int i = 0;
for (final Color fadeColor : effect.getFadeColors()) {
fadeColors[i] = fadeColor.asRGB();
}
actionData.fadeColors = fadeColors;
}
if (effect.hasFlicker()) {
actionData.hasFlicker = true;
}
if (effect.hasTrail()) {
actionData.hasTrail = true;
}
}
}
}
use of org.bukkit.inventory.meta.LeatherArmorMeta in project Denizen-For-Bukkit by DenizenScript.
the class ItemDye method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if ((mechanism.matches("dye") || mechanism.matches("dye_color")) && mechanism.requireObject(dColor.class)) {
dColor color = mechanism.getValue().asType(dColor.class);
LeatherArmorMeta meta = ((LeatherArmorMeta) item.getItemStack().getItemMeta());
meta.setColor(color.getColor());
item.getItemStack().setItemMeta(meta);
}
}
use of org.bukkit.inventory.meta.LeatherArmorMeta in project EliteMobs by MagmaGuy.
the class ZombieTeamRocket method onHit.
@EventHandler
public void onHit(EntityDamageEvent event) {
if (event.getEntity().hasMetadata(powerMetadata) && event.getEntity() instanceof Zombie && !event.getEntity().hasMetadata(MetadataHandler.TEAM_ROCKET_ACTIVATED) && random.nextDouble() < 0.5) {
Entity entity = event.getEntity();
entity.setMetadata(MetadataHandler.TEAM_ROCKET_ACTIVATED, new FixedMetadataValue(plugin, true));
int assistMobLevel = (int) Math.floor(entity.getMetadata(MetadataHandler.ELITE_MOB_MD).get(0).asInt() / 4);
if (assistMobLevel < 1) {
assistMobLevel = 1;
}
LeatherArmorMeta teamRocketChestpieceMeta = (LeatherArmorMeta) TEAM_ROCKET_CHESTPIECE.getItemMeta();
teamRocketChestpieceMeta.setColor(Color.WHITE);
TEAM_ROCKET_CHESTPIECE.setItemMeta(teamRocketChestpieceMeta);
LeatherArmorMeta teamRocketLeggingsMeta = (LeatherArmorMeta) TEAM_ROCKET_CHESTPIECE.getItemMeta();
teamRocketLeggingsMeta.setColor(Color.WHITE);
TEAM_ROCKET_LEGGINGS.setItemMeta(teamRocketLeggingsMeta);
LeatherArmorMeta teamRocketBootsMeta = (LeatherArmorMeta) TEAM_ROCKET_BOOTS.getItemMeta();
teamRocketBootsMeta.setColor(Color.BLACK);
TEAM_ROCKET_BOOTS.setItemMeta(teamRocketBootsMeta);
ItemStack jesseHelmet = TEAM_ROCKET_HELMET.clone();
LeatherArmorMeta jesseHelmetMeta = (LeatherArmorMeta) jesseHelmet.getItemMeta();
jesseHelmetMeta.setColor(Color.PURPLE);
jesseHelmet.setItemMeta(jesseHelmetMeta);
ItemStack jamesHelmet = TEAM_ROCKET_HELMET.clone();
LeatherArmorMeta jamesHelmetMeta = (LeatherArmorMeta) jamesHelmet.getItemMeta();
jamesHelmetMeta.setColor(Color.BLUE);
jamesHelmet.setItemMeta(jamesHelmetMeta);
Zombie jesse = (Zombie) entity.getWorld().spawnEntity(entity.getLocation(), EntityType.ZOMBIE);
jesse.setMetadata(MetadataHandler.ELITE_MOB_MD, new FixedMetadataValue(plugin, assistMobLevel));
jesse.setMetadata(MetadataHandler.CUSTOM_NAME, new FixedMetadataValue(plugin, true));
jesse.setMetadata(MetadataHandler.CUSTOM_ARMOR, new FixedMetadataValue(plugin, true));
jesse.setMetadata(MetadataHandler.FORBIDDEN_MD, new FixedMetadataValue(plugin, true));
jesse.setMetadata(MetadataHandler.CUSTOM_POWERS_MD, new FixedMetadataValue(plugin, true));
jesse.setMetadata(MetadataHandler.TEAM_ROCKET_MEMBER, new FixedMetadataValue(plugin, true));
jesse.setCustomName("Jesse");
jesse.getEquipment().setHelmet(jesseHelmet);
jesse.getEquipment().setChestplate(TEAM_ROCKET_CHESTPIECE);
jesse.getEquipment().setLeggings(TEAM_ROCKET_LEGGINGS);
jesse.getEquipment().setBoots(TEAM_ROCKET_BOOTS);
Zombie james = (Zombie) entity.getWorld().spawnEntity(entity.getLocation(), EntityType.ZOMBIE);
james.setMetadata(MetadataHandler.ELITE_MOB_MD, new FixedMetadataValue(plugin, assistMobLevel));
james.setMetadata(MetadataHandler.CUSTOM_NAME, new FixedMetadataValue(plugin, true));
james.setMetadata(MetadataHandler.CUSTOM_ARMOR, new FixedMetadataValue(plugin, true));
james.setMetadata(MetadataHandler.FORBIDDEN_MD, new FixedMetadataValue(plugin, true));
james.setMetadata(MetadataHandler.CUSTOM_POWERS_MD, new FixedMetadataValue(plugin, true));
james.setMetadata(MetadataHandler.TEAM_ROCKET_MEMBER, new FixedMetadataValue(plugin, true));
james.setCustomName("James");
james.getEquipment().setHelmet(jamesHelmet);
james.getEquipment().setChestplate(TEAM_ROCKET_CHESTPIECE);
james.getEquipment().setLeggings(TEAM_ROCKET_LEGGINGS);
james.getEquipment().setBoots(TEAM_ROCKET_BOOTS);
Ocelot meowth = (Ocelot) entity.getWorld().spawnEntity(entity.getLocation(), EntityType.OCELOT);
meowth.setMetadata(MetadataHandler.TEAM_ROCKET_MEMBER, new FixedMetadataValue(plugin, true));
meowth.setCustomName("Meowth");
((Zombie) entity).getEquipment().setChestplate(TEAM_ROCKET_CHESTPIECE);
((Zombie) entity).getEquipment().setLeggings(TEAM_ROCKET_LEGGINGS);
((Zombie) entity).getEquipment().setBoots(TEAM_ROCKET_BOOTS);
entity.setMetadata(MetadataHandler.CUSTOM_ARMOR, new FixedMetadataValue(plugin, true));
Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
int counter = 1;
@Override
public void run() {
switch(counter) {
case 1:
jesse.setCustomNameVisible(true);
jesse.setCustomName(chatColorConverter(configuration.getStringList("ZombieTeamRocket.Intro").get(0)));
break;
case 2:
jesse.setCustomNameVisible(false);
james.setCustomName(chatColorConverter(configuration.getStringList("ZombieTeamRocket.Intro").get(1)));
james.setCustomNameVisible(true);
break;
case 3:
james.setCustomNameVisible(false);
jesse.setCustomName(chatColorConverter(configuration.getStringList("ZombieTeamRocket.Intro").get(2)));
jesse.setCustomNameVisible(true);
break;
case 4:
jesse.setCustomName(chatColorConverter(configuration.getStringList("ZombieTeamRocket.Intro").get(3)));
break;
case 5:
jesse.setCustomNameVisible(false);
james.setCustomName(chatColorConverter(configuration.getStringList("ZombieTeamRocket.Intro").get(4)));
james.setCustomNameVisible(true);
break;
case 6:
james.setCustomName(chatColorConverter(configuration.getStringList("ZombieTeamRocket.Intro").get(5)));
break;
case 7:
james.setCustomNameVisible(false);
jesse.setCustomName(chatColorConverter(configuration.getStringList("ZombieTeamRocket.Intro").get(6)));
jesse.setCustomNameVisible(true);
break;
case 8:
jesse.setCustomName(chatColorConverter(configuration.getStringList("ZombieTeamRocket.Intro").get(7)));
break;
case 9:
jesse.setCustomNameVisible(false);
james.setCustomName(chatColorConverter(configuration.getStringList("ZombieTeamRocket.Intro").get(8)));
james.setCustomNameVisible(true);
break;
case 10:
james.setCustomName(chatColorConverter(configuration.getStringList("ZombieTeamRocket.Intro").get(9)));
break;
case 11:
james.setCustomNameVisible(false);
jesse.setCustomName(chatColorConverter(configuration.getStringList("ZombieTeamRocket.Intro").get(10)));
jesse.setCustomNameVisible(true);
break;
case 12:
jesse.setCustomNameVisible(false);
james.setCustomName(chatColorConverter(configuration.getStringList("ZombieTeamRocket.Intro").get(11)));
james.setCustomNameVisible(true);
break;
case 13:
james.setCustomNameVisible(false);
jesse.setCustomName(chatColorConverter(configuration.getStringList("ZombieTeamRocket.Intro").get(12)));
jesse.setCustomNameVisible(true);
break;
case 14:
jesse.setCustomName(chatColorConverter(configuration.getStringList("ZombieTeamRocket.Intro").get(13)));
break;
case 15:
jesse.setCustomNameVisible(false);
james.setCustomName(chatColorConverter(configuration.getStringList("ZombieTeamRocket.Intro").get(14)));
james.setCustomNameVisible(true);
break;
case 16:
james.setCustomName(chatColorConverter(configuration.getStringList("ZombieTeamRocket.Intro").get(15)));
break;
case 17:
james.setCustomNameVisible(false);
meowth.setCustomName(chatColorConverter(configuration.getStringList("ZombieTeamRocket.Intro").get(16)));
meowth.setCustomNameVisible(true);
break;
default:
jesse.setCustomName(chatColorConverter(configuration.getString("ZombieTeamRocket.Jesse name")));
jesse.setCustomNameVisible(true);
james.setCustomName(chatColorConverter(configuration.getString("ZombieTeamRocket.James name")));
james.setCustomNameVisible(true);
meowth.setCustomName(chatColorConverter(configuration.getString("ZombieTeamRocket.Meowth name")));
Bukkit.getScheduler().cancelTask(processID);
break;
}
counter++;
}
}, 1, 15 * 2);
}
}
Aggregations