Search in sources :

Example 6 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.

the class EquipCommand method parseArgs.

// <--[command]
// @Name Equip
// @Syntax equip (<entity>|...) (hand:<item>) (offhand:<item>) (head:<item>) (chest:<item>) (legs:<item>) (boots:<item>) (saddle:<item>) (horse_armor:<item>)
// @Required 1
// @Maximum 9
// @Short Equips items and armor on a list of entities.
// @Group entity
// 
// @Description
// This command equips an item or armor to an entity or list of entities to the specified slot(s).
// Set the item to 'air' to unequip any slot.
// 
// @Tags
// <EntityTag.equipment>
// <InventoryTag.equipment>
// 
// @Usage
// Use to equip a stone block on the player's head.
// - equip <player> head:stone
// 
// @Usage
// Use to equip an iron helmet on two defined players.
// - equip <[player]>|<[someplayer]> head:iron_helmet
// 
// @Usage
// Use to unequip all armor off the player.
// - equip <player> head:air chest:air legs:air boots:air
// 
// @Usage
// Use to equip a saddle on the horse the player is riding.
// - equip <player.vehicle> saddle:saddle
// 
// @Usage
// Use to equip a saddle on all nearby pigs.
// - equip <player.location.find_entities[pig].within[10]> saddle:saddle
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    Map<String, ItemTag> equipment = new HashMap<>();
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
            scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
        } else if (arg.matchesArgumentType(ItemTag.class) && arg.matchesPrefix("head", "helmet")) {
            equipment.put("head", ItemTag.valueOf(arg.getValue(), scriptEntry.getContext()));
        } else if (arg.matchesArgumentType(ItemTag.class) && arg.matchesPrefix("chest", "chestplate")) {
            equipment.put("chest", ItemTag.valueOf(arg.getValue(), scriptEntry.getContext()));
        } else if (arg.matchesArgumentType(ItemTag.class) && arg.matchesPrefix("legs", "leggings")) {
            equipment.put("legs", ItemTag.valueOf(arg.getValue(), scriptEntry.getContext()));
        } else if (arg.matchesArgumentType(ItemTag.class) && arg.matchesPrefix("boots", "feet")) {
            equipment.put("boots", ItemTag.valueOf(arg.getValue(), scriptEntry.getContext()));
        } else if (arg.matchesArgumentType(ItemTag.class) && arg.matchesPrefix("saddle")) {
            equipment.put("saddle", ItemTag.valueOf(arg.getValue(), scriptEntry.getContext()));
        } else if (arg.matchesArgumentType(ItemTag.class) && arg.matchesPrefix("horse_armor", "horse_armour")) {
            equipment.put("horse_armor", ItemTag.valueOf(arg.getValue(), scriptEntry.getContext()));
        } else if (arg.matchesArgumentType(ItemTag.class) && arg.matchesPrefix("offhand")) {
            equipment.put("offhand", ItemTag.valueOf(arg.getValue(), scriptEntry.getContext()));
        } else // Default to item in hand if no prefix is used
        if (arg.matchesArgumentType(ItemTag.class)) {
            equipment.put("hand", ItemTag.valueOf(arg.getValue(), scriptEntry.getContext()));
        } else if (arg.matches("player") && Utilities.entryHasPlayer(scriptEntry)) {
            // Player arg for compatibility with old scripts
            scriptEntry.addObject("entities", Collections.singletonList(Utilities.getEntryPlayer(scriptEntry).getDenizenEntity()));
        } else {
            arg.reportUnhandled();
        }
    }
    if (equipment.isEmpty()) {
        throw new InvalidArgumentsException("Must specify equipment!");
    }
    scriptEntry.addObject("equipment", equipment);
    scriptEntry.defaultObject("entities", Utilities.entryDefaultEntityList(scriptEntry, false));
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) EntityTag(com.denizenscript.denizen.objects.EntityTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 7 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.

the class FeedCommand method parseArgs.

// <--[command]
// @Name Feed
// @Syntax feed (<entity>) (amount:<#>) (saturation:<#.#>)
// @Required 0
// @Maximum 3
// @Short Feed the player or npc.
// @Group entity
// 
// @Description
// Feeds the player or npc specified.
// 
// By default targets the player attached to the script queue and feeds a full amount.
// 
// Accepts the 'amount:' argument, which is in half bar increments, up to a total of 20 food points.
// The amount may be negative, to cause hunger instead of satiating it.
// 
// You can optionally also specify an amount to change the saturation by.
// By default, the saturation change will be the same as the food level change.
// This is also up to a total of 20 points. This value may also be negative.
// 
// Also accepts the 'target:<entity>' argument to specify the entity which will be fed the amount.
// 
// @Tags
// <PlayerTag.food_level>
// <PlayerTag.formatted_food_level>
// <PlayerTag.saturation>
// 
// @Usage
// Use to feed the player for 5 foodpoints (or 2.5 bars).
// - feed amount:5
// 
// @Usage
// Use to feed an NPC for 10 foodpoints (or 5 bars).
// - feed <npc> amount:10
// 
// @Usage
// Use to feed a player from a definition fully without refilling saturation.
// - feed <[player]> saturation:0
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (arg.matchesInteger() && arg.matchesPrefix("amount", "amt", "quantity", "qty", "a", "q") && !scriptEntry.hasObject("amount")) {
            scriptEntry.addObject("amount", arg.asElement());
        } else if (arg.matchesInteger() && arg.matchesPrefix("saturation", "sat", "s") && !scriptEntry.hasObject("saturation")) {
            scriptEntry.addObject("saturation", arg.asElement());
        } else if (arg.matchesArgumentType(PlayerTag.class) && !scriptEntry.hasObject("targetplayer") && !scriptEntry.hasObject("targetnpc")) {
            scriptEntry.addObject("targetplayer", arg.asType(PlayerTag.class));
        } else if (Depends.citizens != null && arg.matchesArgumentType(NPCTag.class) && !scriptEntry.hasObject("targetplayer") && !scriptEntry.hasObject("targetnpc")) {
            scriptEntry.addObject("targetnpc", arg.asType(NPCTag.class));
        } else // Backwards compatibility
        if (arg.matches("npc") && !scriptEntry.hasObject("targetplayer") && !scriptEntry.hasObject("targetnpc") && Utilities.entryHasNPC(scriptEntry)) {
            scriptEntry.addObject("targetnpc", Utilities.getEntryNPC(scriptEntry));
        } else if (arg.matches("player") && !scriptEntry.hasObject("targetplayer") && !scriptEntry.hasObject("targetnpc") && Utilities.entryHasPlayer(scriptEntry)) {
            scriptEntry.addObject("targetplayer", Utilities.getEntryPlayer(scriptEntry));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("targetplayer") && !scriptEntry.hasObject("targetnpc")) {
        if (Utilities.entryHasPlayer(scriptEntry)) {
            scriptEntry.addObject("targetplayer", Utilities.getEntryPlayer(scriptEntry));
        } else if (Utilities.entryHasNPC(scriptEntry)) {
            scriptEntry.addObject("targetnpc", Utilities.getEntryNPC(scriptEntry));
        } else {
            throw new InvalidArgumentsException("Must specify a player!");
        }
    }
    scriptEntry.defaultObject("amount", new ElementTag(20));
    scriptEntry.defaultObject("saturation", scriptEntry.getObject("amount"));
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 8 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.

the class RotateCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (!scriptEntry.hasObject("cancel") && (arg.matches("cancel") || arg.matches("stop"))) {
            scriptEntry.addObject("cancel", new ElementTag("true"));
        } else if (!scriptEntry.hasObject("infinite") && arg.matches("infinite")) {
            scriptEntry.addObject("infinite", new ElementTag("true"));
        } else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(DurationTag.class) && arg.matchesPrefix("duration", "d")) {
            scriptEntry.addObject("duration", arg.asType(DurationTag.class));
        } else if (!scriptEntry.hasObject("frequency") && arg.matchesArgumentType(DurationTag.class) && arg.matchesPrefix("frequency", "f")) {
            scriptEntry.addObject("frequency", arg.asType(DurationTag.class));
        } else if (!scriptEntry.hasObject("yaw") && arg.matchesPrefix("yaw", "y", "rotation", "r") && arg.matchesFloat()) {
            scriptEntry.addObject("yaw", arg.asElement());
        } else if (!scriptEntry.hasObject("pitch") && arg.matchesPrefix("pitch", "p", "tilt", "t") && arg.matchesFloat()) {
            scriptEntry.addObject("pitch", arg.asElement());
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
            scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
        } else {
            arg.reportUnhandled();
        }
    }
    scriptEntry.defaultObject("entities", Utilities.entryDefaultEntityList(scriptEntry, true));
    scriptEntry.defaultObject("yaw", new ElementTag(10));
    scriptEntry.defaultObject("pitch", new ElementTag(0));
    scriptEntry.defaultObject("duration", new DurationTag(20));
    scriptEntry.defaultObject("frequency", new DurationTag(1L));
    if (!scriptEntry.hasObject("entities")) {
        throw new InvalidArgumentsException("Must specify entity/entities!");
    }
}
Also used : EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 9 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.

