Player Events
注意:此模组仅适用于服务端,在客户端上无法正常工作
一个 Fabric 模组,当玩家触发特定事件(如死亡、加入服务器、击杀其他玩家等)时,执行并发送可配置的命令和消息。
自 2.2.0 版本起 数据包可以定义函数,通过对应的函数标签 #player_events:<event> 在事件发生时执行。
配置文件位于配置目录 (config/player_events.json),内容如下:
{
"death": {
"actions": [
"${player} just died!"
],
"broadcast_to_everyone": true,
"pick_message_randomly": false
},
"first_join": {
"actions": [
"Welcome to the server ${player}! Remember to read the rules"
],
"broadcast_to_everyone": false,
"pick_message_randomly": false
},
"join": {
"actions": [
"Welcome ${player}",
"/say Hello ${player}"
],
"broadcast_to_everyone": true,
"pick_message_randomly": false
},
"kill_entity": {
"actions": [
"${player} killed ${killedEntity}"
],
"broadcast_to_everyone": true,
"pick_message_randomly": false
},
"kill_player": {
"actions": [
"${player} killed ${killedPlayer}",
"F ${killedPlayer}"
],
"broadcast_to_everyone": true,
"pick_message_randomly": true
},
"leave": {
"actions": [
"Goodbye ${player}!",
"/say Hope to see you soon ${player}"
],
"broadcast_to_everyone": true,
"pick_message_randomly": false
},
"custom_commands": [
{
"command": "/plugins",
"actions": [
"Hey! We don't use plugins"
],
"broadcast_to_everyone": false,
"pick_message_randomly": false
},
{
"command": "/spawn",
"actions": [
"/tp ${player} 0 64 0 0 0"
],
"broadcast_to_everyone": true,
"pick_message_randomly": false
}
]
}
在 JSON 文件中,你可以在每个 <event> 对象的 actions 数组下声明在该事件发生时将发送和/或执行的内容。你也可以通过将 broadcast_to_everyone 设置为 false 来仅向该玩家发送这些消息,但这不适用于像 leave 这样的事件(因为玩家已经不在服务器上了)。
自 2.2.0 版本起 你可以选择随机发送为给定事件定义的其中一条消息,只需将 pick_message_randomly 设置为 true。
每个事件都有一个 ${player} 标记,该标记的每次出现都将被触发事件的玩家替换。其他事件也有以相同方式工作的额外标记。大多数(如果不是全部)标记都可以通过类似 ${player.name} 的方式访问其属性。以下是所有属性的列表:
display实体的显示名称,即你在玩家列表/聊天中看到的那个。例如:"[Team blue] Tom421"uuid实体的 UUIDxyz实体坐标- 更多即将推出™
也支持 颜色代码!
使用 /pe reload 或 /player_events reload 重新加载模组配置。
你可以使用 /pe test <event> 或 /player_events test <event> 测试特定事件上的操作,或者使用 /pe test * 测试所有事件。
2.2.0 支持的事件
death- 当玩家死亡时执行。first_join- 当玩家首次加入时执行。join- 当玩家加入时执行。kill_entity- 当玩家击杀一个实体时执行。额外标记:${killedEntity}- 被击杀的实体。
kill_player- 当玩家击杀另一个玩家时执行。额外标记:${killedPlayer}- 被击杀的玩家。
leave- 当玩家离开时执行。custom_commands- 由使用定义的命令触发的自定义定义事件。注意:此事件不支持数据包函数
此外,你可以创建简单的命令(如果你想要更复杂的命令,这个模组并不是你想要的),或者监听现有的命令。
故障排除
如果在初始化服务器时或应该执行某个操作时出现错误,请参阅以下步骤来解决。
- “配置文件中的 JSON 语法无效”:这很可能是由于命令中包含未转义的双引号引起的。修复方法:
- 检查下方异常中提到的内容。它将准确指出错误位置。
- 使用反斜杠转义动作内的任何双引号,例如
"->\"
- “无效的转义序列”
这是由不正确转义的转义序列(如
\n或\u)引起的。修复方法是,在转义序列的反斜杠前再加一个反斜杠,例如\n->\\n或\\u->\\\\u
开发
这部分面向希望使用模组 API 的模组开发者。
编译
- 克隆或下载仓库
- 在命令行提示符下运行
gradlew build以编译模组。(如果你只需要 API 文件,可以改为运行gradlew api:build)。你将在<repository>/build/libs和<repository>/api/build/libs下找到编译好的.jar文件
API
将 API 添加为你的模组的依赖项
将以下片段添加到你的 build.gradle 中:
repositories {
maven {
url 'https://maven.bymartrixx.me'
}
}
dependencies {
// 使用 gradle.properties 中的版本
modImplementation "me.bymartrixx.player-events:api:${project.player_events_api_version}"
// 直接设置版本号(将 2.1.3 替换为可用的最新版本)
modImplementation "me.bymartrixx.player-events:api:2.1.3"
}
如果你没有直接将版本设置到 build.gradle 文件中,请将以下代码片段添加到你的 gradle.properties:
# 将 2.1.3 替换为可用的最新版本
player_events_api_version = 2.1.3
此外,如果你希望你的模组依赖此 API,请将以下代码片段添加到你的 fabric.mod.json 中:
{
"depends": {
"player_events_api": ">=2.0.0"
}
}
事件
death-me.bymartrixx.playerevents.api.event.PlayerDeathCallback.EVENTfirst_join-me.bymartrixx.playerevents.api.event.PlayerFirstJoinCallback.EVENTjoin-me.bymartrixx.playerevents.api.event.PlayerJoinCallback.EVENTkill_entity-me.bymartrixx.playerevents.api.event.PlayerKillEntityCallback.EVENTkill_player-me.bymartrixx.playerevents.api.event.PlayerKillPlayerCallback.EVENTleave-me.bymartrixx.playerevents.api.event.PlayerLeaveCallback.EVENT- 命令执行 -
me.bymartrixx.playerevents.api.event.CommandExecutionCallback.EVENT
注意
包
io.github.bymartrixx.playerevents.api 已在 2.2.0 版本中被移除。
使用事件
示例代码片段
public class FooMod implements DedicatedServerModInitializer {
public void onInitializeServer() {
PlayerDeathCallback.EVENT.register((player, source) -> {
// 执行某些操作
});
PlayerKillEntityCallback.EVENT.register((player, killedEntity) -> {
// 执行某些操作
});
}
}
Player Events
Note: this mod is server side only and won't work on clients
A Fabric mod that executes and sends configurable commands and messages respectively on certain events triggered by a player, such as Dying, Joining a server, Killing another player, etc.
Since 2.2.0 Datapacks can define functions that will be executed on an event, using the corresponding function tag #player_events:<event>
The config file is located in the config directory (config/player_events.json) and looks like this:
{
"death": {
"actions": [
"${player} just died!"
],
"broadcast_to_everyone": true,
"pick_message_randomly": false
},
"first_join": {
"actions": [
"Welcome to the server ${player}! Remember to read the rules"
],
"broadcast_to_everyone": false,
"pick_message_randomly": false
},
"join": {
"actions": [
"Welcome ${player}",
"/say Hello ${player}"
],
"broadcast_to_everyone": true,
"pick_message_randomly": false
},
"kill_entity": {
"actions": [
"${player} killed ${killedEntity}"
],
"broadcast_to_everyone": true,
"pick_message_randomly": false
},
"kill_player": {
"actions": [
"${player} killed ${killedPlayer}",
"F ${killedPlayer}"
],
"broadcast_to_everyone": true,
"pick_message_randomly": true
},
"leave": {
"actions": [
"Goodbye ${player}!",
"/say Hope to see you soon ${player}"
],
"broadcast_to_everyone": true,
"pick_message_randomly": false
},
"custom_commands": [
{
"command": "/plugins",
"actions": [
"Hey! We don't use plugins"
],
"broadcast_to_everyone": false,
"pick_message_randomly": false
},
{
"command": "/spawn",
"actions": [
"/tp ${player} 0 64 0 0 0"
],
"broadcast_to_everyone": true,
"pick_message_randomly": false
}
]
}
On the JSON file you can declare, under the actions array on each <event> object, what is going
to be sent and/or executed on that event. You can also set these messages to be sent only to the
player by setting broadcast_to_everyone to false, but this won't work with events like leave
(because the player isn't in the server anymore).
Since 2.2.0 You can choose to randomly send one of the defined messages for a given event by setting pick_message_randomly to true.
Every event has a ${player} token, and each instance of this token will be replaced with the player
that triggers the event. Other events have extra tokens that work the same way.
Most (if not all) tokens have properties that can be accessed with something like ${player.name}.
Here is a list of all the properties:
displayEntity's display name, the one you see in the player list/chat. Example: "[Team blue] Tom421"uuidEntity's UUIDxyzEntity coordinates- More coming soon™
Supports color codes too!
Use /pe reload or /player_events reload to reload the mod config.
You can use /pe test <event> or /player_events test <event> to test the actions on a specific
event, or use /pe test * to test every event.
2.2.0 supported events
death- Executed when a player dies.first_join- Executed when a player joins for first time.join- Executed when a player joins.kill_entity- Executed when a player kills an entity. Extra tokens:${killedEntity}- the killed entity.
kill_player- Executed when a player kills another player. Extra tokens:${killedPlayer}- the killed player.
leave- Executed when a player leaves.custom_commands- Custom defined events triggered by using a defined command. Note: This event does not support datapack functions
Additionally, you can create simple commands (if you want a more complex command, this mod isn't what you are looking for) or listen to existing ones.
Troubleshooting
If you get an error when initializing the server or when an action should be executed, here are steps on how to solve it.
- "Invalid JSON syntax in the config file": This is most likely caused by having a command with
unescaped double quotes. To fix it:
- Check what the exception says in the line below. It will indicate exactly where the error is.
- Escape any double quotes inside the action with backslashes like
"->\"
- "Invalid escape sequence"
This is caused because of an improperly escaped escape sequence like
\nor\u. To fix it, just add a backslash before the escape sequence backslash, for example\n->\\nor\\u->\\\\u
Developing
This part is for mod developers that would like to use the mod api.
Compiling
- Clone or download the repository
- On a command prompt run
gradlew buildto compile the mod. (If you only need the API files, you can rungradlew api:buildinstead) . You'll find the compiled.jarfiles under<repository>/build/libsand<repository>/api/build/libs
API
Adding the API as a dependency of your mod
Add the following snippet to your build.gradle:
repositories {
maven {
url 'https://maven.bymartrixx.me'
}
}
dependencies {
// Using the version from the gradle.properties
modImplementation "me.bymartrixx.player-events:api:${project.player_events_api_version}"
// Directly setting the version (replace 2.1.3 with the latest release available)
modImplementation "me.bymartrixx.player-events:api:2.1.3"
}
Add this snippet to your gradle.properties if you aren't directly setting the version to the build.gradle file:
# Replace 2.1.3 with the latest release available
player_events_api_version = 2.1.3
Also, add this snippet to your fabric.mod.json if you want your mod to depend on the api:
{
"depends": {
"player_events_api": ">=2.0.0"
}
}
Events
death-me.bymartrixx.playerevents.api.event.PlayerDeathCallback.EVENTfirst_join-me.bymartrixx.playerevents.api.event.PlayerFirstJoinCallback.EVENTjoin-me.bymartrixx.playerevents.api.event.PlayerJoinCallback.EVENTkill_entity-me.bymartrixx.playerevents.api.event.PlayerKillEntityCallback.EVENTkill_player-me.bymartrixx.playerevents.api.event.PlayerKillPlayerCallback.EVENTleave-me.bymartrixx.playerevents.api.event.PlayerLeaveCallback.EVENT- Command executed -
me.bymartrixx.playerevents.api.event.CommandExecutionCallback.EVENT
Note
The package
io.github.bymartrixx.playerevents.api has been removed in 2.2.0.
Using the events
Example snippet
public class FooMod implements DedicatedServerModInitializer {
public void onInitializeServer() {
PlayerDeathCallback.EVENT.register((player, source) -> {
// Do something
});
PlayerKillEntityCallback.EVENT.register((player, killedEntity) -> {
// Do something
});
}
}
下载 Player Events
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Player Events
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Player Events
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Player Events
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Player Events
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Player Events
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Player Events
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Player Events
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Player Events
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Player Events
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
更新日志可在 查看
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
在游戏画面角落显示附近世界地形、玩家、生物和实体的地图。可创建路径点,帮助你找到标记过的位置。
模组
查看物品与配方
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
模组
AE2:一款流行的自动化与存储模组
模组
那是什么?一个 Waila/Hwyla 的分支。

评论 0
登录后参与评分
还没有评论,来抢沙发吧