From a8b4ee2a1df0c4b3d066e1d25b416fed36b14c33 Mon Sep 17 00:00:00 2001 From: Moulberry Date: Thu, 16 Nov 2023 22:30:37 +0800 Subject: [PATCH] WorldProperties: Pass correct value to handleUpdateProperty, prevent excessive syncing with repeated call to setValue --- .../server/ServerWorldPropertyHolder.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertyHolder.java b/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertyHolder.java index 69cf77d..210f23a 100644 --- a/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertyHolder.java +++ b/src/main/java/com/moulberry/axiom/world_properties/server/ServerWorldPropertyHolder.java @@ -16,6 +16,7 @@ public class ServerWorldPropertyHolder { private T value; private ServerWorldPropertyBase property; + private boolean unsyncedValue = false; public ServerWorldPropertyHolder(T value, ServerWorldPropertyBase property) { this.value = value; @@ -35,10 +36,15 @@ public class ServerWorldPropertyHolder { } public void update(Player player, World world, byte[] data) { - PropertyUpdateResult result = this.property.handleUpdateProperty(player, world, this.value); + T newValue = this.property.widget.dataType().deserialize(data); + + PropertyUpdateResult result = this.property.handleUpdateProperty(player, world, newValue); if (result.isUpdate()) { - this.value = this.property.widget.dataType().deserialize(data); + this.value = newValue; + if (!result.isSync()) { + this.unsyncedValue = true; + } } if (result.isSync()) { this.sync(world); @@ -50,8 +56,11 @@ public class ServerWorldPropertyHolder { } public void setValue(World world, T value) { + boolean sync = this.unsyncedValue || !value.equals(this.value); this.value = value; - this.sync(world); + if (sync) { + this.sync(world); + } } public void sync(World world) {