-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add xdb buffer mode use zh_CN config file update README.md
- Loading branch information
Showing
10 changed files
with
90 additions
and
90 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/indi/nightfish/potato_ip_display/parser/IpParse.kt
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
70 changes: 43 additions & 27 deletions
70
src/main/kotlin/indi/nightfish/potato_ip_display/parser/provider/Ip2regionParser.kt
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,64 +1,80 @@ | ||
package indi.nightfish.potato_ip_display.parser.provider | ||
|
||
import indi.nightfish.potato_ip_display.PotatoIpDisplay | ||
import indi.nightfish.potato_ip_display.parser.IpParse | ||
import org.bukkit.Bukkit | ||
import org.lionsoul.ip2region.xdb.Searcher | ||
|
||
|
||
class Ip2regionParser(private val ip: String) : IpParse { | ||
private val dbPath: String = "plugins/PotatoIpDisplay/ip2region.xdb" | ||
private val unknown: String = "未知" | ||
private val plugin = Bukkit.getPluginManager().getPlugin("PotatoIpDisplay") as PotatoIpDisplay | ||
private val xdbBuffer = plugin.conf.options.xdbBuffer | ||
|
||
private val dbFile: String = "plugins/PotatoIpDisplay/ip2region.xdb" | ||
|
||
private val searcher: Searcher by lazy { | ||
Searcher.newWithFileOnly(dbFile) | ||
private val searcher: Searcher = when (xdbBuffer) { | ||
"none" -> { | ||
Searcher.newWithFileOnly(dbPath) | ||
} | ||
"vindex" -> { | ||
val vIndex: ByteArray = Searcher.loadVectorIndexFromFile(dbPath) | ||
Searcher.newWithVectorIndex(dbPath, vIndex) | ||
} | ||
"cbuff" -> { | ||
val cBuff: ByteArray = Searcher.loadContentFromFile(dbPath) | ||
Searcher.newWithBuffer(cBuff) | ||
} | ||
else -> { | ||
throw IllegalArgumentException("Invalid xdbBuffer in config >> $xdbBuffer") | ||
} | ||
} | ||
|
||
|
||
/* Structure of the information returned: | ||
INDEX: | 0 | 1 | 2 | 3 | 4 | | ||
| COUNTRY | ? | PROVINCE | CITY | ISP | | ||
IP1 | 中国 | 0 | 上海 | 上海市 | 联通 | | ||
IP2 | 美国 | 0 | 加利福尼亚 | 0 | 0 | | ||
IP3 | 0 | 0 | 0 | 内网IP | 内网IP | | ||
INDEX: | 0 | 1 | 2 | 3 | 4 | | ||
| COUNTRY | REGION | PROVINCE | CITY | ISP | | ||
IP1 | 中国 | 0 | 上海 | 上海市 | 联通 | | ||
IP2 | 美国 | 0 | 加利福尼亚 | 0 | 0 | | ||
IP3 | 0 | 0 | 0 | 内网IP | 内网IP | | ||
*/ | ||
|
||
override fun getDistrict(): String { | ||
return "null" | ||
override fun getRegion(): String { | ||
// ip2region doesn't seem to be able to return region information | ||
val region = try { | ||
searcher.search(ip).split("|")[1] | ||
} catch (e: Exception) { "" } | ||
return if (region == "0") unknown else region | ||
} | ||
|
||
override fun getCountry(): String { | ||
val country = try { | ||
searcher.search(ip).split("|")[0] | ||
} catch (e: Exception) { | ||
"" | ||
} | ||
// If null replace with getCity() | ||
return if (country == "0") getCity() else country | ||
} catch (e: Exception) { "" } | ||
return if (country == "0") unknown else country | ||
} | ||
|
||
override fun getProvince(): String { | ||
val province = try { | ||
searcher.search(ip).split("|")[2].replace("省", "") | ||
} catch (e: Exception) { | ||
"" | ||
} | ||
} catch (e: Exception) { "" } | ||
// If null replace with getCountry() | ||
return if (province == "0") getCountry() else province | ||
return if (province == "0") unknown else province | ||
} | ||
|
||
|
||
override fun getCity(): String { | ||
return try { | ||
val city = try { | ||
searcher.search(ip).split("|")[3].replace("市", "") | ||
} catch (e: Exception) { | ||
"" | ||
} | ||
} catch (e: Exception) { "" } | ||
return if (city == "0") unknown else city | ||
} | ||
|
||
override fun getISP(): String { | ||
return try { | ||
val isp = try { | ||
searcher.search(ip).split("|")[4] | ||
} catch (e: Exception) { | ||
"" | ||
} | ||
} catch (e: Exception) { "" } | ||
return if (isp == "0") unknown else isp | ||
} | ||
} |
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
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,35 +1,42 @@ | ||
# Configurations for PotatoIpDisplay-bukkit, | ||
# A Plugin for Checking Player Ip Attributions. | ||
# Learn more at [https://github.com/dmzz-yyhyy/PotatoIpDisplay] | ||
# PotatoIpDisplay-bukkit 配置文件 | ||
# 一款用于显示玩家 IP 归属地的 Minecraft 插件 | ||
# 详情:[https://github.com/dmzz-yyhyy/PotatoIpDisplay] | ||
|
||
# DO NOT TOUCH THIS! | ||
# 请勿修改! | ||
config-version: 1 | ||
|
||
# General options | ||
# 常规设置 | ||
options: | ||
# Working API: "pconline"(remote) or "ip2region"(local) | ||
# "ip2region" depends on ip2region.xdb in the plugin directory to work. | ||
# Get it from [https://github.com/lionsoul2014/ip2region/tree/master/data] | ||
# 查询模式: "pconline"(在线 API)或 "ip2region"(本地) | ||
# "ip2region" 模式为本地查询,插件会自动保存内置的文件至对应路径。 | ||
# 也可以从 [https://github.com/lionsoul2014/ip2region/tree/master/data] 下载 | ||
mode: "ip2region" | ||
# Allow bStats analytics | ||
# 缓存模式:只有模式设置为 ip2region 时生效,用于加速查询。 | ||
# "none": 完全基于文件,不进行缓存。 | ||
# "vindex": 额外占用固定的 512 KB 内存,缓存 VectorIndex 数据。 | ||
# "cbuff": 额外占用文件大小的内存,缓存整个 ip2region.xdb。 | ||
xdb-buffer: "vindex" | ||
# 开启 bStats 统计 | ||
allow-bstats: true | ||
|
||
# 消息设置 | ||
messages: | ||
# Messages sent by players. Use plugin to format | ||
player-chat: | ||
# Whether to listen for, and take over player chat messages | ||
enabled: true | ||
# 是否接管玩家消息事件。 | ||
# 与其他消息格式化插件冲突。 | ||
enabled: false | ||
# 消息格式 | ||
string: "§7[§b%ipAttr%§7] §f%playerName% §7>> §f%msg%" | ||
|
||
# Send a message to the player after logging in | ||
player-login: | ||
# Send a message after player login | ||
# 是否在玩家登录后发送一条消息显示 IP 归属地。 | ||
enabled: true | ||
# 消息格式 | ||
string: "§7[§6PotatoIpDisplay§7] §e您当前IP归属地 §7[§b%ipAttr%§7]" | ||
|
||
# Placeholder API options | ||
# Placeholder API 设置 | ||
papi: | ||
# Enable PAPI support. | ||
# 启用 PAPI 支持。需要安装 Placeholder API。 | ||
enabled: false | ||
# Available placeholders: | ||
# [https://github.com/dmzz-yyhyy/PotatoIpDisplay#placeholder-api] | ||
# 可用变量: | ||
# [https://github.com/dmzz-yyhyy/PotatoIpDisplay#placeholder-api] |