-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathexample_plugin.h
More file actions
65 lines (52 loc) · 2.01 KB
/
example_plugin.h
File metadata and controls
65 lines (52 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved.
#pragma once
#include "example_listener.h"
#include "fibonacci_command.h"
#include <endstone/endstone.hpp>
#include <memory>
#include <vector>
class ExamplePlugin : public endstone::Plugin {
public:
void onLoad() override
{
getLogger().info("onLoad is called");
}
void onEnable() override
{
getLogger().info("onEnable is called");
if (auto *command = getCommand("fibonacci")) {
command->setExecutor(std::make_unique<FibonacciCommandExecutor>());
}
// You can register an event handler directly in the Plugin class.
registerEvent(&ExamplePlugin::onServerLoad, *this);
// You can also create a separate class (e.g. ExampleListener) and register the event handler from that class.
listener_ = std::make_unique<ExampleListener>(*this);
registerEvent(&ExampleListener::onServerLoad, *listener_, endstone::EventPriority::High);
}
void onDisable() override
{
getLogger().info("onDisable is called");
}
bool onCommand(endstone::CommandSender &sender, const endstone::Command &command,
const std::vector<std::string> &args) override
{
// You can also handle commands here instead of setting an executor in onEnable if you prefer
if (command.getName() == "whoami") {
if (sender.isOp()) {
sender.sendMessage(endstone::ColorFormat::DarkGreen + "You are seeing this because you are the OP!");
}
else {
sender.sendErrorMessage("You should never see this!");
}
return true;
}
sender.sendErrorMessage("Unknown command: /{}", command.getName());
return false;
}
void onServerLoad(endstone::ServerLoadEvent &event)
{
getLogger().info("{} is passed to ExamplePlugin::onServerLoad", event.getEventName());
}
private:
std::unique_ptr<ExampleListener> listener_;
};