-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82efccf
commit 78a1b90
Showing
2 changed files
with
83 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
group=online.bingiz.bilibili.video | ||
version=1.0.9-1 | ||
version=1.0.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,21 +39,21 @@ import taboolib.module.nms.NMSMap | |
*/ | ||
object NetworkEngine { | ||
private val client = OkHttpClient.Builder() | ||
.addInterceptor(ReceivedCookiesInterceptor()) | ||
.addInterceptor(UserAgentInterceptor("MinecraftPlugin $pluginId/$pluginVersion([email protected])")) | ||
.build() | ||
.addInterceptor(ReceivedCookiesInterceptor()) | ||
.addInterceptor(UserAgentInterceptor("MinecraftPlugin $pluginId/$pluginVersion([email protected])")) | ||
.build() | ||
|
||
/** | ||
* Bilibili API | ||
* 哔哩哔哩API驱动 | ||
*/ | ||
private val bilibiliAPI by lazy { | ||
Retrofit.Builder() | ||
.baseUrl("https://api.bilibili.com/x/") | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.client(client) | ||
.build() | ||
.create(BilibiliApiDrive::class.java) | ||
.baseUrl("https://api.bilibili.com/x/") | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.client(client) | ||
.build() | ||
.create(BilibiliApiDrive::class.java) | ||
} | ||
|
||
/** | ||
|
@@ -62,11 +62,11 @@ object NetworkEngine { | |
*/ | ||
private val bilibiliPassportAPI by lazy { | ||
Retrofit.Builder() | ||
.baseUrl("https://passport.bilibili.com/x/") | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.client(client) | ||
.build() | ||
.create(BilibiliPassportDrive::class.java) | ||
.baseUrl("https://passport.bilibili.com/x/") | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.client(client) | ||
.build() | ||
.create(BilibiliPassportDrive::class.java) | ||
} | ||
|
||
/** | ||
|
@@ -75,11 +75,11 @@ object NetworkEngine { | |
*/ | ||
private val bilibiliWebsiteAPI by lazy { | ||
Retrofit.Builder() | ||
.baseUrl("https://www.bilibili.com/") | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.client(client) | ||
.build() | ||
.create(BilibiliPassportDrive::class.java) | ||
.baseUrl("https://www.bilibili.com/") | ||
.addConverterFactory(GsonConverterFactory.create()) | ||
.client(client) | ||
.build() | ||
.create(BilibiliPassportDrive::class.java) | ||
} | ||
|
||
/** | ||
|
@@ -90,8 +90,8 @@ object NetworkEngine { | |
fun generateBilibiliQRCodeUrl(player: Player) { | ||
bilibiliPassportAPI.applyQRCodeGenerate().enqueue(object : Callback<BilibiliResult<QRCodeGenerateData>> { | ||
override fun onResponse( | ||
call: Call<BilibiliResult<QRCodeGenerateData>>, | ||
response: Response<BilibiliResult<QRCodeGenerateData>> | ||
call: Call<BilibiliResult<QRCodeGenerateData>>, | ||
response: Response<BilibiliResult<QRCodeGenerateData>> | ||
) { | ||
if (response.isSuccessful) { | ||
val body = response.body() | ||
|
@@ -102,10 +102,10 @@ object NetworkEngine { | |
shiny() | ||
lore.clear() | ||
lore.addAll( | ||
listOf( | ||
"&7请使用Bilibili客户端扫描二维码", | ||
"&7二维码有效期为3分钟", | ||
).colored() | ||
listOf( | ||
"&7请使用Bilibili客户端扫描二维码", | ||
"&7二维码有效期为3分钟", | ||
).colored() | ||
) | ||
} | ||
// 每隔1s检查一次玩家是否扫码 | ||
|
@@ -128,7 +128,7 @@ object NetworkEngine { | |
cookieCache.put(player.uniqueId, it) | ||
player.getDataContainer()["mid"] = mid | ||
player.getDataContainer()["refresh_token"] = | ||
result.data.refreshToken | ||
result.data.refreshToken | ||
player.getDataContainer()["timestamp"] = result.data.timestamp | ||
player.infoAsLang("GenerateUseCookieSuccess") | ||
} | ||
|
@@ -151,8 +151,8 @@ object NetworkEngine { | |
} | ||
} else { | ||
player.infoAsLang( | ||
"GenerateUseCookieFailure", | ||
response.body()?.message ?: "Bilibili未提供任何错误信息" | ||
"GenerateUseCookieFailure", | ||
response.body()?.message ?: "Bilibili未提供任何错误信息" | ||
) | ||
} | ||
} else { | ||
|
@@ -181,70 +181,74 @@ object NetworkEngine { | |
} | ||
} | ||
val csrf = cookieCache[player.uniqueId]?.first { it.startsWith("bili_jct") } | ||
?.replace("bili_jct=", "") | ||
?.split(";") | ||
?.get(0) | ||
?.replace("bili_jct=", "") | ||
?.split(";") | ||
?.get(0) | ||
val sessData = | ||
(cookieCache[player.uniqueId]?.first { it.startsWith("SESSDATA") } + ",buvid3").replace(",", "%2C") | ||
cookieCache[player.uniqueId]?.let { list -> | ||
list.first { it.startsWith("SESSDATA") }.let { | ||
it.substring(0, it.length).split(";")[0] + ",buvid3;" | ||
} | ||
} ?: return | ||
if (csrf != null) { | ||
bilibiliAPI.actionLikeTriple(bvid, csrf, sessData) | ||
.enqueue(object : Callback<BilibiliResult<TripleData>> { | ||
override fun onResponse( | ||
call: Call<BilibiliResult<TripleData>>, | ||
response: Response<BilibiliResult<TripleData>> | ||
) { | ||
if (response.isSuccessful) { | ||
val body = response.body() | ||
if (body != null) { | ||
when (body.code) { | ||
0 -> { | ||
val tripleData = body.data | ||
if (tripleData.coin && tripleData.fav && tripleData.like) { | ||
player.getDataContainer()[bvid] = true | ||
bvCache.put(player.uniqueId to bvid, true) | ||
TripleSendRewardsEvent(player, bvid).call() | ||
} else { | ||
player.infoAsLang( | ||
"GetTripleStatusFailure", | ||
tripleData.like, | ||
tripleData.coin, | ||
tripleData.multiply, | ||
tripleData.fav | ||
) | ||
} | ||
} | ||
|
||
-101 -> { | ||
player.infoAsLang("GetTripleStatusCookieInvalid") | ||
} | ||
|
||
10003 -> { | ||
player.infoAsLang("GetTripleStatusTargetFailed") | ||
} | ||
|
||
else -> { | ||
.enqueue(object : Callback<BilibiliResult<TripleData>> { | ||
override fun onResponse( | ||
call: Call<BilibiliResult<TripleData>>, | ||
response: Response<BilibiliResult<TripleData>> | ||
) { | ||
if (response.isSuccessful) { | ||
val body = response.body() | ||
if (body != null) { | ||
when (body.code) { | ||
0 -> { | ||
val tripleData = body.data | ||
if (tripleData.coin && tripleData.fav && tripleData.like) { | ||
player.getDataContainer()[bvid] = true | ||
bvCache.put(player.uniqueId to bvid, true) | ||
TripleSendRewardsEvent(player, bvid).call() | ||
} else { | ||
player.infoAsLang( | ||
"GetTripleStatusError", | ||
response.body()?.message ?: "Bilibili未提供任何错误信息" | ||
"GetTripleStatusFailure", | ||
tripleData.like, | ||
tripleData.coin, | ||
tripleData.multiply, | ||
tripleData.fav | ||
) | ||
} | ||
} | ||
} else { | ||
player.infoAsLang( | ||
"GetTripleStatusRefuse", | ||
|
||
-101 -> { | ||
player.infoAsLang("GetTripleStatusCookieInvalid") | ||
} | ||
|
||
10003 -> { | ||
player.infoAsLang("GetTripleStatusTargetFailed") | ||
} | ||
|
||
else -> { | ||
player.infoAsLang( | ||
"GetTripleStatusError", | ||
response.body()?.message ?: "Bilibili未提供任何错误信息" | ||
) | ||
) | ||
} | ||
} | ||
} else { | ||
warning("请求失败") | ||
warning("失败原因:${response.code()}") | ||
player.infoAsLang( | ||
"GetTripleStatusRefuse", | ||
response.body()?.message ?: "Bilibili未提供任何错误信息" | ||
) | ||
} | ||
} else { | ||
warning("请求失败") | ||
warning("失败原因:${response.code()}") | ||
} | ||
} | ||
|
||
override fun onFailure(call: Call<BilibiliResult<TripleData>>, t: Throwable) { | ||
player.infoAsLang("NetworkRequestFailure", t.message ?: "Bilibili未提供任何错误信息。") | ||
} | ||
}) | ||
override fun onFailure(call: Call<BilibiliResult<TripleData>>, t: Throwable) { | ||
player.infoAsLang("NetworkRequestFailure", t.message ?: "Bilibili未提供任何错误信息。") | ||
} | ||
}) | ||
} | ||
} | ||
|
||
|