Mineserver
A rewrite of Minecraft 1.8.9 in C++ !
Loading...
Searching...
No Matches
commandsreg.hpp
Go to the documentation of this file.
1
12#ifndef MINESERVER_COMMANDSREG_H
13#define MINESERVER_COMMANDSREG_H
14
15#include <cmd/commands.h>
16#include <utils/config.h>
17#include <plugins/plugins.h>
18#include <server.h>
19
27void helpMessage(const ISender::SenderType senderType, ISender &sender, const std::vector<std::string> &args)
28{
29 (void)senderType;
30 if (!args.empty())
31 {
32 sender.sendMessage(ChatMessage("/help doesn't accept any arguments !"));
33 }
34
35 auto mapCommands = CommandsManager::inst().getCommands();
36 std::string finalString;
37
38 for (auto &kv : mapCommands)
39 {
40 Command &command = kv.second;
41 finalString += "/" + command.name + " " + command.usage + "\n";
42 finalString += command.description + "\n";
43 }
44
45 sender.sendMessage(finalString);
46}
47
55void pluginsMessage(const ISender::SenderType senderType, ISender &sender, const std::vector<std::string> &args)
56{
57 (void)senderType;
58 if (!args.empty())
59 {
60 sender.sendMessage(ChatMessage("/plugins doesn't accept any arguments !"));
61 return;
62 }
63
64 auto plugins = PluginsManager::inst().getPlugins();
65 if (plugins.empty())
66 {
67 sender.sendMessage(ChatMessage("No plugins registered"));
68 return;
69 }
70
71 std::string finalString;
72
73 for (const auto& plugin : plugins)
74 {
75 finalString += plugin->name + " (v" + plugin->version + "), ";
76 }
77
78 finalString.pop_back();
79 finalString.pop_back();
80
81 finalString += " [" + std::to_string(plugins.size()) + "]";
82
83 sender.sendMessage(finalString);
84}
85
91{
93 "help", helpMessage,
94 "", "Returns help message");
95
97 "stop", [](const ISender::SenderType, ISender &, const std::vector<std::string> &)
98 { Server::inst()->stop(); },
99 "", "Stops the server");
100
102 "plugins", std::ref(pluginsMessage),
103 "", "Shows a list of installed plugins");
104
106}
107
108#endif // MINESERVER_COMMANDSREG_H
Minecraft Chat Message implementation.
Definition chatmessage.h:28
void addCommand(const std::string &name, Command::HandlerType handler, const std::string &usage="", const std::string &description="")
Adds a command.
Definition commands.cpp:25
static CommandsManager & inst()
Gets Commands Manager instance.
Definition commands.h:230
const std::unordered_map< std::string, Command > & getCommands() const
Get all registered commands.
Definition commands.h:175
static void registerCommands()
Register config commands.
Definition config.cpp:383
static Config * inst()
Fetch the instance of the config.
Definition config.h:275
Sender Interface.
Definition commands.h:29
virtual void sendMessage(const ChatMessage &message)=0
Sends a message to the sender.
SenderType
Sender type.
Definition commands.h:38
static PluginsManager & inst()
Gets the instance of the plugin manager.
Definition plugins.h:112
const std::vector< std::shared_ptr< Plugin > > & getPlugins() const
Get the registered plugins.
Definition plugins.h:102
void stop()
Stops the server.
Definition server.cpp:109
static Server * inst()
Get the instance of the server.
Definition server.h:90
The file handling commands logic.
void pluginsMessage(const ISender::SenderType senderType, ISender &sender, const std::vector< std::string > &args)
Handler for plugins message.
Definition commandsreg.hpp:55
void registerCommands()
Register commands for the console and general usage.
Definition commandsreg.hpp:90
void helpMessage(const ISender::SenderType senderType, ISender &sender, const std::vector< std::string > &args)
Handler for help message.
Definition commandsreg.hpp:27
The main file for the config io.
The file handling plugin system.
The file containing most of the server logic.
Command struct.
Definition commands.h:76
std::string usage
The usage of the command.
Definition commands.h:106
std::string description
The description of the command.
Definition commands.h:113
std::string name
The name of the command.
Definition commands.h:88