13
0
geforkt von Mirrors/Velocity

Introduce Channel#eventLoop() shorthand

This is such a common call that it makes a lot of sense to go ahead
and expose this.
Dieser Commit ist enthalten in:
Andrew Steinborn 2018-09-29 01:38:30 -04:00
Ursprung 5ab346a02b
Commit 6cd0a6b148
7 geänderte Dateien mit 17 neuen und 16 gelöschten Zeilen

Datei anzeigen

@ -11,10 +11,7 @@ import com.velocitypowered.proxy.protocol.ProtocolConstants;
import com.velocitypowered.proxy.protocol.StateRegistry; import com.velocitypowered.proxy.protocol.StateRegistry;
import com.velocitypowered.proxy.protocol.netty.*; import com.velocitypowered.proxy.protocol.netty.*;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel; import io.netty.channel.*;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.ReferenceCountUtil; import io.netty.util.ReferenceCountUtil;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -104,6 +101,10 @@ public class MinecraftConnection extends ChannelInboundHandlerAdapter {
} }
} }
public EventLoop eventLoop() {
return channel.eventLoop();
}
public void write(Object msg) { public void write(Object msg) {
if (channel.isActive()) { if (channel.isActive()) {
channel.writeAndFlush(msg, channel.voidPromise()); channel.writeAndFlush(msg, channel.voidPromise());

Datei anzeigen

@ -96,7 +96,7 @@ public class BackendPlaySessionHandler implements MinecraftSessionHandler {
if (pme.getResult().isAllowed()) { if (pme.getResult().isAllowed()) {
serverConn.getPlayer().getConnection().write(pm); serverConn.getPlayer().getConnection().write(pm);
} }
}, serverConn.getConnection().getChannel().eventLoop()); }, serverConn.getConnection().eventLoop());
} }
} else if (packet instanceof TabCompleteResponse) { } else if (packet instanceof TabCompleteResponse) {
playerHandler.handleTabCompleteResponse((TabCompleteResponse) packet); playerHandler.handleTabCompleteResponse((TabCompleteResponse) packet);

Datei anzeigen

@ -93,11 +93,11 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
server.getEventManager().fire(event) server.getEventManager().fire(event)
.thenAcceptAsync(pme -> { .thenAcceptAsync(pme -> {
if (pme.getResult().equals(PlayerChatEvent.ChatResult.allowed())){ if (pme.getResult().equals(PlayerChatEvent.ChatResult.allowed())){
player.getConnectedServer().getConnection().write(chat); serverConnection.getConnection().write(chat);
} else if (pme.getResult().isAllowed() && pme.getResult().getMessage().isPresent()){ } else if (pme.getResult().isAllowed() && pme.getResult().getMessage().isPresent()){
player.getConnectedServer().getConnection().write(Chat.createServerbound(pme.getResult().getMessage().get())); serverConnection.getConnection().write(Chat.createServerbound(pme.getResult().getMessage().get()));
} }
}, player.getConnectedServer().getConnection().getChannel().eventLoop()); }, serverConnection.getConnection().eventLoop());
} }
return; return;
} }
@ -290,7 +290,7 @@ public class ClientPlaySessionHandler implements MinecraftSessionHandler {
if (pme.getResult().isAllowed()) { if (pme.getResult().isAllowed()) {
player.getConnectedServer().getConnection().write(packet); player.getConnectedServer().getConnection().write(packet);
} }
}, player.getConnectedServer().getConnection().getChannel().eventLoop()); }, player.getConnectedServer().getConnection().eventLoop());
} }
} }
} }

Datei anzeigen

@ -309,7 +309,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
// In case someone gets creative, assume we want to disconnect the player. // In case someone gets creative, assume we want to disconnect the player.
connection.closeWith(Disconnect.create(friendlyReason)); connection.closeWith(Disconnect.create(friendlyReason));
} }
}, connection.getChannel().eventLoop()); }, connection.eventLoop());
} else { } else {
connection.closeWith(Disconnect.create(friendlyReason)); connection.closeWith(Disconnect.create(friendlyReason));
} }
@ -463,7 +463,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player {
handleConnectionException(server, Disconnect.create(status.getReason().orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR))); handleConnectionException(server, Disconnect.create(status.getReason().orElse(ConnectionMessages.INTERNAL_SERVER_CONNECTION_ERROR)));
break; break;
} }
}, connection.getChannel().eventLoop()); }, connection.eventLoop());
} }
} }
} }

Datei anzeigen

@ -116,7 +116,7 @@ public class HandshakeSessionHandler implements MinecraftSessionHandler {
.thenRunAsync(() -> { .thenRunAsync(() -> {
// The disconnect packet is the same as the server response one. // The disconnect packet is the same as the server response one.
connection.closeWith(LegacyDisconnect.fromPingResponse(LegacyPingResponse.from(event.getPing()))); connection.closeWith(LegacyDisconnect.fromPingResponse(LegacyPingResponse.from(event.getPing())));
}, connection.getChannel().eventLoop()); }, connection.eventLoop());
} else if (packet instanceof LegacyHandshake) { } else if (packet instanceof LegacyHandshake) {
connection.closeWith(LegacyDisconnect.from(TextComponent.of("Your client is old, please upgrade!", TextColor.RED))); connection.closeWith(LegacyDisconnect.from(TextComponent.of("Your client is old, please upgrade!", TextColor.RED)));
} }

Datei anzeigen

@ -129,7 +129,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
profileResponse.getCode(), login.getUsername(), playerIp); profileResponse.getCode(), login.getUsername(), playerIp);
inbound.close(); inbound.close();
} }
}, inbound.getChannel().eventLoop()) }, inbound.eventLoop())
.exceptionally(exception -> { .exceptionally(exception -> {
logger.error("Unable to enable encryption", exception); logger.error("Unable to enable encryption", exception);
inbound.close(); inbound.close();
@ -167,7 +167,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
} else { } else {
initializePlayer(GameProfile.forOfflinePlayer(login.getUsername()), false); initializePlayer(GameProfile.forOfflinePlayer(login.getUsername()), false);
} }
}, inbound.getChannel().eventLoop()); }, inbound.eventLoop());
} }
private EncryptionRequest generateRequest() { private EncryptionRequest generateRequest() {
@ -214,7 +214,7 @@ public class LoginSessionHandler implements MinecraftSessionHandler {
} }
handleProxyLogin(player); handleProxyLogin(player);
}, inbound.getChannel().eventLoop()); }, inbound.eventLoop());
}); });
} }

Datei anzeigen

@ -58,7 +58,7 @@ public class StatusSessionHandler implements MinecraftSessionHandler {
StatusResponse response = new StatusResponse(); StatusResponse response = new StatusResponse();
response.setStatus(VelocityServer.GSON.toJson(event.getPing())); response.setStatus(VelocityServer.GSON.toJson(event.getPing()));
connection.write(response); connection.write(response);
}, connection.getChannel().eventLoop()); }, connection.eventLoop());
} }
@Override @Override