Search in sources :

Example 21 with InvalidArgumentsException

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

the class ChatCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    boolean specified_targets = false;
    boolean specified_talker = false;
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        // Default target is the attached Player, if none specified otherwise.
        if (arg.matchesPrefix("target", "targets", "t")) {
            if (arg.matchesArgumentList(dEntity.class)) {
                scriptEntry.addObject("targets", arg.asType(dList.class));
            }
            specified_targets = true;
        } else if (arg.matches("no_target")) {
            scriptEntry.addObject("targets", new dList());
        } else // Default talker is the attached NPC, if none specified otherwise.
        if (arg.matchesPrefix("talker", "talkers")) {
            if (arg.matchesArgumentList(dEntity.class)) {
                scriptEntry.addObject("talkers", arg.asType(dList.class));
            }
            specified_talker = true;
        } else if (arg.matchesPrefix("range", "r")) {
            if (arg.matchesPrimitive(aH.PrimitiveType.Double)) {
                scriptEntry.addObject("range", arg.asElement());
            }
        } else if (!scriptEntry.hasObject("message")) {
            scriptEntry.addObject("message", new Element(arg.raw_value));
        } else {
            arg.reportUnhandled();
        }
    }
    // Add default recipient as the attached Player if no recipients set otherwise
    if (!scriptEntry.hasObject("targets") && ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() && !specified_targets) {
        scriptEntry.defaultObject("targets", new dList(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().identify()));
    }
    // Add default talker as the attached NPC if no recipients set otherwise
    if (!scriptEntry.hasObject("talkers") && ((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() && !specified_talker) {
        scriptEntry.defaultObject("talkers", new dList(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().identify()));
    }
    // Verify essential fields are set
    if (!scriptEntry.hasObject("targets")) {
        throw new InvalidArgumentsException("Must specify valid targets!");
    }
    if (!scriptEntry.hasObject("talkers")) {
        throw new InvalidArgumentsException("Must specify valid talkers!");
    }
    if (!scriptEntry.hasObject("message")) {
        throw new InvalidArgumentsException("Must specify a message!");
    }
    scriptEntry.defaultObject("range", new Element(Settings.chatBystandersRange()));
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) 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) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 22 with InvalidArgumentsException

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

the class ListenCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    List<aH.Argument> arguments = new ArrayList<aH.Argument>();
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        // <action>
        if (!scriptEntry.hasObject("action") && arg.matchesEnum(Action.values())) {
            scriptEntry.addObject("action", arg.asElement());
        } else // <id:name>
        if (!scriptEntry.hasObject("id") && arg.matchesPrefix("id", "i")) {
            scriptEntry.addObject("id", arg.asElement());
        } else // <script>
        if (!scriptEntry.hasObject("finish_script") && arg.matchesPrefix("script") && arg.matchesArgumentType(dScript.class)) {
            scriptEntry.addObject("finish_script", arg.asType(dScript.class));
        } else // <type>
        if (!scriptEntry.hasObject("type")) {
            scriptEntry.addObject("type", arg.asElement());
        }
        arguments.add(arg);
    }
    // Set defaults
    scriptEntry.defaultObject("action", new Element("new"));
    scriptEntry.defaultObject("id", new Element(UUID.randomUUID().toString()));
    // Check for type (if using NEW) -- it's required
    if (!scriptEntry.hasObject("type") && scriptEntry.getElement("action").asString().equalsIgnoreCase("new")) {
        throw new InvalidArgumentsException("Must specify a listener type!");
    }
    // Player listeners require a player!
    if (((BukkitScriptEntryData) scriptEntry.entryData).getPlayer() == null) {
        throw new InvalidArgumentsException("Must specify a player!");
    }
    // Add arguments
    scriptEntry.addObject("args", arguments);
}
Also used : net.aufdemrand.denizencore.objects.dScript(net.aufdemrand.denizencore.objects.dScript) net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) Element(net.aufdemrand.denizencore.objects.Element) ArrayList(java.util.ArrayList) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 23 with InvalidArgumentsException

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

