mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Merge branch 'master' of https://github.com/Minestom/Minestom
This commit is contained in:
commit
035844787e
@ -17,6 +17,7 @@ import net.minestom.server.network.packet.server.play.ChunkDataPacket;
|
|||||||
import net.minestom.server.network.packet.server.play.UpdateLightPacket;
|
import net.minestom.server.network.packet.server.play.UpdateLightPacket;
|
||||||
import net.minestom.server.network.player.PlayerConnection;
|
import net.minestom.server.network.player.PlayerConnection;
|
||||||
import net.minestom.server.utils.MathUtils;
|
import net.minestom.server.utils.MathUtils;
|
||||||
|
import net.minestom.server.utils.PacketUtils;
|
||||||
import net.minestom.server.utils.Position;
|
import net.minestom.server.utils.Position;
|
||||||
import net.minestom.server.utils.binary.BinaryReader;
|
import net.minestom.server.utils.binary.BinaryReader;
|
||||||
import net.minestom.server.utils.chunk.ChunkCallback;
|
import net.minestom.server.utils.chunk.ChunkCallback;
|
||||||
@ -459,7 +460,7 @@ public abstract class Chunk implements Viewable, DataContainer {
|
|||||||
*
|
*
|
||||||
* @param player the player
|
* @param player the player
|
||||||
*/
|
*/
|
||||||
protected void sendChunk(@NotNull Player player) {
|
protected synchronized void sendChunk(@NotNull Player player) {
|
||||||
// Only send loaded chunk
|
// Only send loaded chunk
|
||||||
if (!isLoaded())
|
if (!isLoaded())
|
||||||
return;
|
return;
|
||||||
@ -503,7 +504,7 @@ public abstract class Chunk implements Viewable, DataContainer {
|
|||||||
*
|
*
|
||||||
* @param player the player to update the chunk to
|
* @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();
|
final PlayerConnection playerConnection = player.getPlayerConnection();
|
||||||
playerConnection.sendPacket(getFreshFullDataPacket());
|
playerConnection.sendPacket(getFreshFullDataPacket());
|
||||||
}
|
}
|
||||||
@ -511,14 +512,8 @@ public abstract class Chunk implements Viewable, DataContainer {
|
|||||||
/**
|
/**
|
||||||
* Sends a full {@link ChunkDataPacket} to all chunk viewers.
|
* Sends a full {@link ChunkDataPacket} to all chunk viewers.
|
||||||
*/
|
*/
|
||||||
public void sendChunkUpdate() {
|
public synchronized void sendChunkUpdate() {
|
||||||
final Set<Player> chunkViewers = getViewers();
|
PacketUtils.sendGroupedPacket(getViewers(), getFreshFullDataPacket());
|
||||||
if (!chunkViewers.isEmpty()) {
|
|
||||||
chunkViewers.forEach(player -> {
|
|
||||||
final PlayerConnection playerConnection = player.getPlayerConnection();
|
|
||||||
playerConnection.sendPacket(getFreshFullDataPacket());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -528,7 +523,7 @@ public abstract class Chunk implements Viewable, DataContainer {
|
|||||||
* @param player the player to send the packet to
|
* @param player the player to send the packet to
|
||||||
* @throws IllegalArgumentException if {@code section} is not a valid section
|
* @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))
|
if (!PlayerUtils.isNettyClient(player))
|
||||||
return;
|
return;
|
||||||
Check.argCondition(!MathUtils.isBetween(section, 0, CHUNK_SECTION_COUNT),
|
Check.argCondition(!MathUtils.isBetween(section, 0, CHUNK_SECTION_COUNT),
|
||||||
|
@ -116,17 +116,24 @@ public class ChunkBatch implements InstanceBatch {
|
|||||||
*/
|
*/
|
||||||
public void flushChunkGenerator(@NotNull ChunkGenerator chunkGenerator, @Nullable ChunkCallback callback) {
|
public void flushChunkGenerator(@NotNull ChunkGenerator chunkGenerator, @Nullable ChunkCallback callback) {
|
||||||
BLOCK_BATCH_POOL.execute(() -> {
|
BLOCK_BATCH_POOL.execute(() -> {
|
||||||
final List<ChunkPopulator> populators = chunkGenerator.getPopulators();
|
synchronized (chunk) {
|
||||||
final boolean hasPopulator = populators != null && !populators.isEmpty();
|
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) {
|
if (hasPopulator) {
|
||||||
for (ChunkPopulator chunkPopulator : populators) {
|
for (ChunkPopulator chunkPopulator : populators) {
|
||||||
chunkPopulator.populateChunk(this, chunk);
|
chunkPopulator.populateChunk(this, chunk);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Refresh chunk for viewers
|
||||||
|
this.chunk.sendChunkUpdate();
|
||||||
|
|
||||||
|
this.instance.refreshLastBlockChangeTime();
|
||||||
|
|
||||||
// Safe callback
|
// Safe callback
|
||||||
instance.scheduleNextTick(inst -> {
|
instance.scheduleNextTick(inst -> {
|
||||||
OptionalCallback.execute(callback, chunk);
|
OptionalCallback.execute(callback, chunk);
|
||||||
|
@ -23,7 +23,7 @@ public class TemporaryCache<T> {
|
|||||||
// Identifier = time
|
// Identifier = time
|
||||||
protected ConcurrentHashMap<UUID, Long> cacheTime = new ConcurrentHashMap<>();
|
protected ConcurrentHashMap<UUID, Long> cacheTime = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private long keepTime;
|
private final long keepTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new temporary cache.
|
* 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 identifier the object identifier
|
||||||
* @param value the object to cache
|
* @param value the object to cache
|
||||||
* @param time the current time in milliseconds
|
* @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.cache.put(identifier, value);
|
||||||
this.cacheTime.put(identifier, time);
|
this.cacheTime.put(identifier, time);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user