ByteBuffers: Rename TextComponent functions to ChatComponent

This commit is contained in:
Bixilon 2020-12-08 17:20:22 +01:00
parent f0e922cdf5
commit 8b80ea6402
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
21 changed files with 46 additions and 35 deletions

View File

@ -48,7 +48,7 @@ public class EntityMetaData {
case INT -> buffer.readInt();
case FLOAT -> buffer.readFloat();
case STRING -> buffer.readString();
case CHAT -> buffer.readTextComponent();
case CHAT -> buffer.readChatComponent();
case BOOLEAN -> buffer.readBoolean();
case VECTOR -> new Vector(buffer.readInt(), buffer.readInt(), buffer.readInt());
case SLOT -> buffer.readSlot();
@ -56,7 +56,7 @@ public class EntityMetaData {
case POSITION -> buffer.readPosition();
case OPT_CHAT -> {
if (buffer.readBoolean()) {
yield buffer.readTextComponent();
yield buffer.readChatComponent();
}
yield null;
}

View File

@ -16,14 +16,18 @@ package de.bixilon.minosoft.data.text;
public final class RGBColor implements ChatCode {
private final int color;
public RGBColor(int color) {
this.color = color;
public RGBColor(int red, int green, int blue, int alpha) {
this.color = blue | (green << 8) | (red << 16) | (alpha << 24);
}
public RGBColor(int red, int green, int blue) {
this.color = blue | (green << 8) | (red << 16);
}
public RGBColor(int color) {
this.color = color;
}
public RGBColor(String colorString) {
if (colorString.startsWith("#")) {
colorString = colorString.substring(1);
@ -31,6 +35,10 @@ public final class RGBColor implements ChatCode {
color = Integer.parseInt(colorString, 16);
}
public int getAlpha() {
return (color >> 24) & 0xFF;
}
public int getRed() {
return (color >> 16) & 0xFF;
}
@ -63,6 +71,9 @@ public final class RGBColor implements ChatCode {
@Override
public String toString() {
if (getAlpha() > 0) {
return String.format("#%08X", color);
}
return String.format("#%06X", (0xFFFFFF & color));
}
}

View File

@ -192,7 +192,7 @@ public class SocketNetwork implements Network {
packet = connection.getPacketByCommand(connection.getConnectionState(), inPacketBuffer.getCommand());
if (packet == null) {
disconnect();
lastException = new UnknownPacketException(String.format("Server sent us a invalid packet (id=0x%x, length=%d, data=%s)", inPacketBuffer.getCommand(), length, inPacketBuffer.getBase64()));
lastException = new UnknownPacketException(String.format("Server sent us an invalid packet (id=0x%x, length=%d, data=%s)", inPacketBuffer.getCommand(), length, inPacketBuffer.getBase64()));
throw lastException;
}
Class<? extends ClientboundPacket> clazz = packet.getClazz();
@ -234,7 +234,7 @@ public class SocketNetwork implements Network {
disconnect();
} catch (IOException e) {
// Could not connect
Log.printException(e, LogLevels.DEBUG);
Log.printException(e, LogLevels.PROTOCOL);
if (socketSThread != null) {
socketSThread.interrupt();
}

View File

@ -24,7 +24,7 @@ public class PacketLoginDisconnect implements ClientboundPacket {
@Override
public boolean read(InByteBuffer buffer) {
reason = buffer.readTextComponent();
reason = buffer.readChatComponent();
return true;
}

View File

@ -47,8 +47,8 @@ public class PacketAdvancements implements ClientboundPacket {
}
AdvancementDisplay display = null;
if (buffer.readBoolean()) {
ChatComponent title = buffer.readTextComponent();
ChatComponent description = buffer.readTextComponent();
ChatComponent title = buffer.readChatComponent();
ChatComponent description = buffer.readChatComponent();
Slot icon = buffer.readSlot();
AdvancementDisplay.AdvancementFrameTypes frameType = AdvancementDisplay.AdvancementFrameTypes.byId(buffer.readVarInt());
int flags = buffer.readInt();

View File

@ -39,14 +39,14 @@ public class PacketBossBar implements ClientboundPacket {
action = BossBarActions.byId(buffer.readVarInt());
switch (action) {
case ADD -> {
title = buffer.readTextComponent();
title = buffer.readChatComponent();
health = buffer.readFloat();
color = BossBarColors.byId(buffer.readVarInt());
divisions = BossBarDivisions.byId(buffer.readVarInt());
flags = buffer.readByte();
}
case UPDATE_HEALTH -> health = buffer.readFloat();
case UPDATE_TITLE -> title = buffer.readTextComponent();
case UPDATE_TITLE -> title = buffer.readChatComponent();
case UPDATE_STYLE -> {
color = BossBarColors.byId(buffer.readVarInt());
divisions = BossBarDivisions.byId(buffer.readVarInt());

View File

@ -29,7 +29,7 @@ public class PacketChatMessageReceiving implements ClientboundPacket {
@Override
public boolean read(InByteBuffer buffer) {
message = buffer.readTextComponent();
message = buffer.readChatComponent();
if (buffer.getVersionId() < 7) {
position = ChatTextPositions.CHAT_BOX;
return true;

View File

@ -38,7 +38,7 @@ public class PacketCombatEvent implements ClientboundPacket {
case ENTITY_DEAD -> {
playerId = buffer.readVarInt();
entityId = buffer.readInt();
message = buffer.readTextComponent();
message = buffer.readChatComponent();
}
}
return true;

View File

@ -24,7 +24,7 @@ public class PacketDisconnect implements ClientboundPacket {
@Override
public boolean read(InByteBuffer buffer) {
reason = buffer.readTextComponent();
reason = buffer.readChatComponent();
return true;
}

View File

@ -102,7 +102,7 @@ public class PacketMapData implements ClientboundPacket {
byte direction = buffer.readByte();
ChatComponent displayName = null;
if (buffer.readBoolean()) {
displayName = buffer.readTextComponent();
displayName = buffer.readChatComponent();
}
pins.add(new MapPinSet(type, direction, x, z, displayName));
}

View File

@ -33,7 +33,7 @@ public class PacketOpenWindow implements ClientboundPacket {
if (buffer.getVersionId() < 6) {
this.windowId = buffer.readByte();
this.type = InventoryTypes.byId(buffer.readUnsignedByte());
this.title = buffer.readTextComponent();
this.title = buffer.readChatComponent();
slotCount = buffer.readByte();
if (!buffer.readBoolean()) {
// no custom name
@ -44,7 +44,7 @@ public class PacketOpenWindow implements ClientboundPacket {
}
this.windowId = buffer.readByte();
this.type = InventoryTypes.byName(buffer.readString());
this.title = buffer.readTextComponent();
this.title = buffer.readChatComponent();
if (buffer.getVersionId() < 452 || buffer.getVersionId() >= 464) {
slotCount = buffer.readByte();
}

View File

@ -61,12 +61,12 @@ public class PacketPlayerListItem implements ClientboundPacket {
}
GameModes gameMode = GameModes.byId(buffer.readVarInt());
int ping = buffer.readVarInt();
ChatComponent displayName = (buffer.readBoolean() ? buffer.readTextComponent() : null);
ChatComponent displayName = (buffer.readBoolean() ? buffer.readChatComponent() : null);
listItemBulk = new PlayerListItemBulk(uuid, name, ping, gameMode, displayName, playerProperties, action);
}
case UPDATE_GAMEMODE -> listItemBulk = new PlayerListItemBulk(uuid, null, 0, GameModes.byId(buffer.readVarInt()), null, null, action);
case UPDATE_LATENCY -> listItemBulk = new PlayerListItemBulk(uuid, null, buffer.readVarInt(), null, null, null, action);
case UPDATE_DISPLAY_NAME -> listItemBulk = new PlayerListItemBulk(uuid, null, 0, null, (buffer.readBoolean() ? buffer.readTextComponent() : null), null, action);
case UPDATE_DISPLAY_NAME -> listItemBulk = new PlayerListItemBulk(uuid, null, 0, null, (buffer.readBoolean() ? buffer.readChatComponent() : null), null, action);
case REMOVE_PLAYER -> listItemBulk = new PlayerListItemBulk(uuid, null, 0, null, null, null, action);
default -> listItemBulk = null;
}

View File

@ -29,12 +29,12 @@ public class PacketScoreboardObjective implements ClientboundPacket {
public boolean read(InByteBuffer buffer) {
name = buffer.readString();
if (buffer.getVersionId() < 7) { // ToDo
value = buffer.readTextComponent();
value = buffer.readChatComponent();
}
action = ScoreboardObjectiveActions.byId(buffer.readUnsignedByte());
if (action == ScoreboardObjectiveActions.CREATE || action == ScoreboardObjectiveActions.UPDATE) {
if (buffer.getVersionId() >= 7) { // ToDo
value = buffer.readTextComponent();
value = buffer.readChatComponent();
}
if (buffer.getVersionId() >= 12) {
if (buffer.getVersionId() >= 346 && buffer.getVersionId() < 349) {

View File

@ -25,8 +25,8 @@ public class PacketTabHeaderAndFooter implements ClientboundPacket {
@Override
public boolean read(InByteBuffer buffer) {
header = buffer.readTextComponent();
footer = buffer.readTextComponent();
header = buffer.readChatComponent();
footer = buffer.readChatComponent();
return true;
}

View File

@ -40,10 +40,10 @@ public class PacketTeams implements ClientboundPacket {
name = buffer.readString();
action = TeamActions.byId(buffer.readUnsignedByte());
if (action == TeamActions.CREATE || action == TeamActions.INFORMATION_UPDATE) {
displayName = buffer.readTextComponent();
displayName = buffer.readChatComponent();
if (buffer.getVersionId() < 352) {
prefix = buffer.readTextComponent();
suffix = buffer.readTextComponent();
prefix = buffer.readChatComponent();
suffix = buffer.readChatComponent();
}
if (buffer.getVersionId() < 100) { // ToDo
setFriendlyFireByLegacy(buffer.readByte());
@ -64,8 +64,8 @@ public class PacketTeams implements ClientboundPacket {
}
}
if (buffer.getVersionId() >= 375) {
prefix = buffer.readTextComponent();
suffix = buffer.readTextComponent();
prefix = buffer.readChatComponent();
suffix = buffer.readChatComponent();
}
}
if (action == TeamActions.CREATE || action == TeamActions.PLAYER_ADD || action == TeamActions.PLAYER_REMOVE) {

View File

@ -35,8 +35,8 @@ public class PacketTitle implements ClientboundPacket {
public boolean read(InByteBuffer buffer) {
action = TitleActions.byId(buffer.readVarInt(), buffer.getVersionId());
switch (action) {
case SET_TITLE -> text = buffer.readTextComponent();
case SET_SUBTITLE -> subText = buffer.readTextComponent();
case SET_TITLE -> text = buffer.readChatComponent();
case SET_SUBTITLE -> subText = buffer.readChatComponent();
case SET_TIMES_AND_DISPLAY -> {
fadeInTime = buffer.readInt();
stayTime = buffer.readInt();

View File

@ -32,7 +32,7 @@ public class PacketUpdateSignReceiving implements ClientboundPacket {
position = buffer.readPosition();
}
for (byte i = 0; i < 4; i++) {
lines[i] = buffer.readTextComponent();
lines[i] = buffer.readChatComponent();
}
return true;
}

View File

@ -44,7 +44,7 @@ public class PacketUpdateSignSending implements ServerboundPacket {
}
} else {
for (int i = 0; i < 4; i++) {
buffer.writeTextComponent(lines[i]);
buffer.writeChatComponent(lines[i]);
}
}
return buffer;

View File

@ -35,7 +35,7 @@ public class ServerListPing {
if (protocolId == -1) {
// Server did not send us a version, trying 1.8
this.protocolId = ProtocolDefinition.FALLBACK_PROTOCOL_VERSION_ID;
Log.warn(String.format("Server sent us a illegal version id (protocolId=%d). Using 1.8.9.", protocolId));
Log.warn(String.format("Server sent us an illegal version id (protocolId=%d). Using 1.8.9.", protocolId));
} else {
this.protocolId = protocolId;
}

View File

@ -199,7 +199,7 @@ public class InByteBuffer {
return new BlockPosition(x, y, z);
}
public ChatComponent readTextComponent() {
public ChatComponent readChatComponent() {
return ChatComponent.valueOf(readString());
}

View File

@ -76,7 +76,7 @@ public class OutByteBuffer {
writeBytes(buffer.array());
}
public void writeTextComponent(ChatComponent chatComponent) {
public void writeChatComponent(ChatComponent chatComponent) {
writeString(chatComponent.getMessage()); // ToDo: test if this should not be json
}