the class PoseCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : scriptEntry) {
        if (arg.matches("add", "assume", "remove")) {
            scriptEntry.addObject("action", Action.valueOf(arg.getValue().toUpperCase()));
        } else if (arg.matchesPrefix("id")) {
            scriptEntry.addObject("pose_id", arg.asElement());
        } else if (arg.matches("player")) {
            scriptEntry.addObject("target", TargetType.PLAYER);
        } else if (arg.matchesArgumentType(LocationTag.class)) {
            scriptEntry.addObject("pose_loc", arg.asType(LocationTag.class));
        }
    }
    // Even if the target is a player, this command requires an NPC to get the pose from.
    if (!Utilities.entryHasNPC(scriptEntry)) {
        throw new InvalidArgumentsException("This command requires an NPC!");
    }
    if (!scriptEntry.hasObject("pose_id")) {
        throw new InvalidArgumentsException("No ID specified!");
    }
    scriptEntry.defaultObject("target", TargetType.NPC);
    scriptEntry.defaultObject("action", Action.ASSUME);
    // If the target is a player, it needs a player! However, you can't ADD/REMOVE poses 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 (!Utilities.entryHasPlayer(scriptEntry)) {
            throw new InvalidArgumentsException("This command requires a linked player!");
        }
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Argument(com.denizenscript.denizencore.objects.Argument) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Example 10 with InvalidArgumentsException

