the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include "net.minecraft.world.scores.h"
3#include "net.minecraft.world.entity.player.h"
4#include "PacketListener.h"
5#include "SetPlayerTeamPacket.h"
6
7SetPlayerTeamPacket::SetPlayerTeamPacket()
8{
9 name = L"";
10 displayName = L"";
11 prefix = L"";
12 suffix = L"";
13 method = 0;
14 options = 0;
15}
16
17SetPlayerTeamPacket::SetPlayerTeamPacket(PlayerTeam *team, int method)
18{
19 name = team->getName();
20 this->method = method;
21
22 if (method == METHOD_ADD || method == METHOD_CHANGE)
23 {
24 displayName = team->getDisplayName();
25 prefix = team->getPrefix();
26 suffix = team->getSuffix();
27 options = team->packOptions();
28 }
29 if (method == METHOD_ADD)
30 {
31 unordered_set<wstring> *playerNames = team->getPlayers();
32 players.insert(players.end(), playerNames->begin(), playerNames->end());
33 }
34}
35
36SetPlayerTeamPacket::SetPlayerTeamPacket(PlayerTeam *team, vector<wstring> *playerNames, int method)
37{
38 if (method != METHOD_JOIN && method != METHOD_LEAVE)
39 {
40 app.DebugPrintf("Method must be join or leave for player constructor");
41#ifndef _CONTENT_PACKAGE
42 __debugbreak();
43#endif
44 }
45 if (playerNames == NULL || playerNames->empty())
46 {
47 app.DebugPrintf("Players cannot be null/empty");
48#ifndef _CONTENT_PACKAGE
49 __debugbreak();
50#endif
51 }
52
53 this->method = method;
54 name = team->getName();
55 this->players.insert(players.end(), playerNames->begin(), playerNames->end());
56}
57
58void SetPlayerTeamPacket::read(DataInputStream *dis)
59{
60 name = readUtf(dis, Objective::MAX_NAME_LENGTH);
61 method = dis->readByte();
62
63 if (method == METHOD_ADD || method == METHOD_CHANGE)
64 {
65 displayName = readUtf(dis, PlayerTeam::MAX_DISPLAY_NAME_LENGTH);
66 prefix = readUtf(dis, PlayerTeam::MAX_PREFIX_LENGTH);
67 suffix = readUtf(dis, PlayerTeam::MAX_SUFFIX_LENGTH);
68 options = dis->readByte();
69 }
70
71 if (method == METHOD_ADD || method == METHOD_JOIN || method == METHOD_LEAVE)
72 {
73 int count = dis->readShort();
74
75 for (int i = 0; i < count; i++)
76 {
77 players.push_back(readUtf(dis, Player::MAX_NAME_LENGTH));
78 }
79 }
80}
81
82void SetPlayerTeamPacket::write(DataOutputStream *dos)
83{
84 writeUtf(name, dos);
85 dos->writeByte(method);
86
87 if (method == METHOD_ADD || method == METHOD_CHANGE)
88 {
89 writeUtf(displayName, dos);
90 writeUtf(prefix, dos);
91 writeUtf(suffix, dos);
92 dos->writeByte(options);
93 }
94
95 if (method == METHOD_ADD || method == METHOD_JOIN || method == METHOD_LEAVE)
96 {
97 dos->writeShort(players.size());
98
99 for (AUTO_VAR(it,players.begin()); it != players.end(); ++it)
100 {
101 writeUtf(*it, dos);
102 }
103 }
104}
105
106void SetPlayerTeamPacket::handle(PacketListener *listener)
107{
108 listener->handleSetPlayerTeamPacket(shared_from_this());
109}
110
111int SetPlayerTeamPacket::getEstimatedSize()
112{
113 return 1 + 2 + name.length();
114}