Skip to content

Commit

Permalink
Writing directly to the netty channel
Browse files Browse the repository at this point in the history
Writing using the standard server methods causes it to only be flushed every tick. This change allows the client to update the map more than 20 times per seconds, as the content is flushed instantly.
  • Loading branch information
pianoman911 committed Apr 6, 2023
1 parent dca319a commit f629774
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ allprojects {
apply(plugin = "maven-publish")

group = "de.pianoman911"
version = "1.4.2"
version = "1.4.3"

repositories {
maven("https://repo.papermc.io/repository/maven-public/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public interface IPlatform<T> {

void sendPacket(Player player, PacketContainer<T> packet);

void flush(Player player);

PacketContainer<T> createMapDataPacket(MapUpdateData data, boolean fullData, int mapId, MapCursorCollection cursors);

PacketContainer<T> createMapEntitySpawnPacket(int entityId, BlockVector pos, BlockFace facing);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ public String getDisplayedName() {

@Override
public void sendPacket(Player player, PacketContainer<Packet<ClientGamePacketListener>> packet) {
((CraftPlayer) player).getHandle().connection.send(packet.getPacket());
((CraftPlayer) player).getHandle().connection.connection.channel.write(packet.getPacket());
}

@Override
public void flush(Player player) {
((CraftPlayer) player).getHandle().connection.connection.channel.flush();
}

@SuppressWarnings("deprecation") // magic values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,12 @@ public String getDisplayedName() {

@Override
public void sendPacket(Player player, PacketContainer<Packet<ClientGamePacketListener>> packet) {
((CraftPlayer) player).getHandle().connection.send(packet.getPacket());
((CraftPlayer) player).getHandle().connection.connection.channel.write(packet.getPacket());
}

@Override
public void flush(Player player) {
((CraftPlayer) player).getHandle().connection.connection.channel.flush();
}

@SuppressWarnings("deprecation") // magic values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public void spawn(Player player) {
frame.spawnPacket().send(player);
frame.setIdPacket(0, false).send(player);
}
plugin.platform().flush(player);
}

@Override
Expand All @@ -125,14 +126,15 @@ public void despawn(Player player) {
ids.add(frame.entityId);
}
plugin.platform().createRemoveEntitiesPacket(ids).send(player);
plugin.platform().flush(player);
}

@Override
public void mapId(Player player, int z) {
for (Frame frame : frames) {
frame.setIdPacket(z, true).send(player);
}

plugin.platform().flush(player);
}

@Override
Expand All @@ -143,6 +145,7 @@ public void update(Player player, IMapUpdateData[] data, boolean fullData, int z
}
frames[i].updatePacket((MapUpdateData) data[i], fullData, z, cursors).send(player);
}
plugin.platform().flush(player);
}

@Override
Expand Down

0 comments on commit f629774

Please # to comment.