Skip to content

Commit 43c42f4

Browse files
Move handler names to the platform
As needs platform handling it should be directly exposed to the wrapper rather than being in the storage
1 parent 295d87d commit 43c42f4

File tree

3 files changed

+36
-16
lines changed

3 files changed

+36
-16
lines changed

common/src/main/java/com/viaversion/viarewind/api/ViaRewindPlatform.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,23 @@ default void init(final File configFile) {
7070
* @return data folder
7171
*/
7272
File getDataFolder();
73+
74+
/**
75+
* Returns the platform's compression handler name. Only used in the 1.8 -> 1.7 protocol.
76+
*
77+
* @return the compression handler name
78+
*/
79+
default String compressHandlerName() {
80+
return "compress";
81+
}
82+
83+
/**
84+
* Returns the platform's decompression handler name. Only used in the 1.8 -> 1.7 protocol.
85+
*
86+
* @return the decompression handler name
87+
*/
88+
default String decompressHandlerName() {
89+
return "decompress";
90+
}
91+
7392
}

common/src/main/java/com/viaversion/viarewind/protocol/v1_8to1_7_6_10/provider/compression/TrackingCompressionHandlerProvider.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
*/
1818
package com.viaversion.viarewind.protocol.v1_8to1_7_6_10.provider.compression;
1919

20+
import com.viaversion.viarewind.ViaRewind;
2021
import com.viaversion.viarewind.api.minecraft.netty.EmptyChannelHandler;
2122
import com.viaversion.viarewind.api.minecraft.netty.ForwardMessageToByteEncoder;
2223
import com.viaversion.viarewind.protocol.v1_8to1_7_6_10.provider.CompressionHandlerProvider;
@@ -31,34 +32,23 @@ public class TrackingCompressionHandlerProvider extends CompressionHandlerProvid
3132
public void onHandleLoginCompressionPacket(UserConnection user, int threshold) {
3233
final ChannelPipeline pipeline = user.getChannel().pipeline();
3334
if (user.isClientSide()) {
34-
pipeline.addBefore(Via.getManager().getInjector().getEncoderName(), compressHandlerName(), getEncoder(threshold));
35-
pipeline.addBefore(Via.getManager().getInjector().getDecoderName(), decompressHandlerName(), getDecoder(threshold));
35+
pipeline.addBefore(Via.getManager().getInjector().getEncoderName(), ViaRewind.getPlatform().compressHandlerName(), getEncoder(threshold));
36+
pipeline.addBefore(Via.getManager().getInjector().getDecoderName(), ViaRewind.getPlatform().decompressHandlerName(), getDecoder(threshold));
3637
} else {
3738
setCompressionEnabled(user, true); // We need to remove compression for 1.7 clients
3839
}
3940
}
4041

41-
public String compressHandlerName() {
42-
return "compress";
43-
}
44-
45-
public String decompressHandlerName() {
46-
return "decompress";
47-
}
48-
4942
@Override
5043
public void onTransformPacket(UserConnection user) {
5144
if (isCompressionEnabled(user)) {
5245
final ChannelPipeline pipeline = user.getChannel().pipeline();
5346

5447
String compressor = null;
5548
String decompressor = null;
56-
if (pipeline.get(compressHandlerName()) != null) { // ViaVersion
57-
compressor = compressHandlerName();
58-
decompressor = decompressHandlerName();
59-
} else if (pipeline.get("compression-encoder") != null) { // Velocity
60-
compressor = "compression-encoder";
61-
decompressor = "compression-decoder";
49+
if (pipeline.get(ViaRewind.getPlatform().compressHandlerName()) != null) {
50+
compressor = ViaRewind.getPlatform().compressHandlerName();
51+
decompressor = ViaRewind.getPlatform().decompressHandlerName();
6252
}
6353

6454
if (compressor != null) { // We can neutralize the effect of compressor to the client

velocity/src/main/java/com/viaversion/viarewind/VelocityPlugin.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,15 @@ public File getDataFolder() {
6868
public Logger getLogger() {
6969
return this.logger;
7070
}
71+
72+
@Override
73+
public String compressHandlerName() {
74+
return "compression-encoder";
75+
}
76+
77+
@Override
78+
public String decompressHandlerName() {
79+
return "compression-decoder";
80+
}
81+
7182
}

0 commit comments

Comments
 (0)