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

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 // Network synchronization, send the absolute position of the entity each X milliseconds
private static final UpdateOption SYNCHRONIZATION_COOLDOWN = new UpdateOption(1500, TimeUnit.MILLISECOND); private static final UpdateOption SYNCHRONIZATION_COOLDOWN = new UpdateOption(1500, TimeUnit.MILLISECOND);
private UpdateOption customSynchronizationCooldown;
private long lastAbsoluteSynchronizationTime; private long lastAbsoluteSynchronizationTime;
// Events // Events
@ -670,7 +671,7 @@ public class Entity implements Viewable, EventHandler, DataContainer, Permission
} }
// Scheduled synchronization // Scheduled synchronization
if (!CooldownUtils.hasCooldown(time, lastAbsoluteSynchronizationTime, SYNCHRONIZATION_COOLDOWN)) { if (!CooldownUtils.hasCooldown(time, lastAbsoluteSynchronizationTime, getSynchronizationCooldown())) {
this.lastAbsoluteSynchronizationTime = time; this.lastAbsoluteSynchronizationTime = time;
sendSynchronization(); sendSynchronization();
} }
@ -1485,6 +1486,22 @@ public class Entity implements Viewable, EventHandler, DataContainer, Permission
this.lastAbsoluteSynchronizationTime = 0; 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 { public enum Pose {
STANDING, STANDING,
FALL_FLYING, FALL_FLYING,