Add methods to check conflicting enchantments. Adds BUKKIT-3830

By: GJ <gjmcferrin@gmail.com>
This commit is contained in:
CraftBukkit/Spigot
2013-03-20 01:35:22 -04:00
parent 56947c94a9
commit afa8771324
3 changed files with 69 additions and 0 deletions

View File

@@ -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);
}
}

View File

@@ -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