Search in sources :

Example 36 with ScriptTag

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

the class AssignmentCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    ScriptTag script = scriptEntry.getObjectTag("script");
    Action action = (Action) scriptEntry.getObject("action");
    List<NPCTag> npcs = (List<NPCTag>) scriptEntry.getObject("npcs");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), db("action", action), script, db("npc", npcs));
    }
    PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
    for (NPCTag npc : npcs) {
        switch(action) {
            case SET:
                {
                    if (script == null) {
                        throw new InvalidArgumentsRuntimeException("Missing script!");
                    }
                    AssignmentTrait assignment = npc.getCitizen().getOrAddTrait(AssignmentTrait.class);
                    assignment.clearAssignments(player);
                    assignment.addAssignmentScript((AssignmentScriptContainer) script.getContainer(), player);
                    break;
                }
            case ADD:
                if (script == null) {
                    throw new InvalidArgumentsRuntimeException("Missing script!");
                }
                npc.getCitizen().getOrAddTrait(AssignmentTrait.class).addAssignmentScript((AssignmentScriptContainer) script.getContainer(), player);
                break;
            case REMOVE:
                if (script == null) {
                    Deprecations.assignmentRemove.warn(scriptEntry);
                    if (npc.getCitizen().hasTrait(AssignmentTrait.class)) {
                        npc.getCitizen().getOrAddTrait(AssignmentTrait.class).clearAssignments(player);
                        npc.getCitizen().removeTrait(AssignmentTrait.class);
                    }
                } else {
                    if (npc.getCitizen().hasTrait(AssignmentTrait.class)) {
                        AssignmentTrait trait = npc.getCitizen().getOrAddTrait(AssignmentTrait.class);
                        trait.removeAssignmentScript(script.getName(), player);
                        trait.checkAutoRemove();
                    }
                }
                break;
            case CLEAR:
                if (npc.getCitizen().hasTrait(AssignmentTrait.class)) {
                    npc.getCitizen().getOrAddTrait(AssignmentTrait.class).clearAssignments(player);
                    npc.getCitizen().removeTrait(AssignmentTrait.class);
                }
                break;
        }
    }
}
Also used : AssignmentTrait(com.denizenscript.denizen.npc.traits.AssignmentTrait) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) NPCTag(com.denizenscript.denizen.objects.NPCTag) InvalidArgumentsRuntimeException(com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException) List(java.util.List) AssignmentScriptContainer(com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer)

Example 37 with ScriptTag

use of com.denizenscript.denizencore.objects.core.ScriptTag 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)

Example 38 with ScriptTag

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

the class NarrateCommand method parseArgs.

// <--[command]
// @Name Narrate
// @Syntax narrate [<text>] (targets:<player>|...) (format:<script>) (per_player) (from:<uuid>)
// @Required 1
// @Maximum 5
// @Short Shows some text to the player.
// @Group player
// 
// @Description
// Prints some text into the target's chat area. If no target is specified it will default to the attached player or the console.
// 
// Accepts the 'format:<script>' argument, which will reformat the text according to the specified format script. See <@link language Format Script Containers>.
// 
// Optionally use 'per_player' with a list of player targets, to have the tags in the text input be reparsed for each and every player.
// So, for example, "- narrate 'hello <player.name>' targets:<server.online_players>"
// would normally say "hello bob" to every player (every player sees the exact same name in the text, ie bob sees "hello bob", steve also sees "hello bob", etc)
// but if you use "per_player", each player online would see their own name (so bob sees "hello bob", steve sees "hello steve", etc).
// 
// Optionally, specify 'from:<uuid>' to indicate that message came from a specific UUID (used for things like the vanilla client social interaction block option).
// 
// @Tags
// None
// 
// @Usage
// Use to narrate text to the player.
// - narrate "Hello World!"
// 
// @Usage
// Use to narrate text to a list of players.
// - narrate "Hello there." targets:<[player]>|<[someplayer]>|<[thatplayer]>
// 
// @Usage
// Use to narrate text to a unique message to every player on the server.
// - narrate "Hello <player.name>, your secret code is <util.random.duuid>." targets:<server.online_players> per_player
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : ArgumentHelper.interpret(scriptEntry, scriptEntry.getOriginalArguments())) {
        if (!scriptEntry.hasObject("format") && arg.matchesPrefix("format", "f")) {
            String formatStr = TagManager.tag(arg.getValue(), scriptEntry.getContext());
            FormatScriptContainer format = ScriptRegistry.getScriptContainer(formatStr);
            if (format == null) {
                Debug.echoError("Could not find format script matching '" + formatStr + "'");
            }
            scriptEntry.addObject("format", new ScriptTag(format));
        } else if (!scriptEntry.hasObject("targets") && arg.matchesPrefix("target", "targets", "t")) {
            scriptEntry.addObject("targets", ListTag.getListFor(TagManager.tagObject(arg.getValue(), scriptEntry.getContext()), scriptEntry.getContext()).filter(PlayerTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("from") && arg.matchesPrefix("from")) {
            scriptEntry.addObject("from", TagManager.tagObject(arg.getValue(), scriptEntry.getContext()));
        } else if (!scriptEntry.hasObject("per_player") && arg.matches("per_player")) {
            scriptEntry.addObject("per_player", new ElementTag(true));
        } else if (!scriptEntry.hasObject("text")) {
            scriptEntry.addObject("text", arg.getRawElement());
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("targets")) {
        scriptEntry.addObject("targets", (Utilities.entryHasPlayer(scriptEntry) ? Collections.singletonList(Utilities.getEntryPlayer(scriptEntry)) : null));
    }
    if (!scriptEntry.hasObject("text")) {
        throw new InvalidArgumentsException("Missing any text!");
    }
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) FormatScriptContainer(com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Aggregations

ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)38 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)17 BukkitTagContext (com.denizenscript.denizen.tags.BukkitTagContext)16 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)8 ListTag (com.denizenscript.denizencore.objects.core.ListTag)8 List (java.util.List)7 ItemTag (com.denizenscript.denizen.objects.ItemTag)5 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)5 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)5 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)5 EntityTag (com.denizenscript.denizen.objects.EntityTag)4 LocationTag (com.denizenscript.denizen.objects.LocationTag)4 FormatScriptContainer (com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer)4 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)4 Player (org.bukkit.entity.Player)4 ImprovedOfflinePlayer (com.denizenscript.denizen.nms.abstracts.ImprovedOfflinePlayer)3 NPCTag (com.denizenscript.denizen.objects.NPCTag)3 AssignmentScriptContainer (com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer)3 InteractScriptContainer (com.denizenscript.denizen.scripts.containers.core.InteractScriptContainer)3 ScriptQueue (com.denizenscript.denizencore.scripts.queues.ScriptQueue)3