fix: don't apply <1.21 attribute modifiers on >1.21 servers

feat/data-edit-commands
William 4 months ago
parent 845abf370a
commit 07da1c04ce
No known key found for this signature in database

@ -635,6 +635,15 @@ public abstract class BukkitData implements Data {
}
}
private static boolean useKeyedModifiers(@NotNull HuskSync plugin) {
if (USE_KEYED_MODIFIERS == TriState.NOT_SET) {
boolean is1_21 = plugin.getMinecraftVersion().compareTo(Version.fromString("1.21")) >= 0;
USE_KEYED_MODIFIERS = TriState.byBoolean(is1_21);
return is1_21;
}
return Boolean.TRUE.equals(USE_KEYED_MODIFIERS.toBoolean());
}
private static void applyAttribute(@Nullable AttributeInstance instance, @Nullable Attribute attribute,
@NotNull HuskSync plugin) {
if (instance == null) {
@ -647,6 +656,7 @@ public abstract class BukkitData implements Data {
.filter(mod -> instance.getModifiers().stream().map(AttributeModifier::getName)
.noneMatch(n -> n.equals(mod.name())))
.distinct()
.filter(mod -> useKeyedModifiers(plugin) == !mod.hasUuid())
.forEach(mod -> instance.addModifier(adapt(mod, plugin)));
}
}
@ -655,11 +665,7 @@ public abstract class BukkitData implements Data {
@NotNull
private static AttributeModifier adapt(@NotNull Modifier modifier, @NotNull HuskSync plugin) {
final int slotId = modifier.equipmentSlot();
if (USE_KEYED_MODIFIERS == TriState.NOT_SET) {
boolean is1_21 = plugin.getMinecraftVersion().compareTo(Version.fromString("1.21")) >= 0;
USE_KEYED_MODIFIERS = TriState.byBoolean(is1_21);
}
if (USE_KEYED_MODIFIERS == TriState.TRUE) {
if (useKeyedModifiers(plugin)) {
try {
// Reflexively create a modern keyed attribute modifier instance. Remove in favor of API long-term.
final EquipmentSlot slot = slotId != -1 ? EquipmentSlot.values()[slotId] : null;

@ -384,6 +384,10 @@ public interface Data {
};
}
public boolean hasUuid() {
return uuid != null;
}
@NotNull
public UUID uuid() {
return uuid != null ? uuid : UUID.nameUUIDFromBytes(name.getBytes());

Loading…
Cancel
Save