use of com.denizenscript.denizencore.objects.Argument 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.objects.Argument 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.objects.Argument in project Denizen-For-Bukkit by DenizenScript.
the class NarrateCommand method parseArgs.
// <--[command]
// @Name Narrate
// @Syntax narrate [<text>] (targets:<player>|...) (format:<script>) (per_player) (from:<uuid>)
// @Required 1
// @Maximum 5
// @Short Shows some text to the player.
// @Group player
//
// @Description
// Prints some text into the target's chat area. If no target is specified it will default to the attached player or the console.
//
// Accepts the 'format:<script>' argument, which will reformat the text according to the specified format script. See <@link language Format Script Containers>.
//
// Optionally use 'per_player' with a list of player targets, to have the tags in the text input be reparsed for each and every player.
// So, for example, "- narrate 'hello <player.name>' targets:<server.online_players>"
// would normally say "hello bob" to every player (every player sees the exact same name in the text, ie bob sees "hello bob", steve also sees "hello bob", etc)
// but if you use "per_player", each player online would see their own name (so bob sees "hello bob", steve sees "hello steve", etc).
//
// Optionally, specify 'from:<uuid>' to indicate that message came from a specific UUID (used for things like the vanilla client social interaction block option).
//
// @Tags
// None
//
// @Usage
// Use to narrate text to the player.
// - narrate "Hello World!"
//
// @Usage
// Use to narrate text to a list of players.
// - narrate "Hello there." targets:<[player]>|<[someplayer]>|<[thatplayer]>
//
// @Usage
// Use to narrate text to a unique message to every player on the server.
// - narrate "Hello <player.name>, your secret code is <util.random.duuid>." targets:<server.online_players> per_player
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : ArgumentHelper.interpret(scriptEntry, scriptEntry.getOriginalArguments())) {
if (!scriptEntry.hasObject("format") && arg.matchesPrefix("format", "f")) {
String formatStr = TagManager.tag(arg.getValue(), scriptEntry.getContext());
FormatScriptContainer format = ScriptRegistry.getScriptContainer(formatStr);
if (format == null) {
Debug.echoError("Could not find format script matching '" + formatStr + "'");
}
scriptEntry.addObject("format", new ScriptTag(format));
} else if (!scriptEntry.hasObject("targets") && arg.matchesPrefix("target", "targets", "t")) {
scriptEntry.addObject("targets", ListTag.getListFor(TagManager.tagObject(arg.getValue(), scriptEntry.getContext()), scriptEntry.getContext()).filter(PlayerTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("from") && arg.matchesPrefix("from")) {
scriptEntry.addObject("from", TagManager.tagObject(arg.getValue(), scriptEntry.getContext()));
} else if (!scriptEntry.hasObject("per_player") && arg.matches("per_player")) {
scriptEntry.addObject("per_player", new ElementTag(true));
} else if (!scriptEntry.hasObject("text")) {
scriptEntry.addObject("text", arg.getRawElement());
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("targets")) {
scriptEntry.addObject("targets", (Utilities.entryHasPlayer(scriptEntry) ? Collections.singletonList(Utilities.getEntryPlayer(scriptEntry)) : null));
}
if (!scriptEntry.hasObject("text")) {
throw new InvalidArgumentsException("Missing any text!");
}
}
use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.
the class ClickableCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
MapTag defMap = new MapTag();
for (Argument arg : scriptEntry) {
if (arg.matchesPrefix("defmap") && arg.matchesArgumentType(MapTag.class)) {
defMap.map.putAll(arg.asType(MapTag.class).map);
} else if (arg.hasPrefix() && arg.getPrefix().getRawValue().startsWith("def.")) {
defMap.putObject(arg.getPrefix().getRawValue().substring("def.".length()), arg.object);
} else if (!scriptEntry.hasObject("script")) {
String scriptName = arg.getRawValue();
int dotIndex = scriptName.indexOf('.');
if (dotIndex > 0) {
scriptEntry.addObject("path", new ElementTag(scriptName.substring(dotIndex + 1)));
scriptName = scriptName.substring(0, dotIndex);
}
ScriptTag script = new ScriptTag(scriptName);
if (!script.isValid()) {
arg.reportUnhandled();
} else {
scriptEntry.addObject("script", script);
}
} else {
arg.reportUnhandled();
}
}
if (!defMap.map.isEmpty()) {
scriptEntry.addObject("def_map", defMap);
}
}
use of com.denizenscript.denizencore.objects.Argument in project Denizen-For-Bukkit by DenizenScript.
the class ItemInventory method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("inventory_contents") && mechanism.hasValue()) {
List<ItemStack> items = new ArrayList<>();
for (ItemTag item : mechanism.valueAsType(ListTag.class).filter(ItemTag.class, mechanism.context)) {
items.add(item.getItemStack());
}
if (item.getItemMeta() instanceof BlockStateMeta) {
BlockStateMeta bsm = ((BlockStateMeta) item.getItemMeta());
InventoryHolder invHolder = (InventoryHolder) bsm.getBlockState();
if (items.size() > getInventoryFor(invHolder).getSize()) {
mechanism.echoError("Invalid inventory_contents input size; expected " + getInventoryFor(invHolder).getSize() + " or less.");
return;
}
getInventoryFor(invHolder).setContents(items.toArray(new ItemStack[0]));
bsm.setBlockState((BlockState) invHolder);
item.setItemMeta(bsm);
} else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17)) {
BundleMeta bundle = (BundleMeta) item.getItemMeta();
bundle.setItems(items);
item.setItemMeta(bundle);
}
}
if (mechanism.matches("inventory") && mechanism.hasValue()) {
Deprecations.itemInventoryTag.warn(mechanism.context);
Argument argument = new Argument("");
argument.unsetValue();
argument.object = mechanism.getValue();
Map.Entry<Integer, InventoryTag> inventoryPair = Conversion.getInventory(argument, mechanism.context);
if (inventoryPair == null || inventoryPair.getValue().getInventory() == null) {
return;
}
ListTag items = InventoryContents.getFrom(inventoryPair.getValue()).getContents(false);
ItemStack[] itemArray = new ItemStack[items.size()];
for (int i = 0; i < itemArray.length; i++) {
itemArray[i] = ((ItemTag) items.objectForms.get(i)).getItemStack().clone();
}
if (item.getItemMeta() instanceof BlockStateMeta) {
BlockStateMeta bsm = ((BlockStateMeta) item.getItemMeta());
InventoryHolder invHolder = (InventoryHolder) bsm.getBlockState();
if (items.size() > getInventoryFor(invHolder).getSize()) {
mechanism.echoError("Invalid inventory mechanism input size; expected " + getInventoryFor(invHolder).getSize() + " or less.");
return;
}
getInventoryFor(invHolder).setContents(itemArray);
bsm.setBlockState((BlockState) invHolder);
item.setItemMeta(bsm);
} else if (NMSHandler.getVersion().isAtLeast(NMSVersion.v1_17)) {
BundleMeta bundle = (BundleMeta) item.getItemMeta();
bundle.setItems(Arrays.asList(itemArray));
item.setItemMeta(bundle);
}
}
}
Aggregations