Skip to content

Commit 5dc2bba

Browse files
committed
Add support for 8-digit numbers in online/max fields
1 parent 8ad8543 commit 5dc2bba

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/main/java/net/elytrium/fastmotd/holder/MOTDBytesHolder.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public MOTDBytesHolder(ComponentSerializer<Component, Component, String> inputSe
4848
this.inputSerializer = inputSerializer;
4949
ServerPing.Builder compatServerPingBuilder = ServerPing.builder();
5050

51-
StringBuilder motd = new StringBuilder("{\"players\":{\"max\": 0,\"online\": 1,\"sample\":[");
51+
StringBuilder motd = new StringBuilder("{\"players\":{\"max\": 0,\"online\": 1,\"sample\":[");
5252

5353
compatServerPingBuilder.maximumPlayers(0);
5454
compatServerPingBuilder.onlinePlayers(1);
@@ -98,8 +98,8 @@ public MOTDBytesHolder(ComponentSerializer<Component, Component, String> inputSe
9898
int lengthOfLength = ProtocolUtils.varIntBytes(length);
9999
varIntLength += lengthOfLength;
100100

101-
this.maxOnlineDigit = Bytes.indexOf(bytes, " 0".getBytes(StandardCharsets.UTF_8)) + 1 + varIntLength;
102-
this.onlineDigit = Bytes.indexOf(bytes, " 1".getBytes(StandardCharsets.UTF_8)) + 1 + varIntLength;
101+
this.maxOnlineDigit = Bytes.indexOf(bytes, " 0".getBytes(StandardCharsets.UTF_8)) + 1 + varIntLength;
102+
this.onlineDigit = Bytes.indexOf(bytes, " 1".getBytes(StandardCharsets.UTF_8)) + 1 + varIntLength;
103103
this.protocolDigit = Bytes.indexOf(bytes, "protocol\": 1}".getBytes(StandardCharsets.UTF_8)) + 19 + varIntLength;
104104

105105
this.byteBuf = Unpooled.directBuffer(length + lengthOfLength);
@@ -127,11 +127,14 @@ public void replaceOnline(int max, int online) {
127127
}
128128

129129
private void localReplaceOnline(int digit, int to) {
130-
this.byteBuf.setByte(digit, to >= 10000 ? (to / 10000 % 10) + '0' : ' ');
131-
this.byteBuf.setByte(digit + 1, to >= 1000 ? (to / 1000 % 10) + '0' : ' ');
132-
this.byteBuf.setByte(digit + 2, to >= 100 ? (to / 100 % 10) + '0' : ' ');
133-
this.byteBuf.setByte(digit + 3, to >= 10 ? (to / 10 % 10) + '0' : ' ');
134-
this.byteBuf.setByte(digit + 4, (to % 10) + '0');
130+
this.byteBuf.setByte(digit + 0, to >= 10000000 ? (to / 10000000 % 10) + '0' : ' ');
131+
this.byteBuf.setByte(digit + 1, to >= 1000000 ? (to / 1000000 % 10) + '0' : ' ');
132+
this.byteBuf.setByte(digit + 2, to >= 100000 ? (to / 100000 % 10) + '0' : ' ');
133+
this.byteBuf.setByte(digit + 3, to >= 10000 ? (to / 10000 % 10) + '0' : ' ');
134+
this.byteBuf.setByte(digit + 4, to >= 1000 ? (to / 1000 % 10) + '0' : ' ');
135+
this.byteBuf.setByte(digit + 5, to >= 100 ? (to / 100 % 10) + '0' : ' ');
136+
this.byteBuf.setByte(digit + 6, to >= 10 ? (to / 10 % 10) + '0' : ' ');
137+
this.byteBuf.setByte(digit + 7, (to % 10) + '0');
135138
}
136139

137140
public ServerPing getCompatPingInfo(ProtocolVersion version, boolean replaceProtocol) {

0 commit comments

Comments
 (0)