time cleanup

This commit is contained in:
Felix Cravic 2020-07-22 21:00:57 +02:00
parent 9b25f0a25f
commit f75c3870a3

View File

@ -334,11 +334,14 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
* 18000 = midnight
* <p>
* This method is unaffected by {@link #getTimeRate()}
* <p>
* It does send the new time to all players in the instance, unaffected by {@link #getTimeUpdate()}
*
* @param time the new time of the instance
*/
public void setTime(long time) {
this.time = time;
PacketWriterUtils.writeAndSend(getPlayers(), getTimePacket());
}
/**
@ -384,6 +387,13 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
this.timeUpdate = timeUpdate;
}
private TimeUpdatePacket getTimePacket() {
TimeUpdatePacket timeUpdatePacket = new TimeUpdatePacket();
timeUpdatePacket.worldAge = worldAge;
timeUpdatePacket.timeOfDay = time;
return timeUpdatePacket;
}
/**
* Get the instance world border
*
@ -756,10 +766,7 @@ public abstract class Instance implements BlockModifier, EventHandler, DataConta
this.time += 1 * timeRate;
if (timeUpdate != null && !CooldownUtils.hasCooldown(time, lastTimeUpdate, timeUpdate)) {
TimeUpdatePacket timeUpdatePacket = new TimeUpdatePacket();
timeUpdatePacket.worldAge = worldAge;
timeUpdatePacket.timeOfDay = this.time;
PacketWriterUtils.writeAndSend(getPlayers(), timeUpdatePacket);
PacketWriterUtils.writeAndSend(getPlayers(), getTimePacket());
this.lastTimeUpdate = time;
}