Skip to content

Commit

Permalink
Add support for 8-digit numbers in online/max fields
Browse files Browse the repository at this point in the history
  • Loading branch information
UserNugget committed Jul 1, 2024
1 parent 8ad8543 commit 5dc2bba
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/main/java/net/elytrium/fastmotd/holder/MOTDBytesHolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public MOTDBytesHolder(ComponentSerializer<Component, Component, String> inputSe
this.inputSerializer = inputSerializer;
ServerPing.Builder compatServerPingBuilder = ServerPing.builder();

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

compatServerPingBuilder.maximumPlayers(0);
compatServerPingBuilder.onlinePlayers(1);
Expand Down Expand Up @@ -98,8 +98,8 @@ public MOTDBytesHolder(ComponentSerializer<Component, Component, String> inputSe
int lengthOfLength = ProtocolUtils.varIntBytes(length);
varIntLength += lengthOfLength;

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

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

private void localReplaceOnline(int digit, int to) {
this.byteBuf.setByte(digit, to >= 10000 ? (to / 10000 % 10) + '0' : ' ');
this.byteBuf.setByte(digit + 1, to >= 1000 ? (to / 1000 % 10) + '0' : ' ');
this.byteBuf.setByte(digit + 2, to >= 100 ? (to / 100 % 10) + '0' : ' ');
this.byteBuf.setByte(digit + 3, to >= 10 ? (to / 10 % 10) + '0' : ' ');
this.byteBuf.setByte(digit + 4, (to % 10) + '0');
this.byteBuf.setByte(digit + 0, to >= 10000000 ? (to / 10000000 % 10) + '0' : ' ');
this.byteBuf.setByte(digit + 1, to >= 1000000 ? (to / 1000000 % 10) + '0' : ' ');
this.byteBuf.setByte(digit + 2, to >= 100000 ? (to / 100000 % 10) + '0' : ' ');
this.byteBuf.setByte(digit + 3, to >= 10000 ? (to / 10000 % 10) + '0' : ' ');
this.byteBuf.setByte(digit + 4, to >= 1000 ? (to / 1000 % 10) + '0' : ' ');
this.byteBuf.setByte(digit + 5, to >= 100 ? (to / 100 % 10) + '0' : ' ');
this.byteBuf.setByte(digit + 6, to >= 10 ? (to / 10 % 10) + '0' : ' ');
this.byteBuf.setByte(digit + 7, (to % 10) + '0');
}

public ServerPing getCompatPingInfo(ProtocolVersion version, boolean replaceProtocol) {
Expand Down

0 comments on commit 5dc2bba

Please sign in to comment.