use of org.bukkit.attribute.Attribute in project MagicPlugin by elBukkit.
the class CompatibilityUtils method removeItemAttributes.
@Override
public boolean removeItemAttributes(ItemStack item) {
if (item == null)
return false;
ItemMeta meta = item.getItemMeta();
if (meta == null)
return false;
Multimap<Attribute, AttributeModifier> modifiers = meta.getAttributeModifiers();
if (modifiers == null || modifiers.isEmpty()) {
return false;
}
for (Attribute attribute : modifiers.keySet()) {
meta.removeAttributeModifier(attribute);
}
item.setItemMeta(meta);
return true;
}
use of org.bukkit.attribute.Attribute in project MagicPlugin by elBukkit.
the class BaseMageModifier method getAttributeModifiers.
@Nullable
public Collection<EntityAttributeModifier> getAttributeModifiers() {
if (attributeModifiers != null) {
return attributeModifiers;
}
ConfigurationSection config = getConfigurationSection("entity_attributes");
if (config == null)
return null;
Set<String> keys = config.getKeys(false);
if (keys.isEmpty())
return null;
attributeModifiers = new ArrayList<>();
for (String key : keys) {
String name = "mage_" + getKey() + "_" + key;
double value;
Double base = null;
String attributeKey = key;
AttributeModifier.Operation operation = AttributeModifier.Operation.ADD_NUMBER;
if (config.isConfigurationSection(key)) {
ConfigurationSection modifierConfig = config.getConfigurationSection(key);
name = modifierConfig.getString("name", name);
attributeKey = modifierConfig.getString("attribute", attributeKey);
value = modifierConfig.getDouble("value");
String operationType = modifierConfig.getString("operation");
if (operationType != null && operationType.equalsIgnoreCase("base")) {
base = value;
} else if (operationType != null && !operationType.isEmpty()) {
try {
operation = AttributeModifier.Operation.valueOf(operationType.toUpperCase());
} catch (Exception ex) {
controller.getLogger().warning("Invalid operation " + operationType + " on entity_attributes." + key + " in mage class " + getKey());
}
}
} else {
value = config.getDouble(key);
}
Attribute attribute = null;
try {
attribute = Attribute.valueOf(attributeKey.toUpperCase());
} catch (Exception ex) {
controller.getLogger().warning("Invalid attribute " + attributeKey + " on entity_attributes." + key + " in mage class " + getKey());
}
if (attribute != null) {
if (base != null) {
attributeModifiers.add(new EntityAttributeModifier(attribute, base));
} else {
AttributeModifier modifier = new AttributeModifier(name, value, operation);
attributeModifiers.add(new EntityAttributeModifier(attribute, modifier));
}
}
}
return attributeModifiers;
}
use of org.bukkit.attribute.Attribute in project SwissKnife by EgirlsNationDev.
the class ItemUtil method removeAttributes.
public static void removeAttributes(ItemStack item) {
ItemMeta itemMeta = item.getItemMeta();
if (item.getItemMeta() == null)
return;
if (item.getItemMeta().getAttributeModifiers() == null)
return;
for (Attribute attribute : item.getItemMeta().getAttributeModifiers().keys()) {
itemMeta.removeAttributeModifier(attribute);
}
item.setItemMeta(itemMeta);
}
use of org.bukkit.attribute.Attribute in project SwissKnife by EgirlsNationDev.
the class EgirlsAttributeCorrector method getReducedDraconiteTotemMeta.
private ItemMeta getReducedDraconiteTotemMeta(ItemMeta meta) {
Multimap<Attribute, AttributeModifier> modifierMap = meta.getAttributeModifiers();
if (modifierMap == null)
return null;
if (modifierMap.size() == 2) {
Multimap<Attribute, AttributeModifier> offHandAttributes = meta.getAttributeModifiers(EquipmentSlot.OFF_HAND);
Multimap<Attribute, AttributeModifier> mainHandAttributes = meta.getAttributeModifiers(EquipmentSlot.HAND);
if (offHandAttributes == null || mainHandAttributes == null) {
return getCleanDraconiteTotemMeta(meta, modifierMap);
}
if (!offHandAttributes.containsKey(GENERIC_MAX_HEALTH) || !mainHandAttributes.containsKey(GENERIC_MAX_HEALTH)) {
return getCleanDraconiteTotemMeta(meta, modifierMap);
}
if (offHandAttributes.keys().size() > 1 || mainHandAttributes.keys().size() > 1) {
return getCleanDraconiteTotemMeta(meta, modifierMap);
} else {
meta.removeAttributeModifier(GENERIC_MAX_HEALTH);
meta.addAttributeModifier(Attribute.GENERIC_MAX_HEALTH, new AttributeModifier(UUID.randomUUID(), "max_health", Modules.get().get(DraconiteItems.class).additionalTotemHp.get(), AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.HAND));
meta.addAttributeModifier(Attribute.GENERIC_MAX_HEALTH, new AttributeModifier(UUID.randomUUID(), "max_health", Modules.get().get(DraconiteItems.class).additionalTotemHp.get(), AttributeModifier.Operation.ADD_NUMBER, EquipmentSlot.OFF_HAND));
return meta;
}
} else {
return getCleanDraconiteSwordMeta(meta, modifierMap);
}
}
use of org.bukkit.attribute.Attribute in project SwissKnife by EgirlsNationDev.
the class IllegalArmorAttributes method isArmorWithIllegalAttributes.
private boolean isArmorWithIllegalAttributes(ItemStack item) {
if (item == null)
return false;
if (!item.hasItemMeta())
return false;
Multimap<Attribute, AttributeModifier> attributeMultiMap = item.getItemMeta().getAttributeModifiers();
if (attributeMultiMap == null)
return false;
if (attributeMultiMap.isEmpty())
return false;
AtomicBoolean illegallyAttributed = new AtomicBoolean(false);
if (customAttributes.get()) {
Collection<AttributeModifier> armorAttribute = attributeMultiMap.get(Attribute.GENERIC_ARMOR);
Collection<AttributeModifier> armorToughnessAttribute = attributeMultiMap.get(Attribute.GENERIC_ARMOR_TOUGHNESS);
Collection<AttributeModifier> knockbackResistanceAttribute = attributeMultiMap.get(Attribute.GENERIC_KNOCKBACK_RESISTANCE);
Collection<AttributeModifier> maxHealthAttribute = attributeMultiMap.get(Attribute.GENERIC_MAX_HEALTH);
armorAttribute.forEach(attributeModifier -> {
if (attributeModifier.getAmount() > armor.get())
illegallyAttributed.set(true);
});
armorToughnessAttribute.forEach(attributeModifier -> {
if (attributeModifier.getAmount() > armorToughness.get())
illegallyAttributed.set(true);
});
knockbackResistanceAttribute.forEach(attributeModifier -> {
if (attributeModifier.getAmount() > knockbackResistance.get())
illegallyAttributed.set(true);
});
maxHealthAttribute.forEach(attributeModifier -> {
if (attributeModifier.getAmount() > maxHealth.get())
illegallyAttributed.set(true);
});
return illegallyAttributed.get();
}
return true;
}
Aggregations