修复签到功能任意参数均视为成功的问题,加入签到给经济功能
This commit is contained in:
@@ -37,6 +37,16 @@ public class ChatFilterManager {
|
||||
private boolean notifyAdmin = true;
|
||||
private boolean notifyAll = false;
|
||||
private int muteDuration = 300;
|
||||
private boolean enabled = true;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean v) {
|
||||
enabled = v;
|
||||
}
|
||||
|
||||
|
||||
private static final Pattern URL_PATTERN =
|
||||
Pattern.compile(
|
||||
@@ -106,6 +116,7 @@ public class ChatFilterManager {
|
||||
if (line.startsWith("\uFEFF"))
|
||||
line = line.substring(1);
|
||||
String t = line.trim();
|
||||
|
||||
if (t.isEmpty()
|
||||
|| t.startsWith("#"))
|
||||
continue;
|
||||
@@ -128,6 +139,12 @@ public class ChatFilterManager {
|
||||
String[] kv = t.split(":", 2);
|
||||
String k = kv[0].trim();
|
||||
String v = kv[1].trim();
|
||||
if (equals("启用过滤")
|
||||
|| equals("enabled")) {
|
||||
enabled = parseBool(v);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (k.equals("通知管理员")) {
|
||||
notifyAdmin = parseBool(v);
|
||||
continue;
|
||||
@@ -238,6 +255,7 @@ public class ChatFilterManager {
|
||||
new FileOutputStream(f),
|
||||
StandardCharsets.UTF_8))) {
|
||||
pw.println("# Sdf1_chat 聊天过滤配置");
|
||||
pw.println("启用过滤: " + enabled);
|
||||
pw.println("通知管理员: true");
|
||||
pw.println("全服通报: false");
|
||||
pw.println("禁言时长: 300");
|
||||
|
||||
@@ -36,7 +36,8 @@ public class ChatInputManager {
|
||||
TICKET_ADMIN_TYPE,
|
||||
TICKET_ADMIN_TITLE,
|
||||
TICKET_ADMIN_DESC,
|
||||
TICKET_ADMIN_PROVIDER
|
||||
TICKET_ADMIN_PROVIDER,
|
||||
BACK_CHECK_ECONOMY_CONFIRM,
|
||||
}
|
||||
|
||||
public static class PlayerState {
|
||||
@@ -63,6 +64,11 @@ public class ChatInputManager {
|
||||
public void reset(Player p) {
|
||||
states.remove(p.getName());
|
||||
}
|
||||
public boolean isInFlow(Player p) {
|
||||
PlayerState state = states.get(p.getName());
|
||||
return state != null
|
||||
&& state.type != InputType.NONE;
|
||||
}
|
||||
|
||||
public void handleInput(Player p, String msg,
|
||||
Main mainPlugin) {
|
||||
@@ -542,24 +548,33 @@ public class ChatInputManager {
|
||||
}
|
||||
|
||||
case BACK_CHECKIN: {
|
||||
int cost = 20;
|
||||
if (!mainPlugin.getDb()
|
||||
.deductPoints(
|
||||
p.getName(), cost)) {
|
||||
p.sendMessage(
|
||||
"§c积分不足,补签需 "
|
||||
+ cost + " 积分");
|
||||
reset(p);
|
||||
String result =
|
||||
mainPlugin.getCheckIn()
|
||||
.backCheckIn(p, msg);
|
||||
if (result == null) {
|
||||
// 等待选择(NEED_CONFIRM)
|
||||
return;
|
||||
}
|
||||
p.sendMessage(
|
||||
"§a补签成功!扣除 "
|
||||
+ cost + " 积分。"
|
||||
+ "日期: " + msg);
|
||||
if (result.startsWith(
|
||||
"NEED_CONFIRM:")) {
|
||||
String[] parts =
|
||||
result.split(":");
|
||||
// 存储到Main的Map
|
||||
mainPlugin.pendingBackCheck.put(
|
||||
p.getName(),
|
||||
parts[1] + ":" + parts[2]);
|
||||
return;
|
||||
}
|
||||
if (result.startsWith("§c")) {
|
||||
p.sendMessage(result);
|
||||
} else {
|
||||
p.sendMessage(result);
|
||||
}
|
||||
reset(p);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
case INVITE_INPUT_CODE: {
|
||||
String code = msg.trim();
|
||||
String myName = p.getName();
|
||||
|
||||
@@ -1,114 +1,286 @@
|
||||
package Sdf1_login;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class CheckInManager {
|
||||
|
||||
private final Main plugin;
|
||||
|
||||
public CheckInManager(Main plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public boolean isCheckedInToday(String name) {
|
||||
String last = (String) plugin.getDb()
|
||||
.getField(name, "last_checkin_date");
|
||||
String today = new SimpleDateFormat("yyyy-MM-dd")
|
||||
.format(new Date());
|
||||
return today.equals(last);
|
||||
}
|
||||
|
||||
public String checkIn(Player p) {
|
||||
String name = p.getName();
|
||||
if (isCheckedInToday(name)) {
|
||||
return plugin.getConfig2()
|
||||
.msg("checkin_already");
|
||||
}
|
||||
|
||||
Object streakObj = plugin.getDb()
|
||||
.getField(name, "checkin_streak");
|
||||
int streak = streakObj != null
|
||||
? ((Number) streakObj).intValue() : 0;
|
||||
|
||||
String lastDate = (String) plugin.getDb()
|
||||
.getField(name, "last_checkin_date");
|
||||
String today = new SimpleDateFormat("yyyy-MM-dd")
|
||||
.format(new Date());
|
||||
|
||||
if (lastDate != null && !lastDate.isEmpty()) {
|
||||
try {
|
||||
java.util.Date lastD = new SimpleDateFormat(
|
||||
"yyyy-MM-dd").parse(lastDate);
|
||||
java.util.Date todayD = new SimpleDateFormat(
|
||||
"yyyy-MM-dd").parse(today);
|
||||
long diff = todayD.getTime() - lastD.getTime();
|
||||
if (diff > 86400000L * 2) {
|
||||
streak = 0;
|
||||
} else if (diff > 86400000L) {
|
||||
streak++;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
if (streak == 0) streak = 1;
|
||||
else streak++;
|
||||
|
||||
double multi = 1.0;
|
||||
if (streak >= 21) multi = 1.5;
|
||||
else if (streak >= 14) multi = 1.3;
|
||||
else if (streak >= 7) multi = 1.1;
|
||||
|
||||
int points = (int) (1 * multi);
|
||||
plugin.getDb().addPoints(name, points);
|
||||
plugin.getDb().setField(
|
||||
name, "checkin_streak", streak);
|
||||
plugin.getDb().setField(
|
||||
name, "last_checkin_date", today);
|
||||
Object totalObj = plugin.getDb()
|
||||
.getField(name, "total_checkin_days");
|
||||
int total = totalObj != null
|
||||
? ((Number) totalObj).intValue() : 0;
|
||||
plugin.getDb().setField(
|
||||
name, "total_checkin_days", total + 1);
|
||||
|
||||
return plugin.getConfig2()
|
||||
.msg("checkin_success")
|
||||
.replace("{points}",
|
||||
String.valueOf(points))
|
||||
.replace("{streak}",
|
||||
String.valueOf(streak))
|
||||
.replace("{multi}",
|
||||
String.valueOf(multi));
|
||||
}
|
||||
|
||||
public String backCheckIn(Player p, String dateStr) {
|
||||
String name = p.getName();
|
||||
if (!plugin.getDb().deductPoints(name, 10)) {
|
||||
return plugin.getConfig2()
|
||||
.msg("checkin_already");
|
||||
}
|
||||
try {
|
||||
java.util.Date target = new SimpleDateFormat(
|
||||
"yyyy-MM-dd").parse(dateStr);
|
||||
java.util.Date now = new SimpleDateFormat(
|
||||
"yyyy-MM-dd").parse(
|
||||
new SimpleDateFormat("yyyy-MM-dd")
|
||||
.format(new Date()));
|
||||
long diff = now.getTime() - target.getTime();
|
||||
if (diff < 0 || diff > 3 * 86400000L) {
|
||||
plugin.getDb().addPoints(name, 10);
|
||||
return plugin.getConfig2()
|
||||
.msg("checkin_already");
|
||||
}
|
||||
plugin.getDb().addPoints(name, 1);
|
||||
return "§a补签成功!日期: " + dateStr;
|
||||
} catch (Exception e) {
|
||||
plugin.getDb().addPoints(name, 10);
|
||||
return "§c日期格式错误,请用 yyyy-MM-dd";
|
||||
}
|
||||
}
|
||||
}
|
||||
package Sdf1_login;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
public class CheckInManager {
|
||||
|
||||
private final Main plugin;
|
||||
|
||||
public CheckInManager(Main plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
// ===== 今日是否已签到 =====
|
||||
public boolean isCheckedInToday(
|
||||
String name) {
|
||||
String last = (String) plugin.getDb()
|
||||
.getField(name,
|
||||
"last_checkin_date");
|
||||
String today = new SimpleDateFormat(
|
||||
"yyyy-MM-dd")
|
||||
.format(new Date());
|
||||
return today.equals(last);
|
||||
}
|
||||
|
||||
// ===== 签到 =====
|
||||
public String checkIn(Player p) {
|
||||
String name = p.getName();
|
||||
if (isCheckedInToday(name)) {
|
||||
return plugin.getConfig2()
|
||||
.msg("checkin_already");
|
||||
}
|
||||
|
||||
Object streakObj = plugin.getDb()
|
||||
.getField(name,
|
||||
"checkin_streak");
|
||||
int streak = streakObj != null
|
||||
? ((Number) streakObj)
|
||||
.intValue() : 0;
|
||||
|
||||
String lastDate = (String) plugin
|
||||
.getDb().getField(name,
|
||||
"last_checkin_date");
|
||||
String today = new SimpleDateFormat(
|
||||
"yyyy-MM-dd")
|
||||
.format(new Date());
|
||||
|
||||
if (lastDate != null
|
||||
&& !lastDate.isEmpty()) {
|
||||
try {
|
||||
java.util.Date lastD =
|
||||
new SimpleDateFormat(
|
||||
"yyyy-MM-dd")
|
||||
.parse(lastDate);
|
||||
java.util.Date todayD =
|
||||
new SimpleDateFormat(
|
||||
"yyyy-MM-dd")
|
||||
.parse(today);
|
||||
long diff = todayD.getTime()
|
||||
- lastD.getTime();
|
||||
if (diff > 86400000L * 2) {
|
||||
streak = 0;
|
||||
} else if (diff
|
||||
> 86400000L) {
|
||||
streak++;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
if (streak == 0) streak = 1;
|
||||
else streak++;
|
||||
|
||||
double multi = 1.0;
|
||||
if (streak >= 21) multi = 1.5;
|
||||
else if (streak >= 14) multi = 1.3;
|
||||
else if (streak >= 7) multi = 1.1;
|
||||
|
||||
int basePoints = plugin.getConfig2()
|
||||
.checkinPoints;
|
||||
int points =
|
||||
(int) (basePoints * multi);
|
||||
|
||||
plugin.getDb().addPoints(
|
||||
name, points);
|
||||
plugin.getDb().setField(
|
||||
name, "checkin_streak",
|
||||
streak);
|
||||
plugin.getDb().setField(
|
||||
name,
|
||||
"last_checkin_date", today);
|
||||
|
||||
Object totalObj = plugin.getDb()
|
||||
.getField(name,
|
||||
"total_checkin_days");
|
||||
int total = totalObj != null
|
||||
? ((Number) totalObj)
|
||||
.intValue() : 0;
|
||||
plugin.getDb().setField(
|
||||
name,
|
||||
"total_checkin_days",
|
||||
total + 1);
|
||||
|
||||
return plugin.getConfig2()
|
||||
.msg("checkin_success")
|
||||
.replace("{points}",
|
||||
String.valueOf(points))
|
||||
.replace("{streak}",
|
||||
String.valueOf(streak))
|
||||
.replace("{multi}",
|
||||
String.valueOf(multi));
|
||||
}
|
||||
|
||||
// ===== 获取连续天数 =====
|
||||
public int getStreak(String name) {
|
||||
Object val = plugin.getDb()
|
||||
.getField(name,
|
||||
"checkin_streak");
|
||||
if (val instanceof Number) {
|
||||
return ((Number) val)
|
||||
.intValue();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ===== 补签入口 =====
|
||||
public String backCheckIn(
|
||||
Player p, String dateStr) {
|
||||
String name = p.getName();
|
||||
String normalized =
|
||||
normalizeDate(dateStr);
|
||||
|
||||
// 严格日期验证
|
||||
java.text.SimpleDateFormat sdf =
|
||||
new java.text.SimpleDateFormat(
|
||||
"yyyy-MM-dd");
|
||||
sdf.setLenient(false);
|
||||
java.util.Date target;
|
||||
try {
|
||||
target = sdf.parse(normalized);
|
||||
} catch (Exception ex) {
|
||||
return "§c无效日期: " + dateStr;
|
||||
}
|
||||
String reformat =
|
||||
sdf.format(target);
|
||||
if (!reformat.equals(normalized)) {
|
||||
return "§c无效日期: " + dateStr;
|
||||
}
|
||||
|
||||
String today = sdf.format(new Date());
|
||||
|
||||
if (normalized.compareTo(today) >= 0) {
|
||||
return "§c今天不需要补签";
|
||||
}
|
||||
|
||||
String threeDaysAgo = getPastDate(3);
|
||||
if (normalized.compareTo(
|
||||
threeDaysAgo) < 0) {
|
||||
return "§c只能补签3天内"
|
||||
+ "(最多到 "
|
||||
+ threeDaysAgo + ")";
|
||||
}
|
||||
|
||||
Object val = plugin.getDb()
|
||||
.getField(name,
|
||||
"backcheck_dates");
|
||||
String existing = val != null
|
||||
? val.toString() : "";
|
||||
boolean alreadyBacked = false;
|
||||
if (!existing.isEmpty()) {
|
||||
for (String d
|
||||
: existing.split(",")) {
|
||||
if (normalizeDate(d.trim())
|
||||
.equals(normalized)) {
|
||||
alreadyBacked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (alreadyBacked) {
|
||||
return "§c该日期已补签: "
|
||||
+ normalized;
|
||||
}
|
||||
|
||||
Object normalCheck =
|
||||
plugin.getDb().getField(
|
||||
name,
|
||||
"last_checkin_date");
|
||||
String lastCheckin = normalCheck
|
||||
!= null
|
||||
? normalCheck.toString()
|
||||
: "";
|
||||
if (lastCheckin.equals(normalized)) {
|
||||
return "§c该日期已签到: "
|
||||
+ normalized;
|
||||
}
|
||||
|
||||
if (!plugin.getDb()
|
||||
.deductPoints(name, 10)) {
|
||||
return "§c积分不足,补签需 10 积分";
|
||||
}
|
||||
|
||||
net.milkbowl.vault.economy
|
||||
.Economy econ =
|
||||
plugin.getEconomy();
|
||||
if (econ != null) {
|
||||
double bal = econ.getBalance(p);
|
||||
if (bal < 10.0) {
|
||||
plugin.getDb()
|
||||
.addPoints(name, 10);
|
||||
int mult = plugin.getConfig2()
|
||||
.backCheckPointMultiplier;
|
||||
int needed = 10 * mult;
|
||||
p.sendMessage("§e§l[补签] "
|
||||
+ "§f经济不足($"
|
||||
+ String.format(
|
||||
"%.2f", bal)
|
||||
+ " < $10)");
|
||||
p.sendMessage("§7是否用 §a§l"
|
||||
+ needed + "积分 "
|
||||
+ "§7代替 10经济?");
|
||||
p.sendMessage("§7输入 §a1 "
|
||||
+ "§7同意,"
|
||||
+ "§c其他 §7取消");
|
||||
return "NEED_CONFIRM:"
|
||||
+ normalized
|
||||
+ ":" + needed;
|
||||
}
|
||||
econ.withdrawPlayer(p, 10);
|
||||
}
|
||||
|
||||
doBackCheckIn(p, normalized);
|
||||
return "§a补签成功!日期: "
|
||||
+ normalized
|
||||
+ " §7(扣除10积分+10经济)";
|
||||
}
|
||||
|
||||
|
||||
// ===== 执行补签 =====
|
||||
public void doBackCheckIn(
|
||||
Player p, String dateStr) {
|
||||
String name = p.getName();
|
||||
Object val = plugin.getDb()
|
||||
.getField(name,
|
||||
"backcheck_dates");
|
||||
String existing = val != null
|
||||
? val.toString() : "";
|
||||
String updated = existing.isEmpty()
|
||||
? dateStr
|
||||
: existing + "," + dateStr;
|
||||
plugin.getDb().setField(name,
|
||||
"backcheck_dates", updated);
|
||||
int streak = getStreak(name);
|
||||
plugin.getDb().setField(name,
|
||||
"checkin_streak",
|
||||
streak + 1);
|
||||
}
|
||||
|
||||
// ===== 标准化日期 =====
|
||||
private String normalizeDate(
|
||||
String input) {
|
||||
String s = input.trim()
|
||||
.replace("/", "-");
|
||||
if (s.matches("\\d{8}")) {
|
||||
return s.substring(0, 4) + "-"
|
||||
+ s.substring(4, 6) + "-"
|
||||
+ s.substring(6, 8);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
// ===== 获取N天前日期 =====
|
||||
private String getPastDate(
|
||||
int daysAgo) {
|
||||
Calendar cal =
|
||||
Calendar.getInstance();
|
||||
cal.add(Calendar.DAY_OF_MONTH,
|
||||
-daysAgo);
|
||||
return new SimpleDateFormat(
|
||||
"yyyy-MM-dd")
|
||||
.format(cal.getTime());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,14 +4,15 @@ import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.*;
|
||||
|
||||
import static java.lang.Double.parseDouble;
|
||||
|
||||
public class ConfigManager {
|
||||
|
||||
private final File dataFolder;
|
||||
private final Map<String, String> messages = new LinkedHashMap<>();
|
||||
private final Map<String, String> smtpSettings = new LinkedHashMap<>();
|
||||
private final Map<String, String> messages =
|
||||
new LinkedHashMap<>();
|
||||
private final Map<String, String> smtpSettings =
|
||||
new LinkedHashMap<>();
|
||||
|
||||
// ===== 公共字段 =====
|
||||
public String adminTag = "admin";
|
||||
public String adminPassword = "qweasd";
|
||||
public int maxAccountsPerIP = 3;
|
||||
@@ -27,9 +28,26 @@ public class ConfigManager {
|
||||
public String smtpConfiguringPlayer = "";
|
||||
public String broadcastServerUrl = "";
|
||||
public int httpPort = 8080;
|
||||
public String garbageTag= "admin";
|
||||
public String garbageTag = "admin";
|
||||
|
||||
// 签到经济奖励
|
||||
public double checkinRewardFixed = 0;
|
||||
public double checkinRewardMin = 0;
|
||||
public double checkinRewardMax = 0;
|
||||
public boolean checkinGivePoints = true;
|
||||
public int checkinPoints = 10;
|
||||
public String checkinRewardType = "none";
|
||||
public int backCheckPointMultiplier = 5;
|
||||
// 提成/工单
|
||||
public double providerPointsPerScore = 2.0;
|
||||
public int baseEconomyReward = 100;
|
||||
public double providerEconomyPerScore = 50.0;
|
||||
public int requesterPointsReward = 10;
|
||||
|
||||
// 垃圾站
|
||||
public boolean garbageEnabled = true;
|
||||
public int garbageInterval = 300;
|
||||
public int garbageMaxRounds = 1;
|
||||
|
||||
public ConfigManager(File dataFolder) {
|
||||
this.dataFolder = dataFolder;
|
||||
@@ -39,232 +57,132 @@ public class ConfigManager {
|
||||
|
||||
public void loadMessages() {
|
||||
messages.clear();
|
||||
File file = new File(dataFolder, "消息.txt");
|
||||
if (!file.exists()) createDefaultMessages(file);
|
||||
File file =
|
||||
new File(dataFolder, "消息.txt");
|
||||
if (!file.exists())
|
||||
createDefaultMessages(file);
|
||||
loadMap(file, messages);
|
||||
}
|
||||
|
||||
public String msg(String key) {
|
||||
String val = messages.getOrDefault(key, key);
|
||||
String val =
|
||||
messages.getOrDefault(key, key);
|
||||
val = val.replace("<b>", "&l");
|
||||
val = val.replace("</b>", "&r");
|
||||
val = val.replace("<br>", "\n");
|
||||
val = val.replace("\\n", "\n");
|
||||
// &颜色码 转换为 §颜色码
|
||||
val = val.replaceAll(
|
||||
"&([0-9a-fk-orA-FK-OR])", "§$1");
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
private void createDefaultMessages(File f) {
|
||||
List<String> L = new ArrayList<>();
|
||||
L.add("# ==========================================");
|
||||
L.add("# Sdf1_login 消息配置文件");
|
||||
L.add("# ==========================================");
|
||||
L.add("# 颜色代码使用 § 符号");
|
||||
L.add("# §0黑色 §1深蓝 §2深绿 §3深青");
|
||||
L.add("# §4深红 §5深紫 §6金色 §7灰色");
|
||||
L.add("# §8深灰 §9蓝色 §a绿色 §b浅蓝");
|
||||
L.add("# §c红色 §d粉色 §e黄色 §f白色");
|
||||
L.add("# §l粗体 §n下划线 §o斜体 §r重置");
|
||||
L.add("#");
|
||||
L.add("# 占位符用 {xxx} 表示,运行时自动替换");
|
||||
L.add("# 支持 <b>粗体</b> 标签");
|
||||
L.add("# 支持 \\n 或 <br> 换行");
|
||||
L.add("# 修改后执行 /sdf1_login reload 重载");
|
||||
L.add("# ==========================================");
|
||||
L.add("# ===== Sdf1_login 消息配置 =====");
|
||||
L.add("# 占位符用 {xxx} 表示");
|
||||
L.add("# 修改后执行 /sdf1_login reload");
|
||||
L.add("");
|
||||
|
||||
// --- 登录/注册 ---
|
||||
L.add("# ---- 登录注册相关 ----");
|
||||
L.add("# login_timeout: 登录超时被踢出时的提示");
|
||||
L.add("# ---- 登录注册 ----");
|
||||
L.add("login_timeout=§c登录超时,请重新登录");
|
||||
L.add("# not_registered: 未注册玩家收到的提示");
|
||||
L.add("not_registered=§e您尚未注册,请使用 /reg <密码>");
|
||||
L.add("# not_logged_in: 已注册但未登录的提示");
|
||||
L.add("not_logged_in=§e您尚未登录,请使用 /login <密码>");
|
||||
L.add("# already_registered: 已注册玩家再次注册时的提示");
|
||||
L.add("already_registered=§c您已注册过账号");
|
||||
L.add("# already_logged_in: 已登录玩家再次登录时的提示");
|
||||
L.add("already_logged_in=§c您已登录");
|
||||
L.add("# reg_success: 注册成功提示");
|
||||
L.add("reg_success=§a注册成功!欢迎来到服务器");
|
||||
L.add("# login_success: 登录成功提示");
|
||||
L.add("login_success=§a登录成功!");
|
||||
L.add("# login_failed: 密码错误提示");
|
||||
L.add("login_failed=§c密码错误,请重试");
|
||||
L.add("");
|
||||
|
||||
// --- 密码 ---
|
||||
L.add("# ---- 密码相关 ----");
|
||||
L.add("# password_wrong: 旧密码验证失败");
|
||||
L.add("# ---- 密码 ----");
|
||||
L.add("password_wrong=§c密码错误");
|
||||
L.add("# password_changed: 密码修改成功");
|
||||
L.add("password_changed=§a密码修改成功!");
|
||||
L.add("# password_format_error: 密码格式不符合要求");
|
||||
L.add("password_format_error=§c密码需6位以上,含大小写字母和数字");
|
||||
L.add("# password_same: 新密码与旧密码相同");
|
||||
L.add("password_same=§c新密码不能与旧密码相同");
|
||||
L.add("# reset_no_email: 找回密码时未绑定邮箱");
|
||||
L.add("reset_no_email=§c您未绑定邮箱,无法找回密码");
|
||||
L.add("# reset_sent: 临时密码已发送到邮箱");
|
||||
L.add("reset_sent=§a临时密码已发送到您的邮箱,请查收");
|
||||
L.add("reset_sent=§a临时密码已发送到您的邮箱");
|
||||
L.add("");
|
||||
|
||||
// --- 签到积分 ---
|
||||
L.add("# ---- 签到积分相关 ----");
|
||||
L.add("# checkin_already: 今日已签到");
|
||||
L.add("# ---- 签到积分 ----");
|
||||
L.add("checkin_already=§c您今日已签到");
|
||||
L.add("# checkin_success: 签到成功,{points}=获得积分 {streak}=连续天数 {multi}=倍率");
|
||||
L.add("checkin_success=§a签到成功!获得 {points} 积分,连续 {streak} 天,倍率 x{multi}");
|
||||
L.add("# points_insufficient: 积分不足");
|
||||
L.add("checkin_success=§a签到成功!获得 {points} 积分");
|
||||
L.add("points_insufficient=§c积分不足,当前: {points}");
|
||||
L.add("# points_purchase_success: 积分购买成功");
|
||||
L.add("points_purchase_success=§a购买成功!消耗 {count} 积分");
|
||||
L.add("");
|
||||
|
||||
// --- 挂机 ---
|
||||
L.add("# ---- 挂机检测相关 ----");
|
||||
L.add("# afk_set_enabled: 挂机检测开启");
|
||||
L.add("# ---- 挂机检测 ----");
|
||||
L.add("afk_set_enabled=§a挂机检测已开启");
|
||||
L.add("# afk_set_disabled: 挂机检测关闭");
|
||||
L.add("afk_set_disabled=§c挂机检测已关闭");
|
||||
L.add("# afk_kick: 因挂机被踢出");
|
||||
L.add("afk_kick=§c因挂机过久被踢出");
|
||||
L.add("");
|
||||
|
||||
// --- 邮箱 ---
|
||||
L.add("# ---- 邮箱相关 ----");
|
||||
L.add("# email_set: 邮箱设置成功");
|
||||
L.add("# ---- 邮箱 ----");
|
||||
L.add("email_set=§a邮箱设置成功:{email}");
|
||||
L.add("# email_format_error: 邮箱格式错误");
|
||||
L.add("email_format_error=§c邮箱格式不正确");
|
||||
L.add("");
|
||||
|
||||
// --- 邀请 ---
|
||||
L.add("# ---- 邀请相关 ----");
|
||||
L.add("# invite_code_generated: 邀请码生成");
|
||||
L.add("# ---- 邀请 ----");
|
||||
L.add("invite_code_generated=§a邀请码:{code}");
|
||||
L.add("# invite_used: 使用邀请码成功");
|
||||
L.add("invite_used=§a邀请成功,邀请人:{player}");
|
||||
L.add("# invite_self: 使用自己的邀请码");
|
||||
L.add("invite_self=§c不能使用自己的邀请码");
|
||||
L.add("# invite_not_found: 邀请码不存在");
|
||||
L.add("invite_not_found=§c邀请码不存在");
|
||||
L.add("# invite_referral_bonus: 被邀请人签到后邀请人获得奖励");
|
||||
L.add("invite_referral_bonus=§a邀请奖励!获得 {points} 积分");
|
||||
L.add("");
|
||||
|
||||
// --- 礼包 ---
|
||||
L.add("# ---- 新人礼包相关 ----");
|
||||
L.add("# gift_not_ready: 礼包条件未满足");
|
||||
L.add("# ---- 礼包 ----");
|
||||
L.add("gift_not_ready=§c礼包条件未满足");
|
||||
L.add("# gift_claimed: 礼包领取成功");
|
||||
L.add("gift_claimed=§a礼包领取成功!");
|
||||
L.add("");
|
||||
|
||||
// --- 审批/IP ---
|
||||
L.add("# ---- 审批与IP限制 ----");
|
||||
L.add("# need_approval: 注册需审批");
|
||||
L.add("# ---- 审批与IP ----");
|
||||
L.add("need_approval=§e注册需审批 (工单#{id})");
|
||||
L.add("# ip_max_accounts: IP注册已达上限");
|
||||
L.add("ip_max_accounts=§cIP注册已达上限");
|
||||
L.add("");
|
||||
|
||||
// --- 管理员 ---
|
||||
L.add("# ---- 管理员操作 ----");
|
||||
L.add("# admin_delete_confirm: 管理员删除账号确认提示");
|
||||
L.add("# ---- 管理员 ----");
|
||||
L.add("admin_delete_confirm=§c请在聊天中输入玩家名确认删除");
|
||||
L.add("");
|
||||
|
||||
// --- 聊天过滤 ---
|
||||
L.add("# ---- 聊天过滤 ----");
|
||||
L.add("# chat_muted: 禁言玩家尝试聊天");
|
||||
L.add("chat_muted=§c§l[Sdf1_chat] §f你已被禁言,无法聊天");
|
||||
L.add("# chat_url_blocked: 发送违规链接被拦截");
|
||||
L.add("# {url}=检测到的链接地址");
|
||||
L.add("chat_url_blocked=§c§l[Sdf1_chat] §f检测到违规第三方链接: §e{url}");
|
||||
L.add("# chat_url_violation: 当前违规次数");
|
||||
L.add("# {count}=当前违规次数");
|
||||
L.add("chat_muted=§c§l[Sdf1_chat] §f你已被禁言");
|
||||
L.add("chat_url_blocked=§c§l[Sdf1_chat] §f检测到违规链接: §e{url}");
|
||||
L.add("chat_url_violation=§7当前违规次数: §e{count}");
|
||||
L.add("# chat_url_admin_notify: 通知管理员,{player}=玩家名 {url}=链接 {count}=次数");
|
||||
L.add("chat_url_admin_notify=§e§l[Sdf1_chat] §f{player} 发送违规链接: {url} (第{count}次)");
|
||||
L.add("# chat_url_broadcast: 全服通报,{player}=玩家名");
|
||||
L.add("chat_url_admin_notify=§e§l[Sdf1_chat] §f{player} 发送违规链接: {url}");
|
||||
L.add("chat_url_broadcast=§c§l[Sdf1_chat] §e{player} §f因发送违规链接被处罚");
|
||||
L.add("");
|
||||
|
||||
// --- 通用 ---
|
||||
L.add("# ---- 通用 ----");
|
||||
L.add("# 未知参数: 未知命令或权限不足时的提示");
|
||||
L.add("未知参数=§c未知参数或权限不足");
|
||||
L.add("# only_player: 仅玩家可用的命令");
|
||||
L.add("# only_player=§c此命令仅玩家可用");
|
||||
|
||||
writeLines(f, L);
|
||||
}
|
||||
|
||||
|
||||
// ==================== SMTP ====================
|
||||
|
||||
public void loadSmtp() {
|
||||
smtpSettings.clear();
|
||||
File file = new File(dataFolder, "SMTP设置.txt");
|
||||
if (!file.exists()) createDefaultSmtp(file);
|
||||
File file =
|
||||
new File(dataFolder, "SMTP设置.txt");
|
||||
if (!file.exists())
|
||||
createDefaultSmtp(file);
|
||||
loadMap(file, smtpSettings);
|
||||
}
|
||||
private double parseDouble(String s, double def) {
|
||||
try { return Double.parseDouble(s.trim()); }
|
||||
catch (Exception e) { return def; }
|
||||
}
|
||||
|
||||
public String getSmtp(String key) {
|
||||
return smtpSettings.getOrDefault(key, "");
|
||||
}
|
||||
/** 获取挂机白名单列表 */
|
||||
public List<String> getAfkWhitelist() {
|
||||
List<String> list = new ArrayList<>();
|
||||
File file = new File(dataFolder, "挂机白名单.txt");
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
try (BufferedWriter w = new BufferedWriter(
|
||||
new OutputStreamWriter(
|
||||
new FileOutputStream(file),
|
||||
StandardCharsets.UTF_8))) {
|
||||
w.write("# 每行一个玩家名,前面加 # 为注释");
|
||||
w.newLine();
|
||||
w.write("# 以下玩家不会被挂机踢出");
|
||||
w.newLine();
|
||||
}
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
try (BufferedReader r = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
new FileInputStream(file),
|
||||
StandardCharsets.UTF_8))) {
|
||||
String line;
|
||||
while ((line = r.readLine()) != null) {
|
||||
line = line.trim();
|
||||
if (!line.isEmpty() && !line.startsWith("#")) {
|
||||
list.add(line);
|
||||
}
|
||||
}
|
||||
} catch (IOException ignored) {}
|
||||
return list;
|
||||
}
|
||||
|
||||
/** 设置SMTP单项(聊天输入用) */
|
||||
public void setSmtp(String key, String value) {
|
||||
smtpSettings.put(key, value);
|
||||
}
|
||||
|
||||
/** 将当前SMTP设置写回文件 */
|
||||
public void saveSmtp() {
|
||||
File file = new File(dataFolder, "SMTP设置.txt");
|
||||
File file =
|
||||
new File(dataFolder, "SMTP设置.txt");
|
||||
List<String> L = new ArrayList<>();
|
||||
L.add("# ===== SMTP 邮件服务器配置 =====");
|
||||
for (Map.Entry<String, String> e : smtpSettings.entrySet()) {
|
||||
for (Map.Entry<String, String> e
|
||||
: smtpSettings.entrySet()) {
|
||||
L.add(e.getKey() + "=" + e.getValue());
|
||||
}
|
||||
writeLines(file, L);
|
||||
@@ -285,17 +203,25 @@ public class ConfigManager {
|
||||
// ==================== 插件设置 ====================
|
||||
|
||||
public void loadSettings() {
|
||||
File file = new File(dataFolder, "插件设置.txt");
|
||||
if (!file.exists()) createDefaultSettings(file);
|
||||
Map<String, String> m = new LinkedHashMap<>();
|
||||
File file =
|
||||
new File(dataFolder, "插件设置.txt");
|
||||
if (!file.exists())
|
||||
createDefaultSettings(file);
|
||||
Map<String, String> m =
|
||||
new LinkedHashMap<>();
|
||||
loadMap(file, m);
|
||||
adminTag = m.getOrDefault("管理标签", adminTag);
|
||||
adminPassword = m.getOrDefault("管理密码", adminPassword);
|
||||
|
||||
adminTag = m.getOrDefault(
|
||||
"管理标签", adminTag);
|
||||
adminPassword = m.getOrDefault(
|
||||
"管理密码", adminPassword);
|
||||
maxAccountsPerIP = parseInt(
|
||||
m.getOrDefault("每IP最大账号数", "3"), 3);
|
||||
approvalMode = m.getOrDefault("审批模式", approvalMode);
|
||||
approvalMode = m.getOrDefault(
|
||||
"审批模式", approvalMode);
|
||||
autoApproveDelayMinutes = parseInt(
|
||||
m.getOrDefault("自动审批延迟分钟", "30"), 30);
|
||||
m.getOrDefault("自动审批延迟分钟", "30"),
|
||||
30);
|
||||
loginTimeout = parseInt(
|
||||
m.getOrDefault("登录超时秒数", "60"), 60);
|
||||
afkEnabled = Boolean.parseBoolean(
|
||||
@@ -304,56 +230,106 @@ public class ConfigManager {
|
||||
m.getOrDefault("挂机超时秒数", "300"), 300);
|
||||
smtpSsl = Boolean.parseBoolean(
|
||||
m.getOrDefault("smtp加密", "true"));
|
||||
httpPort = parseInt(
|
||||
m.getOrDefault("http-port", "8080"),
|
||||
8080);
|
||||
broadcastServerUrl = m.getOrDefault(
|
||||
"resource-pack-url", "");
|
||||
|
||||
// 提成
|
||||
providerPointsPerScore = parseDouble(
|
||||
m.getOrDefault("服务商积分倍率", "2.0"),
|
||||
2.0);
|
||||
m.getOrDefault(
|
||||
"服务商积分倍率", "2.0"), 2.0);
|
||||
baseEconomyReward = parseInt(
|
||||
m.getOrDefault("基础经济奖励", "100"),
|
||||
100);
|
||||
m.getOrDefault(
|
||||
"基础经济奖励", "100"), 100);
|
||||
providerEconomyPerScore = parseDouble(
|
||||
m.getOrDefault("经济奖励每评分", "50.0"),
|
||||
50.0);
|
||||
m.getOrDefault(
|
||||
"经济奖励每评分", "50.0"), 50.0);
|
||||
requesterPointsReward = parseInt(
|
||||
m.getOrDefault("报单人积分奖励", "10"),
|
||||
10);
|
||||
m.getOrDefault(
|
||||
"报单人积分奖励", "10"), 10);
|
||||
|
||||
// 垃圾站
|
||||
garbageEnabled = Boolean.parseBoolean(
|
||||
m.getOrDefault("垃圾站_启用", "true"));
|
||||
m.getOrDefault(
|
||||
"垃圾站_启用", "true"));
|
||||
garbageInterval = parseInt(
|
||||
m.getOrDefault("垃圾站_清理间隔秒",
|
||||
"300"), 300);
|
||||
m.getOrDefault(
|
||||
"垃圾站_清理间隔秒", "300"), 300);
|
||||
garbageMaxRounds = parseInt(
|
||||
m.getOrDefault("垃圾站_保留轮数",
|
||||
"1"), 1);
|
||||
// loadSettings() 末尾添加:
|
||||
m.getOrDefault(
|
||||
"垃圾站_保留轮数", "1"), 1);
|
||||
|
||||
// 签到
|
||||
checkinRewardFixed = parseDouble(
|
||||
m.getOrDefault(
|
||||
"签到固定金额", "0"), 0);
|
||||
checkinRewardMin = parseDouble(
|
||||
m.getOrDefault(
|
||||
"签到最小金额", "0"), 0);
|
||||
checkinRewardMax = parseDouble(
|
||||
m.getOrDefault(
|
||||
"签到最大金额", "0"), 0);
|
||||
checkinGivePoints = Boolean.parseBoolean(
|
||||
m.getOrDefault(
|
||||
"签到给积分", "true"));
|
||||
checkinPoints = parseInt(
|
||||
m.getOrDefault(
|
||||
"签到积分数量", "10"), 10);
|
||||
backCheckPointMultiplier = parseInt(
|
||||
m.getOrDefault(
|
||||
"补签积分倍率", "5"), 5);
|
||||
|
||||
|
||||
// 自动判断模式
|
||||
if (checkinRewardFixed > 0) {
|
||||
checkinRewardType = "fixed";
|
||||
} else if (checkinRewardMin > 0
|
||||
&& checkinRewardMax > 0
|
||||
&& checkinRewardMax
|
||||
> checkinRewardMin) {
|
||||
checkinRewardType = "range";
|
||||
} else {
|
||||
checkinRewardType = "none";
|
||||
}
|
||||
}
|
||||
|
||||
public void saveSettings() {
|
||||
File file = new File(dataFolder, "插件设置.txt");
|
||||
File file =
|
||||
new File(dataFolder, "插件设置.txt");
|
||||
List<String> L = new ArrayList<>();
|
||||
L.add("# ===== Sdf1_login 插件设置 =====");
|
||||
L.add("管理标签=" + adminTag);
|
||||
L.add("管理密码=" + adminPassword);
|
||||
L.add("每IP最大账号数=" + maxAccountsPerIP);
|
||||
L.add("审批模式=" + approvalMode);
|
||||
L.add("自动审批延迟分钟=" + autoApproveDelayMinutes);
|
||||
L.add("自动审批延迟分钟="
|
||||
+ autoApproveDelayMinutes);
|
||||
L.add("登录超时秒数=" + loginTimeout);
|
||||
L.add("挂机踢出=" + afkEnabled);
|
||||
L.add("挂机超时秒数=" + afkTimeout);
|
||||
// 垃圾站设置
|
||||
L.add("# ---- 资源包 ----");
|
||||
L.add("resource-pack-url="
|
||||
+ broadcastServerUrl);
|
||||
L.add("http-port=" + httpPort);
|
||||
L.add("# ---- 垃圾站 ----");
|
||||
L.add("垃圾站_启用=" + garbageEnabled);
|
||||
L.add("垃圾站_清理间隔秒=" + garbageInterval);
|
||||
L.add("垃圾站_清理间隔秒="
|
||||
+ garbageInterval);
|
||||
L.add("垃圾站_保留轮数=" + garbageMaxRounds);
|
||||
L.add("# ---- 签到盲盒奖励 ----");
|
||||
L.add("签到固定金额=" + checkinRewardFixed);
|
||||
L.add("签到最小金额=" + checkinRewardMin);
|
||||
L.add("签到最大金额=" + checkinRewardMax);
|
||||
L.add("签到给积分=" + checkinGivePoints);
|
||||
L.add("签到积分数量=" + checkinPoints);
|
||||
L.add("补签积分倍率="
|
||||
+ backCheckPointMultiplier);
|
||||
|
||||
writeLines(file, L);
|
||||
|
||||
writeLines(file, L);
|
||||
}
|
||||
public double providerPointsPerScore = 2.0;
|
||||
public int baseEconomyReward = 100;
|
||||
public double providerEconomyPerScore = 50.0;
|
||||
public int requesterPointsReward = 10;
|
||||
public boolean garbageEnabled = true;
|
||||
public int garbageInterval = 300;
|
||||
public int garbageMaxRounds = 1;
|
||||
|
||||
|
||||
private void createDefaultSettings(File f) {
|
||||
List<String> L = new ArrayList<>();
|
||||
@@ -366,100 +342,177 @@ public class ConfigManager {
|
||||
L.add("登录超时秒数=60");
|
||||
L.add("挂机踢出=false");
|
||||
L.add("挂机超时秒数=300");
|
||||
L.add("服务商积分倍率=" + providerPointsPerScore);
|
||||
L.add("基础经济奖励=" + baseEconomyReward);
|
||||
L.add("经济奖励每评分=" + providerEconomyPerScore);
|
||||
L.add("报单人积分奖励=" + requesterPointsReward);
|
||||
L.add("# ---- 资源包 ----");
|
||||
L.add("resource-pack-url=");
|
||||
L.add("http-port=8080");
|
||||
L.add("# ---- 垃圾站 ----");
|
||||
L.add("垃圾站_启用=true");
|
||||
L.add("垃圾站_清理间隔秒=300");
|
||||
L.add("垃圾站_保留轮数=1");
|
||||
L.add("# ---- 资源包(HTTP) ----");
|
||||
L.add("resource-pack-url=");
|
||||
L.add("http-port=8080");
|
||||
L.add("# ---- 签到盲盒奖励 ----");
|
||||
L.add("签到固定金额=0");
|
||||
L.add("签到最小金额=50");
|
||||
L.add("签到最大金额=500");
|
||||
L.add("签到给积分=true");
|
||||
L.add("签到积分数量=10");
|
||||
L.add("补签积分倍率=5");
|
||||
|
||||
|
||||
writeLines(f, L);
|
||||
}
|
||||
|
||||
// ==================== 通用读写 ====================
|
||||
// ==================== 通用工具 ====================
|
||||
|
||||
private void loadMap(File file, Map<String, String> map) {
|
||||
try (BufferedReader r = new BufferedReader(
|
||||
new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) {
|
||||
public List<String> getAfkWhitelist() {
|
||||
List<String> list = new ArrayList<>();
|
||||
File file = new File(
|
||||
dataFolder, "挂机白名单.txt");
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
try (BufferedWriter w =
|
||||
new BufferedWriter(
|
||||
new OutputStreamWriter(
|
||||
new FileOutputStream(
|
||||
file),
|
||||
StandardCharsets
|
||||
.UTF_8))) {
|
||||
w.write("# 每行一个玩家名");
|
||||
w.newLine();
|
||||
}
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
try (BufferedReader r =
|
||||
new BufferedReader(
|
||||
new InputStreamReader(
|
||||
new FileInputStream(
|
||||
file),
|
||||
StandardCharsets
|
||||
.UTF_8))) {
|
||||
String line;
|
||||
while ((line = r.readLine()) != null) {
|
||||
line = line.trim();
|
||||
if (line.isEmpty() || line.startsWith("#")) continue;
|
||||
int eq = line.indexOf('=');
|
||||
if (eq > 0) map.put(line.substring(0, eq).trim(), line.substring(eq + 1).trim());
|
||||
if (!line.isEmpty()
|
||||
&& !line.startsWith("#")) {
|
||||
list.add(line);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println("[Sdf1_login] 读取失败: " + file.getName());
|
||||
}
|
||||
} catch (IOException ignored) {}
|
||||
return list;
|
||||
}
|
||||
|
||||
private void writeLines(File file, List<String> lines) {
|
||||
try (BufferedWriter w = new BufferedWriter(
|
||||
new OutputStreamWriter(new FileOutputStream(file), StandardCharsets.UTF_8))) {
|
||||
for (String l : lines) { w.write(l); w.newLine(); }
|
||||
} catch (IOException e) {
|
||||
System.err.println("[Sdf1_login] 写入失败: " + file.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private int parseInt(String s, int def) {
|
||||
try { return Integer.parseInt(s.trim()); } catch (Exception e) { return def; }
|
||||
}
|
||||
/**
|
||||
* 生成6位验证码(字母+数字)
|
||||
*/
|
||||
public String generateSmtpVerifyCode() {
|
||||
String chars =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
+ "abcdefghijklmnopqrstuvwxyz"
|
||||
+ "0123456789";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
java.util.Random r = new java.util.Random();
|
||||
java.util.Random r =
|
||||
new java.util.Random();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
sb.append(chars.charAt(r.nextInt(
|
||||
chars.length())));
|
||||
sb.append(chars.charAt(
|
||||
r.nextInt(chars.length())));
|
||||
}
|
||||
smtpVerifyCode = sb.toString();
|
||||
smtpVerifyExpire =
|
||||
System.currentTimeMillis() + 300000L;
|
||||
System.currentTimeMillis()
|
||||
+ 300000L;
|
||||
return smtpVerifyCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查验证码是否有效
|
||||
*/
|
||||
public boolean checkSmtpVerifyCode(String code) {
|
||||
if (System.currentTimeMillis() > smtpVerifyExpire) {
|
||||
public boolean checkSmtpVerifyCode(
|
||||
String code) {
|
||||
if (System.currentTimeMillis()
|
||||
> smtpVerifyExpire) {
|
||||
smtpVerifyCode = "";
|
||||
return false;
|
||||
}
|
||||
return smtpVerifyCode.equalsIgnoreCase(code);
|
||||
return smtpVerifyCode
|
||||
.equalsIgnoreCase(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除验证码
|
||||
*/
|
||||
public void clearSmtpVerifyCode() {
|
||||
smtpVerifyCode = "";
|
||||
smtpVerifyExpire = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查发送间隔是否>=1分钟
|
||||
*/
|
||||
public boolean canSendSmtpVerify() {
|
||||
return System.currentTimeMillis()
|
||||
- smtpLastSendTime >= 60000L;
|
||||
}
|
||||
|
||||
public void recordSmtpSendTime() {
|
||||
smtpLastSendTime = System.currentTimeMillis();
|
||||
smtpLastSendTime =
|
||||
System.currentTimeMillis();
|
||||
}
|
||||
|
||||
// ==================== 文件读写 ====================
|
||||
|
||||
private void loadMap(File file,
|
||||
Map<String, String> map) {
|
||||
try (BufferedReader r =
|
||||
new BufferedReader(
|
||||
new InputStreamReader(
|
||||
new FileInputStream(
|
||||
file),
|
||||
StandardCharsets
|
||||
.UTF_8))) {
|
||||
String line;
|
||||
while ((line = r.readLine()) != null) {
|
||||
line = line.trim();
|
||||
if (line.isEmpty()
|
||||
|| line.startsWith("#"))
|
||||
continue;
|
||||
int eq = line.indexOf('=');
|
||||
if (eq > 0) {
|
||||
map.put(
|
||||
line.substring(0, eq)
|
||||
.trim(),
|
||||
line.substring(eq + 1)
|
||||
.trim());
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println(
|
||||
"[Sdf1_login] 读取失败: "
|
||||
+ file.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private void writeLines(File file,
|
||||
List<String> lines) {
|
||||
try (BufferedWriter w =
|
||||
new BufferedWriter(
|
||||
new OutputStreamWriter(
|
||||
new FileOutputStream(
|
||||
file),
|
||||
StandardCharsets
|
||||
.UTF_8))) {
|
||||
for (String l : lines) {
|
||||
w.write(l);
|
||||
w.newLine();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.err.println(
|
||||
"[Sdf1_login] 写入失败: "
|
||||
+ file.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private double parseDouble(
|
||||
String s, double def) {
|
||||
try {
|
||||
return Double.parseDouble(s.trim());
|
||||
} catch (Exception e) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
|
||||
private int parseInt(String s, int def) {
|
||||
try {
|
||||
return Integer.parseInt(s.trim());
|
||||
} catch (Exception e) {
|
||||
return def;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ public class GUIManager {
|
||||
public GUIManager(Main plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public void openMain(Player p) {
|
||||
Inventory g = Bukkit.createInventory(
|
||||
null, 27, T_MAIN);
|
||||
@@ -42,17 +41,21 @@ public class GUIManager {
|
||||
g.setItem(14, mkItem(Material.EMERALD,
|
||||
"§d§l积分商城"));
|
||||
g.setItem(16, mkItem(Material.CHEST,
|
||||
"§e§l新人礼包"));
|
||||
g.setItem(18, mkItem(Material.BOOK,
|
||||
"§e§l任务中心"));
|
||||
g.setItem(18, mkItem(Material.EMERALD_BLOCK,
|
||||
"§a§l每日签到",
|
||||
"§7签到获取积分和惊喜奖励"));
|
||||
g.setItem(20, mkItem(Material.BOOK,
|
||||
"§6工单系统",
|
||||
"§7提交bug、求助、举报"));
|
||||
if (p.isOp() || isAdmin(p)) {
|
||||
g.setItem(20, mkItem(Material.CHEST,
|
||||
g.setItem(22, mkItem(Material.CHEST,
|
||||
"§6垃圾回收站",
|
||||
"§7查看和取回清理的物品"));
|
||||
}
|
||||
if (isAdmin(p)) {
|
||||
g.setItem(22, mkItem(Material.REDSTONE_BLOCK,
|
||||
g.setItem(24, mkItem(
|
||||
Material.REDSTONE_BLOCK,
|
||||
"§c§l管理员面板"));
|
||||
}
|
||||
p.openInventory(g);
|
||||
@@ -107,6 +110,70 @@ public class GUIManager {
|
||||
}
|
||||
|
||||
// 在 openGiftStages 方法之前添加:
|
||||
public void openGiftStages(Player p) {
|
||||
Inventory g = Bukkit.createInventory(
|
||||
null, 27, T_GIFT_STAGES);
|
||||
fillBg(g);
|
||||
|
||||
QuestTracker qt =
|
||||
plugin.getQuestTracker();
|
||||
if (qt == null) {
|
||||
g.setItem(22, mkItem(
|
||||
Material.BARRIER,
|
||||
"§7任务系统未加载"));
|
||||
p.openInventory(g);
|
||||
return;
|
||||
}
|
||||
|
||||
List<QuestTracker.QuestFile> quests =
|
||||
qt.getQuests("新人任务");
|
||||
String playerName = p.getName();
|
||||
|
||||
int max = quests.size();
|
||||
for (int i = 0;
|
||||
i < max && i < 9; i++) {
|
||||
QuestTracker.QuestFile qf =
|
||||
quests.get(i);
|
||||
boolean completed =
|
||||
qt.isStageCompleted(
|
||||
playerName, qf);
|
||||
boolean claimed =
|
||||
qt.hasClaimed(
|
||||
playerName, qf);
|
||||
|
||||
Material mat;
|
||||
String status;
|
||||
if (completed && claimed) {
|
||||
mat = Material.LIME_WOOL;
|
||||
status = "§a已领取";
|
||||
} else if (completed) {
|
||||
mat = Material.YELLOW_WOOL;
|
||||
status = "§e可领取";
|
||||
} else {
|
||||
mat = Material.RED_WOOL;
|
||||
status = "§c未达标";
|
||||
}
|
||||
|
||||
List<String> lore =
|
||||
new ArrayList<>();
|
||||
lore.add("§7" + status);
|
||||
for (String cond :
|
||||
qf.conditions) {
|
||||
String progress =
|
||||
qt.getProgress(
|
||||
playerName, cond);
|
||||
lore.add("§7" + progress);
|
||||
}
|
||||
|
||||
g.setItem(10 + i, mkItem(mat,
|
||||
"§e" + qf.displayName,
|
||||
lore.toArray(
|
||||
new String[0])));
|
||||
}
|
||||
g.setItem(26, mkItem(Material.ARROW,
|
||||
"§7返回"));
|
||||
p.openInventory(g);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务列表(带真实完成状态)
|
||||
@@ -408,72 +475,27 @@ public class GUIManager {
|
||||
g.setItem(10, mkItem(Material.BOOK,
|
||||
"§e§l新人任务",
|
||||
"§7完成新手阶段获取奖励"));
|
||||
g.setItem(12, mkItem(Material.COMPASS,
|
||||
g.setItem(12, mkItem(Material.MAP,
|
||||
"§a§l群系打卡",
|
||||
"§7在不同群系打卡完成任务",
|
||||
"§7打卡范围: 32格去重"));
|
||||
g.setItem(14, mkItem(Material.COMPASS,
|
||||
"§b§l主线任务",
|
||||
"§7查看主线任务列表"));
|
||||
g.setItem(14, mkItem(Material.PAPER,
|
||||
g.setItem(16, mkItem(Material.PAPER,
|
||||
"§a§l支线任务",
|
||||
"§7查看支线任务列表"));
|
||||
g.setItem(16, mkItem(Material.EMERALD,
|
||||
"§d§l每日签到",
|
||||
"§7签到获取积分"));
|
||||
g.setItem(22, mkItem(Material.ARROW, "§7返回"));
|
||||
g.setItem(18, mkItem(Material.BOOK,
|
||||
"§6工单系统",
|
||||
"§7提交bug、求助、举报"));
|
||||
g.setItem(20, mkItem(Material.EMERALD,
|
||||
"§a§l每日签到",
|
||||
"§7签到获取积分和奖励"));
|
||||
g.setItem(22, mkItem(Material.ARROW,
|
||||
"§7返回"));
|
||||
p.openInventory(g);
|
||||
}
|
||||
public void openGiftStages(Player p) {
|
||||
Inventory g = Bukkit.createInventory(
|
||||
null, 27, T_GIFT_STAGES);
|
||||
fillBg(g);
|
||||
|
||||
QuestTracker qt = plugin.getQuestTracker();
|
||||
if (qt == null) {
|
||||
g.setItem(22, mkItem(Material.BARRIER,
|
||||
"§7任务系统未加载"));
|
||||
p.openInventory(g);
|
||||
return;
|
||||
}
|
||||
|
||||
List<QuestTracker.QuestFile> quests =
|
||||
qt.getQuests("新人任务");
|
||||
String playerName = p.getName();
|
||||
|
||||
int max = quests.size();
|
||||
for (int i = 0; i < max && i < 9; i++) {
|
||||
QuestTracker.QuestFile qf = quests.get(i);
|
||||
boolean completed =
|
||||
qt.isStageCompleted(playerName, qf);
|
||||
boolean claimed =
|
||||
qt.hasClaimed(playerName, qf);
|
||||
|
||||
Material mat;
|
||||
String status;
|
||||
if (completed && claimed) {
|
||||
mat = Material.LIME_WOOL;
|
||||
status = "§a已领取";
|
||||
} else if (completed) {
|
||||
mat = Material.YELLOW_WOOL;
|
||||
status = "§e可领取";
|
||||
} else {
|
||||
mat = Material.RED_WOOL;
|
||||
status = "§c未达标";
|
||||
}
|
||||
|
||||
// 显示进度
|
||||
List<String> lore = new ArrayList<>();
|
||||
lore.add("§7" + status);
|
||||
for (String cond : qf.conditions) {
|
||||
String progress =
|
||||
qt.getProgress(playerName, cond);
|
||||
lore.add("§7" + progress);
|
||||
}
|
||||
|
||||
g.setItem(10 + i, mkItem(mat,
|
||||
"§e" + qf.displayName,
|
||||
lore.toArray(new String[0])));
|
||||
}
|
||||
g.setItem(26, mkItem(Material.ARROW, "§7返回"));
|
||||
p.openInventory(g);
|
||||
}
|
||||
|
||||
|
||||
public void openTaskList(Player p, String folderName) {
|
||||
@@ -552,6 +574,7 @@ public class GUIManager {
|
||||
slot++;
|
||||
}
|
||||
|
||||
|
||||
g.setItem(53, mkItem(Material.ARROW, "§7返回"));
|
||||
p.openInventory(g);
|
||||
}
|
||||
|
||||
@@ -230,27 +230,26 @@ public class GarbageManager {
|
||||
}
|
||||
|
||||
public void saveItem(ItemStack stack) {
|
||||
{
|
||||
try {
|
||||
String data =
|
||||
stackToBase64(stack);
|
||||
if (data.isEmpty()) return;
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"INSERT INTO items "
|
||||
+ "(item_data, amount, "
|
||||
+ "round, create_time) "
|
||||
+ "VALUES (?,?,?,?)");
|
||||
ps.setString(1, data);
|
||||
ps.setInt(2, stack.getAmount());
|
||||
ps.setInt(3, currentRound);
|
||||
ps.setLong(4,
|
||||
System.currentTimeMillis());
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}}
|
||||
try {
|
||||
String data = stackToBase64(stack);
|
||||
if (data.isEmpty()) return;
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"INSERT INTO items "
|
||||
+ "(item_data, amount, "
|
||||
+ "round, create_time) "
|
||||
+ "VALUES (?,?,?,?)");
|
||||
ps.setString(1, data);
|
||||
ps.setInt(2, stack.getAmount());
|
||||
ps.setInt(3, currentRound);
|
||||
ps.setLong(4,
|
||||
System.currentTimeMillis());
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int deleteOldItems(int beforeRound) {
|
||||
try {
|
||||
@@ -344,11 +343,9 @@ public class GarbageManager {
|
||||
}
|
||||
|
||||
public void openRecyclePage(Player p, int page) {
|
||||
|
||||
Inventory g = Bukkit.createInventory(
|
||||
null, 54, "§6§l垃圾回收站");
|
||||
|
||||
// 获取全部存储物品
|
||||
List<Map<String, Object>> allItems =
|
||||
getStoredItems(999);
|
||||
int total = allItems.size();
|
||||
@@ -381,38 +378,6 @@ public class GarbageManager {
|
||||
.get("amount")).intValue();
|
||||
ItemStack stack = base64ToStack(data);
|
||||
if (stack != null) {
|
||||
try {
|
||||
byte[] bytes =
|
||||
stack.serializeAsBytes();
|
||||
String b64 = java.util.Base64
|
||||
.getEncoder()
|
||||
.encodeToString(bytes);
|
||||
int len = b64.length();
|
||||
String f = len > 15
|
||||
? b64.substring(10, 15) : "短";
|
||||
String m = len >= 5
|
||||
? b64.substring(len / 2,
|
||||
Math.min(len / 2 + 5, len))
|
||||
: "短";
|
||||
String b = len > 10
|
||||
? b64.substring(len - 10, len - 5)
|
||||
: "短";
|
||||
plugin.getLogger().info(
|
||||
"[垃圾站加载] ID#" + id
|
||||
+ " " + stack.getType()
|
||||
+ " x" + amount
|
||||
+ " base64[" + len + "]"
|
||||
+ " 前=" + f
|
||||
+ " 中=" + m
|
||||
+ " 后=" + b);
|
||||
} catch (Exception ex) {
|
||||
plugin.getLogger().warning(
|
||||
"[垃圾站加载] 序列化异常: "
|
||||
+ ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
if (stack != null) {
|
||||
stack.setAmount(amount);
|
||||
ItemMeta im =
|
||||
stack.getItemMeta();
|
||||
@@ -429,10 +394,7 @@ public class GarbageManager {
|
||||
slot++;
|
||||
}
|
||||
|
||||
// 45-48 格:额外投放区(空位)
|
||||
// 52-53 格:额外投放区(空位)
|
||||
|
||||
// 49 格:翻页-上一页
|
||||
// 49 格:上一页
|
||||
if (page > 0) {
|
||||
g.setItem(49, mk(Material.ARROW,
|
||||
"§e上一页 §7("
|
||||
@@ -451,9 +413,8 @@ public class GarbageManager {
|
||||
"§7当前页: §f" + (page + 1)
|
||||
+ "/" + totalPages));
|
||||
|
||||
// 51 格:翻页-下一页
|
||||
boolean canNext = total >= pageSize
|
||||
&& page < totalPages - 1;
|
||||
// 51 格:下一页
|
||||
boolean canNext = page < totalPages - 1;
|
||||
if (canNext) {
|
||||
g.setItem(51, mk(Material.ARROW,
|
||||
"§e下一页 §7("
|
||||
@@ -463,13 +424,15 @@ public class GarbageManager {
|
||||
g.setItem(51, mk(Material.ARROW,
|
||||
"§7已是最后一页"));
|
||||
}
|
||||
// 52格:返回按钮
|
||||
|
||||
// 52 格:返回
|
||||
g.setItem(52, mk(Material.ARROW,
|
||||
"§7返回",
|
||||
"§7返回主菜单"));
|
||||
|
||||
p.openInventory(g);
|
||||
}
|
||||
|
||||
public int getRecyclePage(String name) {
|
||||
return recyclePages
|
||||
.getOrDefault(name, 0);
|
||||
|
||||
@@ -22,7 +22,7 @@ public class GiftManager {
|
||||
public GiftManager(Main plugin) {
|
||||
this.plugin = plugin;
|
||||
this.giftFolder = new File(
|
||||
plugin.getDataFolder(), "新人礼包");
|
||||
plugin.getDataFolder(), "任务面板");
|
||||
}
|
||||
|
||||
public void loadStages() {
|
||||
|
||||
+984
-368
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@@ -178,20 +179,111 @@ public class QuestTracker {
|
||||
BIOME_CATEGORY.put("minecraft:warped_forest", "下界");
|
||||
BIOME_CATEGORY.put("minecraft:soul_sand_valley", "下界");
|
||||
BIOME_CATEGORY.put("minecraft:basalt_deltas", "下界");
|
||||
// 岩岸/沙滩
|
||||
BIOME_CATEGORY.put("minecraft:stony_shore",
|
||||
"石岸");
|
||||
// 海岸
|
||||
BIOME_CATEGORY.put("minecraft:mushroom_fields",
|
||||
"蘑菇岛");
|
||||
// 苍白之园
|
||||
BIOME_CATEGORY.put(
|
||||
"minecraft:pale_garden", "森林");
|
||||
// 末地小型岛屿
|
||||
BIOME_CATEGORY.put(
|
||||
"minecraft:small_end_islands", "末地");
|
||||
// 主世界结构归类
|
||||
BIOME_CATEGORY.put("minecraft:village", "平原");
|
||||
BIOME_CATEGORY.put(
|
||||
"minecraft:desert_pyramid", "沙漠");
|
||||
BIOME_CATEGORY.put(
|
||||
"minecraft:jungle_pyramid", "森林");
|
||||
BIOME_CATEGORY.put(
|
||||
"minecraft:swamp_hut", "沼泽");
|
||||
|
||||
// 末地群系
|
||||
BIOME_CATEGORY.put("minecraft:the_end", "末地");
|
||||
BIOME_CATEGORY.put("minecraft:the_void", "末地");
|
||||
BIOME_CATEGORY.put("minecraft:end_highlands", "末地");
|
||||
BIOME_CATEGORY.put("minecraft:end_midlands", "末地");
|
||||
BIOME_CATEGORY.put("minecraft:end_barrens", "末地");
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 所有群系大类列表
|
||||
private static final String[] ALL_CATEGORIES =
|
||||
{"海洋", "平原", "森林", "沙漠",
|
||||
"恶地", "雪原", "沙砾", "沼泽",
|
||||
"河流", "蘑菇岛", "地下",
|
||||
"下界", "末地"};
|
||||
private static final String[]
|
||||
ALL_CATEGORIES = {
|
||||
"海洋", "平原", "森林", "沙漠",
|
||||
"恶地", "雪原", "沙砾", "沼泽",
|
||||
"河流", "石岸", "蘑菇岛", "地下",
|
||||
"下界", "末地"
|
||||
};
|
||||
|
||||
// ===== 结构映射 =====
|
||||
private static final Map<String, String>
|
||||
STRUCTURE_CATEGORY =
|
||||
new HashMap<>();
|
||||
static {
|
||||
// 主世界结构
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:village", "村庄");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:desert_pyramid",
|
||||
"沙漠");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:jungle_pyramid",
|
||||
"森林");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:swamp_hut", "沼泽");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:igloo", "雪原");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:mansion", "森林");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:pillager_outpost",
|
||||
"平原");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:mineshaft", "地下");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:stronghold", "地下");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:ancient_city",
|
||||
"地下");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:trail_ruins",
|
||||
"平原");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:trial_chambers",
|
||||
"地下");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:ocean_ruin", "海洋");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:shipwreck", "海洋");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:buried_treasure",
|
||||
"海洋");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:ruined_portal",
|
||||
"平原");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:fossil", "平原");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:ancient_city",
|
||||
"地下");
|
||||
// 下界结构
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:nether_fortress",
|
||||
"下界");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:bastion_remnant",
|
||||
"下界");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:nether_fossil",
|
||||
"下界");
|
||||
STRUCTURE_CATEGORY.put(
|
||||
"minecraft:basalt_pillars",
|
||||
"下界");
|
||||
}
|
||||
|
||||
// 所有群系分类的条件关键词映射
|
||||
private static final Map<String, String>
|
||||
@@ -214,6 +306,10 @@ public class QuestTracker {
|
||||
CATEGORY_KEYWORDS.put("地狱", "下界");
|
||||
CATEGORY_KEYWORDS.put("下届", "下界");
|
||||
CATEGORY_KEYWORDS.put("主岛", "末地");
|
||||
CATEGORY_KEYWORDS.put("石岸", "石岸");
|
||||
CATEGORY_KEYWORDS.put("沙滩", "石岸");
|
||||
CATEGORY_KEYWORDS.put("海岸", "石岸");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,25 +320,53 @@ public class QuestTracker {
|
||||
*/
|
||||
public String mapBiomeCategory(
|
||||
String rawKey, String worldName) {
|
||||
// 下界维度优先用世界名
|
||||
// 优先用世界名判断维度
|
||||
if (worldName != null) {
|
||||
String w = worldName.toLowerCase();
|
||||
String w =
|
||||
worldName.toLowerCase();
|
||||
if (w.contains("nether"))
|
||||
return "下界";
|
||||
if (w.contains("end"))
|
||||
return "末地";
|
||||
}
|
||||
|
||||
// 用群系映射表
|
||||
if (rawKey != null) {
|
||||
String lower =
|
||||
rawKey.toLowerCase();
|
||||
// 带 minecraft: 前缀的直接查
|
||||
String cat =
|
||||
BIOME_CATEGORY.get(
|
||||
rawKey.toLowerCase());
|
||||
if (cat != null) return cat;
|
||||
BIOME_CATEGORY.get(lower);
|
||||
if (cat != null)
|
||||
return cat;
|
||||
|
||||
// 不带前缀的尝试补全
|
||||
String prefixed =
|
||||
"minecraft:" + lower;
|
||||
cat = BIOME_CATEGORY.get(prefixed);
|
||||
if (cat != null)
|
||||
return cat;
|
||||
|
||||
// 模糊匹配群系名
|
||||
for (Map.Entry<String, String> entry
|
||||
: BIOME_CATEGORY.entrySet()) {
|
||||
if (entry.getKey()
|
||||
.contains(lower)
|
||||
|| lower.contains(
|
||||
entry.getKey()
|
||||
.replace(
|
||||
"minecraft:",
|
||||
""))) {
|
||||
return entry.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "主世界";
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ========== 解析为区块 ==========
|
||||
|
||||
private List<Section> parseIntoSections(
|
||||
@@ -1611,22 +1735,68 @@ public class QuestTracker {
|
||||
+ ": §e" + cur
|
||||
+ "/" + needed;
|
||||
}
|
||||
if (key.contains("村民")
|
||||
&& key.contains("交易")) {
|
||||
int needed = parseNumberFromText(key);
|
||||
if (needed <= 0) needed = 1;
|
||||
int cur = getCounter(
|
||||
player, "VILLAGER_TRADE");
|
||||
return "§7村民交易: §e"
|
||||
+ cur + "/" + needed;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// ===== 击杀泛解析(支持中文列表) =====
|
||||
// 匹配 "击杀10只骷髅、僵尸、苦力怕" 等
|
||||
if (key.contains("击杀") && key.contains("只")) {
|
||||
int needed = parseNumberFromText(key);
|
||||
if (needed <= 0) needed = 1;
|
||||
|
||||
String mobPart = key;
|
||||
java.util.regex.Matcher killM =
|
||||
java.util.regex.Pattern
|
||||
.compile("击杀\\d+只(.+)")
|
||||
.matcher(key);
|
||||
if (killM.find()) {
|
||||
mobPart = killM.group(1).trim();
|
||||
}
|
||||
|
||||
String[] mobNames = mobPart
|
||||
.split("[、,,,]+");
|
||||
int totalKills = 0;
|
||||
StringBuilder names = new StringBuilder();
|
||||
for (String name : mobNames) {
|
||||
String trimmed = name.trim();
|
||||
if (trimmed.isEmpty()) continue;
|
||||
String entityType =
|
||||
chineseMobToEntity(trimmed);
|
||||
if (!entityType.isEmpty()) {
|
||||
totalKills += getCounter(
|
||||
player,
|
||||
"KILL:" + entityType);
|
||||
if (names.length() > 0)
|
||||
names.append("/");
|
||||
names.append(trimmed);
|
||||
}
|
||||
}
|
||||
return "§7击杀" + names + ": §e"
|
||||
+ totalKills + "/" + needed;
|
||||
}
|
||||
|
||||
// 单一KILL:xxx:N 格式(原有逻辑保留)
|
||||
if (key.startsWith("KILL:")) {
|
||||
String[] parts = key.split(":");
|
||||
if (parts.length >= 3) {
|
||||
int needed =
|
||||
parseInt(parts[2]);
|
||||
int cur = getCounter(
|
||||
player,
|
||||
"KILL:" + parts[1]);
|
||||
return "§7杀 " + parts[1]
|
||||
+ ": §e" + cur
|
||||
+ "/" + needed;
|
||||
String[] p = key.split(":");
|
||||
if (p.length >= 3) {
|
||||
int needed = parseInt(p[2]);
|
||||
int cur = getCounter(player,
|
||||
"KILL:" + p[1]);
|
||||
return "§7击杀" + p[1] + ": §e"
|
||||
+ cur + "/" + needed;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (key.startsWith("KILL_PLAYER")) {
|
||||
String[] parts = key.split(":");
|
||||
int needed = parts.length >= 2
|
||||
@@ -1739,10 +1909,219 @@ public class QuestTracker {
|
||||
+ done + "/"
|
||||
+ quests.size();
|
||||
}
|
||||
// ===== 泛解析:击杀类进度 =====
|
||||
if (key.contains("击杀") || key.contains("猎杀")
|
||||
|| key.contains("消灭")) {
|
||||
int needed = parseNumberFromText(key);
|
||||
if (needed <= 0) needed = 1;
|
||||
List<String> mobTypes = extractMobTypes(key);
|
||||
if (!mobTypes.isEmpty()) {
|
||||
int total = 0;
|
||||
StringBuilder names =
|
||||
new StringBuilder();
|
||||
for (int i = 0;
|
||||
i < mobTypes.size(); i++) {
|
||||
total += getCounter(player,
|
||||
"KILL:" + mobTypes.get(i));
|
||||
if (i > 0) names.append("/");
|
||||
names.append(reverseMobName(
|
||||
mobTypes.get(i)));
|
||||
}
|
||||
return "§7击杀" + names + ": §e"
|
||||
+ total + "/" + needed;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 泛解析:村民交易进度 =====
|
||||
if (key.contains("交易")
|
||||
&& (key.contains("村民")
|
||||
|| key.contains("与村民"))) {
|
||||
int needed = parseNumberFromText(key);
|
||||
if (needed <= 0) needed = 1;
|
||||
int cur = getCounter(player, "TRADE");
|
||||
return "§7村民交易: §e"
|
||||
+ cur + "/" + needed;
|
||||
}
|
||||
// ===== 泛解析:采集/挖矿进度 =====
|
||||
if (key.contains("采集")
|
||||
|| key.contains("挖")) {
|
||||
int needed =
|
||||
parseNumberFromText(key);
|
||||
if (needed <= 0) needed = 1;
|
||||
List<String> matTypes =
|
||||
extractMaterialTypes(key);
|
||||
if (!matTypes.isEmpty()) {
|
||||
int total = 0;
|
||||
StringBuilder names =
|
||||
new StringBuilder();
|
||||
for (int i = 0;
|
||||
i < matTypes.size(); i++) {
|
||||
total += getCounter(
|
||||
player,
|
||||
"MINE:" + matTypes
|
||||
.get(i));
|
||||
if (i > 0)
|
||||
names.append("/");
|
||||
names.append(
|
||||
translateMaterialName(
|
||||
matTypes
|
||||
.get(i)));
|
||||
}
|
||||
return "§7采集" + names
|
||||
+ ": §e" + total
|
||||
+ "/" + needed;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 泛解析:合成进度 =====
|
||||
if (key.contains("合成") || key.contains("制作")) {
|
||||
int needed = parseNumberFromText(key);
|
||||
if (needed <= 0) needed = 1;
|
||||
int cur = getCounter(player, "CRAFT");
|
||||
return "§7合成: §e" + cur + "/" + needed;
|
||||
}
|
||||
|
||||
// ===== 泛解析:钓鱼进度 =====
|
||||
if (key.contains("钓鱼") || key.contains("钓")) {
|
||||
int needed = parseNumberFromText(key);
|
||||
if (needed <= 0) needed = 1;
|
||||
int cur = getCounter(player, "FISH");
|
||||
return "§7钓鱼: §e" + cur + "/" + needed;
|
||||
}
|
||||
|
||||
return "§7" + key;
|
||||
}
|
||||
private String translateMaterialName(
|
||||
String name) {
|
||||
switch (name) {
|
||||
case "COAL_ORE":
|
||||
return "煤矿石";
|
||||
case "DEEPSLATE_COAL_ORE":
|
||||
return "深层煤矿石";
|
||||
case "IRON_ORE":
|
||||
return "铁矿石";
|
||||
case "DEEPSLATE_IRON_ORE":
|
||||
return "深层铁矿石";
|
||||
case "COPPER_ORE":
|
||||
return "铜矿石";
|
||||
case "DEEPSLATE_COPPER_ORE":
|
||||
return "深层铜矿石";
|
||||
case "GOLD_ORE":
|
||||
return "金矿石";
|
||||
case "DEEPSLATE_GOLD_ORE":
|
||||
return "深层金矿石";
|
||||
case "DIAMOND_ORE":
|
||||
return "钻石矿石";
|
||||
case "DEEPSLATE_DIAMOND_ORE":
|
||||
return "深层钻石矿石";
|
||||
case "EMERALD_ORE":
|
||||
return "绿宝石矿石";
|
||||
case "DEEPSLATE_EMERALD_ORE":
|
||||
return "深层绿宝石矿石";
|
||||
case "LAPIS_ORE":
|
||||
return "青金石矿石";
|
||||
case "DEEPSLATE_LAPIS_ORE":
|
||||
return "深层青金石矿石";
|
||||
case "REDSTONE_ORE":
|
||||
return "红石矿石";
|
||||
case "DEEPSLATE_REDSTONE_ORE":
|
||||
return "深层红石矿石";
|
||||
case "NETHER_GOLD_ORE":
|
||||
return "下界金矿石";
|
||||
case "NETHER_QUARTZ_ORE":
|
||||
return "下界石英矿石";
|
||||
case "ANCIENT_DEBRIS":
|
||||
return "远古残骸";
|
||||
case "COAL":
|
||||
return "煤炭";
|
||||
case "RAW_IRON":
|
||||
return "粗铁";
|
||||
case "RAW_GOLD":
|
||||
return "粗金";
|
||||
case "RAW_COPPER":
|
||||
return "粗铜";
|
||||
case "DIAMOND":
|
||||
return "钻石";
|
||||
case "EMERALD":
|
||||
return "绿宝石";
|
||||
case "LAPIS_LAZULI":
|
||||
return "青金石";
|
||||
case "REDSTONE":
|
||||
return "红石";
|
||||
case "QUARTZ":
|
||||
return "石英";
|
||||
default:
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 中文物种名 → Bukkit EntityType 名
|
||||
* 支持击杀泛解析的模糊匹配
|
||||
*/
|
||||
private String chineseMobToEntity(String cn) {
|
||||
String n = cn.toLowerCase().trim();
|
||||
|
||||
// 直接别名表
|
||||
Map<String, String> mobMap = new HashMap<>();
|
||||
mobMap.put("骷髅", "SKELETON");
|
||||
mobMap.put("僵尸", "ZOMBIE");
|
||||
mobMap.put("苦力怕", "CREEPER");
|
||||
mobMap.put("蜘蛛", "SPIDER");
|
||||
mobMap.put("洞穴蜘蛛", "CAVE_SPIDER");
|
||||
mobMap.put("小白", "SKELETON");
|
||||
mobMap.put("末影人", "ENDERMAN");
|
||||
mobMap.put("enderman", "ENDERMAN");
|
||||
mobMap.put("猪灵", "PIGLIN");
|
||||
mobMap.put("猪灵蛮兵", "PIGLIN_BRUTE");
|
||||
mobMap.put("恶魂", "GHAST");
|
||||
mobMap.put("凋灵骷髅", "WITHER_SKELETON");
|
||||
mobMap.put("烈焰人", "BLAZE");
|
||||
mobMap.put("史莱姆", "SLIME");
|
||||
mobMap.put("岩浆怪", "MAGMA_CUBE");
|
||||
mobMap.put("女巫", "WITCH");
|
||||
mobMap.put("蠹虫", "SILVERFISH");
|
||||
mobMap.put("潜影贝", "SHULKER");
|
||||
mobMap.put("守卫者", "GUARDIAN");
|
||||
mobMap.put("远古守卫者", "ELDER_GUARDIAN");
|
||||
mobMap.put("溺尸", "DROWNED");
|
||||
mobMap.put("僵尸村民", "ZOMBIE_VILLAGER");
|
||||
mobMap.put("尸壳", "HUSK");
|
||||
mobMap.put("流浪者", "STRAY");
|
||||
mobMap.put("幻翼", "PHANTOM");
|
||||
mobMap.put("掠夺者", "PILLAGER");
|
||||
mobMap.put("卫道士", "VINDICATOR");
|
||||
mobMap.put("唤魔者", "EVOKER");
|
||||
mobMap.put("恼鬼", "VEX");
|
||||
mobMap.put("劫掠兽", "RAVAGER");
|
||||
mobMap.put("蜘蛛骑士", "SPIDER_JOCKEY");
|
||||
mobMap.put("凋灵", "WITHER");
|
||||
mobMap.put("末影龙", "ENDER_DRAGON");
|
||||
|
||||
// 精确匹配
|
||||
if (mobMap.containsKey(n)) {
|
||||
return mobMap.get(n);
|
||||
}
|
||||
|
||||
// 模糊匹配(包含关系)
|
||||
for (Map.Entry<String, String> en
|
||||
: mobMap.entrySet()) {
|
||||
if (n.contains(en.getKey())
|
||||
|| en.getKey().contains(n)) {
|
||||
return en.getValue();
|
||||
}
|
||||
}
|
||||
|
||||
// 尝试直接用英文名
|
||||
try {
|
||||
return org.bukkit.entity.EntityType
|
||||
.valueOf(n.toUpperCase()
|
||||
.replace(" ", "_"))
|
||||
.name();
|
||||
} catch (Exception e) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> checkInBiome(
|
||||
String player,
|
||||
@@ -1776,6 +2155,23 @@ public class QuestTracker {
|
||||
String category =
|
||||
mapBiomeCategory(
|
||||
rawBiomeKey, worldName);
|
||||
// 结构检测(覆盖纯生物群系分类)
|
||||
// 地下检测:Y低于表面则归类为地下
|
||||
// 覆盖废弃矿井/试炼密室/要塞/远古城市等
|
||||
try {
|
||||
org.bukkit.World uw =
|
||||
Bukkit.getWorld(worldName);
|
||||
if (uw != null) {
|
||||
int surfaceY = uw
|
||||
.getHighestBlockYAt(
|
||||
(int) Math.floor(x),
|
||||
(int) Math.floor(z));
|
||||
if (y < surfaceY - 8) {
|
||||
category = "地下";
|
||||
}
|
||||
}
|
||||
} catch (Exception ignored) {}
|
||||
|
||||
|
||||
// 记录总打卡
|
||||
int allCur = getCounter(
|
||||
@@ -1851,6 +2247,344 @@ public class QuestTracker {
|
||||
return matched;
|
||||
}
|
||||
|
||||
/*
|
||||
* 打卡入口:报告坐标 → 32格去重 → 匹配条件 → 记录
|
||||
*/
|
||||
public String checkInAtPosition(
|
||||
String player, String worldName,
|
||||
double x, double y, double z) {
|
||||
|
||||
List<double[]> history =
|
||||
loadCheckInPositions(player);
|
||||
for (double[] pos : history) {
|
||||
double dist = Math.sqrt(
|
||||
Math.pow(x - pos[0], 2)
|
||||
+ Math.pow(y - pos[1], 2)
|
||||
+ Math.pow(z - pos[2], 2));
|
||||
if (dist <= 32) {
|
||||
return "§c距离上次打卡点太近("
|
||||
+ String.format(
|
||||
"%.0f", dist)
|
||||
+ "格)";
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 获取群系和分类 =====
|
||||
String biome = "minecraft:plains";
|
||||
String category = "平原";
|
||||
try {
|
||||
org.bukkit.World w =
|
||||
Bukkit.getWorld(worldName);
|
||||
if (w != null) {
|
||||
org.bukkit.Location loc =
|
||||
new org.bukkit.Location(
|
||||
w,
|
||||
(int) Math.floor(x),
|
||||
(int) Math.floor(y),
|
||||
(int) Math.floor(z));
|
||||
biome = loc.getBlock()
|
||||
.getBiome().getKey()
|
||||
.toString();
|
||||
category = mapBiomeCategory(
|
||||
biome, worldName);
|
||||
|
||||
int surfaceY = w
|
||||
.getHighestBlockYAt(
|
||||
(int) Math.floor(x),
|
||||
(int) Math.floor(z));
|
||||
if (y < surfaceY - 8) {
|
||||
category = "地下";
|
||||
}
|
||||
|
||||
if ("下界".equals(category)
|
||||
|| w.getEnvironment()
|
||||
== org.bukkit.World
|
||||
.Environment.NETHER) {
|
||||
category = "下界";
|
||||
} else if ("末地".equals(category)
|
||||
|| w.getEnvironment()
|
||||
== org.bukkit.World
|
||||
.Environment.THE_END) {
|
||||
category = "末地";
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
plugin.getLogger().warning(
|
||||
"[QuestTracker] 群系读取失败: "
|
||||
+ ex.getMessage());
|
||||
}
|
||||
|
||||
plugin.getLogger().info(
|
||||
"[QuestTracker] 打卡: "
|
||||
+ player
|
||||
+ " world=" + worldName
|
||||
+ " biome=" + biome
|
||||
+ " cat=" + category
|
||||
+ " pos="
|
||||
+ String.format(
|
||||
"%.0f,%.0f,%.0f",
|
||||
x, y, z));
|
||||
|
||||
saveCheckInPosition(
|
||||
player, x, y, z);
|
||||
recordCheckIn(
|
||||
player, biome, category,
|
||||
worldName, x, y, z);
|
||||
List<String> matched =
|
||||
checkInBiome(
|
||||
player, biome,
|
||||
worldName, x, y, z);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("§a打卡成功!群系: §e")
|
||||
.append(category);
|
||||
if (!matched.isEmpty()) {
|
||||
sb.append("\n§a完成任务条件:");
|
||||
for (String m : matched) {
|
||||
String qn =
|
||||
findQuestName(m);
|
||||
sb.append("\n§7• ");
|
||||
if (qn != null) {
|
||||
sb.append("§e[")
|
||||
.append(qn)
|
||||
.append("§7] §f");
|
||||
}
|
||||
sb.append(m);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据条件文本查找所属任务名
|
||||
*/
|
||||
private String findQuestName(
|
||||
String condition) {
|
||||
for (String cat : Arrays.asList(
|
||||
"新人任务",
|
||||
"主线任务",
|
||||
"支线任务")) {
|
||||
for (QuestFile qf :
|
||||
getQuests(cat)) {
|
||||
if (qf.conditions.contains(
|
||||
condition)) {
|
||||
return qf.displayName;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 加载玩家所有历史打卡坐标
|
||||
* 格式: x1,y1,z1;x2,y2,z2;...
|
||||
*/
|
||||
private List<double[]> loadCheckInPositions(
|
||||
String player) {
|
||||
List<double[]> list = new ArrayList<>();
|
||||
Object val = storage.getCondition(
|
||||
player, "checkin_all_pos");
|
||||
if (val == null) return list;
|
||||
String data = val.toString();
|
||||
if (data.isEmpty()) return list;
|
||||
String[] records = data.split(";");
|
||||
for (String r : records) {
|
||||
String[] parts = r.split(",");
|
||||
if (parts.length >= 3) {
|
||||
try {
|
||||
list.add(new double[]{
|
||||
Double.parseDouble(parts[0]),
|
||||
Double.parseDouble(parts[1]),
|
||||
Double.parseDouble(parts[2])});
|
||||
} catch (NumberFormatException e) {
|
||||
// 跳过损坏数据
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存打卡坐标(追加到已有记录)
|
||||
*/
|
||||
private void saveCheckInPosition(
|
||||
String player, double x,
|
||||
double y, double z) {
|
||||
List<double[]> list =
|
||||
loadCheckInPositions(player);
|
||||
list.add(new double[]{x, y, z});
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (double[] pos : list) {
|
||||
if (sb.length() > 0) sb.append(";");
|
||||
sb.append(pos[0]).append(",")
|
||||
.append(pos[1]).append(",")
|
||||
.append(pos[2]);
|
||||
}
|
||||
storage.setConditionRaw(
|
||||
player,
|
||||
"checkin_all_pos",
|
||||
sb.toString());
|
||||
}
|
||||
// ========== 中文生物名 → EntityType 映射 ==========
|
||||
private static final Map<String, String>
|
||||
MOB_NAME_MAP = new HashMap<>();
|
||||
static {
|
||||
MOB_NAME_MAP.put("洞穴蜘蛛", "CAVE_SPIDER");
|
||||
MOB_NAME_MAP.put("骷髅", "SKELETON");
|
||||
MOB_NAME_MAP.put("僵尸", "ZOMBIE");
|
||||
MOB_NAME_MAP.put("苦力怕", "CREEPER");
|
||||
MOB_NAME_MAP.put("蜘蛛", "SPIDER");
|
||||
MOB_NAME_MAP.put("末影人", "ENDERMAN");
|
||||
MOB_NAME_MAP.put("女巫", "WITCH");
|
||||
MOB_NAME_MAP.put("烈焰人", "BLAZE");
|
||||
MOB_NAME_MAP.put("僵尸猪灵",
|
||||
"ZOMBIFIED_PIGLIN");
|
||||
MOB_NAME_MAP.put("猪灵", "PIGLIN");
|
||||
MOB_NAME_MAP.put("恶魂", "GHAST");
|
||||
MOB_NAME_MAP.put("凋灵骷髅",
|
||||
"WITHER_SKELETON");
|
||||
MOB_NAME_MAP.put("史莱姆", "SLIME");
|
||||
MOB_NAME_MAP.put("岩浆怪", "MAGMA_CUBE");
|
||||
MOB_NAME_MAP.put("溺尸", "DROWNED");
|
||||
MOB_NAME_MAP.put("尸壳", "HUSK");
|
||||
MOB_NAME_MAP.put("流髑", "STRAY");
|
||||
MOB_NAME_MAP.put("幻翼", "PHANTOM");
|
||||
MOB_NAME_MAP.put("守卫者", "GUARDIAN");
|
||||
MOB_NAME_MAP.put("远古守卫者",
|
||||
"ELDER_GUARDIAN");
|
||||
MOB_NAME_MAP.put("掠夺者", "PILLAGER");
|
||||
MOB_NAME_MAP.put("卫道士", "VINDICATOR");
|
||||
MOB_NAME_MAP.put("唤魔者", "EVOKER");
|
||||
MOB_NAME_MAP.put("恼鬼", "VEX");
|
||||
MOB_NAME_MAP.put("劫掠兽", "RAVAGER");
|
||||
MOB_NAME_MAP.put("潜影贝", "SHULKER");
|
||||
MOB_NAME_MAP.put("末影螨", "ENDERMITE");
|
||||
MOB_NAME_MAP.put("凋灵", "WITHER");
|
||||
MOB_NAME_MAP.put("末影龙", "ENDER_DRAGON");
|
||||
MOB_NAME_MAP.put("监守者", "WARDEN");
|
||||
MOB_NAME_MAP.put("嗅探兽", "SNIFFER");
|
||||
MOB_NAME_MAP.put("僵尸村民",
|
||||
"ZOMBIE_VILLAGER");
|
||||
}
|
||||
|
||||
/**
|
||||
* 从条件文本中提取所有匹配的生物类型
|
||||
* 按名称长度降序匹配,避免短名误匹配
|
||||
*/
|
||||
private List<String> extractMobTypes(
|
||||
String text) {
|
||||
List<String> types = new ArrayList<>();
|
||||
List<Map.Entry<String, String>> sorted =
|
||||
new ArrayList<>(
|
||||
MOB_NAME_MAP.entrySet());
|
||||
sorted.sort((a, b) ->
|
||||
b.getKey().length()
|
||||
- a.getKey().length());
|
||||
String remaining = text;
|
||||
for (Map.Entry<String, String> entry
|
||||
: sorted) {
|
||||
if (remaining.contains(
|
||||
entry.getKey())) {
|
||||
if (!types.contains(
|
||||
entry.getValue())) {
|
||||
types.add(entry.getValue());
|
||||
}
|
||||
remaining = remaining.replace(
|
||||
entry.getKey(), "");
|
||||
}
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* EntityType → 中文名
|
||||
*/
|
||||
private String reverseMobName(
|
||||
String entityType) {
|
||||
for (Map.Entry<String, String> entry
|
||||
: MOB_NAME_MAP.entrySet()) {
|
||||
if (entry.getValue()
|
||||
.equals(entityType)) {
|
||||
return entry.getKey();
|
||||
}
|
||||
}
|
||||
return entityType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从条件文本中提取矿物名
|
||||
* "采集任意矿物(煤炭除外)1组"
|
||||
* → [COAL_ORE, IRON_ORE, GOLD_ORE, ...]
|
||||
*/
|
||||
private List<String> extractMaterialTypes(
|
||||
String text) {
|
||||
List<String> types = new ArrayList<>();
|
||||
// 排除列表
|
||||
List<String> excludes =
|
||||
new ArrayList<>();
|
||||
if (text.contains("煤炭除外")) {
|
||||
excludes.add("COAL");
|
||||
excludes.add("COAL_ORE");
|
||||
excludes.add("DEEPSLATE_COAL_ORE");
|
||||
}
|
||||
// 通配符:"矿物" "矿石"
|
||||
if (text.contains("矿物")
|
||||
|| text.contains("矿石")) {
|
||||
String[] ores = {
|
||||
"COAL_ORE",
|
||||
"DEEPSLATE_COAL_ORE",
|
||||
"IRON_ORE",
|
||||
"DEEPSLATE_IRON_ORE",
|
||||
"COPPER_ORE",
|
||||
"DEEPSLATE_COPPER_ORE",
|
||||
"GOLD_ORE",
|
||||
"DEEPSLATE_GOLD_ORE",
|
||||
"DIAMOND_ORE",
|
||||
"DEEPSLATE_DIAMOND_ORE",
|
||||
"EMERALD_ORE",
|
||||
"DEEPSLATE_EMERALD_ORE",
|
||||
"LAPIS_ORE",
|
||||
"DEEPSLATE_LAPIS_ORE",
|
||||
"REDSTONE_ORE",
|
||||
"DEEPSLATE_REDSTONE_ORE",
|
||||
"NETHER_GOLD_ORE",
|
||||
"NETHER_QUARTZ_ORE",
|
||||
"ANCIENT_DEBRIS"
|
||||
};
|
||||
for (String ore : ores) {
|
||||
if (!excludes.contains(ore)) {
|
||||
types.add(ore);
|
||||
}
|
||||
}
|
||||
return types;
|
||||
}
|
||||
// 单个矿物名
|
||||
if (text.contains("煤炭"))
|
||||
types.add("COAL");
|
||||
if (text.contains("铁矿")
|
||||
|| text.contains("铁锭"))
|
||||
types.add("RAW_IRON");
|
||||
if (text.contains("金矿")
|
||||
|| text.contains("金锭"))
|
||||
types.add("RAW_GOLD");
|
||||
if (text.contains("钻石"))
|
||||
types.add("DIAMOND");
|
||||
if (text.contains("绿宝石"))
|
||||
types.add("EMERALD");
|
||||
if (text.contains("青金石"))
|
||||
types.add("LAPIS_LAZULI");
|
||||
if (text.contains("红石"))
|
||||
types.add("REDSTONE");
|
||||
if (text.contains("铜"))
|
||||
types.add("RAW_COPPER");
|
||||
if (text.contains("下界石英")
|
||||
|| text.contains("石英"))
|
||||
types.add("QUARTZ");
|
||||
return types;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从条件文本中提取目标群系分类
|
||||
@@ -2108,6 +2842,16 @@ public class QuestTracker {
|
||||
}
|
||||
}
|
||||
|
||||
if (key.contains("村民")
|
||||
&& key.contains("交易")) {
|
||||
int needed = parseNumberFromText(key);
|
||||
if (needed <= 0) needed = 1;
|
||||
return getCounter(
|
||||
player, "VILLAGER_TRADE")
|
||||
>= needed;
|
||||
}
|
||||
|
||||
|
||||
if (key.startsWith("KILL_PLAYER")) {
|
||||
String[] p = key.split(":");
|
||||
int n = p.length >= 2
|
||||
@@ -2200,6 +2944,63 @@ public class QuestTracker {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// ===== 泛解析:击杀类中文条件 =====
|
||||
if (key.contains("击杀") || key.contains("猎杀")
|
||||
|| key.contains("消灭")) {
|
||||
int needed = parseNumberFromText(key);
|
||||
if (needed <= 0) needed = 1;
|
||||
List<String> mobTypes = extractMobTypes(key);
|
||||
if (!mobTypes.isEmpty()) {
|
||||
int total = 0;
|
||||
for (String mobType : mobTypes) {
|
||||
total += getCounter(player,
|
||||
"KILL:" + mobType);
|
||||
}
|
||||
return total >= needed;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 泛解析:村民交易条件 =====
|
||||
if (key.contains("交易")
|
||||
&& (key.contains("村民")
|
||||
|| key.contains("与村民"))) {
|
||||
int needed = parseNumberFromText(key);
|
||||
if (needed <= 0) needed = 1;
|
||||
return getCounter(player, "TRADE")
|
||||
>= needed;
|
||||
}
|
||||
|
||||
// ===== 泛解析:采集/挖矿类条件 =====
|
||||
if (key.contains("采集") || key.contains("挖")) {
|
||||
int needed = parseNumberFromText(key);
|
||||
if (needed <= 0) needed = 1;
|
||||
List<String> matTypes =
|
||||
extractMaterialTypes(key);
|
||||
if (!matTypes.isEmpty()) {
|
||||
int total = 0;
|
||||
for (String mat : matTypes) {
|
||||
total += getCounter(player,
|
||||
"MINE:" + mat);
|
||||
}
|
||||
return total >= needed;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 泛解析:合成类条件 =====
|
||||
if (key.contains("合成") || key.contains("制作")) {
|
||||
int needed = parseNumberFromText(key);
|
||||
if (needed <= 0) needed = 1;
|
||||
return getCounter(player, "CRAFT")
|
||||
>= needed;
|
||||
}
|
||||
|
||||
// ===== 泛解析:钓鱼类条件 =====
|
||||
if (key.contains("钓鱼") || key.contains("钓")) {
|
||||
int needed = parseNumberFromText(key);
|
||||
if (needed <= 0) needed = 1;
|
||||
return getCounter(player, "FISH")
|
||||
>= needed;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -2271,6 +3072,12 @@ public class QuestTracker {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void onVillagerTrade(String player) {
|
||||
String key = "VILLAGER_TRADE";
|
||||
int cur = getCounter(player, key);
|
||||
setCounter(player, key, cur + 1);
|
||||
}
|
||||
|
||||
private long getCounterLong(
|
||||
String player, String key) {
|
||||
Object val = storage.getCondition(
|
||||
|
||||
@@ -4,30 +4,34 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
|
||||
import org.bukkit.event.player
|
||||
.PlayerResourcePackStatusEvent;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.concurrent
|
||||
.ConcurrentHashMap;
|
||||
|
||||
public class RadioDownloadListener
|
||||
implements Listener {
|
||||
|
||||
private final Main plugin;
|
||||
private final Logger log;
|
||||
private final Map<UUID, Integer> retryCount =
|
||||
new ConcurrentHashMap<>();
|
||||
private final Map<UUID, Integer> totalAttempts =
|
||||
new ConcurrentHashMap<>();
|
||||
private static final int MAX_RETRY = 3;
|
||||
// 每位玩家最多总共尝试5次,防死循环
|
||||
private static final int MAX_TOTAL = 5;
|
||||
private final java.util.logging.Logger log;
|
||||
|
||||
private final ConcurrentHashMap<UUID, Integer>
|
||||
failCount = new ConcurrentHashMap<>();
|
||||
private final ConcurrentHashMap<UUID, Boolean>
|
||||
blocked = new ConcurrentHashMap<>();
|
||||
|
||||
private static final int MAX_FAILED = 3;
|
||||
|
||||
public RadioDownloadListener(Main plugin) {
|
||||
this.plugin = plugin;
|
||||
this.log = plugin.getLogger();
|
||||
}
|
||||
|
||||
public void onPlayerQuit(UUID uuid) {
|
||||
failCount.remove(uuid);
|
||||
blocked.remove(uuid);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -35,84 +39,142 @@ public class RadioDownloadListener
|
||||
PlayerResourcePackStatusEvent e) {
|
||||
Player p = e.getPlayer();
|
||||
UUID uuid = p.getUniqueId();
|
||||
String status = e.getStatus().name();
|
||||
String status =
|
||||
e.getStatus().name();
|
||||
|
||||
log.info("[Radio] " + p.getName()
|
||||
+ " 资源包: " + status);
|
||||
log.info("[Radio] === 资源包状态 ===");
|
||||
log.info("[Radio] 玩家: "
|
||||
+ p.getName());
|
||||
log.info("[Radio] UUID: " + uuid);
|
||||
log.info("[Radio] 状态: "
|
||||
+ status);
|
||||
log.info("[Radio] 原始状态枚举: "
|
||||
+ e.getStatus().getClass()
|
||||
.getSimpleName()
|
||||
+ "."
|
||||
+ e.getStatus().name());
|
||||
|
||||
if (blocked.containsKey(uuid)) {
|
||||
log.info("[Radio] 已熔断,跳过: "
|
||||
+ p.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
case "SUCCESS":
|
||||
log.info("[Radio] " + p.getName()
|
||||
+ " 资源包加载成功");
|
||||
retryCount.remove(uuid);
|
||||
totalAttempts.remove(uuid);
|
||||
log.info("[Radio] "
|
||||
+ p.getName()
|
||||
+ " ✓ 资源包加载成功");
|
||||
failCount.remove(uuid);
|
||||
blocked.remove(uuid);
|
||||
break;
|
||||
|
||||
case "FAILED_DOWNLOAD":
|
||||
int retry = retryCount
|
||||
.getOrDefault(uuid, 0) + 1;
|
||||
int total = totalAttempts
|
||||
.getOrDefault(uuid, 0) + 1;
|
||||
retryCount.put(uuid, retry);
|
||||
totalAttempts.put(uuid, total);
|
||||
|
||||
log.warning("[Radio] " + p.getName()
|
||||
+ " 下载失败 (重试"
|
||||
+ retry + "/" + MAX_RETRY
|
||||
+ ", 总计" + total
|
||||
+ "/" + MAX_TOTAL + ")");
|
||||
|
||||
if (total >= MAX_TOTAL) {
|
||||
p.sendMessage(
|
||||
"§7[Radio] §f资源包加载失败,跳过");
|
||||
retryCount.remove(uuid);
|
||||
totalAttempts.remove(uuid);
|
||||
break;
|
||||
}
|
||||
|
||||
if (retry > MAX_RETRY) {
|
||||
retryCount.put(uuid, 0);
|
||||
Bukkit.getScheduler()
|
||||
.runTaskLater(plugin,
|
||||
() -> {
|
||||
if (p.isOnline()
|
||||
&& plugin
|
||||
.radio
|
||||
!= null) {
|
||||
plugin.radio
|
||||
.sendResourcePack(
|
||||
p);
|
||||
}
|
||||
}, 100L);
|
||||
break;
|
||||
}
|
||||
|
||||
p.sendMessage(
|
||||
"§e[Radio] §f下载失败,重试中...");
|
||||
Bukkit.getScheduler()
|
||||
.runTaskLater(plugin,
|
||||
() -> {
|
||||
if (p.isOnline()
|
||||
&& plugin.radio
|
||||
!= null) {
|
||||
plugin.radio
|
||||
.sendResourcePack(
|
||||
p);
|
||||
}
|
||||
}, 60L);
|
||||
case "ACCEPTED":
|
||||
log.info("[Radio] "
|
||||
+ p.getName()
|
||||
+ " 客户端已接受,"
|
||||
+ "等待下载...");
|
||||
break;
|
||||
|
||||
case "DECLINED":
|
||||
log.info("[Radio] " + p.getName()
|
||||
+ " 拒绝下载");
|
||||
retryCount.remove(uuid);
|
||||
totalAttempts.remove(uuid);
|
||||
log.warning("[Radio] "
|
||||
+ p.getName()
|
||||
+ " ✗ 拒绝了资源包");
|
||||
log.warning("[Radio] "
|
||||
+ "可能原因: "
|
||||
+ "1.客户端设置禁用资源包"
|
||||
+ " 2.已缓存拒绝记录"
|
||||
+ " 3.SSL证书不匹配");
|
||||
handleFailure(p, uuid);
|
||||
break;
|
||||
|
||||
case "FAILED_DOWNLOAD":
|
||||
log.warning("[Radio] "
|
||||
+ p.getName()
|
||||
+ " ✗ 下载失败");
|
||||
log.warning("[Radio] "
|
||||
+ "可能原因: "
|
||||
+ "1.URL无法访问"
|
||||
+ " 2.SSL证书错误"
|
||||
+ " 3.网络超时"
|
||||
+ " 4.文件不存在(404)");
|
||||
handleFailure(p, uuid);
|
||||
break;
|
||||
|
||||
default:
|
||||
retryCount.remove(uuid);
|
||||
totalAttempts.remove(uuid);
|
||||
log.info("[Radio] "
|
||||
+ p.getName()
|
||||
+ " 未知状态: "
|
||||
+ status);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleFailure(
|
||||
Player p, UUID uuid) {
|
||||
int failNum = failCount
|
||||
.getOrDefault(uuid, 0) + 1;
|
||||
failCount.put(uuid, failNum);
|
||||
|
||||
log.warning("[Radio] "
|
||||
+ p.getName()
|
||||
+ " 失败次数: "
|
||||
+ failNum + "/" + MAX_FAILED);
|
||||
|
||||
if (failNum >= MAX_FAILED) {
|
||||
blocked.put(uuid, true);
|
||||
log.severe("[Radio] "
|
||||
+ p.getName()
|
||||
+ " 已达最大失败次数,"
|
||||
+ "触发踢出");
|
||||
Bukkit.getScheduler()
|
||||
.runTaskLater(plugin,
|
||||
() -> {
|
||||
Player kp =
|
||||
Bukkit
|
||||
.getPlayer(
|
||||
uuid);
|
||||
if (kp != null
|
||||
&& kp
|
||||
.isOnline()) {
|
||||
kp.kickPlayer(
|
||||
"§c资源包"
|
||||
+ "加载失败"
|
||||
+ "("
|
||||
+ MAX_FAILED
|
||||
+ "次),"
|
||||
+ "请联系管理员");
|
||||
}
|
||||
}, 1L);
|
||||
return;
|
||||
}
|
||||
|
||||
p.sendMessage(
|
||||
"§e§l[Radio] 下载失败,"
|
||||
+ "重试... ("
|
||||
+ failNum + "/"
|
||||
+ MAX_FAILED + ")");
|
||||
|
||||
// 5秒后重试
|
||||
Bukkit.getScheduler()
|
||||
.runTaskLater(plugin,
|
||||
() -> {
|
||||
if (p.isOnline()
|
||||
&& plugin
|
||||
.radio
|
||||
!= null) {
|
||||
plugin.getLogger()
|
||||
.info(
|
||||
"[Radio] "
|
||||
+ "第"
|
||||
+ failNum
|
||||
+ "次重试: "
|
||||
+ p
|
||||
.getName());
|
||||
plugin.radio
|
||||
.sendResourcePack(
|
||||
p);
|
||||
}
|
||||
}, 100L);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ public class RadioManager {
|
||||
("{\n \"pack\": {\n"
|
||||
+ " \"pack_format\": 54,\n"
|
||||
+ " \"description\":"
|
||||
+ " \"Sdf1 Radio\"\n }\n}")
|
||||
+ " \"为保证服务器正常运行,请勿拒绝资源包!\"\n }\n}")
|
||||
.getBytes("UTF-8"));
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
@@ -412,15 +412,24 @@ public class RadioManager {
|
||||
*/
|
||||
public void sendResourcePack(Player p) {
|
||||
UUID uuid = p.getUniqueId();
|
||||
if (pendingPack.contains(uuid)) return;
|
||||
if (pendingPack.contains(uuid)) {
|
||||
plugin.getLogger().info(
|
||||
"[Radio] 跳过(已等待): "
|
||||
+ p.getName());
|
||||
return;
|
||||
}
|
||||
pendingPack.add(uuid);
|
||||
Bukkit.getScheduler().runTaskLater(
|
||||
plugin, () -> {
|
||||
Bukkit.getScheduler()
|
||||
.runTaskLater(plugin, () -> {
|
||||
pendingPack.remove(uuid);
|
||||
}, 200L);
|
||||
|
||||
String url = getResourcePackUrl();
|
||||
if (url == null || url.isEmpty()) {
|
||||
plugin.getLogger().warning(
|
||||
"[Radio] URL为空,"
|
||||
+ "跳过发送: "
|
||||
+ p.getName());
|
||||
pendingPack.remove(uuid);
|
||||
return;
|
||||
}
|
||||
@@ -429,98 +438,85 @@ public class RadioManager {
|
||||
plugin.getDataFolder(),
|
||||
"radiopack.zip");
|
||||
if (!zip.exists()) {
|
||||
plugin.getLogger().warning(
|
||||
"[Radio] radiopack.zip不存在,"
|
||||
+ "跳过: " + p.getName());
|
||||
pendingPack.remove(uuid);
|
||||
return;
|
||||
}
|
||||
|
||||
// 异步:下载远程zip → 算hash → 比对本地hash
|
||||
final Player fp = p;
|
||||
final String finalUrl = url + "?t="
|
||||
+ System.currentTimeMillis();
|
||||
try {
|
||||
byte[] data =
|
||||
Files.readAllBytes(zip.toPath());
|
||||
String hash = sha1(data);
|
||||
long fileSize = zip.length();
|
||||
|
||||
Bukkit.getScheduler()
|
||||
.runTaskAsynchronously(plugin, () -> {
|
||||
try {
|
||||
// 1. 本地hash
|
||||
byte[] localData =
|
||||
Files.readAllBytes(
|
||||
zip.toPath());
|
||||
String localHash =
|
||||
sha1(localData);
|
||||
plugin.getLogger().info(
|
||||
"[Radio] === 发送资源包 ===");
|
||||
plugin.getLogger().info(
|
||||
"[Radio] 玩家: " + p.getName());
|
||||
plugin.getLogger().info(
|
||||
"[Radio] URL: " + url);
|
||||
plugin.getLogger().info(
|
||||
"[Radio] Hash: " + hash);
|
||||
plugin.getLogger().info(
|
||||
"[Radio] 文件大小: "
|
||||
+ fileSize + " bytes ("
|
||||
+ String.format("%.1f",
|
||||
fileSize / 1024.0)
|
||||
+ " KB)");
|
||||
plugin.getLogger().info(
|
||||
"[Radio] 客户端版本: "
|
||||
+ p.getProtocolVersion());
|
||||
|
||||
// 2. 远程hash
|
||||
byte[] remoteData =
|
||||
downloadBytes(finalUrl);
|
||||
String remoteHash =
|
||||
sha1(remoteData);
|
||||
sendPackWithHash(p, url, hash);
|
||||
|
||||
// 3. 比对
|
||||
plugin.getLogger().info(
|
||||
"[Radio] 本地hash: "
|
||||
+ localHash);
|
||||
plugin.getLogger().info(
|
||||
"[Radio] 远程hash: "
|
||||
+ remoteHash);
|
||||
|
||||
if (!localHash.equals(remoteHash)) {
|
||||
plugin.getLogger().warning(
|
||||
"[Radio] hash不一致,"
|
||||
+ "跳过发送资源包");
|
||||
plugin.getLogger().warning(
|
||||
"[Radio] 请更新远程"
|
||||
+ "radiopack.zip");
|
||||
Bukkit.getScheduler()
|
||||
.runTask(plugin, () -> {
|
||||
fp.sendMessage(
|
||||
"§7[Radio] §f资源包"
|
||||
+ "版本不一致,"
|
||||
+ "跳过安装");
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// 4. hash一致,发送给客户端
|
||||
Bukkit.getScheduler()
|
||||
.runTask(plugin, () -> {
|
||||
sendPackWithHash(
|
||||
fp, finalUrl,
|
||||
remoteHash);
|
||||
});
|
||||
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warning(
|
||||
"[Radio] 校验失败: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().severe(
|
||||
"[Radio] 发送异常: "
|
||||
+ p.getName());
|
||||
e.printStackTrace();
|
||||
pendingPack.remove(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendPackWithHash(
|
||||
Player p, String url, String hash) {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
|
||||
// Paper 1.21: setResourcePack(UUID, String, String, Component, boolean)
|
||||
|
||||
private void sendPackWithHash(
|
||||
Player p,
|
||||
String url,
|
||||
String hash) {
|
||||
UUID uuid = UUID.fromString(
|
||||
"a1b2c3d4-e5f6-7890-abcd-"
|
||||
+ "ef1234567890");
|
||||
|
||||
try {
|
||||
Object component = net.kyori.adventure
|
||||
.text.Component.text("Sdf1 Radio");
|
||||
Object component =
|
||||
net.kyori.adventure.text
|
||||
.Component.text(
|
||||
"§d§l服务器需要自定义资源包,请您点击'继续'由客户端自动下载即可");
|
||||
p.getClass().getMethod(
|
||||
"setResourcePack",
|
||||
UUID.class,
|
||||
String.class,
|
||||
String.class,
|
||||
net.kyori.adventure.text
|
||||
net.kyori.adventure
|
||||
.text
|
||||
.Component.class,
|
||||
boolean.class)
|
||||
.invoke(p, uuid, url,
|
||||
hash, component, false);
|
||||
.invoke(
|
||||
p, uuid, url,
|
||||
hash, component,
|
||||
true);
|
||||
plugin.getLogger().info(
|
||||
"[Radio] 发送成功: "
|
||||
+ p.getName());
|
||||
+ p.getName()
|
||||
+ " url="
|
||||
+ url);
|
||||
return;
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
// 降级:旧版 String 签名
|
||||
try {
|
||||
p.getClass().getMethod(
|
||||
"setResourcePack",
|
||||
@@ -529,8 +525,11 @@ public class RadioManager {
|
||||
String.class,
|
||||
String.class,
|
||||
boolean.class)
|
||||
.invoke(p, uuid, url,
|
||||
hash, "Sdf1 Radio", false);
|
||||
.invoke(
|
||||
p, uuid, url,
|
||||
hash,
|
||||
"Sdf1 Radio",
|
||||
true);
|
||||
plugin.getLogger().info(
|
||||
"[Radio] 旧版签名成功: "
|
||||
+ p.getName());
|
||||
@@ -538,14 +537,15 @@ public class RadioManager {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
// 降级3参
|
||||
try {
|
||||
p.getClass().getMethod(
|
||||
"setResourcePack",
|
||||
UUID.class,
|
||||
String.class,
|
||||
String.class)
|
||||
.invoke(p, uuid, url, hash);
|
||||
.invoke(
|
||||
p, uuid, url,
|
||||
hash);
|
||||
plugin.getLogger().info(
|
||||
"[Radio] 3参签名成功: "
|
||||
+ p.getName());
|
||||
@@ -692,19 +692,86 @@ public class RadioManager {
|
||||
}
|
||||
|
||||
public String getResourcePackUrl() {
|
||||
// 有外部配置 → 随机生成URL
|
||||
if (externalUrl != null
|
||||
&& !externalUrl.isEmpty()) {
|
||||
plugin.getLogger().info(
|
||||
"[Radio] 使用外部地址: "
|
||||
+ externalUrl);
|
||||
return externalUrl;
|
||||
&& !externalUrl.trim().isEmpty()) {
|
||||
return generateRandomUrl(externalUrl);
|
||||
}
|
||||
plugin.getLogger().warning(
|
||||
"[Radio] 未配置外部地址,"
|
||||
+ "跳过资源包");
|
||||
return null;
|
||||
// 无配置 → 用内置HTTP
|
||||
int port = 8080;
|
||||
if (plugin.getConfig2() != null) {
|
||||
port = plugin.getConfig2().httpPort;
|
||||
}
|
||||
return "http://127.0.0.1:"
|
||||
+ port + "/radiopack.zip";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 从配置的域名列表中随机选一个
|
||||
* 生成随机、带时间戳的完整资源包URL
|
||||
*
|
||||
* 规则:
|
||||
* *.example.com
|
||||
* → 随机子域+时间戳
|
||||
* 例: a3f7k2.example.com/pack.zip?t=xxx&v=b9c1e4
|
||||
*
|
||||
* cdn.example.com (无*)
|
||||
* → 直接使用+时间戳
|
||||
* 例: cdn.example.com/pack.zip?t=xxx
|
||||
*/
|
||||
private String generateRandomUrl(
|
||||
String raw) {
|
||||
String[] parts = raw.split("\\|");
|
||||
String pick =
|
||||
parts[(int)(Math.random()
|
||||
* parts.length)].trim();
|
||||
|
||||
// 去掉协议 https:// http://
|
||||
String cleaned = pick
|
||||
.replaceFirst("^https?://", "");
|
||||
// 去掉路径 /path/a?v=1
|
||||
if (cleaned.contains("/")) {
|
||||
cleaned = cleaned.substring(
|
||||
0, cleaned.indexOf('/'));
|
||||
}
|
||||
|
||||
// 随机子域
|
||||
String hex = Long.toHexString(
|
||||
Double.doubleToLongBits(
|
||||
Math.random()));
|
||||
String rand = hex.length() > 6
|
||||
? hex.substring(2, 8) : hex;
|
||||
rand = rand.replaceAll(
|
||||
"[^a-z0-9]", "x");
|
||||
|
||||
String host;
|
||||
if (cleaned.startsWith("*")) {
|
||||
host = rand
|
||||
+ cleaned.substring(1);
|
||||
} else {
|
||||
host = cleaned;
|
||||
}
|
||||
|
||||
String ts = String.valueOf(
|
||||
System.currentTimeMillis());
|
||||
String token = Integer.toHexString(
|
||||
(int)(Math.random()
|
||||
* 0xFFFFFF));
|
||||
|
||||
String url = "https://" + host
|
||||
+ "/radiopack.zip"
|
||||
+ "?t=" + ts
|
||||
+ "&v=" + token;
|
||||
|
||||
plugin.getLogger().info(
|
||||
"[Radio] 生成URL: "
|
||||
+ pick + " → " + url);
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// ========== 全服广播 ==========
|
||||
public void startMainRadio() {
|
||||
stopMainRadio();
|
||||
@@ -847,6 +914,12 @@ public class RadioManager {
|
||||
}
|
||||
}
|
||||
|
||||
// 在 init() 或 registerEvents 中保存引用:
|
||||
// this.listener = new RadioDownloadListener(plugin);
|
||||
private RadioDownloadListener radioListener;
|
||||
|
||||
|
||||
|
||||
// ========== 重载 ==========
|
||||
public void reload() {
|
||||
stopMainRadio();
|
||||
|
||||
Reference in New Issue
Block a user