Search in sources :

Example 6 with InvalidArgumentsException

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

the class SwitchCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("locations") && arg.matchesArgumentList(dLocation.class)) {
            scriptEntry.addObject("locations", arg.asType(dList.class));
        } else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(Duration.class)) {
            scriptEntry.addObject("duration", arg.asType(Duration.class));
        } else if (!scriptEntry.hasObject("state") && arg.matchesEnum(SwitchState.values())) {
            scriptEntry.addObject("switchstate", new Element(arg.getValue().toUpperCase()));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("locations")) {
        throw new InvalidArgumentsException("Must specify a location!");
    }
    scriptEntry.defaultObject("duration", new Duration(0));
    scriptEntry.defaultObject("switchstate", new Element("TOGGLE"));
}
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) Duration(net.aufdemrand.denizencore.objects.Duration) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 7 with InvalidArgumentsException

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

the class StatisticCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    boolean specified_players = false;
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("action") && arg.matchesEnum(Action.values())) {
            scriptEntry.addObject("action", arg.asElement());
        } else if (arg.matchesPrefix("players") && !scriptEntry.hasObject("players") && arg.matchesArgumentList(dPlayer.class)) {
            scriptEntry.addObject("players", arg.asType(dList.class));
            specified_players = true;
        } else if (!scriptEntry.hasObject("statistic") && arg.matchesEnum(Statistic.values())) {
            scriptEntry.addObject("statistic", arg.asElement());
        } else if (!scriptEntry.hasObject("amount") && arg.matchesPrimitive(aH.PrimitiveType.Integer)) {
            scriptEntry.addObject("amount", arg.asElement());
        } else if (arg.matchesPrefix("qualifier", "q") && !scriptEntry.hasObject("material") && !scriptEntry.hasObject("entity")) {
            if (arg.matchesArgumentType(dMaterial.class)) {
                scriptEntry.addObject("material", arg.asType(dMaterial.class));
            } else if (arg.matchesArgumentType(dEntity.class)) {
                scriptEntry.addObject("entity", arg.asType(dEntity.class));
            }
        }
    }
    if (!scriptEntry.hasObject("action")) {
        throw new InvalidArgumentsException("Must specify a valid action!");
    }
    if (!scriptEntry.hasObject("statistic")) {
        throw new InvalidArgumentsException("Must specify a valid Statistic!");
    }
    if (!scriptEntry.hasObject("amount")) {
        scriptEntry.addObject("amount", new Element(1));
    }
    Statistic.Type type = Statistic.valueOf(scriptEntry.getElement("statistic").asString().toUpperCase()).getType();
    if (type != Statistic.Type.UNTYPED) {
        if ((type == Statistic.Type.BLOCK || type == Statistic.Type.ITEM) && !scriptEntry.hasObject("material")) {
            throw new InvalidArgumentsException("Must specify a valid " + type.name() + " MATERIAL!");
        } else if (type == Statistic.Type.ENTITY && !scriptEntry.hasObject("entity")) {
            throw new InvalidArgumentsException("Must specify a valid ENTITY!");
        }
    }
    if (!scriptEntry.hasObject("players") && ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() && !specified_players) {
        scriptEntry.addObject("players", new dList(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().identify()));
    }
    if (!scriptEntry.hasObject("players")) {
        throw new InvalidArgumentsException("Must specify valid players!");
    }
}
Also used : net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) Statistic(org.bukkit.Statistic) 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) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 8 with InvalidArgumentsException

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

