mirror of
https://github.com/WiIIiam278/HuskSync.git
synced 2025-12-23 08:39:19 +00:00
feat: add config to skip certain attributes
This commit is contained in:
@@ -678,12 +678,14 @@ public abstract class BukkitData implements Data {
|
|||||||
private List<Attribute> attributes;
|
private List<Attribute> attributes;
|
||||||
|
|
||||||
@NotNull
|
@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();
|
final List<Attribute> attributes = Lists.newArrayList();
|
||||||
Registry.ATTRIBUTE.forEach(id -> {
|
Registry.ATTRIBUTE.forEach(id -> {
|
||||||
final AttributeInstance instance = player.getAttribute(id);
|
final AttributeInstance instance = player.getAttribute(id);
|
||||||
if (instance == null || instance.getValue() == instance.getDefaultValue()) {
|
if (instance == null || instance.getValue() == instance.getDefaultValue() || plugin
|
||||||
return; // We don't sync unmodified attributes
|
.getSettings().getSynchronization().isIgnoredAttribute(id.getKey().toString())) {
|
||||||
|
// We don't sync unmodified or disabled attributes
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
attributes.add(adapt(instance));
|
attributes.add(adapt(instance));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ public interface BukkitUserDataHolder extends UserDataHolder {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
default Optional<Data.Attributes> getAttributes() {
|
default Optional<Data.Attributes> getAttributes() {
|
||||||
return Optional.of(BukkitData.Attributes.adapt(getBukkitPlayer()));
|
return Optional.of(BukkitData.Attributes.adapt(getBukkitPlayer(), getPlugin()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -255,9 +255,6 @@ public class Settings {
|
|||||||
@Comment("Persist maps locked in a Cartography Table to let them be viewed on any server")
|
@Comment("Persist maps locked in a Cartography Table to let them be viewed on any server")
|
||||||
private boolean persistLockedMaps = true;
|
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 "
|
@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).")
|
+ "pulling data from the database instead (i.e., if the user did not change servers).")
|
||||||
private int networkLatencyMilliseconds = 500;
|
private int networkLatencyMilliseconds = 500;
|
||||||
@@ -273,6 +270,11 @@ public class Settings {
|
|||||||
@Getter(AccessLevel.NONE)
|
@Getter(AccessLevel.NONE)
|
||||||
private Map<String, String> eventPriorities = EventListener.ListenerType.getDefaults();
|
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) {
|
public boolean doAutoPin(@NotNull DataSnapshot.SaveCause cause) {
|
||||||
return autoPinnedSaveCauses.contains(cause.name());
|
return autoPinnedSaveCauses.contains(cause.name());
|
||||||
}
|
}
|
||||||
@@ -281,6 +283,10 @@ public class Settings {
|
|||||||
return id.isCustom() || features.getOrDefault(id.getKeyValue(), id.isEnabledByDefault());
|
return id.isCustom() || features.getOrDefault(id.getKeyValue(), id.isEnabledByDefault());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isIgnoredAttribute(@NotNull String attribute) {
|
||||||
|
return ignoredAttributes.contains(attribute);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public EventListener.Priority getEventPriority(@NotNull EventListener.ListenerType type) {
|
public EventListener.Priority getEventPriority(@NotNull EventListener.ListenerType type) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user