the class ExplodeCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    // Iterate through arguments
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(dLocation.class)) {
            scriptEntry.addObject("location", arg.asType(dLocation.class));
        } else if (!scriptEntry.hasObject("power") && arg.matchesPrimitive(aH.PrimitiveType.Float) && arg.matchesPrefix("power", "p")) {
            scriptEntry.addObject("power", arg.asElement());
        } else if (!scriptEntry.hasObject("breakblocks") && arg.matches("breakblocks")) {
            scriptEntry.addObject("breakblocks", "");
        } else if (!scriptEntry.hasObject("fire") && arg.matches("fire")) {
            scriptEntry.addObject("fire", "");
        } else {
            arg.reportUnhandled();
        }
    }
    // Use default values if necessary
    scriptEntry.defaultObject("power", new Element(1.0));
    scriptEntry.defaultObject("location", ((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() ? ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getLocation() : null, ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getLocation() : null);
    if (!scriptEntry.hasObject("location")) {
        throw new InvalidArgumentsException("Missing location argument!");
    }
}
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.dLocation(net.aufdemrand.denizen.objects.dLocation) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 24 with InvalidArgumentsException

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

the class NarrateCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    if (scriptEntry.getArguments().size() > 4) {
        // TODO: Use this more often!
        throw new InvalidArgumentsException("Too many arguments! Did you forget a 'quote'?");
    }
    // Iterate through arguments
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("format") && 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);
        } else // Add players to target list
        if (!scriptEntry.hasObject("targets") && arg.matchesPrefix("target", "targets", "t")) {
            scriptEntry.addObject("targets", arg.asType(dList.class).filter(dPlayer.class));
        } else // Use raw_value as to not accidentally strip a value before any :'s.
        if (!scriptEntry.hasObject("text")) {
            scriptEntry.addObject("text", new Element(TagManager.cleanOutputFully(arg.raw_value)));
        } else {
            arg.reportUnhandled();
        }
    }
    // to the targets
    if (!scriptEntry.hasObject("targets")) {
        scriptEntry.addObject("targets", (((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer()) : null));
    }
    if (!scriptEntry.hasObject("text")) {
        throw new InvalidArgumentsException("Missing any text!");
    }
}
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.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 25 with InvalidArgumentsException

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

the class ShowFakeCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    dList locations = new dList();
    dList entities = new dList();
    boolean added_entities = false;
    // Iterate through arguments
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (arg.matchesPrefix("to", "players")) {
            for (String entity : dList.valueOf(arg.getValue())) {
                if (dPlayer.matches(entity)) {
                    entities.add(entity);
                }
            }
            // TODO: handle lists properly
            added_entities = true;
        } else if (arg.matchesArgumentList(dMaterial.class)) {
            scriptEntry.addObject("materials", arg.asType(dList.class));
        } else if (locations.isEmpty() && arg.matchesArgumentType(dList.class)) {
            for (String item : dList.valueOf(arg.getValue())) {
                if (dLocation.matches(item)) {
                    locations.add(item);
                }
            }
        } else if (locations.isEmpty() && arg.matchesArgumentType(dLocation.class)) {
            locations.add(arg.getValue());
        } else if (arg.matchesPrefix("d", "duration") && arg.matchesArgumentType(Duration.class)) {
            scriptEntry.addObject("duration", arg.asType(Duration.class));
        } else if (arg.matches("cancel")) {
            scriptEntry.addObject("cancel", new Element(true));
        } else {
            arg.reportUnhandled();
        }
    }
    if (entities.isEmpty() && ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer()) {
        entities.add(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().identify());
    }
    if (locations.isEmpty()) {
        throw new InvalidArgumentsException("Must specify at least one valid location!");
    }
    if (!added_entities && (!((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() || !((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().isOnline())) {
        throw new InvalidArgumentsException("Must have a valid, online player attached!");
    }
    if (entities.isEmpty() && added_entities) {
        throw new InvalidArgumentsException("Must specify valid targets!");
    }
    if (!scriptEntry.hasObject("materials") && !scriptEntry.hasObject("cancel")) {
        throw new InvalidArgumentsException("Must specify valid material(s)!");
    }
    scriptEntry.addObject("entities", entities);
    scriptEntry.addObject("locations", locations);
    scriptEntry.defaultObject("duration", new Duration(10)).defaultObject("cancel", new Element(false));
}
Also used : net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) 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