Search in sources :

Example 51 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData 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 52 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData 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 53 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class FireworkCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    // Initialize necessary fields
    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("type") && arg.matches("random")) {
            scriptEntry.addObject("type", new Element(FireworkEffect.Type.values()[CoreUtilities.getRandom().nextInt(FireworkEffect.Type.values().length)].name()));
        } else if (!scriptEntry.hasObject("type") && arg.matchesEnum(FireworkEffect.Type.values())) {
            scriptEntry.addObject("type", arg.asElement());
        } else if (!scriptEntry.hasObject("power") && arg.matchesPrimitive(aH.PrimitiveType.Integer)) {
            scriptEntry.addObject("power", arg.asElement());
        } else if (!scriptEntry.hasObject("flicker") && arg.matches("flicker")) {
            scriptEntry.addObject("flicker", "");
        } else if (!scriptEntry.hasObject("trail") && arg.matches("trail")) {
            scriptEntry.addObject("trail", "");
        } else if (!scriptEntry.hasObject("primary") && arg.matchesPrefix("primary") && arg.matchesArgumentList(dColor.class)) {
            scriptEntry.addObject("primary", arg.asType(dList.class).filter(dColor.class));
        } else if (!scriptEntry.hasObject("fade") && arg.matchesPrefix("fade") && arg.matchesArgumentList(dColor.class)) {
            scriptEntry.addObject("fade", arg.asType(dList.class).filter(dColor.class));
        } else {
            arg.reportUnhandled();
        }
    }
    // Use the NPC or player's locations as the location if one is not specified
    scriptEntry.defaultObject("location", ((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() ? ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getLocation() : null, ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getLocation() : null);
    scriptEntry.defaultObject("type", new Element("ball"));
    scriptEntry.defaultObject("power", new Element(1));
    scriptEntry.defaultObject("primary", Arrays.asList(dColor.valueOf("yellow")));
}
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.dColor(net.aufdemrand.denizen.objects.dColor) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 54 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData 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 55 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData 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

BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)61 Element (net.aufdemrand.denizencore.objects.Element)38 InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)19 net.aufdemrand.denizencore.objects.aH (net.aufdemrand.denizencore.objects.aH)18 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)18 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)13 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)13 Duration (net.aufdemrand.denizencore.objects.Duration)9 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)8 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)8 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)6 ScriptEntry (net.aufdemrand.denizencore.scripts.ScriptEntry)6 Player (org.bukkit.entity.Player)6 ArrayList (java.util.ArrayList)5 AssignmentTrait (net.aufdemrand.denizen.npc.traits.AssignmentTrait)5 net.aufdemrand.denizen.objects.dInventory (net.aufdemrand.denizen.objects.dInventory)5 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)5 CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)5 net.aufdemrand.denizencore.objects.dObject (net.aufdemrand.denizencore.objects.dObject)5 EventHandler (org.bukkit.event.EventHandler)5