Skip to content

Commit

Permalink
修复检查更新卡主线程问题,优化检查更新逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
Ling556 committed Aug 29, 2021
1 parent 4330705 commit 5f43a82
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/main/kotlin/me/arasple/mc/trhologram/module/service/Updater.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.arasple.mc.trhologram.module.service

import org.bukkit.event.player.PlayerJoinEvent
import taboolib.common.platform.Schedule
import taboolib.common.platform.event.EventPriority
import taboolib.common.platform.event.SubscribeEvent
import taboolib.common.platform.function.console
Expand All @@ -13,6 +14,7 @@ import java.io.InputStreamReader
import java.net.HttpURLConnection
import java.net.URL
import java.nio.charset.StandardCharsets
import java.util.*

/**
* @author Arasple
Expand All @@ -21,17 +23,23 @@ import java.nio.charset.StandardCharsets
object Updater {

private val url = URL("https://github.com/Micalhl/TrHologram/raw/master/Version.txt")
private var LATEST_VERSION: String? = ""
private var NOTIFIED = false
private val NOTIFIED_PLAYER = mutableSetOf<UUID>()

fun init() {
submit(delay = 20, period = (10 * 60 * 20), async = true) {
grabInfo()
}
}

@Schedule(true, 20, 20 * 60 * 10)
private fun grabInfo() {
val latest = getLatestVersion()
if (latest != null && latest != pluginVersion) {
console().sendLang("Plugin-Update", latest)
LATEST_VERSION = getLatestVersion().also {
if (it != null && !NOTIFIED && it != pluginVersion) {
console().sendLang("Plugin-Update", it)
NOTIFIED = true
}
}
}

Expand Down Expand Up @@ -59,9 +67,11 @@ object Updater {

@SubscribeEvent(EventPriority.HIGHEST)
fun e(e: PlayerJoinEvent) {
val latest = getLatestVersion()
if (latest != null && latest != pluginVersion && e.player.isOp) {
e.player.sendLang("Plugin-Update", latest)
LATEST_VERSION?.let {
if (e.player.isOp && LATEST_VERSION != pluginVersion && !NOTIFIED_PLAYER.contains(e.player.uniqueId)) {
e.player.sendLang("Plugin-Update", it)
NOTIFIED_PLAYER.add(e.player.uniqueId)
}
}
}

Expand Down

0 comments on commit 5f43a82

Please sign in to comment.