Skip to content

Commit

Permalink
add inventory.equipment_map
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jul 13, 2020
1 parent 7749f32 commit b12e75c
Showing 1 changed file with 40 additions and 0 deletions.
Expand Up @@ -16,6 +16,7 @@
import com.denizenscript.denizen.tags.BukkitTagContext;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.core.MapTag;
import com.denizenscript.denizencore.objects.notable.Notable;
import com.denizenscript.denizencore.objects.notable.Note;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
Expand Down Expand Up @@ -759,6 +760,32 @@ public ItemStack[] getStorageContents() {
}
}

public static void addToMapIfNonAir(MapTag map, String name, ItemStack item) {
if (item == null || item.getType() == Material.AIR) {
return;
}
map.putObject(name, new ItemTag(item));
}

public MapTag getEquipmentMap() {
MapTag output = new MapTag();
if (inventory instanceof PlayerInventory) {
ItemStack[] equipment = ((PlayerInventory) inventory).getArmorContents();
addToMapIfNonAir(output, "boots", equipment[0]);
addToMapIfNonAir(output, "leggings", equipment[1]);
addToMapIfNonAir(output, "chestplate", equipment[2]);
addToMapIfNonAir(output, "helmet", equipment[3]);
}
else if (inventory instanceof HorseInventory) {
addToMapIfNonAir(output, "saddle", ((HorseInventory) inventory).getSaddle());
addToMapIfNonAir(output, "armor", ((HorseInventory) inventory).getArmor());
}
else {
return null;
}
return output;
}

public ListTag getEquipment() {
ItemStack[] equipment = null;
if (inventory instanceof PlayerInventory) {
Expand Down Expand Up @@ -2274,6 +2301,19 @@ else if (slot > object.getInventory().getSize() - 1) {
return new ElementTag(object.inventory instanceof HorseInventory ? "HORSE" : object.getInventory().getType().name());
});

// <--[tag]
// @attribute <InventoryTag.equipment_map>
// @returns MapTag
// @description
// Returns a MapTag containing the inventory's equipment.
// Output keys for players are boots, leggings, chestplate, helmet.
// Output keys for horses are saddle, armor.
// Air items will be left out of the map.
// -->
registerTag("equipment_map", (attribute, object) -> {
return object.getEquipmentMap();
});

// <--[tag]
// @attribute <InventoryTag.equipment>
// @returns ListTag(ItemTag)
Expand Down

0 comments on commit b12e75c

Please sign in to comment.