Search in sources :

Example 1 with BookScriptContainer

use of com.denizenscript.denizen.scripts.containers.core.BookScriptContainer in project Denizen-For-Bukkit by DenizenScript.

the class ItemTag method valueOf.

@Fetchable("i")
public static ItemTag valueOf(String string, TagContext context) {
    if (string == null || string.equals("")) {
        return null;
    }
    ItemTag stack = null;
    if (ObjectFetcher.isObjectWithProperties(string)) {
        return ObjectFetcher.getObjectFromWithProperties(ItemTag.class, string, context);
    }
    if (string.startsWith("i@")) {
        string = string.substring("i@".length());
    }
    string = CoreUtilities.toLowerCase(string);
    try {
        if (ScriptRegistry.containsScript(string, ItemScriptContainer.class)) {
            ItemScriptContainer isc = ScriptRegistry.getScriptContainerAs(string, ItemScriptContainer.class);
            // TODO: If a script does not contain tags, get the clean reference here.
            stack = isc.getItemFrom(context);
            if (stack == null && (context == null || context.showErrors())) {
                Debug.echoError("Item script '" + isc.getName() + "' returned a null item.");
            }
        } else if (ScriptRegistry.containsScript(string, BookScriptContainer.class)) {
            BookScriptContainer book = ScriptRegistry.getScriptContainerAs(string, BookScriptContainer.class);
            stack = book.getBookFrom(context);
            if (stack == null && (context == null || context.showErrors())) {
                Debug.echoError("Book script '" + book.getName() + "' returned a null item.");
            }
        }
        if (stack != null) {
            return stack;
        }
    } catch (Exception ex) {
        if (Debug.verbose) {
            Debug.echoError(ex);
        }
    }
    try {
        MaterialTag mat = MaterialTag.valueOf(string.toUpperCase(), context);
        if (mat != null) {
            stack = new ItemTag(mat.getMaterial());
        }
        if (stack != null) {
            return stack;
        }
    } catch (Exception ex) {
        if (!string.equalsIgnoreCase("none") && (context == null || context.showErrors())) {
            Debug.log("Does not match a valid item ID or material: " + string);
        }
        if (Debug.verbose) {
            Debug.echoError(ex);
        }
    }
    if (context == null || context.showErrors()) {
        Debug.log("valueOf ItemTag returning null: " + string);
    }
    return null;
}
Also used : ItemScriptContainer(com.denizenscript.denizen.scripts.containers.core.ItemScriptContainer) BookScriptContainer(com.denizenscript.denizen.scripts.containers.core.BookScriptContainer)

Example 2 with BookScriptContainer

use of com.denizenscript.denizen.scripts.containers.core.BookScriptContainer in project Denizen-For-Bukkit by DenizenScript.

the class ScribeCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    Deprecations.scribeCommand.warn(scriptEntry);
    // Retrieve objects from ScriptEntry
    BookAction action = (BookAction) scriptEntry.getObject("action");
    ItemTag book = scriptEntry.getObjectTag("item");
    ScriptTag script = scriptEntry.getObjectTag("script");
    LocationTag location = scriptEntry.getObjectTag("location");
    BookScriptContainer bookScript = (BookScriptContainer) script.getContainer();
    book = bookScript.writeBookTo(book, scriptEntry.getContext());
    // Post-write action? Can be NONE.
    switch(action) {
        case DROP:
            dropBook(location, book.getItemStack());
            break;
        case GIVE:
            giveBook(Utilities.getEntryPlayer(scriptEntry).getPlayerEntity(), book.getItemStack());
            // Update player's inventory
            Utilities.getEntryPlayer(scriptEntry).getPlayerEntity().updateInventory();
            break;
        case EQUIP:
            equipBook(Utilities.getEntryPlayer(scriptEntry).getPlayerEntity(), book.getItemStack());
            // Update player's inventory
            Utilities.getEntryPlayer(scriptEntry).getPlayerEntity().updateInventory();
            break;
        case NONE:
            break;
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) BookScriptContainer(com.denizenscript.denizen.scripts.containers.core.BookScriptContainer) ItemTag(com.denizenscript.denizen.objects.ItemTag)

Aggregations

BookScriptContainer (com.denizenscript.denizen.scripts.containers.core.BookScriptContainer)2 ItemTag (com.denizenscript.denizen.objects.ItemTag)1 LocationTag (com.denizenscript.denizen.objects.LocationTag)1 ItemScriptContainer (com.denizenscript.denizen.scripts.containers.core.ItemScriptContainer)1 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)1