Skip to content

Commit

Permalink
Add fontPath configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Under-estimate committed Jan 6, 2023
1 parent b518927 commit 0094bc6
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
| recordOnlinePlayer | 字符串列表 | 已启用历史在线人数记录的服务器 |
| recordInterval | 整数 | 记录在线人数的时间间隔(秒) |
| recordLimit | 整数 | 最长保留的在线人数记录时间(秒) |
| fontPath | 字符串(默认为空) | 指定渲染图片时所使用的字体文件,如果指定了字体文件并且被成功加载,则不会使用`fontName`配置项(此配置项正常情况下无需使用。如果无法使用系统字体,请使用此配置项指定字体文件([#14](https://github.com/Under-estimate/McMotd/issues/14))) |

## FAQ
### Q: 在QQ群中发送命令没反应
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "org.zrnq"
version = "1.1.12"
version = "1.1.13"

repositories {
maven("https://maven.aliyun.com/repository/public")
Expand Down
20 changes: 20 additions & 0 deletions src/main/kotlin/org/zrnq/mclient/MClientOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.zrnq.mcmotd.McMotd
import org.zrnq.mcmotd.PluginConfig
import java.awt.Font
import java.awt.GraphicsEnvironment
import java.io.File

object MClientOptions {
lateinit var FONT : Font
Expand All @@ -21,6 +22,25 @@ object MClientOptions {
showServerVersion = PluginConfig.showServerVersion
showPlayerList = PluginConfig.showPlayerList

if(PluginConfig.fontPath.isNotBlank()) {
val fontFile = File(PluginConfig.fontPath)
if(!fontFile.exists()) {
McMotd.logger.warning("无法打开指定的字体文件: ${PluginConfig.fontPath},请检查配置文件")
} else {
try {
val font = Font.createFont(Font.TRUETYPE_FONT, fontFile)
if(!GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(font)) {
McMotd.logger.warning("注册字体文件到LocalGraphicsEnvironment时失败")
}
FONT = font.deriveFont(20f)
McMotd.logger.info("正在使用字体文件: ${PluginConfig.fontPath} (${font.fontName})")
return
} catch (e : Exception) {
McMotd.logger.warning("读取字体文件: ${PluginConfig.fontPath}时出错", e)
}
}
}

val fontList = mutableListOf<Font>()
for(f in GraphicsEnvironment.getLocalGraphicsEnvironment().allFonts) {
if(f.name == PluginConfig.fontName) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/org/zrnq/mcmotd/McMotd.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object McMotd : KotlinPlugin(
JvmPluginDescription(
id = "org.zrnq.mcmotd",
name = "Minecraft MOTD Fetcher",
version = "1.1.12",
version = "1.1.13",
) {
author("ZRnQ")
info("""以图片的形式获取指定Minecraft服务器的基本信息""")
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/org/zrnq/mcmotd/PluginConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import net.mamoe.mirai.console.data.AutoSavePluginConfig
import net.mamoe.mirai.console.data.value

object PluginConfig : AutoSavePluginConfig("mcmotd") {
val fontPath by value("")
val fontName by value("Microsoft YaHei")
val showTrueAddress by value(false)
val showServerVersion by value(false)
Expand Down

0 comments on commit 0094bc6

Please sign in to comment.