Search in sources :

Example 6 with EntityAttribute

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));
}
Also used : EntityAttribute(net.aufdemrand.denizen.nms.enums.EntityAttribute) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CompoundTag_v1_11_R1(net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_11_R1) ArrayList(java.util.ArrayList) List(java.util.List) EntityAttributeModifier(net.aufdemrand.denizen.nms.util.EntityAttributeModifier) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map)

Example 7 with EntityAttribute

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;
}
Also used : EntityAttribute(net.aufdemrand.denizen.nms.enums.EntityAttribute) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) EntityAttributeModifier(net.aufdemrand.denizen.nms.util.EntityAttributeModifier) UUID(java.util.UUID)

Example 8 with EntityAttribute

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));
}
Also used : EntityAttribute(net.aufdemrand.denizen.nms.enums.EntityAttribute) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CompoundTag_v1_10_R1(net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_10_R1) EntityAttributeModifier(net.aufdemrand.denizen.nms.util.EntityAttributeModifier) UUID(java.util.UUID) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 List (java.util.List)8 UUID (java.util.UUID)8 EntityAttribute (net.aufdemrand.denizen.nms.enums.EntityAttribute)8 EntityAttributeModifier (net.aufdemrand.denizen.nms.util.EntityAttributeModifier)8 Map (java.util.Map)4 CompoundTag_v1_10_R1 (net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_10_R1)1 CompoundTag_v1_11_R1 (net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_11_R1)1 CompoundTag_v1_8_R3 (net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_8_R3)1 CompoundTag_v1_9_R2 (net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_9_R2)1