geforkt von Mirrors/Paper
Add methods to check conflicting enchantments. Adds BUKKIT-3830
Dieser Commit ist enthalten in:
Ursprung
5f089137ee
Commit
96ba65d506
@ -161,4 +161,8 @@ class CraftMetaEnchantedBook extends CraftMetaItem implements EnchantmentStorage
|
|||||||
public boolean hasStoredEnchants() {
|
public boolean hasStoredEnchants() {
|
||||||
return !(enchantments == null || enchantments.isEmpty());
|
return !(enchantments == null || enchantments.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasConflictingStoredEnchant(Enchantment ench) {
|
||||||
|
return checkConflictingEnchants(enchantments, ench);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -405,6 +405,10 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|||||||
return !(enchantments == null || enchantments.isEmpty());
|
return !(enchantments == null || enchantments.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasConflictingEnchant(Enchantment ench) {
|
||||||
|
return checkConflictingEnchants(enchantments, ench);
|
||||||
|
}
|
||||||
|
|
||||||
public List<String> getLore() {
|
public List<String> getLore() {
|
||||||
return this.lore == null ? null : new ArrayList<String>(this.lore);
|
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
|
@Override
|
||||||
public final String toString() {
|
public final String toString() {
|
||||||
return SerializableMeta.classMap.get(getClass()) + "_META:" + serialize(); // TODO: cry
|
return SerializableMeta.classMap.get(getClass()) + "_META:" + serialize(); // TODO: cry
|
||||||
|
@ -21,6 +21,7 @@ import org.bukkit.inventory.meta.BookMeta;
|
|||||||
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
import org.bukkit.inventory.meta.EnchantmentStorageMeta;
|
||||||
import org.bukkit.inventory.meta.FireworkEffectMeta;
|
import org.bukkit.inventory.meta.FireworkEffectMeta;
|
||||||
import org.bukkit.inventory.meta.FireworkMeta;
|
import org.bukkit.inventory.meta.FireworkMeta;
|
||||||
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||||
import org.bukkit.inventory.meta.MapMeta;
|
import org.bukkit.inventory.meta.MapMeta;
|
||||||
import org.bukkit.inventory.meta.PotionMeta;
|
import org.bukkit.inventory.meta.PotionMeta;
|
||||||
@ -62,6 +63,52 @@ public class ItemMetaTest extends AbstractTestingBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConflictingEnchantment() {
|
||||||
|
ItemMeta itemMeta = Bukkit.getItemFactory().getItemMeta(Material.DIAMOND_PICKAXE);
|
||||||
|
assertThat(itemMeta.hasConflictingEnchant(Enchantment.DURABILITY), is(false));
|
||||||
|
|
||||||
|
itemMeta.addEnchant(Enchantment.SILK_TOUCH, 1, false);
|
||||||
|
assertThat(itemMeta.hasConflictingEnchant(Enchantment.DURABILITY), is(false));
|
||||||
|
assertThat(itemMeta.hasConflictingEnchant(Enchantment.LOOT_BONUS_BLOCKS), is(true));
|
||||||
|
assertThat(itemMeta.hasConflictingEnchant(null), is(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConflictingStoredEnchantment() {
|
||||||
|
EnchantmentStorageMeta itemMeta = (EnchantmentStorageMeta) Bukkit.getItemFactory().getItemMeta(Material.ENCHANTED_BOOK);
|
||||||
|
assertThat(itemMeta.hasConflictingStoredEnchant(Enchantment.DURABILITY), is(false));
|
||||||
|
|
||||||
|
itemMeta.addStoredEnchant(Enchantment.SILK_TOUCH, 1, false);
|
||||||
|
assertThat(itemMeta.hasConflictingStoredEnchant(Enchantment.DURABILITY), is(false));
|
||||||
|
assertThat(itemMeta.hasConflictingStoredEnchant(Enchantment.LOOT_BONUS_BLOCKS), is(true));
|
||||||
|
assertThat(itemMeta.hasConflictingStoredEnchant(null), is(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConflictingEnchantments() {
|
||||||
|
ItemMeta itemMeta = Bukkit.getItemFactory().getItemMeta(Material.DIAMOND_PICKAXE);
|
||||||
|
itemMeta.addEnchant(Enchantment.DURABILITY, 6, true);
|
||||||
|
itemMeta.addEnchant(Enchantment.DIG_SPEED, 6, true);
|
||||||
|
assertThat(itemMeta.hasConflictingEnchant(Enchantment.LOOT_BONUS_BLOCKS), is(false));
|
||||||
|
|
||||||
|
itemMeta.addEnchant(Enchantment.SILK_TOUCH, 1, false);
|
||||||
|
assertThat(itemMeta.hasConflictingEnchant(Enchantment.LOOT_BONUS_BLOCKS), is(true));
|
||||||
|
assertThat(itemMeta.hasConflictingEnchant(null), is(false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testConflictingStoredEnchantments() {
|
||||||
|
EnchantmentStorageMeta itemMeta = (EnchantmentStorageMeta) Bukkit.getItemFactory().getItemMeta(Material.ENCHANTED_BOOK);
|
||||||
|
itemMeta.addStoredEnchant(Enchantment.DURABILITY, 6, true);
|
||||||
|
itemMeta.addStoredEnchant(Enchantment.DIG_SPEED, 6, true);
|
||||||
|
assertThat(itemMeta.hasConflictingStoredEnchant(Enchantment.LOOT_BONUS_BLOCKS), is(false));
|
||||||
|
|
||||||
|
itemMeta.addStoredEnchant(Enchantment.SILK_TOUCH, 1, false);
|
||||||
|
assertThat(itemMeta.hasConflictingStoredEnchant(Enchantment.LOOT_BONUS_BLOCKS), is(true));
|
||||||
|
assertThat(itemMeta.hasConflictingStoredEnchant(null), is(false));
|
||||||
|
}
|
||||||
|
|
||||||
private static FireworkMeta newFireworkMeta() {
|
private static FireworkMeta newFireworkMeta() {
|
||||||
return ((FireworkMeta) Bukkit.getItemFactory().getItemMeta(Material.FIREWORK));
|
return ((FireworkMeta) Bukkit.getItemFactory().getItemMeta(Material.FIREWORK));
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren