|
1 | 1 | package studio.magemonkey.divinity.modules; |
2 | 2 |
|
3 | 3 | import org.apache.commons.lang3.ArrayUtils; |
| 4 | +import org.bukkit.Bukkit; |
4 | 5 | import org.bukkit.Color; |
5 | 6 | import org.bukkit.Material; |
6 | 7 | import org.bukkit.NamespacedKey; |
7 | 8 | import org.bukkit.attribute.Attribute; |
8 | 9 | import org.bukkit.attribute.AttributeModifier; |
9 | 10 | import org.bukkit.configuration.InvalidConfigurationException; |
10 | 11 | import org.bukkit.enchantments.Enchantment; |
| 12 | +import org.bukkit.inventory.EquipmentSlot; |
11 | 13 | import org.bukkit.inventory.ItemFlag; |
12 | 14 | import org.bukkit.inventory.ItemStack; |
13 | 15 | import org.bukkit.inventory.meta.*; |
@@ -135,16 +137,25 @@ public ModuleItem(@NotNull Divinity plugin, @NotNull JYML cfg, @NotNull QModuleD |
135 | 137 |
|
136 | 138 | this.attributes = new HashMap<>(); |
137 | 139 | for (String attr : cfg.getSection("attributes")) { |
138 | | - String[] attrData = cfg.getString("attributes." + attr, "").split(":"); |
139 | | - double value = Double.parseDouble(attrData[0]); |
140 | | - String operation = attrData.length > 1 ? attrData[1] : "ADD_NUMBER"; |
141 | | - NBTAttribute nbtAttr = NBTAttribute.valueOf(attr.toUpperCase()); |
142 | | - AttributeModifier attrModifier = VersionManager.getCompat() |
143 | | - .createAttributeModifier(nbtAttr, value, AttributeModifier.Operation.valueOf(operation)); |
| 140 | + String[] attrData = cfg.getString("attributes." + attr, "").split(":"); |
| 141 | + double value = Double.parseDouble(attrData[0]); |
| 142 | + String operation = attrData.length > 1 ? attrData[1] : "ADD_NUMBER"; |
| 143 | + String equipmentSlot = attrData.length > 2 ? attrData[2] : null; |
| 144 | + NBTAttribute nbtAttr = NBTAttribute.valueOf(attr.toUpperCase()); |
| 145 | + |
| 146 | + // Check attribute through compat support |
| 147 | + AttributeModifier attrModifier = VersionManager.getCompat().createAttributeModifier(nbtAttr, value, AttributeModifier.Operation.valueOf(operation)); |
144 | 148 | if (attrModifier == null) { |
145 | 149 | Codex.warn("Invalid attribute provided: " + attr + " (" + cfg.getFile().getName() + ")"); |
146 | 150 | continue; |
147 | 151 | } |
| 152 | + // If everything was fine and equipmentslot != null, recreate the modifier including the equipment slot |
| 153 | + if(equipmentSlot != null) { |
| 154 | + EquipmentSlot slot = EquipmentSlot.valueOf(equipmentSlot.toUpperCase()); |
| 155 | + attrModifier = new AttributeModifier(attrModifier.getUniqueId(), attrModifier.getName(), attrModifier.getAmount(), attrModifier.getOperation(), slot); |
| 156 | + // Debug |
| 157 | + Bukkit.getLogger().info("Registered attribute " + nbtAttr.name() + " with value " + value + ", operation " + operation + " and equipment slot " + equipmentSlot + " for item " + this.getId()); |
| 158 | + } |
148 | 159 | this.attributes.put(nbtAttr.getAttribute(), attrModifier); |
149 | 160 | } |
150 | 161 |
|
@@ -277,6 +288,7 @@ protected ItemStack build(@NotNull ItemStack item) { |
277 | 288 |
|
278 | 289 | for (Map.Entry<Attribute, AttributeModifier> attribute : this.attributes.entrySet()) { |
279 | 290 | if (attribute != null) { |
| 291 | + AttributeModifier mod = new AttributeModifier(attribute.getValue().getName(), attribute.getValue().getAmount(), attribute.getValue().getOperation()); |
280 | 292 | meta.addAttributeModifier(attribute.getKey(), attribute.getValue()); |
281 | 293 | } |
282 | 294 | } |
|
0 commit comments