merge: 合并远程提交(PVP战神榜/债券系统),保留本地虚拟货币/商城系统修改
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
---
|
||||
name: Bug 反馈
|
||||
about: 报告一个 Bug 以帮助改进插件
|
||||
title: "[Bug] "
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
## Bug 描述
|
||||
请简明扼要地描述 Bug 是什么。
|
||||
|
||||
## 复现步骤
|
||||
1. 进入 ...
|
||||
2. 点击 ...
|
||||
3. 出现错误 ...
|
||||
|
||||
## 期望行为
|
||||
描述你期望发生的事情。
|
||||
|
||||
## 实际行为
|
||||
描述实际发生了什么。
|
||||
|
||||
## 服务端信息
|
||||
- 服务器类型和版本(如 Paper 1.21.4):
|
||||
- 插件版本:
|
||||
|
||||
## 截图 / 日志
|
||||
如有相关截图或报错日志,请粘贴在此处。
|
||||
|
||||
## 其他信息
|
||||
补充任何你认为有助于解决问题的信息。
|
||||
@@ -0,0 +1,5 @@
|
||||
blank_issues_enabled: true
|
||||
contact_links:
|
||||
- name: 问题排查指南
|
||||
url: https://github.com/ypsdf1/sdf1_login
|
||||
about: 在提交 Bug 前,请先查阅文档确认是否已有相关说明。
|
||||
@@ -0,0 +1,20 @@
|
||||
---
|
||||
name: 功能新增
|
||||
about: 提出一个新功能的需求建议
|
||||
title: "[Feature] "
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
## 功能描述
|
||||
请描述你希望添加的新功能。
|
||||
|
||||
## 动机
|
||||
为什么需要这个功能?它能解决什么问题?
|
||||
|
||||
## 建议的实现方式
|
||||
如果对实现方式有想法,请在此描述。
|
||||
|
||||
## 额外信息
|
||||
补充任何你认为有助于理解需求的上下文。
|
||||
@@ -0,0 +1,17 @@
|
||||
---
|
||||
name: 建议提交
|
||||
about: 对插件提出改进建议或反馈
|
||||
title: "[Suggestion] "
|
||||
labels: suggestion
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
## 建议内容
|
||||
请描述你的建议或想法。
|
||||
|
||||
## 背景
|
||||
什么场景下产生的这个建议?
|
||||
|
||||
## 预期效果
|
||||
你认为采用这个建议后能达到什么效果?
|
||||
@@ -1,112 +1,407 @@
|
||||
# Sdf1系列登录插件使用说明
|
||||
|
||||
# 特别说明:本插件仅有简中语言版本,如需除简中以外的任何版本,请下载插件源码,自行修改!
|
||||
|
||||
## 1. 功能介绍
|
||||
|
||||
| 名字 | 描述/作用 | 施工状态 |
|
||||
| :--- | :--- | :--- |
|
||||
| 登录 | 用户登录/注册 | 已完成 |
|
||||
| 世界垃圾箱 | 清理服务器凋落物 | 半成品 |
|
||||
| 工单系统 | 用户提交工单 | 已完成 |
|
||||
| 签到系统 | 签到积分换奖励 | 已完成 |
|
||||
| 名字 | 描述/作用 | 施工状态
|
||||
| :--- | :--- | :---
|
||||
| 登录 | 用户登录/注册 | 已完成
|
||||
| 世界垃圾箱 | 清理服务器凋落物 | 已完成
|
||||
| 工单系统 | 用户提交工单 | 已完成
|
||||
| 签到系统 | 签到积分换奖励 | 已完成
|
||||
| 新人礼包 | 新玩家7日礼包 | 已完成
|
||||
| 挂机检测 | 挂机检测踢出 | 已完成
|
||||
| 自定义菜单 | 可以自己diy指令 | 已完成
|
||||
| 自定义菜单图标 | 可以用自己喜欢的物品当图标 | 已完工
|
||||
|
||||
## 2. 安装说明
|
||||
## 2.安装说明:
|
||||
|
||||
| 前置插件 | 选装类型 |
|
||||
| :--- | :--- |
|
||||
| CY_beibao | 可选 |
|
||||
| EssentialsX | 可选 |
|
||||
| :--- | :---
|
||||
| [CY_beibao](https://pan.ypshidifu.cn/s/Ygc0) | 可选
|
||||
| EssentialsX | 可选
|
||||
|
||||
### 2.1 下载
|
||||
您可以从GitHub和Gitee下载插件,将其放入服务器plugin目录,重启服务器即可。
|
||||
您可以从GitHub和Gitee下载到插件,将其丢入服务器plugin目录,重启服务器即可。
|
||||
|
||||
### 2.2 配置文件
|
||||
### 2.2.2 配置文件
|
||||
|
||||
#### 2.2.1 消息.txt
|
||||
此文件控制整个插件的所有提示消息,修改后执行 /sdf1_login reload 重载插件。
|
||||
#### 2.2.2.1 消息.txt
|
||||
此文件控制着整个插件的所有提示消息,您可以根据自己的需求修改,修改后需要执行 /sdf1_login reload 重载插件。支持[颜色代码](https://zh.minecraft.wiki/w/%E6%A0%BC%E5%BC%8F%E5%8C%96%E4%BB%A3%E7%A0%81)<br>
|
||||
同时兼容`<b> </b>`标签,对段落加粗,`\n 和 <br>`进行段落换行
|
||||
|
||||
#### 2.2.2 挂机白名单.txt
|
||||
挂机踢出开启时,该配置下的玩家不受影响。
|
||||
|
||||
#### 2.2.3 SMTP设置.txt
|
||||
控制SMTP邮件服务器配置,用于找回密码时发送邮件。
|
||||
```txt
|
||||
# ==========================================
|
||||
# Sdf1_login 消息配置文件
|
||||
# ==========================================
|
||||
# 颜色代码使用 § 符号
|
||||
# §0黑色 §1深蓝 §2深绿 §3深青
|
||||
# §4深红 §5深紫 §6金色 §7灰色
|
||||
# §8深灰 §9蓝色 §a绿色 §b浅蓝
|
||||
# §c红色 §d粉色 §e黄色 §f白色
|
||||
# §l粗体 §n下划线 §o斜体 §r重置
|
||||
#
|
||||
# 占位符用 {xxx} 表示,运行时自动替换
|
||||
# 支持 <b>粗体</b> 标签
|
||||
# 支持 \n 或 <br> 换行
|
||||
# 修改后执行 /sdf1_login reload 重载
|
||||
# ==========================================
|
||||
|
||||
#### 2.2.4 插件设置.txt
|
||||
管控整个插件,包括账号注册限制、管理员密码等。
|
||||
# ---- 登录注册相关 ----
|
||||
# login_timeout: 登录超时被踢出时的提示
|
||||
login_timeout=§c登录超时,请重新登录
|
||||
# not_registered: 未注册玩家收到的提示
|
||||
not_registered=§e您尚未注册,请使用 /reg <密码>
|
||||
# not_logged_in: 已注册但未登录的提示
|
||||
not_logged_in=§e您尚未登录,请使用 /login <密码>
|
||||
# already_registered: 已注册玩家再次注册时的提示
|
||||
already_registered=§c您已注册过账号
|
||||
# already_logged_in: 已登录玩家再次登录时的提示
|
||||
already_logged_in=§c您已登录
|
||||
# reg_success: 注册成功提示
|
||||
reg_success=§a注册成功!欢迎来到服务器
|
||||
# login_success: 登录成功提示
|
||||
login_success=§a登录成功!
|
||||
# login_failed: 密码错误提示
|
||||
login_failed=§c密码错误,请重试
|
||||
|
||||
#### 2.2.5 chat.txt
|
||||
控制聊天过滤,处理违规链接。
|
||||
# ---- 密码相关 ----
|
||||
# password_wrong: 旧密码验证失败
|
||||
password_wrong=§c密码错误
|
||||
# password_changed: 密码修改成功
|
||||
password_changed=§a密码修改成功!
|
||||
# password_format_error: 密码格式不符合要求
|
||||
password_format_error=§c密码需6位以上,含大小写字母和数字
|
||||
# password_same: 新密码与旧密码相同
|
||||
password_same=§c新密码不能与旧密码相同
|
||||
# reset_no_email: 找回密码时未绑定邮箱
|
||||
reset_no_email=§c您未绑定邮箱,无法找回密码
|
||||
# reset_sent: 临时密码已发送到邮箱
|
||||
reset_sent=§a临时密码已发送到您的邮箱,请查收
|
||||
|
||||
## 3. 指令
|
||||
# ---- 签到积分相关 ----
|
||||
# checkin_already: 今日已签到
|
||||
checkin_already=§c您今日已签到
|
||||
# checkin_success: 签到成功,{points}=获得积分 {streak}=连续天数 {multi}=倍率
|
||||
checkin_success=§a签到成功!获得 {points} 积分,连续 {streak} 天,倍率 x{multi}
|
||||
# points_insufficient: 积分不足
|
||||
points_insufficient=§c积分不足,当前: {points}
|
||||
# points_purchase_success: 积分购买成功
|
||||
points_purchase_success=§a购买成功!消耗 {count} 积分
|
||||
|
||||
- Sdf1_login 主指令
|
||||
- Sdf1_login reload 重载配置
|
||||
- reg 注册账号
|
||||
- login 登录账号
|
||||
- l 登录账号
|
||||
# ---- 挂机检测相关 ----
|
||||
# afk_set_enabled: 挂机检测开启
|
||||
afk_set_enabled=§a挂机检测已开启
|
||||
# afk_set_disabled: 挂机检测关闭
|
||||
afk_set_disabled=§c挂机检测已关闭
|
||||
# afk_kick: 因挂机被踢出
|
||||
afk_kick=§c因挂机过久被踢出
|
||||
|
||||
## 4. 运行截图
|
||||
# ---- 邮箱相关 ----
|
||||
# email_set: 邮箱设置成功
|
||||
email_set=§a邮箱设置成功:{email}
|
||||
# email_format_error: 邮箱格式错误
|
||||
email_format_error=§c邮箱格式不正确
|
||||
|
||||
# ---- 邀请相关 ----
|
||||
# invite_code_generated: 邀请码生成
|
||||
invite_code_generated=§a邀请码:{code}
|
||||
# invite_used: 使用邀请码成功
|
||||
invite_used=§a邀请成功,邀请人:{player}
|
||||
# invite_self: 使用自己的邀请码
|
||||
invite_self=§c不能使用自己的邀请码
|
||||
# invite_not_found: 邀请码不存在
|
||||
invite_not_found=§c邀请码不存在
|
||||
# invite_referral_bonus: 被邀请人签到后邀请人获得奖励
|
||||
invite_referral_bonus=§a邀请奖励!获得 {points} 积分
|
||||
|
||||
# ---- 新人礼包相关 ----
|
||||
# gift_not_ready: 礼包条件未满足
|
||||
gift_not_ready=§c礼包条件未满足
|
||||
# gift_claimed: 礼包领取成功
|
||||
gift_claimed=§a礼包领取成功!
|
||||
|
||||
# ---- 审批与IP限制 ----
|
||||
# need_approval: 注册需审批
|
||||
need_approval=§e注册需审批 (工单#{id})
|
||||
# ip_max_accounts: IP注册已达上限
|
||||
ip_max_accounts=§cIP注册已达上限
|
||||
|
||||
# ---- 管理员操作 ----
|
||||
# admin_delete_confirm: 管理员删除账号确认提示
|
||||
admin_delete_confirm=§c请在聊天中输入玩家名确认删除
|
||||
|
||||
# ---- 聊天过滤 ----
|
||||
# chat_muted: 禁言玩家尝试聊天
|
||||
chat_muted=§c§l[Sdf1_chat] §f你已被禁言,无法聊天
|
||||
# chat_url_blocked: 发送违规链接被拦截
|
||||
# {url}=检测到的链接地址
|
||||
chat_url_blocked=§c§l[Sdf1_chat] §f检测到违规第三方链接: §e{url}
|
||||
# chat_url_violation: 当前违规次数
|
||||
# {count}=当前违规次数
|
||||
chat_url_violation=§7当前违规次数: §e{count}
|
||||
# chat_url_admin_notify: 通知管理员,{player}=玩家名 {url}=链接 {count}=次数
|
||||
chat_url_admin_notify=§e§l[Sdf1_chat] §f{player} 发送违规链接: {url} (第{count}次)
|
||||
# chat_url_broadcast: 全服通报,{player}=玩家名
|
||||
chat_url_broadcast=§c§l[Sdf1_chat] §e{player} §f因发送违规链接被处罚
|
||||
|
||||
# ---- 通用 ----
|
||||
# 未知参数: 未知命令或权限不足时的提示
|
||||
未知参数=§c未知参数或权限不足
|
||||
# only_player: 仅玩家可用的命令
|
||||
# only_player=§c此命令仅玩家可用
|
||||
|
||||
```
|
||||
|
||||
### 2.2.2 挂机白名单.txt
|
||||
当挂机踢出开启时,该配置下的玩家不受挂机提出影响
|
||||
|
||||
### 2.2.3 SMTP设置.txt
|
||||
|
||||
此文件控制着SMTP邮件服务器的配置,用于找回密码时发送邮件。<br>可通过GUI进行配置,也可以手动修改此配置文件。修改后,重载插件即可生效
|
||||
|
||||
```txt
|
||||
# ===== SMTP 邮件服务器配置 =====
|
||||
smtp地址=smtp.example.com
|
||||
smtp端口=465
|
||||
smtp账号=mail@example.com
|
||||
smtp密码=example.com
|
||||
发件人名称=Sdf1_login
|
||||
smtp加密=true
|
||||
验证码接收邮箱=example@example.com
|
||||
|
||||
```
|
||||
|
||||
### 2.2.4 插件设置.txt
|
||||
|
||||
此配置管控这整个插件,包括玩家能注册多少个账号、默认的管理员面板密码多少、tag包含什么视为管理员等
|
||||
|
||||
```txt
|
||||
# ===== Sdf1_login 插件设置 =====
|
||||
管理标签=admin
|
||||
管理密码=qweasd
|
||||
每IP最大账号数=3
|
||||
审批模式=manual
|
||||
自动审批延迟分钟=30
|
||||
登录超时秒数=60
|
||||
挂机踢出=false
|
||||
挂机超时秒数=300
|
||||
服务商积分倍率=2.0
|
||||
基础经济奖励=100
|
||||
经济奖励每评分=50.0
|
||||
报单人积分奖励=10
|
||||
# ---- 签到盲盒奖励 ----
|
||||
签到固定金额=0
|
||||
签到最小金额=10
|
||||
签到最大金额=100
|
||||
签到给积分=true
|
||||
签到积分数量=10
|
||||
|
||||
|
||||
```
|
||||
|
||||
### 2.2.5 chat.txt
|
||||
该文件控制着聊天过滤,当玩家发送违规链接时,会自动根据配置规则进行处理。<br>
|
||||
可用的处罚规则:
|
||||
- warn: 警告
|
||||
- mute: 禁言
|
||||
- kick: 踢出
|
||||
- ban: 封禁
|
||||
- banip:封禁IP
|
||||
|
||||
```txt
|
||||
# Sdf1_chat 聊天过滤配置
|
||||
通知管理员: true
|
||||
全服通报: true
|
||||
禁言时长: 300
|
||||
|
||||
白名单:
|
||||
*.minecraft.net
|
||||
baidu.com
|
||||
github.com
|
||||
|
||||
处罚规则:
|
||||
1:warn:0
|
||||
2:warn:0
|
||||
3:mute:300
|
||||
5:mute:600
|
||||
8:kick:0
|
||||
10:ban:0
|
||||
|
||||
白名单玩家:
|
||||
|
||||
```
|
||||
### 2.2.6 radio_config.txt
|
||||
```txt
|
||||
# ============ Sdf1 Radio Config ============
|
||||
#
|
||||
# resource-pack-url
|
||||
# 填外部地址(HTTP或HTTPS均可)
|
||||
# 例: https://example.com/radiopack.zip
|
||||
# 留空 = 使用内置HTTP服务
|
||||
#
|
||||
# http-port
|
||||
# 内置HTTP端口(仅resource-pack-url为空时生效)
|
||||
#
|
||||
# ============ Settings ===============
|
||||
|
||||
resource-pack-url=https://*.ypshidifu.cn/|*.mcserver.ccwu.cc
|
||||
http-port=443
|
||||
```
|
||||
- radio_config这里可以使用通配符域名,当使用通配符时,系统随机生成url,拒绝过资源包的玩家,每次都会收到提示。并且自1.2版本起,拒绝资源包=放弃游玩服务器。如果您无需广播功能,可以不放ogg文件进入`./plugin/radio/ogg`。这样服务端不会自动生成资源包,也不会强制下载了
|
||||
|
||||
### 2.2.7 菜单.txt
|
||||
- 自定义菜单配置文件
|
||||
|
||||
```json
|
||||
# 服务器菜单
|
||||
# 使用类json格式
|
||||
// 支持使用://Java单行注释、#yml单行注释、/* */块注释,也支持<!--- --->的块注释
|
||||
|
||||
{
|
||||
标题:主城传送
|
||||
指令:/dom tp 主城区 # 这里如果是xxx.txt则表示进入二级目录
|
||||
权限类型:玩家
|
||||
图标:COMPASS
|
||||
}
|
||||
|
||||
{
|
||||
标题:随机传送
|
||||
指令:/rtp
|
||||
权限类型:玩家
|
||||
图标:ENDER_PEARL
|
||||
}
|
||||
|
||||
{
|
||||
标题:擂台比武
|
||||
指令:/dom tp PVP
|
||||
权限类型:玩家
|
||||
图标:netherite_spear
|
||||
}
|
||||
|
||||
{
|
||||
标题:领地操作
|
||||
指令:/dom
|
||||
权限类型:玩家
|
||||
图标:paper
|
||||
}
|
||||
{
|
||||
标题:逛商店
|
||||
指令:/dom tp shop
|
||||
权限类型:玩家
|
||||
图标:honeycomb
|
||||
}
|
||||
|
||||
{
|
||||
标题:传送开关
|
||||
指令:/tptoggle
|
||||
权限类型:玩家
|
||||
图标:redstone_torch
|
||||
}
|
||||
|
||||
{
|
||||
标题:返回上一个位置
|
||||
指令:/back
|
||||
权限类型:玩家
|
||||
图标:red_bed
|
||||
}
|
||||
{
|
||||
标题:前往小黑塔
|
||||
指令:/dom tp 小黑塔
|
||||
权限类型:玩家
|
||||
图标:dragon_head
|
||||
}
|
||||
{
|
||||
标题:云背包
|
||||
指令:/cy
|
||||
权限类型:玩家
|
||||
图标:potato
|
||||
}
|
||||
{
|
||||
标题:自杀
|
||||
指令:/suicide
|
||||
权限类型:玩家
|
||||
图标:wooden_axe
|
||||
}
|
||||
{
|
||||
标题:游戏商人
|
||||
指令:/shop
|
||||
权限类型:玩家
|
||||
图标:shield
|
||||
格子:28
|
||||
}
|
||||
```
|
||||
|
||||
## 3. 指令参数及介绍
|
||||
|
||||
- Sdf1_login 主指令<br>
|
||||
- Sdf1_login reload 重载配置文件<br>
|
||||
- reg 注册账号<br>
|
||||
- login 登录账号<br>
|
||||
- l 登录账号<br>
|
||||
- sdf1_login del 删除玩家账号<br>
|
||||
- sdf1_login radio 停止播放广播<br>
|
||||
- sdf1_login radio reload 重载广播并重新打包资源包
|
||||
- menu 开/关 是否开启自定义菜单
|
||||
|
||||
## 4. 自定义菜单物品
|
||||
- 打开主界面,选择"我的"进入<br>
|
||||

|
||||
- 将你的自定义物品与雪球交换<br>
|
||||

|
||||
- 随后系统会给你重新发放菜单,并且此时图标就是你的自定义物品了
|
||||
|
||||
## 运行截图
|
||||
|
||||
主界面
|
||||
|
||||

|
||||

|
||||
|
||||
邀请数据
|
||||
|
||||

|
||||

|
||||
|
||||
积分商店
|
||||
|
||||

|
||||

|
||||
|
||||
任务中心
|
||||
|
||||

|
||||

|
||||
|
||||
垃圾箱
|
||||
|
||||

|
||||

|
||||
|
||||
管理员面板
|
||||
|
||||

|
||||

|
||||
|
||||
管理面板-用户管理
|
||||

|
||||
|
||||

|
||||
|
||||
工单中心
|
||||
|
||||

|
||||

|
||||
|
||||
工单管理
|
||||
|
||||

|
||||

|
||||
|
||||
我的工单
|
||||

|
||||
|
||||

|
||||
|
||||
提交工单
|
||||
|
||||

|
||||

|
||||
|
||||
服务商列表
|
||||
|
||||

|
||||

|
||||
|
||||
服务商抢单大厅
|
||||
|
||||

|
||||

|
||||
|
||||
服务商-接单界面
|
||||

|
||||
|
||||

|
||||
管理员-工单详情页面
|
||||

|
||||
|
||||
管理员-工单详情
|
||||
|
||||

|
||||
|
||||
## 5. 下载地址
|
||||
|
||||
- GitHub: https://github.com/ypsdf1/sdf1_login
|
||||
- Gitee: https://gitee.com/nihaoshidifu/sdf1_login
|
||||
## 4. 下载地址
|
||||
- GitHub:[https://github.com/ypsdf1/sdf1_login](https://github.com/ypsdf1/sdf1_login)
|
||||
- Gitee:[https://gitee.com/nihaoshidifu/sdf1_login](https://gitee.com/nihaoshidifu/sdf1_login)
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 203 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 155 KiB |
@@ -33,6 +33,7 @@
|
||||
<version>1.21.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.MilkBowl</groupId>
|
||||
<artifactId>VaultAPI</artifactId>
|
||||
|
||||
@@ -0,0 +1,593 @@
|
||||
package Sdf1_login;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import java.io.File;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
|
||||
public class BondManager {
|
||||
|
||||
private final Main plugin;
|
||||
private Connection db;
|
||||
|
||||
// ===== 交易类型常量 =====
|
||||
public static final String TX_ADMIN_GIVE = "admin_give";
|
||||
public static final String TX_ADMIN_DEDUCT = "admin_deduct";
|
||||
public static final String TX_TRANSFER_OUT = "transfer_out";
|
||||
public static final String TX_TRANSFER_IN = "transfer_in";
|
||||
public static final String TX_REDEEM = "redeem";
|
||||
public static final String TX_SHOP_BUY = "shop_buy";
|
||||
public static final String TX_DAILY_SIGN = "daily_sign";
|
||||
public static final String TX_FREEZE = "freeze";
|
||||
public static final String TX_UNFREEZE = "unfreeze";
|
||||
|
||||
public static final int MAX_WATER_DAYS = 14;
|
||||
public static final int ADMIN_MAX_WATER_DAYS = 30;
|
||||
|
||||
public BondManager(Main plugin) {
|
||||
this.plugin = plugin;
|
||||
initDB();
|
||||
}
|
||||
|
||||
// ======================== 数据库初始化 ========================
|
||||
|
||||
private void initDB() {
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
File dbFile = new File(
|
||||
plugin.getDataFolder(), "bond.db");
|
||||
db = DriverManager.getConnection(
|
||||
"jdbc:sqlite:" + dbFile.getAbsolutePath());
|
||||
Statement st = db.createStatement();
|
||||
st.execute("PRAGMA journal_mode=WAL");
|
||||
|
||||
// 债券余额(含冻结状态)
|
||||
st.execute("CREATE TABLE IF NOT EXISTS bonds ("
|
||||
+ "player_name TEXT PRIMARY KEY,"
|
||||
+ "amount INTEGER DEFAULT 0,"
|
||||
+ "status TEXT DEFAULT 'normal')");
|
||||
|
||||
// 兼容旧表
|
||||
try {
|
||||
st.execute("ALTER TABLE bonds "
|
||||
+ "ADD COLUMN status "
|
||||
+ "TEXT DEFAULT 'normal'");
|
||||
} catch (SQLException ignored) {}
|
||||
|
||||
// 旧流水(保留兼容)
|
||||
st.execute("CREATE TABLE IF NOT EXISTS bond_log ("
|
||||
+ "id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
||||
+ "player_name TEXT NOT NULL,"
|
||||
+ "amount INTEGER NOT NULL,"
|
||||
+ "reason TEXT DEFAULT '',"
|
||||
+ "time INTEGER DEFAULT 0)");
|
||||
|
||||
// 新交易流水表
|
||||
st.execute("CREATE TABLE IF NOT EXISTS "
|
||||
+ "bond_transaction ("
|
||||
+ "id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
||||
+ "player_name TEXT NOT NULL,"
|
||||
+ "type TEXT NOT NULL,"
|
||||
+ "amount INTEGER NOT NULL,"
|
||||
+ "target_player TEXT DEFAULT '',"
|
||||
+ "operator TEXT DEFAULT '',"
|
||||
+ "reason TEXT DEFAULT '',"
|
||||
+ "balance_after INTEGER DEFAULT 0,"
|
||||
+ "time INTEGER DEFAULT 0)");
|
||||
|
||||
try {
|
||||
st.execute("CREATE INDEX "
|
||||
+ "IF NOT EXISTS idx_tx_pt "
|
||||
+ "ON bond_transaction("
|
||||
+ "player_name, time)");
|
||||
} catch (SQLException ignored) {}
|
||||
try {
|
||||
st.execute("ALTER TABLE bond_transaction "
|
||||
+ "ADD COLUMN balance_before "
|
||||
+ "INTEGER DEFAULT 0");
|
||||
} catch (SQLException ignored) {}
|
||||
|
||||
|
||||
st.close();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(
|
||||
"[Bond] DB init failed: "
|
||||
+ e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
// ======================== 账户状态 ========================
|
||||
|
||||
public boolean isFrozen(String player) {
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"SELECT status FROM bonds "
|
||||
+ "WHERE player_name=?");
|
||||
ps.setString(1, player);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
String s = rs.getString("status");
|
||||
rs.close(); ps.close();
|
||||
return "frozen".equals(s);
|
||||
}
|
||||
rs.close(); ps.close();
|
||||
} catch (SQLException ignored) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getAccountStatus(String player) {
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"SELECT status FROM bonds "
|
||||
+ "WHERE player_name=?");
|
||||
ps.setString(1, player);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
String s = rs.getString("status");
|
||||
rs.close(); ps.close();
|
||||
return s != null ? s : "normal";
|
||||
}
|
||||
rs.close(); ps.close();
|
||||
} catch (SQLException ignored) {}
|
||||
return "normal";
|
||||
}
|
||||
|
||||
public void freezeAccount(String player) {
|
||||
ensureAccount(player);
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"UPDATE bonds SET status='frozen' "
|
||||
+ "WHERE player_name=?");
|
||||
ps.setString(1, player);
|
||||
ps.executeUpdate(); ps.close();
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
public void unfreezeAccount(String player) {
|
||||
ensureAccount(player);
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"UPDATE bonds SET status='normal' "
|
||||
+ "WHERE player_name=?");
|
||||
ps.setString(1, player);
|
||||
ps.executeUpdate(); ps.close();
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
}
|
||||
|
||||
private void ensureAccount(String player) {
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"INSERT OR IGNORE INTO bonds "
|
||||
+ "(player_name,amount,status) "
|
||||
+ "VALUES (?,0,'normal')");
|
||||
ps.setString(1, player);
|
||||
ps.executeUpdate(); ps.close();
|
||||
} catch (SQLException ignored) {}
|
||||
}
|
||||
|
||||
// ======================== 余额查询 ========================
|
||||
|
||||
public int getBonds(String player) {
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"SELECT amount FROM bonds "
|
||||
+ "WHERE player_name=?");
|
||||
ps.setString(1, player);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
int v = 0;
|
||||
if (rs.next()) v = rs.getInt("amount");
|
||||
rs.close(); ps.close();
|
||||
return v;
|
||||
} catch (SQLException e) { return 0; }
|
||||
}
|
||||
|
||||
// ======================== 增加债券 ========================
|
||||
|
||||
public int addBonds(String player, int amount) {
|
||||
return addBondsInternal(player, amount,
|
||||
TX_ADMIN_GIVE, "", "",
|
||||
"管理员发放");
|
||||
}
|
||||
|
||||
public int addBonds(String player, int amount,
|
||||
String type,
|
||||
String targetPlayer,
|
||||
String operator,
|
||||
String reason) {
|
||||
if (isFrozen(player)) return -1;
|
||||
return addBondsInternal(player, amount,
|
||||
type, targetPlayer, operator, reason);
|
||||
}
|
||||
|
||||
private int addBondsInternal(String player,
|
||||
int amount,
|
||||
String type,
|
||||
String targetPlayer,
|
||||
String operator,
|
||||
String reason) {
|
||||
int before = getBonds(player);
|
||||
int after = before + amount;
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"INSERT INTO bonds "
|
||||
+ "(player_name,amount,status)"
|
||||
+ " VALUES (?,?, 'normal') "
|
||||
+ "ON CONFLICT(player_name) "
|
||||
+ "DO UPDATE SET amount=?");
|
||||
ps.setString(1, player);
|
||||
ps.setInt(2, after);
|
||||
ps.setInt(3, after);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
logTransaction(player, type, amount,
|
||||
targetPlayer, operator, reason,
|
||||
before, after);
|
||||
logLegacy(player, amount);
|
||||
return after;
|
||||
}
|
||||
|
||||
// ======================== 扣除债券 ========================
|
||||
|
||||
|
||||
|
||||
private boolean deductBondsInternal(String player,
|
||||
int amount,
|
||||
String type,
|
||||
String targetPlayer,
|
||||
String operator,
|
||||
String reason) {
|
||||
int before = getBonds(player);
|
||||
if (before < amount) return false;
|
||||
int after = before - amount;
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"UPDATE bonds SET amount=? "
|
||||
+ "WHERE player_name=?");
|
||||
ps.setInt(1, after);
|
||||
ps.setString(2, player);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
logTransaction(player, type, amount,
|
||||
targetPlayer, operator, reason,
|
||||
before, after);
|
||||
logLegacy(player, -amount);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ======================== 流水写入 ========================
|
||||
|
||||
private void logTransaction(String player,
|
||||
String type,
|
||||
int amount,
|
||||
String targetPlayer,
|
||||
String operator,
|
||||
String reason,
|
||||
int balanceBefore,
|
||||
int balanceAfter) {
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"INSERT INTO bond_transaction "
|
||||
+ "(player_name, type, amount,"
|
||||
+ " target_player, operator,"
|
||||
+ " reason, balance_before,"
|
||||
+ " balance_after, time)"
|
||||
+ " VALUES (?,?,?,?,?,?,?,?,?)");
|
||||
ps.setString(1, player);
|
||||
ps.setString(2, type);
|
||||
ps.setInt(3, amount);
|
||||
ps.setString(4,
|
||||
targetPlayer != null
|
||||
? targetPlayer : "");
|
||||
ps.setString(5,
|
||||
operator != null ? operator : "");
|
||||
ps.setString(6,
|
||||
reason != null ? reason : "");
|
||||
ps.setInt(7, balanceBefore);
|
||||
ps.setInt(8, balanceAfter);
|
||||
ps.setLong(9,
|
||||
System.currentTimeMillis());
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ======================== 扣除债券 ========================
|
||||
|
||||
/** 完整版:含冻结检查 + 流水记录 */
|
||||
public boolean deductBonds(String player, int amount,
|
||||
String type,
|
||||
String targetPlayer,
|
||||
String operator,
|
||||
String reason) {
|
||||
if (isFrozen(player)) return false;
|
||||
return deductBondsInternal(player, amount,
|
||||
type, targetPlayer, operator, reason);
|
||||
}
|
||||
|
||||
|
||||
public boolean setBonds(String player, int amount) {
|
||||
ensureAccount(player);
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"INSERT INTO bonds "
|
||||
+ "(player_name,amount,status) "
|
||||
+ "VALUES (?,?, 'normal') "
|
||||
+ "ON CONFLICT(player_name) "
|
||||
+ "DO UPDATE SET amount=?");
|
||||
ps.setString(1, player);
|
||||
ps.setInt(2, amount);
|
||||
ps.setInt(3, amount);
|
||||
ps.executeUpdate(); ps.close();
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
return true;
|
||||
}
|
||||
|
||||
// ======================== 转账 ========================
|
||||
|
||||
public TransferResult transfer(String from,
|
||||
String to,
|
||||
int amount) {
|
||||
if (from.equalsIgnoreCase(to))
|
||||
return new TransferResult(false,
|
||||
"不能给自己转账");
|
||||
if (isFrozen(from))
|
||||
return new TransferResult(false,
|
||||
"你的账户已被冻结");
|
||||
if (isFrozen(to))
|
||||
return new TransferResult(false,
|
||||
to + " 的账户已被冻结");
|
||||
if (isSameIP(from, to))
|
||||
return new TransferResult(false,
|
||||
"不能与同IP玩家转账");
|
||||
|
||||
if (!deductBondsInternal(from, amount,
|
||||
TX_TRANSFER_OUT, to, from,
|
||||
"转账给" + to))
|
||||
return new TransferResult(false, "债券不足");
|
||||
|
||||
addBondsInternal(to, amount,
|
||||
TX_TRANSFER_IN, from, from,
|
||||
"收到来自" + from + "的转账");
|
||||
|
||||
return new TransferResult(true, "转账成功");
|
||||
}
|
||||
|
||||
// ======================== 同IP检测 ========================
|
||||
|
||||
public boolean isSameIP(String p1, String p2) {
|
||||
String ip1 = getPlayerIPAny(p1);
|
||||
String ip2 = getPlayerIPAny(p2);
|
||||
if (ip1 == null || ip2 == null) return false;
|
||||
return ip1.equals(ip2);
|
||||
}
|
||||
|
||||
/** 获取同IP下的所有其他在线玩家 */
|
||||
public List<String> getSameIPPlayers(String player) {
|
||||
String ip = getPlayerIPAny(player);
|
||||
if (ip == null) return Collections.emptyList();
|
||||
List<String> list = new ArrayList<>();
|
||||
for (Player p :
|
||||
plugin.getServer().getOnlinePlayers()) {
|
||||
String pIp = plugin.getPlayerIP(p);
|
||||
if (pIp != null && pIp.equals(ip)
|
||||
&& !p.getName()
|
||||
.equalsIgnoreCase(player)) {
|
||||
list.add(p.getName());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private String getPlayerIPAny(String player) {
|
||||
// 在线:直接取
|
||||
Player p = plugin.getServer()
|
||||
.getPlayerExact(player);
|
||||
if (p != null) {
|
||||
String ip = plugin.getPlayerIP(p);
|
||||
if (ip != null) return ip;
|
||||
}
|
||||
// 离线:查主库
|
||||
try {
|
||||
Object v = plugin.getDb()
|
||||
.getField(player, "last_login_ip");
|
||||
if (v != null) return v.toString();
|
||||
} catch (Exception ignored) {}
|
||||
try {
|
||||
Object v = plugin.getDb()
|
||||
.getField(player, "register_ip");
|
||||
if (v != null) return v.toString();
|
||||
} catch (Exception ignored) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
// ======================== 流水查询 ========================
|
||||
|
||||
public List<Map<String, Object>> getTransactions(
|
||||
String player, int days) {
|
||||
days = Math.min(days, MAX_WATER_DAYS);
|
||||
long cutoff = System.currentTimeMillis()
|
||||
- (long) days * 24 * 60 * 60 * 1000;
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"SELECT * FROM bond_transaction "
|
||||
+ "WHERE player_name=? "
|
||||
+ "AND time>=? "
|
||||
+ "ORDER BY time DESC");
|
||||
ps.setString(1, player);
|
||||
ps.setLong(2, cutoff);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
Map<String, Object> row =
|
||||
new LinkedHashMap<>();
|
||||
row.put("id", rs.getInt("id"));
|
||||
row.put("type", rs.getString("type"));
|
||||
row.put("amount",
|
||||
rs.getInt("amount"));
|
||||
row.put("target_player",
|
||||
rs.getString("target_player"));
|
||||
row.put("operator",
|
||||
rs.getString("operator"));
|
||||
row.put("reason",
|
||||
rs.getString("reason"));
|
||||
row.put("balance_after",
|
||||
rs.getInt("balance_after"));
|
||||
row.put("balance_before", rs.getInt("balance_before"));
|
||||
row.put("time", rs.getLong("time"));
|
||||
list.add(row);
|
||||
}
|
||||
rs.close(); ps.close();
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
return list;
|
||||
}
|
||||
// 放在 getTransactions 方法后面:
|
||||
|
||||
/**
|
||||
* 获取该玩家全部流水(不限时间,供打印使用)
|
||||
*/
|
||||
public List<Map<String, Object>>
|
||||
getAllTransactions(String player) {
|
||||
List<Map<String, Object>> list =
|
||||
new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"SELECT * FROM bond_transaction "
|
||||
+ "WHERE player_name=? "
|
||||
+ "ORDER BY time ASC");
|
||||
ps.setString(1, player);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
Map<String, Object> row =
|
||||
new LinkedHashMap<>();
|
||||
row.put("id", rs.getInt("id"));
|
||||
row.put("player_name",
|
||||
rs.getString("player_name"));
|
||||
row.put("type", rs.getString("type"));
|
||||
row.put("amount",
|
||||
rs.getInt("amount"));
|
||||
row.put("target_player",
|
||||
rs.getString("target_player"));
|
||||
row.put("operator",
|
||||
rs.getString("operator"));
|
||||
row.put("reason",
|
||||
rs.getString("reason"));
|
||||
row.put("balance_after",
|
||||
rs.getInt("balance_after"));
|
||||
row.put("balance_before", rs.getInt("balance_before"));
|
||||
row.put("time", rs.getLong("time"));
|
||||
list.add(row);
|
||||
}
|
||||
rs.close(); ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
// 放在 getAllTransactions 方法后面:
|
||||
|
||||
/**
|
||||
* 获取所有有流水记录的玩家名(去重)
|
||||
*/
|
||||
public List<String> getAllPlayerNames() {
|
||||
List<String> list = new ArrayList<>();
|
||||
try {
|
||||
Statement st = db.createStatement();
|
||||
ResultSet rs = st.executeQuery(
|
||||
"SELECT DISTINCT player_name "
|
||||
+ "FROM bond_transaction "
|
||||
+ "ORDER BY player_name ASC");
|
||||
while (rs.next()) {
|
||||
list.add(rs.getString("player_name"));
|
||||
}
|
||||
rs.close(); st.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<Map<String, Object>>
|
||||
getTransferTransactions(
|
||||
String player, int days) {
|
||||
days = Math.min(days, MAX_WATER_DAYS);
|
||||
long cutoff = System.currentTimeMillis()
|
||||
- (long) days * 24 * 60 * 60 * 1000;
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"SELECT * FROM bond_transaction "
|
||||
+ "WHERE player_name=? "
|
||||
+ "AND time>=? "
|
||||
+ "AND (type=? OR type=?) "
|
||||
+ "ORDER BY time DESC");
|
||||
ps.setString(1, player);
|
||||
ps.setLong(2, cutoff);
|
||||
ps.setString(3, TX_TRANSFER_OUT);
|
||||
ps.setString(4, TX_TRANSFER_IN);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
Map<String, Object> row =
|
||||
new LinkedHashMap<>();
|
||||
row.put("id", rs.getInt("id"));
|
||||
row.put("type", rs.getString("type"));
|
||||
row.put("amount",
|
||||
rs.getInt("amount"));
|
||||
row.put("target_player",
|
||||
rs.getString("target_player"));
|
||||
row.put("reason",
|
||||
rs.getString("reason"));
|
||||
row.put("balance_after",
|
||||
rs.getInt("balance_after"));
|
||||
row.put("balance_before", rs.getInt("balance_before"));
|
||||
row.put("time", rs.getLong("time"));
|
||||
list.add(row);
|
||||
}
|
||||
rs.close(); ps.close();
|
||||
} catch (SQLException e) { e.printStackTrace(); }
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
private void logLegacy(String player, int amount) {
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"INSERT INTO bond_log "
|
||||
+ "(player_name,amount,time) "
|
||||
+ "VALUES (?,?,?)");
|
||||
ps.setString(1, player);
|
||||
ps.setInt(2, amount);
|
||||
ps.setLong(3,
|
||||
System.currentTimeMillis());
|
||||
ps.executeUpdate(); ps.close();
|
||||
} catch (SQLException ignored) {}
|
||||
}
|
||||
|
||||
public Map<String, Object> getLog(
|
||||
String player, int limit) {
|
||||
Map<String, Object> info = new LinkedHashMap<>();
|
||||
info.put("balance", getBonds(player));
|
||||
return info;
|
||||
}
|
||||
|
||||
// ======================== 转账结果 ========================
|
||||
|
||||
public static class TransferResult {
|
||||
public final boolean success;
|
||||
public final String message;
|
||||
public TransferResult(boolean success,
|
||||
String message) {
|
||||
this.success = success;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,356 @@
|
||||
package Sdf1_login;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class BondPrinter {
|
||||
|
||||
private final Main plugin;
|
||||
private final File outputDir;
|
||||
|
||||
private static final SimpleDateFormat FILE_SDF =
|
||||
new SimpleDateFormat(
|
||||
"yyyy-MM-dd_HH-mm-ss");
|
||||
private static final SimpleDateFormat CELL_SDF =
|
||||
new SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
private static final LinkedHashMap<String, String>
|
||||
TYPE_NAMES = new LinkedHashMap<>();
|
||||
|
||||
static {
|
||||
TYPE_NAMES.put("admin_give", "管理员发放");
|
||||
TYPE_NAMES.put("admin_deduct", "管理员扣除");
|
||||
TYPE_NAMES.put("transfer_out", "转出");
|
||||
TYPE_NAMES.put("transfer_in", "转入");
|
||||
TYPE_NAMES.put("redeem", "CDK兑换");
|
||||
TYPE_NAMES.put("shop_buy", "商城购买");
|
||||
TYPE_NAMES.put("daily_sign", "签到奖励");
|
||||
TYPE_NAMES.put("freeze", "冻结");
|
||||
TYPE_NAMES.put("unfreeze", "解冻");
|
||||
}
|
||||
|
||||
public BondPrinter(Main plugin) {
|
||||
this.plugin = plugin;
|
||||
this.outputDir = new File(
|
||||
plugin.getDataFolder(), "printer");
|
||||
if (!this.outputDir.exists()) {
|
||||
this.outputDir.mkdirs();
|
||||
}
|
||||
}
|
||||
|
||||
// ============ 打印单个玩家 ============
|
||||
|
||||
public void printPlayer(String player,
|
||||
CommandSender sender) {
|
||||
Bukkit.getScheduler()
|
||||
.runTaskAsynchronously(plugin,
|
||||
() -> doPrintPlayer(
|
||||
player, sender));
|
||||
}
|
||||
|
||||
private void doPrintPlayer(String player,
|
||||
CommandSender sender) {
|
||||
try {
|
||||
List<Map<String, Object>> txs =
|
||||
plugin.getBonds()
|
||||
.getAllTransactions(player);
|
||||
|
||||
String fileName = player + "_"
|
||||
+ FILE_SDF.format(new Date())
|
||||
+ ".xls";
|
||||
File file = new File(outputDir, fileName);
|
||||
|
||||
deleteOld(player);
|
||||
|
||||
PrintWriter pw = new PrintWriter(
|
||||
new OutputStreamWriter(
|
||||
new FileOutputStream(file),
|
||||
StandardCharsets.UTF_8));
|
||||
try {
|
||||
writeXmlHeader(pw,
|
||||
escXml(player));
|
||||
writeXmlRow(pw,
|
||||
new String[]{
|
||||
"时间", "类型",
|
||||
"金额", "对象",
|
||||
"操作者", "理由",
|
||||
"操作前余额",
|
||||
"操作后余额"});
|
||||
|
||||
for (Map<String, Object> tx : txs) {
|
||||
writeXmlRow(pw, new String[]{
|
||||
txTime(tx),
|
||||
txTypeName(tx),
|
||||
String.valueOf(
|
||||
txInt(tx,
|
||||
"amount")),
|
||||
txStr(tx,
|
||||
"target_player"),
|
||||
txStr(tx, "operator"),
|
||||
txStr(tx, "reason"),
|
||||
String.valueOf(
|
||||
txInt(tx,
|
||||
"balance_before")),
|
||||
String.valueOf(
|
||||
txInt(tx,
|
||||
"balance_after"))
|
||||
});
|
||||
}
|
||||
|
||||
writeXmlFooter(pw);
|
||||
pw.flush();
|
||||
} finally {
|
||||
pw.close();
|
||||
}
|
||||
|
||||
if (sender != null) {
|
||||
sender.sendMessage("§a[打印] §f"
|
||||
+ player + " §a流水已导出");
|
||||
sender.sendMessage("§7文件: §f"
|
||||
+ fileName);
|
||||
sender.sendMessage("§7共 §f"
|
||||
+ txs.size()
|
||||
+ " §7条,§724小时后删除");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (sender != null) {
|
||||
sender.sendMessage("§c导出失败: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
plugin.getLogger().severe(
|
||||
"[Printer] " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ============ 打印全服 ============
|
||||
|
||||
public void printAll(CommandSender sender) {
|
||||
Bukkit.getScheduler()
|
||||
.runTaskAsynchronously(plugin,
|
||||
() -> doPrintAll(sender));
|
||||
}
|
||||
|
||||
private void doPrintAll(CommandSender sender) {
|
||||
try {
|
||||
List<String> players =
|
||||
plugin.getBonds()
|
||||
.getAllPlayerNames();
|
||||
if (players.isEmpty()) {
|
||||
if (sender != null) {
|
||||
sender.sendMessage(
|
||||
"§c没有流水数据");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
String fileName = "全服流水_"
|
||||
+ FILE_SDF.format(new Date())
|
||||
+ ".xls";
|
||||
File file = new File(outputDir, fileName);
|
||||
|
||||
PrintWriter pw = new PrintWriter(
|
||||
new OutputStreamWriter(
|
||||
new FileOutputStream(file),
|
||||
StandardCharsets.UTF_8));
|
||||
try {
|
||||
writeXmlHeader(pw, "全服流水");
|
||||
writeXmlRow(pw,
|
||||
new String[]{
|
||||
"玩家", "时间",
|
||||
"类型", "金额",
|
||||
"对象", "操作者",
|
||||
"理由",
|
||||
"操作前余额",
|
||||
"操作后余额"});
|
||||
|
||||
Set<String> written = new HashSet<>();
|
||||
int totalRows = 0;
|
||||
|
||||
for (String player : players) {
|
||||
List<Map<String, Object>> txs =
|
||||
plugin.getBonds()
|
||||
.getAllTransactions(
|
||||
player);
|
||||
for (Map<String, Object> tx : txs) {
|
||||
int txId = ((Number) tx
|
||||
.get("id"))
|
||||
.intValue();
|
||||
if (!written.add(
|
||||
String.valueOf(
|
||||
txId))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
writeXmlRow(pw, new String[]{
|
||||
player,
|
||||
txTime(tx),
|
||||
txTypeName(tx),
|
||||
String.valueOf(
|
||||
txInt(tx,
|
||||
"amount")),
|
||||
txStr(tx,
|
||||
"target_player"),
|
||||
txStr(tx, "operator"),
|
||||
txStr(tx, "reason"),
|
||||
String.valueOf(
|
||||
txInt(tx,
|
||||
"balance_before")),
|
||||
String.valueOf(
|
||||
txInt(tx,
|
||||
"balance_after"))
|
||||
});
|
||||
totalRows++;
|
||||
}
|
||||
}
|
||||
|
||||
writeXmlFooter(pw);
|
||||
pw.flush();
|
||||
|
||||
if (sender != null) {
|
||||
sender.sendMessage(
|
||||
"§a[打印] §f全服流水"
|
||||
+ " §a已导出");
|
||||
sender.sendMessage("§7文件: §f"
|
||||
+ fileName);
|
||||
sender.sendMessage("§7共 §f"
|
||||
+ players.size()
|
||||
+ " 名玩家,§f"
|
||||
+ totalRows + " §7条");
|
||||
sender.sendMessage(
|
||||
"§724小时后自动删除");
|
||||
}
|
||||
} finally {
|
||||
pw.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (sender != null) {
|
||||
sender.sendMessage("§c导出失败: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
plugin.getLogger().severe(
|
||||
"[Printer] " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// ============ 清理 ============
|
||||
|
||||
public void cleanupOldFiles() {
|
||||
long now = System.currentTimeMillis();
|
||||
long maxAge = 24L * 60 * 60 * 1000;
|
||||
File[] files = outputDir.listFiles(
|
||||
(d, n) -> n.endsWith(".xls"));
|
||||
if (files == null) {
|
||||
return;
|
||||
}
|
||||
int count = 0;
|
||||
for (File f : files) {
|
||||
if (now - f.lastModified() > maxAge) {
|
||||
if (f.delete()) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
plugin.getLogger().info(
|
||||
"[Printer] 清理 "
|
||||
+ count + " 个过期文件");
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteOld(String player) {
|
||||
File[] old = outputDir.listFiles(
|
||||
(d, n) -> n.startsWith(player + "_")
|
||||
&& n.endsWith(".xls"));
|
||||
if (old != null) {
|
||||
for (File f : old) {
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ============ XML工具 ============
|
||||
|
||||
private void writeXmlHeader(PrintWriter pw,
|
||||
String sheetName) {
|
||||
pw.println("<?xml version=\"1.0\"?>");
|
||||
pw.println("<?mso-application "
|
||||
+ "progid=\"Excel.Sheet\"?>");
|
||||
pw.println("<Workbook xmlns="
|
||||
+ "\"urn:schemas-microsoft-com"
|
||||
+ ":office:spreadsheet\"");
|
||||
pw.println(" xmlns:ss="
|
||||
+ "\"urn:schemas-microsoft-com"
|
||||
+ ":office:spreadsheet\">");
|
||||
pw.println(" <Worksheet ss:Name=\""
|
||||
+ sheetName + "\">");
|
||||
pw.println(" <Table>");
|
||||
}
|
||||
|
||||
private void writeXmlRow(PrintWriter pw,
|
||||
String[] cells) {
|
||||
pw.println(" <Row>");
|
||||
for (String cell : cells) {
|
||||
pw.println(" <Cell>"
|
||||
+ "<Data ss:Type=\"String\">"
|
||||
+ escXml(cell != null ? cell : "")
|
||||
+ "</Data></Cell>");
|
||||
}
|
||||
pw.println(" </Row>");
|
||||
}
|
||||
|
||||
private void writeXmlFooter(PrintWriter pw) {
|
||||
pw.println(" </Table>");
|
||||
pw.println(" </Worksheet>");
|
||||
pw.println("</Workbook>");
|
||||
}
|
||||
|
||||
private String escXml(String val) {
|
||||
if (val == null) {
|
||||
return "";
|
||||
}
|
||||
return val.replace("&", "&")
|
||||
.replace("<", "<")
|
||||
.replace(">", ">")
|
||||
.replace("\"", """);
|
||||
}
|
||||
|
||||
private String txTime(Map<String, Object> tx) {
|
||||
Object t = tx.get("time");
|
||||
if (t == null) return "";
|
||||
long ms = ((Number) t).longValue();
|
||||
return CELL_SDF.format(new Date(ms));
|
||||
}
|
||||
|
||||
private String txTypeName(
|
||||
Map<String, Object> tx) {
|
||||
String type = (String) tx.get("type");
|
||||
return TYPE_NAMES.getOrDefault(type, type);
|
||||
}
|
||||
|
||||
private int txInt(Map<String, Object> tx,
|
||||
String key) {
|
||||
Object v = tx.get(key);
|
||||
if (v == null) return 0;
|
||||
return ((Number) v).intValue();
|
||||
}
|
||||
|
||||
private String txStr(Map<String, Object> tx,
|
||||
String key) {
|
||||
Object v = tx.get(key);
|
||||
return v != null ? v.toString() : "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,551 @@
|
||||
package Sdf1_login;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scoreboard.Scoreboard;
|
||||
|
||||
import java.io.*;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
public class CDKManager {
|
||||
|
||||
private final Main plugin;
|
||||
private Connection db;
|
||||
private final Map<String, CDKInput> pendingInputs
|
||||
= new ConcurrentHashMap<>();
|
||||
|
||||
public CDKManager(Main plugin) {
|
||||
this.plugin = plugin;
|
||||
initDB();
|
||||
}
|
||||
|
||||
private void initDB() {
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
File dbFile = new File(
|
||||
plugin.getDataFolder(), "bond.db");
|
||||
db = DriverManager.getConnection(
|
||||
"jdbc:sqlite:" + dbFile.getAbsolutePath());
|
||||
Statement st = db.createStatement();
|
||||
st.execute("PRAGMA journal_mode=WAL");
|
||||
st.execute("CREATE TABLE IF NOT EXISTS cdk ("
|
||||
+ "code TEXT PRIMARY KEY,"
|
||||
+ "amount INTEGER DEFAULT 0,"
|
||||
+ "type TEXT DEFAULT 'bond',"
|
||||
+ "used INTEGER DEFAULT 0,"
|
||||
+ "used_by TEXT DEFAULT '',"
|
||||
+ "created_time INTEGER DEFAULT 0,"
|
||||
+ "used_time INTEGER DEFAULT 0)");
|
||||
st.close();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(
|
||||
"[CDK] DB init failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadCDKsFromDir() {
|
||||
File dir = new File(
|
||||
plugin.getDataFolder(), "cdk");
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
plugin.getLogger().info(
|
||||
"[CDK] 已创建 cdk/ 目录");
|
||||
return;
|
||||
}
|
||||
File[] files = dir.listFiles(
|
||||
(d, n) -> n.endsWith(".txt"));
|
||||
if (files == null || files.length == 0) {
|
||||
plugin.getLogger().warning(
|
||||
"[CDK] cdk/ 目录下"
|
||||
+ "无 .txt 文件");
|
||||
return;
|
||||
}
|
||||
int count = 0;
|
||||
for (File f : files) {
|
||||
int loaded = loadCDKFile(f);
|
||||
plugin.getLogger().info(
|
||||
"[CDK] 文件: " + f.getName()
|
||||
+ " 加载 " + loaded + " 条");
|
||||
count += loaded;
|
||||
}
|
||||
plugin.getLogger().info(
|
||||
"[CDK] 共导入 " + count + " 条");
|
||||
}
|
||||
|
||||
/** 单文件加载,返回成功数 */
|
||||
private int loadCDKFile(File f) {
|
||||
int count = 0;
|
||||
try {
|
||||
BufferedReader br = new BufferedReader(
|
||||
new InputStreamReader(
|
||||
new FileInputStream(f),
|
||||
StandardCharsets.UTF_8));
|
||||
String line;
|
||||
int lineNum = 0;
|
||||
while ((line = br.readLine()) != null) {
|
||||
lineNum++;
|
||||
line = line.trim();
|
||||
if (line.isEmpty()) continue;
|
||||
if (line.startsWith("#")) continue;
|
||||
if (line.startsWith("//")) continue;
|
||||
|
||||
// 支持格式:
|
||||
// CODE 100
|
||||
// CODE,100
|
||||
// CODE 100 bond
|
||||
// CODE,100,bond
|
||||
String[] parts = line
|
||||
.split("[,\\s]+");
|
||||
if (parts.length < 2) {
|
||||
plugin.getLogger().warning(
|
||||
"[CDK] " + f.getName()
|
||||
+ " L" + lineNum
|
||||
+ " 格式错误: "
|
||||
+ line);
|
||||
continue;
|
||||
}
|
||||
|
||||
String code = parts[0].trim();
|
||||
if (code.isEmpty()) continue;
|
||||
|
||||
int amount;
|
||||
try {
|
||||
amount = Integer.parseInt(
|
||||
parts[1].trim());
|
||||
} catch (NumberFormatException e) {
|
||||
plugin.getLogger().warning(
|
||||
"[CDK] " + f.getName()
|
||||
+ " L" + lineNum
|
||||
+ " 金额格式错误: "
|
||||
+ parts[1]);
|
||||
continue;
|
||||
}
|
||||
|
||||
String type = parts.length >= 3
|
||||
? parts[2].trim() : "bond";
|
||||
|
||||
boolean ok = addCDK(code, amount,
|
||||
type);
|
||||
if (ok) {
|
||||
count++;
|
||||
} else {
|
||||
plugin.getLogger().warning(
|
||||
"[CDK] " + f.getName()
|
||||
+ " L" + lineNum
|
||||
+ " 重复跳过: "
|
||||
+ code);
|
||||
}
|
||||
}
|
||||
br.close();
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warning(
|
||||
"[CDK] 读取失败: " + f.getName()
|
||||
+ " " + e.getMessage());
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
public int importFromFile(String fileName) {
|
||||
File dir = new File(
|
||||
plugin.getDataFolder(), "cdk");
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
// 先在 cdk/ 目录下找
|
||||
File f = new File(dir, fileName);
|
||||
if (!f.exists()) {
|
||||
// 再在插件根目录找
|
||||
f = new File(
|
||||
plugin.getDataFolder(), fileName);
|
||||
}
|
||||
if (!f.exists()) {
|
||||
plugin.getLogger().warning(
|
||||
"[CDK] 文件不存在: "
|
||||
+ fileName);
|
||||
return -1;
|
||||
}
|
||||
|
||||
plugin.getLogger().info(
|
||||
"[CDK] 开始导入: "
|
||||
+ f.getAbsolutePath()
|
||||
+ " 大小:" + f.length()
|
||||
+ " bytes");
|
||||
|
||||
int count = loadCDKFile(f);
|
||||
plugin.getLogger().info(
|
||||
"[CDK] 导入完成: " + count + " 条");
|
||||
return count;
|
||||
}
|
||||
|
||||
public int importFromSdf1(String fileName) {
|
||||
int count = 0;
|
||||
Scoreboard board = Bukkit.getScoreboardManager()
|
||||
.getMainScoreboard();
|
||||
// 尝试从sdf1的计分板读取口令
|
||||
// 这部分依赖sdf1插件的配置
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
private boolean addCDK(String code, int amount,
|
||||
String type) {
|
||||
try {
|
||||
// 先检查是否已存在
|
||||
PreparedStatement check =
|
||||
db.prepareStatement(
|
||||
"SELECT code FROM cdk "
|
||||
+ "WHERE code=?");
|
||||
check.setString(1, code);
|
||||
ResultSet rs = check.executeQuery();
|
||||
if (rs.next()) {
|
||||
rs.close();
|
||||
check.close();
|
||||
return false;
|
||||
}
|
||||
rs.close();
|
||||
check.close();
|
||||
|
||||
PreparedStatement ps =
|
||||
db.prepareStatement(
|
||||
"INSERT INTO cdk "
|
||||
+ "(code, amount, type,"
|
||||
+ " created_time)"
|
||||
+ " VALUES (?,?,?,?)");
|
||||
ps.setString(1, code);
|
||||
ps.setInt(2, amount);
|
||||
ps.setString(3,
|
||||
type != null ? type : "bond");
|
||||
ps.setLong(4,
|
||||
System.currentTimeMillis());
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
plugin.getLogger().warning(
|
||||
"[CDK] addCDK失败: " + code
|
||||
+ " " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 替换整个 redeem 方法 =====
|
||||
public String redeem(String code, String player) {
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"SELECT amount,type,used FROM cdk "
|
||||
+ "WHERE code=?");
|
||||
ps.setString(1, code);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (!rs.next()) {
|
||||
rs.close(); ps.close();
|
||||
return null;
|
||||
}
|
||||
int amount = rs.getInt("amount");
|
||||
String type = rs.getString("type");
|
||||
int used = rs.getInt("used");
|
||||
rs.close(); ps.close();
|
||||
|
||||
if (used == 1) return "该兑换码已被使用";
|
||||
|
||||
// [新增] 冻结检查
|
||||
if (plugin.getBonds().isFrozen(player)) {
|
||||
return "账户已被冻结,无法兑换";
|
||||
}
|
||||
|
||||
PreparedStatement up = db.prepareStatement(
|
||||
"UPDATE cdk SET used=1,"
|
||||
+ "used_by=?,used_time=? "
|
||||
+ "WHERE code=?");
|
||||
up.setString(1, player);
|
||||
up.setLong(2, System.currentTimeMillis());
|
||||
up.setString(3, code);
|
||||
up.executeUpdate(); up.close();
|
||||
|
||||
if ("bond".equals(type)) {
|
||||
// [修改] 使用带流水的重载方法
|
||||
plugin.getBonds().addBonds(player, amount,
|
||||
BondManager.TX_REDEEM, "",
|
||||
"system", "CDK兑换: " + code);
|
||||
return "兑换成功!获得 " + amount + " 债券";
|
||||
}
|
||||
return null;
|
||||
} catch (SQLException e) {
|
||||
return "兑换失败";
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 聊天输入系统(主插件转发调用)=====
|
||||
|
||||
public void requestInput(Player p, String type, String context) {
|
||||
CDKInput input = new CDKInput();
|
||||
input.type = type;
|
||||
input.context = context;
|
||||
input.time = System.currentTimeMillis();
|
||||
pendingInputs.put(p.getName(), input);
|
||||
}
|
||||
|
||||
public boolean isListening(String playerName) {
|
||||
return pendingInputs.containsKey(playerName);
|
||||
}
|
||||
|
||||
public void onChat(Player p, String msg) {
|
||||
CDKInput input = pendingInputs.remove(p.getName());
|
||||
if (input == null) return;
|
||||
|
||||
if (System.currentTimeMillis() - input.time > 60000) {
|
||||
p.sendMessage("§c输入超时,请重新操作");
|
||||
return;
|
||||
}
|
||||
|
||||
if ("cdk".equals(input.type)) {
|
||||
String result = redeem(msg.trim(), p.getName());
|
||||
p.sendMessage(result != null
|
||||
? "§e§l[CDK] §f" + result
|
||||
: "§c§l[CDK] §f无效的兑换码");
|
||||
return;
|
||||
}
|
||||
|
||||
if ("econ".equals(input.type)) {
|
||||
handleEconInput(p, msg.trim(), input.context);
|
||||
return;
|
||||
}
|
||||
|
||||
if ("bond".equals(input.type)) {
|
||||
handleBondInput(p, msg.trim(), input.context);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleEconInput(Player admin, String msg, String target) {
|
||||
net.milkbowl.vault.economy.Economy econ = null;
|
||||
try {
|
||||
var reg = plugin.getServer().getServicesManager()
|
||||
.getRegistration(net.milkbowl.vault.economy.Economy.class);
|
||||
if (reg != null) econ = reg.getProvider();
|
||||
} catch (Exception ignored) {}
|
||||
if (econ == null) {
|
||||
admin.sendMessage("§c经济系统不可用");
|
||||
return;
|
||||
}
|
||||
if (!msg.startsWith("+") && !msg.startsWith("-")) {
|
||||
admin.sendMessage("§c格式: §a+100 §7给钱 / §c-50 §7扣钱");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String numStr = msg.substring(1).trim();
|
||||
double amount = Double.parseDouble(numStr);
|
||||
if (amount <= 0) {
|
||||
admin.sendMessage("§c金额必须大于0");
|
||||
return;
|
||||
}
|
||||
if (msg.startsWith("-")) {
|
||||
Player tp = plugin.getServer().getPlayerExact(target);
|
||||
if (tp == null) {
|
||||
admin.sendMessage("§c" + target + " 不在线");
|
||||
return;
|
||||
}
|
||||
if (!econ.has(tp, amount)) {
|
||||
admin.sendMessage("§c" + target + " 余额不足");
|
||||
return;
|
||||
}
|
||||
double oldBal = econ.getBalance(tp);
|
||||
econ.withdrawPlayer(tp, amount);
|
||||
double newBal = econ.getBalance(tp);
|
||||
admin.sendMessage("§7============== §c余额扣款 §7==============");
|
||||
admin.sendMessage("§7目标: §e" + target);
|
||||
admin.sendMessage("§c扣款: §e-$" + String.format("%.2f", amount));
|
||||
admin.sendMessage("§7余额: §e" + String.format("%.2f", oldBal) + " → §c" + String.format("%.2f", newBal));
|
||||
admin.sendMessage("§7============== §c余额扣款 §7==============");
|
||||
tp.sendMessage("§7============== §c余额扣款 §7==============");
|
||||
tp.sendMessage("§c扣款: §e-$" + String.format("%.2f", amount));
|
||||
tp.sendMessage("§7余额: §e" + String.format("%.2f", oldBal) + " → §c" + String.format("%.2f", newBal));
|
||||
tp.sendMessage("§7操作者: §e" + admin.getName());
|
||||
tp.sendMessage("§7============== §c余额扣款 §7==============");
|
||||
} else {
|
||||
double oldBal = econ.getBalance(target);
|
||||
econ.depositPlayer(target, amount);
|
||||
double newBal = econ.getBalance(target);
|
||||
Player tp = plugin.getServer().getPlayerExact(target);
|
||||
admin.sendMessage("§7============== §6余额转账 §7==============");
|
||||
admin.sendMessage("§7目标: §e" + target);
|
||||
admin.sendMessage("§a到账: §e$" + String.format("%.2f", amount));
|
||||
admin.sendMessage("§7余额: §e" + String.format("%.2f", oldBal) + " → §a" + String.format("%.2f", newBal));
|
||||
admin.sendMessage("§7============== §6余额转账 §7==============");
|
||||
if (tp != null) {
|
||||
tp.sendMessage("§7============== §a收到转账 §7==============");
|
||||
tp.sendMessage("§a到账: §e$" + String.format("%.2f", amount));
|
||||
tp.sendMessage("§7余额: §e" + String.format("%.2f", oldBal) + " → §a" + String.format("%.2f", newBal));
|
||||
tp.sendMessage("§7来自: §e" + admin.getName());
|
||||
tp.sendMessage("§7============== §a收到转账 §7==============");
|
||||
}
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
admin.sendMessage("§c格式错误,请输入 §a+数字 §7或 §c-数字");
|
||||
}
|
||||
}
|
||||
// ===== 替换整个 handleBondInput 方法 =====
|
||||
private void handleBondInput(Player admin,
|
||||
String msg,
|
||||
String target) {
|
||||
if (!msg.startsWith("+")
|
||||
&& !msg.startsWith("-")) {
|
||||
admin.sendMessage(
|
||||
"§c格式: §a+100 §7给债券"
|
||||
+ " / §c-50 §7扣债券");
|
||||
admin.sendMessage(
|
||||
"§7可附加理由: §a+100 活动奖励");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String sign = msg.substring(0, 1);
|
||||
String rest = msg.substring(1).trim();
|
||||
|
||||
// 拆分金额和理由
|
||||
String[] parts = rest.split("\\s+", 2);
|
||||
int amount = Integer.parseInt(parts[0]);
|
||||
String reason = parts.length >= 2
|
||||
? parts[1].trim()
|
||||
: "管理员手动调整";
|
||||
|
||||
if (amount <= 0) {
|
||||
admin.sendMessage("§c金额必须大于0");
|
||||
return;
|
||||
}
|
||||
String opName = admin.getName();
|
||||
String txType = "-".equals(sign)
|
||||
? BondManager.TX_ADMIN_DEDUCT
|
||||
: BondManager.TX_ADMIN_GIVE;
|
||||
|
||||
if ("-".equals(sign)) {
|
||||
if (plugin.getBonds()
|
||||
.isFrozen(target)) {
|
||||
admin.sendMessage("§c" + target
|
||||
+ " 账户已被冻结");
|
||||
return;
|
||||
}
|
||||
int oldBal = plugin.getBonds()
|
||||
.getBonds(target);
|
||||
if (plugin.getBonds().deductBonds(
|
||||
target, amount, txType,
|
||||
"", opName, reason)) {
|
||||
int newBal = plugin.getBonds()
|
||||
.getBonds(target);
|
||||
admin.sendMessage(
|
||||
"§7============== §c"
|
||||
+ "债券扣款 §7"
|
||||
+ "=============");
|
||||
admin.sendMessage(
|
||||
"§7目标: §e" + target);
|
||||
admin.sendMessage("§c扣款: §c-"
|
||||
+ amount + " §6枚");
|
||||
admin.sendMessage("§7理由: §f"
|
||||
+ reason);
|
||||
admin.sendMessage("§7债券: §e"
|
||||
+ oldBal + " → §c"
|
||||
+ newBal);
|
||||
admin.sendMessage(
|
||||
"§7============== §c"
|
||||
+ "债券扣款 §7"
|
||||
+ "=============");
|
||||
Player tp = plugin.getServer()
|
||||
.getPlayerExact(target);
|
||||
if (tp != null) {
|
||||
tp.sendMessage(
|
||||
"§7============== §c"
|
||||
+ "债券扣款 §7"
|
||||
+ "=============");
|
||||
tp.sendMessage("§c扣款: §c-"
|
||||
+ amount + " §6枚");
|
||||
tp.sendMessage("§7理由: §f"
|
||||
+ reason);
|
||||
tp.sendMessage("§7债券: §e"
|
||||
+ oldBal + " → §c"
|
||||
+ newBal);
|
||||
tp.sendMessage("§7操作者: §e"
|
||||
+ opName);
|
||||
tp.sendMessage(
|
||||
"§7============== §c"
|
||||
+ "债券扣款 §7"
|
||||
+ "=============");
|
||||
}
|
||||
} else {
|
||||
admin.sendMessage("§c" + target
|
||||
+ " 债券不足(当前: "
|
||||
+ oldBal + ")");
|
||||
}
|
||||
} else {
|
||||
if (plugin.getBonds()
|
||||
.isFrozen(target)) {
|
||||
admin.sendMessage("§c" + target
|
||||
+ " 账户已被冻结");
|
||||
return;
|
||||
}
|
||||
int oldBal = plugin.getBonds()
|
||||
.getBonds(target);
|
||||
plugin.getBonds().addBonds(target,
|
||||
amount, txType,
|
||||
"", opName, reason);
|
||||
int newBal = plugin.getBonds()
|
||||
.getBonds(target);
|
||||
admin.sendMessage(
|
||||
"§7============== §6"
|
||||
+ "债券转账 §7"
|
||||
+ "=============");
|
||||
admin.sendMessage(
|
||||
"§7目标: §e" + target);
|
||||
admin.sendMessage("§a到账: §a+"
|
||||
+ amount + " §6枚");
|
||||
admin.sendMessage("§7理由: §f"
|
||||
+ reason);
|
||||
admin.sendMessage("§7债券: §e"
|
||||
+ oldBal + " → §a"
|
||||
+ newBal);
|
||||
admin.sendMessage(
|
||||
"§7============== §6"
|
||||
+ "债券转账 §7"
|
||||
+ "=============");
|
||||
Player tp = plugin.getServer()
|
||||
.getPlayerExact(target);
|
||||
if (tp != null) {
|
||||
tp.sendMessage(
|
||||
"§7============== §a"
|
||||
+ "收到债券 §7"
|
||||
+ "=============");
|
||||
tp.sendMessage("§a到账: §a+"
|
||||
+ amount + " §6枚");
|
||||
tp.sendMessage("§7理由: §f"
|
||||
+ reason);
|
||||
tp.sendMessage("§7债券: §e"
|
||||
+ oldBal + " → §a"
|
||||
+ newBal);
|
||||
tp.sendMessage("§7来自: §e"
|
||||
+ opName);
|
||||
tp.sendMessage(
|
||||
"§7============== §a"
|
||||
+ "收到债券 §7"
|
||||
+ "=============");
|
||||
}
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
admin.sendMessage("§c格式错误,请输入 "
|
||||
+ "§a+数字 §7或 §c-数字");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void cancelInput(String player) {
|
||||
pendingInputs.remove(player);
|
||||
}
|
||||
|
||||
static class CDKInput {
|
||||
String type;
|
||||
String context;
|
||||
long time;
|
||||
}
|
||||
}
|
||||
@@ -35,36 +35,28 @@ public class CheckInManager {
|
||||
}
|
||||
|
||||
Object streakObj = plugin.getDb()
|
||||
.getField(name,
|
||||
"checkin_streak");
|
||||
.getField(name, "checkin_streak");
|
||||
int streak = streakObj != null
|
||||
? ((Number) streakObj)
|
||||
.intValue() : 0;
|
||||
? ((Number) streakObj).intValue()
|
||||
: 0;
|
||||
|
||||
String lastDate = (String) plugin
|
||||
.getDb().getField(name,
|
||||
"last_checkin_date");
|
||||
String today = new SimpleDateFormat(
|
||||
"yyyy-MM-dd")
|
||||
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()) {
|
||||
if (lastDate != null && !lastDate.isEmpty()) {
|
||||
try {
|
||||
java.util.Date lastD =
|
||||
new SimpleDateFormat(
|
||||
"yyyy-MM-dd")
|
||||
new SimpleDateFormat("yyyy-MM-dd")
|
||||
.parse(lastDate);
|
||||
java.util.Date todayD =
|
||||
new SimpleDateFormat(
|
||||
"yyyy-MM-dd")
|
||||
new SimpleDateFormat("yyyy-MM-dd")
|
||||
.parse(today);
|
||||
long diff = todayD.getTime()
|
||||
- lastD.getTime();
|
||||
long diff = todayD.getTime() - lastD.getTime();
|
||||
if (diff > 86400000L * 2) {
|
||||
streak = 0;
|
||||
} else if (diff
|
||||
> 86400000L) {
|
||||
} else if (diff > 86400000L) {
|
||||
streak++;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
@@ -79,41 +71,35 @@ public class CheckInManager {
|
||||
else if (streak >= 14) multi = 1.3;
|
||||
else if (streak >= 7) multi = 1.1;
|
||||
|
||||
int basePoints = plugin.getConfig2()
|
||||
.checkinPoints;
|
||||
int points =
|
||||
(int) (basePoints * multi);
|
||||
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);
|
||||
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");
|
||||
.getField(name, "total_checkin_days");
|
||||
int total = totalObj != null
|
||||
? ((Number) totalObj)
|
||||
.intValue() : 0;
|
||||
plugin.getDb().setField(
|
||||
name,
|
||||
"total_checkin_days",
|
||||
? ((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));
|
||||
int bondReward = 1;
|
||||
if (streak >= 21) bondReward = 3;
|
||||
else if (streak >= 14) bondReward = 2;
|
||||
else if (streak >= 7) bondReward = 2;
|
||||
plugin.getBonds().addBonds(name, bondReward);
|
||||
|
||||
return plugin.getConfig2().msg("checkin_success")
|
||||
.replace("{points}", String.valueOf(points))
|
||||
.replace("{streak}", String.valueOf(streak))
|
||||
.replace("{multi}", String.valueOf(multi))
|
||||
+ " §e+" + bondReward + "债券";
|
||||
}
|
||||
|
||||
|
||||
// ===== 获取连续天数 =====
|
||||
public int getStreak(String name) {
|
||||
Object val = plugin.getDb()
|
||||
@@ -257,8 +243,12 @@ public class CheckInManager {
|
||||
plugin.getDb().setField(name,
|
||||
"checkin_streak",
|
||||
streak + 1);
|
||||
int bondReward = 1;
|
||||
if (streak >= 21) bondReward = 3;
|
||||
else if (streak >= 14) bondReward = 2;
|
||||
else if (streak >= 7) bondReward = 2;
|
||||
plugin.getBonds().addBonds(name, bondReward);
|
||||
}
|
||||
|
||||
// ===== 标准化日期 =====
|
||||
private String normalizeDate(
|
||||
String input) {
|
||||
|
||||
@@ -0,0 +1,569 @@
|
||||
package Sdf1_login;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CypayCommand
|
||||
implements CommandExecutor, TabCompleter {
|
||||
|
||||
private final Main plugin;
|
||||
private static final SimpleDateFormat SDF =
|
||||
new SimpleDateFormat(
|
||||
"yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
public CypayCommand(Main plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
private boolean hasAdminPerm(CommandSender s) {
|
||||
if (s.isOp()) return true;
|
||||
if (!(s instanceof Player)) return true;
|
||||
Player p = (Player) s;
|
||||
String tag =
|
||||
plugin.getConfig2().adminTag;
|
||||
return !tag.isEmpty()
|
||||
&& p.getScoreboardTags().contains(tag);
|
||||
}
|
||||
|
||||
private int parseAmount(String s) {
|
||||
return Integer.parseInt(
|
||||
s.trim().replaceAll("[+]", ""));
|
||||
}
|
||||
|
||||
private List<String> filter(
|
||||
List<String> list, String prefix) {
|
||||
String low = prefix.toLowerCase();
|
||||
return list.stream()
|
||||
.filter(x -> x.toLowerCase()
|
||||
.startsWith(low))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender,
|
||||
Command cmd,
|
||||
String label,
|
||||
String[] args) {
|
||||
|
||||
// ===== /cypay — 查自己 =====
|
||||
if (args.length == 0) {
|
||||
String name = sender instanceof Player
|
||||
? sender.getName() : "Console";
|
||||
int bonds =
|
||||
plugin.getBonds().getBonds(name);
|
||||
String status = plugin.getBonds()
|
||||
.getAccountStatus(name);
|
||||
sender.sendMessage(
|
||||
"§e§l[债券] §f" + name
|
||||
+ " 余额: §a" + bonds);
|
||||
sender.sendMessage(
|
||||
"§e§l[债券] §f状态: "
|
||||
+ ("frozen".equals(status)
|
||||
? "§c冻结中"
|
||||
: "§a正常"));
|
||||
return true;
|
||||
}
|
||||
|
||||
// ===== /cypay import =====
|
||||
if (args.length == 2
|
||||
&& "import".equalsIgnoreCase(
|
||||
args[0])) {
|
||||
if (!hasAdminPerm(sender)) {
|
||||
sender.sendMessage("§c权限不足");
|
||||
return true;
|
||||
}
|
||||
String file = args[1];
|
||||
if (!file.endsWith(".txt"))
|
||||
file += ".txt";
|
||||
int result = plugin.getCDK()
|
||||
.importFromFile(file);
|
||||
if (result == -1)
|
||||
sender.sendMessage("§c文件不存在: "
|
||||
+ file);
|
||||
else
|
||||
sender.sendMessage("§a导入完成: "
|
||||
+ result + " 条");
|
||||
return true;
|
||||
}
|
||||
|
||||
// ===== /cypay freeze =====
|
||||
if (args.length == 2
|
||||
&& "freeze".equalsIgnoreCase(
|
||||
args[0])) {
|
||||
if (!hasAdminPerm(sender)) {
|
||||
sender.sendMessage("§c权限不足");
|
||||
return true;
|
||||
}
|
||||
String target = args[1];
|
||||
if (plugin.getBonds().isFrozen(target)) {
|
||||
sender.sendMessage("§c" + target
|
||||
+ " 已处于冻结状态");
|
||||
return true;
|
||||
}
|
||||
plugin.getBonds().freezeAccount(target);
|
||||
sender.sendMessage("§a已冻结 " + target
|
||||
+ " 的债券账户");
|
||||
Player tp = plugin.getServer()
|
||||
.getPlayerExact(target);
|
||||
if (tp != null)
|
||||
tp.sendMessage(
|
||||
"§c§l[系统] 你的债券账户"
|
||||
+ "已被管理员冻结");
|
||||
return true;
|
||||
}
|
||||
|
||||
// ===== /cypay unfreeze =====
|
||||
if (args.length == 2
|
||||
&& "unfreeze".equalsIgnoreCase(
|
||||
args[0])) {
|
||||
if (!hasAdminPerm(sender)) {
|
||||
sender.sendMessage("§c权限不足");
|
||||
return true;
|
||||
}
|
||||
String target = args[1];
|
||||
if (!plugin.getBonds()
|
||||
.isFrozen(target)) {
|
||||
sender.sendMessage("§c" + target
|
||||
+ " 未被冻结");
|
||||
return true;
|
||||
}
|
||||
plugin.getBonds().unfreezeAccount(target);
|
||||
sender.sendMessage("§a已解冻 " + target
|
||||
+ " 的债券账户");
|
||||
Player tp = plugin.getServer()
|
||||
.getPlayerExact(target);
|
||||
if (tp != null)
|
||||
tp.sendMessage(
|
||||
"§a§l[系统] 你的债券账户"
|
||||
+ "已被解冻");
|
||||
return true;
|
||||
}
|
||||
|
||||
// ===== /cypay water [days] =====
|
||||
if (args.length >= 2
|
||||
&& "water".equalsIgnoreCase(
|
||||
args[0])) {
|
||||
if (!hasAdminPerm(sender)) {
|
||||
sender.sendMessage("§c权限不足");
|
||||
return true;
|
||||
}
|
||||
String target = args[1];
|
||||
int days = 7;
|
||||
if (args.length >= 3) {
|
||||
try {
|
||||
days = Integer.parseInt(args[2]);
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
days = Math.min(days,
|
||||
BondManager.ADMIN_MAX_WATER_DAYS);
|
||||
|
||||
if (days <= 0) days = 1;
|
||||
|
||||
List<Map<String, Object>> txs =
|
||||
plugin.getBonds()
|
||||
.getTransactions(
|
||||
target, days);
|
||||
|
||||
sender.sendMessage(
|
||||
"§e§l===== " + target
|
||||
+ " 流水记录 (近"
|
||||
+ days + "天) =====");
|
||||
sender.sendMessage("§f当前余额: §a"
|
||||
+ plugin.getBonds()
|
||||
.getBonds(target)
|
||||
+ " §f状态: "
|
||||
+ (plugin.getBonds()
|
||||
.isFrozen(target)
|
||||
? "§c冻结" : "§a正常"));
|
||||
|
||||
if (txs.isEmpty()) {
|
||||
sender.sendMessage("§7 (暂无记录)");
|
||||
} else {
|
||||
for (Map<String, Object> tx : txs) {
|
||||
sender.sendMessage(
|
||||
formatTxLine(tx));
|
||||
}
|
||||
}
|
||||
sender.sendMessage(
|
||||
"§e§l=========================="
|
||||
+ "==========");
|
||||
return true;
|
||||
}
|
||||
// ===== /cypay printer [player] =====
|
||||
if ("printer".equalsIgnoreCase(args[0])) {
|
||||
if (!hasAdminPerm(sender)
|
||||
&& !(sender instanceof Player)
|
||||
== false) {
|
||||
// 控制台也可以用
|
||||
if (!(sender instanceof Player))
|
||||
; // 放行
|
||||
else if (!hasAdminPerm(sender)) {
|
||||
sender.sendMessage("§c权限不足");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (args.length == 1) {
|
||||
// 打印全服
|
||||
sender.sendMessage(
|
||||
"§e正在导出全服流水...");
|
||||
plugin.getBonds(); // 确保实例就绪
|
||||
if (plugin.getBondPrinter() != null) {
|
||||
plugin.getBondPrinter()
|
||||
.printAll(sender);
|
||||
} else {
|
||||
sender.sendMessage("§cPrinter未初始化");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (args.length == 2) {
|
||||
// 打印指定玩家
|
||||
String target = args[1];
|
||||
sender.sendMessage("§e正在导出 "
|
||||
+ target + " 的流水...");
|
||||
if (plugin.getBondPrinter() != null) {
|
||||
plugin.getBondPrinter()
|
||||
.printPlayer(target, sender);
|
||||
} else {
|
||||
sender.sendMessage("§cPrinter未初始化");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== /cypay give/remove =====
|
||||
if (args.length == 3) {
|
||||
String action = args[0].toLowerCase();
|
||||
if ("give".equals(action)
|
||||
|| "remove".equals(action)) {
|
||||
if (!hasAdminPerm(sender)) {
|
||||
sender.sendMessage("§c权限不足");
|
||||
return true;
|
||||
}
|
||||
String target = args[1];
|
||||
try {
|
||||
int amount =
|
||||
parseAmount(args[2]);
|
||||
if (amount <= 0) {
|
||||
sender.sendMessage(
|
||||
"§c金额必须大于0");
|
||||
return true;
|
||||
}
|
||||
String txType =
|
||||
"give".equals(action)
|
||||
? BondManager
|
||||
.TX_ADMIN_GIVE
|
||||
: BondManager
|
||||
.TX_ADMIN_DEDUCT;
|
||||
String opName =
|
||||
sender instanceof Player
|
||||
? sender.getName()
|
||||
: "Console";
|
||||
|
||||
if ("give".equals(action)) {
|
||||
plugin.getBonds().addBonds(
|
||||
target, amount,
|
||||
txType, "",
|
||||
opName, "管理员发放");
|
||||
sender.sendMessage(
|
||||
"§a已给 " + target
|
||||
+ " " + amount
|
||||
+ " 债券");
|
||||
Player tp = plugin.getServer()
|
||||
.getPlayerExact(target);
|
||||
if (tp != null)
|
||||
tp.sendMessage(
|
||||
"§a管理员给了你 "
|
||||
+ amount
|
||||
+ " 债券");
|
||||
} else {
|
||||
if (plugin.getBonds()
|
||||
.deductBonds(target,
|
||||
amount,
|
||||
txType, "",
|
||||
opName,
|
||||
"管理员扣除")) {
|
||||
sender.sendMessage(
|
||||
"§a已扣除 " + target
|
||||
+ " " + amount
|
||||
+ " 债券");
|
||||
Player tp = plugin
|
||||
.getServer()
|
||||
.getPlayerExact(
|
||||
target);
|
||||
if (tp != null)
|
||||
tp.sendMessage(
|
||||
"§c管理员扣除了"
|
||||
+ "你的 "
|
||||
+ amount
|
||||
+ " 债券");
|
||||
} else {
|
||||
sender.sendMessage(
|
||||
"§c" + target
|
||||
+ " 债券不足"
|
||||
+ "或账户冻结");
|
||||
}
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
sender.sendMessage(
|
||||
"§c金额格式错误");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== /cypay <player> <amount> — 仅玩家转账 =====
|
||||
if (args.length == 2) {
|
||||
try {
|
||||
int amount = parseAmount(args[1]);
|
||||
if (amount <= 0) {
|
||||
sender.sendMessage(
|
||||
"§c金额必须大于0");
|
||||
return true;
|
||||
}
|
||||
// ★ 控制台禁止转账
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage(
|
||||
"§c控制台不能转账,请使用 "
|
||||
+ "/cypay give <玩家> <金额>");
|
||||
return true;
|
||||
}
|
||||
Player p = (Player) sender;
|
||||
String target = args[0];
|
||||
BondManager.TransferResult r =
|
||||
plugin.getBonds().transfer(
|
||||
p.getName(),
|
||||
target, amount);
|
||||
if (r.success) {
|
||||
p.sendMessage("§e§l[债券转账] §f向 §a"
|
||||
+ target + " §f转出 §c"
|
||||
+ amount + " §f枚债券");
|
||||
Player tp = plugin.getServer()
|
||||
.getPlayerExact(target);
|
||||
if (tp != null)
|
||||
tp.sendMessage("§e§l[债券转账] §f收到 §a"
|
||||
+ p.getName()
|
||||
+ " §f转入 §a"
|
||||
+ amount + " §f枚债券");
|
||||
} else {
|
||||
p.sendMessage("§c" + r.message
|
||||
+ ",当前: "
|
||||
+ plugin.getBonds()
|
||||
.getBonds(p.getName()));
|
||||
}
|
||||
return true;
|
||||
} catch (NumberFormatException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
// ===== /cypay <player> — 查指定玩家 =====
|
||||
if (args.length == 1) {
|
||||
String target = args[0];
|
||||
if (hasAdminPerm(sender)) {
|
||||
int bonds = plugin.getBonds()
|
||||
.getBonds(target);
|
||||
String status = plugin.getBonds()
|
||||
.getAccountStatus(target);
|
||||
sender.sendMessage(
|
||||
"§e§l[债券] §f" + target
|
||||
+ " 余额: §a"
|
||||
+ bonds);
|
||||
sender.sendMessage(
|
||||
"§e§l[债券] §f状态: "
|
||||
+ ("frozen".equals(
|
||||
status)
|
||||
? "§c冻结中"
|
||||
: "§a正常"));
|
||||
} else {
|
||||
int bonds = plugin.getBonds()
|
||||
.getBonds(
|
||||
sender.getName());
|
||||
sender.sendMessage(
|
||||
"§e§l[债券] §f你的余额: §a"
|
||||
+ bonds);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
showHelp(sender);
|
||||
return true;
|
||||
}
|
||||
|
||||
// ===== 流水行格式化 =====
|
||||
|
||||
private String formatTxLine(
|
||||
Map<String, Object> tx) {
|
||||
String type = (String) tx.get("type");
|
||||
int amount = ((Number) tx.get("amount"))
|
||||
.intValue();
|
||||
String tgt = (String) tx.get("target_player");
|
||||
String reason = (String) tx.get("reason");
|
||||
int bal = ((Number) tx.get("balance_after"))
|
||||
.intValue();
|
||||
long time = ((Number) tx.get("time"))
|
||||
.longValue();
|
||||
|
||||
boolean pos = amount > 0;
|
||||
String sign = pos ? "+" : "";
|
||||
String color = pos ? "§a" : "§c";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("§7[")
|
||||
.append(SDF.format(new Date(time)))
|
||||
.append("] ")
|
||||
.append(formatTxType(type))
|
||||
.append(" ")
|
||||
.append(color).append(sign)
|
||||
.append(amount).append("§7");
|
||||
if (tgt != null && !tgt.isEmpty())
|
||||
sb.append(" §e↔ ").append(tgt);
|
||||
if (reason != null && !reason.isEmpty())
|
||||
sb.append(" §7(").append(reason)
|
||||
.append(")");
|
||||
sb.append(" §7余额:§f").append(bal);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private String formatTxType(String type) {
|
||||
if (type == null) return "§7未知";
|
||||
switch (type) {
|
||||
case BondManager.TX_ADMIN_GIVE:
|
||||
return "§a管理员发放";
|
||||
case BondManager.TX_ADMIN_DEDUCT:
|
||||
return "§c管理员扣除";
|
||||
case BondManager.TX_TRANSFER_OUT:
|
||||
return "§c转出";
|
||||
case BondManager.TX_TRANSFER_IN:
|
||||
return "§a转入";
|
||||
case BondManager.TX_REDEEM:
|
||||
return "§aCDK兑换";
|
||||
case BondManager.TX_SHOP_BUY:
|
||||
return "§e商城购买";
|
||||
case BondManager.TX_DAILY_SIGN:
|
||||
return "§a签到奖励";
|
||||
case BondManager.TX_FREEZE:
|
||||
return "§c冻结";
|
||||
case BondManager.TX_UNFREEZE:
|
||||
return "§a解冻";
|
||||
default:
|
||||
return "§7" + type;
|
||||
}
|
||||
}
|
||||
|
||||
private void showHelp(CommandSender sender) {
|
||||
sender.sendMessage("§e§l债券命令帮助:");
|
||||
sender.sendMessage(
|
||||
"§e/cypay §7- 查询自己余额");
|
||||
sender.sendMessage(
|
||||
"§e/cypay <玩家> §7- 查余额(管理员)");
|
||||
sender.sendMessage(
|
||||
"§e/cypay <玩家> <金额> §7- 转账");
|
||||
if (hasAdminPerm(sender)) {
|
||||
sender.sendMessage(
|
||||
"§e/cypay give <玩家> <金额> §7- 给债券");
|
||||
sender.sendMessage(
|
||||
"§e/cypay remove <玩家> <金额> §7- 扣债券");
|
||||
sender.sendMessage(
|
||||
"§e/cypay import <文件> §7- 导入CDK");
|
||||
sender.sendMessage(
|
||||
"§e/cypay freeze <玩家> §7- 冻结");
|
||||
sender.sendMessage(
|
||||
"§e/cypay unfreeze <玩家> §7- 解冻");
|
||||
sender.sendMessage(
|
||||
"§e/cypay water <玩家> [天数] §7- 流水");
|
||||
sender.sendMessage(
|
||||
"§e/cypay printer §7- 导出全服流水xlsx");
|
||||
sender.sendMessage(
|
||||
"§e/cypay printer <玩家> §7- 导出指定玩家xlsx");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(
|
||||
CommandSender sender, Command command,
|
||||
String label, String[] args) {
|
||||
List<String> list = new ArrayList<>();
|
||||
|
||||
if (args.length == 1) {
|
||||
String last = args[0].toLowerCase();
|
||||
if (hasAdminPerm(sender)) {
|
||||
list.add("give");
|
||||
list.add("remove");
|
||||
list.add("import");
|
||||
list.add("freeze");
|
||||
list.add("unfreeze");
|
||||
list.add("water");
|
||||
list.add("printer");
|
||||
|
||||
File cdkDir = new File(
|
||||
plugin.getDataFolder(),
|
||||
"cdk");
|
||||
if (cdkDir.exists()) {
|
||||
File[] files = cdkDir.listFiles(
|
||||
(d, n) -> n
|
||||
.endsWith(".txt"));
|
||||
if (files != null)
|
||||
for (File f : files)
|
||||
list.add(f.getName());
|
||||
}
|
||||
}
|
||||
for (Player o :
|
||||
Bukkit.getOnlinePlayers())
|
||||
list.add(o.getName());
|
||||
return filter(list, last);
|
||||
}
|
||||
|
||||
if (args.length == 2) {
|
||||
String first = args[0].toLowerCase();
|
||||
if ("give".equals(first)
|
||||
|| "remove".equals(first)
|
||||
|| "freeze".equals(first)
|
||||
|| "unfreeze".equals(first)
|
||||
|| "water".equals(first)) {
|
||||
for (Player o :
|
||||
Bukkit.getOnlinePlayers())
|
||||
list.add(o.getName());
|
||||
return filter(list,
|
||||
args[1].toLowerCase());
|
||||
}
|
||||
list.add("10");
|
||||
list.add("50");
|
||||
list.add("100");
|
||||
return filter(list,
|
||||
args[1].toLowerCase());
|
||||
}
|
||||
|
||||
if (args.length == 3) {
|
||||
String first = args[0].toLowerCase();
|
||||
if ("give".equals(first)
|
||||
|| "remove".equals(first)) {
|
||||
list.add("10");
|
||||
list.add("50");
|
||||
list.add("100");
|
||||
list.add("999");
|
||||
return filter(list,
|
||||
args[2].toLowerCase());
|
||||
}
|
||||
if ("water".equals(first)) {
|
||||
list.add("1");
|
||||
list.add("3");
|
||||
list.add("7");
|
||||
list.add("14");
|
||||
return filter(list,
|
||||
args[2].toLowerCase());
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
@@ -160,6 +160,40 @@ public class DatabaseManager {
|
||||
+ "alert_date TEXT NOT NULL,"
|
||||
+ "notified INTEGER DEFAULT 0,"
|
||||
+ "notified_time INTEGER DEFAULT 0)");
|
||||
// PVP区域表
|
||||
st.execute("CREATE TABLE IF NOT EXISTS "
|
||||
+ "pvp_regions ("
|
||||
+ "id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
||||
+ "name TEXT NOT NULL UNIQUE,"
|
||||
+ "world TEXT NOT NULL,"
|
||||
+ "x1 INTEGER NOT NULL,"
|
||||
+ "y1 INTEGER NOT NULL,"
|
||||
+ "z1 INTEGER NOT NULL,"
|
||||
+ "x2 INTEGER NOT NULL,"
|
||||
+ "y2 INTEGER NOT NULL,"
|
||||
+ "z2 INTEGER NOT NULL,"
|
||||
+ "create_time INTEGER DEFAULT 0"
|
||||
+ ")");
|
||||
|
||||
// PVP击杀总榜表
|
||||
st.execute("CREATE TABLE IF NOT EXISTS "
|
||||
+ "pvp_kills ("
|
||||
+ "player_name TEXT NOT NULL,"
|
||||
+ "region_name TEXT NOT NULL,"
|
||||
+ "kills INTEGER DEFAULT 0,"
|
||||
+ "deaths INTEGER DEFAULT 0,"
|
||||
+ "PRIMARY KEY(player_name, region_name)"
|
||||
+ ")");
|
||||
|
||||
|
||||
// 菜单图标表
|
||||
st.execute("CREATE TABLE IF NOT EXISTS "
|
||||
+ "menu_icons ("
|
||||
+ "player_name TEXT PRIMARY KEY,"
|
||||
+ "icon_b64 TEXT DEFAULT '',"
|
||||
+ "item_name TEXT DEFAULT '',"
|
||||
+ "save_time INTEGER DEFAULT 0"
|
||||
+ ")");
|
||||
|
||||
// 工单表
|
||||
st.execute("CREATE TABLE IF NOT EXISTS "
|
||||
@@ -239,6 +273,76 @@ public class DatabaseManager {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
// ==================== 菜单图标 ====================
|
||||
|
||||
public void saveMenuIcon(String name,
|
||||
String iconB64, String itemName) {
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"INSERT OR REPLACE INTO menu_icons "
|
||||
+ "(player_name, icon_b64, "
|
||||
+ "item_name, save_time) "
|
||||
+ "VALUES (?,?,?,?)");
|
||||
ps.setString(1, name);
|
||||
ps.setString(2, iconB64);
|
||||
ps.setString(3, itemName);
|
||||
ps.setLong(4,
|
||||
System.currentTimeMillis());
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String getMenuIcon(String name) {
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"SELECT icon_b64 FROM menu_icons "
|
||||
+ "WHERE player_name=?");
|
||||
ps.setString(1, name);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
String b64 = null;
|
||||
if (rs.next()) {
|
||||
b64 = rs.getString("icon_b64");
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
return b64;
|
||||
} catch (SQLException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteMenuIcon(String name) {
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"DELETE FROM menu_icons "
|
||||
+ "WHERE player_name=?");
|
||||
ps.setString(1, name);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasMenuIcon(String name) {
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"SELECT 1 FROM menu_icons "
|
||||
+ "WHERE player_name=? "
|
||||
+ "AND icon_b64 IS NOT NULL "
|
||||
+ "AND icon_b64 != '' "
|
||||
+ "LIMIT 1");
|
||||
ps.setString(1, name);
|
||||
boolean r = ps.executeQuery().next();
|
||||
ps.close();
|
||||
return r;
|
||||
} catch (SQLException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== 用户操作 ====================
|
||||
|
||||
@@ -747,6 +851,252 @@ public class DatabaseManager {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// ==================== PVP区域 ====================
|
||||
|
||||
public void savePVPRegion(String name,
|
||||
String world,
|
||||
int x1, int y1, int z1,
|
||||
int x2, int y2, int z2) {
|
||||
try {
|
||||
PreparedStatement ps =
|
||||
db.prepareStatement(
|
||||
"INSERT OR REPLACE "
|
||||
+ "INTO pvp_regions "
|
||||
+ "(name, world, "
|
||||
+ "x1, y1, z1, "
|
||||
+ "x2, y2, z2, "
|
||||
+ "create_time) "
|
||||
+ "VALUES "
|
||||
+ "(?,?,?,?,?,?,?,?,?)");
|
||||
ps.setString(1, name);
|
||||
ps.setString(2, world);
|
||||
ps.setInt(3, x1);
|
||||
ps.setInt(4, y1);
|
||||
ps.setInt(5, z1);
|
||||
ps.setInt(6, x2);
|
||||
ps.setInt(7, y2);
|
||||
ps.setInt(8, z2);
|
||||
ps.setLong(9,
|
||||
System.currentTimeMillis());
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Object>
|
||||
getPVPRegion(String name) {
|
||||
try {
|
||||
PreparedStatement ps =
|
||||
db.prepareStatement(
|
||||
"SELECT * FROM "
|
||||
+ "pvp_regions "
|
||||
+ "WHERE name=?");
|
||||
ps.setString(1, name);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
Map<String, Object> row =
|
||||
new LinkedHashMap<>();
|
||||
for (int i = 1; i <= rs
|
||||
.getMetaData()
|
||||
.getColumnCount(); i++) {
|
||||
row.put(rs.getMetaData()
|
||||
.getColumnName(i),
|
||||
rs.getObject(i));
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
return row;
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<Map<String, Object>>
|
||||
getAllPVPRegions() {
|
||||
List<Map<String, Object>> list =
|
||||
new ArrayList<>();
|
||||
try {
|
||||
Statement st =
|
||||
db.createStatement();
|
||||
ResultSet rs =
|
||||
st.executeQuery(
|
||||
"SELECT * FROM "
|
||||
+ "pvp_regions");
|
||||
while (rs.next()) {
|
||||
Map<String, Object> row =
|
||||
new LinkedHashMap<>();
|
||||
for (int i = 1; i <= rs
|
||||
.getMetaData()
|
||||
.getColumnCount(); i++) {
|
||||
row.put(rs.getMetaData()
|
||||
.getColumnName(i),
|
||||
rs.getObject(i));
|
||||
}
|
||||
list.add(row);
|
||||
}
|
||||
rs.close();
|
||||
st.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public void deletePVPRegion(String name) {
|
||||
try {
|
||||
PreparedStatement ps =
|
||||
db.prepareStatement(
|
||||
"DELETE FROM "
|
||||
+ "pvp_regions "
|
||||
+ "WHERE name=?");
|
||||
ps.setString(1, name);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== PVP击杀 ====================
|
||||
|
||||
public int getPVPKills(
|
||||
String player, String region) {
|
||||
try {
|
||||
PreparedStatement ps =
|
||||
db.prepareStatement(
|
||||
"SELECT kills FROM "
|
||||
+ "pvp_kills "
|
||||
+ "WHERE "
|
||||
+ "player_name=? "
|
||||
+ "AND region_name=?");
|
||||
ps.setString(1, player);
|
||||
ps.setString(2, region);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
int kills = 0;
|
||||
if (rs.next())
|
||||
kills = rs.getInt("kills");
|
||||
rs.close();
|
||||
ps.close();
|
||||
return kills;
|
||||
} catch (SQLException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public int getPVPDeaths(
|
||||
String player, String region) {
|
||||
try {
|
||||
PreparedStatement ps =
|
||||
db.prepareStatement(
|
||||
"SELECT deaths FROM "
|
||||
+ "pvp_kills "
|
||||
+ "WHERE "
|
||||
+ "player_name=? "
|
||||
+ "AND region_name=?");
|
||||
ps.setString(1, player);
|
||||
ps.setString(2, region);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
int deaths = 0;
|
||||
if (rs.next())
|
||||
deaths = rs.getInt("deaths");
|
||||
rs.close();
|
||||
ps.close();
|
||||
return deaths;
|
||||
} catch (SQLException e) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void addPVPKill(
|
||||
String player, String region) {
|
||||
try {
|
||||
PreparedStatement ps =
|
||||
db.prepareStatement(
|
||||
"INSERT INTO pvp_kills "
|
||||
+ "(player_name, "
|
||||
+ "region_name, "
|
||||
+ "kills, deaths) "
|
||||
+ "VALUES (?,?,1,0) "
|
||||
+ "ON CONFLICT"
|
||||
+ "(player_name, "
|
||||
+ "region_name) "
|
||||
+ "DO UPDATE SET "
|
||||
+ "kills=kills+1");
|
||||
ps.setString(1, player);
|
||||
ps.setString(2, region);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void addPVPDeath(
|
||||
String player, String region) {
|
||||
try {
|
||||
PreparedStatement ps =
|
||||
db.prepareStatement(
|
||||
"INSERT INTO pvp_kills "
|
||||
+ "(player_name, "
|
||||
+ "region_name, "
|
||||
+ "kills, deaths) "
|
||||
+ "VALUES (?,?,0,1) "
|
||||
+ "ON CONFLICT"
|
||||
+ "(player_name, "
|
||||
+ "region_name) "
|
||||
+ "DO UPDATE SET "
|
||||
+ "deaths=deaths+1");
|
||||
ps.setString(1, player);
|
||||
ps.setString(2, region);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public List<Map<String, Object>>
|
||||
getPVPKillTop(String region, int limit) {
|
||||
List<Map<String, Object>> list =
|
||||
new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps =
|
||||
db.prepareStatement(
|
||||
"SELECT player_name, "
|
||||
+ "kills, deaths "
|
||||
+ "FROM pvp_kills "
|
||||
+ "WHERE "
|
||||
+ "region_name=? "
|
||||
+ "AND kills>0 "
|
||||
+ "ORDER BY kills "
|
||||
+ "DESC LIMIT ?");
|
||||
ps.setString(1, region);
|
||||
ps.setInt(2, limit);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
Map<String, Object> row =
|
||||
new LinkedHashMap<>();
|
||||
row.put("player_name",
|
||||
rs.getString("player_name"));
|
||||
row.put("kills",
|
||||
rs.getInt("kills"));
|
||||
row.put("deaths",
|
||||
rs.getInt("deaths"));
|
||||
list.add(row);
|
||||
}
|
||||
rs.close();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
// ==================== 安全报警 ====================
|
||||
@@ -773,6 +1123,7 @@ public class DatabaseManager {
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public List<Map<String, Object>>
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
package Sdf1_login;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.persistence.PersistentDataType;
|
||||
import org.bukkit.util.io.BukkitObjectInputStream;
|
||||
import org.bukkit.util.io.BukkitObjectOutputStream;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.Base64;
|
||||
|
||||
public class MenuIconManager {
|
||||
|
||||
private final Main plugin;
|
||||
private final NamespacedKey iconKey;
|
||||
|
||||
public MenuIconManager(Main plugin) {
|
||||
this.plugin = plugin;
|
||||
this.iconKey = new NamespacedKey(
|
||||
plugin, "custom_menu_icon");
|
||||
}
|
||||
|
||||
// ========== GUIManager 调用的方法 ==========
|
||||
|
||||
/**
|
||||
* Base64 → ItemStack
|
||||
* 对应 GUIManager 中的
|
||||
* plugin.getMenuIconMgr().deserializeItem(...)
|
||||
*/
|
||||
public ItemStack deserializeItem(String b64) {
|
||||
if (b64 == null || b64.isEmpty())
|
||||
return null;
|
||||
try {
|
||||
byte[] data =
|
||||
Base64.getDecoder().decode(b64);
|
||||
ByteArrayInputStream bais =
|
||||
new ByteArrayInputStream(data);
|
||||
BukkitObjectInputStream is =
|
||||
new BukkitObjectInputStream(bais);
|
||||
Object obj = is.readObject();
|
||||
is.close();
|
||||
if (obj instanceof ItemStack)
|
||||
return (ItemStack) obj;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* ItemStack → Base64
|
||||
* 对应 GUIManager 中的
|
||||
* plugin.getMenuIconMgr().serializeItem(...)
|
||||
*/
|
||||
public String serializeItem(ItemStack item) {
|
||||
if (item == null) return null;
|
||||
try {
|
||||
ByteArrayOutputStream baos =
|
||||
new ByteArrayOutputStream();
|
||||
BukkitObjectOutputStream os =
|
||||
new BukkitObjectOutputStream(baos);
|
||||
os.writeObject(item);
|
||||
os.close();
|
||||
return Base64.getEncoder()
|
||||
.encodeToString(
|
||||
baos.toByteArray());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 给物品打上菜单图标标记
|
||||
* 对应 GUIManager 中的
|
||||
* plugin.getMenuIconMgr().ensureMenuIconTag(...)
|
||||
*/
|
||||
public void ensureMenuIconTag(ItemStack item) {
|
||||
if (item == null) return;
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null) return;
|
||||
meta.getPersistentDataContainer().set(
|
||||
iconKey,
|
||||
PersistentDataType.STRING,
|
||||
"menu");
|
||||
item.setItemMeta(meta);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图标Key
|
||||
* 对应 GUIManager 中的
|
||||
* plugin.getMenuIconMgr().getIconKey()
|
||||
*/
|
||||
public NamespacedKey getIconKey() {
|
||||
return iconKey;
|
||||
}
|
||||
|
||||
// ========== LoginManager / Main 调用的方法 ==========
|
||||
|
||||
/**
|
||||
* 获取玩家自定义图标物品
|
||||
* 有返回物品,无返回null
|
||||
*/
|
||||
public ItemStack getIcon(Player player) {
|
||||
String b64 = plugin.getDb()
|
||||
.getMenuIcon(player.getName());
|
||||
if (b64 == null || b64.isEmpty())
|
||||
return null;
|
||||
ItemStack item = deserializeItem(b64);
|
||||
if (item == null) return null;
|
||||
ensureMenuIconTag(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存图标到DB
|
||||
*/
|
||||
public void saveIcon(Player player,
|
||||
ItemStack item) {
|
||||
String b64 = serializeItem(item);
|
||||
if (b64 != null) {
|
||||
plugin.getDb().saveMenuIcon(
|
||||
player.getName(), b64,
|
||||
item.getType().name());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除图标
|
||||
*/
|
||||
public void removeIcon(Player player) {
|
||||
plugin.getDb().deleteMenuIcon(
|
||||
player.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查物品是否是自定义菜单图标
|
||||
*/
|
||||
public boolean isCustomMenuIcon(
|
||||
ItemStack item) {
|
||||
if (item == null) return false;
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
if (meta == null) return false;
|
||||
return meta.getPersistentDataContainer()
|
||||
.has(iconKey,
|
||||
PersistentDataType.STRING);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -250,6 +250,95 @@ public class RadioManager {
|
||||
Arrays.sort(files);
|
||||
for (File f : files) list.add(f);
|
||||
}
|
||||
/**
|
||||
* 解析 pack.png:优先读取插件目录,
|
||||
* 没有则搜索图片并用ffmpeg转码
|
||||
*/
|
||||
private File resolvePackIcon() {
|
||||
File dataDir = plugin.getDataFolder();
|
||||
File packPng = new File(dataDir, "pack.png");
|
||||
|
||||
if (packPng.exists()
|
||||
&& packPng.length() > 0) {
|
||||
plugin.getLogger().info(
|
||||
"[Radio] 找到 pack.png ("
|
||||
+ packPng.length()
|
||||
+ " bytes)");
|
||||
return packPng;
|
||||
}
|
||||
|
||||
// 搜索可转换的图片文件
|
||||
String[] exts = {"png", "jpg", "jpeg",
|
||||
"bmp", "webp", "tiff", "gif"};
|
||||
File[] found = dataDir.listFiles(
|
||||
(dir, name) -> {
|
||||
String low = name.toLowerCase();
|
||||
for (String ext : exts) {
|
||||
if (low.endsWith("." + ext)
|
||||
&& !name.equals(
|
||||
"pack.png")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
if (found != null && found.length > 0) {
|
||||
File src = found[0];
|
||||
plugin.getLogger().info(
|
||||
"[Radio] 找到图片: "
|
||||
+ src.getName()
|
||||
+ " → 转码为 pack.png");
|
||||
if (convertToPackPng(src, packPng)) {
|
||||
return packPng;
|
||||
}
|
||||
plugin.getLogger().warning(
|
||||
"[Radio] 转码失败");
|
||||
return null;
|
||||
}
|
||||
|
||||
plugin.getLogger().warning(
|
||||
"[Radio] 未找到 pack.png 或可转换图片");
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* ffmpeg 将任意图片转为 256x256 PNG
|
||||
*/
|
||||
private boolean convertToPackPng(
|
||||
File input, File output) {
|
||||
try {
|
||||
ProcessBuilder pb = new ProcessBuilder(
|
||||
"ffmpeg", "-y",
|
||||
"-i", input.getAbsolutePath(),
|
||||
"-vf",
|
||||
"scale='min(256,iw)'"
|
||||
+ ":'min(256,ih)':"
|
||||
+ "force_original_aspect_ratio"
|
||||
+ "=decrease,"
|
||||
+ "pad=256:256:"
|
||||
+ "(ow-iw)/2:"
|
||||
+ "(oh-ih)/2:"
|
||||
+ "color=0x00000000",
|
||||
"-c:v", "png",
|
||||
output.getAbsolutePath());
|
||||
pb.redirectErrorStream(true);
|
||||
Process p = pb.start();
|
||||
boolean ok = p.waitFor(
|
||||
30, TimeUnit.SECONDS);
|
||||
if (!ok) {
|
||||
p.destroyForcibly();
|
||||
return false;
|
||||
}
|
||||
return output.exists()
|
||||
&& output.length() > 0;
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warning(
|
||||
"[Radio] ffmpeg转码失败: "
|
||||
+ e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 资源包构建 ==========
|
||||
private void buildResourcePack() {
|
||||
@@ -320,6 +409,25 @@ public class RadioManager {
|
||||
plugin.getLogger().warning(
|
||||
"[Radio] sounds.json写入失败");
|
||||
}
|
||||
// sounds.json 写入后...
|
||||
|
||||
// ===== 新增:打包 pack.png 作为资源包图标 =====
|
||||
File iconPng = resolvePackIcon();
|
||||
if (iconPng != null && iconPng.exists()) {
|
||||
try {
|
||||
Files.copy(iconPng.toPath(),
|
||||
new File(packDir, "pack.png")
|
||||
.toPath(),
|
||||
StandardCopyOption
|
||||
.REPLACE_EXISTING);
|
||||
plugin.getLogger().info(
|
||||
"[Radio] pack.png 已加入资源包");
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warning(
|
||||
"[Radio] pack.png复制失败: "
|
||||
+ e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// pack.mcmeta(pack_format=54)
|
||||
try {
|
||||
@@ -407,30 +515,32 @@ public class RadioManager {
|
||||
// ========== 资源包发送 ==========
|
||||
|
||||
/**
|
||||
* 发送资源包(可选,不强制)
|
||||
* 优先用HTTP URL发送,兜底用byte[]
|
||||
* 发送资源包(带限流,不禁重试)
|
||||
*/
|
||||
private final Map<UUID, Long> lastSendTime =
|
||||
new ConcurrentHashMap<>();
|
||||
|
||||
public void sendResourcePack(Player p) {
|
||||
UUID uuid = p.getUniqueId();
|
||||
if (pendingPack.contains(uuid)) {
|
||||
|
||||
// 最短间隔 5秒(不是10秒的全锁死)
|
||||
Long last = lastSendTime.get(uuid);
|
||||
if (last != null
|
||||
&& System.currentTimeMillis() - last
|
||||
< 5000L) {
|
||||
plugin.getLogger().info(
|
||||
"[Radio] 跳过(已等待): "
|
||||
"[Radio] 跳过(5秒内): "
|
||||
+ p.getName());
|
||||
return;
|
||||
}
|
||||
pendingPack.add(uuid);
|
||||
Bukkit.getScheduler()
|
||||
.runTaskLater(plugin, () -> {
|
||||
pendingPack.remove(uuid);
|
||||
}, 200L);
|
||||
lastSendTime.put(uuid,
|
||||
System.currentTimeMillis());
|
||||
|
||||
String url = getResourcePackUrl();
|
||||
if (url == null || url.isEmpty()) {
|
||||
plugin.getLogger().warning(
|
||||
"[Radio] URL为空,"
|
||||
+ "跳过发送: "
|
||||
"[Radio] URL为空,跳过: "
|
||||
+ p.getName());
|
||||
pendingPack.remove(uuid);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -441,7 +551,6 @@ public class RadioManager {
|
||||
plugin.getLogger().warning(
|
||||
"[Radio] radiopack.zip不存在,"
|
||||
+ "跳过: " + p.getName());
|
||||
pendingPack.remove(uuid);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -452,22 +561,10 @@ public class RadioManager {
|
||||
long fileSize = zip.length();
|
||||
|
||||
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());
|
||||
"[Radio] 发送: " + p.getName()
|
||||
+ " url=" + url
|
||||
+ " size=" + fileSize
|
||||
+ " hash=" + hash);
|
||||
|
||||
sendPackWithHash(p, url, hash);
|
||||
|
||||
@@ -476,7 +573,6 @@ public class RadioManager {
|
||||
"[Radio] 发送异常: "
|
||||
+ p.getName());
|
||||
e.printStackTrace();
|
||||
pendingPack.remove(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -486,37 +582,38 @@ public class RadioManager {
|
||||
Player p,
|
||||
String url,
|
||||
String hash) {
|
||||
|
||||
UUID uuid = UUID.fromString(
|
||||
"a1b2c3d4-e5f6-7890-abcd-"
|
||||
+ "ef1234567890");
|
||||
|
||||
// 尝试5参 + Component
|
||||
try {
|
||||
Object component =
|
||||
net.kyori.adventure.text
|
||||
.Component.text(
|
||||
"§d§l服务器需要自定义资源包,请您点击'继续'由客户端自动下载即可");
|
||||
"§d§l请下载自定义资源包");
|
||||
p.getClass().getMethod(
|
||||
"setResourcePack",
|
||||
UUID.class,
|
||||
String.class,
|
||||
String.class,
|
||||
net.kyori.adventure
|
||||
.text
|
||||
.Component.class,
|
||||
.text.Component
|
||||
.class,
|
||||
boolean.class)
|
||||
.invoke(
|
||||
p, uuid, url,
|
||||
hash, component,
|
||||
true);
|
||||
plugin.getLogger().info(
|
||||
"[Radio] 发送成功: "
|
||||
+ p.getName()
|
||||
+ " url="
|
||||
+ url);
|
||||
"[Radio] 成功(5参): "
|
||||
+ p.getName());
|
||||
return;
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
// 尝试5参 + String描述
|
||||
try {
|
||||
p.getClass().getMethod(
|
||||
"setResourcePack",
|
||||
@@ -531,12 +628,13 @@ public class RadioManager {
|
||||
"Sdf1 Radio",
|
||||
true);
|
||||
plugin.getLogger().info(
|
||||
"[Radio] 旧版签名成功: "
|
||||
"[Radio] 成功(5参String): "
|
||||
+ p.getName());
|
||||
return;
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
// 尝试3参
|
||||
try {
|
||||
p.getClass().getMethod(
|
||||
"setResourcePack",
|
||||
@@ -547,18 +645,27 @@ public class RadioManager {
|
||||
p, uuid, url,
|
||||
hash);
|
||||
plugin.getLogger().info(
|
||||
"[Radio] 3参签名成功: "
|
||||
"[Radio] 成功(3参): "
|
||||
+ p.getName());
|
||||
return;
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
// ★ 全部失败 → 通知玩家 + 熔断
|
||||
plugin.getLogger().severe(
|
||||
"[Radio] 所有签名失败: "
|
||||
+ p.getName());
|
||||
+ p.getName()
|
||||
+ " 客户端版本: "
|
||||
+ p.getProtocolVersion());
|
||||
p.sendMessage(
|
||||
"§e§l[Radio] §f资源包发送失败,"
|
||||
+ "§7部分功能可能异常");
|
||||
p.sendMessage(
|
||||
"§7可尝试: §e/rejoin §7或重启客户端");
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void sendPackFromLocal(
|
||||
Player p, String url) {
|
||||
File zip = new File(
|
||||
@@ -610,7 +717,7 @@ public class RadioManager {
|
||||
}
|
||||
|
||||
public void clearPending(UUID uuid) {
|
||||
pendingPack.remove(uuid);
|
||||
lastSendTime.remove(uuid);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,370 @@
|
||||
package Sdf1_login;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.Base64;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class UserGroupManager {
|
||||
|
||||
private final Main plugin;
|
||||
private Connection db;
|
||||
private final Map<String, UserGroupConfig> groupConfigs = new ConcurrentHashMap<>();
|
||||
|
||||
public UserGroupManager(Main plugin) {
|
||||
this.plugin = plugin;
|
||||
initDB();
|
||||
loadGroupConfigs();
|
||||
startExpiryChecker();
|
||||
}
|
||||
|
||||
// ===== DB =====
|
||||
|
||||
private void initDB() {
|
||||
try {
|
||||
Class.forName("org.sqlite.JDBC");
|
||||
File dbFile = new File(plugin.getDataFolder(), "usergroup.db");
|
||||
db = DriverManager.getConnection("jdbc:sqlite:" + dbFile.getAbsolutePath());
|
||||
Statement st = db.createStatement();
|
||||
st.execute("PRAGMA journal_mode=WAL");
|
||||
st.execute("CREATE TABLE IF NOT EXISTS user_group_config ("
|
||||
+ "group_name TEXT PRIMARY KEY,"
|
||||
+ "display_name TEXT DEFAULT '',"
|
||||
+ "display_color TEXT DEFAULT '§f',"
|
||||
+ "display_emoji TEXT DEFAULT '',"
|
||||
+ "priority INTEGER DEFAULT 0,"
|
||||
+ "is_permanent INTEGER DEFAULT 1,"
|
||||
+ "duration_minutes INTEGER DEFAULT 0,"
|
||||
+ "pack_url TEXT DEFAULT '',"
|
||||
+ "pack_hash TEXT DEFAULT '',"
|
||||
+ "pack_prompt TEXT DEFAULT 'Custom Resource Pack',"
|
||||
+ "pack_size INTEGER DEFAULT 0)");
|
||||
st.execute("CREATE TABLE IF NOT EXISTS user_group_member ("
|
||||
+ "player_name TEXT NOT NULL,"
|
||||
+ "group_name TEXT NOT NULL,"
|
||||
+ "added_by TEXT DEFAULT 'system',"
|
||||
+ "added_time INTEGER DEFAULT 0,"
|
||||
+ "expiry_time INTEGER DEFAULT 0,"
|
||||
+ "PRIMARY KEY(player_name, group_name))");
|
||||
st.close();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("[UserGroup] DB init failed: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 配置加载 =====
|
||||
|
||||
public void loadGroupConfigs() {
|
||||
groupConfigs.clear();
|
||||
File dir = new File(plugin.getDataFolder(), "用户组");
|
||||
if (!dir.exists()) dir.mkdirs();
|
||||
File[] files = dir.listFiles((d, n) -> n.endsWith(".txt"));
|
||||
if (files == null) return;
|
||||
|
||||
for (File f : files) {
|
||||
try {
|
||||
List<String> lines = java.nio.file.Files.readAllLines(
|
||||
f.toPath(), StandardCharsets.UTF_8);
|
||||
UserGroupConfig cfg = parseGroupConfig(lines);
|
||||
if (cfg != null) {
|
||||
groupConfigs.put(cfg.name, cfg);
|
||||
saveGroupConfigToDB(cfg);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warning("[UserGroup] Failed to load: " + f.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private UserGroupConfig parseGroupConfig(List<String> lines) {
|
||||
UserGroupConfig cfg = new UserGroupConfig();
|
||||
boolean inBlock = false;
|
||||
|
||||
for (String raw : lines) {
|
||||
String l = raw;
|
||||
|
||||
// 块注释
|
||||
if (l.contains("<!--")) { inBlock = true; continue; }
|
||||
if (l.contains("-->")) { inBlock = false; continue; }
|
||||
if (l.contains("/*")) { inBlock = true; continue; }
|
||||
if (l.contains("*/")) { inBlock = false; continue; }
|
||||
if (inBlock) continue;
|
||||
|
||||
// 行注释
|
||||
l = l.trim();
|
||||
if (l.isEmpty()) continue;
|
||||
if (l.startsWith("#") || l.startsWith("//")) continue;
|
||||
|
||||
// 行内注释
|
||||
int h = l.indexOf('#');
|
||||
int s = l.indexOf("//");
|
||||
if (h >= 0) l = l.substring(0, h).trim();
|
||||
if (s >= 0 && (h < 0 || s < h)) l = l.substring(0, s).trim();
|
||||
if (l.isEmpty()) continue;
|
||||
|
||||
// 解析键值对
|
||||
String key = l;
|
||||
String val = "";
|
||||
int idx = l.indexOf('\uff1a');
|
||||
if (idx < 0) idx = l.indexOf(':');
|
||||
if (idx >= 0) {
|
||||
key = l.substring(0, idx).trim();
|
||||
val = l.substring(idx + 1).trim();
|
||||
if (val.startsWith("\"") && val.endsWith("\""))
|
||||
val = val.substring(1, val.length() - 1);
|
||||
}
|
||||
|
||||
switch (key) {
|
||||
case "组名":
|
||||
case "name": cfg.name = val; break;
|
||||
case "显示名":
|
||||
case "display": cfg.displayName = val; break;
|
||||
case "颜色":
|
||||
case "color": cfg.displayColor = val; break;
|
||||
case "符号":
|
||||
case "emoji": cfg.displayEmoji = val; break;
|
||||
case "优先级":
|
||||
case "priority":
|
||||
try { cfg.priority = Integer.parseInt(val); } catch (Exception ignored) {}
|
||||
break;
|
||||
case "类型":
|
||||
case "type":
|
||||
cfg.permanent = val.equalsIgnoreCase("永久") || val.equalsIgnoreCase("permanent");
|
||||
break;
|
||||
case "时长":
|
||||
case "duration":
|
||||
try { cfg.durationMinutes = Integer.parseInt(val); } catch (Exception ignored) {}
|
||||
break;
|
||||
case "资源包URL":
|
||||
case "pack_url": cfg.packUrl = val; break;
|
||||
case "资源包Hash":
|
||||
case "pack_hash": cfg.packHash = val; break;
|
||||
case "资源包提示":
|
||||
case "pack_prompt": cfg.packPrompt = val; break;
|
||||
case "资源包大小":
|
||||
case "pack_size":
|
||||
try { cfg.packSize = Integer.parseInt(val); } catch (Exception ignored) {}
|
||||
break;
|
||||
case "本地文件":
|
||||
case "local_file": cfg.localFile = val; break;
|
||||
}
|
||||
}
|
||||
|
||||
if (cfg.name == null || cfg.name.isEmpty()) return null;
|
||||
return cfg;
|
||||
}
|
||||
|
||||
private void saveGroupConfigToDB(UserGroupConfig cfg) {
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"INSERT OR REPLACE INTO user_group_config "
|
||||
+ "(group_name, display_name, display_color, display_emoji,"
|
||||
+ " priority, is_permanent, duration_minutes,"
|
||||
+ " pack_url, pack_hash, pack_prompt, pack_size)"
|
||||
+ " VALUES (?,?,?,?,?,?,?,?,?,?,?)");
|
||||
ps.setString(1, cfg.name);
|
||||
ps.setString(2, cfg.displayName);
|
||||
ps.setString(3, cfg.displayColor);
|
||||
ps.setString(4, cfg.displayEmoji);
|
||||
ps.setInt(5, cfg.priority);
|
||||
ps.setInt(6, cfg.permanent ? 1 : 0);
|
||||
ps.setInt(7, cfg.durationMinutes);
|
||||
ps.setString(8, cfg.packUrl);
|
||||
ps.setString(9, cfg.packHash);
|
||||
ps.setString(10, cfg.packPrompt);
|
||||
ps.setInt(11, cfg.packSize);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 玩家操作 =====
|
||||
|
||||
public boolean addPlayer(String player, String groupName, String addedBy, long durationMinutes) {
|
||||
UserGroupConfig cfg = groupConfigs.get(groupName);
|
||||
if (cfg == null) return false;
|
||||
long now = System.currentTimeMillis();
|
||||
long expiry = cfg.permanent ? 0 : now + durationMinutes * 60 * 1000;
|
||||
if (!cfg.permanent && durationMinutes > 0) expiry = now + durationMinutes * 60 * 1000;
|
||||
else if (!cfg.permanent) expiry = now + cfg.durationMinutes * 60 * 1000;
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"INSERT OR REPLACE INTO user_group_member "
|
||||
+ "(player_name, group_name, added_by, added_time, expiry_time)"
|
||||
+ " VALUES (?,?,?,?,?)");
|
||||
ps.setString(1, player);
|
||||
ps.setString(2, groupName);
|
||||
ps.setString(3, addedBy);
|
||||
ps.setLong(4, now);
|
||||
ps.setLong(5, expiry);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
Player p = plugin.getServer().getPlayerExact(player);
|
||||
if (p != null) sendResourcePack(p);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean removePlayer(String player, String groupName) {
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"DELETE FROM user_group_member WHERE player_name=? AND group_name=?");
|
||||
ps.setString(1, player);
|
||||
ps.setString(2, groupName);
|
||||
int rows = ps.executeUpdate();
|
||||
ps.close();
|
||||
return rows > 0;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> getPlayerGroups(String player) {
|
||||
List<Map<String, Object>> list = new ArrayList<>();
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"SELECT * FROM user_group_member WHERE player_name=?");
|
||||
ps.setString(1, player);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
long now = System.currentTimeMillis();
|
||||
while (rs.next()) {
|
||||
Map<String, Object> row = new LinkedHashMap<>();
|
||||
row.put("group_name", rs.getString("group_name"));
|
||||
row.put("added_by", rs.getString("added_by"));
|
||||
long expiry = rs.getLong("expiry_time");
|
||||
row.put("expiry_time", expiry);
|
||||
row.put("expired", expiry > 0 && expiry <= now);
|
||||
list.add(row);
|
||||
}
|
||||
rs.close(); ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public UserGroupConfig getHighestGroup(String player) {
|
||||
List<Map<String, Object>> groups = getPlayerGroups(player);
|
||||
long now = System.currentTimeMillis();
|
||||
UserGroupConfig best = null;
|
||||
for (Map<String, Object> g : groups) {
|
||||
long expiry = (long) g.get("expiry_time");
|
||||
if (expiry > 0 && expiry <= now) continue;
|
||||
String name = (String) g.get("group_name");
|
||||
UserGroupConfig cfg = groupConfigs.get(name);
|
||||
if (cfg != null && (best == null || cfg.priority > best.priority)) {
|
||||
best = cfg;
|
||||
}
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
public boolean isPlayerInGroup(String player, String groupName) {
|
||||
try {
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"SELECT 1 FROM user_group_member WHERE player_name=? AND group_name=?");
|
||||
ps.setString(1, player);
|
||||
ps.setString(2, groupName);
|
||||
boolean exists = ps.executeQuery().next();
|
||||
ps.close();
|
||||
return exists;
|
||||
} catch (SQLException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 过期自动移除 =====
|
||||
|
||||
private void startExpiryChecker() {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
checkExpiry();
|
||||
}
|
||||
}.runTaskTimerAsynchronously(plugin, 1200L, 1200L); // 每分钟检查
|
||||
}
|
||||
|
||||
private void checkExpiry() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
PreparedStatement ps = db.prepareStatement(
|
||||
"SELECT player_name, group_name FROM user_group_member "
|
||||
+ "WHERE expiry_time > 0 AND expiry_time <= ?");
|
||||
ps.setLong(1, now);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
List<String[]> expired = new ArrayList<>();
|
||||
while (rs.next()) {
|
||||
expired.add(new String[]{
|
||||
rs.getString("player_name"),
|
||||
rs.getString("group_name")});
|
||||
}
|
||||
rs.close(); ps.close();
|
||||
|
||||
for (String[] e : expired) {
|
||||
PreparedStatement del = db.prepareStatement(
|
||||
"DELETE FROM user_group_member WHERE player_name=? AND group_name=?");
|
||||
del.setString(1, e[0]);
|
||||
del.setString(2, e[1]);
|
||||
del.executeUpdate();
|
||||
del.close();
|
||||
plugin.getLogger().info("[UserGroup] 过期移除: " + e[0] + " -> " + e[1]);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
// ===== 资源包分发 =====
|
||||
|
||||
public void sendResourcePack(Player p) {
|
||||
UserGroupConfig cfg = getHighestGroup(p.getName());
|
||||
if (cfg == null || cfg.packUrl == null || cfg.packUrl.isEmpty()) return;
|
||||
|
||||
String url = cfg.packUrl;
|
||||
String prompt = cfg.packPrompt != null
|
||||
? cfg.packPrompt : "Custom Resource Pack";
|
||||
|
||||
plugin.getServer().getScheduler().runTaskLater(plugin, () -> {
|
||||
try {
|
||||
p.setResourcePack(url, new byte[0], prompt, false);
|
||||
plugin.getLogger().info("[UserGroup] 资源包已发送: "
|
||||
+ p.getName() + " -> " + cfg.displayName);
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warning(
|
||||
"[UserGroup] 资源包发送失败: " + e.getMessage());
|
||||
}
|
||||
}, 40L);
|
||||
}
|
||||
|
||||
public Map<String, UserGroupConfig> getGroupConfigs() {
|
||||
return groupConfigs;
|
||||
}
|
||||
|
||||
// ===== 配置类 =====
|
||||
|
||||
public static class UserGroupConfig {
|
||||
public String name;
|
||||
public String displayName = "";
|
||||
public String displayColor = "§f";
|
||||
public String displayEmoji = "";
|
||||
public int priority = 0;
|
||||
public boolean permanent = true;
|
||||
public int durationMinutes = 0;
|
||||
public String packUrl = "";
|
||||
public String packHash = "";
|
||||
public String packPrompt = "Custom Resource Pack";
|
||||
public int packSize = 0;
|
||||
public String localFile = "";
|
||||
}
|
||||
}
|
||||
@@ -60,9 +60,9 @@ commands:
|
||||
deny:
|
||||
description: 拒绝OA请求
|
||||
usage: /deny <编号> [理由]
|
||||
sdf1debug:
|
||||
description: 调试指令
|
||||
usage: /sdf1debug <玩家> take.<阶段>
|
||||
#sdf1debug:
|
||||
# description: 调试指令
|
||||
# usage: /sdf1debug <玩家> take.<阶段>
|
||||
email:
|
||||
description: 绑定邮箱
|
||||
usage: /email <邮箱>
|
||||
@@ -87,3 +87,12 @@ commands:
|
||||
menu:
|
||||
description: 雪球菜单开关控制
|
||||
usage: /menu <开/关>
|
||||
pvp :
|
||||
description: PVP榜单
|
||||
usage: /pvp
|
||||
cypay :
|
||||
description: 草原探险债券
|
||||
usage: /cypay
|
||||
printer :
|
||||
description: 打印债券流水
|
||||
usage: /printer
|
||||
Reference in New Issue
Block a user