Skip to content

Commit 68f5664

Browse files
committed
feat: update stubs
1 parent 044cb12 commit 68f5664

File tree

4 files changed

+41
-15
lines changed

4 files changed

+41
-15
lines changed

endstone_papi/_papi.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <endstone_papi/papi.h>
2+
#include <pybind11/functional.h>
23
#include <pybind11/pybind11.h>
34
#include <pybind11/stl.h>
45

@@ -44,7 +45,7 @@ class PyPlaceholderAPI : public papi::PlaceholderAPI {
4445
}
4546
};
4647

47-
PYBIND11_MODULE(pypapi, m)
48+
PYBIND11_MODULE(_papi, m)
4849
{
4950
py::module_::import("endstone");
5051
py::module_::import("endstone.plugin");

endstone_papi/_papi.pyi

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,43 @@
1-
from endstone.plugin import Service
1+
from __future__ import annotations
22
from endstone import Player
3+
from endstone.plugin import Service, Plugin
4+
from typing import Callable
35

46
__all__ = ["PlaceholderAPI"]
57

68
class PlaceholderAPI(Service):
7-
def set_placeholders(self, player: Player, text: str) -> str:
9+
def __init__(self) -> None: ...
10+
def _get_placeholder_pattern(self) -> str:
11+
"""
12+
Get the normal placeholder pattern.
813
"""
9-
Translates all placeholders into their corresponding values.
10-
The pattern of a valid placeholder is {<identifier>:<params>}.
1114

12-
Args:
13-
player (Player): Player to parse the placeholders against.
14-
text (str): Text to set the placeholder values in.
15+
def _get_registered_identifiers(self) -> list[str]:
16+
"""
17+
Get all registered placeholder identifiers.
18+
"""
1519

16-
Returns:
17-
str: String containing all translated placeholders.
20+
def contains_placeholders(self, text: str) -> bool:
21+
"""
22+
Check if a String contains any placeholders.
23+
"""
24+
25+
def is_registered(self, identifier: str) -> bool:
26+
"""
27+
Check if a specific placeholder identifier is currently registered.
28+
"""
29+
30+
def register_placeholder(
31+
self,
32+
plugin: Plugin,
33+
identifier: str,
34+
processor: Callable[[Player, str], str],
35+
) -> bool:
36+
"""
37+
Attempt to register a placeholder.
38+
"""
39+
40+
def set_placeholders(self, player: Player, text: str) -> str:
41+
"""
42+
Translates all placeholders into their corresponding values.
1843
"""

endstone_papi/papi.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@ def contains_placeholders(self, text: str) -> bool:
5151
return self._placeholder_pattern.search(text) is not None
5252

5353
def register_placeholder(
54-
self,
55-
plugin: Plugin,
56-
identifier: str,
57-
processor: Callable[[Player, str], str],
54+
self,
55+
plugin: Plugin,
56+
identifier: str,
57+
processor: Callable[[Player, str], str],
5858
) -> bool:
5959
# TODO(daoge): duplicate placeholders are not allowed in the current design, shall we implement namespaces?
6060
if self.is_registered(identifier):

endstone_papi/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from endstone import Player
22
from endstone.plugin import Plugin, ServicePriority
33
from endstone.command import Command, CommandSender
4-
from .pypapi import PlaceholderAPI
4+
from .papi import PlaceholderAPI
55

66

77
class PlaceholderAPIPlugin(Plugin):

0 commit comments

Comments
 (0)