Skip to content

Commit 4e2a8b5

Browse files
Update VV API usage
1 parent 3e78ec6 commit 4e2a8b5

File tree

5 files changed

+32
-41
lines changed

5 files changed

+32
-41
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Here is an example implementation:
119119
```java
120120
public class CustomVLPipeline extends VLPipeline {
121121

122-
public CustomVLPipeline(UserConnection user) {
122+
public CustomVLPipeline(UserConnection connection) {
123123
super(user);
124124
}
125125

@@ -145,7 +145,7 @@ The same can be done for the `VLLegacyPipeline` with similar functions for the d
145145

146146
Then you can add the Via* pipeline to your netty pipeline:
147147
```java
148-
final UserConnection user = new UserConnectionImpl(channel, true/*clientside or serverside*/);
148+
final UserConnection connection = new UserConnectionImpl(channel, true/*clientside or serverside*/);
149149
new ProtocolPipelineImpl(user);
150150

151151
channel.pipeline().addLast(new CustomVLPipeline(user));
@@ -155,7 +155,7 @@ Both `VLPipeline` and `VLLegacyPipeline` contain various functions allowing you
155155
if you need a more complex/dynamic pipeline setup you can also manually add the Via* handlers to the pipeline.
156156
Here is an example implementation:
157157
```java
158-
final UserConnection user = new UserConnectionImpl(channel, true/*clientside or serverside*/);
158+
final UserConnection connection = new UserConnectionImpl(channel, true/*clientside or serverside*/);
159159
new ProtocolPipelineImpl(user);
160160

161161
//channel.pipeline().addBefore("packet_decoder", VLLegacyPipeline.VIA_DECODER_NAME, new ViaDecoder(user));

src/main/java/com/viaversion/vialoader/commands/UserCommandSender.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828

2929
public class UserCommandSender implements ViaCommandSender {
3030

31-
private final UserConnection user;
31+
private final UserConnection connection;
3232

33-
public UserCommandSender(final UserConnection user) {
34-
this.user = user;
33+
public UserCommandSender(final UserConnection connection) {
34+
this.connection = connection;
3535
}
3636

3737
@Override
@@ -41,17 +41,17 @@ public boolean hasPermission(String permission) {
4141

4242
@Override
4343
public void sendMessage(String msg) {
44-
Via.getPlatform().sendMessage(this.getUUID(), msg);
44+
Via.getPlatform().sendMessage(connection, msg);
4545
}
4646

4747
@Override
4848
public UUID getUUID() {
49-
return this.user.getProtocolInfo().getUuid();
49+
return this.connection.getProtocolInfo().getUuid();
5050
}
5151

5252
@Override
5353
public String getName() {
54-
return this.user.getProtocolInfo().getUsername();
54+
return this.connection.getProtocolInfo().getUsername();
5555
}
5656

5757
}

src/main/java/com/viaversion/vialoader/impl/platform/ViaVersionPlatformImpl.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import org.slf4j.LoggerFactory;
4040

4141
import java.io.File;
42-
import java.util.UUID;
4342
import java.util.concurrent.TimeUnit;
4443
import java.util.logging.Logger;
4544

@@ -103,19 +102,11 @@ public VLTask runRepeatingSync(Runnable runnable, long period) {
103102
}
104103

105104
@Override
106-
public void sendCustomPayload(UUID uuid, String channel, String message) {
107-
UserConnection connection = Via.getManager().getConnectionManager().getConnectedClient(uuid);
108-
if (connection == null) {
109-
// The connection field will always be null on clientside platforms, get the first connection instead
110-
connection = Via.getManager().getConnectionManager().getConnections().stream().findFirst().orElse(null);
111-
}
112-
113-
if (connection != null) {
114-
final PacketWrapper customPayload = PacketWrapper.create(PacketTypeUtil.getServerboundPacketType("CUSTOM_PAYLOAD", connection), connection);
115-
customPayload.write(Types.STRING, channel);
116-
customPayload.write(Types.REMAINING_BYTES, message.getBytes());
117-
customPayload.sendToServer(InitialBaseProtocol.class);
118-
}
105+
public void sendCustomPayload(UserConnection connection, String channel, byte[] message) {
106+
final PacketWrapper customPayload = PacketWrapper.create(PacketTypeUtil.getServerboundPacketType("CUSTOM_PAYLOAD", connection), connection);
107+
customPayload.write(Types.STRING, channel);
108+
customPayload.write(Types.REMAINING_BYTES, message);
109+
customPayload.sendToServer(InitialBaseProtocol.class);
119110
}
120111

121112
@Override

src/main/java/com/viaversion/vialoader/netty/VLLegacyPipeline.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ public abstract class VLLegacyPipeline extends ChannelInboundHandlerAdapter {
4747
public static final String VIABEDROCK_FRAME_ENCAPSULATION_HANDLER_NAME = "viabedrock-frame-encapsulation";
4848
public static final String VIABEDROCK_PACKET_ENCAPSULATION_HANDLER_NAME = "viabedrock-packet-encapsulation";
4949

50-
protected final UserConnection user;
50+
protected final UserConnection connection;
5151
protected final ProtocolVersion version;
5252

53-
public VLLegacyPipeline(final UserConnection user) {
54-
this(user, Via.getManager().getProviders().get(VersionProvider.class).getServerProtocol(user));
53+
public VLLegacyPipeline(final UserConnection connection) {
54+
this(connection, Via.getManager().getProviders().get(VersionProvider.class).getServerProtocol(connection));
5555
}
5656

57-
public VLLegacyPipeline(final UserConnection user, final ProtocolVersion version) {
58-
this.user = user;
57+
public VLLegacyPipeline(final UserConnection connection, final ProtocolVersion version) {
58+
this.connection = connection;
5959
this.version = version;
6060
}
6161

@@ -64,7 +64,7 @@ public void handlerAdded(ChannelHandlerContext ctx) {
6464
ctx.pipeline().addBefore(this.packetDecoderName(), VIA_DECODER_NAME, this.createViaDecoder());
6565
ctx.pipeline().addBefore(this.packetEncoderName(), VIA_ENCODER_NAME, this.createViaEncoder());
6666

67-
if (this.user.isClientSide()) {
67+
if (this.connection.isClientSide()) {
6868
final ProtocolVersion r1_6_4 = ProtocolVersion.getProtocol(VersionType.RELEASE_INITIAL, 78);
6969
if (ProtocolVersion.isRegistered(r1_6_4.getVersionType(), r1_6_4.getOriginalVersion()) && this.version.olderThanOrEqualTo(r1_6_4)) {
7070
ctx.pipeline().addBefore(this.lengthSplitterName(), VIALEGACY_PRE_NETTY_LENGTH_PREPENDER_NAME, this.createViaLegacyPreNettyLengthPrepender());
@@ -101,19 +101,19 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
101101
}
102102

103103
protected ChannelHandler createViaDecoder() {
104-
return new ViaDecoder(this.user);
104+
return new ViaDecoder(this.connection);
105105
}
106106

107107
protected ChannelHandler createViaEncoder() {
108-
return new ViaEncoder(this.user);
108+
return new ViaEncoder(this.connection);
109109
}
110110

111111
protected ChannelHandler createViaLegacyPreNettyLengthPrepender() {
112-
return new PreNettyLengthPrepender(this.user);
112+
return new PreNettyLengthPrepender(this.connection);
113113
}
114114

115115
protected ChannelHandler createViaLegacyPreNettyLengthRemover() {
116-
return new PreNettyLengthRemover(this.user);
116+
return new PreNettyLengthRemover(this.connection);
117117
}
118118

119119
protected ChannelHandler createViaBedrockDisconnectHandler() {

src/main/java/com/viaversion/vialoader/netty/VLPipeline.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,23 @@ public abstract class VLPipeline extends ChannelInboundHandlerAdapter {
4545
public static final String VIABEDROCK_FRAME_ENCAPSULATION_HANDLER_NAME = "viabedrock-frame-encapsulation";
4646
public static final String VIABEDROCK_PACKET_ENCAPSULATION_HANDLER_NAME = "viabedrock-packet-encapsulation";
4747

48-
protected final UserConnection user;
48+
protected final UserConnection connection;
4949
protected final ProtocolVersion version;
5050

51-
public VLPipeline(final UserConnection user) {
52-
this(user, Via.getManager().getProviders().get(VersionProvider.class).getServerProtocol(user));
51+
public VLPipeline(final UserConnection connection) {
52+
this(connection, Via.getManager().getProviders().get(VersionProvider.class).getServerProtocol(connection));
5353
}
5454

55-
public VLPipeline(final UserConnection user, final ProtocolVersion version) {
56-
this.user = user;
55+
public VLPipeline(final UserConnection connection, final ProtocolVersion version) {
56+
this.connection = connection;
5757
this.version = version;
5858
}
5959

6060
@Override
6161
public void handlerAdded(ChannelHandlerContext ctx) {
6262
ctx.pipeline().addBefore(this.packetCodecName(), VIA_CODEC_NAME, this.createViaCodec());
6363

64-
if (this.user.isClientSide()) {
64+
if (this.connection.isClientSide()) {
6565
final ProtocolVersion r1_6_4 = ProtocolVersion.getProtocol(VersionType.RELEASE_INITIAL, 78);
6666
if (ProtocolVersion.isRegistered(r1_6_4.getVersionType(), r1_6_4.getOriginalVersion()) && this.version.olderThanOrEqualTo(r1_6_4)) {
6767
ctx.pipeline().addBefore(this.lengthCodecName(), VIALEGACY_PRE_NETTY_LENGTH_CODEC_NAME, this.createViaLegacyPreNettyLengthCodec());
@@ -88,11 +88,11 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
8888
}
8989

9090
protected ChannelHandler createViaCodec() {
91-
return new ViaCodec(this.user);
91+
return new ViaCodec(this.connection);
9292
}
9393

9494
protected ChannelHandler createViaLegacyPreNettyLengthCodec() {
95-
return new PreNettyLengthCodec(this.user);
95+
return new PreNettyLengthCodec(this.connection);
9696
}
9797

9898
protected ChannelHandler createViaBedrockDisconnectHandler() {

0 commit comments

Comments
 (0)