use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemRawNBT method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("raw_nbt") && mechanism.requireObject(MapTag.class)) {
MapTag input = mechanism.valueAsType(MapTag.class);
setFullNBT(item, input, mechanism.context, true);
}
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemAttributeModifiers method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("attribute_modifiers") && mechanism.requireObject(MapTag.class)) {
Multimap<org.bukkit.attribute.Attribute, AttributeModifier> metaMap = LinkedHashMultimap.create();
MapTag map = mechanism.valueAsType(MapTag.class);
for (Map.Entry<StringHolder, ObjectTag> mapEntry : map.map.entrySet()) {
org.bukkit.attribute.Attribute attr = org.bukkit.attribute.Attribute.valueOf(mapEntry.getKey().str.toUpperCase());
for (ObjectTag listValue : CoreUtilities.objectToList(mapEntry.getValue(), mechanism.context)) {
metaMap.put(attr, EntityAttributeModifiers.modiferForMap(attr, (MapTag) listValue));
}
}
ItemMeta meta = item.getItemMeta();
meta.setAttributeModifiers(metaMap);
item.setItemMeta(meta);
}
// -->
if (mechanism.matches("add_attribute_modifiers") && mechanism.requireObject(MapTag.class)) {
ItemMeta meta = item.getItemMeta();
MapTag input = mechanism.valueAsType(MapTag.class);
for (Map.Entry<StringHolder, ObjectTag> subValue : input.map.entrySet()) {
org.bukkit.attribute.Attribute attr = org.bukkit.attribute.Attribute.valueOf(subValue.getKey().str.toUpperCase());
for (ObjectTag listValue : CoreUtilities.objectToList(subValue.getValue(), mechanism.context)) {
meta.addAttributeModifier(attr, EntityAttributeModifiers.modiferForMap(attr, (MapTag) listValue));
}
}
item.setItemMeta(meta);
}
// -->
if (mechanism.matches("remove_attribute_modifiers") && mechanism.requireObject(ListTag.class)) {
ItemMeta meta = item.getItemMeta();
ArrayList<String> inputList = new ArrayList<>(mechanism.valueAsType(ListTag.class));
for (String toRemove : new ArrayList<>(inputList)) {
if (new ElementTag(toRemove).matchesEnum(org.bukkit.attribute.Attribute.class)) {
inputList.remove(toRemove);
org.bukkit.attribute.Attribute attr = org.bukkit.attribute.Attribute.valueOf(toRemove.toUpperCase());
meta.removeAttributeModifier(attr);
}
}
for (String toRemove : inputList) {
UUID id = UUID.fromString(toRemove);
Multimap<org.bukkit.attribute.Attribute, AttributeModifier> metaMap = meta.getAttributeModifiers();
for (org.bukkit.attribute.Attribute attribute : metaMap.keys()) {
for (AttributeModifier modifer : metaMap.get(attribute)) {
if (modifer.getUniqueId().equals(id)) {
meta.removeAttributeModifier(attribute, modifer);
break;
}
}
}
}
item.setItemMeta(meta);
}
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemAttributeModifiers method getAttributeModifiers.
public MapTag getAttributeModifiers() {
ItemMeta meta = item.getItemMeta();
if (meta == null) {
return null;
}
MapTag map = new MapTag();
Multimap<org.bukkit.attribute.Attribute, AttributeModifier> metaMap = meta.getAttributeModifiers();
if (metaMap == null) {
return map;
}
for (org.bukkit.attribute.Attribute attribute : metaMap.keys()) {
Collection<AttributeModifier> modifiers = metaMap.get(attribute);
if (modifiers.isEmpty()) {
continue;
}
ListTag subList = new ListTag();
for (AttributeModifier modifier : modifiers) {
subList.addObject(EntityAttributeModifiers.mapify(modifier));
}
map.putObject(attribute.name(), subList);
}
return map;
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemBaseColor method setBaseColor.
private void setBaseColor(DyeColor color, TagContext context) {
if (color == null && item.getBukkitMaterial() == Material.SHIELD) {
ItemRawNBT property = ItemRawNBT.getFrom(item);
MapTag nbt = property.getFullNBTMap();
nbt.putObject("BlockEntityTag", null);
property.setFullNBT(item, nbt, context, false);
return;
}
ItemMeta itemMeta = item.getItemMeta();
if (itemMeta instanceof BlockStateMeta) {
Banner banner = (Banner) ((BlockStateMeta) itemMeta).getBlockState();
banner.setBaseColor(color);
banner.update();
((BlockStateMeta) itemMeta).setBlockState(banner);
} else {
((BannerMeta) itemMeta).setBaseColor(color);
}
item.setItemMeta(itemMeta);
}
use of com.denizenscript.denizencore.objects.core.MapTag in project Denizen-For-Bukkit by DenizenScript.
the class ItemBook method getBookMap.
public MapTag getBookMap() {
MapTag outMap = new MapTag();
BookMeta bookInfo = (BookMeta) item.getItemMeta();
if (item.getBukkitMaterial().equals(Material.WRITTEN_BOOK) && bookInfo.hasAuthor() && bookInfo.hasTitle()) {
outMap.putObject("author", new ElementTag(bookInfo.getAuthor(), true));
outMap.putObject("title", new ElementTag(bookInfo.getTitle(), true));
}
if (bookInfo.hasPages()) {
List<BaseComponent[]> pages = bookInfo.spigot().getPages();
ListTag pageList = new ListTag(pages.size());
for (BaseComponent[] page : pages) {
pageList.addObject(new ElementTag(FormattedTextHelper.stringify(page, ChatColor.BLACK), true));
}
outMap.putObject("pages", pageList);
}
return outMap;
}
Aggregations