Skip to content

Commit a43a156

Browse files
authored
KillServer 1.1.0
KillServer 1.1.0
2 parents 911d530 + ab1622c commit a43a156

3 files changed

Lines changed: 75 additions & 13 deletions

File tree

src/KillServer/README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,12 @@
4848

4949
## 新的事件
5050

51-
待完成
51+
[Read the Docs 文档](https://mcdr-plugins.readthedocs.io/zh-cn/latest/kill_server/events.html)
52+
53+
> [!IMPORTANT]
54+
> 自 1.1.0 版本起, 插件事件已经完全重构,
55+
> 使用 `from kill_server import *` 导入 `ServerStoppingEvent` 这些事件变量的的已不再适用,
56+
> 它们全部合并到了 [`ServerEvents`](https://mcdr-plugins.readthedocs.io/zh-cn/latest/kill_server/events.html#kill_server.events.server_event.ServerEvents)
57+
>
58+
> 使用事件 ID 监听事件的, 依然可以继续使用
59+

src/KillServer/kill_server/events/server_event.py

Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
from mcdreforged import MCDRPluginEvents, PluginEvent, PluginServerInterface
22
from mcdreforged.plugin.plugin_event import MCDREvent
33

4+
server: PluginServerInterface | None = PluginServerInterface.psi_opt()
5+
46

57
class ServerEvent(PluginEvent):
6-
"""服务器事件, 包括服务端控制等"""
8+
"""服务器事件, 包括服务端控制等
9+
10+
Attributes:
11+
id (str): 事件 ID
12+
"""
713

814
def __init__(self, event_id: str) -> None:
915
super().__init__(event_id)
1016

1117
@classmethod
1218
def is_server_event(cls, e: PluginEvent) -> bool:
13-
return isinstance(e, cls)
19+
"""判断该事件是否为一个服务器控制事件
20+
21+
.. note::
22+
包括 MCDR 内置的和本插件定义的
23+
"""
24+
return e.id in _ServerEventStorage.EVENT_DICT
1425

1526

1627
class _ServerEventStorage:
@@ -49,29 +60,71 @@ class ServerEvents:
4960

5061
# Server starting
5162
SERVER_PRE_STARTING: MCDREvent = MCDRPluginEvents.SERVER_START_PRE
52-
"""服务器准备启动"""
63+
"""服务器准备启动
64+
65+
:事件 ID: ``mcdr.server_start_pre``
66+
:回调参数: :class:`~mcdreforged.plugin.si.plugin_server_interface.PluginServerInterface`
67+
68+
See Also:
69+
https://docs.mcdreforged.com/zh-cn/latest/plugin_dev/event.html#server-start-pre
70+
"""
5371
SERVER_STARTING: MCDREvent = MCDRPluginEvents.SERVER_START
54-
"""服务器正在启动"""
72+
"""服务器正在启动
73+
74+
:事件 ID: ``mcdr.server_start``
75+
:回调参数: :class:`~mcdreforged.plugin.si.plugin_server_interface.PluginServerInterface`
76+
77+
See Also:
78+
https://docs.mcdreforged.com/zh-cn/latest/plugin_dev/event.html#server-start
79+
"""
5580
SERVER_STARTED: MCDREvent = MCDRPluginEvents.SERVER_STARTUP
56-
"""服务器已启动"""
81+
"""服务器已启动
82+
83+
:事件 ID: ``mcdr.server_startup``
84+
:回调参数: :class:`~mcdreforged.plugin.si.plugin_server_interface.PluginServerInterface`
85+
86+
See Also:
87+
https://docs.mcdreforged.com/zh-cn/latest/plugin_dev/event.html#server-startup
88+
"""
5789
# Server Stopping
5890
SERVER_STOPPING: ServerEvent = ServerEvent("kill_server.server_stopping")
59-
"""服务器正在停止"""
91+
"""服务器正在停止
92+
93+
:事件 ID: ``kill_server.server_stopping``
94+
:回调参数: :class:`~mcdreforged.plugin.si.plugin_server_interface.PluginServerInterface`
95+
"""
6096
PLUGIN_STOPPING_SERVER: ServerEvent = ServerEvent("kill_server.plugin_stopping_server")
6197
"""服务器正在被插件/MCDR命令关闭
6298
63-
当且仅当 :meth:`mcdreforged.plugin.si.ServerInterface.stop` 调用时触发
99+
当且仅当 :meth:`ServerInterface.stop() <mcdreforged.plugin.si.server_interface.ServerInterface.stop>` 调用时触发
100+
101+
:事件 ID: ``kill_server.plugin_stopping_server``
102+
:回调参数: :class:`~mcdreforged.plugin.si.plugin_server_interface.PluginServerInterface`
64103
"""
65104
PLUGIN_KILLING_SERVER: ServerEvent = ServerEvent("kill_server.plugin_killing_server")
66105
"""服务器正在被插件/MCDR命令强制关闭
67106
68-
当且仅当 :meth:`mcdreforged.plugin.si.ServerInterface.kill` 调用时触发
107+
当且仅当 :meth:`ServerInterface.kill() <mcdreforged.plugin.si.server_interface.ServerInterface.kill>` 调用时触发
108+
109+
:事件 ID: ``kill_server.plugin_killing_server``
110+
:回调参数: :class:`~mcdreforged.plugin.si.plugin_server_interface.PluginServerInterface`
69111
"""
70112
SERVER_STOPPED: MCDREvent = MCDRPluginEvents.SERVER_STOP
71-
"""服务器已停止"""
113+
"""服务器已停止
114+
115+
:事件 ID: ``mcdr.server_stop``
116+
:回调参数: :class:`~mcdreforged.plugin.si.plugin_server_interface.PluginServerInterface`
117+
118+
See Also:
119+
https://docs.mcdreforged.com/zh-cn/latest/plugin_dev/event.html#server-stop
120+
"""
72121

73122
WORLD_SAVED: ServerEvent = ServerEvent("kill_server.world_saved")
74-
"""世界已保存"""
123+
"""世界已保存
124+
125+
:事件 ID: ``kill_server.world_saved``
126+
:回调参数: :class:`~mcdreforged.plugin.si.plugin_server_interface.PluginServerInterface`
127+
"""
75128

76129
# Methods
77130
@classmethod
@@ -96,4 +149,5 @@ def __register_server_events():
96149

97150
def dispatch(event: PluginEvent, args: tuple = ()):
98151
"""以指定参数分发事件"""
99-
PluginServerInterface.psi().dispatch_event(event, args)
152+
assert server is not None
153+
server.dispatch_event(event, args)

src/KillServer/mcdreforged.plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "kill_server",
3-
"version": "1.0.1-beta.2",
3+
"version": "1.1.0",
44
"name": "KillServer",
55
"description": {
66
"en_us": "Force to kill mc server",

0 commit comments

Comments
 (0)