/
0048-1.13-scoreboard-support.patch
161 lines (152 loc) · 6.83 KB
/
0048-1.13-scoreboard-support.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
From a25bca47d6013791dfb61366811c8546d8d86422 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Sat, 21 Jul 2018 17:14:39 +0100
Subject: [PATCH] 1.13 scoreboard support
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java
index 10e16d79..f902301e 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/DefinedPacket.java
@@ -5,6 +5,9 @@ import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
+import net.md_5.bungee.api.chat.BaseComponent; // Waterfall - 1.13
+import net.md_5.bungee.api.chat.TextComponent; // Waterfall - 1.13
+import net.md_5.bungee.chat.ComponentSerializer; // Waterfall - 1.13
import java.util.UUID;
@@ -183,6 +186,15 @@ public abstract class DefinedPacket
return new UUID( input.readLong(), input.readLong() );
}
+ // Waterfall start - 1.13
+ public static String readComponentAsString(ByteBuf buf)
+ {
+ String json = readString(buf);
+ BaseComponent[] components = ComponentSerializer.parse(json);
+ return components[0] == null ? json : TextComponent.toLegacyText(components);
+ }
+ // Waterfall end - 1.13
+
public void read(ByteBuf buf)
{
throw new UnsupportedOperationException( "Packet must implement read method" );
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java
index 6279d9f3..9f9c76fc 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/ScoreboardObjective.java
@@ -1,5 +1,8 @@
package net.md_5.bungee.protocol.packet;
+import net.md_5.bungee.api.chat.BaseComponent;
+import net.md_5.bungee.api.chat.TextComponent; // Waterfall - 1.13
+import net.md_5.bungee.chat.ComponentSerializer; // Waterfall - 1.13
import net.md_5.bungee.protocol.DefinedPacket;
import io.netty.buffer.ByteBuf;
import java.util.Locale;
@@ -32,12 +35,15 @@ public class ScoreboardObjective extends DefinedPacket
action = buf.readByte();
if ( action == 0 || action == 2 )
{
- value = readString( buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
{
+ // Waterfall start - 1.13
+ value = readComponentAsString(buf);
type = HealthDisplay.values()[readVarInt( buf )];
} else
{
+ value = readString(buf);
+ // Waterfall end
type = HealthDisplay.fromString( readString( buf ) );
}
}
@@ -50,12 +56,16 @@ public class ScoreboardObjective extends DefinedPacket
buf.writeByte( action );
if ( action == 0 || action == 2 )
{
- writeString( value, buf );
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
{
+ // Waterfall start - 1.13
+ String valueJson = ComponentSerializer.toString(TextComponent.fromLegacyText(value));
+ writeString(valueJson, buf);
writeVarInt( type.ordinal(), buf );
} else
{
+ writeString(value, buf);
+ // Waterfall end
writeString( type.toString(), buf );
}
}
diff --git a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java
index f93508d9..8be62c7b 100644
--- a/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java
+++ b/protocol/src/main/java/net/md_5/bungee/protocol/packet/Team.java
@@ -1,5 +1,8 @@
package net.md_5.bungee.protocol.packet;
+import net.md_5.bungee.api.chat.BaseComponent;
+import net.md_5.bungee.api.chat.TextComponent; // Waterfall
+import net.md_5.bungee.chat.ComponentSerializer; // Waterfall
import net.md_5.bungee.protocol.DefinedPacket;
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
@@ -46,7 +49,13 @@ public class Team extends DefinedPacket
mode = buf.readByte();
if ( mode == 0 || mode == 2 )
{
- displayName = readString( buf );
+ // Waterfall start - 1.13
+ if (protocolVersion >= ProtocolConstants.MINECRAFT_1_13) {
+ displayName = readComponentAsString( buf );
+ } else {
+ displayName = readString( buf );
+ }
+ // Waterfall end
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_13 )
{
prefix = readString( buf );
@@ -61,8 +70,10 @@ public class Team extends DefinedPacket
color = ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 ) ? readVarInt( buf ) : buf.readByte();
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
{
- prefix = readString( buf );
- suffix = readString( buf );
+ // Waterfall start - 1.13
+ prefix = readComponentAsString( buf );
+ suffix = readComponentAsString( buf );
+ // Waterfall end
}
}
if ( mode == 0 || mode == 3 || mode == 4 )
@@ -83,7 +94,14 @@ public class Team extends DefinedPacket
buf.writeByte( mode );
if ( mode == 0 || mode == 2 )
{
- writeString( displayName, buf );
+ // Waterfall start - 1.13
+ if (protocolVersion >= ProtocolConstants.MINECRAFT_1_13) {
+ String displayNameJson = ComponentSerializer.toString(TextComponent.fromLegacyText(displayName));
+ writeString( displayNameJson, buf );
+ } else {
+ writeString( displayName, buf );
+ }
+ // Waterfall end - 1.13
if ( protocolVersion < ProtocolConstants.MINECRAFT_1_13 )
{
writeString( prefix, buf );
@@ -98,9 +116,14 @@ public class Team extends DefinedPacket
if ( protocolVersion >= ProtocolConstants.MINECRAFT_1_13 )
{
+ // Waterfall start - 1.13
+ String prefixJson = ComponentSerializer.toString(TextComponent.fromLegacyText(prefix));
+ String suffixJson = ComponentSerializer.toString(TextComponent.fromLegacyText(suffix));
+
writeVarInt( color, buf );
- writeString( prefix, buf );
- writeString( suffix, buf );
+ writeString( prefixJson, buf );
+ writeString( suffixJson, buf );
+ // Waterfall end - 1.13
} else
{
buf.writeByte( color );
--
2.18.0