Search in sources :

Example 1 with BookScriptContainer

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

the class ScribeCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Retrieve objects from ScriptEntry
    BookAction action = (BookAction) scriptEntry.getObject("action");
    dItem book = (dItem) scriptEntry.getObject("item");
    dScript script = (dScript) scriptEntry.getObject("script");
    dLocation location = (dLocation) scriptEntry.getObject("location");
    BookScriptContainer bookScript = (BookScriptContainer) script.getContainer();
    book = bookScript.writeBookTo(book, ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer(), ((BukkitScriptEntryData) scriptEntry.entryData).getNPC());
    // Post-write action? Can be NONE.
    switch(action) {
        case DROP:
            dropBook(location, book.getItemStack());
            break;
        case GIVE:
            giveBook(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity(), book.getItemStack());
            // Update player's inventory
            ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().updateInventory();
            break;
        case EQUIP:
            equipBook(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity(), book.getItemStack());
            // Update player's inventory
            ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().updateInventory();
            break;
        case NONE:
            break;
    }
}
Also used : net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizencore.objects.dScript(net.aufdemrand.denizencore.objects.dScript) BookScriptContainer(net.aufdemrand.denizen.scripts.containers.core.BookScriptContainer) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Aggregations

BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)1 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)1 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)1 BookScriptContainer (net.aufdemrand.denizen.scripts.containers.core.BookScriptContainer)1 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)1