Search in sources :

Example 1 with InvalidArgumentsException

use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.

the class GiveCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    /* Match arguments to expected variables */
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("qty") && arg.matchesPrefix("q", "qty", "quantity") && arg.matchesPrimitive(aH.PrimitiveType.Double)) {
            scriptEntry.addObject("qty", arg.asElement());
            scriptEntry.addObject("set_quantity", new Element(true));
        } else if (!scriptEntry.hasObject("type") && arg.matches("money", "coins")) {
            scriptEntry.addObject("type", Type.MONEY);
        } else if (!scriptEntry.hasObject("type") && arg.matches("xp", "exp", "experience")) {
            scriptEntry.addObject("type", Type.EXP);
        } else if (!scriptEntry.hasObject("engrave") && arg.matches("engrave")) {
            scriptEntry.addObject("engrave", new Element(true));
        } else if (!scriptEntry.hasObject("unlimit_stack_size") && arg.matches("unlimit_stack_size")) {
            scriptEntry.addObject("unlimit_stack_size", new Element(true));
        } else if (!scriptEntry.hasObject("items") && !scriptEntry.hasObject("type")) {
            scriptEntry.addObject("items", dList.valueOf(arg.raw_value.startsWith("item:") ? arg.raw_value.substring("item:".length()) : arg.raw_value).filter(dItem.class, scriptEntry));
        } else if (!scriptEntry.hasObject("inventory") && arg.matchesPrefix("t", "to") && arg.matchesArgumentType(dInventory.class)) {
            scriptEntry.addObject("inventory", arg.asType(dInventory.class));
        } else if (!scriptEntry.hasObject("slot") && arg.matchesPrefix("slot") && arg.matchesPrimitive(aH.PrimitiveType.Integer)) {
            scriptEntry.addObject("slot", arg.asElement());
        } else {
            arg.reportUnhandled();
        }
    }
    scriptEntry.defaultObject("type", Type.ITEM).defaultObject("engrave", new Element(false)).defaultObject("unlimit_stack_size", new Element(false)).defaultObject("qty", new Element(1)).defaultObject("slot", new Element(1));
    Type type = (Type) scriptEntry.getObject("type");
    if (type != Type.MONEY && scriptEntry.getObject("inventory") == null) {
        scriptEntry.addObject("inventory", ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getInventory() : null);
    }
    if (!scriptEntry.hasObject("inventory") && type != Type.MONEY) {
        throw new InvalidArgumentsException("Must specify an inventory to give to!");
    }
    if (type == Type.ITEM && scriptEntry.getObject("items") == null) {
        throw new InvalidArgumentsException("Must specify item/items!");
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dInventory(net.aufdemrand.denizen.objects.dInventory) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 2 with InvalidArgumentsException

use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.

the class PushCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("origin") && arg.matchesPrefix("origin", "o", "source", "shooter", "s")) {
            if (arg.matchesArgumentType(dEntity.class)) {
                scriptEntry.addObject("originEntity", arg.asType(dEntity.class));
            } else if (arg.matchesArgumentType(dLocation.class)) {
                scriptEntry.addObject("originLocation", arg.asType(dLocation.class));
            } else {
                dB.echoError("Ignoring unrecognized argument: " + arg.raw_value);
            }
        } else if (!scriptEntry.hasObject("destination") && arg.matchesArgumentType(dLocation.class) && arg.matchesPrefix("destination", "d")) {
            scriptEntry.addObject("destination", arg.asType(dLocation.class));
        } else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(Duration.class) && arg.matchesPrefix("duration", "d")) {
            scriptEntry.addObject("duration", arg.asType(Duration.class));
        } else if (!scriptEntry.hasObject("speed") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("speed", "s")) {
            scriptEntry.addObject("speed", arg.asElement());
        } else if (!scriptEntry.hasObject("script") && (arg.matchesArgumentType(dScript.class) || arg.matchesPrefix("script"))) {
            scriptEntry.addObject("script", arg.asType(dScript.class));
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(dEntity.class)) {
            scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class));
        } else if (!scriptEntry.hasObject("force_along") && arg.matches("force_along")) {
            scriptEntry.addObject("force_along", new Element(true));
        } else if (!scriptEntry.hasObject("no_rotate") && arg.matches("no_rotate")) {
            scriptEntry.addObject("no_rotate", new Element(true));
        } else if (!scriptEntry.hasObject("precision") && arg.matchesPrefix("precision")) {
            scriptEntry.addObject("precision", arg.asElement());
        } else if (!scriptEntry.hasObject("no_damage") && arg.matches("no_damage")) {
            scriptEntry.addObject("no_damage", new Element(true));
        } else if (arg.matchesPrefix("def", "define", "context")) {
            scriptEntry.addObject("definitions", arg.asType(dList.class));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("originLocation")) {
        scriptEntry.defaultObject("originEntity", ((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() ? ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getDenizenEntity() : null, ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getDenizenEntity() : null);
    }
    scriptEntry.defaultObject("speed", new Element(1.5));
    scriptEntry.defaultObject("duration", new Duration(20));
    scriptEntry.defaultObject("force_along", new Element(false));
    scriptEntry.defaultObject("precision", new Element(2));
    if (!scriptEntry.hasObject("entities")) {
        throw new InvalidArgumentsException("Must specify entity/entities!");
    }
    if (!scriptEntry.hasObject("originEntity") && !scriptEntry.hasObject("originLocation")) {
        throw new InvalidArgumentsException("Must specify an origin location!");
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) net.aufdemrand.denizencore.objects.dScript(net.aufdemrand.denizencore.objects.dScript) net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element) Duration(net.aufdemrand.denizencore.objects.Duration) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 3 with InvalidArgumentsException

use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.

the class FlagCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    boolean specified_target = false;
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        // specified amount of time
        if (!scriptEntry.hasObject("duration") && arg.matchesPrefix("duration", "d") && arg.matchesArgumentType(Duration.class)) {
            scriptEntry.addObject("duration", arg.asType(Duration.class));
        } else // Also allow attached dObjects to be specified...
        if (!scriptEntry.hasObject("flag_target") && arg.matches("npc", "denizen")) {
            specified_target = true;
            scriptEntry.addObject("flag_target", ((BukkitScriptEntryData) scriptEntry.entryData).getNPC());
        } else if (!scriptEntry.hasObject("flag_target") && arg.matches("global", "server")) {
            specified_target = true;
            scriptEntry.addObject("flag_target", Element.SERVER);
        } else if (!scriptEntry.hasObject("flag_target") && arg.matches("player")) {
            specified_target = true;
            scriptEntry.addObject("flag_target", ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer());
        } else // as the name of the flag..
        if (!scriptEntry.hasObject("flag_target") && arg.startsWith("n@") && !arg.hasPrefix()) {
            if (// TODO: Optimize
            dNPC.valueOf(arg.getValue()) == null) {
                throw new InvalidArgumentsException("Invalid NPC target.");
            }
            specified_target = true;
            scriptEntry.addObject("flag_target", arg.asType(dNPC.class));
        } else if (!scriptEntry.hasObject("flag_target") && arg.startsWith("p@") && !arg.hasPrefix()) {
            if (// TODO: Optimize
            dPlayer.valueOf(arg.getValue()) == null) {
                throw new InvalidArgumentsException("Invalid Player target.");
            }
            specified_target = true;
            scriptEntry.addObject("flag_target", arg.asType(dPlayer.class));
        } else if (!scriptEntry.hasObject("flag_target") && !arg.hasPrefix()) {
            if (// TODO: Optimize
            dEntity.valueOf(arg.getValue()) == null) {
                throw new InvalidArgumentsException("Invalid Entity target.");
            }
            specified_target = true;
            scriptEntry.addObject("flag_target", arg.asType(dEntity.class));
        } else // Check if setting a boolean
        if (!scriptEntry.hasObject("flag_name") && arg.raw_value.split(":", 3).length == 1) {
            scriptEntry.addObject("action", FlagManager.Action.SET_BOOLEAN);
            scriptEntry.addObject("value", Element.TRUE);
            scriptEntry.addObject("flag_name", arg.asElement());
        } else // Check for flag_name:value/action
        if (!scriptEntry.hasObject("flag_name") && arg.raw_value.split(":", 3).length == 2) {
            String[] flagArgs = arg.raw_value.split(":", 2);
            scriptEntry.addObject("flag_name", new Element(flagArgs[0].toUpperCase()));
            if (flagArgs[1].equals("++") || flagArgs[1].equals("+")) {
                scriptEntry.addObject("action", FlagManager.Action.INCREASE);
                scriptEntry.addObject("value", new Element(1));
            } else if (flagArgs[1].equals("--") || flagArgs[1].equals("-")) {
                scriptEntry.addObject("action", FlagManager.Action.DECREASE);
                scriptEntry.addObject("value", new Element(1));
            } else if (flagArgs[1].equals("!")) {
                scriptEntry.addObject("action", FlagManager.Action.DELETE);
                scriptEntry.addObject("value", Element.FALSE);
            } else if (flagArgs[1].equals("<-")) {
                scriptEntry.addObject("action", FlagManager.Action.REMOVE);
                scriptEntry.addObject("value", Element.FALSE);
            } else {
                // No ACTION, we're just setting a value...
                scriptEntry.addObject("action", FlagManager.Action.SET_VALUE);
                scriptEntry.addObject("value", new Element(flagArgs[1]));
            }
        } else // Check for flag_name:action:value
        if (!scriptEntry.hasObject("flag_name") && arg.raw_value.split(":", 3).length == 3) {
            String[] flagArgs = arg.raw_value.split(":", 3);
            scriptEntry.addObject("flag_name", new Element(flagArgs[0].toUpperCase()));
            if (flagArgs[1].equals("->")) {
                scriptEntry.addObject("action", FlagManager.Action.INSERT);
            } else if (flagArgs[1].equals("<-")) {
                scriptEntry.addObject("action", FlagManager.Action.REMOVE);
            } else if (flagArgs[1].equals("||") || flagArgs[1].equals("|")) {
                scriptEntry.addObject("action", FlagManager.Action.SPLIT);
            } else if (flagArgs[1].equals("++") || flagArgs[1].equals("+")) {
                scriptEntry.addObject("action", FlagManager.Action.INCREASE);
            } else if (flagArgs[1].equals("--") || flagArgs[1].equals("-")) {
                scriptEntry.addObject("action", FlagManager.Action.DECREASE);
            } else if (flagArgs[1].equals("**") || flagArgs[1].equals("*")) {
                scriptEntry.addObject("action", FlagManager.Action.MULTIPLY);
            } else if (flagArgs[1].equals("//") || flagArgs[1].equals("/")) {
                scriptEntry.addObject("action", FlagManager.Action.DIVIDE);
            } else {
                scriptEntry.addObject("action", FlagManager.Action.SET_VALUE);
                scriptEntry.addObject("value", new Element(arg.raw_value.split(":", 2)[1]));
                continue;
            }
            scriptEntry.addObject("value", new Element(flagArgs[2]));
        } else {
            arg.reportUnhandled();
        }
    }
    // Set defaults
    if (!specified_target) {
        scriptEntry.defaultObject("flag_target", ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer());
    }
    // Check required arguments
    if (!scriptEntry.hasObject("action")) {
        throw new InvalidArgumentsException("Must specify a flag action or value.");
    }
    if (!scriptEntry.hasObject("flag_target")) {
        throw new InvalidArgumentsException("Must specify a flag target!");
    }
}
Also used : net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) Element(net.aufdemrand.denizencore.objects.Element) Duration(net.aufdemrand.denizencore.objects.Duration) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 4 with InvalidArgumentsException

