AzerothCore 3.3.5a
OpenSource WoW Emulator
Loading...
Searching...
No Matches
Acore::ChatCommands::PlayerIdentifier Struct Reference

#include "ChatCommandTags.h"

Inheritance diagram for Acore::ChatCommands::PlayerIdentifier:
Acore::Impl::ChatCommands::ContainerTag

Public Types

using value_type = Player *
 
- Public Types inherited from Acore::Impl::ChatCommands::ContainerTag
using ChatCommandResult = Acore::Impl::ChatCommands::ChatCommandResult
 

Public Member Functions

 PlayerIdentifier ()
 
 PlayerIdentifier (Player &player)
 
 operator ObjectGuid () const
 
 operator std::string const & () const
 
 operator std::string_view () const
 
std::string const & GetName () const
 
ObjectGuid GetGUID () const
 
bool IsConnected () const
 
PlayerGetConnectedPlayer () const
 
ChatCommandResult TryConsume (ChatHandler const *handler, std::string_view args)
 

Static Public Member Functions

static Optional< PlayerIdentifierFromTarget (ChatHandler *handler)
 
static Optional< PlayerIdentifierFromSelf (ChatHandler *handler)
 
static Optional< PlayerIdentifierFromTargetOrSelf (ChatHandler *handler)
 

Private Attributes

std::string _name
 
ObjectGuid _guid
 
Player_player
 

Detailed Description

Member Typedef Documentation

◆ value_type

Constructor & Destructor Documentation

◆ PlayerIdentifier() [1/2]

Acore::ChatCommands::PlayerIdentifier::PlayerIdentifier ( )
inline
173: _name(), _guid(), _player(nullptr) {}
ObjectGuid _guid
Definition: ChatCommandTags.h:199
Player * _player
Definition: ChatCommandTags.h:200
std::string _name
Definition: ChatCommandTags.h:198

◆ PlayerIdentifier() [2/2]

Acore::ChatCommands::PlayerIdentifier::PlayerIdentifier ( Player player)
136 : _name(player.GetName()), _guid(player.GetGUID()), _player(&player) {}
static ObjectGuid GetGUID(Object const *o)
Definition: Object.h:106
std::string const & GetName() const
Definition: Object.h:446

Member Function Documentation

◆ FromSelf()

Optional< Acore::ChatCommands::PlayerIdentifier > Acore::ChatCommands::PlayerIdentifier::FromSelf ( ChatHandler handler)
static
148{
149 if (Player* player = handler->GetPlayer())
150 return { *player };
151
152 return std::nullopt;
153}
Player * GetPlayer() const
Definition: Chat.cpp:37
Definition: Player.h:1046

References ChatHandler::GetPlayer().

Referenced by instance_commandscript::HandleInstanceGetBossStateCommand(), and instance_commandscript::HandleInstanceSetBossStateCommand().

◆ FromTarget()

◆ FromTargetOrSelf()

static Optional< PlayerIdentifier > Acore::ChatCommands::PlayerIdentifier::FromTargetOrSelf ( ChatHandler handler)
inlinestatic
190 {
191 if (Optional<PlayerIdentifier> fromTarget = FromTarget(handler))
192 return fromTarget;
193 else
194 return FromSelf(handler);
195 }
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:24
static Optional< PlayerIdentifier > FromTarget(ChatHandler *handler)
Definition: ChatCommandTags.cpp:138
static Optional< PlayerIdentifier > FromSelf(ChatHandler *handler)
Definition: ChatCommandTags.cpp:147

Referenced by arena_commandscript::HandleArenaCaptainCommand(), arena_commandscript::HandleArenaCreateCommand(), cache_commandscript::HandleCacheDeleteCommand(), cache_commandscript::HandleCacheInfoCommand(), cache_commandscript::HandleCacheRefreshCommand(), character_commandscript::HandleCharacterChangeAccountCommand(), character_commandscript::HandleCharacterLevelCommand(), character_commandscript::HandleCharacterReputationCommand(), character_commandscript::HandleCharacterTitlesCommand(), misc_commandscript::HandleCombatStopCommand(), deserter_commandscript::HandleDeserterRemove(), misc_commandscript::HandleFreezeCommand(), gear_commandscript::HandleGearRepairCommand(), misc_commandscript::HandleGetDistanceCommand(), misc_commandscript::HandleGPSCommand(), group_commandscript::HandleGroupDisbandCommand(), group_commandscript::HandleGroupLeaderCommand(), group_commandscript::HandleGroupListCommand(), group_commandscript::HandleGroupRemoveCommand(), misc_commandscript::HandleGroupSummonCommand(), guild_commandscript::HandleGuildRankCommand(), inventory_commandscript::HandleInventoryCountCommand(), misc_commandscript::HandleKickPlayerCommand(), learn_commandscript::HandleLearnAllDefaultCommand(), character_commandscript::HandleLevelUpCommand(), lfg_commandscript::HandleLfgGroupInfoCommand(), lfg_commandscript::HandleLfgPlayerInfoCommand(), misc_commandscript::HandlePInfoCommand(), player_commandscript::HandlePlayerLearnCommand(), player_commandscript::HandlePlayerUnLearnCommand(), quest_commandscript::HandleQuestAdd(), quest_commandscript::HandleQuestComplete(), quest_commandscript::HandleQuestRemove(), quest_commandscript::HandleQuestReward(), misc_commandscript::HandleRecallCommand(), misc_commandscript::HandleReviveCommand(), send_commandscript::HandleSendItemsCommand(), send_commandscript::HandleSendMailCommand(), send_commandscript::HandleSendMessageCommand(), send_commandscript::HandleSendMoneyCommand(), tele_commandscript::HandleTeleNameCommand(), misc_commandscript::HandleUnFreezeCommand(), misc_commandscript::HandleUnmuteCommand(), and misc_commandscript::HandleUnstuckCommand().

