修复邮箱黑白名单不生效+email复读机bug:loadMap支持多行值(裸行续行),email命令添加args长度检查,移除重复email处理器死代码
This commit is contained in:
@@ -280,9 +280,27 @@ public class ConfigManager {
|
||||
} else {
|
||||
L.add("邮箱验证模式=默认");
|
||||
}
|
||||
// 保存邮箱后缀列表
|
||||
if (smtpSettings.containsKey("邮箱后缀列表")) {
|
||||
L.add("邮箱后缀列表=" + smtpSettings.get("邮箱后缀列表"));
|
||||
// 保存邮箱后缀列表(支持多行格式:每行一个后缀)
|
||||
L.add("# 邮箱后缀列表(每行一个,不含@)");
|
||||
String suffixVal = smtpSettings.getOrDefault("邮箱后缀列表", "");
|
||||
if (suffixVal != null && !suffixVal.trim().isEmpty()) {
|
||||
// 用逗号或换行分割,每行保存一个
|
||||
String[] parts = suffixVal.split("[,\\n]+");
|
||||
boolean firstSuffix = true;
|
||||
for (String s : parts) {
|
||||
String trimmed = s.trim();
|
||||
if (!trimmed.isEmpty()) {
|
||||
if (firstSuffix) {
|
||||
L.add("邮箱后缀列表=" + trimmed);
|
||||
firstSuffix = false;
|
||||
} else {
|
||||
L.add(trimmed);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (firstSuffix) {
|
||||
L.add("邮箱后缀列表=");
|
||||
}
|
||||
} else {
|
||||
L.add("邮箱后缀列表=");
|
||||
}
|
||||
@@ -638,6 +656,7 @@ public class ConfigManager {
|
||||
try (BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) {
|
||||
String line;
|
||||
boolean firstLine = true;
|
||||
String lastKey = null; // 跟踪上一个key,用于续行
|
||||
while ((line = r.readLine()) != null) {
|
||||
// 处理UTF-8 BOM头
|
||||
if (firstLine) {
|
||||
@@ -647,9 +666,25 @@ public class ConfigManager {
|
||||
}
|
||||
}
|
||||
line = line.trim();
|
||||
if (line.isEmpty() || line.startsWith("#")) continue;
|
||||
if (line.isEmpty() || line.startsWith("#")) {
|
||||
lastKey = null; // 空行/注释行中断续行
|
||||
continue;
|
||||
}
|
||||
int eq = line.indexOf('=');
|
||||
if (eq > 0) map.put(line.substring(0, eq).trim(), line.substring(eq + 1).trim());
|
||||
if (eq > 0) {
|
||||
// key=value 标准行
|
||||
String key = line.substring(0, eq).trim();
|
||||
String val = line.substring(eq + 1).trim();
|
||||
map.put(key, val);
|
||||
lastKey = key; // 记录key,后续裸行可续行
|
||||
} else if (lastKey != null && !map.getOrDefault(lastKey, "").isEmpty()) {
|
||||
// 裸行 + 上一个key有值 → 续行,用\n连接
|
||||
String existing = map.get(lastKey);
|
||||
map.put(lastKey, existing + "\n" + line);
|
||||
} else if (lastKey != null) {
|
||||
// 裸行 + 上一个key值为空 → 直接赋值
|
||||
map.put(lastKey, line);
|
||||
}
|
||||
}
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
|
||||
@@ -6695,24 +6695,28 @@ public class Main extends JavaPlugin
|
||||
|
||||
// ===== email =====
|
||||
if (sub.equals("email")) {
|
||||
// email reload —— 控制台/玩家均可执行,仅需isAdmin
|
||||
if (args.length >= 2
|
||||
&& args[1].equalsIgnoreCase("reload")) {
|
||||
if (!isAdmin(sender)) {
|
||||
sender.sendMessage("§c权限不足,仅管理员可用");
|
||||
return true;
|
||||
}
|
||||
config.reloadSmtp();
|
||||
sender.sendMessage("§a邮件配置已重载");
|
||||
sender.sendMessage("§7SMTP地址: "
|
||||
+ config.getSmtp("smtp地址"));
|
||||
sender.sendMessage("§7验证模式: "
|
||||
+ config.getEmailValidationMode());
|
||||
return true;
|
||||
}
|
||||
// 以下为玩家专属操作
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("§c仅玩家可用");
|
||||
return true;
|
||||
}
|
||||
Player p2 = (Player) sender;
|
||||
if (args.length >= 2) {
|
||||
// 检查是否为reload子命令(仅管理员可用)
|
||||
if (args[1].equalsIgnoreCase("reload")) {
|
||||
if (!p2.hasPermission("sdf1_login.admin")) {
|
||||
p2.sendMessage("§c权限不足,仅管理员可用");
|
||||
return true;
|
||||
}
|
||||
config.reloadSmtp();
|
||||
p2.sendMessage("§a邮件配置已重载");
|
||||
p2.sendMessage("§7SMTP地址: " + config.getSmtp("smtp地址"));
|
||||
p2.sendMessage("§7验证模式: " + config.getEmailValidationMode());
|
||||
return true;
|
||||
}
|
||||
String emailAddr = args[1];
|
||||
if (!emailAddr.contains("@")
|
||||
|| !emailAddr.contains(".")) {
|
||||
@@ -7011,90 +7015,6 @@ public class Main extends JavaPlugin
|
||||
return true;
|
||||
}
|
||||
|
||||
// email
|
||||
if (sub.equals("email")) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("§c仅玩家可用");
|
||||
return true;
|
||||
}
|
||||
Player p2 = (Player) sender;
|
||||
if (args.length >= 2) {
|
||||
String emailAddr = args[1];
|
||||
if (!emailAddr.contains("@")
|
||||
|| !emailAddr.contains(".")) {
|
||||
p2.sendMessage("§c邮箱格式不正确");
|
||||
return true;
|
||||
}
|
||||
// 邮箱后缀黑白名单校验
|
||||
if (!config.isEmailSuffixAllowed(emailAddr)) {
|
||||
String mode = config.getEmailValidationMode();
|
||||
if ("白名单".equals(mode)) {
|
||||
p2.sendMessage("§c该邮箱后缀不在允许列表中");
|
||||
} else if ("黑名单".equals(mode)) {
|
||||
p2.sendMessage("§c该邮箱后缀被禁止使用");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
String oldEmail = (String) db.getField(
|
||||
p2.getName(), "email");
|
||||
if (oldEmail != null
|
||||
&& !oldEmail.isEmpty()) {
|
||||
// 已绑定:先验证密码
|
||||
chatInput.getState(p2).type =
|
||||
ChatInputManager.InputType
|
||||
.SET_EMAIL_VERIFY;
|
||||
chatInput.getState(p2)
|
||||
.targetPlayer = emailAddr;
|
||||
chatInput.getState(p2)
|
||||
.ticketTitle = "need_pwd";
|
||||
p2.sendMessage("§e您已绑定邮箱: "
|
||||
+ oldEmail);
|
||||
p2.sendMessage(
|
||||
"§e请输入登录密码以确认修改:");
|
||||
} else {
|
||||
// 未绑定:直接发验证码
|
||||
String code = String.valueOf(
|
||||
(int) (Math.random()
|
||||
* 900000 + 100000));
|
||||
chatInput.getState(p2).type =
|
||||
ChatInputManager.InputType
|
||||
.SET_EMAIL_VERIFY;
|
||||
chatInput.getState(p2)
|
||||
.targetPlayer = emailAddr;
|
||||
chatInput.getState(p2)
|
||||
.ticketTitle = code;
|
||||
final String to = emailAddr;
|
||||
final String c = code;
|
||||
final Player fp = p2;
|
||||
Bukkit.getScheduler()
|
||||
.runTaskAsynchronously(this,
|
||||
() -> {
|
||||
boolean sent = email
|
||||
.sendVerifyCode(to, c);
|
||||
Bukkit.getScheduler().runTask(
|
||||
this, () -> {
|
||||
if (sent) {
|
||||
fp.sendMessage(
|
||||
"§a验证码已发送到 "
|
||||
+ to);
|
||||
fp.sendMessage(
|
||||
"§e输入6位验证码(0取消):");
|
||||
} else {
|
||||
fp.sendMessage(
|
||||
"§c发送失败");
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
} else {
|
||||
chatInput.getState(p2).type =
|
||||
ChatInputManager.InputType
|
||||
.SET_EMAIL;
|
||||
p2.sendMessage("§e请输入邮箱:");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// sign
|
||||
if (sub.equals("sign")) {
|
||||
|
||||
Reference in New Issue
Block a user