Skip to content

Commit

Permalink
显示玩家加入服务器使用的地址, 支持限定玩家加入服务器使用的地址
Browse files Browse the repository at this point in the history
  • Loading branch information
ApliNi committed Apr 23, 2024
1 parent aa9a6f1 commit 94af633
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/main/java/aplini/ipacwhitelist/listener/onPlayerLogin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -67,6 +68,15 @@ public void onPlayerLoginEvent(PlayerLoginEvent event) {
}
}

// 限定玩家只能通过以下地址加入服务器
String playerAddressHost = Objects.requireNonNull(player.getAddress()).getHostString();
plugin.getLogger().info("玩家 %s 通过地址 %s 连接服务器".formatted(playerName, playerAddressHost));
if(config.getBoolean("whitelist.addressConfig.enable", false)){
if(!config.getStringList("whitelist.addressConfig.list").contains(playerAddressHost)){
event.disallow(KICK_OTHER, msg(config.getString("whitelist.addressConfig.kickMsg", ""), playerUUID, playerName));
}
}

// 玩家名称字符检查
if(!Pattern.matches(config.getString("whitelist.playerNameRule", ".*"), playerName)){
event.disallow(KICK_OTHER, msg(config.getString("whitelist.playerNameRuleMsg", ""), playerUUID, playerName));
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ whitelist:
# - '^fe80::1234:.+$' # IPv6 没有方括号
ipBlacklistMsg: '§6IpacEL §f> §b您已被列入黑名单: §a%playerName%' # var: %ip%

# 限定玩家只能通过以下地址加入服务器
addressConfig:
enable: false
list: [ ]
kickMsg: '§6IpacEL §f> §b此地址不可用'

# 玩家名称字符检查
# 名称长度为 3 到 16 字符, 允许包含 Geyser 的 "." 前缀
playerNameRule: '^(?:\.?[a-zA-Z0-9_]{3,16})$'
Expand Down

0 comments on commit 94af633

Please sign in to comment.