-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
927eeb4
commit 24cf1f6
Showing
2 changed files
with
39 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,12 @@ | ||
// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved. | ||
|
||
#include "endstone/command/plugin_command.h" | ||
#include "endstone/plugin/plugin.h" | ||
#include "endstone/util/color_format.h" | ||
#include "fibonacci_command.h" | ||
|
||
class ExamplePlugin : public endstone::Plugin { | ||
public: | ||
ExamplePlugin() = default; | ||
|
||
void onLoad() override | ||
{ | ||
getLogger().info("onLoad is called"); | ||
|
@@ -16,37 +15,16 @@ class ExamplePlugin : public endstone::Plugin { | |
void onEnable() override | ||
{ | ||
getLogger().info("onEnable is called"); | ||
|
||
// Register permissions | ||
auto *root = registerPermission("cpp_example.command", | ||
"Allow users to use all commands provided by this example plugin"); | ||
registerPermission(root, "cpp_example.command.debug", "Allow users to use the debug command", | ||
endstone::PermissionDefault::Operator); | ||
auto *fib = registerPermission(root, "cpp_example.command.fibonacci", | ||
"Allow users to use the fibonacci command", endstone::PermissionDefault::True); | ||
registerPermission(fib, "cpp_example.command.fibonacci.large_n", | ||
"Allow users to use the fibonacci command with n >= 1000", | ||
endstone::PermissionDefault::Operator); | ||
|
||
// Register commands | ||
registerCommand("debug", "Print debug information of this plugin.", {"/debug"}, {}, | ||
{"cpp_example.command.debug"}); | ||
registerCommand("fibonacci", "A simple command that writes the Fibonacci series up to n.", | ||
{"/fibonacci <n: int>"}, {"fib"}, | ||
{"cpp_example.command.fibonacci", "cpp_example.command.fibonacci.large_n"}) | ||
->setExecutor(std::make_unique<FibonacciCommandExecutor>()); | ||
if (auto *command = getCommand("fibonacci")) { | ||
command->setExecutor(std::make_unique<FibonacciCommandExecutor>()); | ||
} | ||
} | ||
|
||
void onDisable() override | ||
{ | ||
getLogger().info("onDisable is called"); | ||
} | ||
|
||
[[nodiscard]] const endstone::PluginDescription &getDescription() const override | ||
{ | ||
return description_; | ||
} | ||
|
||
bool onCommand(endstone::CommandSender &sender, const endstone::Command &command, | ||
const std::vector<std::string> &args) override | ||
{ | ||
|
@@ -64,12 +42,4 @@ class ExamplePlugin : public endstone::Plugin { | |
sender.sendErrorMessage("Unknown command: /{}", command.getName()); | ||
return false; | ||
} | ||
|
||
private: | ||
endstone::PluginDescription description_{ | ||
"CppExamplePlugin", // name | ||
"0.2.0", // version | ||
"C++ example plugin for Endstone servers", // description | ||
{"Endstone Developers <[email protected]>"} // authors | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,38 @@ | |
|
||
#include "example_plugin.h" | ||
|
||
// The ENDSTONE_PLUGIN macro defines the entry point for the plugin. | ||
ENDSTONE_PLUGIN(ExamplePlugin) | ||
// The ENDSTONE_PLUGIN macro defines the metadata for the plugin. | ||
ENDSTONE_PLUGIN(/*name=*/"CppExamplePlugin", /*version=*/"0.3.0", /*main_class=*/ExamplePlugin) | ||
{ | ||
plugin.description = "C++ example plugin for Endstone servers"; | ||
plugin.authors = {"Endstone Developers <[email protected]>"}; | ||
|
||
plugin.command("debug") | ||
.description("Print debug information.") | ||
.usages("/debug") | ||
.permissions("cpp_example.command.debug"); | ||
|
||
plugin.command("fibonacci") | ||
.description("A simple command that writes the Fibonacci series up to n.") | ||
.usages("/fibonacci <n: int>") | ||
.aliases("fib") | ||
.permissions("cpp_example.command.fibonacci", "cpp_example.command.fibonacci.large_n"); | ||
|
||
plugin.permission("cpp_example.command") | ||
.description("Allow users to use all commands provided by this example plugin") | ||
.children("cpp_example.command.debug", true) | ||
.children("cpp_example.command.fibonacci", true); | ||
|
||
plugin.permission("cpp_example.command.debug") | ||
.description("Allow users to use the debug command") | ||
.default_(endstone::PermissionDefault::Operator); | ||
|
||
plugin.permission("cpp_example.command.fibonacci") | ||
.description("Allow users to use the fibonacci command") | ||
.default_(endstone::PermissionDefault::True) | ||
.children("cpp_example.command.fibonacci.large_n", true); | ||
|
||
plugin.permission("cpp_example.command.fibonacci.large_n") | ||
.description("Allow users to use the fibonacci command with n >= 1000") | ||
.default_(endstone::PermissionDefault::Operator); | ||
} |