Search in sources :

Example 1 with Fetchable

use of com.denizenscript.denizencore.objects.Fetchable in project Denizen-For-Bukkit by DenizenScript.

the class EnchantmentTag method valueOf.

@Fetchable("enchantment")
public static EnchantmentTag valueOf(String string, TagContext context) {
    if (string == null) {
        return null;
    }
    string = CoreUtilities.toLowerCase(string);
    if (string.startsWith("enchantment@")) {
        string = string.substring("enchantment@".length());
    }
    Enchantment ench;
    NamespacedKey key = Utilities.parseNamespacedKey(string);
    ench = Enchantment.getByKey(key);
    if (ench == null) {
        ench = Enchantment.getByName(string.toUpperCase());
    }
    if (ench == null) {
        ench = Enchantment.getByKey(new NamespacedKey("denizen", Utilities.cleanseNamespaceID(string)));
    }
    if (ench == null && ScriptRegistry.containsScript(string, EnchantmentScriptContainer.class)) {
        ench = ScriptRegistry.getScriptContainerAs(string, EnchantmentScriptContainer.class).enchantment;
    }
    if (ench == null) {
        if (context == null || context.debug) {
            Debug.echoError("Unknown enchantment '" + string + "'");
        }
        return null;
    }
    return new EnchantmentTag(ench);
}
Also used : NamespacedKey(org.bukkit.NamespacedKey) EnchantmentScriptContainer(com.denizenscript.denizen.scripts.containers.core.EnchantmentScriptContainer) Enchantment(org.bukkit.enchantments.Enchantment) Fetchable(com.denizenscript.denizencore.objects.Fetchable)

Aggregations

EnchantmentScriptContainer (com.denizenscript.denizen.scripts.containers.core.EnchantmentScriptContainer)1 Fetchable (com.denizenscript.denizencore.objects.Fetchable)1 NamespacedKey (org.bukkit.NamespacedKey)1 Enchantment (org.bukkit.enchantments.Enchantment)1