use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class GiveCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag unlimit_stack_size = scriptEntry.getElement("unlimit_stack_size");
InventoryTag inventory = scriptEntry.getObjectTag("inventory");
ElementTag quantity = scriptEntry.getElement("quantity");
Type type = (Type) scriptEntry.getObject("type");
ElementTag slot = scriptEntry.getElement("slot");
Object items_object = scriptEntry.getObject("items");
List<ItemTag> items = null;
if (items_object != null) {
items = (List<ItemTag>) items_object;
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("Type", type.name()), inventory, quantity, unlimit_stack_size, db("Items", items), slot);
}
switch(type) {
case MONEY:
if (Depends.economy != null) {
Depends.economy.depositPlayer(Utilities.getEntryPlayer(scriptEntry).getOfflinePlayer(), quantity.asDouble());
} else {
Debug.echoError("No economy loaded! Have you installed Vault and a compatible economy plugin?");
}
break;
case EXP:
Utilities.getEntryPlayer(scriptEntry).getPlayerEntity().giveExp(quantity.asInt());
break;
case ITEM:
boolean set_quantity = scriptEntry.hasObject("set_quantity");
boolean limited = !unlimit_stack_size.asBoolean();
for (ItemTag item : items) {
ItemStack is = item.getItemStack();
if (is.getType() == Material.AIR) {
Debug.echoError("Cannot give air!");
continue;
}
if (set_quantity) {
is.setAmount(quantity.asInt());
}
int slotId = SlotHelper.nameToIndexFor(slot.asString(), inventory.getInventory().getHolder());
if (slotId == -1) {
Debug.echoError(scriptEntry, "The input '" + slot.asString() + "' is not a valid slot!");
return;
}
List<ItemStack> leftovers = inventory.addWithLeftovers(slotId, limited, is);
if (!leftovers.isEmpty()) {
Debug.echoDebug(scriptEntry, "The inventory didn't have enough space, the rest of the items have been placed on the floor.");
for (ItemStack leftoverItem : leftovers) {
inventory.getLocation().getWorld().dropItem(inventory.getLocation(), leftoverItem);
}
}
}
break;
}
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class ScribeCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (arg.matchesEnum(BookAction.class) && !scriptEntry.hasObject("action")) {
scriptEntry.addObject("action", BookAction.valueOf(arg.getValue().toUpperCase()));
} else if (!scriptEntry.hasObject("script") && arg.matchesArgumentType(ScriptTag.class)) {
scriptEntry.addObject("script", arg.asType(ScriptTag.class));
} else if (!scriptEntry.hasObject("location") && arg.matchesArgumentType(LocationTag.class)) {
scriptEntry.addObject("location", arg.asType(LocationTag.class));
scriptEntry.addObject("action", BookAction.DROP);
} else if (!scriptEntry.hasObject("item") && arg.matchesArgumentType(ItemTag.class)) {
scriptEntry.addObject("item", arg.asType(ItemTag.class));
} else {
arg.reportUnhandled();
}
}
scriptEntry.defaultObject("action", BookAction.GIVE);
scriptEntry.defaultObject("item", new ItemTag(Material.WRITTEN_BOOK));
// Must contain a book script
if (!scriptEntry.hasObject("script")) {
throw new InvalidArgumentsException("Missing SCRIPT argument!");
}
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class EquipCommand method parseArgs.
// <--[command]
// @Name Equip
// @Syntax equip (<entity>|...) (hand:<item>) (offhand:<item>) (head:<item>) (chest:<item>) (legs:<item>) (boots:<item>) (saddle:<item>) (horse_armor:<item>)
// @Required 1
// @Maximum 9
// @Short Equips items and armor on a list of entities.
// @Group entity
//
// @Description
// This command equips an item or armor to an entity or list of entities to the specified slot(s).
// Set the item to 'air' to unequip any slot.
//
// @Tags
// <EntityTag.equipment>
// <InventoryTag.equipment>
//
// @Usage
// Use to equip a stone block on the player's head.
// - equip <player> head:stone
//
// @Usage
// Use to equip an iron helmet on two defined players.
// - equip <[player]>|<[someplayer]> head:iron_helmet
//
// @Usage
// Use to unequip all armor off the player.
// - equip <player> head:air chest:air legs:air boots:air
//
// @Usage
// Use to equip a saddle on the horse the player is riding.
// - equip <player.vehicle> saddle:saddle
//
// @Usage
// Use to equip a saddle on all nearby pigs.
// - equip <player.location.find_entities[pig].within[10]> saddle:saddle
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
Map<String, ItemTag> equipment = new HashMap<>();
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.matchesArgumentType(ItemTag.class) && arg.matchesPrefix("head", "helmet")) {
equipment.put("head", ItemTag.valueOf(arg.getValue(), scriptEntry.getContext()));
} else if (arg.matchesArgumentType(ItemTag.class) && arg.matchesPrefix("chest", "chestplate")) {
equipment.put("chest", ItemTag.valueOf(arg.getValue(), scriptEntry.getContext()));
} else if (arg.matchesArgumentType(ItemTag.class) && arg.matchesPrefix("legs", "leggings")) {
equipment.put("legs", ItemTag.valueOf(arg.getValue(), scriptEntry.getContext()));
} else if (arg.matchesArgumentType(ItemTag.class) && arg.matchesPrefix("boots", "feet")) {
equipment.put("boots", ItemTag.valueOf(arg.getValue(), scriptEntry.getContext()));
} else if (arg.matchesArgumentType(ItemTag.class) && arg.matchesPrefix("saddle")) {
equipment.put("saddle", ItemTag.valueOf(arg.getValue(), scriptEntry.getContext()));
} else if (arg.matchesArgumentType(ItemTag.class) && arg.matchesPrefix("horse_armor", "horse_armour")) {
equipment.put("horse_armor", ItemTag.valueOf(arg.getValue(), scriptEntry.getContext()));
} else if (arg.matchesArgumentType(ItemTag.class) && arg.matchesPrefix("offhand")) {
equipment.put("offhand", ItemTag.valueOf(arg.getValue(), scriptEntry.getContext()));
} else // Default to item in hand if no prefix is used
if (arg.matchesArgumentType(ItemTag.class)) {
equipment.put("hand", ItemTag.valueOf(arg.getValue(), scriptEntry.getContext()));
} else if (arg.matches("player") && Utilities.entryHasPlayer(scriptEntry)) {
// Player arg for compatibility with old scripts
scriptEntry.addObject("entities", Collections.singletonList(Utilities.getEntryPlayer(scriptEntry).getDenizenEntity()));
} else {
arg.reportUnhandled();
}
}
if (equipment.isEmpty()) {
throw new InvalidArgumentsException("Must specify equipment!");
}
scriptEntry.addObject("equipment", equipment);
scriptEntry.defaultObject("entities", Utilities.entryDefaultEntityList(scriptEntry, false));
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class TradeInputs method adjust.
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("inputs")) {
List<ItemStack> ingredients = new ArrayList<>();
List<ItemTag> list = mechanism.valueAsType(ListTag.class).filter(ItemTag.class, mechanism.context);
if (!mechanism.hasValue() || list.isEmpty()) {
recipe.getRecipe().setIngredients(ingredients);
return;
}
for (ItemTag item : list) {
ingredients.add(item.getItemStack());
}
if (ingredients.size() > 2) {
mechanism.echoError("Trade recipe input was given " + list.size() + " items. Only using the first two items!");
ingredients = ingredients.subList(0, 2);
}
recipe.getRecipe().setIngredients(ingredients);
}
}
use of com.denizenscript.denizen.objects.ItemTag in project Denizen-For-Bukkit by DenizenScript.
the class ToastCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag text = scriptEntry.getElement("text");
ElementTag frame = scriptEntry.getElement("frame");
ItemTag icon = scriptEntry.getObjectTag("icon");
final List<PlayerTag> targets = (List<PlayerTag>) scriptEntry.getObject("targets");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, name, text, frame, icon, db("targets", targets));
}
final Advancement advancement = new Advancement(true, new NamespacedKey(Denizen.getInstance(), UUID.randomUUID().toString()), null, icon.getItemStack(), text.asString(), "", null, Advancement.Frame.valueOf(frame.asString().toUpperCase()), true, false, true, 0, 0, 1);
final AdvancementHelper advancementHelper = NMSHandler.getAdvancementHelper();
for (PlayerTag target : targets) {
Player player = target.getPlayerEntity();
if (player != null) {
advancementHelper.grant(advancement, player);
advancementHelper.revoke(advancement, player);
}
}
}
Aggregations