feat: add config to skip certain attributes

feat/data-edit-commands
William 11 months ago
parent 7b8fb92737
commit 8293d767da
No known key found for this signature in database

@ -678,12 +678,14 @@ public abstract class BukkitData implements Data {
private List<Attribute> attributes;
@NotNull
public static BukkitData.Attributes adapt(@NotNull Player player) {
public static BukkitData.Attributes adapt(@NotNull Player player, @NotNull HuskSync plugin) {
final List<Attribute> attributes = Lists.newArrayList();
Registry.ATTRIBUTE.forEach(id -> {
final AttributeInstance instance = player.getAttribute(id);
if (instance == null || instance.getValue() == instance.getDefaultValue()) {
return; // We don't sync unmodified attributes
if (instance == null || instance.getValue() == instance.getDefaultValue() || plugin
.getSettings().getSynchronization().isIgnoredAttribute(id.getKey().toString())) {
// We don't sync unmodified or disabled attributes
return;
}
attributes.add(adapt(instance));
});

@ -121,7 +121,7 @@ public interface BukkitUserDataHolder extends UserDataHolder {
@NotNull
@Override
default Optional<Data.Attributes> getAttributes() {
return Optional.of(BukkitData.Attributes.adapt(getBukkitPlayer()));
return Optional.of(BukkitData.Attributes.adapt(getBukkitPlayer(), getPlugin()));
}
@NotNull

@ -255,9 +255,6 @@ public class Settings {
@Comment("Persist maps locked in a Cartography Table to let them be viewed on any server")
private boolean persistLockedMaps = true;
@Comment("Whether to synchronize player max health (requires health syncing to be enabled)")
private boolean synchronizeMaxHealth = true;
@Comment("If using the DELAY sync method, how long should this server listen for Redis key data updates before "
+ "pulling data from the database instead (i.e., if the user did not change servers).")
private int networkLatencyMilliseconds = 500;
@ -273,6 +270,11 @@ public class Settings {
@Getter(AccessLevel.NONE)
private Map<String, String> eventPriorities = EventListener.ListenerType.getDefaults();
@Comment({"For attribute syncing, which attributes should be ignored/skipped when syncing",
"(e.g. \"minecraft:generic.max_health\", \"minecraft:generic.attack_damage\")"})
@Getter(AccessLevel.NONE)
private List<String> ignoredAttributes = new ArrayList<>(List.of(""));
public boolean doAutoPin(@NotNull DataSnapshot.SaveCause cause) {
return autoPinnedSaveCauses.contains(cause.name());
}
@ -281,6 +283,10 @@ public class Settings {
return id.isCustom() || features.getOrDefault(id.getKeyValue(), id.isEnabledByDefault());
}
public boolean isIgnoredAttribute(@NotNull String attribute) {
return ignoredAttributes.contains(attribute);
}
@NotNull
public EventListener.Priority getEventPriority(@NotNull EventListener.ListenerType type) {
try {

Loading…
Cancel
Save