Skip to content

Commit 4b97869

Browse files
committed
refactor: update registerPlaceholder function signature
1 parent c3a4289 commit 4b97869

File tree

5 files changed

+12
-14
lines changed

5 files changed

+12
-14
lines changed

endstone_papi/pypapi.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ class PyPlaceholderAPI : public papi::PlaceholderAPI {
1010
public:
1111
using PlaceholderAPI::PlaceholderAPI;
1212

13-
[[nodiscard]] std::string setPlaceholder(const endstone::Player &player, std::string_view text) const override
13+
[[nodiscard]] std::string setPlaceholders(const endstone::Player &player, std::string_view text) const override
1414
{
15-
PYBIND11_OVERRIDE_PURE_NAME(std::string, PlaceholderAPI, "set_placeholder", setPlaceholder, player, text);
15+
PYBIND11_OVERRIDE_PURE_NAME(std::string, PlaceholderAPI, "set_placeholders", setPlaceholder, player, text);
1616
}
1717

1818
[[nodiscard]] bool isRegistered(std::string_view identifier) const override
@@ -33,10 +33,8 @@ class PyPlaceholderAPI : public papi::PlaceholderAPI {
3333
PYBIND11_OVERRIDE_PURE_NAME(bool, PlaceholderAPI, "contains_placeholders", containsPlaceholders, text);
3434
}
3535

36-
[[nodiscard]] bool registerPlaceholder(
37-
endstone::Plugin &plugin, std::string_view identifier,
38-
std::function<std::string(std::optional<endstone::Player &>, std::optional<std::string>)> processor)
39-
const override
36+
[[nodiscard]] bool registerPlaceholder(const endstone::Plugin &plugin, std::string_view identifier,
37+
Processor processor) const override
4038
{
4139
PYBIND11_OVERRIDE_PURE_NAME(bool, PlaceholderAPI, "register_placeholder", registerPlaceholder, plugin,
4240
identifier, processor);
@@ -51,7 +49,7 @@ PYBIND11_MODULE(pypapi, m)
5149
py::class_<papi::PlaceholderAPI, PyPlaceholderAPI, endstone::Service, std::shared_ptr<papi::PlaceholderAPI>>(
5250
m, "PlaceholderAPI")
5351
.def(py::init<>())
54-
.def("set_placeholder", &papi::PlaceholderAPI::setPlaceholder, py::arg("player"), py::arg("text"),
52+
.def("set_placeholders", &papi::PlaceholderAPI::setPlaceholders, py::arg("player"), py::arg("text"),
5553
"Translates all placeholders into their corresponding values.")
5654
.def("is_registered", &papi::PlaceholderAPI::isRegistered, py::arg("identifier"),
5755
"Check if a specific placeholder identifier is currently registered.")

endstone_papi/pypapi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, plugin: Plugin):
1616
self._placeholder_pattern = re.compile(r"[{]([^{}]+)[}]")
1717
self._register_default_placeholders()
1818

19-
def set_placeholder(self, player: Player | None, text: str) -> str:
19+
def set_placeholders(self, player: Player | None, text: str) -> str:
2020
return apply(player, text, self._registry.get)
2121

2222
def is_registered(self, identifier: str) -> bool:

endstone_papi/pypapi.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ from endstone import Player
44
__all__ = ["PlaceholderAPI"]
55

66
class PlaceholderAPI(Service):
7-
def set_placeholder(self, player: Player, text: str) -> str:
7+
def set_placeholders(self, player: Player, text: str) -> str:
88
"""
99
Translates all placeholders into their corresponding values.
1010
The pattern of a valid placeholder is {<identifier>:<params>}.

examples/cpp/plugin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class JoinExample : public endstone::Plugin {
1818
void onPlayerJoin(endstone::PlayerJoinEvent &event)
1919
{
2020
std::string join_text = "{player_name} joined the server! Their game mode is {player_gamemode}";
21-
join_text = papi_->setPlaceholder(event.getPlayer(), join_text);
21+
join_text = papi_->setPlaceholders(event.getPlayer(), join_text);
2222
event.setJoinMessage(join_text);
2323
}
2424

include/endstone_papi/papi.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace papi {
66
class PlaceholderAPI : public endstone::Service {
77
public:
8+
using Processor = std::function<std::string(const endstone::Player &, std::string)>;
89
/**
910
* Translates all placeholders into their corresponding values.
1011
* <br>The pattern of a valid placeholder is <code>{<identifier>|<params>}</code>.
@@ -13,7 +14,7 @@ class PlaceholderAPI : public endstone::Service {
1314
* @param text Text to set the placeholder values in
1415
* @return String containing all translated placeholders
1516
*/
16-
[[nodiscard]] virtual std::string setPlaceholder(const endstone::Player &player, std::string_view text) const = 0;
17+
[[nodiscard]] virtual std::string setPlaceholders(const endstone::Player &player, std::string_view text) const = 0;
1718

1819
/**
1920
* Check if a specific placeholder identifier is currently registered.
@@ -53,8 +54,7 @@ class PlaceholderAPI : public endstone::Service {
5354
* @param processor the processor that will process the placeholder
5455
* @return true if the placeholder was successfully registered, false otherwise
5556
*/
56-
[[nodiscard]] virtual bool registerPlaceholder(
57-
endstone::Plugin &plugin, std::string_view identifier,
58-
std::function<std::string(std::optional<endstone::Player &>, std::optional<std::string>)> processor) const = 0;
57+
[[nodiscard]] virtual bool registerPlaceholder(const endstone::Plugin &plugin, std::string_view identifier,
58+
Processor processor) const = 0;
5959
};
6060
} // namespace papi

0 commit comments

Comments
 (0)