mirror of
https://github.com/GeyserMC/Geyser.git
synced 2025-12-20 07:19:29 +00:00
Allow updating properties immediately (#5961)
This commit is contained in:
@@ -62,7 +62,23 @@ public interface GeyserEntity {
|
|||||||
/**
|
/**
|
||||||
* Updates multiple properties with just one update packet.
|
* Updates multiple properties with just one update packet.
|
||||||
* @see BatchPropertyUpdater
|
* @see BatchPropertyUpdater
|
||||||
|
*
|
||||||
|
* @param consumer a batch updater
|
||||||
* @since 2.9.0
|
* @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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -778,8 +778,11 @@ public class Entity implements GeyserEntity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updatePropertiesBatched(Consumer<BatchPropertyUpdater> consumer) {
|
public void updatePropertiesBatched(Consumer<BatchPropertyUpdater> consumer, boolean immediate) {
|
||||||
if (this.propertyManager != null) {
|
if (this.propertyManager == null) {
|
||||||
|
throw new IllegalArgumentException("Given entity has no registered properties!");
|
||||||
|
}
|
||||||
|
|
||||||
Objects.requireNonNull(consumer);
|
Objects.requireNonNull(consumer);
|
||||||
GeyserEntityProperties propertyDefinitions = definition.registeredProperties();
|
GeyserEntityProperties propertyDefinitions = definition.registeredProperties();
|
||||||
consumer.accept(new BatchPropertyUpdater() {
|
consumer.accept(new BatchPropertyUpdater() {
|
||||||
@@ -808,10 +811,11 @@ public class Entity implements GeyserEntity {
|
|||||||
packet.setRuntimeEntityId(getGeyserId());
|
packet.setRuntimeEntityId(getGeyserId());
|
||||||
propertyManager.applyFloatProperties(packet.getProperties().getFloatProperties());
|
propertyManager.applyFloatProperties(packet.getProperties().getFloatProperties());
|
||||||
propertyManager.applyIntProperties(packet.getProperties().getIntProperties());
|
propertyManager.applyIntProperties(packet.getProperties().getIntProperties());
|
||||||
|
if (immediate) {
|
||||||
|
session.sendUpstreamPacketImmediately(packet);
|
||||||
|
} else {
|
||||||
session.sendUpstreamPacket(packet);
|
session.sendUpstreamPacket(packet);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Given entity has no registered properties!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user