Skip to content

Commit 0fe81e3

Browse files
committed
Fixed block changes not sending because it was not getting the amount of blocks correctly.
1 parent 81329d4 commit 0fe81e3

4 files changed

Lines changed: 12 additions & 27 deletions

File tree

src/main/java/codes/kooper/blockify/managers/BlockChangeManager.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@
2727
public class BlockChangeManager {
2828

2929
private final ConcurrentHashMap<Player, BukkitTask> blockChangeTasks;
30-
private final ConcurrentHashMap<Player, Vector<Long>> chunksBeingSent;
3130
private final ConcurrentHashMap<BlockData, Integer> blockDataToId;
3231

3332
public BlockChangeManager() {
3433
this.blockChangeTasks = new ConcurrentHashMap<>();
35-
this.chunksBeingSent = new ConcurrentHashMap<>();
34+
//this.chunksBeingSent = new ConcurrentHashMap<>();
3635
this.blockDataToId = new ConcurrentHashMap<>();
3736
}
3837

@@ -133,7 +132,11 @@ public void sendBlockChanges(Stage stage, Audience audience, ConcurrentHashMap<B
133132
Bukkit.getScheduler().runTask(Blockify.getInstance(), () -> new OnBlockChangeSendEvent(stage, blockChanges).callEvent());
134133

135134
// 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) {
137140
for (Player onlinePlayer : audience.getPlayers()) {
138141
if (onlinePlayer != null) {
139142
for (Map.Entry<BlockifyChunk, ConcurrentHashMap<BlockifyPosition, BlockData>> entry : blockChanges.entrySet()) {
@@ -222,18 +225,6 @@ public void sendChunkPacket(Stage stage, Player player, BlockifyChunk chunk, Con
222225
// Get the user from PacketEvents API
223226
User user = PacketEvents.getAPI().getPlayerManager().getUser(player);
224227

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-
237228
// Loop through the chunks y positions
238229
for (int chunkY = stage.getMinPosition().getY() >> 4; chunkY <= stage.getMaxPosition().getY() >> 4; chunkY++) {
239230
// Create a list of encoded blocks for PacketEvents wrapper
@@ -264,12 +255,6 @@ public void sendChunkPacket(Stage stage, Player player, BlockifyChunk chunk, Con
264255
WrapperPlayServerMultiBlockChange wrapper = new WrapperPlayServerMultiBlockChange(new Vector3i(chunk.x(), chunkY, chunk.z()), true, encodedBlocksArray);
265256
Bukkit.getScheduler().runTask(Blockify.getInstance(), () -> user.sendPacket(wrapper));
266257
}
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-
}
273258
}
274259

275260

src/main/java/codes/kooper/blockify/managers/StageManager.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414

1515
@Getter
1616
public class StageManager {
17-
private final Map<String, Stage> stages = new HashMap<>();
17+
private final Map<String, Stage> stages;
18+
19+
public StageManager() {
20+
this.stages = new HashMap<>();
21+
}
1822

1923
/**
2024
* Create a new stage

src/main/java/codes/kooper/blockify/models/Stage.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public void sendBlocksToAudience() {
7171
* @param blocks Blocks to refresh to the audience.
7272
*/
7373
public void refreshBlocksToAudience(Set<BlockifyPosition> blocks) {
74+
Blockify.getInstance().getLogger().info("Refresh with size " + blocks.size());
7475
ConcurrentHashMap<BlockifyChunk, ConcurrentHashMap<BlockifyPosition, BlockData>> blockChanges = new ConcurrentHashMap<>();
7576
for (View view : views) {
7677
for (BlockifyPosition position : blocks) {

src/main/java/codes/kooper/blockify/protocol/ChunkLoadAdapter.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,6 @@ public void onPacketPlaySend(PacketPlaySendEvent event) {
4141
// If the chunk is not in the world, return.
4242
if (!stage.getWorld().equals(player.getWorld())) return;
4343

44-
// If the chunk is being sent to the player, return.
45-
if (Blockify.getInstance().getBlockChangeManager().getChunksBeingSent().get(player.getUniqueId()) != null && Blockify.getInstance().getBlockChangeManager().getChunksBeingSent().get(player.getUniqueId()).contains(blockifyChunk.getChunkKey())) {
46-
return;
47-
}
48-
4944
Blockify.getInstance().getBlockChangeManager().sendChunkPacket(stage, player, blockifyChunk, view.getBlocks());
5045
}
5146
}

0 commit comments

Comments
 (0)