use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.

the class TeamCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    String name = null;
    String prefix = null;
    String suffix = null;
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (arg.matchesPrefix("id") && !scriptEntry.hasObject("id")) {
            scriptEntry.addObject("id", arg.asElement());
        } else if (arg.matchesPrefix("name") && !scriptEntry.hasObject("name")) {
            Element nameElement = arg.asElement();
            name = nameElement.asString();
            scriptEntry.addObject("name", nameElement);
        } else if (arg.matchesPrefix("add") && !scriptEntry.hasObject("add")) {
            scriptEntry.addObject("add", arg.asType(dList.class));
        } else if (arg.matchesPrefix("remove") && !scriptEntry.hasObject("remove")) {
            scriptEntry.addObject("remove", arg.asType(dList.class));
        } else if (arg.matchesPrefix("prefix") && !scriptEntry.hasObject("prefix")) {
            Element prefixElement = arg.asElement();
            prefix = prefixElement.asString();
            scriptEntry.addObject("prefix", prefixElement);
        } else if (arg.matchesPrefix("suffix") && !scriptEntry.hasObject("suffix")) {
            Element suffixElement = arg.asElement();
            suffix = suffixElement.asString();
            scriptEntry.addObject("suffix", suffixElement);
        }
    }
    if (name == null || name.length() == 0 || name.length() > 16) {
        throw new InvalidArgumentsException("Must specify a team name between 1 and 16 characters!");
    }
    if (!scriptEntry.hasObject("add") && !scriptEntry.hasObject("remove") && !scriptEntry.hasObject("prefix") && !scriptEntry.hasObject("suffix")) {
        throw new InvalidArgumentsException("Must specify something to do with the team!");
    }
    if ((prefix != null && prefix.length() > 16) || (suffix != null && suffix.length() > 16)) {
        throw new InvalidArgumentsException("Prefixes and suffixes must be 16 characters or less!");
    }
    scriptEntry.defaultObject("id", new Element("main"));
}
Also used : net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 5 with InvalidArgumentsException

