Botcraft 1.21.4
Loading...
Searching...
No Matches
CommandNode.hpp
Go to the documentation of this file.
1#if PROTOCOL_VERSION > 344 /* > 1.12.2 */
2#pragma once
3
4#include <memory>
5
9
10
11namespace ProtocolCraft
12{
13 class CommandNode : public NetworkType
14 {
15 SERIALIZED_FIELD(Flags, char);
16 SERIALIZED_FIELD(Children, std::vector<VarInt>);
17 SERIALIZED_FIELD(RedirectNode, VarInt);
18 SERIALIZED_FIELD(Name, std::string);
19#if PROTOCOL_VERSION < 759 /* < 1.19 */
21#else
23#endif
24 SERIALIZED_FIELD(Properties, std::shared_ptr<BrigadierProperty>);
25 SERIALIZED_FIELD(SuggestionType, Identifier);
26
28
29 public:
30 virtual ~CommandNode()
31 {
32
33 }
34
35 protected:
36 virtual void ReadImpl(ReadIterator& iter, size_t& length) override
37 {
38 SetFlags(ReadData<char>(iter, length));
39 SetChildren(ReadData<std::vector<VarInt>>(iter, length));
40 if (GetFlags() & 0x08)
41 {
42 SetRedirectNode(ReadData<VarInt>(iter, length));
43 }
44 const char node_type = GetFlags() & 0x03;
45 if (node_type == 1 || node_type == 2)
46 {
47 SetName(ReadData<std::string>(iter, length));
48 }
49 if (node_type == 2)
50 {
51#if PROTOCOL_VERSION < 759 /* < 1.19 */
52 SetParser(ReadData<Identifier>(iter, length));
53 SetProperties(BrigadierProperty::CreateProperties(GetParser()));
54#else
55 SetParserId(ReadData<BrigadierPropertyType, VarInt>(iter, length));
56 SetProperties(BrigadierProperty::CreateProperties(GetParserId()));
57#endif
58 GetProperties()->Read(iter, length);
59 if (GetFlags() & 0x10)
60 {
61 SetSuggestionType(ReadData<Identifier>(iter, length));
62 }
63 }
64 }
65
66 virtual void WriteImpl(WriteContainer& container) const override
67 {
68 WriteData<char>(GetFlags(), container);
69 WriteData<std::vector<VarInt>>(GetChildren(), container);
70 if (GetFlags() & 0x08)
71 {
72 WriteData<VarInt>(GetRedirectNode(), container);
73 }
74 const char node_type = GetFlags() & 0x03;
75 if (node_type == 1 || node_type == 2)
76 {
77 WriteData<std::string>(GetName(), container);
78 }
79 if (node_type == 2)
80 {
81#if PROTOCOL_VERSION < 759 /* < 1.19 */
82 WriteData<Identifier>(GetParser(), container);
83#else
84 WriteData<BrigadierPropertyType, VarInt>(GetParserId(), container);
85#endif
86 GetProperties()->Write(container);
87 if (GetFlags() & 0x10)
88 {
89 WriteData<Identifier>(GetSuggestionType(), container);
90 }
91 }
92 }
93
94 virtual Json::Value SerializeImpl() const override
95 {
96 Json::Value output;
97
98 output[std::string(field_name<Flags_index>)] = GetFlags();
99 output[std::string(field_name<Children_index>)] = GetChildren();
100
101 if (GetFlags() & 0x08)
102 {
103 output[std::string(field_name<RedirectNode_index>)] = GetRedirectNode();
104 }
105
106 const char node_type = GetFlags() & 0x03;
107 if (node_type == 1 || node_type == 2)
108 {
109 output[std::string(field_name<Name_index>)] = GetName();
110 }
111 if (node_type == 2)
112 {
113#if PROTOCOL_VERSION < 759 /* < 1.19 */
114 output[std::string(field_name<Parser_index>)] = GetParser();
115#else
116 output[std::string(field_name<ParserId_index>)] = GetParserId();
117#endif
118 output[std::string(field_name<Properties_index>)] = GetProperties()->Serialize();
119 if (GetFlags() & 0x10)
120 {
121 output[std::string(field_name<SuggestionType_index>)] = GetSuggestionType();
122 }
123 }
124
125 return output;
126 }
127 };
128} // ProtocolCraft
129#endif
#define SERIALIZED_FIELD(Name,...)
static std::shared_ptr< BrigadierProperty > CreateProperties(const BrigadierPropertyType parser_id)
SERIALIZED_FIELD(Name, std::string)
SERIALIZED_FIELD(RedirectNode, VarInt)
virtual void ReadImpl(ReadIterator &iter, size_t &length) override
SERIALIZED_FIELD(ParserId, Internal::DiffType< BrigadierPropertyType, VarInt >)
SERIALIZED_FIELD(SuggestionType, Identifier)
virtual Json::Value SerializeImpl() const override
SERIALIZED_FIELD(Properties, std::shared_ptr< BrigadierProperty >)
SERIALIZED_FIELD(Children, std::vector< VarInt >)
virtual void WriteImpl(WriteContainer &container) const override
Main class, basically a JsonVariant with extra utility functions it doesn't inherit JsonVariant direc...
Definition Json.hpp:45
StorageType ReadData(ReadIterator &iter, size_t &length)
std::vector< unsigned char > WriteContainer
std::vector< unsigned char >::const_iterator ReadIterator
Just a simple type wrapper that will store with T1 and serialize as T2 (can be used for Enum/VarInt f...
Definition Templates.hpp:72