feat: CraftBank Folia 1.21.8 经济与银行核心插件初始实现
实现完整的现金/钱包、银行卡、支票、活期储蓄与定期存款系统, 实现并以 Highest 优先级注册 Vault Economy 接口,接入 PlaceholderAPI。 全程遵循 Folia 调度模型(AsyncScheduler / 实体区域线程), 数据缓存线程安全,支票兑现与定期领取做防刷处理。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
package com.craftbank.util;
|
||||
|
||||
/**
|
||||
* 金额解析与校验工具。统一对金额做四舍五入到 2 位小数, 防止浮点误差刷钱。
|
||||
*/
|
||||
public final class Amounts {
|
||||
|
||||
private Amounts() {
|
||||
}
|
||||
|
||||
/** 将金额规整到 2 位小数 (向下取整到分, 避免凭空多出小数刷钱)。 */
|
||||
public static double normalize(double amount) {
|
||||
return Math.floor(amount * 100.0) / 100.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析用户输入的金额字符串。
|
||||
*
|
||||
* @return 规整后的正数金额, 解析失败或非正数返回 -1。
|
||||
*/
|
||||
public static double parse(String input) {
|
||||
if (input == null || input.isBlank()) {
|
||||
return -1;
|
||||
}
|
||||
double value;
|
||||
try {
|
||||
value = Double.parseDouble(input.trim());
|
||||
} catch (NumberFormatException ex) {
|
||||
return -1;
|
||||
}
|
||||
if (!Double.isFinite(value) || value <= 0) {
|
||||
return -1;
|
||||
}
|
||||
return normalize(value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.craftbank.util;
|
||||
|
||||
import com.craftbank.CraftBank;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* 消息发送辅助。从 config.yml 的 Messages 段读取文案并自动附加前缀。
|
||||
*/
|
||||
public final class Msg {
|
||||
|
||||
private final CraftBank plugin;
|
||||
|
||||
public Msg(CraftBank plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
public String prefix() {
|
||||
return Text.color(plugin.getConfig().getString("Messages.prefix", "&8[&b工艺银行&8] &r"));
|
||||
}
|
||||
|
||||
/** 读取 Messages.<key>, 缺失时回退到 def。 */
|
||||
public String get(String key, String def) {
|
||||
return Text.color(plugin.getConfig().getString("Messages." + key, def));
|
||||
}
|
||||
|
||||
/** 发送一条带前缀的原始 (已含颜色) 文本。 */
|
||||
public void send(CommandSender to, String rawColored) {
|
||||
to.sendMessage(prefix() + rawColored);
|
||||
}
|
||||
|
||||
/** 发送一条带前缀的、应用 & 颜色代码的文本。 */
|
||||
public void raw(CommandSender to, String text) {
|
||||
to.sendMessage(prefix() + Text.color(text));
|
||||
}
|
||||
|
||||
/** 发送 Messages.<key> 的内容 (带前缀)。 */
|
||||
public void key(CommandSender to, String key, String def) {
|
||||
send(to, get(key, def));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.craftbank.util;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 文本与颜色代码处理工具。
|
||||
*/
|
||||
public final class Text {
|
||||
|
||||
private Text() {
|
||||
}
|
||||
|
||||
public static String color(String input) {
|
||||
if (input == null) {
|
||||
return "";
|
||||
}
|
||||
return ChatColor.translateAlternateColorCodes('&', input);
|
||||
}
|
||||
|
||||
public static List<String> color(List<String> input) {
|
||||
List<String> out = new ArrayList<>();
|
||||
if (input == null) {
|
||||
return out;
|
||||
}
|
||||
for (String line : input) {
|
||||
out.add(color(line));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public static String strip(String input) {
|
||||
return input == null ? "" : ChatColor.stripColor(color(input));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user