use of com.denizenscript.denizencore.scripts.containers.core.TaskScriptContainer in project Denizen-For-Bukkit by DenizenScript.
the class PushCommand method parseArgs.
// <--[command]
// @Name Push
// @Syntax push [<entity>|...] (origin:<entity>/<location>) (destination:<location>) (speed:<#.#>) (duration:<duration>) (script:<name>) (def:<element>|...) (force_along) (precision:<#>) (no_rotate) (no_damage) (ignore_collision)
// @Required 1
// @Maximum 12
// @Short Pushes entities through the air in a straight line.
// @Group entity
//
// @Description
// Pushes entities through the air in a straight line at a certain speed and for a certain duration,
// triggering a script when they hit an obstacle or stop flying.
//
// You must specify an entity to be pushed.
//
// Usually, you should specify the origin and the destination. If unspecified, they will be assumed from contextual data.
//
// You can specify the script to be run with the (script:<name>) argument,
// and optionally specify definitions to be available in this script with the (def:<element>|...) argument.
//
// Using the 'no_damage' argument causes the entity to receive no damage when they stop moving.
//
// Optionally use the "ignore_collision" argument to ignore block collisions.
//
// Optionally use "speed:#" to set how fast it should be pushed.
//
// Optionally use "force_along" to cause the entity to teleport through any blockage.
//
// Optionally use "no_rotate" to prevent entities being rotated at the start of the push.
//
// Optionally use "duration:#" to set the max length of time to continue pushing.
//
// The push command is ~waitable. Refer to <@link language ~waitable>.
//
// @Tags
// <EntityTag.velocity>
// <entry[saveName].pushed_entities> returns the list of pushed entities.
//
// @Usage
// Use to launch an arrow straight towards a target.
// - push arrow destination:<player.location>
//
// @Usage
// Use to launch an entity into the air.
// - push cow
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("origin") && arg.matchesPrefix("origin", "o", "source", "shooter", "s")) {
if (arg.matchesArgumentType(EntityTag.class)) {
scriptEntry.addObject("origin_entity", arg.asType(EntityTag.class));
} else if (arg.matchesArgumentType(LocationTag.class)) {
scriptEntry.addObject("origin_location", arg.asType(LocationTag.class));
} else {
Debug.echoError("Ignoring unrecognized argument: " + arg.getRawValue());
}
} else if (!scriptEntry.hasObject("destination") && arg.matchesArgumentType(LocationTag.class) && arg.matchesPrefix("destination", "d")) {
scriptEntry.addObject("destination", arg.asType(LocationTag.class));
} else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(DurationTag.class) && arg.matchesPrefix("duration", "d")) {
scriptEntry.addObject("duration", arg.asType(DurationTag.class));
} else if (!scriptEntry.hasObject("speed") && arg.matchesFloat() && arg.matchesPrefix("speed", "s")) {
scriptEntry.addObject("speed", arg.asElement());
} else if (!scriptEntry.hasObject("script") && ((arg.matchesArgumentType(ScriptTag.class) && arg.asType(ScriptTag.class).getContainer() instanceof TaskScriptContainer) || arg.matchesPrefix("script"))) {
scriptEntry.addObject("script", arg.asType(ScriptTag.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("force_along") && arg.matches("force_along")) {
scriptEntry.addObject("force_along", new ElementTag(true));
} else if (!scriptEntry.hasObject("no_rotate") && arg.matches("no_rotate")) {
scriptEntry.addObject("no_rotate", new ElementTag(true));
} else if (!scriptEntry.hasObject("precision") && arg.matchesPrefix("precision")) {
scriptEntry.addObject("precision", arg.asElement());
} else if (!scriptEntry.hasObject("no_damage") && arg.matches("no_damage")) {
scriptEntry.addObject("no_damage", new ElementTag(true));
} else if (!scriptEntry.hasObject("ignore_collision") && arg.matches("ignore_collision")) {
scriptEntry.addObject("ignore_collision", new ElementTag(true));
} else if (arg.matchesPrefix("def", "define", "context")) {
scriptEntry.addObject("definitions", arg.asType(ListTag.class));
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("origin_location")) {
scriptEntry.defaultObject("origin_entity", Utilities.entryDefaultEntity(scriptEntry, false));
}
scriptEntry.defaultObject("speed", new ElementTag(1.5));
scriptEntry.defaultObject("duration", new DurationTag(20));
scriptEntry.defaultObject("force_along", new ElementTag(false));
scriptEntry.defaultObject("precision", new ElementTag(2));
if (!scriptEntry.hasObject("entities")) {
throw new InvalidArgumentsException("Must specify entity/entities!");
}
if (!scriptEntry.hasObject("origin_entity") && !scriptEntry.hasObject("origin_location")) {
throw new InvalidArgumentsException("Must specify an origin location!");
}
}
Aggregations