use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.
the class HealCommand method parseArgs.
// <--[command]
// @Name Heal
// @Syntax heal (<#.#>) ({player}/<entity>|...)
// @Required 0
// @Maximum 2
// @Short Heals the player or list of entities.
// @Group entity
//
// @Description
// This command heals a player, list of players, entity or list of entities.
//
// If no amount is specified it will heal the specified player(s)/entity(s) fully.
//
// @Tags
// <EntityTag.health>
// <EntityTag.health_max>
//
// @Usage
// Use to fully heal a player.
// - heal
//
// @Usage
// Use to heal a player 5 hearts.
// - heal 10
//
// @Usage
// Use to heal a defined player fully.
// - heal <[someplayer]>
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
boolean specified_targets = false;
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("amount") && arg.matchesFloat()) {
scriptEntry.addObject("amount", arg.asElement());
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentType(ListTag.class)) {
// Entity arg
scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
specified_targets = true;
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentType(EntityTag.class)) {
// Entity arg
scriptEntry.addObject("entities", Collections.singletonList(arg.asType(EntityTag.class)));
specified_targets = true;
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("amount")) {
scriptEntry.addObject("amount", new ElementTag(-1));
}
if (!specified_targets) {
List<EntityTag> entities = new ArrayList<>();
if (Utilities.getEntryPlayer(scriptEntry) != null) {
entities.add(Utilities.getEntryPlayer(scriptEntry).getDenizenEntity());
} else if (Utilities.getEntryNPC(scriptEntry) != null) {
entities.add(Utilities.getEntryNPC(scriptEntry).getDenizenEntity());
} else {
throw new InvalidArgumentsException("No valid target entities found.");
}
scriptEntry.addObject("entities", entities);
}
}
use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.
the class ScribeCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (arg.matchesEnum(BookAction.class) && !scriptEntry.hasObject("action")) {
scriptEntry.addObject("action", BookAction.valueOf(arg.getValue().toUpperCase()));
} else if (!scriptEntry.hasObject("script") && arg.matchesArgumentType(ScriptTag.class)) {
scriptEntry.addObject("script", arg.asType(ScriptTag.class));
} else if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(LocationTag.class)) {
scriptEntry.addObject("location", arg.asType(LocationTag.class));
scriptEntry.addObject("action", BookAction.DROP);
} else if (!scriptEntry.hasObject("item") && arg.matchesArgumentType(ItemTag.class)) {
scriptEntry.addObject("item", arg.asType(ItemTag.class));
} else {
arg.reportUnhandled();
}
}
scriptEntry.defaultObject("action", BookAction.GIVE);
scriptEntry.defaultObject("item", new ItemTag(Material.WRITTEN_BOOK));
// Must contain a book script
if (!scriptEntry.hasObject("script")) {
throw new InvalidArgumentsException("Missing SCRIPT argument!");
}
}
use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.
the class AttachCommand method parseArgs.
// <--[command]
// @Name attach
// @Syntax attach [<entity>|...] [to:<entity>/cancel] (offset:<offset>) (relative) (yaw_offset:<#.#>) (pitch_offset:<#.#>) (sync_server) (no_rotate/no_pitch) (for:<player>|...)
// @Required 2
// @Maximum 9
// @Short Attaches a list of entities to another entity, for client-visible motion sync.
// @Group entity
//
// @Description
// Attaches a list of entities to another entity, for client-visible motion sync.
//
// You must specify the entity or list of entities to be attached.
// You must specify the entity that they will be attached to, or 'cancel' to end attachment.
//
// Optionally, specify an offset location vector to be a positional offset. This can include a yaw/pitch to offset those as well.
// Note that setting an offset of 0,0,0 will produce slightly different visual results from not setting any offset.
//
// Optionally, specify 'relative' to indicate that the offset vector should rotate with the target entity.
// If relative is used, optionally specify yaw_offset and/or pitch_offset to add an offset to rotation of the target entity when calculating the attachment offset.
//
// Optionally, specify 'for' with a player or list of players to only sync motion for those players.
// If unspecified, will sync for everyone.
//
// Optionally, specify 'sync_server' to keep the serverside position of the attached entities near the target entity.
// This can reduce some visual artifacts (such as entity unloading at distance), but may produce unintended functional artifacts.
// Note that you should generally only use 'sync_server' when you exclude the 'for' argument.
//
// Optionally specify 'no_rotate' to retain the attached entity's own rotation and ignore the target rotation.
// Optionally instead specify 'no_pitch' to retain the attached entity's own pitch, but use the target yaw.
//
// Note that attaches involving a player will not be properly visible to that player, but will still be visible to *other* players.
//
// It may be ideal to change setting "Packets.Auto init" in the Denizen config to "true" to guarantee this command functions as expected.
//
// @Tags
// <EntityTag.attached_entities[(<player>)]>
// <EntityTag.attached_to[(<player>)]>
// <EntityTag.attached_offset[(<player>)]>
//
// @Usage
// Use to attach random NPC to the air 3 blocks above a linked NPC.
// - attach <server.list_npcs.random> to:<npc> offset:0,3,0
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("to") && !scriptEntry.hasObject("cancel") && arg.matchesPrefix("to") && arg.matchesArgumentType(EntityTag.class)) {
scriptEntry.addObject("to", arg.asType(EntityTag.class));
} else if (!scriptEntry.hasObject("cancel") && !scriptEntry.hasObject("to") && arg.matches("cancel")) {
scriptEntry.addObject("cancel", new ElementTag(true));
} else if (!scriptEntry.hasObject("relative") && arg.matches("relative")) {
scriptEntry.addObject("relative", new ElementTag(true));
} else if (!scriptEntry.hasObject("sync_server") && arg.matches("sync_server")) {
scriptEntry.addObject("sync_server", new ElementTag(true));
} else if (!scriptEntry.hasObject("no_rotate") && arg.matches("no_rotate")) {
scriptEntry.addObject("no_rotate", new ElementTag(true));
} else if (!scriptEntry.hasObject("no_pitch") && arg.matches("no_pitch")) {
scriptEntry.addObject("no_pitch", new ElementTag(true));
} else if (!scriptEntry.hasObject("yaw_offset") && arg.matchesPrefix("yaw_offset") && arg.matchesFloat()) {
scriptEntry.addObject("yaw_offset", arg.asElement());
} else if (!scriptEntry.hasObject("pitch_offset") && arg.matchesPrefix("pitch_offset") && arg.matchesFloat()) {
scriptEntry.addObject("pitch_offset", arg.asElement());
} else if (!scriptEntry.hasObject("offset") && arg.matchesPrefix("offset") && arg.matchesArgumentType(LocationTag.class)) {
scriptEntry.addObject("offset", arg.asType(LocationTag.class));
} else if (!scriptEntry.hasObject("for") && arg.matchesPrefix("for") && arg.matchesArgumentList(PlayerTag.class)) {
scriptEntry.addObject("for", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("entities")) {
throw new InvalidArgumentsException("Must specify attaching entities!");
}
if (!scriptEntry.hasObject("to") && !scriptEntry.hasObject("cancel")) {
throw new InvalidArgumentsException("Must specify a target entity, or 'cancel'!");
}
scriptEntry.defaultObject("cancel", new ElementTag(false));
scriptEntry.defaultObject("relative", new ElementTag(false));
scriptEntry.defaultObject("sync_server", new ElementTag(false));
scriptEntry.defaultObject("no_rotate", new ElementTag(false));
scriptEntry.defaultObject("no_pitch", new ElementTag(false));
scriptEntry.defaultObject("yaw_offset", new ElementTag(0f));
scriptEntry.defaultObject("pitch_offset", new ElementTag(0f));
}
use of com.denizenscript.denizencore.objects.Argument 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));
}
use of com.denizenscript.denizencore.objects.Argument 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"));
}
Aggregations