Search in sources :

Example 1 with Comparable

use of net.aufdemrand.denizencore.scripts.commands.core.Comparable 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)

Aggregations

BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)1 FormatScriptContainer (net.aufdemrand.denizen.scripts.containers.core.FormatScriptContainer)1 BukkitTagContext (net.aufdemrand.denizen.tags.BukkitTagContext)1 Element (net.aufdemrand.denizencore.objects.Element)1 net.aufdemrand.denizencore.objects.dObject (net.aufdemrand.denizencore.objects.dObject)1 Comparable (net.aufdemrand.denizencore.scripts.commands.core.Comparable)1