Java Code Examples for org.bukkit.enchantments.Enchantment#getMaxLevel()

The following examples show how to use org.bukkit.enchantments.Enchantment#getMaxLevel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MagicianTalisman.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
public MagicianTalisman(SlimefunItemStack item, ItemStack[] recipe) {
    super(item, recipe, false, false, "magician", 80);

    for (Enchantment enchantment : Enchantment.values()) {
        try {
            for (int i = 1; i <= enchantment.getMaxLevel(); i++) {
                enchantments.add(new TalismanEnchantment(enchantment, i));
            }
        }
        catch (Exception x) {
            Slimefun.getLogger().log(Level.SEVERE, x, () -> "The following Exception occurred while trying to register the following Enchantment: " + enchantment);
        }
    }

    if (!enchantments.isEmpty()) {
        addItemSetting(enchantments.toArray(new ItemSetting[0]));
    }
}
 
Example 2
Source File: ItemStack.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds the specified {@link Enchantment} to this item stack.
 * <p>
 * If this item stack already contained the given enchantment (at any
 * level), it will be replaced.
 *
 * @param ench  Enchantment to add
 * @param level Level of the enchantment
 * @throws IllegalArgumentException if enchantment null, or enchantment is
 *                                  not applicable
 */
@Utility
public void addEnchantment(Enchantment ench, int level) {
    Validate.notNull(ench, "Enchantment cannot be null");
    if ((level < ench.getStartLevel()) || (level > ench.getMaxLevel())) {
        throw new IllegalArgumentException("Enchantment level is either too low or too high (given " + level + ", bounds are " + ench.getStartLevel() + " to " + ench.getMaxLevel() + ")");
    } else if (!ench.canEnchantItem(this)) {
        throw new IllegalArgumentException("Specified enchantment cannot be applied to this itemstack");
    }

    addUnsafeEnchantment(ench, level);
}
 
Example 3
Source File: CraftMetaEnchantedBook.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public boolean addStoredEnchant(Enchantment ench, int level, boolean ignoreRestrictions) {
    if (enchantments == null) {
        enchantments = new HashMap<Enchantment, Integer>(4);
    }

    if (ignoreRestrictions || level >= ench.getStartLevel() && level <= ench.getMaxLevel()) {
        Integer old = enchantments.put(ench, level);
        return old == null || old != level;
    }
    return false;
}
 
Example 4
Source File: CraftMetaItem.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public boolean addEnchant(Enchantment ench, int level, boolean ignoreRestrictions) {
    Validate.notNull(ench, "Enchantment cannot be null");
    if (enchantments == null) {
        enchantments = new HashMap<Enchantment, Integer>(4);
    }

    if (ignoreRestrictions || level >= ench.getStartLevel() && level <= ench.getMaxLevel()) {
        Integer old = enchantments.put(ench, level);
        return old == null || old != level;
    }
    return false;
}
 
Example 5
Source File: ItemStackImpl.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
public void addEnchantment(Enchantment ench, int level) {
    Validate.notNull(ench, "Enchantment cannot be null");
    if (level >= ench.getStartLevel() && level <= ench.getMaxLevel()) {
        if (!ench.canEnchantItem(this)) {
            throw new IllegalArgumentException("Specified enchantment cannot be applied to this itemstack");
        } else {
            this.addUnsafeEnchantment(ench, level);
        }
    } else {
        throw new IllegalArgumentException("Enchantment level is either too low or too high (given " + level + ", bounds are " + ench.getStartLevel() + " to " + ench.getMaxLevel() + ")");
    }
}
 
Example 6
Source File: CraftMetaEnchantedBook.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public boolean addStoredEnchant(Enchantment ench, int level, boolean ignoreRestrictions) {
    if (enchantments == null) {
        enchantments = new HashMap<Enchantment, Integer>(4);
    }

    if (ignoreRestrictions || level >= ench.getStartLevel() && level <= ench.getMaxLevel()) {
        Integer old = enchantments.put(ench, level);
        return old == null || old != level;
    }
    return false;
}
 
Example 7
Source File: CraftMetaItem.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public boolean addEnchant(Enchantment ench, int level, boolean ignoreRestrictions) {
    if (enchantments == null) {
        enchantments = new HashMap<Enchantment, Integer>(4);
    }

    if (ignoreRestrictions || level >= ench.getStartLevel() && level <= ench.getMaxLevel()) {
        Integer old = enchantments.put(ench, level);
        return old == null || old != level;
    }
    return false;
}
 
Example 8
Source File: CraftMetaItem.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean addEnchant(Enchantment ench, int level, boolean ignoreRestrictions) {
	if (this.enchantments == null) {
		this.enchantments = new HashMap<Enchantment, Integer>(4);
	}
	if ((ignoreRestrictions) || ((level >= ench.getStartLevel()) && (level <= ench.getMaxLevel()))) {
		Integer old = (Integer) this.enchantments.put(ench, Integer.valueOf(level));
		return (old == null) || (old.intValue() != level);
	}
	return false;
}