diff options
author | Wesley Wolfe <weswolf@aol.com> | 2013-01-09 04:45:01 -0600 |
---|---|---|
committer | Wesley Wolfe <weswolf@aol.com> | 2013-01-09 05:04:08 -0600 |
commit | dd7ba4a25834236910e7a17542a8a1116d5c8d0a (patch) | |
tree | eaa2f467ef77d55c19f11e203e135a3aee845556 /src/main/java | |
parent | 43865e8e67e2a36dce47e5da24222df861e04a5c (diff) | |
download | craftbukkit-dd7ba4a25834236910e7a17542a8a1116d5c8d0a.tar craftbukkit-dd7ba4a25834236910e7a17542a8a1116d5c8d0a.tar.gz craftbukkit-dd7ba4a25834236910e7a17542a8a1116d5c8d0a.tar.lz craftbukkit-dd7ba4a25834236910e7a17542a8a1116d5c8d0a.tar.xz craftbukkit-dd7ba4a25834236910e7a17542a8a1116d5c8d0a.zip |
Various ItemMeta fixes.
Fixes BUKKIT-3408, BUKKIT-3190, BUKKIT-3191, BUKKIT-3407
These changes relate mostly to semantical changes for serialization
contract, exception of changing the map scaling value from byte to boolean,
what it should have been in the first place. Appropriate unit tests were
added for CraftMapMeta, as they were missing.
Diffstat (limited to 'src/main/java')
6 files changed, 15 insertions, 13 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java index 476089a1..a2a91dec 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBook.java @@ -1,7 +1,6 @@ package org.bukkit.craftbukkit.inventory; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Map; @@ -74,7 +73,7 @@ class CraftMetaBook extends CraftMetaItem implements BookMeta { setTitle(SerializableMeta.getString(map, BOOK_TITLE.BUKKIT, true)); - Collection<?> pages = SerializableMeta.getObject(Collection.class, map, BOOK_PAGES.BUKKIT, true); + Iterable<?> pages = SerializableMeta.getObject(Iterable.class, map, BOOK_PAGES.BUKKIT, true); CraftMetaItem.safelyAdd(pages, this.pages, MAX_PAGE_LENGTH); } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCharge.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCharge.java index 84ce4bbd..40ac8adf 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCharge.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaCharge.java @@ -30,7 +30,7 @@ class CraftMetaCharge extends CraftMetaItem implements FireworkEffectMeta { CraftMetaCharge(Map<String, Object> map) { super(map); - effect = SerializableMeta.getObject(FireworkEffect.class, map, EXPLOSION.BUKKIT, true); + setEffect(SerializableMeta.getObject(FireworkEffect.class, map, EXPLOSION.BUKKIT, true)); } CraftMetaCharge(NBTTagCompound tag) { diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java index 0ac73e1e..5d955ef2 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaFirework.java @@ -172,7 +172,7 @@ class CraftMetaFirework extends CraftMetaItem implements FireworkMeta { Integer power = SerializableMeta.getObject(Integer.class, map, FLIGHT.BUKKIT, true); if (power != null) { - this.power = power; + setPower(power); } Iterable<?> effects = SerializableMeta.getObject(Iterable.class, map, EXPLOSIONS.BUKKIT, true); diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java index cc976ebf..ea6efcaa 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java @@ -271,14 +271,16 @@ class CraftMetaItem implements ItemMeta, Repairable { CraftMetaItem(Map<String, Object> map) { setDisplayName(SerializableMeta.getString(map, NAME.BUKKIT, true)); - if (map.containsKey(LORE.BUKKIT)) { - lore = (List<String>) map.get(LORE.BUKKIT); + Iterable<?> lore = SerializableMeta.getObject(Iterable.class, map, LORE.BUKKIT, true); + if (lore != null) { + safelyAdd(lore, this.lore = new ArrayList<String>(), Integer.MAX_VALUE); } enchantments = buildEnchantments(map, ENCHANTMENTS); - if (map.containsKey(REPAIR.BUKKIT)) { - repairCost = (Integer) map.get(REPAIR.BUKKIT); + Integer repairCost = SerializableMeta.getObject(Integer.class, map, REPAIR.BUKKIT, true); + if (repairCost != null) { + setRepairCost(repairCost); } } @@ -556,7 +558,7 @@ class CraftMetaItem implements ItemMeta, Repairable { return SerializableMeta.Deserializers.UNSPECIFIC; } - static void safelyAdd(Collection<?> addFrom, Collection<String> addTo, int maxItemLength) { + static void safelyAdd(Iterable<?> addFrom, Collection<String> addTo, int maxItemLength) { if (addFrom == null) { return; } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java index 0bd57c03..5bad0edf 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaMap.java @@ -42,8 +42,9 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta { CraftMetaMap(Map<String, Object> map) { super(map); - if (map.containsKey(MAP_SCALING.BUKKIT)) { - this.scaling = SerializableMeta.getBoolean(map, MAP_SCALING.BUKKIT) ? SCALING_TRUE : SCALING_FALSE; + Boolean scaling = SerializableMeta.getObject(Boolean.class, map, MAP_SCALING.BUKKIT, true); + if (scaling != null) { + setScaling(scaling); } } @@ -126,7 +127,7 @@ class CraftMetaMap extends CraftMetaItem implements MapMeta { super.serialize(builder); if (hasScaling()) { - builder.put(MAP_SCALING.BUKKIT, scaling); + builder.put(MAP_SCALING.BUKKIT, isScaling()); } return builder; diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaPotion.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaPotion.java index d8c507cb..3d565f64 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaPotion.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaPotion.java @@ -64,7 +64,7 @@ class CraftMetaPotion extends CraftMetaItem implements PotionMeta { CraftMetaPotion(Map<String, Object> map) { super(map); - List<?> rawEffectList = SerializableMeta.getObject(List.class, map, POTION_EFFECTS.BUKKIT, true); + Iterable<?> rawEffectList = SerializableMeta.getObject(Iterable.class, map, POTION_EFFECTS.BUKKIT, true); if (rawEffectList == null) { return; } |