Botcraft 26.3
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
10#include <vector>
11#endif
12
13namespace ProtocolCraft
14{
15#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
16 class Chat : public NetworkType
17#else
18 class Chat : public NBT::Tag
19#endif
20 {
21 public:
22 virtual ~Chat() override
23 {
24
25 }
26
27#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
28 auto& SetRawText(const std::string& s)
29 {
30 raw_text = s;
31 return *this;
32 }
33#endif
34
35 const std::string& GetText() const
36 {
37 return text;
38 }
39
40#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
41 const std::string& GetRawText() const
42 {
43 return raw_text;
44 }
45#endif
46
47 protected:
48 virtual void ReadImpl(ReadIterator& iter, size_t& length) override
49 {
50#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
51 raw_text = ReadData<std::string>(iter, length);
52 text = ParseChat(Json::Parse(raw_text));
53#else
54 NBT::Tag::ReadImpl(iter, length);
55 text = ParseChat(*this);
56#endif
57 }
58
59#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
60 virtual void WriteImpl(WriteContainer& container) const override
61 {
62 WriteData<std::string>(raw_text, container);
63 }
64#endif
65
66#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
67 virtual Json::Value SerializeImpl() const override
68 {
69 Json::Value output;
70
71 output["raw_text"] = raw_text;
72
73 return output;
74 }
75#endif
76
77 private:
78#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
79 static std::string ParseChat(const Json::Value& raw_json);
80#else
81 static std::string ParseChatCompound(const NBT::TagCompound& raw);
82 static std::vector<std::string> ParseChatParts(const NBT::Tag& tag);
83 static std::string ParseChat(const NBT::Tag& tag);
84#endif
85
86
87 private:
88 std::string text;
89#if PROTOCOL_VERSION < 765 /* < 1.20.3 */
90 std::string raw_text;
91#endif
92 };
93}
std::string text
Definition Chat.hpp:88
const std::string & GetText() const
Definition Chat.hpp:35
virtual void ReadImpl(ReadIterator &iter, size_t &length) override
Definition Chat.hpp:48
static std::vector< std::string > ParseChatParts(const NBT::Tag &tag)
Definition Chat.cpp:250
static std::string ParseChat(const NBT::Tag &tag)
Definition Chat.cpp:289
virtual ~Chat() override
Definition Chat.hpp:22
static std::string ParseChatCompound(const NBT::TagCompound &raw)
Definition Chat.cpp:82
virtual void WriteImpl(WriteContainer &container) const override
Definition Tag.cpp:133
virtual void ReadImpl(ReadIterator &iter, size_t &length) override
Definition Tag.cpp:128
virtual Json::Value SerializeImpl() const override
Definition Tag.cpp:157
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