Skip to content

Commit

Permalink
feat: add /debug command which should only be executable by server …
Browse files Browse the repository at this point in the history
…operators
  • Loading branch information
wu-vincent committed Mar 15, 2024
1 parent 9dc7780 commit 927eeb4
Showing 1 changed file with 28 additions and 18 deletions.
46 changes: 28 additions & 18 deletions include/example_plugin.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) 2024, The Endstone Project. (https://endstone.dev) All Rights Reserved.

#include "endstone/plugin/plugin.h"
#include "endstone/util/color_format.h"
#include "fibonacci_command.h"

class ExamplePlugin : public endstone::Plugin {
Expand All @@ -16,25 +17,23 @@ class ExamplePlugin : public endstone::Plugin {
{
getLogger().info("onEnable is called");

auto *root = registerPermission( // root permission
"cpp_example.command", // name
"Allow users to use all commands provided by this example plugin"); // description
// 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);

auto *fibonacci = registerPermission(root, // parent
"cpp_example.command.fibonacci", // name
"Allow users to use the fibonacci command", // description
endstone::PermissionDefault::True); // default

registerPermission(fibonacci, // parent
"cpp_example.command.fibonacci.large_n", // name
"Allow users to use the fibonacci command with n >= 1000", // description
endstone::PermissionDefault::Operator); // default

registerCommand("fibonacci", // name
"A simple command that writes the Fibonacci series up to n.", // description
{"/fibonacci <n: int>"}, // usages
{"fib"}, // aliases
{"cpp_example.command.fibonacci", "cpp_example.command.fibonacci.large_n"}) // permissions
// 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>());
}

Expand All @@ -52,6 +51,17 @@ class ExamplePlugin : public endstone::Plugin {
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() == "debug") {
if (sender.isOp()) {
sender.sendMessage(endstone::ColorFormat::DARK_GREEN + "You are seeing this because you are OP!");
}
else {
sender.sendErrorMessage("You should never see this!");
}
return true;
}

sender.sendErrorMessage("Unknown command: /{}", command.getName());
return false;
}

Expand Down

0 comments on commit 927eeb4

Please sign in to comment.