mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-07 08:58:20 +01:00
Fix JSON string not being displayable using ColoredText, remove unnecessary fields in PlayerListHeaderAndFooterPacket
This commit is contained in:
parent
728107b0fe
commit
200b244224
@ -178,7 +178,6 @@ public class ColoredText extends JsonMessage {
|
||||
|
||||
String currentColor = "";
|
||||
SpecialComponentContainer specialComponentContainer = new SpecialComponentContainer();
|
||||
|
||||
for (int i = 0; i < message.length(); i++) {
|
||||
// Last char or null
|
||||
final Character p = i == 0 ? null : message.charAt(i - 1);
|
||||
@ -202,7 +201,7 @@ public class ColoredText extends JsonMessage {
|
||||
continue;
|
||||
|
||||
inFormat = false;
|
||||
formatStart = 0;
|
||||
//formatStart = 0;
|
||||
formatEnd = i;
|
||||
|
||||
// Color component
|
||||
@ -270,13 +269,20 @@ public class ColoredText extends JsonMessage {
|
||||
objects.add(getMessagePart(MessageType.KEYBIND, keybindCode, currentColor, specialComponentContainer));
|
||||
continue;
|
||||
}
|
||||
|
||||
// Was not a component, add the encapsulated string
|
||||
final String current = message.substring(formatStart, i + 1);
|
||||
objects.add(getMessagePart(MessageType.RAW, current, currentColor, specialComponentContainer));
|
||||
}
|
||||
}
|
||||
|
||||
// Add the remaining of the message as a raw message when any
|
||||
if (formatEnd < message.length()) {
|
||||
final String lastRawMessage = message.substring(formatEnd + 1);
|
||||
objects.add(getMessagePart(MessageType.RAW, lastRawMessage, currentColor, specialComponentContainer));
|
||||
// if 'objects' is empty, an empty message is required for the client to understand the final JSON
|
||||
if (!lastRawMessage.isEmpty() || objects.isEmpty()) {
|
||||
objects.add(getMessagePart(MessageType.RAW, lastRawMessage, currentColor, specialComponentContainer));
|
||||
}
|
||||
}
|
||||
|
||||
return objects;
|
||||
|
@ -937,8 +937,6 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
*/
|
||||
public void sendHeaderFooter(@Nullable JsonMessage header, @Nullable JsonMessage footer) {
|
||||
PlayerListHeaderAndFooterPacket playerListHeaderAndFooterPacket = new PlayerListHeaderAndFooterPacket();
|
||||
playerListHeaderAndFooterPacket.emptyHeader = header == null;
|
||||
playerListHeaderAndFooterPacket.emptyFooter = footer == null;
|
||||
playerListHeaderAndFooterPacket.header = header;
|
||||
playerListHeaderAndFooterPacket.footer = footer;
|
||||
|
||||
|
@ -10,22 +10,18 @@ public class PlayerListHeaderAndFooterPacket implements ServerPacket {
|
||||
|
||||
private static final String EMPTY_COMPONENT = "{\"translate\":\"\"}";
|
||||
|
||||
public boolean emptyHeader;
|
||||
public boolean emptyFooter;
|
||||
|
||||
public JsonMessage header; // Only text
|
||||
public JsonMessage footer; // Only text
|
||||
|
||||
|
||||
@Override
|
||||
public void write(@NotNull BinaryWriter writer) {
|
||||
if (emptyHeader) {
|
||||
if (header == null) {
|
||||
writer.writeSizedString(EMPTY_COMPONENT);
|
||||
} else {
|
||||
writer.writeSizedString(header.toString());
|
||||
}
|
||||
|
||||
if (emptyFooter) {
|
||||
if (footer == null) {
|
||||
writer.writeSizedString(EMPTY_COMPONENT);
|
||||
} else {
|
||||
writer.writeSizedString(footer.toString());
|
||||
|
Loading…
Reference in New Issue
Block a user