diff options
author | GJ <gjmcferrin@gmail.com> | 2013-03-20 01:35:22 -0400 |
---|---|---|
committer | GJ <gjmcferrin@gmail.com> | 2013-03-25 10:51:54 -0400 |
commit | 96ba65d506641ef37fbefc5f9a6c65a4ccec5d23 (patch) | |
tree | 02c5daf647182e1c0890e0c8270164facec22aac /src/main/java/org | |
parent | 5f089137ee63505b85ee7ddf0e75cb797c835d41 (diff) | |
download | craftbukkit-96ba65d506641ef37fbefc5f9a6c65a4ccec5d23.tar craftbukkit-96ba65d506641ef37fbefc5f9a6c65a4ccec5d23.tar.gz craftbukkit-96ba65d506641ef37fbefc5f9a6c65a4ccec5d23.tar.lz craftbukkit-96ba65d506641ef37fbefc5f9a6c65a4ccec5d23.tar.xz craftbukkit-96ba65d506641ef37fbefc5f9a6c65a4ccec5d23.zip |
Add methods to check conflicting enchantments. Adds BUKKIT-3830
Diffstat (limited to 'src/main/java/org')
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEnchantedBook.java | 4 | ||||
-rw-r--r-- | src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java | 18 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEnchantedBook.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEnchantedBook.java index 612a630d..f975e867 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEnchantedBook.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaEnchantedBook.java @@ -161,4 +161,8 @@ class CraftMetaEnchantedBook extends CraftMetaItem implements EnchantmentStorage public boolean hasStoredEnchants() { return !(enchantments == null || enchantments.isEmpty()); } + + public boolean hasConflictingStoredEnchant(Enchantment ench) { + return checkConflictingEnchants(enchantments, ench); + } } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java index 30916f99..90e7ffc3 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java @@ -405,6 +405,10 @@ class CraftMetaItem implements ItemMeta, Repairable { return !(enchantments == null || enchantments.isEmpty()); } + public boolean hasConflictingEnchant(Enchantment ench) { + return checkConflictingEnchants(enchantments, ench); + } + public List<String> getLore() { return this.lore == null ? null : new ArrayList<String>(this.lore); } @@ -555,6 +559,20 @@ class CraftMetaItem implements ItemMeta, Repairable { } } + static boolean checkConflictingEnchants(Map<Enchantment, Integer> enchantments, Enchantment ench) { + if (enchantments == null || enchantments.isEmpty()) { + return false; + } + + for (Enchantment enchant : enchantments.keySet()) { + if (enchant.conflictsWith(ench)) { + return true; + } + } + + return false; + } + @Override public final String toString() { return SerializableMeta.classMap.get(getClass()) + "_META:" + serialize(); // TODO: cry |