From 0c527202e52425bd2eba4ab11da239db49187626 Mon Sep 17 00:00:00 2001 From: William Date: Sat, 22 Jun 2024 18:07:53 +0100 Subject: [PATCH] fix: NMS exceptions being thrown when applying modifiers Spigot's validation for this is like my hoover: it sucks. --- .../main/java/net/william278/husksync/data/BukkitData.java | 6 ++++-- gradle.properties | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/bukkit/src/main/java/net/william278/husksync/data/BukkitData.java b/bukkit/src/main/java/net/william278/husksync/data/BukkitData.java index 26b04142..e4b53c68 100644 --- a/bukkit/src/main/java/net/william278/husksync/data/BukkitData.java +++ b/bukkit/src/main/java/net/william278/husksync/data/BukkitData.java @@ -625,7 +625,7 @@ public abstract class BukkitData implements Data { @Nullable private static UUID getModifierId(@NotNull AttributeModifier modifier) { try { - return UUID.fromString(modifier.getName()); + return modifier.getUniqueId(); } catch (Throwable e) { return null; } @@ -656,10 +656,12 @@ public abstract class BukkitData implements Data { // Reflexively create a modern keyed attribute modifier instance. Remove in favor of API long-term. final EquipmentSlot slot = slotId != -1 ? EquipmentSlot.values()[slotId] : null; final Class slotGroup = Class.forName(EQUIPMENT_SLOT_GROUP); + final String modifierName = modifier.name() == null ? modifier.uuid().toString() : modifier.name(); return AttributeModifier.class.getDeclaredConstructor( NamespacedKey.class, double.class, AttributeModifier.Operation.class, slotGroup ).newInstance( - NamespacedKey.fromString(modifier.name()), modifier.amount(), + NamespacedKey.fromString(modifierName), + modifier.amount(), AttributeModifier.Operation.values()[modifier.operationType()], slot == null ? slotGroup.getField(EQUIPMENT_SLOT_GROUP$ANY).get(null) : EquipmentSlot.class.getDeclaredMethod(EQUIPMENT_SLOT$getGroup).invoke(slot) diff --git a/gradle.properties b/gradle.properties index cedb7c44..88376ced 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs='-Dfile.encoding=UTF-8' org.gradle.daemon=true javaVersion=17 -plugin_version=3.6.4 +plugin_version=3.6.5 plugin_archive=husksync plugin_description=A modern, cross-server player data synchronization system