Compare commits

..

9 Commits

Author SHA1 Message Date
50656d011f Use mojang uuid api
Use nickac skin render api
Update version to v1.2.0
2024-04-30 16:26:43 +08:00
sbbtd
0fcc1c0d54 fix: UUID API 2024-02-22 15:05:22 +08:00
adef471210 Fix UUID API
Update version to v1.1.0
2024-02-22 09:17:07 +08:00
feb2d309e0 Update version to v1.0.0
Update dependencies
Fix null UUID error
2023-09-03 01:13:52 +08:00
8c143bb4d4 更新版本到 0.1.2
更新依赖
2023-01-29 01:49:25 +00:00
502milk
9b281361ce
修复获取skin失败 2023-01-29 09:15:38 +08:00
1902e922a3 更新到v0.1.1
修复 未查询到数据时提示异常问题
修复 获取玩家头像未显示双层皮肤问题
2022-02-12 20:10:29 +08:00
5113868a79 Merge remote-tracking branch 'origin/master' 2022-02-08 22:21:06 +08:00
d45d1caf56 修复 未显示双层皮肤的问题 2022-02-08 22:20:50 +08:00
9 changed files with 89 additions and 43 deletions

View File

@ -8,12 +8,11 @@
```
/jms avatar <username> # 查询玩家头像
/jms body <username> # 查询玩家皮肤模型
/jms cape <username> # 获取玩家披风文件
/jms head <username> # 查询玩家头模型
/jms skin <username> # 获取玩家皮肤文件
/jms uuid <username> # 查询玩家UUID
```
# API
- 获取皮肤接口 [Crafatar](https://crafatar.com/)
- 获取玩家UUID接口 [TenApi](https://docs.tenapi.cn/mc.html)
- 获取皮肤接口 [nickac](https://nmsr.nickac.dev/)
- 获取玩家UUID接口 [Mojang](https://zh.minecraft.wiki/w/Mojang_API)

View File

@ -1,15 +1,21 @@
plugins {
val kotlinVersion = "1.5.30"
val kotlinVersion = "1.8.10"
kotlin("jvm") version kotlinVersion
kotlin("plugin.serialization") version kotlinVersion
id("net.mamoe.mirai-console") version "2.9.2"
id("net.mamoe.mirai-console") version "2.16.0"
}
group = "top.jie65535"
version = "0.1.0"
group = "top.jie65535.mirai"
version = "1.2.0"
repositories {
maven("https://maven.aliyun.com/repository/public")
mavenCentral()
}
dependencies {
val ktorVersion = "2.3.8"
implementation("io.ktor:ktor-client-core-jvm:$ktorVersion")
implementation("io.ktor:ktor-client-okhttp-jvm:$ktorVersion")
}

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0
gradlew vendored Normal file → Executable file
View File

View File

@ -64,20 +64,29 @@ object JMSCommand : CompositeCommand(
}
}
@SubCommand("cape")
@Description("获取玩家披风文件")
suspend fun CommandSender.getCape(username: String) {
try {
sendImage(MinecraftPlayer(username).cape)
} catch (e: Throwable) {
JMinecraftSkin.logger.error("获取玩家披风文件失败", e)
e.message?.let { sendMessage(it) }
}
}
// @SubCommand("cape")
// @Description("获取玩家披风文件")
// suspend fun CommandSender.getCape(username: String) {
// try {
// sendImage(MinecraftPlayer(username).cape)
// } catch (e: Throwable) {
// JMinecraftSkin.logger.error("获取玩家披风文件失败", e)
// e.message?.let { sendMessage(it) }
// }
// }
private suspend fun CommandSender.sendImage(data: ByteArray) {
data.toExternalResource().use {
subject?.sendImage(it)
try {
if (data.isEmpty()) {
subject?.sendMessage("未查询到数据")
return
}
data.toExternalResource().use {
subject?.sendImage(it)
}
} catch (e: Throwable) {
subject?.sendMessage(String(data))
}
}
}

View File

@ -9,7 +9,7 @@ object JMinecraftSkin : KotlinPlugin(
JvmPluginDescription(
id = "top.jie65535.mirai-console-jms-plugin",
name = "J Minecraft Skin",
version = "0.1.0",
version = "1.2.0",
) {
author("jie65535")
info("MC皮肤查询插件")
@ -19,7 +19,7 @@ object JMinecraftSkin : KotlinPlugin(
override fun onEnable() {
JMSPluginData.reload()
JMSCommand.register()
logger.info { "Plugin loaded" }
logger.info { "Plugin loaded. https://github.com/jie65535/mirai-console-jms-plugin" }
}
override fun onDisable() {

View File

@ -35,5 +35,5 @@ class MinecraftPlayer(username: String) {
/**
* 披风文件
*/
val cape get() = MinecraftSkinService.getCapes(uuid)
// val cape get() = MinecraftSkinService.getCapes(uuid)
}

View File

@ -11,29 +11,33 @@ object MinecraftSkinService {
* 获取头像
*/
fun getAvatars(uuid: String)
= HttpUtil.get("https://crafatar.com/avatars/$uuid")
// = HttpUtil.get("https://crafatar.com/avatars/$uuid?overlay")
= HttpUtil.get("https://nmsr.nickac.dev/face/$uuid")
/**
* 获取玩家头模型渲染图
*/
fun getHeadRenders(uuid: String)
= HttpUtil.get("https://crafatar.com/renders/head/$uuid")
// = HttpUtil.get("https://crafatar.com/renders/head/$uuid?overlay")
= HttpUtil.get("https://nmsr.nickac.dev/head/$uuid")
/**
* 获取玩家皮肤模型渲染图
*/
fun getBodyRenders(uuid: String)
= HttpUtil.get("https://crafatar.com/renders/body/$uuid")
// = HttpUtil.get("https://crafatar.com/renders/body/$uuid?overlay")
= HttpUtil.get("https://nmsr.nickac.dev/fullbody/$uuid")
/**
* 获取玩家皮肤源文件
*/
fun getSkins(uuid: String)
= HttpUtil.get("https://crafatar.com/skin/$uuid")
// = HttpUtil.get("https://crafatar.com/skins/$uuid")
= HttpUtil.get("https://nmsr.nickac.dev/skin/$uuid")
/**
* 获取玩家皮肤源文件
*/
fun getCapes(uuid: String)
= HttpUtil.get("https://crafatar.com/capes/$uuid")
}
// /**
// * 获取玩家皮肤源文件
// */
// fun getCapes(uuid: String)
// = HttpUtil.get("https://crafatar.com/capes/$uuid")
}

View File

@ -1,12 +1,7 @@
package top.jie65535
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.jsonPrimitive
import net.mamoe.mirai.console.util.cast
import kotlinx.serialization.json.*
/**
* Minecraft UUID Service
@ -18,21 +13,54 @@ object MinecraftUuidService {
/**
* 根据游戏角色名获取UUID
*/
@OptIn(ExperimentalSerializationApi::class)
fun getUuid(username: String) : String {
if (!checkUsername(username)) {
throw IllegalArgumentException("用户名格式不正确")
}
var uuid = JMSPluginData.idMap[username]
if (uuid != null) {
return uuid
}
val retJson = HttpUtil.get("https://tenapi.cn/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)
if (response["code"]!!.jsonPrimitive.content == "200") {
// if (response["code"]!!.jsonPrimitive.content == "200") {
// val elem = response["data"]!!.jsonObject["id"]!!.jsonPrimitive
// if (elem == JsonNull) throw Exception("Player UUID Not Found!")
// uuid = elem.content
// } else {
// 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(response["msg"]!!.jsonPrimitive.content)
throw Exception("未知错误")
}
JMSPluginData.idMap[username] = 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
}
}
}