use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class FlyCommand method parseArgs.
// <--[command]
// @Name Fly
// @Syntax fly (cancel) [<entity>|...] (controller:<player>) (origin:<location>) (destinations:<location>|...) (speed:<#.#>) (rotationthreshold:<#.#>)
// @Required 1
// @Maximum 7
// @Short Make an entity fly where its controller is looking or fly to waypoints.
// @Group entity
//
// @Description
// Make an entity fly where its controller is looking or fly to waypoints.
// This is particularly useful as a way to make flying entities rideable (or make a non-flying entity start flying).
//
// Optionally specify a list of "destinations" to make it move through a series of checkpoints (disabling the "controller" functionality).
//
// Optionally specify an "origin" location where the entities should teleport to at the start.
//
// Optionally specify the "speed" argument to set how fast the entity should fly.
//
// Optionally specify the "rotationthreshold" to set the minimum threshold (in degrees) before the entity should forcibly rotate to the correct direction.
//
// Use the "cancel" argument to stop an existing flight.
//
// @Tags
// <PlayerTag.can_fly>
// <PlayerTag.fly_speed>
// <PlayerTag.is_flying>
//
// @Usage
// Use to make a player ride+fly a newly spawned dragon.
// - fly <player>|ender_dragon
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("cancel") && arg.matches("cancel")) {
scriptEntry.addObject("cancel", "");
} else if (!scriptEntry.hasObject("destinations") && arg.matchesPrefix("destination", "destinations", "d")) {
scriptEntry.addObject("destinations", arg.asType(ListTag.class).filter(LocationTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("controller") && arg.matchesArgumentType(PlayerTag.class) && arg.matchesPrefix("controller", "c")) {
// Check if it matches a PlayerTag, but save it as a EntityTag
scriptEntry.addObject("controller", arg.asType(EntityTag.class));
} else if (!scriptEntry.hasObject("origin") && arg.matchesArgumentType(LocationTag.class)) {
scriptEntry.addObject("origin", arg.asType(LocationTag.class));
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("rotation_threshold") && arg.matchesPrefix("rotationthreshold", "rotation", "r") && arg.matchesFloat()) {
scriptEntry.addObject("rotation_threshold", arg.asElement());
} else if (!scriptEntry.hasObject("speed") && arg.matchesFloat()) {
scriptEntry.addObject("speed", arg.asElement());
} else {
arg.reportUnhandled();
}
}
scriptEntry.defaultObject("origin", Utilities.entryDefaultLocation(scriptEntry, true));
scriptEntry.defaultObject("speed", new ElementTag(1.2));
scriptEntry.defaultObject("rotation_threshold", new ElementTag(15));
if (!scriptEntry.hasObject("entities")) {
throw new InvalidArgumentsException("Must specify entity/entities!");
}
if (!scriptEntry.hasObject("origin")) {
throw new InvalidArgumentsException("Must specify an origin!");
}
}
use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class MountCommand method parseArgs.
// <--[command]
// @Name Mount
// @Syntax mount (cancel) [<entity>|...] (<location>)
// @Required 0
// @Maximum 3
// @Short Mounts one entity onto another.
// @Group entity
//
// @Description
// Mounts an entity onto another as though in a vehicle. Can be used to force a player into a vehicle or to
// mount an entity onto another entity. e.g. a player onto an npc. If the entity(s) don't exist they will be
// spawned. Accepts a location, which the entities will be teleported to on mounting.
//
// @Tags
// <EntityTag.vehicle>
// <EntityTag.is_inside_vehicle>
// <entry[saveName].mounted_entities> returns a list of entities that were mounted.
//
// @Usage
// Use to mount an NPC on top of a player.
// - mount <npc>|<player>
//
// @Usage
// Use to spawn a mutant pile of mobs.
// - mount cow|pig|sheep|chicken
//
// @Usage
// Use to place a diamond block above a player's head.
// - mount falling_block,diamond_block|<player>
//
// @Usage
// Use to force an entity in a vehicle.
// - mount <player>|boat
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
List<EntityTag> entities = null;
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("cancel") && arg.matches("cancel")) {
scriptEntry.addObject("cancel", "");
} else if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(LocationTag.class)) {
scriptEntry.addObject("location", arg.asType(LocationTag.class));
scriptEntry.addObject("custom_location", new ElementTag(true));
} else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
entities = arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry);
scriptEntry.addObject("entities", entities);
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("entities")) {
throw new InvalidArgumentsException("Must specify entity/entities!");
}
if (!scriptEntry.hasObject("location")) {
if (entities != null) {
for (int i = entities.size() - 1; i >= 0; i--) {
if (entities.get(i).isSpawned()) {
scriptEntry.defaultObject("location", entities.get(i).getLocation());
break;
}
}
}
scriptEntry.defaultObject("location", Utilities.entryDefaultLocation(scriptEntry, true));
}
if (!scriptEntry.hasObject("location")) {
throw new InvalidArgumentsException("Must specify a location!");
}
}
use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class CreateCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("entity_type") && arg.matchesArgumentType(EntityTag.class)) {
// Avoid duplication of objects
EntityTag ent = arg.asType(EntityTag.class);
if (!ent.isGeneric() && !ent.isCitizensNPC()) {
throw new InvalidArgumentsException("Entity supplied must be generic or a Citizens NPC!");
}
scriptEntry.addObject("entity_type", ent);
} else if (!scriptEntry.hasObject("spawn_location") && arg.matchesArgumentType(LocationTag.class)) {
scriptEntry.addObject("spawn_location", arg.asType(LocationTag.class));
} else if (!scriptEntry.hasObject("name")) {
scriptEntry.addObject("name", arg.asElement());
} else if (!scriptEntry.hasObject("traits") && arg.matchesPrefix("t", "trait", "traits")) {
scriptEntry.addObject("traits", arg.asType(ListTag.class));
} else if (!scriptEntry.hasObject("registry") && arg.matchesPrefix("registry")) {
scriptEntry.addObject("registry", arg.asElement());
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("name")) {
throw new InvalidArgumentsException("Must specify a name!");
}
if (!scriptEntry.hasObject("entity_type")) {
throw new InvalidArgumentsException("Must specify an entity type!");
}
}
use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class GiveCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("quantity") && arg.matchesPrefix("q", "qty", "quantity") && arg.matchesFloat()) {
if (arg.matchesPrefix("q", "qty")) {
Deprecations.qtyTags.warn(scriptEntry);
}
scriptEntry.addObject("quantity", arg.asElement());
scriptEntry.addObject("set_quantity", new ElementTag(true));
} else if (!scriptEntry.hasObject("type") && arg.matches("money", "coins")) {
Deprecations.giveTakeMoney.warn(scriptEntry);
scriptEntry.addObject("type", Type.MONEY);
} else if (!scriptEntry.hasObject("type") && arg.matches("xp", "exp", "experience")) {
scriptEntry.addObject("type", Type.EXP);
} else if (!scriptEntry.hasObject("unlimit_stack_size") && arg.matches("unlimit_stack_size")) {
scriptEntry.addObject("unlimit_stack_size", new ElementTag(true));
} else if (!scriptEntry.hasObject("items") && !scriptEntry.hasObject("type") && (arg.matchesArgumentList(ItemTag.class))) {
scriptEntry.addObject("items", arg.asType(ListTag.class).filter(ItemTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("inventory") && arg.matchesPrefix("t", "to") && arg.matchesArgumentType(InventoryTag.class)) {
scriptEntry.addObject("inventory", arg.asType(InventoryTag.class));
} else if (!scriptEntry.hasObject("slot") && arg.matchesPrefix("slot")) {
scriptEntry.addObject("slot", arg.asElement());
} else {
arg.reportUnhandled();
}
}
scriptEntry.defaultObject("type", Type.ITEM).defaultObject("unlimit_stack_size", new ElementTag(false)).defaultObject("quantity", new ElementTag(1)).defaultObject("slot", new ElementTag(1));
Type type = (Type) scriptEntry.getObject("type");
if (type == Type.ITEM) {
if (!scriptEntry.hasObject("items")) {
throw new InvalidArgumentsException("Must specify item/items!");
}
if (!scriptEntry.hasObject("inventory")) {
if (!Utilities.entryHasPlayer(scriptEntry)) {
throw new InvalidArgumentsException("Must specify an inventory to give to!");
}
scriptEntry.addObject("inventory", Utilities.getEntryPlayer(scriptEntry).getInventory());
}
} else {
if (!Utilities.entryHasPlayer(scriptEntry)) {
throw new InvalidArgumentsException("Must link a player to give money or XP!");
}
}
}
use of com.denizenscript.denizencore.exceptions.InvalidArgumentsException in project Denizen-For-Bukkit by DenizenScript.
the class ShowFakeCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("players") && arg.matchesPrefix("to", "players")) {
scriptEntry.addObject("players", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
} else if (arg.matchesPrefix("d", "duration") && arg.matchesArgumentType(DurationTag.class)) {
scriptEntry.addObject("duration", arg.asType(DurationTag.class));
} else if (arg.matches("cancel")) {
scriptEntry.addObject("cancel", new ElementTag(true));
} else if (!scriptEntry.hasObject("materials") && arg.matchesArgumentList(MaterialTag.class)) {
scriptEntry.addObject("materials", arg.asType(ListTag.class).filter(MaterialTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("locations") && arg.matchesArgumentList(LocationTag.class)) {
scriptEntry.addObject("locations", arg.asType(ListTag.class).filter(LocationTag.class, scriptEntry));
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("players") && Utilities.entryHasPlayer(scriptEntry)) {
scriptEntry.defaultObject("players", Collections.singletonList(Utilities.getEntryPlayer(scriptEntry)));
}
if (!scriptEntry.hasObject("locations")) {
throw new InvalidArgumentsException("Must specify at least one valid location!");
}
if (!scriptEntry.hasObject("players")) {
throw new InvalidArgumentsException("Must have a valid, online player attached!");
}
if (!scriptEntry.hasObject("materials") && !scriptEntry.hasObject("cancel")) {
throw new InvalidArgumentsException("Must specify valid material(s)!");
}
scriptEntry.defaultObject("duration", new DurationTag(10));
scriptEntry.defaultObject("cancel", new ElementTag(false));
}
Aggregations