Search in sources :

Example 26 with InvalidArgumentsException

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

the class SidebarCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    Action action = Action.SET;
    for (aH.Argument arg : aH.interpret(scriptEntry.getOriginalArguments())) {
        if (!scriptEntry.hasObject("action") && arg.matchesEnum(Action.values())) {
            action = Action.valueOf(arg.getValue().toUpperCase());
        } else if (!scriptEntry.hasObject("title") && arg.matchesPrefix("title", "t", "objective", "obj", "o")) {
            scriptEntry.addObject("title", arg.asElement());
        } else if (!scriptEntry.hasObject("lines") && arg.matchesPrefix("lines", "line", "l")) {
            scriptEntry.addObject("lines", arg.asElement());
        } else if (!scriptEntry.hasObject("value") && arg.matchesPrefix("value", "values", "val", "v")) {
            scriptEntry.addObject("value", arg.asElement());
        } else if (!scriptEntry.hasObject("increment") && arg.matchesPrefix("increment", "inc", "i")) {
            scriptEntry.addObject("increment", arg.asElement());
        } else if (!scriptEntry.hasObject("start") && arg.matchesPrefix("start", "s")) {
            scriptEntry.addObject("start", arg.asElement());
        } else if (!scriptEntry.hasObject("players") && arg.matchesPrefix("players", "player", "p")) {
            scriptEntry.addObject("players", arg.asElement());
        } else if (!scriptEntry.hasObject("per_player") && arg.matches("per_player")) {
            scriptEntry.addObject("per_player", new Element(true));
        }
    }
    if (action == Action.ADD && !scriptEntry.hasObject("value")) {
        throw new InvalidArgumentsException("Must specify value(s) for that action!");
    }
    if (action == Action.SET && !scriptEntry.hasObject("value") && !scriptEntry.hasObject("title") && !scriptEntry.hasObject("increment") && !scriptEntry.hasObject("start")) {
        throw new InvalidArgumentsException("Must specify at least one of: value(s), title, increment, or start for that action!");
    }
    if (action == Action.SET && scriptEntry.hasObject("lines") && !scriptEntry.hasObject("value")) {
        throw new InvalidArgumentsException("Must specify value(s) when setting lines!");
    }
    scriptEntry.addObject("action", new Element(action.name()));
    BukkitScriptEntryData entryData = (BukkitScriptEntryData) scriptEntry.entryData;
    scriptEntry.defaultObject("per_player", new Element(false)).defaultObject("players", new Element(entryData.hasPlayer() ? entryData.getPlayer().identify() : "li@"));
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) Element(net.aufdemrand.denizencore.objects.Element) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 27 with InvalidArgumentsException

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

the class PoseCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    // Parse Arguments
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (arg.matches("add", "assume", "remove")) {
            scriptEntry.addObject("action", Action.valueOf(arg.getValue().toUpperCase()));
        } else if (arg.matchesPrefix("id")) {
            scriptEntry.addObject("pose_id", arg.getValue());
        } else if (arg.matches("player")) {
            scriptEntry.addObject("target", TargetType.PLAYER);
        } else if (arg.matchesArgumentType(dLocation.class)) {
            scriptEntry.addObject("pose_loc", arg.asType(dLocation.class));
        }
    }
    // Even if the target is a player, this command requires an NPC to get the pose from.
    if (!((BukkitScriptEntryData) scriptEntry.entryData).hasNPC()) {
        throw new InvalidArgumentsException("This command requires an NPC!");
    }
    // It also requires a pose ID
    if (!scriptEntry.hasObject("pose_id")) {
        throw new InvalidArgumentsException("No ID specified!");
    }
    // Set default objects
    scriptEntry.defaultObject("target", TargetType.NPC);
    scriptEntry.defaultObject("action", Action.ASSUME);
    // from players, so only allow ASSUME.
    if (scriptEntry.getObject("target") == TargetType.PLAYER) {
        if (scriptEntry.getObject("action") != Action.ASSUME) {
            throw new InvalidArgumentsException("You cannot add or remove poses from a player.");
        } else if (!((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer()) {
            throw new InvalidArgumentsException("This command requires a linked player!");
        }
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 28 with InvalidArgumentsException

use of net.aufdemrand.denizencore.exceptions.InvalidArgumentsException 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

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