◆ GetConnectedPlayer()

◆ GetGUID()

◆ GetName()

std::string const & Acore::ChatCommands::PlayerIdentifier::GetName ( ) const
inline

◆ IsConnected()

bool Acore::ChatCommands::PlayerIdentifier::IsConnected ( ) const
inline
182{ return (_player != nullptr); }

◆ operator ObjectGuid()

Acore::ChatCommands::PlayerIdentifier::operator ObjectGuid ( ) const
inline
176{ return _guid; }

◆ operator std::string const &()

Acore::ChatCommands::PlayerIdentifier::operator std::string const & ( ) const
inline
177{ return _name; }

◆ operator std::string_view()

Acore::ChatCommands::PlayerIdentifier::operator std::string_view ( ) const
inline
178{ return _name; }

◆ TryConsume()

ChatCommandResult Acore::ChatCommands::PlayerIdentifier::TryConsume ( ChatHandler const *  handler,
std::string_view  args 
)
91{
92 Variant<Hyperlink<player>, ObjectGuid::LowType, std::string_view> val;
93 ChatCommandResult next = ArgInfo<decltype(val)>::TryConsume(val, handler, args);
94 if (!next)
95 return next;
96
97 if (val.holds_alternative<ObjectGuid::LowType>())
98 {
99 _guid = ObjectGuid::Create<HighGuid::Player>(val.get<ObjectGuid::LowType>());
100
102 {
103 _name = _player->GetName();
104 }
105 else if (!sCharacterCache->GetCharacterNameByGuid(_guid, _name))
106 {
108 }
109
110 return next;
111 }
112 else
113 {
114 if (val.holds_alternative<Hyperlink<player>>())
115 _name.assign(static_cast<std::string_view>(val.get<Hyperlink<player>>()));
116 else
117 _name.assign(val.get<std::string_view>());
118
121
123 {
124 _guid = _player->GetGUID();
125 }
126 else if (!(_guid = sCharacterCache->GetCharacterGuidByName(_name)))
127 {
129 }
130
131 return next;
132 }
133}
#define STRING_VIEW_FMT_ARG(str)
Definition: Define.h:101
#define sCharacterCache
Definition: CharacterCache.h:83
bool normalizePlayerName(std::string &name)
Definition: ObjectMgr.cpp:264
@ LANG_CMDPARSER_CHAR_GUID_NO_EXIST
Definition: Language.h:1007
@ LANG_CMDPARSER_CHAR_NAME_INVALID
Definition: Language.h:1009
@ LANG_CMDPARSER_CHAR_NAME_NO_EXIST
Definition: Language.h:1008
std::string FormatAcoreString(ChatHandler const *handler, AcoreStrings which, Ts &&... args)
Definition: ChatCommandHelpers.h:126
Player * FindPlayerByLowGUID(ObjectGuid::LowType lowguid)
Definition: ObjectAccessor.cpp:256
Player * FindPlayerByName(std::string const &name, bool checkInWorld=true)
Definition: ObjectAccessor.cpp:276
Definition: ChatCommandArgs.h:50
Definition: ChatCommandHelpers.h:101
ChatCommandResult TryConsume(ChatHandler const *handler, std::string_view args)
Definition: ChatCommandTags.cpp:90
LowType GetCounter() const
Definition: ObjectGuid.h:147
std::string ToString() const
Definition: ObjectGuid.cpp:47
uint32 LowType
Definition: ObjectGuid.h:124

References ObjectAccessor::FindPlayerByLowGUID(), ObjectAccessor::FindPlayerByName(), Acore::Impl::ChatCommands::FormatAcoreString(), Acore::ChatCommands::Variant< T1, Ts >::get(), Acore::ChatCommands::Variant< T1, Ts >::holds_alternative(), LANG_CMDPARSER_CHAR_GUID_NO_EXIST, LANG_CMDPARSER_CHAR_NAME_INVALID, LANG_CMDPARSER_CHAR_NAME_NO_EXIST, normalizePlayerName(), sCharacterCache, and STRING_VIEW_FMT_ARG.

Member Data Documentation

◆ _guid

ObjectGuid Acore::ChatCommands::PlayerIdentifier::_guid
private

◆ _name

std::string Acore::ChatCommands::PlayerIdentifier::_name
private

◆ _player

Player* Acore::ChatCommands::PlayerIdentifier::_player
private