1
0
mirror of https://github.com/GeyserMC/Geyser.git synced 2025-12-19 14:59:27 +00:00

Allow updating properties immediately (#5961)

This commit is contained in:
chris
2025-11-20 14:37:56 +01:00
committed by GitHub
parent cc08b71b39
commit b0256ce7ac
2 changed files with 50 additions and 30 deletions

View File

@@ -62,7 +62,23 @@ public interface GeyserEntity {
/**
* Updates multiple properties with just one update packet.
* @see BatchPropertyUpdater
*
* @param consumer a batch updater
* @since 2.9.0
*/
void updatePropertiesBatched(Consumer<BatchPropertyUpdater> consumer);
default void updatePropertiesBatched(Consumer<BatchPropertyUpdater> consumer) {
this.updatePropertiesBatched(consumer, false);
}
/**
* Updates multiple properties with just one update packet, which can be sent immediately to the client.
* Usually, sending updates immediately is not required except for specific situations where packet batching
* would result in update order issues.
* @see BatchPropertyUpdater
*
* @param consumer a batch updater
* @param immediate whether this update should be sent immediately
* @since 2.9.1
*/
void updatePropertiesBatched(Consumer<BatchPropertyUpdater> consumer, boolean immediate);
}

View File

@@ -778,8 +778,11 @@ public class Entity implements GeyserEntity {
}
@Override
public void updatePropertiesBatched(Consumer<BatchPropertyUpdater> consumer) {
if (this.propertyManager != null) {
public void updatePropertiesBatched(Consumer<BatchPropertyUpdater> consumer, boolean immediate) {
if (this.propertyManager == null) {
throw new IllegalArgumentException("Given entity has no registered properties!");
}
Objects.requireNonNull(consumer);
GeyserEntityProperties propertyDefinitions = definition.registeredProperties();
consumer.accept(new BatchPropertyUpdater() {
@@ -808,10 +811,11 @@ public class Entity implements GeyserEntity {
packet.setRuntimeEntityId(getGeyserId());
propertyManager.applyFloatProperties(packet.getProperties().getFloatProperties());
propertyManager.applyIntProperties(packet.getProperties().getIntProperties());
if (immediate) {
session.sendUpstreamPacketImmediately(packet);
} else {
session.sendUpstreamPacket(packet);
}
} else {
throw new IllegalArgumentException("Given entity has no registered properties!");
}
}
}