11package studio .magemonkey .divinity .stats .items ;
22
3+ import org .bukkit .Bukkit ;
34import org .bukkit .Keyed ;
45import org .bukkit .NamespacedKey ;
56import org .bukkit .attribute .Attribute ;
@@ -310,7 +311,10 @@ public static void updateVanillaAttributes(@NotNull ItemStack item, @Nullable Pl
310311 addAttribute (item , player , NBTAttribute .MAX_HEALTH , getStat (item , player , TypedStat .Type .MAX_HEALTH ));
311312 addAttribute (item , player , NBTAttribute .MOVEMENT_SPEED , getStat (item , player , TypedStat .Type .MOVEMENT_SPEED ));
312313 addAttribute (item , player , NBTAttribute .ATTACK_SPEED , getStat (item , player , TypedStat .Type .ATTACK_SPEED ));
313- addAttribute (item , player , NBTAttribute .KNOCKBACK_RESISTANCE , getStat (item , player , TypedStat .Type .KNOCKBACK_RESISTANCE ));
314+ addAttribute (item ,
315+ player ,
316+ NBTAttribute .KNOCKBACK_RESISTANCE ,
317+ getStat (item , player , TypedStat .Type .KNOCKBACK_RESISTANCE ));
314318
315319 double vanilla = DamageAttribute .getVanillaDamage (item );
316320 if (vanilla > 1 ) addAttribute (item , player , NBTAttribute .ATTACK_DAMAGE , vanilla );
@@ -324,12 +328,16 @@ public static void updateVanillaAttributes(@NotNull ItemStack item, @Nullable Pl
324328 toughness == 0 ? DefenseAttribute .getVanillaToughness (item ) : toughness );
325329 }
326330 ItemMeta im = item .getItemMeta ();
331+ if (im == null ) {
332+ im = Bukkit .getItemFactory ().getItemMeta (item .getType ());
333+ }
327334
328335 // For 1.20.4+, the HIDE_ATTRIBUTES flag doesn't work unless an attribute has been added that's not the default.
329336 // Note: This only applies to Paper and its forks.
330337 if (Version .CURRENT .isAtLeast (Version .V1_20_R4 )) {
331338 Attribute moveSpeed = VersionManager .getNms ().getAttribute ("MOVEMENT_SPEED" );
332- if (im .getAttributeModifiers (VersionManager .getNms ().getAttribute ("MOVEMENT_SPEED" )) == null ) {
339+ if (!im .hasAttributeModifiers ()
340+ || im .getAttributeModifiers (VersionManager .getNms ().getAttribute ("MOVEMENT_SPEED" )) == null ) {
333341 //noinspection RedundantCast
334342 im .addAttributeModifier (moveSpeed ,
335343 new AttributeModifier (((Keyed ) moveSpeed ).getKey ().getKey (), 0 , Operation .ADD_NUMBER ));
0 commit comments