diff --git a/pom.xml b/pom.xml
index 056225a24..9be80b8b6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
me.blackvein.quests
quests
- 3.4.2
+ 3.4.3
quests
https://github.com/FlyingPikachu/Quests/
jar
diff --git a/src/main/java/me/blackvein/quests/util/ItemUtil.java b/src/main/java/me/blackvein/quests/util/ItemUtil.java
index 2620009d8..a1a6dbe89 100644
--- a/src/main/java/me/blackvein/quests/util/ItemUtil.java
+++ b/src/main/java/me/blackvein/quests/util/ItemUtil.java
@@ -27,6 +27,7 @@ import org.bukkit.configuration.serialization.ConfigurationSerialization;
import org.bukkit.configuration.serialization.DelegateDeserialization;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
+import org.bukkit.inventory.meta.EnchantmentStorageMeta;
import org.bukkit.inventory.meta.ItemMeta;
import me.blackvein.quests.Quester;
@@ -82,9 +83,18 @@ public class ItemUtil {
}
if (one.getEnchantments().equals(two.getEnchantments()) == false) {
return -5;
- } else {
- return 0;
}
+ if (one.getType().equals(Material.ENCHANTED_BOOK)) {
+ EnchantmentStorageMeta esmeta1 = (EnchantmentStorageMeta) one.getItemMeta();
+ EnchantmentStorageMeta esmeta2 = (EnchantmentStorageMeta) two.getItemMeta();
+ if (esmeta1.hasStoredEnchants() && esmeta2.hasStoredEnchants() == false) {
+ return -6;
+ }
+ if (esmeta1.getStoredEnchants().equals(esmeta2.getStoredEnchants()) == false) {
+ return -6;
+ }
+ }
+ return 0;
}
/**
@@ -103,9 +113,11 @@ public class ItemUtil {
ItemStack stack = null;
String[] args = data.split(":");
ItemMeta meta = null;
+ EnchantmentStorageMeta esmeta = null;
Map enchs = new HashMap();
String display = null;
LinkedList lore = new LinkedList();
+ LinkedHashMap stored = new LinkedHashMap();
LinkedHashMap extra = new LinkedHashMap();
for (String targ : args) {
String arg = targ.replace("minecraft|", "minecraft:");
@@ -133,8 +145,17 @@ public class ItemUtil {
display = ChatColor.translateAlternateColorCodes('&', arg.substring(12));
} else if (arg.startsWith("lore-")) {
lore.add(ChatColor.translateAlternateColorCodes('&', arg.substring(5)));
+ } else if (arg.startsWith("stored-enchants")) {
+ int dash = arg.lastIndexOf('-');
+ String value = arg.substring(dash + 1);
+ String[] mapping = value.replace("{", "").replace("}", "").split(", ");
+ for (String s : mapping) {
+ if (s.contains("=")) {
+ String[] keyval = s.split("=");
+ stored.put(Enchantment.getByName(keyval[0]), Integer.valueOf(keyval[1]));
+ }
+ }
} else if (arg.contains("-")) {
-
int dash = arg.lastIndexOf('-');
String key = arg.substring(0, dash);
String value = arg.substring(dash + 1);
@@ -154,20 +175,20 @@ public class ItemUtil {
List pages = Arrays.asList(value.split(", "));
extra.put(key, pages);
} else if (value.startsWith("{") && value.endsWith("}")) {
- // Map such as stored enchants for enchanted books
- String[] enchants = value.replace("{", "").replace("}", "").split(", ");
- Map stored = new HashMap();
- for (String s : enchants) {
+ // For nested mappings. Does NOT handle stored enchants, see earlier code
+ String[] mapping = value.replace("{", "").replace("}", "").split(", ");
+ Map nested = new HashMap();
+ for (String s : mapping) {
if (s.contains("=")) {
String[] keyval = s.split("=");
- stored.put(keyval[0], keyval[1]);
+ nested.put(keyval[0], keyval[1]);
} else {
Bukkit.getLogger().severe("Quests does not know how to handle "
+ value + " so please contact the developer on Github");
return null;
}
}
- extra.put(key, stored);
+ extra.put(key, nested);
} else {
extra.put(key, value);
}
@@ -175,6 +196,7 @@ public class ItemUtil {
return null;
}
}
+
if (!extra.isEmpty()) {
meta = ItemUtil.deserializeItemMeta(meta.getClass(), (Map) extra);
}
@@ -189,7 +211,15 @@ public class ItemUtil {
if (!lore.isEmpty()) {
meta.setLore(lore);
}
- stack.setItemMeta(meta);
+ if (stack.getType().equals(Material.ENCHANTED_BOOK)) {
+ esmeta = (EnchantmentStorageMeta) meta;
+ for (Entry e : stored.entrySet()) {
+ esmeta.addStoredEnchant(e.getKey(), e.getValue(), true);
+ }
+ stack.setItemMeta(esmeta);
+ } else {
+ stack.setItemMeta(meta);
+ }
return stack;
}