mirror of
https://github.com/jie65535/mirai-console-jms-plugin.git
synced 2025-06-02 17:39:17 +08:00
Use mojang uuid api
Use nickac skin render api Update version to v1.2.0
This commit is contained in:
parent
0fcc1c0d54
commit
50656d011f
@ -8,12 +8,11 @@
|
|||||||
```
|
```
|
||||||
/jms avatar <username> # 查询玩家头像
|
/jms avatar <username> # 查询玩家头像
|
||||||
/jms body <username> # 查询玩家皮肤模型
|
/jms body <username> # 查询玩家皮肤模型
|
||||||
/jms cape <username> # 获取玩家披风文件
|
|
||||||
/jms head <username> # 查询玩家头模型
|
/jms head <username> # 查询玩家头模型
|
||||||
/jms skin <username> # 获取玩家皮肤文件
|
/jms skin <username> # 获取玩家皮肤文件
|
||||||
/jms uuid <username> # 查询玩家UUID
|
/jms uuid <username> # 查询玩家UUID
|
||||||
```
|
```
|
||||||
|
|
||||||
# API
|
# API
|
||||||
- 获取皮肤接口 [Crafatar](https://crafatar.com/)
|
- 获取皮肤接口 [nickac](https://nmsr.nickac.dev/)
|
||||||
- 获取玩家UUID接口 [TenApi](https://docs.tenapi.cn/mc.html)
|
- 获取玩家UUID接口 [Mojang](https://zh.minecraft.wiki/w/Mojang_API)
|
||||||
|
@ -7,7 +7,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = "top.jie65535.mirai"
|
group = "top.jie65535.mirai"
|
||||||
version = "1.1.1"
|
version = "1.2.0"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
maven("https://maven.aliyun.com/repository/public")
|
maven("https://maven.aliyun.com/repository/public")
|
||||||
@ -15,7 +15,6 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|
||||||
val ktorVersion = "2.3.8"
|
val ktorVersion = "2.3.8"
|
||||||
implementation("io.ktor:ktor-client-core-jvm:$ktorVersion")
|
implementation("io.ktor:ktor-client-core-jvm:$ktorVersion")
|
||||||
implementation("io.ktor:ktor-client-okhttp-jvm:$ktorVersion")
|
implementation("io.ktor:ktor-client-okhttp-jvm:$ktorVersion")
|
||||||
|
@ -64,16 +64,16 @@ object JMSCommand : CompositeCommand(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubCommand("cape")
|
// @SubCommand("cape")
|
||||||
@Description("获取玩家披风文件")
|
// @Description("获取玩家披风文件")
|
||||||
suspend fun CommandSender.getCape(username: String) {
|
// suspend fun CommandSender.getCape(username: String) {
|
||||||
try {
|
// try {
|
||||||
sendImage(MinecraftPlayer(username).cape)
|
// sendImage(MinecraftPlayer(username).cape)
|
||||||
} catch (e: Throwable) {
|
// } catch (e: Throwable) {
|
||||||
JMinecraftSkin.logger.error("获取玩家披风文件失败", e)
|
// JMinecraftSkin.logger.error("获取玩家披风文件失败", e)
|
||||||
e.message?.let { sendMessage(it) }
|
// e.message?.let { sendMessage(it) }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
private suspend fun CommandSender.sendImage(data: ByteArray) {
|
private suspend fun CommandSender.sendImage(data: ByteArray) {
|
||||||
try {
|
try {
|
||||||
|
@ -9,7 +9,7 @@ object JMinecraftSkin : KotlinPlugin(
|
|||||||
JvmPluginDescription(
|
JvmPluginDescription(
|
||||||
id = "top.jie65535.mirai-console-jms-plugin",
|
id = "top.jie65535.mirai-console-jms-plugin",
|
||||||
name = "J Minecraft Skin",
|
name = "J Minecraft Skin",
|
||||||
version = "1.1.1",
|
version = "1.2.0",
|
||||||
) {
|
) {
|
||||||
author("jie65535")
|
author("jie65535")
|
||||||
info("MC皮肤查询插件")
|
info("MC皮肤查询插件")
|
||||||
@ -19,7 +19,7 @@ object JMinecraftSkin : KotlinPlugin(
|
|||||||
override fun onEnable() {
|
override fun onEnable() {
|
||||||
JMSPluginData.reload()
|
JMSPluginData.reload()
|
||||||
JMSCommand.register()
|
JMSCommand.register()
|
||||||
logger.info { "Plugin loaded. https://github.com/jie65535/mirai-console-jcf-plugin" }
|
logger.info { "Plugin loaded. https://github.com/jie65535/mirai-console-jms-plugin" }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDisable() {
|
override fun onDisable() {
|
||||||
|
@ -35,5 +35,5 @@ class MinecraftPlayer(username: String) {
|
|||||||
/**
|
/**
|
||||||
* 披风文件
|
* 披风文件
|
||||||
*/
|
*/
|
||||||
val cape get() = MinecraftSkinService.getCapes(uuid)
|
// val cape get() = MinecraftSkinService.getCapes(uuid)
|
||||||
}
|
}
|
@ -11,29 +11,33 @@ object MinecraftSkinService {
|
|||||||
* 获取头像
|
* 获取头像
|
||||||
*/
|
*/
|
||||||
fun getAvatars(uuid: String)
|
fun getAvatars(uuid: String)
|
||||||
= HttpUtil.get("https://crafatar.com/avatars/$uuid?overlay")
|
// = HttpUtil.get("https://crafatar.com/avatars/$uuid?overlay")
|
||||||
|
= HttpUtil.get("https://nmsr.nickac.dev/face/$uuid")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取玩家头模型渲染图
|
* 获取玩家头模型渲染图
|
||||||
*/
|
*/
|
||||||
fun getHeadRenders(uuid: String)
|
fun getHeadRenders(uuid: String)
|
||||||
= HttpUtil.get("https://crafatar.com/renders/head/$uuid?overlay")
|
// = HttpUtil.get("https://crafatar.com/renders/head/$uuid?overlay")
|
||||||
|
= HttpUtil.get("https://nmsr.nickac.dev/head/$uuid")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取玩家皮肤模型渲染图
|
* 获取玩家皮肤模型渲染图
|
||||||
*/
|
*/
|
||||||
fun getBodyRenders(uuid: String)
|
fun getBodyRenders(uuid: String)
|
||||||
= HttpUtil.get("https://crafatar.com/renders/body/$uuid?overlay")
|
// = HttpUtil.get("https://crafatar.com/renders/body/$uuid?overlay")
|
||||||
|
= HttpUtil.get("https://nmsr.nickac.dev/fullbody/$uuid")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取玩家皮肤源文件
|
* 获取玩家皮肤源文件
|
||||||
*/
|
*/
|
||||||
fun getSkins(uuid: String)
|
fun getSkins(uuid: String)
|
||||||
= HttpUtil.get("https://crafatar.com/skins/$uuid")
|
// = HttpUtil.get("https://crafatar.com/skins/$uuid")
|
||||||
|
= HttpUtil.get("https://nmsr.nickac.dev/skin/$uuid")
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 获取玩家皮肤源文件
|
// * 获取玩家皮肤源文件
|
||||||
*/
|
// */
|
||||||
fun getCapes(uuid: String)
|
// fun getCapes(uuid: String)
|
||||||
= HttpUtil.get("https://crafatar.com/capes/$uuid")
|
// = HttpUtil.get("https://crafatar.com/capes/$uuid")
|
||||||
}
|
}
|
||||||
|
@ -14,22 +14,53 @@ object MinecraftUuidService {
|
|||||||
* 根据游戏角色名获取UUID
|
* 根据游戏角色名获取UUID
|
||||||
*/
|
*/
|
||||||
fun getUuid(username: String) : String {
|
fun getUuid(username: String) : String {
|
||||||
|
if (!checkUsername(username)) {
|
||||||
|
throw IllegalArgumentException("用户名格式不正确")
|
||||||
|
}
|
||||||
|
|
||||||
var uuid = JMSPluginData.idMap[username]
|
var uuid = JMSPluginData.idMap[username]
|
||||||
if (uuid != null) {
|
if (uuid != null) {
|
||||||
return uuid
|
return uuid
|
||||||
}
|
}
|
||||||
|
|
||||||
val retJson = HttpUtil.get("https://tenapi.cn/v2/mc/?uid=$username").decodeToString()
|
val retJson = HttpUtil.get("https://api.mojang.com/users/profiles/minecraft/$username").decodeToString()
|
||||||
|
// val retJson = HttpUtil.get("https://tenapi.cn/v2/mc/?uid=$username").decodeToString()
|
||||||
val response = Json.decodeFromString<JsonObject>(retJson)
|
val response = Json.decodeFromString<JsonObject>(retJson)
|
||||||
if (response["code"]!!.jsonPrimitive.content == "200") {
|
// if (response["code"]!!.jsonPrimitive.content == "200") {
|
||||||
val elem = response["data"]!!.jsonObject["id"]!!.jsonPrimitive
|
// val elem = response["data"]!!.jsonObject["id"]!!.jsonPrimitive
|
||||||
if (elem == JsonNull) throw Exception("Player UUID Not Found!")
|
// if (elem == JsonNull) throw Exception("Player UUID Not Found!")
|
||||||
uuid = elem.content
|
// uuid = elem.content
|
||||||
} else {
|
// } else {
|
||||||
throw Exception(response["msg"]!!.jsonPrimitive.content)
|
// throw Exception(response["msg"]!!.jsonPrimitive.content)
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
if (response.containsKey("id")) {
|
||||||
|
uuid = response["id"]!!.jsonPrimitive.content
|
||||||
|
} else if (response.containsKey("errorMessage")) {
|
||||||
|
throw Exception(response["errorMessage"]!!.jsonPrimitive.content)
|
||||||
|
} else {
|
||||||
|
throw Exception("未知错误")
|
||||||
|
}
|
||||||
JMSPluginData.idMap[username] = uuid
|
JMSPluginData.idMap[username] = uuid
|
||||||
return uuid
|
return uuid
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 检查用户名格式
|
||||||
|
* 相当于正则 [0-9a-zA-Z_]{2, 16}
|
||||||
|
* 直接代码检查懒得正则了
|
||||||
|
*/
|
||||||
|
fun checkUsername(username: String): Boolean {
|
||||||
|
// 长度校验
|
||||||
|
if (username.length < 2 || username.length > 16) {
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
// 字符校验
|
||||||
|
for (ch in username) {
|
||||||
|
if (!ch.isLetterOrDigit() && ch != '_')
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user