SmartBroadcast
中文
SmartBroadcast 是一款适用于 Paper / Folia 1.20.1 的智能 Minecraft 局域网发现协议广播插件。它根据可配置的表达式规则,决定何时广播局域网服务器信息以及广播什么 MOTD。
功能特性
- 支持 Folia:使用
GlobalRegionScheduler 和 AsyncScheduler,并在 plugin.yml 中设置 folia-supported: true
- 支持 Minecraft 局域网发现协议:向
224.0.2.60:4445 发送 UDP 组播数据包
- 多规则支持:规则按顺序检查,并使用第一个匹配的规则
- 禁止广播规则:匹配的规则可以设置
broadcast: false 以抑制广播
- 表达式条件:支持玩家数量、白名单状态、端口、MOTD、PlaceholderAPI 占位符等
- PlaceholderAPI 支持:PAPI 占位符可用于表达式和 MOTD 值中
- MiniMessage 支持:自定义 MOTD 值可以使用 MiniMessage 语法,并会被转换为旧版文本
- 当前服务器 MOTD 支持:使用
{server_motd} 广播当前的 Paper MOTD
- 热重载支持:
/smartbroadcast reload
局域网发现协议
当多人服务器列表界面打开时,Minecraft 客户端会监听 224.0.2.60:4445 上的 UDP 组播数据包。服务器应在此格式下发送 UTF-8 字符串:
[MOTD]<server MOTD>[/MOTD][AD]<server port>[/AD]
重要提示:此协议不支持 Adventure 富文本组件。SmartBroadcast 在广播前会将 MiniMessage 或当前服务器 MOTD 转换为旧版 § 文本,以便客户端正确解析。
默认行为
默认情况下,插件仅在至少有一名玩家在线时广播当前服务器 MOTD:
rules:
- name: "players-online"
expression: "online > 0"
broadcast: true
motd: "{server_motd}"
如果没有规则匹配,则不会发送任何局域网数据包。
安装
- 构建插件:
./gradlew shadowJar
- 将生成的 JAR 文件复制到服务器的
plugins 目录中:
build/libs/SmartBroadcast-1.0.0.jar
- 启动你的 Paper / Folia 1.20.1 服务器。
- 如果需要 PlaceholderAPI 支持,请同时安装 PlaceholderAPI。
命令与权限
| 命令 |
权限 |
描述 |
/smartbroadcast reload |
smartbroadcast.admin |
重新加载配置 |
/sbc reload |
smartbroadcast.admin |
重新加载配置 |
/lanbroadcast reload |
smartbroadcast.admin |
重新加载配置 |
配置
broadcast:
enabled: true
address: "224.0.2.60"
port: 4445
interval-millis: 1500
advertised-port: -1
enabled:是否启用广播
address:局域网发现组播地址,默认为 224.0.2.60
port:局域网发现组播端口,默认为 4445
interval-millis:广播间隔;原版约为 1500ms
advertised-port:向客户端广播的服务器端口;-1 表示使用当前服务器端口
表达式规则
规则从上到下依次检查。第一个计算结果为真的规则将被使用。
布尔运算符
&& and (且)
|| or (或)
! not (非)
示例:
expression: "online > 0 && !whitelist"
括号
expression: "(online > 0 && !whitelist) || %server_tps_1% >= 18"
比较运算符
== equals (等于)
!= not equals (不等于)
> greater than (大于)
>= greater than or equal (大于等于)
< less than (小于)
<= less than or equal (小于等于)
字符串运算符
contains contains substring (包含子串)
matches regular expression match (正则表达式匹配)
示例:
expression: "motd contains 'Survival'"
expression: "%server_name% matches 'Lobby.*'"
字面量
支持的字面量:
true
false
- 数字,如
0 和 18.5
- 字符串,如
'Lobby' 或 "Survival"
内置变量
| 变量 |
类型 |
描述 |
online |
number |
当前在线玩家数量 |
max_players |
number |
最大玩家数量 |
port |
number |
向客户端广播的端口 |
whitelist |
boolean |
白名单是否启用 |
motd |
string |
当前服务器 MOTD 的纯文本形式 |
PlaceholderAPI
安装 PlaceholderAPI 后,PAPI 占位符可直接用于表达式和 MOTD 值中:
expression: "%server_online% > 0"
expression: "%server_tps_1% >= 18"
expression: "%server_name% contains 'Lobby'"
motd: "<green>%server_online%</green><gray>/</gray><yellow>%server_max_players%</yellow>"
MOTD 渲染
广播当前服务器 MOTD
motd: "{server_motd}"
插件读取当前的 Paper MOTD,并在广播前将其转换为旧版文本。
自定义 MiniMessage MOTD
motd: "<gradient:#55ff55:#00aaaa>SmartBroadcast</gradient> <gray>|</gray> <yellow>%server_online%</yellow>"
处理流程:
- 应用 PlaceholderAPI
- 解析 MiniMessage
- 转换为旧版
§ 文本
- 使用局域网发现协议发送 UDP 组播数据包
多规则示例
rules:
- name: "hide-when-whitelist"
expression: "whitelist == true"
broadcast: false
- name: "good-tps"
expression: "online > 0 && %server_tps_1% >= 18"
broadcast: true
motd: "{server_motd}"
- name: "fallback"
expression: "online > 0"
broadcast: true
motd: "<yellow>Server is online</yellow>"
构建要求
- Java 17+
- Gradle
- Paper API 1.20.1
构建命令:
./gradlew shadowJar
如果本地没有 Gradle Wrapper,请使用已安装的 Gradle 发行版:
gradle shadowJar
测试建议
- 在 Folia 1.20.1 上启动插件,并确认控制台无报错
- 运行
/smartbroadcast reload 以测试热重载
- 保持至少一名玩家在线,并从同一局域网内的客户端刷新多人服务器列表
- 测试
broadcast: false 是否禁止广播
- 安装 PlaceholderAPI 并测试诸如
%server_online% 和 %server_tps_1% 等表达式
许可证
本项目遵循 GNU General Public License v3.0 开源协议。详情请参阅 LICENSE。
SmartBroadcast
中文
SmartBroadcast is an intelligent Minecraft LAN discovery protocol broadcaster plugin for Paper / Folia 1.20.1. It decides when to broadcast LAN server information, and what MOTD to broadcast, based on configurable expression rules.
Features
- Folia support: uses
GlobalRegionScheduler and AsyncScheduler, with folia-supported: true in plugin.yml
- Minecraft LAN discovery protocol support: sends UDP multicast packets to
224.0.2.60:4445
- Multiple rules: rules are checked in order, and the first matching rule is used
- No-broadcast rules: a matched rule can set
broadcast: false to suppress broadcasting
- Expression conditions: player count, whitelist status, port, MOTD, PlaceholderAPI placeholders, and more
- PlaceholderAPI support: PAPI placeholders can be used in both expressions and MOTD values
- MiniMessage support: custom MOTD values can use MiniMessage and will be converted to legacy text
- Current server MOTD support: use
{server_motd} to broadcast the current Paper MOTD
- Hot reload support:
/smartbroadcast reload
LAN Discovery Protocol
Minecraft clients listen for UDP multicast packets on 224.0.2.60:4445 while the multiplayer server list screen is open. The server should send a UTF-8 string in this format:
[MOTD]<server MOTD>[/MOTD][AD]<server port>[/AD]
Important: this protocol does not support Adventure rich text components. SmartBroadcast converts MiniMessage or the current server MOTD into legacy § text before broadcasting, so clients can parse it correctly.
Default Behavior
By default, the plugin broadcasts the current server MOTD only when at least one player is online:
rules:
- name: "players-online"
expression: "online > 0"
broadcast: true
motd: "{server_motd}"
If no rule matches, no LAN packet is sent.
Installation
- Build the plugin:
./gradlew shadowJar
- Copy the generated JAR into your server's
plugins directory:
build/libs/SmartBroadcast-1.0.0.jar
- Start your Paper / Folia 1.20.1 server.
- Install PlaceholderAPI as well if you need PlaceholderAPI support.
Commands and Permissions
| Command |
Permission |
Description |
/smartbroadcast reload |
smartbroadcast.admin |
Reloads the configuration |
/sbc reload |
smartbroadcast.admin |
Reloads the configuration |
/lanbroadcast reload |
smartbroadcast.admin |
Reloads the configuration |
Configuration
broadcast:
enabled: true
address: "224.0.2.60"
port: 4445
interval-millis: 1500
advertised-port: -1
enabled: whether broadcasting is enabled
address: LAN discovery multicast address, defaults to 224.0.2.60
port: LAN discovery multicast port, defaults to 4445
interval-millis: broadcast interval; vanilla uses about 1500ms
advertised-port: server port advertised to clients; -1 means the current server port
Expression Rules
Rules are checked from top to bottom. The first rule whose expression evaluates to true is used.
Boolean Operators
&& and
|| or
! not
Example:
expression: "online > 0 && !whitelist"
Parentheses
expression: "(online > 0 && !whitelist) || %server_tps_1% >= 18"
Comparison Operators
== equals
!= not equals
> greater than
>= greater than or equal
< less than
<= less than or equal
String Operators
contains contains substring
matches regular expression match
Examples:
expression: "motd contains 'Survival'"
expression: "%server_name% matches 'Lobby.*'"
Literals
Supported literals:
true
false
- numbers such as
0 and 18.5
- strings such as
'Lobby' or "Survival"
Built-in Variables
| Variable |
Type |
Description |
online |
number |
Current online player count |
max_players |
number |
Maximum player count |
port |
number |
Port advertised to clients |
whitelist |
boolean |
Whether the whitelist is enabled |
motd |
string |
Plain-text form of the current server MOTD |
PlaceholderAPI
When PlaceholderAPI is installed, PAPI placeholders can be used directly in expressions and MOTD values:
expression: "%server_online% > 0"
expression: "%server_tps_1% >= 18"
expression: "%server_name% contains 'Lobby'"
motd: "<green>%server_online%</green><gray>/</gray><yellow>%server_max_players%</yellow>"
MOTD Rendering
Broadcast Current Server MOTD
motd: "{server_motd}"
The plugin reads the current Paper MOTD and converts it to legacy text before broadcasting.
Custom MiniMessage MOTD
motd: "<gradient:#55ff55:#00aaaa>SmartBroadcast</gradient> <gray>|</gray> <yellow>%server_online%</yellow>"
Processing pipeline:
- Apply PlaceholderAPI
- Parse MiniMessage
- Convert to legacy
§ text
- Send a UDP multicast packet using the LAN discovery protocol
Multiple Rules Example
rules:
- name: "hide-when-whitelist"
expression: "whitelist == true"
broadcast: false
- name: "good-tps"
expression: "online > 0 && %server_tps_1% >= 18"
broadcast: true
motd: "{server_motd}"
- name: "fallback"
expression: "online > 0"
broadcast: true
motd: "<yellow>Server is online</yellow>"
Build Requirements
- Java 17+
- Gradle
- Paper API 1.20.1
Build command:
./gradlew shadowJar
If Gradle Wrapper is not available locally, use an installed Gradle distribution:
gradle shadowJar
Testing Suggestions
- Start the plugin on Folia 1.20.1 and confirm there are no console errors
- Run
/smartbroadcast reload to test hot reload
- Keep at least one player online and refresh the multiplayer server list from a client on the same LAN
- Test whether
broadcast: false suppresses broadcasting
- Install PlaceholderAPI and test expressions such as
%server_online% and %server_tps_1%
License
This project is licensed under the GNU General Public License v3.0. See LICENSE for details.
评论 0
登录后参与评分
还没有评论,来抢沙发吧