Botcraft 1.21.4
Loading...
Searching...
No Matches
Chat.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4
5#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
7#else
9#endif
10
11namespace ProtocolCraft
12{
13#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
14 class Chat : public NetworkType
15#else
16 class Chat : public NBT::Tag
17#endif
18 {
19 public:
20 virtual ~Chat() override
21 {
22
23 }
24
25#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
26 auto& SetRawText(const std::string& s)
27 {
28 raw_text = s;
29 return *this;
30 }
31#endif
32
33 const std::string& GetText() const
34 {
35 return text;
36 }
37
38#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
39 const std::string& GetRawText() const
40 {
41 return raw_text;
42 }
43#endif
44
45 protected:
46 virtual void ReadImpl(ReadIterator& iter, size_t& length) override
47 {
48#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
49 raw_text = ReadData<std::string>(iter, length);
50 text = ParseChat(Json::Parse(raw_text));
51#else
52 NBT::Tag::ReadUnnamedImpl(iter, length);
53 if (is<NBT::TagCompound>())
54 {
55 text = ParseChat(get<NBT::TagCompound>());
56 }
57 else if (is<NBT::TagString>())
58 {
59 text = get<NBT::TagString>();
60 }
61#endif
62
63 }
64
65 virtual void WriteImpl(WriteContainer& container) const override
66 {
67#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
68 WriteData<std::string>(raw_text, container);
69#else
71#endif
72 }
73
74#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
75 virtual Json::Value SerializeImpl() const override
76 {
77 Json::Value output;
78
79 output["raw_text"] = raw_text;
80
81 return output;
82 }
83#endif
84
85 private:
86#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
87 std::string ParseChat(const Json::Value& raw_json);
88#else
89 std::string ParseChat(const NBT::TagCompound& raw);
90#endif
91
92
93 private:
94 std::string text;
95#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
96 std::string raw_text;
97#endif
98 };
99}
std::string text
Definition Chat.hpp:94
const std::string & GetText() const
Definition Chat.hpp:33
virtual void ReadImpl(ReadIterator &iter, size_t &length) override
Definition Chat.hpp:46
std::string ParseChat(const NBT::TagCompound &raw)
Definition Chat.cpp:77
virtual void WriteImpl(WriteContainer &container) const override
Definition Chat.hpp:65
virtual ~Chat() override
Definition Chat.hpp:20
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45
void WriteUnnamedImpl(WriteContainer &container) const
Definition Tag.cpp:159
virtual Json::Value SerializeImpl() const override
Definition Tag.cpp:329
void ReadUnnamedImpl(ReadIterator &iter, size_t &length)
Definition Tag.cpp:94
Value Parse(std::string_view::const_iterator iter, size_t length, bool no_except=false)
Parse a string_view from iter for at most length characters.
Definition Json.cpp:390
std::vector< unsigned char > WriteContainer
std::vector< unsigned char >::const_iterator ReadIterator