use of org.bukkit.attribute.AttributeModifier 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 org.bukkit.attribute.AttributeModifier 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 org.bukkit.attribute.AttributeModifier in project Arcade2 by ShootGame.
the class ItemAttributeModifierParser method parseNode.
@Override
protected ParserResult<ItemAttributeModifier> parseNode(Node node, String name, String value) throws ParserException {
EquipmentSlot slot = this.slotParser.parse(node.property("slot", "equipment-slot", "equipmentslot")).orDefaultNull();
AttributeModifier modifier = this.modifierParser.parseWithDefinition(node, name, value).orFail();
return ParserResult.fine(node, name, value, new ItemAttributeModifier(slot, modifier));
}
use of org.bukkit.attribute.AttributeModifier in project NoCheatPlus by NoCheatPlus.
the class BukkitAttributeAccess method getSprintAttributeMultiplier.
@Override
public double getSprintAttributeMultiplier(final Player player) {
final AttributeInstance attrInst = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
final AttributeModifier mod = getModifier(attrInst, AttribUtil.ID_SPRINT_BOOST);
return mod == null ? 1.0 : getMultiplier(mod);
}
use of org.bukkit.attribute.AttributeModifier in project NoCheatPlus by NoCheatPlus.
the class BukkitAttributeAccess method getSpeedAttributeMultiplier.
@Override
public double getSpeedAttributeMultiplier(final Player player) {
final AttributeInstance attrInst = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED);
final double val = attrInst.getValue() / attrInst.getBaseValue();
final AttributeModifier mod = getModifier(attrInst, AttribUtil.ID_SPRINT_BOOST);
return mod == null ? val : (val / getMultiplier(mod));
}
Aggregations