mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Fixed chunk synchronization during generation and packet sending
This commit is contained in:
parent
d7d610ffef
commit
da4216a51f
@ -459,7 +459,7 @@ public abstract class Chunk implements Viewable, DataContainer {
|
||||
*
|
||||
* @param player the player
|
||||
*/
|
||||
protected void sendChunk(@NotNull Player player) {
|
||||
protected synchronized void sendChunk(@NotNull Player player) {
|
||||
// Only send loaded chunk
|
||||
if (!isLoaded())
|
||||
return;
|
||||
@ -503,7 +503,7 @@ public abstract class Chunk implements Viewable, DataContainer {
|
||||
*
|
||||
* @param player the player to update the chunk to
|
||||
*/
|
||||
public void sendChunkUpdate(@NotNull Player player) {
|
||||
public synchronized void sendChunkUpdate(@NotNull Player player) {
|
||||
final PlayerConnection playerConnection = player.getPlayerConnection();
|
||||
playerConnection.sendPacket(getFreshFullDataPacket());
|
||||
}
|
||||
@ -511,7 +511,7 @@ public abstract class Chunk implements Viewable, DataContainer {
|
||||
/**
|
||||
* Sends a full {@link ChunkDataPacket} to all chunk viewers.
|
||||
*/
|
||||
public void sendChunkUpdate() {
|
||||
public synchronized void sendChunkUpdate() {
|
||||
final Set<Player> chunkViewers = getViewers();
|
||||
if (!chunkViewers.isEmpty()) {
|
||||
chunkViewers.forEach(player -> {
|
||||
@ -528,7 +528,7 @@ public abstract class Chunk implements Viewable, DataContainer {
|
||||
* @param player the player to send the packet to
|
||||
* @throws IllegalArgumentException if {@code section} is not a valid section
|
||||
*/
|
||||
public void sendChunkSectionUpdate(int section, @NotNull Player player) {
|
||||
public synchronized void sendChunkSectionUpdate(int section, @NotNull Player player) {
|
||||
if (!PlayerUtils.isNettyClient(player))
|
||||
return;
|
||||
Check.argCondition(!MathUtils.isBetween(section, 0, CHUNK_SECTION_COUNT),
|
||||
|
@ -116,21 +116,23 @@ public class ChunkBatch implements InstanceBatch {
|
||||
*/
|
||||
public void flushChunkGenerator(@NotNull ChunkGenerator chunkGenerator, @Nullable ChunkCallback callback) {
|
||||
BLOCK_BATCH_POOL.execute(() -> {
|
||||
final List<ChunkPopulator> populators = chunkGenerator.getPopulators();
|
||||
final boolean hasPopulator = populators != null && !populators.isEmpty();
|
||||
synchronized (chunk) {
|
||||
final List<ChunkPopulator> populators = chunkGenerator.getPopulators();
|
||||
final boolean hasPopulator = populators != null && !populators.isEmpty();
|
||||
|
||||
chunkGenerator.generateChunkData(this, chunk.getChunkX(), chunk.getChunkZ());
|
||||
chunkGenerator.generateChunkData(this, chunk.getChunkX(), chunk.getChunkZ());
|
||||
|
||||
if (hasPopulator) {
|
||||
for (ChunkPopulator chunkPopulator : populators) {
|
||||
chunkPopulator.populateChunk(this, chunk);
|
||||
if (hasPopulator) {
|
||||
for (ChunkPopulator chunkPopulator : populators) {
|
||||
chunkPopulator.populateChunk(this, chunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Safe callback
|
||||
instance.scheduleNextTick(inst -> {
|
||||
OptionalCallback.execute(callback, chunk);
|
||||
});
|
||||
// Safe callback
|
||||
instance.scheduleNextTick(inst -> {
|
||||
OptionalCallback.execute(callback, chunk);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,7 @@ public class TemporaryCache<T> {
|
||||
// Identifier = time
|
||||
protected ConcurrentHashMap<UUID, Long> cacheTime = new ConcurrentHashMap<>();
|
||||
|
||||
private long keepTime;
|
||||
private final long keepTime;
|
||||
|
||||
/**
|
||||
* Creates a new temporary cache.
|
||||
@ -42,13 +42,13 @@ public class TemporaryCache<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Caches an object
|
||||
* Caches an object.
|
||||
*
|
||||
* @param identifier the object identifier
|
||||
* @param value the object to cache
|
||||
* @param time the current time in milliseconds
|
||||
*/
|
||||
public synchronized void cacheObject(@NotNull UUID identifier, T value, long time) {
|
||||
public void cacheObject(@NotNull UUID identifier, T value, long time) {
|
||||
this.cache.put(identifier, value);
|
||||
this.cacheTime.put(identifier, time);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user