Botcraft 1.21.4
Loading...
Searching...
No Matches
Identifier.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace ProtocolCraft
6{
7 class Identifier : public NetworkType
8 {
10
12
13 public:
14 bool operator <(const Identifier& rhs) const
15 {
16 return GetName() < rhs.GetName() ||
17 (GetName() == rhs.GetName() && GetNamespace() < rhs.GetNamespace());
18 }
19
20 std::string GetName() const
21 {
22 const size_t split = RawString.find(':');
23 return split == std::string::npos ? RawString : RawString.substr(split + 1);
24 }
25
26 auto& SetName(const std::string& name)
27 {
28 const std::string namespace_ = GetNamespace();
29 RawString = namespace_.empty() ? name : (namespace_ + ':' + name);
30 return *this;
31 }
32
33 std::string GetNamespace() const
34 {
35 const size_t split = RawString.find(':');
36 return split == std::string::npos ? "" : RawString.substr(0, split);
37 }
38
39 auto& SetNamespace(const std::string& namespace_)
40 {
41 const std::string name = GetName();
42 RawString = namespace_.empty() ? name : (namespace_ + ':' + name);
43 return *this;
44 }
45
46 std::string GetFull() const
47 {
48 if (GetNamespace().empty())
49 {
50 return "minecraft:" + GetName();
51 }
52 else
53 {
54 return RawString;
55 }
56 }
57
58 auto& SetRawString(const std::string& raw)
59 {
60 RawString = raw;
61 return *this;
62 }
63 };
64} // ProtocolCraft
bool operator<(const Identifier &rhs) const
std::string GetFull() const
auto & SetNamespace(const std::string &namespace_)
auto & SetRawString(const std::string &raw)
std::string GetNamespace() const
auto & SetName(const std::string &name)
std::string GetName() const
SERIALIZED_FIELD_WITHOUT_GETTER_SETTER(RawString, std::string)