Skip to content

Commit 265ee9a

Browse files
committed
feat(bungee): 支持 Velocity 代理并优化跨代理通信
- 添加 Velocity 代理支持,新增 bungeecord:main 通道 - 实现 ProxyType 枚举区分 BUNGEE、VELOCITY 和 AUTO 模式 - 在初始化阶段注册两个通道确保兼容性 - 根据配置的代理类型动态选择发送通道 - 更新设置文件添加代理类型配置选项 - 修复跨代理消息发送逻辑以支持多通道
1 parent faa25ba commit 265ee9a

3 files changed

Lines changed: 34 additions & 5 deletions

File tree

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
group=me.arasple.mc.trmenu
2-
version=3.9.25
2+
version=3.9.26

plugin/src/main/kotlin/trplugins/menu/util/Bungees.kt

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,28 @@ import java.io.IOException
1313
*/
1414
object Bungees {
1515

16+
private const val CHANNEL_BUNGEE = "BungeeCord"
17+
private const val CHANNEL_VELOCITY = "bungeecord:main"
18+
19+
private val proxyType: ProxyType
20+
get() = runCatching {
21+
ProxyType.valueOf(TrMenu.SETTINGS.getString("Options.Proxy", "AUTO")!!.uppercase())
22+
}.getOrElse { ProxyType.AUTO }
23+
24+
private val channels: List<String>
25+
get() = when (proxyType) {
26+
ProxyType.BUNGEE -> listOf(CHANNEL_BUNGEE)
27+
ProxyType.VELOCITY -> listOf(CHANNEL_VELOCITY)
28+
ProxyType.AUTO -> listOf(CHANNEL_BUNGEE, CHANNEL_VELOCITY)
29+
}
30+
1631
init {
17-
if (!Bukkit.getMessenger().isOutgoingChannelRegistered(TrMenu.plugin, "BungeeCord")) {
18-
Bukkit.getMessenger().registerOutgoingPluginChannel(TrMenu.plugin, "BungeeCord")
32+
val messenger = Bukkit.getMessenger()
33+
// init 阶段按 AUTO 注册两个 channel,确保后续任何配置都能工作
34+
listOf(CHANNEL_BUNGEE, CHANNEL_VELOCITY).forEach { channel ->
35+
if (!messenger.isOutgoingChannelRegistered(TrMenu.plugin, channel)) {
36+
messenger.registerOutgoingPluginChannel(TrMenu.plugin, channel)
37+
}
1938
}
2039
}
2140

@@ -31,7 +50,14 @@ object Bungees {
3150
e.printStackTrace()
3251
}
3352
}
34-
player.sendPluginMessage(TrMenu.plugin, "BungeeCord", byteArray.toByteArray())
53+
val data = byteArray.toByteArray()
54+
// 根据配置的代理类型决定向哪些 channel 发送
55+
channels.forEach { channel ->
56+
player.sendPluginMessage(TrMenu.plugin, channel, data)
57+
}
3558
}
3659

37-
}
60+
enum class ProxyType {
61+
BUNGEE, VELOCITY, AUTO
62+
}
63+
}

plugin/src/main/resources/settings.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Options:
1111
Bedrock: false
1212
Packet-Inventory:
1313
Create-Id: false
14+
# 代理类型: BUNGEE / VELOCITY / AUTO
15+
# AUTO 模式下同时注册 BungeeCord 和 bungeecord:main 两个 channel
16+
Proxy: AUTO
1417
Bedrock-Open-Delay: 20
1518

1619
Placeholders:

0 commit comments

Comments
 (0)