Search in sources :

Example 1 with FormatScriptContainer

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

the class AnnounceCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Fetch objects
    Element text = scriptEntry.getElement("text");
    AnnounceType type = (AnnounceType) scriptEntry.getObject("type");
    FormatScriptContainer format = (FormatScriptContainer) scriptEntry.getObject("format");
    Element flag = scriptEntry.getElement("flag");
    // Report to dB
    dB.report(scriptEntry, getName(), aH.debugObj("Message", text) + (format != null ? aH.debugObj("Format", format.getName()) : "") + aH.debugObj("Type", type.name()) + (flag != null ? aH.debugObj("Flag_Name", flag) : ""));
    String message = format != null ? format.getFormattedText(scriptEntry) : text.asString();
    // Use Bukkit to broadcast the message to everybody in the server.
    if (type == AnnounceType.ALL) {
        DenizenAPI.getCurrentInstance().getServer().broadcastMessage(message);
    } else if (type == AnnounceType.TO_OPS) {
        for (Player player : Bukkit.getOnlinePlayers()) {
            if (player.isOp()) {
                player.sendMessage(message);
            }
        }
    } else if (type == AnnounceType.TO_FLAGGED) {
        for (Player player : Bukkit.getOnlinePlayers()) {
            if (FlagManager.playerHasFlag(dPlayer.mirrorBukkitPlayer(player), flag.asString())) {
                player.sendMessage(message);
            }
        }
    } else if (type == AnnounceType.TO_CONSOLE) {
        Bukkit.getServer().getConsoleSender().sendMessage(message);
    }
}
Also used : net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Player(org.bukkit.entity.Player) Element(net.aufdemrand.denizencore.objects.Element) FormatScriptContainer(net.aufdemrand.denizen.scripts.containers.core.FormatScriptContainer)

Example 2 with FormatScriptContainer

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

the class ChatScriptEvent method applyDetermination.

@Override
public boolean applyDetermination(ScriptContainer container, String determination) {
    String lower = CoreUtilities.toLowerCase(determination);
    if (lower.startsWith("format:")) {
        String name = determination.substring(7);
        FormatScriptContainer formatscr = ScriptRegistry.getScriptContainer(name);
        if (formatscr == null) {
            dB.echoError("Could not find format script matching '" + name + '\'');
        } else {
            String formatstr = formatscr.getFormatText(null, player);
            if (net.aufdemrand.denizencore.utilities.debugging.dB.verbose) {
                dB.log("Setting format to " + formatstr);
            }
            format = new Element(formatstr);
        }
    } else if (lower.startsWith("recipients:")) {
        String rec_new = determination.substring(11);
        dList recs = dList.valueOf(rec_new);
        List<dPlayer> players = recs.filter(dPlayer.class);
        recipients.clear();
        for (dPlayer player : players) {
            recipients.add(player.getPlayerEntity());
        }
    } else if (!lower.startsWith("cancelled")) {
        message = new Element(determination);
    } else {
        return super.applyDetermination(container, determination);
    }
    return true;
}
Also used : FormatScriptContainer(net.aufdemrand.denizen.scripts.containers.core.FormatScriptContainer) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList)

Example 3 with FormatScriptContainer

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

the class BukkitElementProperties method getAttribute.

