mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-09 09:57:45 +01:00
Added support of custom entity position synchronization cooldown
This commit is contained in:
parent
de15c4b6c5
commit
1ae2cf78af
@ -101,6 +101,7 @@ public class Entity implements Viewable, EventHandler, DataContainer, Permission
|
||||
|
||||
// Network synchronization, send the absolute position of the entity each X milliseconds
|
||||
private static final UpdateOption SYNCHRONIZATION_COOLDOWN = new UpdateOption(1500, TimeUnit.MILLISECOND);
|
||||
private UpdateOption customSynchronizationCooldown;
|
||||
private long lastAbsoluteSynchronizationTime;
|
||||
|
||||
// Events
|
||||
@ -670,7 +671,7 @@ public class Entity implements Viewable, EventHandler, DataContainer, Permission
|
||||
}
|
||||
|
||||
// Scheduled synchronization
|
||||
if (!CooldownUtils.hasCooldown(time, lastAbsoluteSynchronizationTime, SYNCHRONIZATION_COOLDOWN)) {
|
||||
if (!CooldownUtils.hasCooldown(time, lastAbsoluteSynchronizationTime, getSynchronizationCooldown())) {
|
||||
this.lastAbsoluteSynchronizationTime = time;
|
||||
sendSynchronization();
|
||||
}
|
||||
@ -1485,6 +1486,22 @@ public class Entity implements Viewable, EventHandler, DataContainer, Permission
|
||||
this.lastAbsoluteSynchronizationTime = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set custom cooldown for position synchronization.
|
||||
*
|
||||
* @param cooldown custom cooldown for position synchronization.
|
||||
*/
|
||||
public void setCustomSynchronizationCooldown(@Nullable UpdateOption cooldown) {
|
||||
this.customSynchronizationCooldown = cooldown;
|
||||
}
|
||||
|
||||
private UpdateOption getSynchronizationCooldown() {
|
||||
if (this.customSynchronizationCooldown != null) {
|
||||
return this.customSynchronizationCooldown;
|
||||
}
|
||||
return SYNCHRONIZATION_COOLDOWN;
|
||||
}
|
||||
|
||||
public enum Pose {
|
||||
STANDING,
|
||||
FALL_FLYING,
|
||||
|
Loading…
Reference in New Issue
Block a user