44import org .bukkit .Color ;
55import org .bukkit .Material ;
66import org .bukkit .NamespacedKey ;
7+ import org .bukkit .attribute .Attribute ;
8+ import org .bukkit .attribute .AttributeModifier ;
79import org .bukkit .configuration .InvalidConfigurationException ;
810import org .bukkit .enchantments .Enchantment ;
911import org .bukkit .inventory .ItemFlag ;
1012import org .bukkit .inventory .ItemStack ;
11- import org .bukkit .inventory .meta .Damageable ;
12- import org .bukkit .inventory .meta .ItemMeta ;
13- import org .bukkit .inventory .meta .LeatherArmorMeta ;
14- import org .bukkit .inventory .meta .PotionMeta ;
13+ import org .bukkit .inventory .meta .*;
1514import org .jetbrains .annotations .NotNull ;
15+ import studio .magemonkey .codex .Codex ;
1616import studio .magemonkey .codex .CodexEngine ;
1717import studio .magemonkey .codex .api .items .ItemType ;
1818import studio .magemonkey .codex .api .items .exception .MissingItemException ;
1919import studio .magemonkey .codex .api .items .exception .MissingProviderException ;
2020import studio .magemonkey .codex .api .items .providers .VanillaProvider ;
21+ import studio .magemonkey .codex .api .meta .NBTAttribute ;
22+ import studio .magemonkey .codex .compat .VersionManager ;
2123import studio .magemonkey .codex .config .api .JYML ;
2224import studio .magemonkey .codex .manager .LoadableItem ;
2325import studio .magemonkey .codex .util .ItemUT ;
3840import java .util .*;
3941
4042public abstract class ModuleItem extends LoadableItem {
41- protected final QModuleDrop <?> module ;
42- protected Divinity plugin ;
43- protected String name ;
44- protected ItemType material ;
45- protected List <String > lore ;
46- protected int modelData ;
47- protected int durability ;
48- protected int [] color ;
49- protected boolean enchanted ;
50- protected String hash ;
51- protected Set <ItemFlag > flags ;
52- protected boolean isUnbreakable ;
53- protected Map <Enchantment , Integer > enchants ;
43+ protected final QModuleDrop <?> module ;
44+ protected Divinity plugin ;
45+ protected String name ;
46+ protected ItemType material ;
47+ protected List <String > lore ;
48+ protected int modelData ;
49+ protected int durability ;
50+ protected int [] color ;
51+ protected boolean enchanted ;
52+ protected String hash ;
53+ protected Set <ItemFlag > flags ;
54+ protected boolean isUnbreakable ;
55+ protected Map <Enchantment , Integer > enchants ;
56+ protected String armorTrim ;
57+ protected Map <Attribute , AttributeModifier > attributes ;
5458
5559 // Creating new config
5660 @ Deprecated
@@ -99,6 +103,7 @@ public ModuleItem(@NotNull Divinity plugin, @NotNull JYML cfg, @NotNull QModuleD
99103
100104 this .enchanted = cfg .getBoolean ("enchanted" );
101105 this .hash = cfg .getString ("skull-hash" );
106+ this .armorTrim = cfg .getString ("armor-trim" );
102107
103108 this .flags = new HashSet <>();
104109 for (String flag : cfg .getStringList ("item-flags" )) {
@@ -128,6 +133,21 @@ public ModuleItem(@NotNull Divinity plugin, @NotNull JYML cfg, @NotNull QModuleD
128133 this .enchants .put (en , level );
129134 }
130135
136+ this .attributes = new HashMap <>();
137+ 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 ));
144+ if (attrModifier == null ) {
145+ Codex .warn ("Invalid attribute provided: " + attr + " (" + cfg .getFile ().getName () + ")" );
146+ continue ;
147+ }
148+ this .attributes .put (nbtAttr .getAttribute (), attrModifier );
149+ }
150+
131151 cfg .saveChanges ();
132152 }
133153
@@ -234,9 +254,18 @@ protected ItemStack build(@NotNull ItemStack item) {
234254 if (meta instanceof LeatherArmorMeta ) {
235255 LeatherArmorMeta lm = (LeatherArmorMeta ) meta ;
236256 lm .setColor (Color .fromRGB (r , g , b ));
257+ if (this .armorTrim != null ) {
258+ String [] trimData = this .armorTrim .split (":" );
259+ VersionManager .getArmorUtil ().addTrim (meta , trimData [0 ].toLowerCase (), trimData [1 ].toLowerCase ());
260+ }
237261 } else if (meta instanceof PotionMeta ) {
238262 PotionMeta pm = (PotionMeta ) meta ;
239263 pm .setColor (Color .fromRGB (r , g , b ));
264+ } else if (meta instanceof ArmorMeta ) {
265+ if (this .armorTrim != null ) {
266+ String [] trimData = this .armorTrim .split (":" );
267+ VersionManager .getArmorUtil ().addTrim (meta , trimData [0 ].toLowerCase (), trimData [1 ].toLowerCase ());
268+ }
240269 }
241270 }
242271
@@ -246,6 +275,11 @@ protected ItemStack build(@NotNull ItemStack item) {
246275 meta .addEnchant (NamespaceResolver .getEnchantment ("POWER" , "ARROW_DAMAGE" ), 1 , true ); // ARROW_DAMAGE/POWER
247276 }
248277
278+ for (Map .Entry <Attribute , AttributeModifier > attribute : this .attributes .entrySet ()) {
279+ if (attribute != null ) {
280+ meta .addAttributeModifier (attribute .getKey (), attribute .getValue ());
281+ }
282+ }
249283 item .setItemMeta (meta );
250284
251285 for (Map .Entry <Enchantment , Integer > e : this .enchants .entrySet ()) {
0 commit comments