use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.

the class PlaySoundCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    // Iterate through arguments
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("locations") && !scriptEntry.hasObject("entities") && arg.matchesArgumentList(dLocation.class)) {
            scriptEntry.addObject("locations", arg.asType(dList.class).filter(dLocation.class));
        } else if (!scriptEntry.hasObject("locations") && !scriptEntry.hasObject("entities") && arg.matchesArgumentList(dPlayer.class)) {
            scriptEntry.addObject("entities", arg.asType(dList.class).filter(dPlayer.class));
        } else if (!scriptEntry.hasObject("volume") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("volume, v")) {
            scriptEntry.addObject("volume", arg.asElement());
        } else if (!scriptEntry.hasObject("pitch") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("pitch, p")) {
            scriptEntry.addObject("pitch", arg.asElement());
        } else if (!scriptEntry.hasObject("sound") && arg.matchesPrimitive(aH.PrimitiveType.String)) {
            scriptEntry.addObject("sound", arg.asElement());
        } else if (!scriptEntry.hasObject("custom") && arg.matches("custom")) {
            scriptEntry.addObject("custom", Element.TRUE);
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("sound")) {
        throw new InvalidArgumentsException("Missing sound argument!");
    }
    if (!scriptEntry.hasObject("locations") && !scriptEntry.hasObject("entities")) {
        throw new InvalidArgumentsException("Missing location argument!");
    }
    scriptEntry.defaultObject("volume", new Element(1));
    scriptEntry.defaultObject("pitch", new Element(1));
    scriptEntry.defaultObject("custom", Element.FALSE);
}
Also used : net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Aggregations

InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)28 net.aufdemrand.denizencore.objects.aH (net.aufdemrand.denizencore.objects.aH)28 Element (net.aufdemrand.denizencore.objects.Element)25 BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)16 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)14 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)9 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)7 Duration (net.aufdemrand.denizencore.objects.Duration)6 ArrayList (java.util.ArrayList)3 FormatScriptContainer (net.aufdemrand.denizen.scripts.containers.core.FormatScriptContainer)3 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)2 net.aufdemrand.denizen.objects.dMaterial (net.aufdemrand.denizen.objects.dMaterial)2 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)2 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)2 ParticleHelper (net.aufdemrand.denizen.nms.abstracts.ParticleHelper)1 Effect (net.aufdemrand.denizen.nms.interfaces.Effect)1 Particle (net.aufdemrand.denizen.nms.interfaces.Particle)1 net.aufdemrand.denizen.objects.dInventory (net.aufdemrand.denizen.objects.dInventory)1 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)1 Statistic (org.bukkit.Statistic)1