Skip to content

Commit

Permalink
修复已过期的白名单可登录为参观账户的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ApliNi committed Aug 13, 2023
1 parent d7485ac commit a167251
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/main/java/aplini/ipacwhitelist/IpacWhitelist.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,19 @@ public void onPlayerLogin(PlayerLoginEvent event) {
}
}

case EXPIRED -> { // 白名单已过期
getLogger().info("[IpacWhitelist] %s 白名单已过期".formatted(event.getPlayer().getName()));
event.setKickMessage(plugin.getConfig().getString("message.join.not", "").replace("%player%", event.getPlayer().getName()));
event.setResult(PlayerLoginEvent.Result.KICK_WHITELIST);
}

case BLACK -> { // 黑名单
getLogger().info("[IpacWhitelist] %s 在黑名单中".formatted(event.getPlayer().getName()));
event.setKickMessage(plugin.getConfig().getString("message.join.black", "").replace("%player%", event.getPlayer().getName()));
event.setResult(PlayerLoginEvent.Result.KICK_BANNED);
}

case VISIT_DEL_DATA -> { // 已删除数据的参观账户
case VISIT_DATA_DELETE -> { // 已删除数据的参观账户
Visit.onNewVisitPlayerLoginEvent(event);
}

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/aplini/ipacwhitelist/util/SQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static wlType setPlayerData(String name, String UUID, int Time, wlType Wh
// 输出账户类型
switch(results.getInt("Type")){
case 1 -> out = VISIT;
case 2 -> out = VISIT_DEL_DATA;
case 2 -> out = VISIT_DATA_DELETE;
default -> out = DEFAULT;
}
// 处理缺省值
Expand Down Expand Up @@ -193,7 +193,7 @@ public static wlType banPlayerUUID(String UUID){


// 是否在白名单中
// NOT = 不在, WHITE = 存在, ERROR = 出错, VISIT = 存在但是参观账号, VISIT_DEL_DATA = 已删除数据的参观账户
// NOT = 不在, EXPIRED = 过期, WHITE = 存在, ERROR = 出错, VISIT = 存在但是参观账号, VISIT_DEL_DATA = 已删除数据的参观账户
public static wlType isWhitelisted(Player player){
try {
PreparedStatement sql;
Expand All @@ -209,9 +209,9 @@ public static wlType isWhitelisted(Player player){
if(results.getLong("WHITE") == BLACK.getID()){return BLACK;}
// 是否为参观账户
if(results.getLong("Type") == VISIT.getID()){return VISIT;}
if(results.getLong("Type") == VISIT_DEL_DATA.getID()){return VISIT_DEL_DATA;}
if(results.getLong("Type") == VISIT_DATA_DELETE.getID()){return VISIT_DATA_DELETE;}
// 白名单上的玩家是否超时
if(Util.isWhitelistedTimeout(results.getLong("TIME"))){return NOT;}
if(Util.isWhitelistedTimeout(results.getLong("TIME"))){return EXPIRED;}

// 更新名称和最后加入时间
PreparedStatement update = connection.prepareStatement("UPDATE `player` SET `NAME` = ?, `TIME` = ? WHERE `ID` = ?;");
Expand All @@ -236,9 +236,9 @@ public static wlType isWhitelisted(Player player){
if(results.getLong("WHITE") == BLACK.getID()){return BLACK;}
// 是否为参观账户
if(results.getLong("Type") == VISIT.getID()){return VISIT;}
if(results.getLong("Type") == VISIT_DEL_DATA.getID()){return VISIT_DEL_DATA;}
if(results.getLong("Type") == VISIT_DATA_DELETE.getID()){return VISIT_DATA_DELETE;}
// 白名单上的玩家是否超时
if(Util.isWhitelistedTimeout(results.getLong("TIME"))){return NOT;}
if(Util.isWhitelistedTimeout(results.getLong("TIME"))){return EXPIRED;}

// 更新UUID/名称和最后加入时间
PreparedStatement update = connection.prepareStatement("UPDATE `player` SET `UUID` = ?, `NAME` = ?, `TIME` = ? WHERE `ID` = ?;");
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/aplini/ipacwhitelist/util/wlType.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public enum wlType {
// 数据表 Type -> ID
DEFAULT(0), // 默认, 正常的账户
VISIT(1), // 参观账户
VISIT_DEL_DATA(2), // 已删除数据的参观账户
VISIT_DATA_DELETE(2), // 已删除数据的参观账户

// 数据表 White
NOT_WHITE(0), // 不在白名单中
Expand All @@ -16,6 +16,7 @@ public enum wlType {

// 表示
NOT(0), // 不存在的
EXPIRED(0), // 白名单过期
ERROR(-5), // 出错
;

Expand Down

0 comments on commit a167251

Please sign in to comment.