Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Added method to check conflicting enchants on an item stack. #561

Closed
wants to merge 1 commit into from

3 participants

@gmcferrin

Addresses BUKKIT-1151

@jrtc27 jrtc27 commented on the diff
src/main/java/org/bukkit/enchantments/Enchantment.java
@@ -263,4 +263,22 @@ public static Enchantment getByName(String name) {
public static Enchantment[] values() {
return byId.values().toArray(new Enchantment[byId.size()]);
}
+
+ /**
+ * Checks if this Enchantment conflicts with any enchantments already applied to the given {@link ItemStack}.
@jrtc27
jrtc27 added a note

"the given" has two spaces in it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@CelticMinstrel

Uh, this shouldn't be static. It'll fail to compile because of that.

Whoops. I'll fix it.

@gmcferrin

Updated & resubmitted here: #565

@gmcferrin gmcferrin closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 0 deletions.
  1. +18 −0 src/main/java/org/bukkit/enchantments/Enchantment.java
View
18 src/main/java/org/bukkit/enchantments/Enchantment.java
@@ -263,4 +263,22 @@ public static Enchantment getByName(String name) {
public static Enchantment[] values() {
return byId.values().toArray(new Enchantment[byId.size()]);
}
+
+ /**
+ * Checks if this Enchantment conflicts with any enchantments already applied to the given {@link ItemStack}.
@jrtc27
jrtc27 added a note

"the given" has two spaces in it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ *
+ * @param item Item to test
+ * @return True if the enchantment conflicts, otherwise False
+ */
+ public static boolean conflictsWith(ItemStack item) {
+ Map<Enchantment, Integer> enchantments = item.getEnchantments();
+
+ for (Enchantment enchant : enchantments.keySet()) {
+ if (this.conflictsWith(enchant)) {
+ return true;
+ }
+ }
+
+ return false;
+ }
}
Something went wrong with that request. Please try again.