mirror of
https://github.com/PikaMug/Quests.git
synced 2024-11-29 14:16:09 +01:00
Add support for Enchanted Books, part 2 for #520. Bump version
This commit is contained in:
parent
65c0b58c49
commit
4cbeac1d10
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<groupId>me.blackvein.quests</groupId>
|
<groupId>me.blackvein.quests</groupId>
|
||||||
<artifactId>quests</artifactId>
|
<artifactId>quests</artifactId>
|
||||||
<version>3.4.2</version>
|
<version>3.4.3</version>
|
||||||
<name>quests</name>
|
<name>quests</name>
|
||||||
<url>https://github.com/FlyingPikachu/Quests/</url>
|
<url>https://github.com/FlyingPikachu/Quests/</url>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
@ -27,6 +27,7 @@ import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
|||||||
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
import org.bukkit.configuration.serialization.DelegateDeserialization;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
import me.blackvein.quests.Quester;
|
import me.blackvein.quests.Quester;
|
||||||
@ -82,9 +83,18 @@ public class ItemUtil {
|
|||||||
}
|
}
|
||||||
if (one.getEnchantments().equals(two.getEnchantments()) == false) {
|
if (one.getEnchantments().equals(two.getEnchantments()) == false) {
|
||||||
return -5;
|
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;
|
ItemStack stack = null;
|
||||||
String[] args = data.split(":");
|
String[] args = data.split(":");
|
||||||
ItemMeta meta = null;
|
ItemMeta meta = null;
|
||||||
|
EnchantmentStorageMeta esmeta = null;
|
||||||
Map<Enchantment, Integer> enchs = new HashMap<Enchantment, Integer>();
|
Map<Enchantment, Integer> enchs = new HashMap<Enchantment, Integer>();
|
||||||
String display = null;
|
String display = null;
|
||||||
LinkedList<String> lore = new LinkedList<String>();
|
LinkedList<String> lore = new LinkedList<String>();
|
||||||
|
LinkedHashMap<Enchantment, Integer> stored = new LinkedHashMap<Enchantment, Integer>();
|
||||||
LinkedHashMap<String, Object> extra = new LinkedHashMap<String, Object>();
|
LinkedHashMap<String, Object> extra = new LinkedHashMap<String, Object>();
|
||||||
for (String targ : args) {
|
for (String targ : args) {
|
||||||
String arg = targ.replace("minecraft|", "minecraft:");
|
String arg = targ.replace("minecraft|", "minecraft:");
|
||||||
@ -133,8 +145,17 @@ public class ItemUtil {
|
|||||||
display = ChatColor.translateAlternateColorCodes('&', arg.substring(12));
|
display = ChatColor.translateAlternateColorCodes('&', arg.substring(12));
|
||||||
} else if (arg.startsWith("lore-")) {
|
} else if (arg.startsWith("lore-")) {
|
||||||
lore.add(ChatColor.translateAlternateColorCodes('&', arg.substring(5)));
|
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("-")) {
|
} else if (arg.contains("-")) {
|
||||||
|
|
||||||
int dash = arg.lastIndexOf('-');
|
int dash = arg.lastIndexOf('-');
|
||||||
String key = arg.substring(0, dash);
|
String key = arg.substring(0, dash);
|
||||||
String value = arg.substring(dash + 1);
|
String value = arg.substring(dash + 1);
|
||||||
@ -154,20 +175,20 @@ public class ItemUtil {
|
|||||||
List<String> pages = Arrays.asList(value.split(", "));
|
List<String> pages = Arrays.asList(value.split(", "));
|
||||||
extra.put(key, pages);
|
extra.put(key, pages);
|
||||||
} else if (value.startsWith("{") && value.endsWith("}")) {
|
} else if (value.startsWith("{") && value.endsWith("}")) {
|
||||||
// Map such as stored enchants for enchanted books
|
// For nested mappings. Does NOT handle stored enchants, see earlier code
|
||||||
String[] enchants = value.replace("{", "").replace("}", "").split(", ");
|
String[] mapping = value.replace("{", "").replace("}", "").split(", ");
|
||||||
Map<String, String> stored = new HashMap<String, String>();
|
Map<String, String> nested = new HashMap<String, String>();
|
||||||
for (String s : enchants) {
|
for (String s : mapping) {
|
||||||
if (s.contains("=")) {
|
if (s.contains("=")) {
|
||||||
String[] keyval = s.split("=");
|
String[] keyval = s.split("=");
|
||||||
stored.put(keyval[0], keyval[1]);
|
nested.put(keyval[0], keyval[1]);
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getLogger().severe("Quests does not know how to handle "
|
Bukkit.getLogger().severe("Quests does not know how to handle "
|
||||||
+ value + " so please contact the developer on Github");
|
+ value + " so please contact the developer on Github");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
extra.put(key, stored);
|
extra.put(key, nested);
|
||||||
} else {
|
} else {
|
||||||
extra.put(key, value);
|
extra.put(key, value);
|
||||||
}
|
}
|
||||||
@ -175,6 +196,7 @@ public class ItemUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!extra.isEmpty()) {
|
if (!extra.isEmpty()) {
|
||||||
meta = ItemUtil.deserializeItemMeta(meta.getClass(), (Map<String, Object>) extra);
|
meta = ItemUtil.deserializeItemMeta(meta.getClass(), (Map<String, Object>) extra);
|
||||||
}
|
}
|
||||||
@ -189,7 +211,15 @@ public class ItemUtil {
|
|||||||
if (!lore.isEmpty()) {
|
if (!lore.isEmpty()) {
|
||||||
meta.setLore(lore);
|
meta.setLore(lore);
|
||||||
}
|
}
|
||||||
|
if (stack.getType().equals(Material.ENCHANTED_BOOK)) {
|
||||||
|
esmeta = (EnchantmentStorageMeta) meta;
|
||||||
|
for (Entry<Enchantment, Integer> e : stored.entrySet()) {
|
||||||
|
esmeta.addStoredEnchant(e.getKey(), e.getValue(), true);
|
||||||
|
}
|
||||||
|
stack.setItemMeta(esmeta);
|
||||||
|
} else {
|
||||||
stack.setItemMeta(meta);
|
stack.setItemMeta(meta);
|
||||||
|
}
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user