Skip to content

Commit 35c2b35

Browse files
committed
feat(examples): add player_connect_err_printer
1 parent 0bbffbe commit 35c2b35

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ def on_mcdr_start(server: PluginServerInterface):
238238

239239
## 实例
240240

241+
> 所有示例代码都在`examples`目录中
242+
241243
### 1. 玩家非正常退出报告
242244

243245
首先编写python代码:

examples/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Examples
2+
3+
这里有一些示例脚本,每一个文件夹是一整个脚本。如需使用,须将整个文件夹复制到`config/hooks/scripts`中,并执行`!!hooks reload`
4+
5+
There are some example scripts. If you want to try them, you must copy the full folder to `config/hooks/scripts` and execute `!!hooks reload`
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
tasks:
2+
- name: player_connect_err_printer
3+
task_type: python_code
4+
command_file: '{hooks_config_path}/scripts/player_connect_err_printer/script.py'
5+
hooks:
6+
- on_info
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from mcdreforged.api.all import *
2+
3+
# hooks在执行本脚本时会自动提前声明info、server这几个实例,所以你可以忽略IDE提示的"未解析的引用",本脚本在实际执行时是没有问题的
4+
# 使用/开发之前一定要仔细阅读仓库根路径下的README.md !!!!!!
5+
if info.content.__contains__('lost connection: ') \
6+
and not info.content.endswith('Disconnected') \
7+
and not info.content.endswith('Killed'):
8+
server.tell('@a', RTextList(
9+
RText('检测到玩家非正常退出:', color=RColor.red),
10+
RText(info.content, color=RColor.yellow).c(RAction.copy_to_clipboard, info.content).h('点击复制到剪贴板'),
11+
))

0 commit comments

Comments
 (0)