Search in sources :

Example 21 with ScriptEntry

use of com.denizenscript.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.

the class WalkCommand method checkHeld.

public void checkHeld(EntityTag entity) {
    for (int i = 0; i < held.size(); i++) {
        ScriptEntry entry = held.get(i);
        List<EntityTag> waitForEntities = (List<EntityTag>) entry.getObject("entities");
        if (waitForEntities == null) {
            continue;
        }
        waitForEntities.remove(entity);
        if (waitForEntities.isEmpty()) {
            if (!entry.hasObject("tally") || ((List<NPCTag>) entry.getObject("tally")).isEmpty()) {
                entry.setFinished(true);
                held.remove(i);
                i--;
            }
        }
    }
}
Also used : NPCTag(com.denizenscript.denizen.objects.NPCTag) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) EntityTag(com.denizenscript.denizen.objects.EntityTag) ArrayList(java.util.ArrayList) List(java.util.List)

Example 22 with ScriptEntry

use of com.denizenscript.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.

the class PauseCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    DurationTag duration = scriptEntry.getObjectTag("duration");
    ElementTag pauseTypeElement = scriptEntry.getElement("pause_type");
    PauseType pauseType = PauseType.valueOf(pauseTypeElement.asString().toUpperCase());
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), duration, pauseTypeElement);
    }
    NPCTag npc = null;
    if (Utilities.getEntryNPC(scriptEntry) != null) {
        npc = Utilities.getEntryNPC(scriptEntry);
    }
    pause(npc, pauseType, !scriptEntry.getCommandName().equalsIgnoreCase("RESUME"));
    if (duration != null) {
        if (durations.containsKey(npc.getCitizen().getId() + pauseType.name())) {
            try {
                Denizen.getInstance().getServer().getScheduler().cancelTask(durations.get(npc.getCitizen().getId() + pauseType.name()));
            } catch (Exception e) {
                Debug.echoError(scriptEntry, "There was an error pausing that!");
                Debug.echoError(scriptEntry, e);
            }
        }
        Debug.echoDebug(scriptEntry, "Running delayed task: Unpause " + pauseType.toString());
        final NPCTag theNpc = npc;
        final ScriptEntry se = scriptEntry;
        durations.put(npc.getId() + pauseType.name(), Denizen.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), () -> {
            Debug.echoDebug(se, "Running delayed task: Pausing " + pauseType.toString());
            pause(theNpc, pauseType, false);
        }, duration.getTicks()));
    }
}
Also used : NPCTag(com.denizenscript.denizen.objects.NPCTag) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 23 with ScriptEntry

use of com.denizenscript.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.

the class WalkCommandCitizensEvents method checkHeld.

public void checkHeld(NavigationEvent e) {
    if (e.getNPC() == null) {
        return;
    }
    for (int i = 0; i < WalkCommand.held.size(); i++) {
        ScriptEntry entry = WalkCommand.held.get(i);
        List<NPCTag> tally = (List<NPCTag>) entry.getObject("tally");
        if (tally == null) {
            WalkCommand.held.remove(i--);
            continue;
        }
        for (int x = 0; x < tally.size(); x++) {
            if (!tally.get(x).isSpawned()) {
                tally.remove(x--);
            }
        }
        tally.remove(new NPCTag(e.getNPC()));
        if (tally.isEmpty()) {
            Bukkit.getScheduler().runTaskLater(Denizen.getInstance(), () -> entry.setFinished(true), 1);
            WalkCommand.held.remove(i--);
        }
    }
}
Also used : NPCTag(com.denizenscript.denizen.objects.NPCTag) ScriptEntry(com.denizenscript.denizencore.scripts.ScriptEntry) List(java.util.List)

Aggregations

ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)23 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)11 EntityTag (com.denizenscript.denizen.objects.EntityTag)10 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)9 NPCTag (com.denizenscript.denizen.objects.NPCTag)8 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)8 ListTag (com.denizenscript.denizencore.objects.core.ListTag)8 AbstractCommand (com.denizenscript.denizencore.scripts.commands.AbstractCommand)8 List (java.util.List)8 Debug (com.denizenscript.denizen.utilities.debugging.Debug)7 BukkitScriptEntryData (com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData)7 ScriptQueue (com.denizenscript.denizencore.scripts.queues.ScriptQueue)7 InstantQueue (com.denizenscript.denizencore.scripts.queues.core.InstantQueue)7 NMSHandler (com.denizenscript.denizen.nms.NMSHandler)6 Utilities (com.denizenscript.denizen.utilities.Utilities)6 Argument (com.denizenscript.denizencore.objects.Argument)6 ContextSource (com.denizenscript.denizencore.scripts.queues.ContextSource)5 Player (org.bukkit.entity.Player)5 Denizen (com.denizenscript.denizen.Denizen)4 LocationTag (com.denizenscript.denizen.objects.LocationTag)4