Search in sources :

Example 11 with ScriptEntry

use of net.aufdemrand.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.

the class BreakCommand method execute.

// <--[action]
// @Actions
// dig
//
// @Triggers when the NPC breaks a block with the Break Command
//
// @Context
// <context.location> returns the location the NPC Dug
// <context.material> Returns the Block dug
//
// -->
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    final dLocation location = (dLocation) scriptEntry.getObject("location");
    final dNPC npc = (dNPC) scriptEntry.getObject("entity");
    Element radius = scriptEntry.getElement("radius");
    final HashMap<String, dObject> context = new HashMap<String, dObject>();
    dMaterial material = dMaterial.getMaterialFrom(location.getBlock().getType(), location.getBlock().getData());
    context.put("location", location);
    context.put("material", material);
    dB.report(scriptEntry, getName(), location.debug() + npc.debug() + radius.debug());
    final ScriptEntry se = scriptEntry;
    BlockBreaker.BlockBreakerConfiguration config = new BlockBreaker.BlockBreakerConfiguration();
    config.item(npc.getLivingEntity().getEquipment().getItemInHand());
    config.radius(radius.asDouble());
    config.callback(new Runnable() {

        @Override
        public void run() {
            npc.action("dig", null, context);
            se.setFinished(true);
        }
    });
    BlockBreaker breaker = npc.getCitizen().getBlockBreaker(location.getBlock(), config);
    if (breaker.shouldExecute()) {
        TaskRunnable run = new TaskRunnable(breaker);
        run.taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(DenizenAPI.getCurrentInstance(), run, 0, 1);
    }
}
Also used : net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) HashMap(java.util.HashMap) Element(net.aufdemrand.denizencore.objects.Element) ScriptEntry(net.aufdemrand.denizencore.scripts.ScriptEntry) BlockBreaker(net.citizensnpcs.api.npc.BlockBreaker) net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) net.aufdemrand.denizencore.objects.dObject(net.aufdemrand.denizencore.objects.dObject) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 12 with ScriptEntry

use of net.aufdemrand.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.

the class AbstractTrigger method parse.

public boolean parse(dNPC npc, dPlayer player, InteractScriptContainer script, String id, Map<String, dObject> context) {
    if (npc == null || player == null || script == null) {
        return false;
    }
    List<ScriptEntry> entries = script.getEntriesFor(this.getClass(), player, npc, id, true);
    if (entries.isEmpty()) {
        return false;
    }
    dB.echoDebug(script, DebugElement.Header, "Parsing " + name + " trigger: n@" + npc.getName() + "/p@" + player.getName());
    // Create Queue
    TimedQueue queue = TimedQueue.getQueue(ScriptQueue.getNextId(script.getName()));
    // Add all entries to set it up
    queue.addEntries(entries);
    // Add context
    if (context != null) {
        OldEventManager.OldEventContextSource oecs = new OldEventManager.OldEventContextSource();
        oecs.contexts = context;
        queue.setContextSource(oecs);
    }
    // Start it
    queue.start();
    return true;
}
Also used : OldEventManager(net.aufdemrand.denizencore.events.OldEventManager) ScriptEntry(net.aufdemrand.denizencore.scripts.ScriptEntry) TimedQueue(net.aufdemrand.denizencore.scripts.queues.core.TimedQueue)

Example 13 with ScriptEntry

use of net.aufdemrand.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.

the class dB method echoError.

