Skip to content

Commit

Permalink
#3 将ip解析放入线程
Browse files Browse the repository at this point in the history
  • Loading branch information
dmzz-yyhyy committed Apr 3, 2024
1 parent e53f893 commit 0b85028
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package indi.nightfish.potato_ip_display.listener

import indi.nightfish.potato_ip_display.util.IpAttributeMap
import indi.nightfish.potato_ip_display.PotatoIpDisplay
import indi.nightfish.potato_ip_display.parser.IpParseFactory
import indi.nightfish.potato_ip_display.util.IpAttributeMap
import org.bukkit.Bukkit
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerJoinEvent
import org.bukkit.event.player.PlayerLoginEvent
import org.bukkit.scheduler.BukkitRunnable


class PlayerJoinListener : Listener {
Expand All @@ -16,20 +17,25 @@ class PlayerJoinListener : Listener {

@EventHandler
fun onPlayerLogin(event: PlayerLoginEvent) {
val playerAddress = event.realAddress.hostAddress
val playerName = event.player.name
val ipParse = IpParseFactory.getIpParse(playerAddress)
var result = ipParse.getProvince()

if (result == "未知" || result == "") {
result = ipParse.getCity()
if (result == "未知" || result == "") {
result = ipParse.getCountry()
}
}

IpAttributeMap.playerIpAttributeMap[playerName] = result
plugin.log("Player named $playerName connect to proxy from ${ipParse.getProvince()}${ipParse.getCity()} ${ipParse.getISP()}")
object : BukkitRunnable() {
override fun run() {
val playerAddress = event.realAddress.hostAddress
val playerName = event.player.name
val ipParse = IpParseFactory.getIpParse(playerAddress)
var result = ipParse.getProvince()

if (result == "未知" || result == "") {
result = ipParse.getCity()
if (result == "未知" || result == "") {
result = ipParse.getCountry()
}
}

IpAttributeMap.playerIpAttributeMap[playerName] = result
plugin.log("Player named $playerName connect to proxy from ${ipParse.getProvince()}${ipParse.getCity()} ${ipParse.getISP()}")
}
}.run()
}

@EventHandler
Expand Down

0 comments on commit 0b85028

Please sign in to comment.