9
0
mirror of https://github.com/BX-Team/DivineMC.git synced 2026-01-06 15:41:52 +00:00

add back api + add new; optimize Connection.flushQueue

This commit is contained in:
NONPLAYT
2025-03-03 01:42:23 +03:00
parent 9386e465a9
commit 31a1a929ee
11 changed files with 683 additions and 5 deletions

View File

@@ -0,0 +1,60 @@
--- a/net/minecraft/network/Connection.java
+++ b/net/minecraft/network/Connection.java
@@ -85,7 +_,7 @@
private static final ProtocolInfo<ServerHandshakePacketListener> INITIAL_PROTOCOL = HandshakeProtocols.SERVERBOUND;
private final PacketFlow receiving;
private volatile boolean sendLoginDisconnect = true;
- private final Queue<WrappedConsumer> pendingActions = Queues.newConcurrentLinkedQueue(); // Paper - Optimize network
+ private final Queue<WrappedConsumer> pendingActions = new java.util.ArrayDeque<>(); // Paper - Optimize network // DivineMC - Optimize Connection.flushQueue
public Channel channel;
public SocketAddress address;
// Spigot start
@@ -541,10 +_,10 @@
if (io.papermc.paper.util.MCUtil.isMainThread()) {
return this.processQueue();
} else if (this.isPending) {
- // Should only happen during login/status stages
- synchronized (this.pendingActions) {
- return this.processQueue();
- }
+ // DivineMC start - Optimize Connection.flushQueue
+ this.channel.eventLoop().execute(this::processQueue);
+ return false;
+ // DivineMC end - Optimize Connection.flushQueue
}
return false;
}
@@ -554,29 +_,16 @@
return true;
}
- // If we are on main, we are safe here in that nothing else should be processing queue off main anymore
- // But if we are not on main due to login/status, the parent is synchronized on packetQueue
- final java.util.Iterator<WrappedConsumer> iterator = this.pendingActions.iterator();
- while (iterator.hasNext()) {
- final WrappedConsumer queued = iterator.next(); // poll -> peek
-
- // Fix NPE (Spigot bug caused by handleDisconnection())
- if (queued == null) {
- return true;
- }
-
- if (queued.isConsumed()) {
- continue;
- }
-
+ // DivineMC start - Optimize Connection.flushQueue
+ WrappedConsumer queued;
+ while ((queued = this.pendingActions.poll()) != null) {
if (queued instanceof PacketSendAction packetSendAction) {
final Packet<?> packet = packetSendAction.packet;
if (!packet.isReady()) {
return false;
}
}
-
- iterator.remove();
+ // DivineMC end - Optimize Connection.flushQueue
if (queued.tryMarkConsumed()) {
queued.accept(this);
}

View File

@@ -0,0 +1,10 @@
--- a/net/minecraft/server/players/PlayerList.java
+++ b/net/minecraft/server/players/PlayerList.java
@@ -716,7 +_,6 @@
return this.respawn(player, keepInventory, reason, eventReason, null);
}
public ServerPlayer respawn(ServerPlayer player, boolean keepInventory, Entity.RemovalReason reason, org.bukkit.event.player.PlayerRespawnEvent.RespawnReason eventReason, org.bukkit.Location location) {
- player.stopRiding(); // CraftBukkit
this.players.remove(player);
this.playersByName.remove(player.getScoreboardName().toLowerCase(java.util.Locale.ROOT)); // Spigot
player.serverLevel().removePlayerImmediately(player, reason);