the class YamlCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    boolean isSet = false;
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("action") && arg.matchesPrefix("LOAD")) {
            scriptEntry.addObject("action", new Element("LOAD"));
            scriptEntry.addObject("filename", arg.asElement());
        } else if (!scriptEntry.hasObject("action") && arg.matchesPrefix("SAVEFILE", "FILESAVE")) {
            scriptEntry.addObject("action", new Element("SAVE"));
            scriptEntry.addObject("filename", arg.asElement());
        } else if (!scriptEntry.hasObject("action") && arg.matches("CREATE")) {
            scriptEntry.addObject("action", new Element("CREATE"));
        } else if (!scriptEntry.hasObject("action") && arg.matches("SET")) {
            scriptEntry.addObject("action", new Element("SET"));
            isSet = true;
        } else if (!scriptEntry.hasObject("action") && arg.matches("UNLOAD")) {
            scriptEntry.addObject("action", new Element("UNLOAD"));
        } else if (!scriptEntry.hasObject("action") && arg.matchesPrefix("WRITE")) {
            dB.echoError(scriptEntry.getResidingQueue(), "YAML write is deprecated, use YAML set!");
            scriptEntry.addObject("action", new Element("WRITE"));
            scriptEntry.addObject("key", arg.asElement());
        } else if (!scriptEntry.hasObject("value") && arg.matchesPrefix("VALUE")) {
            if (arg.matchesArgumentType(dList.class)) {
                scriptEntry.addObject("value", arg.asType(dList.class));
            } else {
                scriptEntry.addObject("value", arg.asElement());
            }
        } else if (!scriptEntry.hasObject("id") && arg.matchesPrefix("ID")) {
            scriptEntry.addObject("id", arg.asElement());
        } else if (!scriptEntry.hasObject("split") && arg.matches("split_list")) {
            scriptEntry.addObject("split", new Element("true"));
        } else if (!scriptEntry.hasObject("fix_formatting") && arg.matches("fix_formatting")) {
            scriptEntry.addObject("fix_formatting", new Element("true"));
        } else // Check for key:value/action
        if (isSet && !scriptEntry.hasObject("value") && arg.raw_value.split(":", 3).length == 2) {
            String[] flagArgs = arg.raw_value.split(":", 2);
            scriptEntry.addObject("key", new Element(flagArgs[0]));
            if (flagArgs[1].equals("++") || flagArgs[1].equals("+")) {
                scriptEntry.addObject("yaml_action", YAML_Action.INCREASE);
                scriptEntry.addObject("value", new Element(1));
            } else if (flagArgs[1].equals("--") || flagArgs[1].equals("-")) {
                scriptEntry.addObject("yaml_action", YAML_Action.DECREASE);
                scriptEntry.addObject("value", new Element(1));
            } else if (flagArgs[1].equals("!")) {
                scriptEntry.addObject("yaml_action", YAML_Action.DELETE);
                scriptEntry.addObject("value", Element.FALSE);
            } else if (flagArgs[1].equals("<-")) {
                scriptEntry.addObject("yaml_action", YAML_Action.REMOVE);
                scriptEntry.addObject("value", Element.FALSE);
            } else {
                // No ACTION, we're just setting a value...
                scriptEntry.addObject("yaml_action", YAML_Action.SET_VALUE);
                scriptEntry.addObject("value", new Element(flagArgs[1]));
            }
        } else // Check for key:action:value
        if (isSet && !scriptEntry.hasObject("value") && arg.raw_value.split(":", 3).length == 3) {
            String[] flagArgs = arg.raw_value.split(":", 3);
            scriptEntry.addObject("key", new Element(flagArgs[0]));
            if (flagArgs[1].equals("->")) {
                scriptEntry.addObject("yaml_action", YAML_Action.INSERT);
            } else if (flagArgs[1].equals("<-")) {
                scriptEntry.addObject("yaml_action", YAML_Action.REMOVE);
            } else if (flagArgs[1].equals("||") || flagArgs[1].equals("|")) {
                scriptEntry.addObject("yaml_action", YAML_Action.SPLIT);
            } else if (flagArgs[1].equals("++") || flagArgs[1].equals("+")) {
                scriptEntry.addObject("yaml_action", YAML_Action.INCREASE);
            } else if (flagArgs[1].equals("--") || flagArgs[1].equals("-")) {
                scriptEntry.addObject("yaml_action", YAML_Action.DECREASE);
            } else if (flagArgs[1].equals("**") || flagArgs[1].equals("*")) {
                scriptEntry.addObject("yaml_action", YAML_Action.MULTIPLY);
            } else if (flagArgs[1].equals("//") || flagArgs[1].equals("/")) {
                scriptEntry.addObject("yaml_action", YAML_Action.DIVIDE);
            } else {
                scriptEntry.addObject("yaml_action", YAML_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();
        }
    }
    if (!scriptEntry.hasObject("id")) {
        throw new InvalidArgumentsException("Must specify an id!");
    }
    if (!scriptEntry.hasObject("action")) {
        throw new InvalidArgumentsException("Must specify an action!");
    }
    if (!scriptEntry.hasObject("key") && scriptEntry.getElement("action").asString().equalsIgnoreCase("write")) {
        throw new InvalidArgumentsException("Must specify a key!");
    }
    scriptEntry.defaultObject("value", new Element(""));
    scriptEntry.defaultObject("fix_formatting", new Element("false"));
}
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 9 with InvalidArgumentsException

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

