Skip to content

Commit ee4b60e

Browse files
committed
Update to ViaVersion 3.0 for 1.16 support
1 parent 647bcc8 commit ee4b60e

File tree

5 files changed

+40
-53
lines changed

5 files changed

+40
-53
lines changed

bukkit/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>fr.mrmicky</groupId>
99
<artifactId>viachatfixer</artifactId>
10-
<version>0.2.0</version>
10+
<version>0.3.0</version>
1111
</parent>
1212

1313
<artifactId>viachatfixer-bukkit</artifactId>
@@ -17,7 +17,7 @@
1717
<repositories>
1818
<repository>
1919
<id>spigotmc-repo</id>
20-
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
20+
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
2121
</repository>
2222
</repositories>
2323

common/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>fr.mrmicky</groupId>
99
<artifactId>viachatfixer</artifactId>
10-
<version>0.2.0</version>
10+
<version>0.3.0</version>
1111
</parent>
1212

1313
<artifactId>viachatfixer-common</artifactId>

common/src/main/java/fr/mrmicky/viachatfixer/handlers/via/ViaChatHandler.java

Lines changed: 34 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,88 +2,73 @@
22

33
import fr.mrmicky.viachatfixer.ViaChatFixerPlatform;
44
import fr.mrmicky.viachatfixer.handlers.ChatHandler;
5-
import us.myles.ViaVersion.api.PacketWrapper;
65
import us.myles.ViaVersion.api.Via;
76
import us.myles.ViaVersion.api.data.UserConnection;
87
import us.myles.ViaVersion.api.protocol.Protocol;
98
import us.myles.ViaVersion.api.protocol.ProtocolRegistry;
109
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
11-
import us.myles.ViaVersion.api.remapper.PacketHandler;
1210
import us.myles.ViaVersion.api.remapper.PacketRemapper;
1311
import us.myles.ViaVersion.api.type.Type;
1412
import us.myles.ViaVersion.packets.State;
1513
import us.myles.ViaVersion.protocols.protocol1_11to1_10.Protocol1_11To1_10;
14+
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.ServerboundPackets1_9_3;
1615

17-
import java.lang.reflect.Field;
1816
import java.util.HashSet;
19-
import java.util.Map;
2017
import java.util.Set;
2118
import java.util.UUID;
2219

2320
public class ViaChatHandler implements ChatHandler {
2421

2522
private final Set<UUID> unknownPlayers = new HashSet<>();
2623

27-
private ViaChatFixerPlatform platform;
24+
private final ViaChatFixerPlatform platform;
2825

2926
public ViaChatHandler(ViaChatFixerPlatform platform) {
3027
this.platform = platform;
3128
}
3229

3330
@Override
34-
public void init() throws Exception {
31+
public void init() {
3532
if (ProtocolRegistry.SERVER_PROTOCOL >= ProtocolVersion.v1_11.getId()) {
3633
platform.getLogger().warning("This plugin is not required on 1.11+ servers, you can just remove it :)");
34+
return;
3735
}
3836

39-
Field registryMapField = ProtocolRegistry.class.getDeclaredField("registryMap");
40-
registryMapField.setAccessible(true);
41-
4237
//noinspection unchecked
43-
Map<Integer, Map<Integer, Protocol>> registryMap = (Map<Integer, Map<Integer, Protocol>>) registryMapField.get(null);
44-
45-
Protocol protocol = null;
46-
for (Map<Integer, Protocol> protocolMap : registryMap.values()) {
47-
for (Protocol prot : protocolMap.values()) {
48-
if (prot instanceof Protocol1_11To1_10) {
49-
protocol = prot;
50-
break;
51-
}
52-
}
53-
}
38+
Protocol<?, ?, ?, ServerboundPackets1_9_3> protocol = ProtocolRegistry.getProtocol(Protocol1_11To1_10.class);
5439

5540
if (protocol == null) {
56-
throw new RuntimeException("Protocol 1_11To1_10 not found");
41+
throw new IllegalStateException("Protocol 1_11To1_10 not found");
5742
}
5843

5944
protocol.registerIncoming(State.PLAY, 0x02, 0x02, new PacketRemapper() {
6045
@Override
6146
public void registerMap() {
6247
map(Type.STRING); // 0 - Message
63-
handler(new PacketHandler() {
64-
@Override
65-
public void handle(PacketWrapper wrapper) throws Exception {
66-
String msg = wrapper.get(Type.STRING, 0);
48+
handler(wrapper -> {
49+
// 100 character limit on older servers
50+
String message = wrapper.get(Type.STRING, 0);
6751

68-
if (msg.length() > 100) {
69-
wrapper.set(Type.STRING, 0, msg.substring(0, 100));
52+
if (message.length() <= 100) {
53+
return;
54+
}
7055

71-
UserConnection connection = wrapper.user();
72-
ChatTracker chatTracker = connection.get(ChatTracker.class);
56+
wrapper.set(Type.STRING, 0, message.substring(0, 100));
7357

74-
if (chatTracker == null) {
75-
chatTracker = new ChatTracker(connection);
76-
connection.put(chatTracker);
77-
}
58+
UserConnection connection = wrapper.user();
59+
ChatTracker chatTracker = connection.get(ChatTracker.class);
7860

79-
// don't allow messages longer than 256 characters
80-
if (msg.length() > 256) {
81-
msg = msg.substring(0, 256);
82-
}
61+
if (chatTracker == null) {
62+
chatTracker = new ChatTracker(connection);
63+
connection.put(chatTracker);
64+
}
8365

84-
chatTracker.updateLastMessage(msg);
85-
}
66+
// don't allow messages longer than 256 characters
67+
if (message.length() > 256) {
68+
message = message.substring(0, 256);
8669
}
70+
71+
chatTracker.updateLastMessage(message);
8772
});
8873
}
8974
}, true);
@@ -102,17 +87,19 @@ public String handle(UUID uuid) {
10287

10388
ChatTracker chatTracker = connection.get(ChatTracker.class);
10489

105-
if (chatTracker != null && chatTracker.getLastMessage() != null) {
106-
if (!chatTracker.isValid(100)) {
107-
chatTracker.reset();
108-
return null;
109-
}
90+
if (chatTracker == null || chatTracker.getLastMessage() == null) {
91+
return null;
92+
}
11093

111-
String message = chatTracker.getLastMessage();
94+
if (!chatTracker.isValid(100)) {
11295
chatTracker.reset();
113-
return message;
96+
return null;
11497
}
11598

116-
return null;
99+
String message = chatTracker.getLastMessage();
100+
101+
chatTracker.reset();
102+
103+
return message;
117104
}
118105
}

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>fr.mrmicky</groupId>
88
<artifactId>viachatfixer</artifactId>
9-
<version>0.2.0</version>
9+
<version>0.3.0</version>
1010
<packaging>pom</packaging>
1111

1212
<name>ViaChatFixer</name>
@@ -48,7 +48,7 @@
4848
<dependency>
4949
<groupId>us.myles</groupId>
5050
<artifactId>viaversion</artifactId>
51-
<version>2.1.3</version>
51+
<version>3.0.0</version>
5252
<scope>provided</scope>
5353
</dependency>
5454
</dependencies>

universal/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>fr.mrmicky</groupId>
99
<artifactId>viachatfixer</artifactId>
10-
<version>0.2.0</version>
10+
<version>0.3.0</version>
1111
</parent>
1212

1313
<artifactId>viachatfixer-universal</artifactId>

0 commit comments

Comments
 (0)