Added support of custom entity position synchronization cooldown

This commit is contained in:
Konstantin Shandurenko 2021-03-01 13:09:08 +03:00
parent de15c4b6c5
commit 1ae2cf78af
1 changed files with 18 additions and 1 deletions

View File

@ -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,