use of net.aufdemrand.denizen.nms.enums.EntityAttribute in project Denizen-For-Bukkit by DenizenScript.
the class ItemHelper_v1_11_R1 method setAttributeModifiers.
@Override
public ItemStack setAttributeModifiers(ItemStack itemStack, Map<EntityAttribute, List<EntityAttributeModifier>> modifiers) {
List<Tag> modifierList = new ArrayList<Tag>(getNbtData(itemStack).getList("AttributeModifiers"));
for (Map.Entry<EntityAttribute, List<EntityAttributeModifier>> entry : modifiers.entrySet()) {
EntityAttribute attribute = entry.getKey();
for (EntityAttributeModifier modifier : entry.getValue()) {
Map<String, Tag> compound = new HashMap<String, Tag>();
compound.put("AttributeName", new StringTag(attribute.getName()));
UUID uuid = modifier.getUniqueId();
compound.put("UUIDMost", new LongTag(uuid.getMostSignificantBits()));
compound.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits()));
compound.put("Name", new StringTag(modifier.getName()));
compound.put("Operation", new IntTag(modifier.getOperation().ordinal()));
compound.put("Amount", new DoubleTag(modifier.getAmount()));
modifierList.add(new CompoundTag_v1_11_R1(compound));
}
}
return addNbtData(itemStack, "AttributeModifiers", new ListTag(CompoundTag.class, modifierList));
}
use of net.aufdemrand.denizen.nms.enums.EntityAttribute in project Denizen-For-Bukkit by DenizenScript.
the class ItemHelper_v1_10_R1 method getAttributeModifiers.
@Override
public Map<EntityAttribute, List<EntityAttributeModifier>> getAttributeModifiers(ItemStack itemStack) {
Map<EntityAttribute, List<EntityAttributeModifier>> modifiers = new HashMap<EntityAttribute, List<EntityAttributeModifier>>();
List<Tag> modifierList = getNbtData(itemStack).getList("AttributeModifiers");
for (Tag tag : modifierList) {
if (!(tag instanceof CompoundTag)) {
continue;
}
CompoundTag modifier = (CompoundTag) tag;
EntityAttribute attribute = EntityAttribute.getByName(modifier.getString("AttributeName"));
if (attribute == null) {
continue;
}
if (!modifiers.containsKey(attribute)) {
modifiers.put(attribute, new ArrayList<EntityAttributeModifier>());
}
UUID uuid = new UUID(modifier.getLong("UUIDMost"), modifier.getLong("UUIDLeast"));
String name = modifier.getString("Name");
EntityAttributeModifier.Operation operation = EntityAttributeModifier.Operation.values()[modifier.getInt("Operation")];
if (operation == null) {
continue;
}
double amount = modifier.getDouble("Amount");
modifiers.get(attribute).add(new EntityAttributeModifier(uuid, name, operation, amount));
}
return modifiers;
}
use of net.aufdemrand.denizen.nms.enums.EntityAttribute in project Denizen-For-Bukkit by DenizenScript.
the class ItemHelper_v1_10_R1 method setAttributeModifiers.
@Override
public ItemStack setAttributeModifiers(ItemStack itemStack, Map<EntityAttribute, List<EntityAttributeModifier>> modifiers) {
List<Tag> modifierList = new ArrayList<Tag>(getNbtData(itemStack).getList("AttributeModifiers"));
for (Map.Entry<EntityAttribute, List<EntityAttributeModifier>> entry : modifiers.entrySet()) {
EntityAttribute attribute = entry.getKey();
for (EntityAttributeModifier modifier : entry.getValue()) {
Map<String, Tag> compound = new HashMap<String, Tag>();
compound.put("AttributeName", new StringTag(attribute.getName()));
UUID uuid = modifier.getUniqueId();
compound.put("UUIDMost", new LongTag(uuid.getMostSignificantBits()));
compound.put("UUIDLeast", new LongTag(uuid.getLeastSignificantBits()));
compound.put("Name", new StringTag(modifier.getName()));
compound.put("Operation", new IntTag(modifier.getOperation().ordinal()));
compound.put("Amount", new DoubleTag(modifier.getAmount()));
modifierList.add(new CompoundTag_v1_10_R1(compound));
}
}
return addNbtData(itemStack, "AttributeModifiers", new ListTag(CompoundTag.class, modifierList));
}
Aggregations