use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.

the class ActionBarCommand method parseArgs.

// <--[command]
// @Name ActionBar
// @Syntax actionbar [<text>] (targets:<player>|...) (format:<name>) (per_player)
// @Required 1
// @Maximum 4
// @Short Sends a message to a player's action bar.
// @group player
// 
// @Description
// Sends a message to the target's action bar area.
// If no target is specified it will default to the attached player.
// Accepts the 'format:<name>' argument, which will reformat the text according to the specified format script. See <@link language Format Script Containers>.
// 
// Optionally use 'per_player' with a list of player targets, to have the tags in the text input be reparsed for each and every player.
// So, for example, "- actionbar 'hello <player.name>' targets:<server.online_players>"
// would normally show "hello bob" to every player (every player sees the exact same name in the text, ie bob sees "hello bob", steve also sees "hello bob", etc)
// but if you use "per_player", each player online would see their own name (so bob sees "hello bob", steve sees "hello steve", etc).
// 
// @Tags
// None
// 
// @Usage
// Use to send a message to the player's action bar.
// - actionbar "Hey there <player.name>!"
// 
// @Usage
// Use to send a message to a list of players.
// - actionbar "Hey, welcome to the server!" targets:<[thatplayer]>|<[player]>|<[someplayer]>
// 
// @Usage
// Use to send a message to a list of players, with a formatted message.
// - actionbar "Hey there!" targets:<[thatplayer]>|<[player]> format:ServerChat
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (Argument arg : ArgumentHelper.interpret(scriptEntry, scriptEntry.getOriginalArguments())) {
        if (!scriptEntry.hasObject("format") && arg.matchesPrefix("format", "f")) {
            String formatStr = TagManager.tag(arg.getValue(), scriptEntry.getContext());
            FormatScriptContainer format = ScriptRegistry.getScriptContainer(formatStr);
            if (format == null) {
                Debug.echoError("Could not find format script matching '" + formatStr + "'");
            }
            scriptEntry.addObject("format", new ScriptTag(format));
        } else if (!scriptEntry.hasObject("targets") && arg.matchesPrefix("targets", "target")) {
            scriptEntry.addObject("targets", ListTag.getListFor(TagManager.tagObject(arg.getValue(), scriptEntry.getContext()), scriptEntry.getContext()).filter(PlayerTag.class, scriptEntry));
        } else if (!scriptEntry.hasObject("per_player") && arg.matches("per_player")) {
            scriptEntry.addObject("per_player", new ElementTag(true));
        } else if (!scriptEntry.hasObject("text")) {
            scriptEntry.addObject("text", arg.getRawElement());
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("text")) {
        throw new InvalidArgumentsException("Must specify a message!");
    }
    if (!scriptEntry.hasObject("targets") && !Utilities.entryHasPlayer(scriptEntry)) {
        throw new InvalidArgumentsException("Must specify target(s).");
    }
    if (!scriptEntry.hasObject("targets")) {
        if (!Utilities.entryHasPlayer(scriptEntry)) {
            throw new InvalidArgumentsException("Must specify valid player Targets!");
        } else {
            scriptEntry.addObject("targets", Collections.singletonList(Utilities.getEntryPlayer(scriptEntry)));
        }
    }
}
Also used : Argument(com.denizenscript.denizencore.objects.Argument) FormatScriptContainer(com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer) ScriptTag(com.denizenscript.denizencore.objects.core.ScriptTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) InvalidArgumentsException(com.denizenscript.denizencore.exceptions.InvalidArgumentsException)

Aggregations

InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)41 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)31 Argument (com.denizenscript.denizencore.objects.Argument)30 EntityTag (com.denizenscript.denizen.objects.EntityTag)15 ListTag (com.denizenscript.denizencore.objects.core.ListTag)14 LocationTag (com.denizenscript.denizen.objects.LocationTag)11 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)11 ItemTag (com.denizenscript.denizen.objects.ItemTag)8 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)7 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)5 FormatScriptContainer (com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer)3 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)2 ArrayList (java.util.ArrayList)2 ParticleHelper (com.denizenscript.denizen.nms.abstracts.ParticleHelper)1 AssignmentTrait (com.denizenscript.denizen.npc.traits.AssignmentTrait)1 ColorTag (com.denizenscript.denizen.objects.ColorTag)1 NPCTag (com.denizenscript.denizen.objects.NPCTag)1 WorldTag (com.denizenscript.denizen.objects.WorldTag)1 AssignmentScriptContainer (com.denizenscript.denizen.scripts.containers.core.AssignmentScriptContainer)1 InteractScriptContainer (com.denizenscript.denizen.scripts.containers.core.InteractScriptContainer)1