TitleSerializer -> TextMapper
This commit is contained in:
@@ -9,7 +9,7 @@ import lombok.Setter;
|
|||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import mc.core.network.NetOutputStream;
|
import mc.core.network.NetOutputStream;
|
||||||
import mc.core.network.SCPacket;
|
import mc.core.network.SCPacket;
|
||||||
import mc.core.network.proto_1_12_2.serializers.TextSerializer;
|
import mc.core.network.proto_1_12_2.serializers.TextMapper;
|
||||||
import mc.core.text.Text;
|
import mc.core.text.Text;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -72,7 +72,7 @@ public class BossBarPacket implements SCPacket {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (action == ACTION_ADD || action == ACTION_UPDATE_TITLE) {
|
if (action == ACTION_ADD || action == ACTION_UPDATE_TITLE) {
|
||||||
netStream.writeString(TextSerializer.serialize(barData.title).toString());
|
netStream.writeString(TextMapper.getInstance().mapping(barData.title));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action == ACTION_ADD || action == ACTION_UPDATE_HEALTH) {
|
if (action == ACTION_ADD || action == ACTION_UPDATE_HEALTH) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import lombok.ToString;
|
|||||||
import mc.core.chat.MessageType;
|
import mc.core.chat.MessageType;
|
||||||
import mc.core.network.NetOutputStream;
|
import mc.core.network.NetOutputStream;
|
||||||
import mc.core.network.SCPacket;
|
import mc.core.network.SCPacket;
|
||||||
import mc.core.network.proto_1_12_2.serializers.TextSerializer;
|
import mc.core.network.proto_1_12_2.serializers.TextMapper;
|
||||||
import mc.core.text.Text;
|
import mc.core.text.Text;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@@ -24,7 +24,7 @@ public class ChatMessageServerPacket implements SCPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSelf(NetOutputStream netStream) {
|
public void writeSelf(NetOutputStream netStream) {
|
||||||
netStream.writeString(TextSerializer.serialize(text).toString());
|
netStream.writeString(TextMapper.getInstance().mapping(text));
|
||||||
netStream.writeByte(type.getId());
|
netStream.writeByte(type.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import lombok.NoArgsConstructor;
|
|||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import mc.core.network.NetOutputStream;
|
import mc.core.network.NetOutputStream;
|
||||||
import mc.core.network.SCPacket;
|
import mc.core.network.SCPacket;
|
||||||
import mc.core.network.proto_1_12_2.serializers.TextSerializer;
|
import mc.core.network.proto_1_12_2.serializers.TextMapper;
|
||||||
import mc.core.text.Text;
|
import mc.core.text.Text;
|
||||||
|
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@@ -20,6 +20,6 @@ public class DisconnectPacket implements SCPacket {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeSelf(NetOutputStream netStream) {
|
public void writeSelf(NetOutputStream netStream) {
|
||||||
netStream.writeString(TextSerializer.serialize(reason).toString());
|
netStream.writeString(TextMapper.getInstance().mapping(reason));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import lombok.Setter;
|
|||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import mc.core.network.NetOutputStream;
|
import mc.core.network.NetOutputStream;
|
||||||
import mc.core.network.SCPacket;
|
import mc.core.network.SCPacket;
|
||||||
import mc.core.network.proto_1_12_2.serializers.TextSerializer;
|
import mc.core.network.proto_1_12_2.serializers.TextMapper;
|
||||||
import mc.core.text.Text;
|
import mc.core.text.Text;
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
@@ -23,13 +23,13 @@ public class PlayerListHeaderAndFooterPacket implements SCPacket {
|
|||||||
if (header == null) {
|
if (header == null) {
|
||||||
netStream.writeString("{\"translate\":\"\"}");
|
netStream.writeString("{\"translate\":\"\"}");
|
||||||
} else {
|
} else {
|
||||||
netStream.writeString(TextSerializer.serialize(header).toString());
|
netStream.writeString(TextMapper.getInstance().mapping(header));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (footer == null) {
|
if (footer == null) {
|
||||||
netStream.writeString("{\"translate\":\"\"}");
|
netStream.writeString("{\"translate\":\"\"}");
|
||||||
} else {
|
} else {
|
||||||
netStream.writeString(TextSerializer.serialize(footer).toString());
|
netStream.writeString(TextMapper.getInstance().mapping(footer));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import lombok.ToString;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import mc.core.network.NetOutputStream;
|
import mc.core.network.NetOutputStream;
|
||||||
import mc.core.network.SCPacket;
|
import mc.core.network.SCPacket;
|
||||||
import mc.core.network.proto_1_12_2.serializers.TextSerializer;
|
import mc.core.network.proto_1_12_2.serializers.TextMapper;
|
||||||
import mc.core.player.PlayerMode;
|
import mc.core.player.PlayerMode;
|
||||||
import mc.core.text.Text;
|
import mc.core.text.Text;
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ public class PlayerListItemPacket implements SCPacket {
|
|||||||
if (action == ACTION_ADD_PLAYER || action == ACTION_UPDATE_DISPLAY_NAME) {
|
if (action == ACTION_ADD_PLAYER || action == ACTION_UPDATE_DISPLAY_NAME) {
|
||||||
netStream.writeBoolean(playerData.hasDisplayName);
|
netStream.writeBoolean(playerData.hasDisplayName);
|
||||||
if (playerData.hasDisplayName) {
|
if (playerData.hasDisplayName) {
|
||||||
netStream.writeString(TextSerializer.serialize(playerData.displayName).toString());
|
netStream.writeString(TextMapper.getInstance().mapping(playerData.displayName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import lombok.Setter;
|
|||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
import mc.core.network.NetOutputStream;
|
import mc.core.network.NetOutputStream;
|
||||||
import mc.core.network.SCPacket;
|
import mc.core.network.SCPacket;
|
||||||
import mc.core.network.proto_1_12_2.serializers.TextSerializer;
|
import mc.core.network.proto_1_12_2.serializers.TextMapper;
|
||||||
import mc.core.text.Text;
|
import mc.core.text.Text;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@@ -98,7 +98,7 @@ public class TitlePacket implements SCPacket {
|
|||||||
case SET_TITLE:
|
case SET_TITLE:
|
||||||
case SET_SUBTITLE:
|
case SET_SUBTITLE:
|
||||||
case SET_ACTION_BAR:
|
case SET_ACTION_BAR:
|
||||||
netStream.writeString(TextSerializer.serialize(this.text).toString());
|
netStream.writeString(TextMapper.getInstance().mapping(this.text));
|
||||||
break;
|
break;
|
||||||
case SET_DISPLAY_TIME:
|
case SET_DISPLAY_TIME:
|
||||||
netStream.writeInt(this.fadeInTime);
|
netStream.writeInt(this.fadeInTime);
|
||||||
|
|||||||
@@ -6,10 +6,14 @@ package mc.core.network.proto_1_12_2.serializers;
|
|||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import lombok.Getter;
|
||||||
import mc.core.text.Text;
|
import mc.core.text.Text;
|
||||||
|
|
||||||
public class TextSerializer {
|
public class TextMapper implements Mapper<Text, String> {
|
||||||
public static JsonObject serialize(Text text) {
|
@Getter
|
||||||
|
private static TextMapper instance = new TextMapper();
|
||||||
|
|
||||||
|
private JsonObject serialize(Text text) {
|
||||||
JsonObject jsonObject = new JsonObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
jsonObject.addProperty("text", text.getContent());
|
jsonObject.addProperty("text", text.getContent());
|
||||||
|
|
||||||
@@ -43,4 +47,9 @@ public class TextSerializer {
|
|||||||
|
|
||||||
return jsonObject;
|
return jsonObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String mapping(Text fromObject) {
|
||||||
|
return serialize(fromObject).toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user