use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.
the class TakeCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
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")) {
scriptEntry.addObject("type", Type.XP);
} else if (!scriptEntry.hasObject("type") && arg.matches("item_in_hand", "iteminhand")) {
scriptEntry.addObject("type", Type.ITEMINHAND);
} else if (!scriptEntry.hasObject("type") && arg.matches("cursoritem", "cursor_item")) {
scriptEntry.addObject("type", Type.CURSORITEM);
} else 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());
} else if (!scriptEntry.hasObject("items") && arg.matchesPrefix("bydisplay") && !scriptEntry.hasObject("type")) {
scriptEntry.addObject("type", Type.BYDISPLAY);
scriptEntry.addObject("displayname", arg.asType(ListTag.class));
} else if (!scriptEntry.hasObject("items") && arg.matchesPrefix("nbt") && !scriptEntry.hasObject("type")) {
Deprecations.itemNbt.warn(scriptEntry);
scriptEntry.addObject("type", Type.NBT);
scriptEntry.addObject("nbt_key", arg.asElement());
} else if (!scriptEntry.hasObject("items") && arg.matchesPrefix("flagged") && !scriptEntry.hasObject("type")) {
scriptEntry.addObject("type", Type.FLAGGED);
scriptEntry.addObject("flag_name", arg.asType(ListTag.class));
} else if (!scriptEntry.hasObject("type") && !scriptEntry.hasObject("items") && arg.matchesPrefix("bycover")) {
scriptEntry.addObject("type", Type.BYCOVER);
scriptEntry.addObject("cover", arg.asType(ListTag.class));
} else if (!scriptEntry.hasObject("type") && !scriptEntry.hasObject("items") && arg.matchesPrefix("item")) {
scriptEntry.addObject("type", Type.MATCHER);
scriptEntry.addObject("matcher_text", arg.asElement());
} else if (!scriptEntry.hasObject("type") && !scriptEntry.hasObject("items") && arg.matchesPrefix("material")) {
Deprecations.takeRawItems.warn(scriptEntry);
scriptEntry.addObject("type", Type.MATERIAL);
scriptEntry.addObject("material", arg.asType(ListTag.class).filter(MaterialTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("type") && !scriptEntry.hasObject("items") && arg.matchesPrefix("script", "scriptname")) {
Deprecations.takeRawItems.warn(scriptEntry);
scriptEntry.addObject("type", Type.SCRIPTNAME);
scriptEntry.addObject("scriptitem", arg.asType(ListTag.class).filter(ItemTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("type") && !scriptEntry.hasObject("items") && arg.matchesPrefix("raw_exact")) {
scriptEntry.addObject("type", Type.RAWEXACT);
scriptEntry.addObject("items", arg.asType(ListTag.class).filter(ItemTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("slot") && !scriptEntry.hasObject("type") && arg.matchesPrefix("slot")) {
scriptEntry.addObject("type", Type.SLOT);
scriptEntry.addObject("slot", arg.asType(ListTag.class));
} else if (!scriptEntry.hasObject("items") && !scriptEntry.hasObject("type") && arg.matchesArgumentList(ItemTag.class)) {
Deprecations.takeRawItems.warn(scriptEntry);
scriptEntry.addObject("items", arg.asType(ListTag.class).filter(ItemTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("inventory") && arg.matchesPrefix("f", "from") && arg.matchesArgumentType(InventoryTag.class)) {
scriptEntry.addObject("inventory", arg.asType(InventoryTag.class));
} else if (!scriptEntry.hasObject("type") && arg.matches("inventory")) {
Deprecations.takeCommandInventory.warn(scriptEntry);
scriptEntry.addObject("type", Type.INVENTORY);
} else if (!scriptEntry.hasObject("inventory") && arg.matches("npc")) {
Deprecations.takeCommandInventory.warn(scriptEntry);
scriptEntry.addObject("inventory", Utilities.getEntryNPC(scriptEntry).getDenizenEntity().getInventory());
} else {
arg.reportUnhandled();
}
}
scriptEntry.defaultObject("type", Type.ITEM).defaultObject("quantity", new ElementTag(1));
Type type = (Type) scriptEntry.getObject("type");
if (type != Type.MONEY && scriptEntry.getObject("inventory") == null) {
scriptEntry.addObject("inventory", Utilities.entryHasPlayer(scriptEntry) ? Utilities.getEntryPlayer(scriptEntry).getInventory() : null);
}
if (!scriptEntry.hasObject("inventory") && type != Type.MONEY) {
throw new InvalidArgumentsException("Must specify an inventory to take from!");
}
if (requiresPlayerTypes.contains(type) && !Utilities.entryHasPlayer(scriptEntry)) {
throw new InvalidArgumentsException("Cannot take '" + type.name() + "' without a linked player.");
}
}
use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.
the class RemoveCommand method parseArgs.
// <--[command]
// @Name Remove
// @Syntax remove [<entity>|...] (world:<world>)
// @Required 1
// @Maximum 2
// @Short Despawns an entity or list of entities, permanently removing any NPCs.
// @Group entity
// @Description
// Removes the selected entity. May also take a list of entities to remove.
//
// Any NPC removed this way is completely removed, as if by '/npc remove'.
// For temporary NPC removal, see <@link command despawn>.
//
// If a generic entity name is given (like 'zombie'), this will remove all entities of that type from the given world.
// Optionally, you may specify a world to target.
// (Defaults to the world of the player running the command)
//
// @Tags
// <EntityTag.is_spawned>
//
// @Usage
// Use to remove the entity the player is looking at.
// - remove <player.target>
//
// @Usage
// Use to remove all nearby entities around the player, excluding the player itself.
// - remove <player.location.find_entities.within[10].exclude[<player>]>
//
// @Usage
// Use to remove all dropped items in the world called cookies.
// - remove dropped_item world:cookies
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
EntityTag.allowDespawnedNpcs = true;
scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
EntityTag.allowDespawnedNpcs = false;
} else if (!scriptEntry.hasObject("world") && arg.matchesArgumentType(WorldTag.class)) {
scriptEntry.addObject("world", arg.asType(WorldTag.class));
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("entities")) {
throw new InvalidArgumentsException("Must specify entity/entities!");
}
scriptEntry.defaultObject("world", Utilities.entryDefaultWorld(scriptEntry, false));
}
use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.
the class SpawnCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(EntityTag.class)) {
EntityTag.allowDespawnedNpcs = true;
scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
EntityTag.allowDespawnedNpcs = false;
} else if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(LocationTag.class)) {
scriptEntry.addObject("location", arg.asType(LocationTag.class));
} else if (!scriptEntry.hasObject("target") && arg.matchesArgumentType(EntityTag.class) && arg.matchesPrefix("target")) {
scriptEntry.addObject("target", arg.asType(EntityTag.class));
} else if (!scriptEntry.hasObject("spread") && arg.matchesInteger()) {
scriptEntry.addObject("spread", arg.asElement());
} else if (!scriptEntry.hasObject("persistent") && arg.matches("persistent")) {
scriptEntry.addObject("persistent", "");
} else {
arg.reportUnhandled();
}
}
// Use the NPC or player's locations as the location if one is not specified
scriptEntry.defaultObject("location", Utilities.entryDefaultLocation(scriptEntry, false));
if (!scriptEntry.hasObject("entities")) {
throw new InvalidArgumentsException("Must specify entity/entities!");
}
if (!scriptEntry.hasObject("location")) {
throw new InvalidArgumentsException("Must specify a location!");
}
}
use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.
the class AdvancementCommand method parseArgs.
// <--[command]
// @Name Advancement
// @Syntax advancement [id:<name>] (delete/grant:<players>/revoke:<players>/{create}) (parent:<name>) (icon:<item>) (title:<text>) (description:<text>) (background:<key>) (frame:<type>) (toast:<boolean>) (announce:<boolean>) (hidden:<boolean>) (x:<offset>) (y:<offset>) (progress_length:<#>)
// @Required 1
// @Maximum 14
// @Short Controls a custom advancement.
// @Group player
//
// @Description
// Controls custom Minecraft player advancements. You should generally create advancements manually on server start.
// Currently, the ID argument may only refer to advancements added through this command.
// The default action is to create and register a new advancement.
// You may also delete an existing advancement, in which case do not provide any further arguments.
// You may grant or revoke an advancement for a list of players, in which case do not provide any further arguments.
// The parent argument sets the root advancement in the advancements menu, in the format "namespace:key".
// If no namespace is specified, the parent is assumed to have been created through this command.
// The icon argument sets the icon displayed in toasts and the advancements menu.
// The title argument sets the title that will show on toasts and in the advancements menu.
// The description argument sets the information that will show when scrolling over a chat announcement or in the advancements menu.
// The background argument sets the image to use if the advancement goes to a new tab.
// If the background is unspecified, defaults to "minecraft:textures/gui/advancements/backgrounds/stone.png".
// The frame argument sets the type of advancement - valid arguments are CHALLENGE, GOAL, and TASK.
// The toast argument sets whether the advancement should display a toast message when a player completes it. Default is true.
// The announce argument sets whether the advancement should display a chat message to the server when a player completes it. Default is true.
// The hidden argument sets whether the advancement should be hidden until it is completed.
// The x and y arguments are offsets based on the size of an advancement icon in the menu. They are required for custom tabs to look reasonable.
//
// When creating an advancement, optionally specify 'progress_length' to make it require multiple parts.
// When granting an advancement, optionally specify 'progress_length' to only grant partial progress.
//
// To award a pre-existing vanilla advancement, instead use <@link mechanism PlayerTag.award_advancement>
//
// WARNING: Failure to re-create advancements on every server start may result in loss of data - use <@link event server prestart>.
//
// @Tags
// <PlayerTag.has_advancement[<advancement>]>
// <PlayerTag.advancements>
// <server.advancement_types>
//
// @Usage
// Creates a new advancement that has a potato icon.
// - advancement id:hello_world icon:baked_potato "title:Hello World" "description:You said hello to the world."
//
// @Usage
// Creates a new advancement with the parent "hello_world" and a CHALLENGE frame. Hidden until it is completed.
// - advancement id:hello_universe parent:hello_world icon:ender_pearl "title:Hello Universe" "description:You said hello to the UNIVERSE." frame:challenge hidden:true x:1
//
// @Usage
// Grants the "hello_world" advancement to the current player.
// - advancement id:hello_world grant:<player>
//
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (!scriptEntry.hasObject("id") && arg.matchesPrefix("id")) {
scriptEntry.addObject("id", arg.asElement());
} else if (!scriptEntry.hasObject("parent") && arg.matchesPrefix("parent")) {
scriptEntry.addObject("parent", arg.asElement());
} else if (!scriptEntry.hasObject("create") && arg.matches("create")) {
// unused, just to be explicit
scriptEntry.addObject("create", new ElementTag(true));
} else if (!scriptEntry.hasObject("delete") && arg.matches("delete", "remove")) {
scriptEntry.addObject("delete", new ElementTag(true));
} else if (!scriptEntry.hasObject("grant") && arg.matchesPrefix("grant", "give", "g") && arg.matchesArgumentList(PlayerTag.class)) {
scriptEntry.addObject("grant", arg.asType(ListTag.class));
} else if (!scriptEntry.hasObject("revoke") && arg.matchesPrefix("revoke", "take", "r") && arg.matchesArgumentList(PlayerTag.class)) {
scriptEntry.addObject("revoke", arg.asType(ListTag.class));
} else if (!scriptEntry.hasObject("icon") && arg.matchesPrefix("icon", "i") && arg.matchesArgumentType(ItemTag.class)) {
scriptEntry.addObject("icon", arg.asType(ItemTag.class));
} else if (!scriptEntry.hasObject("title") && arg.matchesPrefix("title", "text", "t")) {
scriptEntry.addObject("title", arg.asElement());
} else if (!scriptEntry.hasObject("description") && arg.matchesPrefix("description", "desc", "d")) {
scriptEntry.addObject("description", arg.asElement());
} else if (!scriptEntry.hasObject("background") && arg.matchesPrefix("background", "bg")) {
scriptEntry.addObject("background", arg.asElement());
} else if (!scriptEntry.hasObject("frame") && arg.matchesPrefix("frame", "f") && arg.matchesEnum(Advancement.Frame.class)) {
scriptEntry.addObject("frame", arg.asElement());
} else if (!scriptEntry.hasObject("toast") && arg.matchesPrefix("toast", "show") && arg.matchesBoolean()) {
scriptEntry.addObject("toast", arg.asElement());
} else if (!scriptEntry.hasObject("announce") && arg.matchesPrefix("announce", "chat") && arg.matchesBoolean()) {
scriptEntry.addObject("announce", arg.asElement());
} else if (!scriptEntry.hasObject("hidden") && arg.matchesPrefix("hidden", "hide", "h") && arg.matchesBoolean()) {
scriptEntry.addObject("hidden", arg.asElement());
} else if (!scriptEntry.hasObject("x") && arg.matchesPrefix("x") && arg.matchesFloat()) {
scriptEntry.addObject("x", arg.asElement());
} else if (!scriptEntry.hasObject("y") && arg.matchesPrefix("y") && arg.matchesFloat()) {
scriptEntry.addObject("y", arg.asElement());
} else if (!scriptEntry.hasObject("progress_length") && arg.matchesPrefix("progress_length") && arg.matchesInteger()) {
scriptEntry.addObject("progress_length", arg.asElement());
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("id")) {
throw new InvalidArgumentsException("Must specify an ID!");
}
scriptEntry.defaultObject("icon", new ItemTag(Material.AIR));
scriptEntry.defaultObject("title", new ElementTag(""));
scriptEntry.defaultObject("description", new ElementTag(""));
scriptEntry.defaultObject("background", new ElementTag("minecraft:textures/gui/advancements/backgrounds/stone.png"));
scriptEntry.defaultObject("frame", new ElementTag("TASK"));
scriptEntry.defaultObject("toast", new ElementTag(true));
scriptEntry.defaultObject("announce", new ElementTag(true));
scriptEntry.defaultObject("hidden", new ElementTag(false));
scriptEntry.defaultObject("x", new ElementTag(0f));
scriptEntry.defaultObject("y", new ElementTag(0f));
}
use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.
the class ChatCommand method parseArgs.
// TODO: Should the chat command be in the NPC group instead?
// <--[command]
// @Name Chat
// @Syntax chat [<text>] (no_target/targets:<entity>|...) (talkers:<entity>|...) (range:<#.#>)
// @Required 1
// @Maximum 4
// @Plugin Citizens
// @Short Causes an NPC/NPCs to send a chat message to nearby players.
// @Synonyms Say,Speak
// @Group player
//
// @Description
// Chat uses an NPC's speech controller provided by Denizen, typically inside 'interact' or 'task' script-containers.
// Typically there is already player and NPC context inside a queue that is using the 'chat' command.
// In this case, only a text input is required.
// Alternatively, target entities can be specified to have any Entity chat to a different target/targets,
// or specify 'no_target' to not send the message to any specific target.
//
// Chat from an NPC is formatted by the settings present in Denizen's config.yml.
// Players being chatted to see a slightly different message than surrounding players.
// By default, a 'chat' will allow other players nearby to also see the conversation. For example:
// <code>
// - chat 'Hello!'
// </code>
// The player being chatted to, by default the attached Player to the script queue, will see a message 'Jack says to you, Hello!',
// however surrounding entities will see something along the lines of 'Jack says to Bob, Hello!'.
// The format for this is configurable.
//
// If sending messages to the Player without any surrounding entities hearing the message is desirable,
// it is often times recommended to instead use the 'narrate' command.
// Alternatively, on a server-wide scale, the configuration node for the 'range' can be set to 0, however this is discouraged.
//
// @Tags
// None
//
// @Usage
// Use to emulate an NPC talking out loud to a Player within an interact script-container.
// - chat "Hello, <player.name>! Nice day, eh?"
//
// @Usage
// Use to have an NPC talk to a group of individuals.
// - chat targets:<npc.location.find_players_within[6].filter[has_flag[clan_initiate]]> "Welcome, initiate!"
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
boolean specified_targets = false;
boolean specified_talker = false;
for (Argument arg : scriptEntry) {
if (arg.matchesPrefix("target", "targets", "t")) {
if (arg.matchesArgumentList(EntityTag.class)) {
scriptEntry.addObject("targets", arg.asType(ListTag.class));
}
specified_targets = true;
} else if (arg.matches("no_target")) {
scriptEntry.addObject("targets", new ListTag());
} else if (arg.matchesPrefix("talker", "talkers")) {
if (arg.matchesArgumentList(EntityTag.class)) {
scriptEntry.addObject("talkers", arg.asType(ListTag.class));
}
specified_talker = true;
} else if (arg.matchesPrefix("range", "r")) {
if (arg.matchesFloat()) {
scriptEntry.addObject("range", arg.asElement());
}
} else if (!scriptEntry.hasObject("message")) {
scriptEntry.addObject("message", arg.getRawElement());
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("targets") && Utilities.entryHasPlayer(scriptEntry) && !specified_targets) {
scriptEntry.defaultObject("targets", new ListTag(Utilities.getEntryPlayer(scriptEntry)));
}
if (!scriptEntry.hasObject("talkers") && Utilities.entryHasNPC(scriptEntry) && !specified_talker) {
scriptEntry.defaultObject("talkers", new ListTag(Utilities.getEntryNPC(scriptEntry)));
}
if (!scriptEntry.hasObject("targets")) {
throw new InvalidArgumentsException("Must specify valid targets!");
}
if (!scriptEntry.hasObject("talkers")) {
throw new InvalidArgumentsException("Must specify valid talkers!");
}
if (!scriptEntry.hasObject("message")) {
throw new InvalidArgumentsException("Must specify a message!");
}
scriptEntry.defaultObject("range", new ElementTag(Settings.chatBystandersRange()));
}
Aggregations