Mineserver
A rewrite of Minecraft 1.8.9 in C++ !
Loading...
Searching...
No Matches
CommandsManager Class Reference

Commands Manager. More...

#include <commands.h>

Public Types

enum  CallCommandError { NONE , FORMAT , COMMAND_NOT_FOUND , RUNTIME_ERROR }
 Call command return code. More...
 

Public Member Functions

 CommandsManager ()
 Construct a new Commands Manager object.
 
 ~CommandsManager ()
 Destroy the Commands Manager object.
 
void addCommand (const std::string &name, Command::HandlerType handler, const std::string &usage="", const std::string &description="")
 Adds a command.
 
const std::unordered_map< std::string, Command > & getCommands () const
 Get all registered commands.
 
CallCommandError callCommand (ISender::SenderType type, ISender *sender, std::string commandString)
 Calls a command.
 

Static Public Member Functions

static void loadLua (lua_State *state, const char *namespaceName)
 Register Lua things.
 
static CommandsManagerinst ()
 Gets Commands Manager instance.
 

Detailed Description

Commands Manager.

The manager class for handling all commands logic.

Member Enumeration Documentation

◆ CallCommandError

Call command return code.

Enumerator
NONE 

No errors.

FORMAT 

Errors while parsing the command.

COMMAND_NOT_FOUND 

Command was not found.

RUNTIME_ERROR 

Error while running the command.

Member Function Documentation

◆ addCommand()

void CommandsManager::addCommand ( const std::string & name,
Command::HandlerType handler,
const std::string & usage = "",
const std::string & description = "" )

Adds a command.

Adds it by struct fields values.

Parameters
namesee Command::name
handlerCommand::handler
usageCommand::usage
descriptionCommand::description

◆ callCommand()

CommandsManager::CallCommandError CommandsManager::callCommand ( ISender::SenderType type,
ISender * sender,
std::string commandString )

Calls a command.

Parameters
typethe type of the sender that asked for the command
senderthe sender
commandStringthe command string such as '/test info'
Returns
CallCommandError error struct

◆ getCommands()

const std::unordered_map< std::string, Command > & CommandsManager::getCommands ( ) const
inline

Get all registered commands.

Returns
const std::unordered_map<std::string, Command>& commands as map, key for command name

◆ inst()

static CommandsManager & CommandsManager::inst ( )
inlinestatic

Gets Commands Manager instance.

Returns
CommandsManager& the instance

◆ loadLua()

void CommandsManager::loadLua ( lua_State * state,
const char * namespaceName )
static

Register Lua things.

Parameters
statestate to register to
namespaceNamenamespace name

The documentation for this class was generated from the following files: