mirror of
https://github.com/WiIIiam278/HuskSync.git
synced 2025-12-20 07:19:16 +00:00
fix: don't apply <1.21 attribute modifiers on >1.21 servers
This commit is contained in:
@@ -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,
|
private static void applyAttribute(@Nullable AttributeInstance instance, @Nullable Attribute attribute,
|
||||||
@NotNull HuskSync plugin) {
|
@NotNull HuskSync plugin) {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
@@ -647,6 +656,7 @@ public abstract class BukkitData implements Data {
|
|||||||
.filter(mod -> instance.getModifiers().stream().map(AttributeModifier::getName)
|
.filter(mod -> instance.getModifiers().stream().map(AttributeModifier::getName)
|
||||||
.noneMatch(n -> n.equals(mod.name())))
|
.noneMatch(n -> n.equals(mod.name())))
|
||||||
.distinct()
|
.distinct()
|
||||||
|
.filter(mod -> useKeyedModifiers(plugin) == !mod.hasUuid())
|
||||||
.forEach(mod -> instance.addModifier(adapt(mod, plugin)));
|
.forEach(mod -> instance.addModifier(adapt(mod, plugin)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -655,11 +665,7 @@ public abstract class BukkitData implements Data {
|
|||||||
@NotNull
|
@NotNull
|
||||||
private static AttributeModifier adapt(@NotNull Modifier modifier, @NotNull HuskSync plugin) {
|
private static AttributeModifier adapt(@NotNull Modifier modifier, @NotNull HuskSync plugin) {
|
||||||
final int slotId = modifier.equipmentSlot();
|
final int slotId = modifier.equipmentSlot();
|
||||||
if (USE_KEYED_MODIFIERS == TriState.NOT_SET) {
|
if (useKeyedModifiers(plugin)) {
|
||||||
boolean is1_21 = plugin.getMinecraftVersion().compareTo(Version.fromString("1.21")) >= 0;
|
|
||||||
USE_KEYED_MODIFIERS = TriState.byBoolean(is1_21);
|
|
||||||
}
|
|
||||||
if (USE_KEYED_MODIFIERS == TriState.TRUE) {
|
|
||||||
try {
|
try {
|
||||||
// Reflexively create a modern keyed attribute modifier instance. Remove in favor of API long-term.
|
// 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 EquipmentSlot slot = slotId != -1 ? EquipmentSlot.values()[slotId] : null;
|
||||||
|
|||||||
@@ -384,6 +384,10 @@ public interface Data {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasUuid() {
|
||||||
|
return uuid != null;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public UUID uuid() {
|
public UUID uuid() {
|
||||||
return uuid != null ? uuid : UUID.nameUUIDFromBytes(name.getBytes());
|
return uuid != null ? uuid : UUID.nameUUIDFromBytes(name.getBytes());
|
||||||
|
|||||||
Reference in New Issue
Block a user