|
27 | 27 | public class BlockChangeManager { |
28 | 28 |
|
29 | 29 | private final ConcurrentHashMap<Player, BukkitTask> blockChangeTasks; |
30 | | - private final ConcurrentHashMap<Player, Vector<Long>> chunksBeingSent; |
31 | 30 | private final ConcurrentHashMap<BlockData, Integer> blockDataToId; |
32 | 31 |
|
33 | 32 | public BlockChangeManager() { |
34 | 33 | this.blockChangeTasks = new ConcurrentHashMap<>(); |
35 | | - this.chunksBeingSent = new ConcurrentHashMap<>(); |
| 34 | + //this.chunksBeingSent = new ConcurrentHashMap<>(); |
36 | 35 | this.blockDataToId = new ConcurrentHashMap<>(); |
37 | 36 | } |
38 | 37 |
|
@@ -133,7 +132,11 @@ public void sendBlockChanges(Stage stage, Audience audience, ConcurrentHashMap<B |
133 | 132 | Bukkit.getScheduler().runTask(Blockify.getInstance(), () -> new OnBlockChangeSendEvent(stage, blockChanges).callEvent()); |
134 | 133 |
|
135 | 134 | // If there is only one block change, send it to the player directly |
136 | | - if (blockChanges.size() == 1) { |
| 135 | + int blockCount = 0; |
| 136 | + for (Map.Entry<BlockifyChunk, ConcurrentHashMap<BlockifyPosition, BlockData>> entry : blockChanges.entrySet()) { |
| 137 | + blockCount += entry.getValue().size(); |
| 138 | + } |
| 139 | + if (blockCount == 1) { |
137 | 140 | for (Player onlinePlayer : audience.getPlayers()) { |
138 | 141 | if (onlinePlayer != null) { |
139 | 142 | for (Map.Entry<BlockifyChunk, ConcurrentHashMap<BlockifyPosition, BlockData>> entry : blockChanges.entrySet()) { |
@@ -222,18 +225,6 @@ public void sendChunkPacket(Stage stage, Player player, BlockifyChunk chunk, Con |
222 | 225 | // Get the user from PacketEvents API |
223 | 226 | User user = PacketEvents.getAPI().getPlayerManager().getUser(player); |
224 | 227 |
|
225 | | - // Initialize the chunksBeingSent map for this player if not present |
226 | | - chunksBeingSent.computeIfAbsent(player, k -> new Vector<>()); |
227 | | - |
228 | | - Vector<Long> playerChunksBeingSent = chunksBeingSent.get(player); |
229 | | - |
230 | | - // Ensure the chunk isn't already being sent |
231 | | - if (playerChunksBeingSent.contains(chunk.getChunkKey())) { |
232 | | - return; |
233 | | - } |
234 | | - // Add this chunk to the chunks being sent list |
235 | | - playerChunksBeingSent.add(chunk.getChunkKey()); |
236 | | - |
237 | 228 | // Loop through the chunks y positions |
238 | 229 | for (int chunkY = stage.getMinPosition().getY() >> 4; chunkY <= stage.getMaxPosition().getY() >> 4; chunkY++) { |
239 | 230 | // Create a list of encoded blocks for PacketEvents wrapper |
@@ -264,12 +255,6 @@ public void sendChunkPacket(Stage stage, Player player, BlockifyChunk chunk, Con |
264 | 255 | WrapperPlayServerMultiBlockChange wrapper = new WrapperPlayServerMultiBlockChange(new Vector3i(chunk.x(), chunkY, chunk.z()), true, encodedBlocksArray); |
265 | 256 | Bukkit.getScheduler().runTask(Blockify.getInstance(), () -> user.sendPacket(wrapper)); |
266 | 257 | } |
267 | | - |
268 | | - // Remove the chunk from the chunks being sent list |
269 | | - playerChunksBeingSent.remove(chunk.getChunkKey()); |
270 | | - if (playerChunksBeingSent.isEmpty()) { |
271 | | - chunksBeingSent.remove(player); |
272 | | - } |
273 | 258 | } |
274 | 259 |
|
275 | 260 |
|
|
0 commit comments