public static void echoError(ScriptQueue source, Throwable ex) {
    if (ThrowErrorEvent) {
        ThrowErrorEvent = false;
        Map<String, dObject> context = new HashMap<String, dObject>();
        Throwable thrown = ex;
        if (ex.getCause() != null) {
            thrown = ex.getCause();
        }
        context.put("message", new Element(thrown.getMessage()));
        context.put("type", new Element(thrown.getClass().getSimpleName()));
        context.put("queue", source);
        ScriptEntry entry = (source != null ? source.getLastEntryExecuted() : null);
        List<String> Determinations = OldEventManager.doEvents(Arrays.asList("server generates exception"), entry == null ? new BukkitScriptEntryData(null, null) : entry.entryData, context);
        ThrowErrorEvent = true;
        for (String Determination : Determinations) {
            if (Determination.equalsIgnoreCase("CANCELLED")) {
                return;
            }
        }
    }
    if (!showDebug) {
        return;
    }
    if (!showStackTraces) {
        dB.echoError(source, "Exception! Enable '/denizen debug -s' for the nitty-gritty.");
    } else {
        dB.echoError(source, "Internal exception was thrown!");
        ex.printStackTrace();
        if (dB.record) {
            String prefix = ConsoleSender.dateFormat.format(new Date()) + " [SEVERE] ";
            boolean first = true;
            while (ex != null) {
                dB.Recording.append(URLEncoder.encode(prefix + (first ? "" : "Caused by: ") + ex.toString() + "\n"));
                for (StackTraceElement ste : ex.getStackTrace()) {
                    dB.Recording.append(URLEncoder.encode(prefix + ste.toString() + "\n"));
                }
                if (ex.getCause() == ex) {
                    return;
                }
                ex = ex.getCause();
                first = false;
            }
        }
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizencore.objects.dObject(net.aufdemrand.denizencore.objects.dObject) DebugElement(net.aufdemrand.denizencore.utilities.debugging.dB.DebugElement) Element(net.aufdemrand.denizencore.objects.Element) ScriptEntry(net.aufdemrand.denizencore.scripts.ScriptEntry)

Example 14 with ScriptEntry

use of net.aufdemrand.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.

the class dB method echoError.

public static void echoError(ScriptQueue source, String message) {
    dScript script = null;
    if (source != null && source.getEntries().size() > 0 && source.getEntries().get(0).getScript() != null) {
        script = source.getEntries().get(0).getScript();
    } else if (source != null && source.getLastEntryExecuted() != null && source.getLastEntryExecuted().getScript() != null) {
        script = source.getLastEntryExecuted().getScript();
    }
    if (ThrowErrorEvent) {
        ThrowErrorEvent = false;
        Map<String, dObject> context = new HashMap<String, dObject>();
        context.put("message", new Element(message));
        if (source != null) {
            context.put("queue", source);
        }
        if (script != null) {
            context.put("script", script);
        }
        List<String> events = new ArrayList<String>();
        events.add("script generates error");
        if (script != null) {
            events.add(script.identifySimple() + " generates error");
        }
        ScriptEntry entry = (source != null ? source.getLastEntryExecuted() : null);
        List<String> Determinations = OldEventManager.doEvents(events, entry != null ? entry.entryData : new BukkitScriptEntryData(null, null), context, true);
        ThrowErrorEvent = true;
        for (String Determination : Determinations) {
            if (Determination.equalsIgnoreCase("CANCELLED")) {
                return;
            }
        }
    }
    if (!showDebug) {
        return;
    }
    ConsoleSender.sendMessage(ChatColor.LIGHT_PURPLE + " " + ChatColor.RED + "ERROR" + (script != null ? " in script '" + script.getName() + "'" : "") + "! " + ChatColor.WHITE + trimMessage(message));
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizencore.objects.dScript(net.aufdemrand.denizencore.objects.dScript) net.aufdemrand.denizencore.objects.dObject(net.aufdemrand.denizencore.objects.dObject) DebugElement(net.aufdemrand.denizencore.utilities.debugging.dB.DebugElement) Element(net.aufdemrand.denizencore.objects.Element) ScriptEntry(net.aufdemrand.denizencore.scripts.ScriptEntry)

Example 15 with ScriptEntry

use of net.aufdemrand.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.

the class PauseCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    pause(dNPC, pauseType, !scriptEntry.getCommandName().equalsIgnoreCase("RESUME"));
    // If duration...
    if (duration > 0) {
        if (durations.containsKey(dNPC.getCitizen().getId() + pauseType.name())) {
            try {
                DenizenAPI.getCurrentInstance().getServer().getScheduler().cancelTask(durations.get(dNPC.getCitizen().getId() + pauseType.name()));
            } catch (Exception e) {
                dB.echoError(scriptEntry.getResidingQueue(), "There was an error pausing that!");
                dB.echoError(scriptEntry.getResidingQueue(), e);
            }
        }
        dB.echoDebug(scriptEntry, "Running delayed task: Unpause " + pauseType.toString());
        final ScriptEntry se = scriptEntry;
        durations.put(dNPC.getId() + pauseType.name(), DenizenAPI.getCurrentInstance().getServer().getScheduler().scheduleSyncDelayedTask(DenizenAPI.getCurrentInstance(), new Runnable() {

            @Override
            public void run() {
                dB.echoDebug(se, "Running delayed task: Pausing " + pauseType.toString());
                pause(dNPC, pauseType, false);
            }
        }, duration * 20));
    }
}
Also used : ScriptEntry(net.aufdemrand.denizencore.scripts.ScriptEntry) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException)

Aggregations

ScriptEntry (net.aufdemrand.denizencore.scripts.ScriptEntry)20 Element (net.aufdemrand.denizencore.objects.Element)9 ScriptQueue (net.aufdemrand.denizencore.scripts.queues.ScriptQueue)8 List (java.util.List)7 BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)6 net.aufdemrand.denizencore.objects.dObject (net.aufdemrand.denizencore.objects.dObject)5 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)5 DebugElement (net.aufdemrand.denizencore.utilities.debugging.dB.DebugElement)5 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)4 OldEventManager (net.aufdemrand.denizencore.events.OldEventManager)4 CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)4 InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)4 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)4 ArrayList (java.util.ArrayList)3 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)3 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)3 BukkitTagContext (net.aufdemrand.denizen.tags.BukkitTagContext)2 ScriptEntryCreationException (net.aufdemrand.denizencore.exceptions.ScriptEntryCreationException)2 InstantQueue (net.aufdemrand.denizencore.scripts.queues.core.InstantQueue)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2