the class CastCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    // Iterate through arguments
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("remove") && arg.matches("remove", "cancel")) {
            scriptEntry.addObject("remove", new Element(true));
        } else if (!scriptEntry.hasObject("ambient") && arg.matches("no_ambient")) {
            scriptEntry.addObject("ambient", new Element(false));
        } else if (!scriptEntry.hasObject("show_particles") && arg.matches("hide_particles")) {
            scriptEntry.addObject("show_particles", new Element(false));
        } else if (!scriptEntry.hasObject("duration") && arg.matchesPrefix("duration", "d") && arg.matchesArgumentType(Duration.class)) {
            scriptEntry.addObject("duration", arg.asType(Duration.class));
        } else if (!scriptEntry.hasObject("amplifier") && arg.matchesPrefix("power", "p", "amplifier", "a") && arg.matchesPrimitive(aH.PrimitiveType.Double)) {
            scriptEntry.addObject("amplifier", arg.asElement());
        } else if (!scriptEntry.hasObject("effect") && PotionEffectType.getByName(arg.asElement().asString()) != null) {
            scriptEntry.addObject("effect", PotionEffectType.getByName(arg.asElement().asString()));
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(dEntity.class)) {
            scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class));
        } else {
            arg.reportUnhandled();
        }
    }
    // No targets specified, let's use defaults if available
    scriptEntry.defaultObject("entities", (((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getDenizenEntity()) : null), (((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getDenizenEntity()) : null));
    // No potion specified? Problem!
    if (!scriptEntry.hasObject("effect")) {
        throw new InvalidArgumentsException("Must specify a valid PotionType!");
    }
    scriptEntry.defaultObject("duration", new Duration(60));
    scriptEntry.defaultObject("amplifier", new Element(1));
    scriptEntry.defaultObject("remove", new Element(false));
    scriptEntry.defaultObject("show_particles", new Element(true));
    scriptEntry.defaultObject("ambient", new Element(true));
}
Also used : 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 10 with InvalidArgumentsException

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

the class RotateCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("cancel") && (arg.matches("cancel") || arg.matches("stop"))) {
            scriptEntry.addObject("cancel", new Element("true"));
        } else if (!scriptEntry.hasObject("infinite") && arg.matches("infinite")) {
            scriptEntry.addObject("infinite", new Element("true"));
        } else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(Duration.class) && arg.matchesPrefix("duration", "d")) {
            scriptEntry.addObject("duration", arg.asType(Duration.class));
        } else if (!scriptEntry.hasObject("frequency") && arg.matchesArgumentType(Duration.class) && arg.matchesPrefix("frequency", "f")) {
            scriptEntry.addObject("frequency", arg.asType(Duration.class));
        } else if (!scriptEntry.hasObject("yaw") && arg.matchesPrefix("yaw", "y", "rotation", "r") && arg.matchesPrimitive(aH.PrimitiveType.Float)) {
            scriptEntry.addObject("yaw", arg.asElement());
        } else if (!scriptEntry.hasObject("pitch") && arg.matchesPrefix("pitch", "p", "tilt", "t") && arg.matchesPrimitive(aH.PrimitiveType.Float)) {
            scriptEntry.addObject("pitch", arg.asElement());
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(dEntity.class)) {
            scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class));
        } else {
            arg.reportUnhandled();
        }
    }
    // Use the NPC or the Player as the default entity
    scriptEntry.defaultObject("entities", (((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getDenizenEntity()) : null), (((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getDenizenEntity()) : null));
    scriptEntry.defaultObject("yaw", new Element(10));
    scriptEntry.defaultObject("pitch", new Element(0));
    scriptEntry.defaultObject("duration", new Duration(20));
    scriptEntry.defaultObject("frequency", Duration.valueOf("1t"));
    // Check to make sure required arguments have been filled
    if (!scriptEntry.hasObject("entities")) {
        throw new InvalidArgumentsException("Must specify entity/entities!");
    }
}
Also used : 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)

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