mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Add PlayerConnection#flush
without guarantee
This commit is contained in:
parent
a43f6f6b62
commit
dbf5ff6cd4
@ -7,7 +7,6 @@ import net.minestom.server.instance.Instance;
|
||||
import net.minestom.server.instance.InstanceManager;
|
||||
import net.minestom.server.monitoring.TickMonitor;
|
||||
import net.minestom.server.network.ConnectionManager;
|
||||
import net.minestom.server.network.player.PlayerSocketConnection;
|
||||
import net.minestom.server.thread.SingleThreadProvider;
|
||||
import net.minestom.server.thread.ThreadProvider;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -83,10 +82,7 @@ public final class UpdateManager {
|
||||
|
||||
// Flush all waiting packets
|
||||
for (Player player : connectionManager.getOnlinePlayers()) {
|
||||
final var connection = player.getPlayerConnection();
|
||||
if (connection instanceof PlayerSocketConnection) {
|
||||
((PlayerSocketConnection) connection).flush();
|
||||
}
|
||||
player.getPlayerConnection().flush();
|
||||
}
|
||||
|
||||
// Disable thread until next tick
|
||||
|
@ -571,9 +571,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
PlayerSpawnEvent spawnEvent = new PlayerSpawnEvent(this, instance, firstSpawn);
|
||||
EventDispatcher.call(spawnEvent);
|
||||
|
||||
if (playerConnection instanceof PlayerSocketConnection) {
|
||||
((PlayerSocketConnection) playerConnection).flush();
|
||||
}
|
||||
this.playerConnection.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -293,9 +293,7 @@ public final class ConnectionManager {
|
||||
EventDispatcher.call(asyncPlayerPreLoginEvent);
|
||||
// Close the player channel if he has been disconnected (kick)
|
||||
if (!player.isOnline()) {
|
||||
if (playerConnection instanceof PlayerSocketConnection) {
|
||||
((PlayerSocketConnection) playerConnection).flush();
|
||||
}
|
||||
playerConnection.flush();
|
||||
//playerConnection.disconnect();
|
||||
return;
|
||||
}
|
||||
|
@ -50,9 +50,8 @@ public abstract class PlayerConnection {
|
||||
if (tickCounter % MinecraftServer.TICK_PER_SECOND == 0 && tickCounter > 0) {
|
||||
tickCounter = 0;
|
||||
// Retrieve the packet count
|
||||
final int count = packetCounter.get();
|
||||
final int count = packetCounter.getAndSet(0);
|
||||
this.lastPacketCounter.set(count);
|
||||
this.packetCounter.set(0);
|
||||
if (count > MinecraftServer.getRateLimit()) {
|
||||
// Sent too many packets
|
||||
player.kick(rateLimitKickMessage);
|
||||
@ -101,6 +100,15 @@ public abstract class PlayerConnection {
|
||||
*/
|
||||
public abstract void sendPacket(@NotNull ServerPacket serverPacket, boolean skipTranslating);
|
||||
|
||||
/**
|
||||
* Flush waiting data to the connection.
|
||||
* <p>
|
||||
* Might not do anything depending on the implementation.
|
||||
*/
|
||||
public void flush() {
|
||||
// Empty
|
||||
}
|
||||
|
||||
protected boolean shouldSendPacket(@NotNull ServerPacket serverPacket) {
|
||||
return player == null ||
|
||||
PACKET_LISTENER_MANAGER.processServerPacket(serverPacket, Collections.singleton(player));
|
||||
|
@ -252,6 +252,7 @@ public class PlayerSocketConnection extends PlayerConnection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
if (!channel.isOpen()) return;
|
||||
synchronized (tickBuffer) {
|
||||
|
Loading…
Reference in New Issue
Block a user