From 746416e3c9239c7450a84ddaf79e26868ec7248d Mon Sep 17 00:00:00 2001
From: yaohunya <31456652@qq.com>
Date: Sun, 14 Jul 2024 21:20:39 +0800
Subject: [PATCH] test111
---
.gitignore | 28 +---
.idea/.gitignore | 8 ++
.idea/compiler.xml | 13 ++
.idea/jarRepositories.xml | 25 ++++
.idea/misc.xml | 14 ++
.idea/uiDesigner.xml | 124 +++++++++++++++++
.idea/vcs.xml | 6 +
.../java/com/yaohun/aurechargedata/Main.java | 3 +
.../yaohun/aurechargedata/api/ConsumeAPI.java | 4 +
.../aurechargedata/api/RechargeAPI.java | 130 ++++++++++++++++++
.../yaohun/aurechargedata/data/DayData.java | 4 -
.../yaohun/aurechargedata/data/MonthData.java | 4 -
.../aurechargedata/data/PlayerData.java | 75 ++++++++++
.../yaohun/aurechargedata/data/TermData.java | 4 -
.../aurechargedata/manage/ConsumeManage.java | 65 ++++-----
.../aurechargedata/manage/RechargeManage.java | 69 +++++-----
.../yaohun/aurechargedata/util/TimeType.java | 5 +
src/main/resources/recharge.yml | 2 +-
target/classes/recharge.yml | 2 +-
19 files changed, 480 insertions(+), 105 deletions(-)
create mode 100644 .idea/.gitignore
create mode 100644 .idea/compiler.xml
create mode 100644 .idea/jarRepositories.xml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/uiDesigner.xml
create mode 100644 .idea/vcs.xml
create mode 100644 src/main/java/com/yaohun/aurechargedata/api/ConsumeAPI.java
create mode 100644 src/main/java/com/yaohun/aurechargedata/api/RechargeAPI.java
delete mode 100644 src/main/java/com/yaohun/aurechargedata/data/DayData.java
delete mode 100644 src/main/java/com/yaohun/aurechargedata/data/MonthData.java
create mode 100644 src/main/java/com/yaohun/aurechargedata/data/PlayerData.java
delete mode 100644 src/main/java/com/yaohun/aurechargedata/data/TermData.java
create mode 100644 src/main/java/com/yaohun/aurechargedata/util/TimeType.java
diff --git a/.gitignore b/.gitignore
index 9154f4c..981c582 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,26 +1,2 @@
-# ---> Java
-# Compiled class file
-*.class
-
-# Log file
-*.log
-
-# BlueJ files
-*.ctxt
-
-# Mobile Tools for Java (J2ME)
-.mtj.tmp/
-
-# Package Files #
-*.jar
-*.war
-*.nar
-*.ear
-*.zip
-*.tar.gz
-*.rar
-
-# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
-hs_err_pid*
-replay_pid*
-
+/.idea/
+/target/
\ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..35410ca
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..28569e9
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
new file mode 100644
index 0000000..551c8bc
--- /dev/null
+++ b/.idea/jarRepositories.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..132404b
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml
new file mode 100644
index 0000000..2b63946
--- /dev/null
+++ b/.idea/uiDesigner.xml
@@ -0,0 +1,124 @@
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+ -
+
+
+
+
+ -
+
+
+ -
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/com/yaohun/aurechargedata/Main.java b/src/main/java/com/yaohun/aurechargedata/Main.java
index c819024..9bcd30f 100644
--- a/src/main/java/com/yaohun/aurechargedata/Main.java
+++ b/src/main/java/com/yaohun/aurechargedata/Main.java
@@ -1,7 +1,9 @@
package com.yaohun.aurechargedata;
+import com.yaohun.aurechargedata.api.RechargeAPI;
import com.yaohun.aurechargedata.manage.ConsumeManage;
import com.yaohun.aurechargedata.manage.RechargeManage;
+import com.yaohun.aurechargedata.util.TimeType;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
@@ -12,6 +14,7 @@ public class Main extends JavaPlugin {
@Override
public void onEnable() {
plugin = this;
+ saveDefaultConfig();
rechargeManage = new RechargeManage();
consumeManage = new ConsumeManage();
}
diff --git a/src/main/java/com/yaohun/aurechargedata/api/ConsumeAPI.java b/src/main/java/com/yaohun/aurechargedata/api/ConsumeAPI.java
new file mode 100644
index 0000000..d6bcb2c
--- /dev/null
+++ b/src/main/java/com/yaohun/aurechargedata/api/ConsumeAPI.java
@@ -0,0 +1,4 @@
+package com.yaohun.aurechargedata.api;
+
+public class ConsumeAPI {
+}
diff --git a/src/main/java/com/yaohun/aurechargedata/api/RechargeAPI.java b/src/main/java/com/yaohun/aurechargedata/api/RechargeAPI.java
new file mode 100644
index 0000000..e3f47ab
--- /dev/null
+++ b/src/main/java/com/yaohun/aurechargedata/api/RechargeAPI.java
@@ -0,0 +1,130 @@
+package com.yaohun.aurechargedata.api;
+
+import com.yaohun.aurechargedata.Main;
+import com.yaohun.aurechargedata.data.PlayerData;
+import com.yaohun.aurechargedata.manage.RechargeManage;
+import com.yaohun.aurechargedata.util.TimeType;
+import org.bukkit.configuration.file.FileConfiguration;
+
+public abstract class RechargeAPI {
+
+ public static void setRechargeData(String name, int money) {
+ RechargeManage manage = Main.rechargeManage; // 获取充值管理实例
+ PlayerData dataAPI = manage.getPlayerData(name); // 获取玩家的充值数据实例
+ // 设置玩家的每日、每月和年度充值数据为指定金额
+ dataAPI.setValueData(TimeType.Daily, money); // 设置每日充值数据
+ dataAPI.setValueData(TimeType.Monthly, money); // 设置每月充值数据
+ dataAPI.setValueData(TimeType.Annual, money); // 设置年度充值数据
+ }
+ // 增加累积充值金额
+ public static void addRechargeData(String name, int money) {
+ RechargeManage manage = Main.rechargeManage; // 获取充值管理实例
+ PlayerData dataAPI = manage.getPlayerData(name); // 获取玩家的充值数据实例
+ // 向玩家的每日、每月和年度充值数据中添加指定金额
+ dataAPI.addValueData(TimeType.Daily, money); // 增加每日充值数据
+ dataAPI.addValueData(TimeType.Monthly, money); // 增加每月充值数据
+ dataAPI.addValueData(TimeType.Annual, money); // 增加年度充值数据
+ }
+ public static void takeRechargeData(String name, int money) {
+ RechargeManage manage = Main.rechargeManage; // 获取充值管理实例
+ PlayerData dataAPI = manage.getPlayerData(name); // 获取玩家的充值数据实例
+ // 减少玩家的每日、每月和年度充值数据
+ int currentDaily = dataAPI.getValueData(TimeType.Daily);
+ if (currentDaily >= money) {
+ dataAPI.setValueData(TimeType.Daily, currentDaily - money); // 减少每日充值数据
+ } else {
+ dataAPI.setValueData(TimeType.Daily, 0); // 如果减少金额大于当前累积值,设为0
+ }
+ int currentMonthly = dataAPI.getValueData(TimeType.Monthly);
+ if (currentMonthly >= money) {
+ dataAPI.setValueData(TimeType.Monthly, currentMonthly - money); // 减少每月充值数据
+ } else {
+ dataAPI.setValueData(TimeType.Monthly, 0); // 如果减少金额大于当前累积值,设为0
+ }
+ int currentAnnual = dataAPI.getValueData(TimeType.Annual);
+ if (currentAnnual >= money) {
+ dataAPI.setValueData(TimeType.Annual, currentAnnual - money); // 减少年度充值数据
+ } else {
+ dataAPI.setValueData(TimeType.Annual, 0); // 如果减少金额大于当前累积值,设为0
+ }
+ }
+
+ // 增加累积充值金额
+ public static void addRechargeData(String name,int money,TimeType timeType) {
+ RechargeManage manage = Main.rechargeManage; // 获取充值管理实例
+ PlayerData dataAPI = manage.getPlayerData(name); // 获取玩家的充值数据实例
+ // 根据时间类型向玩家的充值数据中添加指定金额
+ if (timeType == TimeType.Daily) {
+ dataAPI.addValueData(TimeType.Daily, money); // 增加每日充值数据
+ dataAPI.addValueData(TimeType.Monthly, money); // 增加每月充值数据
+ dataAPI.addValueData(TimeType.Annual, money); // 增加年度充值数据
+ } else if (timeType == TimeType.Monthly) {
+ dataAPI.addValueData(TimeType.Monthly, money); // 增加每月充值数据
+ dataAPI.addValueData(TimeType.Annual, money); // 增加年度充值数据
+ } else if (timeType == TimeType.Annual) {
+ dataAPI.addValueData(TimeType.Annual, money); // 增加年度充值数据
+ }
+ }
+
+ public void setRechargeData(String name, int money, TimeType timeType) {
+ RechargeManage manage = Main.rechargeManage; // 获取充值管理实例
+ PlayerData dataAPI = manage.getPlayerData(name); // 获取玩家的充值数据实例
+ // 根据时间类型设置玩家的累积充值数据
+ if (timeType == TimeType.Daily) {
+ dataAPI.setValueData(TimeType.Daily, money); // 设置每日累积充值数据
+ dataAPI.setValueData(TimeType.Monthly, money); // 设置每月累积充值数据
+ dataAPI.setValueData(TimeType.Annual, money); // 设置年度累积充值数据
+ } else if (timeType == TimeType.Monthly) {
+ dataAPI.setValueData(TimeType.Monthly, money); // 设置每月累积充值数据
+ dataAPI.setValueData(TimeType.Annual, money); // 设置年度累积充值数据
+ } else if (timeType == TimeType.Annual) {
+ dataAPI.setValueData(TimeType.Annual, money); // 设置年度累积充值数据
+ }
+ }
+
+ public void takeRechargeData(String name, int money, TimeType timeType) {
+ RechargeManage manage = Main.rechargeManage; // 获取充值管理实例
+ PlayerData dataAPI = manage.getPlayerData(name); // 获取玩家的充值数据实例
+ // 根据时间类型减少玩家的累积充值数据
+ if (timeType == TimeType.Daily) {
+ int currentDaily = dataAPI.getValueData(TimeType.Daily);
+ if (currentDaily >= money) {
+ dataAPI.setValueData(TimeType.Daily, currentDaily - money); // 减少每日累积充值数据
+ } else {
+ dataAPI.setValueData(TimeType.Daily, 0); // 如果减少金额大于当前累积值,设为0
+ }
+ int currentMonthly = dataAPI.getValueData(TimeType.Monthly);
+ if (currentMonthly >= money) {
+ dataAPI.setValueData(TimeType.Monthly, currentMonthly - money); // 减少每月累积充值数据
+ } else {
+ dataAPI.setValueData(TimeType.Monthly, 0); // 如果减少金额大于当前累积值,设为0
+ }
+ int currentAnnual = dataAPI.getValueData(TimeType.Annual);
+ if (currentAnnual >= money) {
+ dataAPI.setValueData(TimeType.Annual, currentAnnual - money); // 减少年度累积充值数据
+ } else {
+ dataAPI.setValueData(TimeType.Annual, 0); // 如果减少金额大于当前累积值,设为0
+ }
+ } else if (timeType == TimeType.Monthly) {
+ int currentMonthly = dataAPI.getValueData(TimeType.Monthly);
+ if (currentMonthly >= money) {
+ dataAPI.setValueData(TimeType.Monthly, currentMonthly - money); // 减少每月累积充值数据
+ } else {
+ dataAPI.setValueData(TimeType.Monthly, 0); // 如果减少金额大于当前累积值,设为0
+ }
+ int currentAnnual = dataAPI.getValueData(TimeType.Annual);
+ if (currentAnnual >= money) {
+ dataAPI.setValueData(TimeType.Annual, currentAnnual - money); // 减少年度累积充值数据
+ } else {
+ dataAPI.setValueData(TimeType.Annual, 0); // 如果减少金额大于当前累积值,设为0
+ }
+ } else if (timeType == TimeType.Annual) {
+ int currentAnnual = dataAPI.getValueData(TimeType.Annual);
+ if (currentAnnual >= money) {
+ dataAPI.setValueData(TimeType.Annual, currentAnnual - money); // 减少年度累积充值数据
+ } else {
+ dataAPI.setValueData(TimeType.Annual, 0); // 如果减少金额大于当前累积值,设为0
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/yaohun/aurechargedata/data/DayData.java b/src/main/java/com/yaohun/aurechargedata/data/DayData.java
deleted file mode 100644
index 8600bd5..0000000
--- a/src/main/java/com/yaohun/aurechargedata/data/DayData.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.yaohun.aurechargedata.data;
-
-public class DayData {
-}
diff --git a/src/main/java/com/yaohun/aurechargedata/data/MonthData.java b/src/main/java/com/yaohun/aurechargedata/data/MonthData.java
deleted file mode 100644
index 2595c46..0000000
--- a/src/main/java/com/yaohun/aurechargedata/data/MonthData.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.yaohun.aurechargedata.data;
-
-public class MonthData {
-}
diff --git a/src/main/java/com/yaohun/aurechargedata/data/PlayerData.java b/src/main/java/com/yaohun/aurechargedata/data/PlayerData.java
new file mode 100644
index 0000000..a5e53e7
--- /dev/null
+++ b/src/main/java/com/yaohun/aurechargedata/data/PlayerData.java
@@ -0,0 +1,75 @@
+package com.yaohun.aurechargedata.data;
+
+import com.yaohun.aurechargedata.util.TimeType;
+import org.bukkit.configuration.ConfigurationSection;
+
+import java.util.HashMap;
+
+public class PlayerData {
+
+ private String name; // 玩家名称
+ private HashMap valueMap; // 存储时间类型和对应值的映射
+
+ // 构造函数,从配置节中加载玩家数据
+ public PlayerData(String name, ConfigurationSection section) {
+ this.name = name; // 设置玩家名称
+ this.valueMap = new HashMap<>(); // 创建一个新的映射
+ // 如果配置节不为空,则加载数据
+ if (section != null) {
+ // 遍历配置节中的所有键
+ for (String dataKey : section.getKeys(false)) {
+ int value = section.getInt(dataKey); // 获取键对应的整数值
+ // 根据键名将值存储到不同的时间类型中
+ if (dataKey.equalsIgnoreCase("daydata")) {
+ valueMap.put(TimeType.Daily, value); // 每日数据
+ } else if (dataKey.equalsIgnoreCase("monthdata")) {
+ valueMap.put(TimeType.Monthly, value); // 每月数据
+ } else {
+ valueMap.put(TimeType.Annual, value); // 年度数据
+ }
+ }
+ }else{
+ // 配置节为空时存入默认数据
+ valueMap.put(TimeType.Daily, 0);
+ valueMap.put(TimeType.Monthly, 0);
+ valueMap.put(TimeType.Annual, 0);
+ }
+ }
+
+ // 获取玩家名称
+ public String getName() {
+ return name;
+ }
+
+ // 根据时间类型获取对应的值,如果值不存在返回 -1
+ public int getValueData(TimeType timeType) {
+ return valueMap.getOrDefault(timeType, -1);
+ }
+
+ // 设置特定时间类型的值
+ public void setValueData(TimeType timeType, Integer amount) {
+ valueMap.put(timeType, amount);
+ }
+
+ // 增加特定时间类型的值
+ public void addValueData(TimeType timeType, Integer amount) {
+ Integer currentValue = valueMap.getOrDefault(timeType, 0);
+ int newAmount = currentValue + amount;
+ valueMap.put(timeType, newAmount);
+ }
+
+ public HashMap getValueMap() {
+ return valueMap;
+ }
+
+ // 根据时间类型返回对应的数据键名
+ public String getTimeToString(TimeType timeType) {
+ if (timeType == TimeType.Daily) {
+ return "daydata"; // 如果时间类型是每日,则返回对应的数据键名
+ } else if (timeType == TimeType.Monthly) {
+ return "monthdata"; // 如果时间类型是每月,则返回对应的数据键名
+ }
+ return "annualData"; // 默认情况下返回年度数据键名
+ }
+
+}
diff --git a/src/main/java/com/yaohun/aurechargedata/data/TermData.java b/src/main/java/com/yaohun/aurechargedata/data/TermData.java
deleted file mode 100644
index 276a009..0000000
--- a/src/main/java/com/yaohun/aurechargedata/data/TermData.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package com.yaohun.aurechargedata.data;
-
-public class TermData {
-}
diff --git a/src/main/java/com/yaohun/aurechargedata/manage/ConsumeManage.java b/src/main/java/com/yaohun/aurechargedata/manage/ConsumeManage.java
index c4de133..afc3c0a 100644
--- a/src/main/java/com/yaohun/aurechargedata/manage/ConsumeManage.java
+++ b/src/main/java/com/yaohun/aurechargedata/manage/ConsumeManage.java
@@ -1,5 +1,9 @@
package com.yaohun.aurechargedata.manage;
+import com.yaohun.aurechargedata.data.PlayerData;
+import com.yaohun.aurechargedata.util.TimeType;
+import org.bukkit.Bukkit;
+import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -12,51 +16,42 @@ public class ConsumeManage {
private File file;
private FileConfiguration yml;
private String dataKey = "ConsumeData";
- private HashMap consumeData = new HashMap<>();
- private HashMap dayDataMap = new HashMap<>();
- private HashMap monthDataMap = new HashMap<>();
+ private HashMap dataHashMap = new HashMap<>();
public ConsumeManage(){
file = new File("plugins/AuRechargeData", "consume.yml");
+ // 如果文件不存在,则创建新文件
+ if (!file.exists()) {
+ try {
+ file.getParentFile().mkdirs(); // 确保父文件夹存在
+ file.createNewFile(); // 创建新文件
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
yml = YamlConfiguration.loadConfiguration(file);
// 检查配置文件中是否包含 "RechargeData" 节点
if (yml.getConfigurationSection(dataKey) != null) {
// 遍历 "RechargeData" 节点下的所有键(用户名)
for (String name : yml.getConfigurationSection(dataKey).getKeys(false)) {
- // 构建键路径前缀
- String str = dataKey+"." + name + ".";
- // 获取每日充值数据并存储到 dayDataMap
- double day = yml.getDouble(str + "daydata");
- dayDataMap.put(name, day);
- // 获取每月充值数据并存储到 monthDataMap
- double month = yml.getDouble(str + "monthdata");
- monthDataMap.put(name, month);
- // 获取长期充值数据并存储到 rechargeData
- double term = yml.getDouble(str + "longTermData");
- consumeData.put(name, term);
+ ConfigurationSection section = yml.getConfigurationSection(dataKey+"."+name);
+ dataHashMap.put(name,new PlayerData(name,section));
}
}
+ Bukkit.getConsoleSender().sendMessage("§6[充值数据] §f已有消费记录的玩家: §a" + dataHashMap.size() + "名");
}
public void SaveData(){
yml.set(dataKey,null);
- // 保存 dayDataMap 到配置文件
- for (Map.Entry entry : dayDataMap.entrySet()) {
- String name = entry.getKey();
- double dayData = entry.getValue();
- yml.set(dataKey+"." + name + ".daydata", dayData);
- }
- // 保存 monthDataMap 到配置文件
- for (Map.Entry entry : monthDataMap.entrySet()) {
- String name = entry.getKey();
- double monthData = entry.getValue();
- yml.set(dataKey+"." + name + ".monthdata", monthData);
- }
- // 保存 rechargeData 到配置文件
- for (Map.Entry entry : consumeData.entrySet()) {
- String name = entry.getKey();
- double longTermData = entry.getValue();
- yml.set(dataKey+"." + name + ".longTermData", longTermData);
+ for (String name : dataHashMap.keySet()){
+ PlayerData playerData = dataHashMap.get(name);
+ for (TimeType timeType : playerData.getValueMap().keySet()){
+ int value = playerData.getValueData(timeType);
+ String timeKey = playerData.getTimeToString(timeType);
+ if(value >= 1) {
+ yml.set(dataKey + "." + name + "." + timeKey, value);
+ }
+ }
}
// 保存配置文件
try {
@@ -65,4 +60,12 @@ public class ConsumeManage {
e.printStackTrace();
}
}
+
+ public PlayerData getPlayerData(String name) {
+ if(dataHashMap.get(name) == null){
+ dataHashMap.put(name,new PlayerData(name,null));
+ return dataHashMap.get(name);
+ }
+ return dataHashMap.get(name);
+ }
}
diff --git a/src/main/java/com/yaohun/aurechargedata/manage/RechargeManage.java b/src/main/java/com/yaohun/aurechargedata/manage/RechargeManage.java
index 1ea6ffd..c7f67ad 100644
--- a/src/main/java/com/yaohun/aurechargedata/manage/RechargeManage.java
+++ b/src/main/java/com/yaohun/aurechargedata/manage/RechargeManage.java
@@ -1,10 +1,12 @@
package com.yaohun.aurechargedata.manage;
-import com.yaohun.aurechargedata.data.DayData;
-import com.yaohun.aurechargedata.data.MonthData;
-import com.yaohun.aurechargedata.data.TermData;
+import com.yaohun.aurechargedata.data.PlayerData;
+import com.yaohun.aurechargedata.util.TimeType;
+import org.bukkit.Bukkit;
+import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
+import org.bukkit.entity.Player;
import java.io.File;
import java.io.IOException;
@@ -16,51 +18,42 @@ public class RechargeManage {
private File file;
private FileConfiguration yml;
private String dataKey = "RechargeData";
- private HashMap rechargeData = new HashMap<>();
- private HashMap dayDataMap = new HashMap<>();
- private HashMap monthDataMap = new HashMap<>();
+ private HashMap dataHashMap = new HashMap<>();
public RechargeManage(){
file = new File("plugins/AuRechargeData", "recharge.yml");
+ // 如果文件不存在,则创建新文件
+ if (!file.exists()) {
+ try {
+ file.getParentFile().mkdirs(); // 确保父文件夹存在
+ file.createNewFile(); // 创建新文件
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
yml = YamlConfiguration.loadConfiguration(file);
// 检查配置文件中是否包含 "RechargeData" 节点
if (yml.getConfigurationSection(dataKey) != null) {
// 遍历 "RechargeData" 节点下的所有键(用户名)
for (String name : yml.getConfigurationSection(dataKey).getKeys(false)) {
- // 构建键路径前缀
- String str = dataKey+"." + name + ".";
- // 获取每日充值数据并存储到 dayDataMap
- double day = yml.getDouble(str + "daydata");
- dayDataMap.put(name, day);
- // 获取每月充值数据并存储到 monthDataMap
- double month = yml.getDouble(str + "monthdata");
- monthDataMap.put(name, month);
- // 获取长期充值数据并存储到 rechargeData
- double term = yml.getDouble(str + "longTermData");
- rechargeData.put(name, term);
+ ConfigurationSection section = yml.getConfigurationSection(dataKey+"."+name);
+ dataHashMap.put(name,new PlayerData(name,section));
}
}
+ Bukkit.getConsoleSender().sendMessage("§6[充值数据] §f已有充值记录的玩家: §a" + dataHashMap.size() + "名");
}
public void SaveData(){
yml.set(dataKey,null);
- // 保存 dayDataMap 到配置文件
- for (Map.Entry entry : dayDataMap.entrySet()) {
- String name = entry.getKey();
- double dayData = entry.getValue();
- yml.set(dataKey+"." + name + ".daydata", dayData);
- }
- // 保存 monthDataMap 到配置文件
- for (Map.Entry entry : monthDataMap.entrySet()) {
- String name = entry.getKey();
- double monthData = entry.getValue();
- yml.set(dataKey+"." + name + ".monthdata", monthData);
- }
- // 保存 rechargeData 到配置文件
- for (Map.Entry entry : rechargeData.entrySet()) {
- String name = entry.getKey();
- double longTermData = entry.getValue();
- yml.set(dataKey+"." + name + ".longTermData", longTermData);
+ for (String name : dataHashMap.keySet()){
+ PlayerData playerData = dataHashMap.get(name);
+ for (TimeType timeType : playerData.getValueMap().keySet()){
+ int value = playerData.getValueData(timeType);
+ String timeKey = playerData.getTimeToString(timeType);
+ if(value >= 1) {
+ yml.set(dataKey + "." + name + "." + timeKey, value);
+ }
+ }
}
// 保存配置文件
try {
@@ -69,4 +62,12 @@ public class RechargeManage {
e.printStackTrace();
}
}
+
+ public PlayerData getPlayerData(String name) {
+ if(dataHashMap.get(name) == null){
+ dataHashMap.put(name,new PlayerData(name,null));
+ return dataHashMap.get(name);
+ }
+ return dataHashMap.get(name);
+ }
}
diff --git a/src/main/java/com/yaohun/aurechargedata/util/TimeType.java b/src/main/java/com/yaohun/aurechargedata/util/TimeType.java
new file mode 100644
index 0000000..206668f
--- /dev/null
+++ b/src/main/java/com/yaohun/aurechargedata/util/TimeType.java
@@ -0,0 +1,5 @@
+package com.yaohun.aurechargedata.util;
+
+public enum TimeType {
+ Annual,Monthly,Daily
+}
diff --git a/src/main/resources/recharge.yml b/src/main/resources/recharge.yml
index 1dac979..9d637ff 100644
--- a/src/main/resources/recharge.yml
+++ b/src/main/resources/recharge.yml
@@ -2,4 +2,4 @@ RechargeData:
玩家名:
daydata: 100 # 今日数据
monthdata: 100 # 本月数据
- longTermData: 100 # 长期数据
\ No newline at end of file
+ annualData: 100 # 长期数据
\ No newline at end of file
diff --git a/target/classes/recharge.yml b/target/classes/recharge.yml
index 1dac979..9d637ff 100644
--- a/target/classes/recharge.yml
+++ b/target/classes/recharge.yml
@@ -2,4 +2,4 @@ RechargeData:
玩家名:
daydata: 100 # 今日数据
monthdata: 100 # 本月数据
- longTermData: 100 # 长期数据
\ No newline at end of file
+ annualData: 100 # 长期数据
\ No newline at end of file