use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.
the class ExperienceCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
int amount = 0;
Type type = Type.SET;
boolean level = false;
boolean silent = false;
for (Argument arg : scriptEntry) {
if (arg.matchesInteger()) {
amount = arg.asElement().asInt();
} else if (arg.matches("set", "give", "take")) {
type = Type.valueOf(arg.asElement().asString().toUpperCase());
} else if (arg.matches("level")) {
level = true;
} else if (arg.matches("silent")) {
silent = true;
} else {
arg.reportUnhandled();
}
}
scriptEntry.addObject("quantity", amount).addObject("type", type).addObject("level", level).addObject("silent", silent);
}
use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.
the class SidebarCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
Action action = Action.SET;
for (Argument arg : ArgumentHelper.interpret(scriptEntry, scriptEntry.getOriginalArguments())) {
if (!scriptEntry.hasObject("action") && arg.matchesEnum(Action.class)) {
action = Action.valueOf(arg.getValue().toUpperCase());
} else if (!scriptEntry.hasObject("title") && arg.matchesPrefix("title", "t", "objective", "obj", "o")) {
scriptEntry.addObject("title", arg.asElement());
} else if (!scriptEntry.hasObject("scores") && arg.matchesPrefix("scores", "score", "lines", "line", "l")) {
scriptEntry.addObject("scores", arg.asElement());
} else if (!scriptEntry.hasObject("value") && arg.matchesPrefix("value", "values", "val", "v")) {
scriptEntry.addObject("value", arg.asElement());
} else if (!scriptEntry.hasObject("increment") && arg.matchesPrefix("increment", "inc", "i")) {
scriptEntry.addObject("increment", arg.asElement());
} else if (!scriptEntry.hasObject("start") && arg.matchesPrefix("start", "s")) {
scriptEntry.addObject("start", arg.asElement());
} else if (!scriptEntry.hasObject("players") && arg.matchesPrefix("players", "player", "p")) {
scriptEntry.addObject("players", arg.asElement());
} else if (!scriptEntry.hasObject("per_player") && arg.matches("per_player")) {
scriptEntry.addObject("per_player", new ElementTag(true));
} else {
arg.reportUnhandled();
}
}
if (action == Action.ADD && !scriptEntry.hasObject("value")) {
throw new InvalidArgumentsException("Must specify value(s) for that action!");
}
if (action == Action.SET && !scriptEntry.hasObject("value") && !scriptEntry.hasObject("title") && !scriptEntry.hasObject("increment") && !scriptEntry.hasObject("start")) {
throw new InvalidArgumentsException("Must specify at least one of: value(s), title, increment, or start for that action!");
}
if (action == Action.SET && scriptEntry.hasObject("scores") && !scriptEntry.hasObject("value")) {
throw new InvalidArgumentsException("Must specify value(s) when setting scores!");
}
scriptEntry.addObject("action", new ElementTag(action.name()));
scriptEntry.defaultObject("per_player", new ElementTag(false));
scriptEntry.defaultObject("players", new ElementTag(Utilities.entryHasPlayer(scriptEntry) ? Utilities.getEntryPlayer(scriptEntry).identify() : "li@"));
}
use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.
the class TeamCommand method parseArgs.
// <--[command]
// @Name Team
// @Syntax team (id:<scoreboard>/{main}) [name:<team>] (add:<entry>|...) (remove:<entry>|...) (prefix:<prefix>) (suffix:<suffix>) (option:<type> status:<status>) (color:<color>)
// @Required 2
// @Maximum 9
// @Short Controls scoreboard teams.
// @Group player
//
// @Description
// The Team command allows you to control a scoreboard team.
//
// Use the "prefix" or "suffix" arguments to modify a team's playername prefix and suffix.
// NOTE: Prefixes and suffixes cannot be longer than 16 characters!
//
// The "entry" value can be a player's name to affect that player, or an entity's UUID to affect that entity.
// You can alternately input a raw PlayerTag or EntityTag, and they will be automatically translated to the name/UUID internally.
//
// Use the "color" argument to set the team color (for glowing, names, etc). Must be from <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/ChatColor.html>.
//
// Use the "add" and "remove" arguments to add or remove players by name to/from the team.
//
// Use the "option" and "status" arguments together to set a team option's status.
// Option can be "COLLISION_RULE", "DEATH_MESSAGE_VISIBILITY", or "NAME_TAG_VISIBILITY", with status "ALWAYS", "FOR_OTHER_TEAMS", "FOR_OWN_TEAM", or "NEVER".
// Option can instead be "FRIENDLY_FIRE" or "SEE_INVISIBLE", only allowing status "ALWAYS" or "NEVER".
//
// @Tags
// <server.scoreboard[(<board>)].team[<team>].members>
//
// @Usage
// Use to add a player to a team.
// - team name:red add:<player>
//
// @Usage
// Use to add some mob to a team.
// - team name:blue add:<player.location.find_entities[monster].within[10]>
//
// @Usage
// Use to change the prefix for a team.
// - team name:red "prefix:[<red>Red Team<reset>]"
//
// @Usage
// Use to hide nameplates for members of a team.
// - team name:red option:name_tag_visibility status:never
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
String name = null;
String prefix = null;
String suffix = null;
for (Argument arg : scriptEntry) {
if (arg.matchesPrefix("id") && !scriptEntry.hasObject("id")) {
scriptEntry.addObject("id", arg.asElement());
} else if (arg.matchesPrefix("name") && !scriptEntry.hasObject("name")) {
ElementTag nameElement = arg.asElement();
name = nameElement.asString();
scriptEntry.addObject("name", nameElement);
} else if (arg.matchesPrefix("add") && !scriptEntry.hasObject("add")) {
scriptEntry.addObject("add", arg.asType(ListTag.class));
} else if (arg.matchesPrefix("remove") && !scriptEntry.hasObject("remove")) {
scriptEntry.addObject("remove", arg.asType(ListTag.class));
} else if (arg.matchesPrefix("prefix") && !scriptEntry.hasObject("prefix")) {
ElementTag prefixElement = arg.asElement();
prefix = prefixElement.asString();
scriptEntry.addObject("prefix", prefixElement);
} else if (arg.matchesPrefix("suffix") && !scriptEntry.hasObject("suffix")) {
ElementTag suffixElement = arg.asElement();
suffix = suffixElement.asString();
scriptEntry.addObject("suffix", suffixElement);
} else if (arg.matchesPrefix("color") && arg.matchesEnum(ChatColor.class) && !scriptEntry.hasObject("color")) {
scriptEntry.addObject("color", arg.asElement());
} else if (arg.matchesPrefix("option") && !scriptEntry.hasObject("option") && (arg.matchesEnum(Team.Option.class) || arg.matches("friendly_fire", "see_invisible"))) {
scriptEntry.addObject("option", arg.asElement());
} else if (arg.matchesPrefix("status") && !scriptEntry.hasObject("status") && arg.matchesEnum(Team.OptionStatus.class)) {
scriptEntry.addObject("status", arg.asElement());
} else {
arg.reportUnhandled();
}
}
if (name == null || name.length() == 0 || name.length() > 16) {
throw new InvalidArgumentsException("Must specify a team name between 1 and 16 characters!");
}
if (!scriptEntry.hasObject("add") && !scriptEntry.hasObject("remove") && !scriptEntry.hasObject("option") && !scriptEntry.hasObject("color") && !scriptEntry.hasObject("prefix") && !scriptEntry.hasObject("suffix")) {
throw new InvalidArgumentsException("Must specify something to do with the team!");
}
if ((prefix != null && prefix.length() > 64) || (suffix != null && suffix.length() > 64)) {
throw new InvalidArgumentsException("Prefixes and suffixes must be 64 characters or less!");
}
if (scriptEntry.hasObject("option") != scriptEntry.hasObject("status")) {
throw new InvalidArgumentsException("Option and Status arguments must go together!");
}
scriptEntry.defaultObject("id", new ElementTag("main"));
}
use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.
the class FakeEquipCommand method parseArgs.
// <--[command]
// @Name FakeEquip
// @Syntax fakeequip [<entity>|...] (for:<player>|...) (duration:<duration>/reset) (hand:<item>) (offhand:<item>) (head:<item>) (chest:<item>) (legs:<item>) (boots:<item>)
// @Required 1
// @Maximum 9
// @Short Fake-equips items and armor on a list of entities for players to see without real change.
// @Group entity
//
// @Description
// This command fake-equips items and armor on a list of entities.
//
// The change doesn't happen on-server, and no armor effects will happen from it.
//
// The equipment can only be seen by certain players. By default, the linked player is used.
//
// The changes will remain in place for as long as the duration is specified (even if the real equipment is changed).
// The changes can be manually reset early by using the 'reset' argument.
// If you do not provide a duration, the fake equipment will last until manually reset.
// This does not persist across server restarts.
//
// Set the item to 'air' to unequip any slot.
//
// @Tags
// <EntityTag.equipment>
// <InventoryTag.equipment>
//
// @Usage
// Use to fake-equip a stone block on the player's head.
// - fakeequip <player> head:stone duration:10s
//
// @Usage
// Use to fake-equip an iron helmet on two defined players.
// - fakeequip <[player]>|<[someplayer]> head:iron_helmet duration:1m
//
// @Usage
// Use to fake-unequip all armor off the player.
// - fakeequip <player> head:air chest:air legs:air boots:air duration:5s
//
// @Usage
// Use to make all players within 30 blocks of an entity see it permanently equip a shield.
// - fakeequip <[entity]> offhand:shield for:<[entity].find_players_within[30]> duration:0
//
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
EquipmentOverride equipment = new EquipmentOverride();
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.matchesPrefix("duration") && arg.matchesArgumentType(DurationTag.class)) {
scriptEntry.addObject("duration", arg.asType(DurationTag.class));
} else if (arg.matches("reset")) {
scriptEntry.addObject("reset", new ElementTag(true));
} else if (arg.matchesPrefix("for") && arg.matchesArgumentList(PlayerTag.class)) {
scriptEntry.addObject("for", arg.asType(ListTag.class).filter(PlayerTag.class, scriptEntry));
} else if (arg.matchesPrefix("head", "helmet") && arg.matchesArgumentType(ItemTag.class)) {
equipment.head = arg.asType(ItemTag.class);
} else if (arg.matchesPrefix("chest", "chestplate") && arg.matchesArgumentType(ItemTag.class)) {
equipment.chest = arg.asType(ItemTag.class);
} else if (arg.matchesPrefix("legs", "leggings") && arg.matchesArgumentType(ItemTag.class)) {
equipment.legs = arg.asType(ItemTag.class);
} else if (arg.matchesPrefix("boots", "feet") && arg.matchesArgumentType(ItemTag.class)) {
equipment.boots = arg.asType(ItemTag.class);
} else if (arg.matchesPrefix("offhand") && arg.matchesArgumentType(ItemTag.class)) {
equipment.offhand = arg.asType(ItemTag.class);
} else if (arg.matchesPrefix("hand") && arg.matchesArgumentType(ItemTag.class)) {
equipment.hand = arg.asType(ItemTag.class);
} else {
arg.reportUnhandled();
}
}
if (equipment.isEmpty() && !scriptEntry.hasObject("reset")) {
throw new InvalidArgumentsException("Must specify equipment!");
}
if (!scriptEntry.hasObject("for")) {
PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
if (player == null) {
throw new InvalidArgumentsException("Must specify a for player!");
}
scriptEntry.addObject("for", Collections.singletonList(player));
}
scriptEntry.addObject("equipment", equipment);
}
use of com.denizenscript.denizencore.objects.Argument 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!");
}
}
Aggregations