@Override
public String getAttribute(Attribute attribute) {
    // -->
    if (attribute.startsWith("is") && attribute.hasContext(1) && (attribute.startsWith("to", 2) || attribute.startsWith("than", 2)) && attribute.hasContext(2)) {
        // Use the Comparable object as implemented for the IF command. First, a new Comparable!
        Comparable com = new Comparable();
        // Check for negative logic
        String operator;
        if (attribute.getContext(1).startsWith("!")) {
            operator = attribute.getContext(1).substring(1);
            com.setNegativeLogic();
        } else {
            operator = attribute.getContext(1);
        }
        // Operator is the value of the .is[] context. Valid are Comparable.Operators, same
        // as used by the IF command.
        Comparable.Operator comparableOperator = null;
        try {
            comparableOperator = Comparable.Operator.valueOf(operator.replace("==", "EQUALS").replace(">=", "OR_MORE").replace("<=", "OR_LESS").replace("<", "LESS").replace(">", "MORE").replace("=", "EQUALS").toUpperCase());
        } catch (IllegalArgumentException e) {
        }
        if (comparableOperator != null) {
            com.setOperator(comparableOperator);
            // Comparable is the value of this element
            com.setComparable(element.asString());
            // Compared_to is the value of the .to[] context.
            com.setComparedto(attribute.getContext(2));
            return new Element(com.determineOutcome()).getAttribute(attribute.fulfill(2));
        } else {
            net.aufdemrand.denizencore.utilities.debugging.dB.echoError("Unknown operator '" + operator + "'.");
        }
    }
    // -->
    if (attribute.startsWith("aschunk") || attribute.startsWith("as_chunk")) {
        dObject object = Element.handleNull(element.asString(), dChunk.valueOf(element.asString(), new BukkitTagContext(attribute.getScriptEntry(), false)), "dChunk", attribute.hasAlternative());
        if (object != null) {
            return object.getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("ascolor") || attribute.startsWith("as_color")) {
        dObject object = Element.handleNull(element.asString(), dColor.valueOf(element.asString(), new BukkitTagContext(attribute.getScriptEntry(), false)), "dColor", attribute.hasAlternative());
        if (object != null) {
            return object.getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("ascuboid") || attribute.startsWith("as_cuboid")) {
        dObject object = Element.handleNull(element.asString(), dCuboid.valueOf(element.asString(), new BukkitTagContext(attribute.getScriptEntry(), false)), "dCuboid", attribute.hasAlternative());
        if (object != null) {
            return object.getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("asentity") || attribute.startsWith("as_entity")) {
        dObject object = Element.handleNull(element.asString(), dEntity.valueOf(element.asString(), new BukkitTagContext(attribute.getScriptEntry(), false)), "dEntity", attribute.hasAlternative());
        if (object != null) {
            return object.getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("asinventory") || attribute.startsWith("as_inventory")) {
        dObject object = Element.handleNull(element.asString(), dInventory.valueOf(element.asString(), new BukkitTagContext(attribute.getScriptEntry(), false)), "dInventory", attribute.hasAlternative());
        if (object != null) {
            return object.getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("asitem") || attribute.startsWith("as_item")) {
        dObject object = Element.handleNull(element.asString(), dItem.valueOf(element.asString(), new BukkitTagContext(attribute.getScriptEntry(), false)), "dItem", attribute.hasAlternative());
        if (object != null) {
            return object.getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("aslocation") || attribute.startsWith("as_location")) {
        dObject object = Element.handleNull(element.asString(), dLocation.valueOf(element.asString(), new BukkitTagContext(attribute.getScriptEntry(), false)), "dLocation", attribute.hasAlternative());
        if (object != null) {
            return object.getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("asmaterial") || attribute.startsWith("as_material")) {
        dObject object = Element.handleNull(element.asString(), dMaterial.valueOf(element.asString(), new BukkitTagContext(attribute.getScriptEntry(), false)), "dMaterial", attribute.hasAlternative());
        if (object != null) {
            return object.getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("asnpc") || attribute.startsWith("as_npc")) {
        dObject object = Element.handleNull(element.asString(), dNPC.valueOf(element.asString(), new BukkitTagContext(attribute.getScriptEntry(), false)), "dNPC", attribute.hasAlternative());
        if (object != null) {
            return object.getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("asplayer") || attribute.startsWith("as_player")) {
        dObject object = Element.handleNull(element.asString(), dPlayer.valueOf(element.asString(), new BukkitTagContext(attribute.getScriptEntry(), false)), "dPlayer", attribute.hasAlternative());
        if (object != null) {
            return object.getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("asworld") || attribute.startsWith("as_world")) {
        dObject object = Element.handleNull(element.asString(), dWorld.valueOf(element.asString(), new BukkitTagContext(attribute.getScriptEntry(), false)), "dWorld", attribute.hasAlternative());
        if (object != null) {
            return object.getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("asplugin") || attribute.startsWith("as_plugin")) {
        dObject object = Element.handleNull(element.asString(), dPlugin.valueOf(element.asString(), new BukkitTagContext(attribute.getScriptEntry(), false)), "dPlugin", attribute.hasAlternative());
        if (object != null) {
            return object.getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("debug.no_color")) {
        return new Element(ChatColor.stripColor(element.debug())).getAttribute(attribute.fulfill(2));
    }
    // -->
    if (attribute.startsWith("last_color")) {
        return new Element(ChatColor.getLastColors(element.asString())).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("format") && attribute.hasContext(1)) {
        FormatScriptContainer format = ScriptRegistry.getScriptContainer(attribute.getContext(1));
        if (format == null) {
            net.aufdemrand.denizencore.utilities.debugging.dB.echoError("Could not find format script matching '" + attribute.getContext(1) + "'");
            return null;
        } else {
            return new Element(format.getFormattedText(element.asString(), attribute.getScriptEntry() != null ? ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getNPC() : null, attribute.getScriptEntry() != null ? ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer() : null)).getAttribute(attribute.fulfill(1));
        }
    }
    // -->
    if (attribute.startsWith("strip_color")) {
        return new Element(ChatColor.stripColor(element.asString())).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("parse_color")) {
        char prefix = '&';
        if (attribute.hasContext(1)) {
            prefix = attribute.getContext(1).charAt(0);
        }
        return new Element(ChatColor.translateAlternateColorCodes(prefix, element.asString())).getAttribute(attribute.fulfill(1));
    }
    // -->
    if (attribute.startsWith("to_itemscript_hash")) {
        return new Element(ItemScriptHelper.createItemScriptID(element.asString())).getAttribute(attribute.fulfill(1));
    }
    return null;
}
Also used : Comparable(net.aufdemrand.denizencore.scripts.commands.core.Comparable) BukkitTagContext(net.aufdemrand.denizen.tags.BukkitTagContext) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dObject(net.aufdemrand.denizencore.objects.dObject) FormatScriptContainer(net.aufdemrand.denizen.scripts.containers.core.FormatScriptContainer)

Example 4 with FormatScriptContainer

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

the class ActionBarCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (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);
        }
        if (arg.matchesPrefix("targets", "target") && arg.matchesArgumentList(dPlayer.class)) {
            scriptEntry.addObject("targets", arg.asType(dList.class).filter(dPlayer.class));
        } else if (!scriptEntry.hasObject("text")) {
            scriptEntry.addObject("text", new Element(TagManager.cleanOutputFully(arg.raw_value)));
        }
    }
    if (!scriptEntry.hasObject("text")) {
        throw new InvalidArgumentsException("Must specify a message!");
    }
    if (!scriptEntry.hasObject("targets") && !((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer()) {
        throw new InvalidArgumentsException("Must specify target(s).");
    }
    if (!scriptEntry.hasObject("targets")) {
        BukkitScriptEntryData data = (BukkitScriptEntryData) scriptEntry.entryData;
        if (!data.hasPlayer()) {
            throw new InvalidArgumentsException("Must specify valid player Targets!");
        } else {
            scriptEntry.addObject("targets", Arrays.asList(data.getPlayer()));
        }
    }
}
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.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Element(net.aufdemrand.denizencore.objects.Element) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 5 with FormatScriptContainer

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

the class ActionBarCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element text = scriptEntry.getElement("text");
    FormatScriptContainer format = (FormatScriptContainer) scriptEntry.getObject("format");
    List<dPlayer> targets = (List<dPlayer>) scriptEntry.getObject("targets");
    dB.report(scriptEntry, getName(), text.debug() + aH.debugList("Targets", targets));
    if (format != null) {
        text = new Element(format.getFormattedText(scriptEntry));
    }
    for (dPlayer player : targets) {
        if (player.isValid() && player.isOnline()) {
            NMSHandler.getInstance().getPacketHelper().sendActionBarMessage(player.getPlayerEntity(), text.asString());
        } else {
            dB.echoError(scriptEntry.getResidingQueue(), "Tried to send action bar message to non-existent or offline player!");
        }
    }
}
Also used : Element(net.aufdemrand.denizencore.objects.Element) FormatScriptContainer(net.aufdemrand.denizen.scripts.containers.core.FormatScriptContainer) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList)

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