Skip to content

Commit

Permalink
fix: NMS exceptions being thrown when applying modifiers
Browse files Browse the repository at this point in the history
Spigot's validation for this is like my hoover: it sucks.
  • Loading branch information
WiIIiam278 committed Jun 22, 2024
1 parent d4e33aa commit 0c52720
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ private static Modifier adapt(@NotNull AttributeModifier modifier) {
@Nullable
private static UUID getModifierId(@NotNull AttributeModifier modifier) {
try {
return UUID.fromString(modifier.getName());
return modifier.getUniqueId();
} catch (Throwable e) {
return null;
}
Expand Down Expand Up @@ -656,10 +656,12 @@ private static AttributeModifier adapt(@NotNull Modifier modifier, @NotNull Husk
// 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)
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 0c52720

Please sign in to comment.