use of org.bukkit.inventory.meta.CrossbowMeta in project Denizen-For-Bukkit by DenizenScript.
the class ItemChargedProjectile method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("charged_projectiles")) {
CrossbowMeta meta = (CrossbowMeta) item.getItemMeta();
meta.setChargedProjectiles(null);
for (ItemTag projectile : mechanism.valueAsType(ListTag.class).filter(ItemTag.class, mechanism.context)) {
try {
meta.addChargedProjectile(projectile.getItemStack());
} catch (IllegalArgumentException e) {
mechanism.echoError("Charged crossbow projectiles may only be arrows or fireworks!");
}
}
item.setItemMeta(meta);
}
// -->
if (mechanism.matches("add_charged_projectile") && mechanism.requireObject(ItemTag.class)) {
CrossbowMeta meta = (CrossbowMeta) item.getItemMeta();
try {
meta.addChargedProjectile(mechanism.valueAsType(ItemTag.class).getItemStack());
} catch (IllegalArgumentException e) {
mechanism.echoError("Charged crossbow projectiles may only be arrows or fireworks!");
}
item.setItemMeta(meta);
}
// -->
if (mechanism.matches("remove_charged_projectiles")) {
CrossbowMeta meta = (CrossbowMeta) item.getItemMeta();
meta.setChargedProjectiles(null);
item.setItemMeta(meta);
}
}
use of org.bukkit.inventory.meta.CrossbowMeta in project Denizen-For-Bukkit by DenizenScript.
the class ItemChargedProjectile method getChargedProjectiles.
public ListTag getChargedProjectiles() {
CrossbowMeta meta = (CrossbowMeta) item.getItemMeta();
ListTag list = new ListTag();
if (!meta.hasChargedProjectiles()) {
return list;
}
for (ItemStack projectile : meta.getChargedProjectiles()) {
list.addObject(new ItemTag(projectile));
}
return list;
}
use of org.bukkit.inventory.meta.CrossbowMeta in project CitizensAPI by CitizensDev.
the class ItemStorage method deserialiseMeta.
private static void deserialiseMeta(DataKey root, ItemStack res) {
if (root.keyExists("encoded-meta")) {
byte[] raw = BaseEncoding.base64().decode(root.getString("encoded-meta"));
try {
BukkitObjectInputStream inp = new BukkitObjectInputStream(new ByteArrayInputStream(raw));
ItemMeta meta = (ItemMeta) inp.readObject();
res.setItemMeta(meta);
Bukkit.getPluginManager().callEvent(new CitizensDeserialiseMetaEvent(root, res));
return;
} catch (IOException e1) {
e1.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
if (SUPPORTS_CUSTOM_MODEL_DATA) {
try {
if (root.keyExists("custommodel")) {
ItemMeta meta = ensureMeta(res);
meta.setCustomModelData(root.getInt("custommodel"));
res.setItemMeta(meta);
}
} catch (Throwable t) {
SUPPORTS_CUSTOM_MODEL_DATA = false;
}
}
if (root.keyExists("flags")) {
ItemMeta meta = ensureMeta(res);
for (DataKey key : root.getRelative("flags").getIntegerSubKeys()) {
meta.addItemFlags(ItemFlag.valueOf(key.getString("")));
}
res.setItemMeta(meta);
}
if (root.keyExists("lore")) {
ItemMeta meta = ensureMeta(res);
List<String> lore = Lists.newArrayList();
for (DataKey key : root.getRelative("lore").getIntegerSubKeys()) lore.add(key.getString(""));
meta.setLore(lore);
res.setItemMeta(meta);
}
if (root.keyExists("displayname")) {
ItemMeta meta = ensureMeta(res);
meta.setDisplayName(root.getString("displayname"));
res.setItemMeta(meta);
}
if (root.keyExists("firework")) {
FireworkMeta meta = ensureMeta(res);
for (DataKey sub : root.getRelative("firework.effects").getIntegerSubKeys()) {
meta.addEffect(deserialiseFireworkEffect(sub));
}
meta.setPower(root.getInt("firework.power"));
res.setItemMeta(meta);
}
if (root.keyExists("book")) {
BookMeta meta = ensureMeta(res);
for (DataKey sub : root.getRelative("book.pages").getIntegerSubKeys()) {
meta.addPage(sub.getString(""));
}
meta.setTitle(root.getString("book.title"));
meta.setAuthor(root.getString("book.author"));
res.setItemMeta(meta);
}
if (root.keyExists("armor")) {
LeatherArmorMeta meta = ensureMeta(res);
meta.setColor(Color.fromRGB(root.getInt("armor.color")));
res.setItemMeta(meta);
}
if (root.keyExists("map")) {
MapMeta meta = ensureMeta(res);
meta.setScaling(root.getBoolean("map.scaling"));
res.setItemMeta(meta);
}
if (root.keyExists("blockstate")) {
BlockStateMeta meta = ensureMeta(res);
if (root.keyExists("blockstate.banner")) {
Banner banner = (Banner) meta.getBlockState();
deserialiseBanner(root.getRelative("blockstate"), banner);
banner.update(true);
meta.setBlockState(banner);
}
res.setItemMeta(meta);
}
if (root.keyExists("enchantmentstorage")) {
EnchantmentStorageMeta meta = ensureMeta(res);
for (DataKey key : root.getRelative("enchantmentstorage").getSubKeys()) {
meta.addStoredEnchant(deserialiseEnchantment(key.name()), key.getInt(""), true);
}
res.setItemMeta(meta);
}
if (root.keyExists("skull")) {
SkullMeta meta = ensureMeta(res);
if (root.keyExists("skull.owner") && !root.getString("skull.owner").isEmpty()) {
meta.setOwner(root.getString("skull.owner", ""));
}
if (root.keyExists("skull.texture") && !root.getString("skull.texture").isEmpty()) {
CitizensAPI.getSkullMetaProvider().setTexture(root.getString("skull.texture", ""), meta);
}
res.setItemMeta(meta);
}
if (root.keyExists("banner")) {
BannerMeta meta = ensureMeta(res);
if (root.keyExists("banner.basecolor")) {
meta.setBaseColor(DyeColor.valueOf(root.getString("banner.basecolor")));
}
if (root.keyExists("banner.patterns")) {
for (DataKey sub : root.getRelative("banner.patterns").getIntegerSubKeys()) {
Pattern pattern = new Pattern(DyeColor.valueOf(sub.getString("color")), PatternType.getByIdentifier(sub.getString("type")));
meta.addPattern(pattern);
}
}
res.setItemMeta(meta);
}
if (root.keyExists("potion")) {
PotionMeta meta = ensureMeta(res);
try {
PotionData data = new PotionData(PotionType.valueOf(root.getString("potion.data.type")), root.getBoolean("potion.data.extended"), root.getBoolean("potion.data.upgraded"));
meta.setBasePotionData(data);
} catch (Throwable t) {
}
for (DataKey sub : root.getRelative("potion.effects").getIntegerSubKeys()) {
int duration = sub.getInt("duration");
int amplifier = sub.getInt("amplifier");
PotionEffectType type = PotionEffectType.getByName(sub.getString("type"));
boolean ambient = sub.getBoolean("ambient");
meta.addCustomEffect(new PotionEffect(type, duration, amplifier, ambient), true);
}
res.setItemMeta(meta);
}
if (root.keyExists("crossbow") && SUPPORTS_1_14_API) {
CrossbowMeta meta = null;
try {
meta = ensureMeta(res);
} catch (Throwable t) {
SUPPORTS_1_14_API = false;
// old MC version
}
if (meta != null) {
for (DataKey key : root.getRelative("crossbow.projectiles").getSubKeys()) {
meta.addChargedProjectile(ItemStorage.loadItemStack(key));
}
res.setItemMeta(meta);
}
}
if (root.keyExists("repaircost") && res.getItemMeta() instanceof Repairable) {
ItemMeta meta = ensureMeta(res);
((Repairable) meta).setRepairCost(root.getInt("repaircost"));
res.setItemMeta(meta);
}
if (root.keyExists("attributes") && SUPPORTS_ATTRIBUTES) {
ItemMeta meta = ensureMeta(res);
try {
for (DataKey attr : root.getRelative("attributes").getSubKeys()) {
Attribute attribute = Attribute.valueOf(attr.name());
for (DataKey modifier : attr.getIntegerSubKeys()) {
UUID uuid = UUID.fromString(modifier.getString("uuid"));
String name = modifier.getString("name");
double amount = modifier.getDouble("amount");
Operation operation = Operation.valueOf(modifier.getString("operation"));
EquipmentSlot slot = modifier.keyExists("slot") ? EquipmentSlot.valueOf(modifier.getString("slot")) : null;
meta.addAttributeModifier(attribute, new AttributeModifier(uuid, name, amount, operation, slot));
}
}
} catch (Throwable e) {
SUPPORTS_ATTRIBUTES = false;
}
res.setItemMeta(meta);
}
ItemMeta meta = res.getItemMeta();
if (meta != null) {
try {
meta.setUnbreakable(root.getBoolean("unbreakable", false));
} catch (Throwable t) {
// probably backwards-compat issue, don't log
}
res.setItemMeta(meta);
}
Bukkit.getPluginManager().callEvent(new CitizensDeserialiseMetaEvent(root, res));
}
Aggregations