Skip to content

Commit 943221c

Browse files
committed
complete some TODO
1 parent b797713 commit 943221c

File tree

7 files changed

+55
-14
lines changed

7 files changed

+55
-14
lines changed

common/src/main/kotlin/me/regadpole/plumbot/PlatformImpl.kt

+2
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ package me.regadpole.plumbot
22

33
abstract class PlatformImpl {
44
abstract fun getPlayerList() : List<String>
5+
abstract fun getTPS(): List<Double>
6+
abstract fun dispatchCommand(cmd: String): StringBuilder
57
}

common/src/main/kotlin/me/regadpole/plumbot/PlumBot.kt

+8-5
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import me.regadpole.plumbot.database.Database
1010
import me.regadpole.plumbot.database.MySQL
1111
import me.regadpole.plumbot.database.SQLite
1212
import taboolib.common.platform.Plugin
13-
import taboolib.common.platform.function.disablePlugin
14-
import taboolib.common.platform.function.info
15-
import taboolib.common.platform.function.submitAsync
16-
import taboolib.common.platform.function.warning
13+
import taboolib.common.platform.function.*
1714

1815

1916
object PlumBot : Plugin() {
@@ -26,8 +23,11 @@ object PlumBot : Plugin() {
2623

2724
private lateinit var database: Database
2825

29-
var playerList = mutableListOf<String>()
26+
// TODO: 初始化platformImpl
27+
private lateinit var platformImpl: PlatformImpl
3028

29+
// var playerList = mutableListOf<String>()
30+
val playerList = onlinePlayers()
3131
override fun onLoad() {
3232
ConfigResolver.loadConfig()
3333
config = ConfigResolver.getConfigLoader()
@@ -100,5 +100,8 @@ object PlumBot : Plugin() {
100100
fun getDatabase(): Database {
101101
return database
102102
}
103+
fun getPlatformImpl(): PlatformImpl {
104+
return platformImpl
105+
}
103106

104107
}

common/src/main/kotlin/me/regadpole/plumbot/config/LangConfig.kt

+3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ class LangConfig(langConfig: Configuration) {
1212
val forwarding = Forwarding(config)
1313
val playerJoinMsg = config.getString("playerJoinMsg")
1414
val playerLeaveMsg = config.getString("playerLeaveMsg")
15+
val online = config.getString("online")
16+
val tps = config.getString("tps")
1517
val whitelist = Whitelist(config)
1618
val commandSendFinish = config.getString("commandSendFinish")
1719
val messageOnDie = config.getString("messageOnDie")
20+
val help = config.getStringList("help")
1821
class Forwarding(config: Configuration) {
1922
val toPlatform = config.getString("forwarding.toPlatform")
2023
val toServer = config.getString("forwarding.toServer")

common/src/main/kotlin/me/regadpole/plumbot/listener/GPlatformListener.kt

+12-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package me.regadpole.plumbot.listener
22

33
import me.regadpole.plumbot.PlumBot
44
import me.regadpole.plumbot.internal.WhitelistHelper
5-
import taboolib.common5.util.replace
65

76
object GPlatformListener {
87
fun onGroupMessage(message: String, groupId: String, senderId: String, senderName: String) {
@@ -22,14 +21,22 @@ object GPlatformListener {
2221
}
2322
}
2423
if (message.substring(1) == "help" || message.substring(1) == "帮助") {
25-
24+
val sbuilder = StringBuilder()
25+
PlumBot.getLangConfig().getLangConf().help.forEach {
26+
sbuilder.append(it.replace("prefix", PlumBot.getConfig().getConfig().groups.prefix!!))
27+
}
28+
PlumBot.getBot().sendGroupMsg(groupId, sbuilder.toString())
2629
}
2730
if (PlumBot.getConfig().getConfig().groups.forwarding.tps && message.substring(1) == "tps") {
28-
// TODO: 获取服务器 TPS 并返回
31+
val tps = PlumBot.getPlatformImpl().getTPS()
32+
PlumBot.getBot().sendGroupMsg(groupId, PlumBot.getLangConfig().getLangConf().tps!!
33+
.replace("%tps%", tps[0].toString())
34+
.replace("%mspt%", tps[1].toString()))
2935
}
3036
if (PlumBot.getConfig().getConfig().groups.forwarding.online && message.substring(1) == "在线人数") {
31-
// TODO: 看看这样写有没有问题((
32-
PlumBot.getBot().sendGroupMsg(groupId, "在线玩家: ${PlumBot.playerList.joinToString(", ")}")
37+
PlumBot.getBot().sendGroupMsg(groupId, PlumBot.getLangConfig().getLangConf().online!!
38+
.replace("%count%", PlumBot.playerList.size.toString())
39+
.replace("%player_list%", PlumBot.playerList.joinToString(", ")))
3340
}
3441
if (PlumBot.getConfig().getConfig().groups.botAdmins.contains(groupId) && message.substring(1) == "cmd") {
3542
// TODO: 执行message内游戏命令并返回

common/src/main/kotlin/me/regadpole/plumbot/listener/game/GameListener.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import me.regadpole.plumbot.event.GDeathEvent
55
import me.regadpole.plumbot.event.GJoinEvent
66
import me.regadpole.plumbot.event.GPlayerChatEvent
77
import me.regadpole.plumbot.event.GQuitEvent
8-
import taboolib.common5.util.replace
98

109
object GameListener {
1110
fun onChat(event: GPlayerChatEvent) {
@@ -38,7 +37,7 @@ object GameListener {
3837
}
3938

4039
fun onJoin(event: GJoinEvent) {
41-
PlumBot.playerList.add(event.player.name)
40+
// PlumBot.playerList.add(event.player.name)
4241
if (!PlumBot.getConfig().getConfig().groups.forwarding.whitelist.enable) {
4342
return
4443
}
@@ -63,7 +62,7 @@ object GameListener {
6362
}
6463

6564
fun onQuit(event: GQuitEvent) {
66-
PlumBot.playerList.remove(event.player.name)
65+
// PlumBot.playerList.remove(event.player.name)
6766
if (PlumBot.getConfig().getConfig().groups.forwarding.joinAndLeave) {
6867
var message: String = PlumBot.getLangConfig().getLangConf().playerLeaveMsg?: return
6968
message = message.replace("%player_name%", event.player.name)

common/src/main/resources/lang/en_US.yml

+23-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ forwarding:
2121
playerJoinMsg: "%player_name% join the server"
2222
playerLeaveMsg: "%player_name% leave the server"
2323

24+
# Optional placeholders: %count%, %player_list%
25+
online: "Online players: (%count% players): %player_list%"
26+
# Optional placeholders:%tps%, %mspt%
27+
tps: "tps:%tps% \n mspt:%mspt%"
28+
2429
whitelist:
2530
# Optional placeholders:%enable_groups%
2631
kickServer: "please enter the group to apply the whitelist"
@@ -32,6 +37,12 @@ whitelist:
3237
removeBind: "successfully remove the whitelist, your whitelist is %whitelist_name%"
3338
# Optional placeholders:%whitelist_name%, %platform_id%
3439
queryBind: "your whitelist is %whitelist_name%"
40+
# Optional placeholders:%player_name%, %whitelist_name%, %platform_id%, %whitelist_limit%
41+
fullBind: "You have applied for whitelist with limit: %whitelist_limit%"
42+
# Optional placeholders:%player_name%
43+
existsBind: "%player_name% has been bound!"
44+
notExistsBind: "%player_name% hasn't been bound!"
45+
notBelongToYou: "%player_name% hasn't been bound by YOU!"
3546
admin:
3647
# Optional placeholders:%player_name%, %whitelist_name%, %target_platform_id%, %sender_platform_id%
3748
addBind: "successfully apply the whitelist, %target_platform_id%'s whitelist is %whitelist_name%"
@@ -43,4 +54,15 @@ whitelist:
4354
commandSendFinish: "sending the command to the server..."
4455

4556
# Optional placeholders:%player_name%, %world_name%, %pos%
46-
messageOnDie: "Player %player_name% was died at %pos% in %world_name%"
57+
messageOnDie: "Player %player_name% was died at %pos% in %world_name%"
58+
59+
# Optional placeholders: %prefix%
60+
help:
61+
- "PlumBot help page"
62+
- "%prefix%在线人数 - List online players"
63+
- "%prefix%tps - Query the TPS"
64+
- "%prefix%申请白名单 <ID> - Apply for whitelist"
65+
- "%prefix%移除白名单 <ID> - Remove whitelist"
66+
- "%prefix%查询白名单 - Query whitelist"
67+
- "管理员命令"
68+
- "%prefix%cmd <命令> - Dispatch commands to the server"

common/src/main/resources/lang/zh_CN.yml

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ forwarding:
2121
playerJoinMsg: "%player_name%进入服务器"
2222
playerLeaveMsg: "%player_name%退出服务器"
2323

24+
# 可选占位符:%count%, %player_list%
25+
online: "当前在线: (%count%人): %player_list%"
26+
# 可选占位符:%tps%, %mspt%
27+
tps: "当前tps:%tps% \n 当前mspt:%mspt%"
28+
2429
whitelist:
2530
# 可选占位符:%enable_groups%
2631
kickServer: "请加入qq群:xxx申请白名单"

0 commit comments

Comments
 (0)