mirror of
https://github.com/WiIIiam278/HuskSync.git
synced 2025-12-19 14:59:21 +00:00
fix: attribute syncing setting bad base value
This commit is contained in:
@@ -483,7 +483,7 @@ public abstract class BukkitData implements Data {
|
||||
}
|
||||
final int stat = p.getStatistic(id, material);
|
||||
if (stat != 0) {
|
||||
map.computeIfAbsent(id.getKey().getKey(), k -> Maps.newHashMap())
|
||||
map.compute(id.getKey().getKey(), (k, v) -> v == null ? Maps.newHashMap() : v)
|
||||
.put(material.getKey().getKey(), stat);
|
||||
}
|
||||
});
|
||||
@@ -497,21 +497,21 @@ public abstract class BukkitData implements Data {
|
||||
}
|
||||
final int stat = p.getStatistic(id, entity);
|
||||
if (stat != 0) {
|
||||
map.computeIfAbsent(id.getKey().getKey(), k -> Maps.newHashMap())
|
||||
map.compute(id.getKey().getKey(), (k, v) -> v == null ? Maps.newHashMap() : v)
|
||||
.put(entity.getKey().getKey(), stat);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(@NotNull BukkitUser user, @NotNull BukkitHuskSync plugin) {
|
||||
genericStatistics.forEach((id, v) -> applyStat(user, id, Statistic.Type.UNTYPED, v));
|
||||
blockStatistics.forEach((id, m) -> m.forEach((b, v) -> applyStat(user, id, Statistic.Type.BLOCK, v, b)));
|
||||
itemStatistics.forEach((id, m) -> m.forEach((i, v) -> applyStat(user, id, Statistic.Type.ITEM, v, i)));
|
||||
entityStatistics.forEach((id, m) -> m.forEach((e, v) -> applyStat(user, id, Statistic.Type.ENTITY, v, e)));
|
||||
public void apply(@NotNull BukkitUser user, @NotNull BukkitHuskSync p) {
|
||||
genericStatistics.forEach((k, v) -> applyStat(p, user, k, Statistic.Type.UNTYPED, v));
|
||||
blockStatistics.forEach((k, m) -> m.forEach((b, v) -> applyStat(p, user, k, Statistic.Type.BLOCK, v, b)));
|
||||
itemStatistics.forEach((k, m) -> m.forEach((i, v) -> applyStat(p, user, k, Statistic.Type.ITEM, v, i)));
|
||||
entityStatistics.forEach((k, m) -> m.forEach((e, v) -> applyStat(p, user, k, Statistic.Type.ENTITY, v, e)));
|
||||
}
|
||||
|
||||
private void applyStat(@NotNull UserDataHolder user, @NotNull String id,
|
||||
private void applyStat(@NotNull HuskSync plugin, @NotNull UserDataHolder user, @NotNull String id,
|
||||
@NotNull Statistic.Type type, int value, @NotNull String... key) {
|
||||
final Player player = ((BukkitUser) user).getPlayer();
|
||||
final Statistic stat = matchStatistic(id);
|
||||
@@ -525,7 +525,8 @@ public abstract class BukkitData implements Data {
|
||||
case BLOCK, ITEM -> player.setStatistic(stat, Objects.requireNonNull(matchMaterial(key[0])), value);
|
||||
case ENTITY -> player.setStatistic(stat, Objects.requireNonNull(matchEntityType(key[0])), value);
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
} catch (Throwable a) {
|
||||
plugin.log(Level.WARNING, "Failed to apply statistic " + id, a);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -571,7 +572,7 @@ public abstract class BukkitData implements Data {
|
||||
final AttributeSettings settings = plugin.getSettings().getSynchronization().getAttributes();
|
||||
Registry.ATTRIBUTE.forEach(id -> {
|
||||
final AttributeInstance instance = player.getAttribute(id);
|
||||
if (!settings.isSyncedAttribute(id.getKey().toString()) || instance == null
|
||||
if (settings.isIgnoredAttribute(id.getKey().toString()) || instance == null
|
||||
|| Double.compare(instance.getValue(), instance.getDefaultValue()) == 0) {
|
||||
return; // We don't sync attributes not marked as to be synced
|
||||
}
|
||||
@@ -619,8 +620,8 @@ public abstract class BukkitData implements Data {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
instance.setBaseValue(attribute == null ? instance.getDefaultValue() : attribute.baseValue());
|
||||
instance.getModifiers().forEach(instance::removeModifier);
|
||||
instance.setBaseValue(attribute == null ? instance.getValue() : attribute.baseValue());
|
||||
if (attribute != null) {
|
||||
attribute.modifiers().stream()
|
||||
.filter(mod -> instance.getModifiers().stream().map(AttributeModifier::getName)
|
||||
@@ -642,9 +643,13 @@ public abstract class BukkitData implements Data {
|
||||
|
||||
@Override
|
||||
public void apply(@NotNull BukkitUser user, @NotNull BukkitHuskSync plugin) throws IllegalStateException {
|
||||
Registry.ATTRIBUTE.forEach(id -> applyAttribute(
|
||||
user.getPlayer().getAttribute(id), getAttribute(id).orElse(null)
|
||||
));
|
||||
final AttributeSettings settings = plugin.getSettings().getSynchronization().getAttributes();
|
||||
Registry.ATTRIBUTE.forEach(id -> {
|
||||
if (settings.isIgnoredAttribute(id.getKey().toString())) {
|
||||
return;
|
||||
}
|
||||
applyAttribute(user.getPlayer().getAttribute(id), getAttribute(id).orElse(null));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -304,8 +304,8 @@ public class Settings {
|
||||
return pat.contains("*") ? value.matches(pat.replace("*", ".*")) : pat.equals(value);
|
||||
}
|
||||
|
||||
public boolean isSyncedAttribute(@NotNull String attribute) {
|
||||
return syncedAttributes.stream().anyMatch(wildcard -> matchesWildcard(wildcard, attribute));
|
||||
public boolean isIgnoredAttribute(@NotNull String attribute) {
|
||||
return syncedAttributes.stream().noneMatch(wildcard -> matchesWildcard(wildcard, attribute));
|
||||
}
|
||||
|
||||
public boolean isIgnoredModifier(@NotNull String modifier) {
|
||||
|
||||
@@ -48,6 +48,7 @@ import net.william278.desertwell.util.ThrowingConsumer;
|
||||
import net.william278.husksync.FabricHuskSync;
|
||||
import net.william278.husksync.HuskSync;
|
||||
import net.william278.husksync.adapter.Adaptable;
|
||||
import net.william278.husksync.config.Settings.SynchronizationSettings.AttributeSettings;
|
||||
import net.william278.husksync.user.FabricUser;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -570,10 +571,11 @@ public abstract class FabricData implements Data {
|
||||
@NotNull
|
||||
public static FabricData.Attributes adapt(@NotNull ServerPlayerEntity player, @NotNull HuskSync plugin) {
|
||||
final List<Attribute> attributes = Lists.newArrayList();
|
||||
final AttributeSettings settings = plugin.getSettings().getSynchronization().getAttributes();
|
||||
Registries.ATTRIBUTE.forEach(id -> {
|
||||
final EntityAttributeInstance instance = player.getAttributeInstance(RegistryEntry.of(id));
|
||||
final Identifier key = Registries.ATTRIBUTE.getId(id);
|
||||
if (instance == null || key == null) {
|
||||
if (instance == null || key == null || settings.isIgnoredAttribute(key.asString())) {
|
||||
return;
|
||||
}
|
||||
final Set<Modifier> modifiers = Sets.newHashSet();
|
||||
@@ -608,10 +610,17 @@ public abstract class FabricData implements Data {
|
||||
|
||||
@Override
|
||||
protected void apply(@NotNull FabricUser user, @NotNull FabricHuskSync plugin) {
|
||||
Registries.ATTRIBUTE.forEach(id -> applyAttribute(
|
||||
final AttributeSettings settings = plugin.getSettings().getSynchronization().getAttributes();
|
||||
Registries.ATTRIBUTE.forEach(id -> {
|
||||
final Identifier key = Registries.ATTRIBUTE.getId(id);
|
||||
if (key == null || settings.isIgnoredAttribute(key.toString())) {
|
||||
return;
|
||||
}
|
||||
applyAttribute(
|
||||
user.getPlayer().getAttributeInstance(RegistryEntry.of(id)),
|
||||
getAttribute(id).orElse(null)
|
||||
));
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -620,8 +629,8 @@ public abstract class FabricData implements Data {
|
||||
if (instance == null) {
|
||||
return;
|
||||
}
|
||||
instance.setBaseValue(attribute == null ? instance.getAttribute().value().getDefaultValue() : attribute.baseValue());
|
||||
instance.getModifiers().forEach(instance::removeModifier);
|
||||
instance.setBaseValue(attribute == null ? instance.getValue() : attribute.baseValue());
|
||||
if (attribute != null) {
|
||||
attribute.modifiers().forEach(modifier -> instance.addTemporaryModifier(new EntityAttributeModifier(
|
||||
Identifier.of(modifier.uuid().toString()),
|
||||
|
||||
Reference in New Issue
Block a user