Skip to content

Commit

Permalink
complete some TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
RegadPoleCN committed Oct 12, 2024
1 parent b797713 commit 943221c
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 14 deletions.
2 changes: 2 additions & 0 deletions common/src/main/kotlin/me/regadpole/plumbot/PlatformImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ package me.regadpole.plumbot

abstract class PlatformImpl {
abstract fun getPlayerList() : List<String>
abstract fun getTPS(): List<Double>
abstract fun dispatchCommand(cmd: String): StringBuilder
}
13 changes: 8 additions & 5 deletions common/src/main/kotlin/me/regadpole/plumbot/PlumBot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import me.regadpole.plumbot.database.Database
import me.regadpole.plumbot.database.MySQL
import me.regadpole.plumbot.database.SQLite
import taboolib.common.platform.Plugin
import taboolib.common.platform.function.disablePlugin
import taboolib.common.platform.function.info
import taboolib.common.platform.function.submitAsync
import taboolib.common.platform.function.warning
import taboolib.common.platform.function.*


object PlumBot : Plugin() {
Expand All @@ -26,8 +23,11 @@ object PlumBot : Plugin() {

private lateinit var database: Database

var playerList = mutableListOf<String>()
// TODO: 初始化platformImpl
private lateinit var platformImpl: PlatformImpl

// var playerList = mutableListOf<String>()
val playerList = onlinePlayers()
override fun onLoad() {
ConfigResolver.loadConfig()
config = ConfigResolver.getConfigLoader()
Expand Down Expand Up @@ -100,5 +100,8 @@ object PlumBot : Plugin() {
fun getDatabase(): Database {
return database
}
fun getPlatformImpl(): PlatformImpl {
return platformImpl
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ class LangConfig(langConfig: Configuration) {
val forwarding = Forwarding(config)
val playerJoinMsg = config.getString("playerJoinMsg")
val playerLeaveMsg = config.getString("playerLeaveMsg")
val online = config.getString("online")
val tps = config.getString("tps")
val whitelist = Whitelist(config)
val commandSendFinish = config.getString("commandSendFinish")
val messageOnDie = config.getString("messageOnDie")
val help = config.getStringList("help")
class Forwarding(config: Configuration) {
val toPlatform = config.getString("forwarding.toPlatform")
val toServer = config.getString("forwarding.toServer")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package me.regadpole.plumbot.listener

import me.regadpole.plumbot.PlumBot
import me.regadpole.plumbot.internal.WhitelistHelper
import taboolib.common5.util.replace

object GPlatformListener {
fun onGroupMessage(message: String, groupId: String, senderId: String, senderName: String) {
Expand All @@ -22,14 +21,22 @@ object GPlatformListener {
}
}
if (message.substring(1) == "help" || message.substring(1) == "帮助") {

val sbuilder = StringBuilder()
PlumBot.getLangConfig().getLangConf().help.forEach {
sbuilder.append(it.replace("prefix", PlumBot.getConfig().getConfig().groups.prefix!!))
}
PlumBot.getBot().sendGroupMsg(groupId, sbuilder.toString())
}
if (PlumBot.getConfig().getConfig().groups.forwarding.tps && message.substring(1) == "tps") {
// TODO: 获取服务器 TPS 并返回
val tps = PlumBot.getPlatformImpl().getTPS()
PlumBot.getBot().sendGroupMsg(groupId, PlumBot.getLangConfig().getLangConf().tps!!
.replace("%tps%", tps[0].toString())
.replace("%mspt%", tps[1].toString()))
}
if (PlumBot.getConfig().getConfig().groups.forwarding.online && message.substring(1) == "在线人数") {
// TODO: 看看这样写有没有问题((
PlumBot.getBot().sendGroupMsg(groupId, "在线玩家: ${PlumBot.playerList.joinToString(", ")}")
PlumBot.getBot().sendGroupMsg(groupId, PlumBot.getLangConfig().getLangConf().online!!
.replace("%count%", PlumBot.playerList.size.toString())
.replace("%player_list%", PlumBot.playerList.joinToString(", ")))
}
if (PlumBot.getConfig().getConfig().groups.botAdmins.contains(groupId) && message.substring(1) == "cmd") {
// TODO: 执行message内游戏命令并返回
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import me.regadpole.plumbot.event.GDeathEvent
import me.regadpole.plumbot.event.GJoinEvent
import me.regadpole.plumbot.event.GPlayerChatEvent
import me.regadpole.plumbot.event.GQuitEvent
import taboolib.common5.util.replace

object GameListener {
fun onChat(event: GPlayerChatEvent) {
Expand Down Expand Up @@ -38,7 +37,7 @@ object GameListener {
}

fun onJoin(event: GJoinEvent) {
PlumBot.playerList.add(event.player.name)
// PlumBot.playerList.add(event.player.name)
if (!PlumBot.getConfig().getConfig().groups.forwarding.whitelist.enable) {
return
}
Expand All @@ -63,7 +62,7 @@ object GameListener {
}

fun onQuit(event: GQuitEvent) {
PlumBot.playerList.remove(event.player.name)
// PlumBot.playerList.remove(event.player.name)
if (PlumBot.getConfig().getConfig().groups.forwarding.joinAndLeave) {
var message: String = PlumBot.getLangConfig().getLangConf().playerLeaveMsg?: return
message = message.replace("%player_name%", event.player.name)
Expand Down
24 changes: 23 additions & 1 deletion common/src/main/resources/lang/en_US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ forwarding:
playerJoinMsg: "%player_name% join the server"
playerLeaveMsg: "%player_name% leave the server"

# Optional placeholders: %count%, %player_list%
online: "Online players: (%count% players): %player_list%"
# Optional placeholders:%tps%, %mspt%
tps: "tps:%tps% \n mspt:%mspt%"

whitelist:
# Optional placeholders:%enable_groups%
kickServer: "please enter the group to apply the whitelist"
Expand All @@ -32,6 +37,12 @@ whitelist:
removeBind: "successfully remove the whitelist, your whitelist is %whitelist_name%"
# Optional placeholders:%whitelist_name%, %platform_id%
queryBind: "your whitelist is %whitelist_name%"
# Optional placeholders:%player_name%, %whitelist_name%, %platform_id%, %whitelist_limit%
fullBind: "You have applied for whitelist with limit: %whitelist_limit%"
# Optional placeholders:%player_name%
existsBind: "%player_name% has been bound!"
notExistsBind: "%player_name% hasn't been bound!"
notBelongToYou: "%player_name% hasn't been bound by YOU!"
admin:
# Optional placeholders:%player_name%, %whitelist_name%, %target_platform_id%, %sender_platform_id%
addBind: "successfully apply the whitelist, %target_platform_id%'s whitelist is %whitelist_name%"
Expand All @@ -43,4 +54,15 @@ whitelist:
commandSendFinish: "sending the command to the server..."

# Optional placeholders:%player_name%, %world_name%, %pos%
messageOnDie: "Player %player_name% was died at %pos% in %world_name%"
messageOnDie: "Player %player_name% was died at %pos% in %world_name%"

# Optional placeholders: %prefix%
help:
- "PlumBot help page"
- "%prefix%在线人数 - List online players"
- "%prefix%tps - Query the TPS"
- "%prefix%申请白名单 <ID> - Apply for whitelist"
- "%prefix%移除白名单 <ID> - Remove whitelist"
- "%prefix%查询白名单 - Query whitelist"
- "管理员命令"
- "%prefix%cmd <命令> - Dispatch commands to the server"
5 changes: 5 additions & 0 deletions common/src/main/resources/lang/zh_CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ forwarding:
playerJoinMsg: "%player_name%进入服务器"
playerLeaveMsg: "%player_name%退出服务器"

# 可选占位符:%count%, %player_list%
online: "当前在线: (%count%人): %player_list%"
# 可选占位符:%tps%, %mspt%
tps: "当前tps:%tps% \n 当前mspt:%mspt%"

whitelist:
# 可选占位符:%enable_groups%
kickServer: "请加入qq群:xxx申请白名单"
Expand Down

0 comments on commit 943221c

Please sign in to comment.