Search in sources :

Example 6 with FormatScriptContainer

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

the class NarrateCommand method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    List<dPlayer> targets = (List<dPlayer>) scriptEntry.getObject("targets");
    String text = scriptEntry.getElement("text").asString();
    FormatScriptContainer format = (FormatScriptContainer) scriptEntry.getObject("format");
    // Report to dB
    dB.report(scriptEntry, getName(), aH.debugObj("Narrating", text) + aH.debugList("Targets", targets) + (format != null ? aH.debugObj("Format", format.getName()) : ""));
    if (targets == null) {
        Bukkit.getServer().getConsoleSender().sendMessage(format != null ? format.getFormattedText(scriptEntry) : text);
        return;
    }
    for (dPlayer player : targets) {
        if (player != null && player.isOnline()) {
            player.getPlayerEntity().sendMessage(format != null ? format.getFormattedText(scriptEntry) : text);
        } else {
            dB.echoError("Narrated to non-existent or offline player!");
        }
    }
}
Also used : net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) FormatScriptContainer(net.aufdemrand.denizen.scripts.containers.core.FormatScriptContainer) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList)

Example 7 with FormatScriptContainer

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

the class NarrateCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    if (scriptEntry.getArguments().size() > 4) {
        // TODO: Use this more often!
        throw new InvalidArgumentsException("Too many arguments! Did you forget a 'quote'?");
    }
    // Iterate through arguments
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("format") && arg.matchesPrefix("format", "f")) {
            String formatStr = arg.getValue();
            FormatScriptContainer format = ScriptRegistry.getScriptContainer(formatStr);
            if (format == null) {
                dB.echoError("Could not find format script matching '" + formatStr + '\'');
            }
            scriptEntry.addObject("format", format);
        } else // Add players to target list
        if (!scriptEntry.hasObject("targets") && arg.matchesPrefix("target", "targets", "t")) {
            scriptEntry.addObject("targets", arg.asType(dList.class).filter(dPlayer.class));
        } else // Use raw_value as to not accidentally strip a value before any :'s.
        if (!scriptEntry.hasObject("text")) {
            scriptEntry.addObject("text", new Element(TagManager.cleanOutputFully(arg.raw_value)));
        } else {
            arg.reportUnhandled();
        }
    }
    // to the targets
    if (!scriptEntry.hasObject("targets")) {
        scriptEntry.addObject("targets", (((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer()) : null));
    }
    if (!scriptEntry.hasObject("text")) {
        throw new InvalidArgumentsException("Missing any text!");
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) FormatScriptContainer(net.aufdemrand.denizen.scripts.containers.core.FormatScriptContainer) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 8 with FormatScriptContainer

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

the class AnnounceCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    // let's check if there are more argument than usual.
    if (scriptEntry.getArguments().size() > 3) {
        throw new InvalidArgumentsException("Too many arguments! Did you forget a 'quote'?");
    }
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("type") && arg.matches("to_ops")) {
            scriptEntry.addObject("type", AnnounceType.TO_OPS);
        } else if (!scriptEntry.hasObject("type") && arg.matches("to_console")) {
            scriptEntry.addObject("type", AnnounceType.TO_CONSOLE);
        } else if (!scriptEntry.hasObject("type") && arg.matchesPrefix("to_flagged")) {
            scriptEntry.addObject("type", AnnounceType.TO_FLAGGED);
            scriptEntry.addObject("flag", arg.asElement());
        } else if (!scriptEntry.hasObject("format") && arg.matchesPrefix("format")) {
            FormatScriptContainer format = null;
            String formatStr = arg.getValue();
            format = ScriptRegistry.getScriptContainer(formatStr);
            if (format == null) {
                dB.echoError("Could not find format script matching '" + formatStr + '\'');
            }
            scriptEntry.addObject("format", format);
        } else if (!scriptEntry.hasObject("text")) {
            scriptEntry.addObject("text", new Element(arg.raw_value));
        }
    }
    // If text is missing, alert the console.
    if (!scriptEntry.hasObject("text")) {
        throw new InvalidArgumentsException("Missing text argument!");
    }
    scriptEntry.defaultObject("type", AnnounceType.ALL);
}
Also used : net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) FormatScriptContainer(net.aufdemrand.denizen.scripts.containers.core.FormatScriptContainer) Element(net.aufdemrand.denizencore.objects.Element) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Aggregations

FormatScriptContainer (net.aufdemrand.denizen.scripts.containers.core.FormatScriptContainer)8 Element (net.aufdemrand.denizencore.objects.Element)7 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)5 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)4 List (java.util.List)3 BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)3 InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)3 net.aufdemrand.denizencore.objects.aH (net.aufdemrand.denizencore.objects.aH)3 BukkitTagContext (net.aufdemrand.denizen.tags.BukkitTagContext)1 net.aufdemrand.denizencore.objects.dObject (net.aufdemrand.denizencore.objects.dObject)1 Comparable (net.aufdemrand.denizencore.scripts.commands.core.Comparable)1 Player (org.bukkit.entity.Player)1