Search in sources :

Example 11 with ScriptQueue

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

the class DenizenChat method talk.

@Override
public void talk(SpeechContext speechContext) {
    if (!(speechContext instanceof DenizenSpeechContext)) {
        return;
    }
    DenizenSpeechContext context = (DenizenSpeechContext) speechContext;
    Talkable talker = context.getTalker();
    if (talker == null) {
        return;
    }
    ScriptEntry entry = context.getScriptEntry();
    ScriptQueue queue = entry.getResidingQueue();
    String defTalker = null;
    if (queue.hasDefinition("talker")) {
        defTalker = queue.getDefinition("talker");
    }
    queue.addDefinition("talker", new dEntity(talker.getEntity()).identify());
    String defMessage = null;
    if (queue.hasDefinition("message")) {
        defMessage = queue.getDefinition("message");
    }
    queue.addDefinition("message", context.getMessage());
    // Chat to the world using Denizen chat settings
    if (!context.hasRecipients()) {
        String text = TagManager.tag(Settings.chatNoTargetFormat(), new BukkitTagContext(entry, false));
        talkToBystanders(talker, text, context);
    } else // Single recipient
    if (context.size() <= 1) {
        // Send chat to target
        String text = TagManager.tag(Settings.chatToTargetFormat(), new BukkitTagContext(entry, false));
        for (Talkable entity : context) {
            entity.talkTo(context, text, this);
        }
        // Check if bystanders hear targeted chat
        if (context.isBystandersEnabled()) {
            String defTarget = null;
            if (queue.hasDefinition("target")) {
                defTarget = queue.getDefinition("target");
            }
            queue.addDefinition("target", new dEntity(context.iterator().next().getEntity()).identify());
            String bystanderText = TagManager.tag(Settings.chatWithTargetToBystandersFormat(), new BukkitTagContext(entry, false));
            talkToBystanders(talker, bystanderText, context);
            if (defTarget != null) {
                queue.addDefinition("target", defTarget);
            }
        }
    } else // Multiple recipients
    {
        // Send chat to targets
        String text = TagManager.tag(Settings.chatToTargetFormat(), new BukkitTagContext(entry, false));
        for (Talkable entity : context) {
            entity.talkTo(context, text, this);
        }
        if (context.isBystandersEnabled()) {
            String[] format = Settings.chatMultipleTargetsFormat().split("%target%");
            if (format.length <= 1) {
                dB.echoError("Invalid 'Commands.Chat.Options.Multiple targets format' in config.yml! Must have at least 1 %target%");
            }
            StringBuilder parsed = new StringBuilder();
            Iterator<Talkable> iter = context.iterator();
            int i = 0;
            while (iter.hasNext()) {
                if (i == format.length) {
                    parsed.append(format[i]);
                    break;
                }
                parsed.append(format[i]).append(new dEntity(iter.next().getEntity()).getName());
                i++;
            }
            String targets = TagManager.tag(parsed.toString(), new BukkitTagContext(entry, false));
            String defTargets = null;
            if (queue.hasDefinition("targets")) {
                defTargets = queue.getDefinition("targets");
            }
            queue.addDefinition("targets", targets);
            String bystanderText = TagManager.tag(Settings.chatWithTargetsToBystandersFormat(), new BukkitTagContext(entry, false));
            talkToBystanders(talker, bystanderText, context);
            if (defTargets != null) {
                queue.addDefinition("targets", defTargets);
            }
        }
    }
    if (defMessage != null) {
        queue.addDefinition("message", defMessage);
    }
    if (defTalker != null) {
        queue.addDefinition("talker", defTalker);
    }
}
Also used : BukkitTagContext(net.aufdemrand.denizen.tags.BukkitTagContext) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Iterator(java.util.Iterator) ScriptEntry(net.aufdemrand.denizencore.scripts.ScriptEntry) Talkable(net.citizensnpcs.api.ai.speech.Talkable) ScriptQueue(net.aufdemrand.denizencore.scripts.queues.ScriptQueue)

Example 12 with ScriptQueue

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

the class ModifyBlockCommand method execute.

@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    final dList materials = scriptEntry.getdObject("materials");
    final List<dLocation> locations = (List<dLocation>) scriptEntry.getObject("locations");
    final dList location_list = scriptEntry.getdObject("location_list");
    final Element physics = scriptEntry.getElement("physics");
    final Element natural = scriptEntry.getElement("natural");
    final Element delayed = scriptEntry.getElement("delayed");
    final Element radiusElement = scriptEntry.getElement("radius");
    final Element heightElement = scriptEntry.getElement("height");
    final Element depthElement = scriptEntry.getElement("depth");
    final dScript script = scriptEntry.getdObject("script");
    dList percents = scriptEntry.getdObject("percents");
    if (percents != null && percents.size() != materials.size()) {
        dB.echoError(scriptEntry.getResidingQueue(), "Percents length != materials length");
        percents = null;
    }
    final List<dMaterial> materialList = materials.filter(dMaterial.class);
    dB.report(scriptEntry, getName(), (locations == null ? location_list.debug() : aH.debugList("locations", locations)) + materials.debug() + physics.debug() + radiusElement.debug() + heightElement.debug() + depthElement.debug() + natural.debug() + delayed.debug() + (script != null ? script.debug() : "") + (percents != null ? percents.debug() : ""));
    final boolean doPhysics = physics.asBoolean();
    final boolean isNatural = natural.asBoolean();
    final int radius = radiusElement.asInt();
    final int height = heightElement.asInt();
    final int depth = depthElement.asInt();
    List<Float> percentages = null;
    if (percents != null) {
        percentages = new ArrayList<Float>();
        for (String str : percents) {
            percentages.add(new Element(str).asFloat());
        }
    }
    final List<Float> percs = percentages;
    if ((locations == null || locations.size() == 0) && (location_list == null || location_list.size() == 0)) {
        dB.echoError("Must specify a valid location!");
    }
    if (materialList.size() == 0) {
        dB.echoError("Must specify a valid material!");
    }
    no_physics = !doPhysics;
    if (delayed.asBoolean()) {
        new BukkitRunnable() {

            int index = 0;

            @Override
            public void run() {
                long start = System.currentTimeMillis();
                dLocation loc;
                if (locations != null) {
                    loc = locations.get(0);
                } else {
                    loc = dLocation.valueOf(location_list.get(0));
                }
                boolean was_static = preSetup(loc);
                while ((locations != null && locations.size() > index) || (location_list != null && location_list.size() > index)) {
                    dLocation nLoc;
                    if (locations != null) {
                        nLoc = locations.get(index);
                    } else {
                        nLoc = dLocation.valueOf(location_list.get(index));
                    }
                    handleLocation(nLoc, index, materialList, doPhysics, isNatural, radius, height, depth, percs);
                    index++;
                    if (System.currentTimeMillis() - start > 50) {
                        break;
                    }
                }
                postComplete(loc, was_static);
                if ((locations != null && locations.size() == index) || (location_list != null && location_list.size() == index)) {
                    if (script != null) {
                        List<ScriptEntry> entries = script.getContainer().getBaseEntries(scriptEntry.entryData.clone());
                        ScriptQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId(script.getContainer().getName())).addEntries(entries);
                        queue.start();
                    }
                    scriptEntry.setFinished(true);
                    cancel();
                }
            }
        }.runTaskTimer(DenizenAPI.getCurrentInstance(), 1, 1);
    } else {
        dLocation loc;
        if (locations != null) {
            loc = locations.get(0);
        } else {
            loc = dLocation.valueOf(location_list.get(0));
        }
        boolean was_static = preSetup(loc);
        int index = 0;
        if (locations != null) {
            for (dObject obj : locations) {
                handleLocation((dLocation) obj, index, materialList, doPhysics, isNatural, radius, height, depth, percentages);
                index++;
            }
        } else {
            for (String str : location_list) {
                handleLocation(dLocation.valueOf(str), index, materialList, doPhysics, isNatural, radius, height, depth, percentages);
                index++;
            }
        }
        postComplete(loc, was_static);
        scriptEntry.setFinished(true);
    }
}
Also used : net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) net.aufdemrand.denizencore.objects.dScript(net.aufdemrand.denizencore.objects.dScript) net.aufdemrand.denizencore.objects.dObject(net.aufdemrand.denizencore.objects.dObject) ArrayList(java.util.ArrayList) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) List(java.util.List) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) ScriptQueue(net.aufdemrand.denizencore.scripts.queues.ScriptQueue)

Example 13 with ScriptQueue

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

the class CommandScriptContainer method runCommandScript.

public ScriptQueue runCommandScript(dPlayer player, dNPC npc, Map<String, dObject> context) {
    ScriptQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId(getName())).addEntries(getBaseEntries(new BukkitScriptEntryData(player, npc)));
    if (context != null) {
        OldEventManager.OldEventContextSource oecs = new OldEventManager.OldEventContextSource();
        oecs.contexts = context;
        queue.setContextSource(oecs);
    }
    queue.start();
    return queue;
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) OldEventManager(net.aufdemrand.denizencore.events.OldEventManager) ScriptQueue(net.aufdemrand.denizencore.scripts.queues.ScriptQueue)

Aggregations

ScriptQueue (net.aufdemrand.denizencore.scripts.queues.ScriptQueue)13 ScriptEntry (net.aufdemrand.denizencore.scripts.ScriptEntry)8 Element (net.aufdemrand.denizencore.objects.Element)5 List (java.util.List)4 BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)4 OldEventManager (net.aufdemrand.denizencore.events.OldEventManager)4 Duration (net.aufdemrand.denizencore.objects.Duration)4 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)3 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)3 CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)3 InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)3 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)3 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 ArrayList (java.util.ArrayList)2 net.aufdemrand.denizencore.objects.dObject (net.aufdemrand.denizencore.objects.dObject)2 Delayable (net.aufdemrand.denizencore.scripts.queues.core.Delayable)2 Vector (org.bukkit.util.Vector)2 Iterator (java.util.Iterator)1 BlockHelper (net.aufdemrand.denizen.nms.interfaces.BlockHelper)1