From e1a3d0d04519873d784251e8f184a31109bd0480 Mon Sep 17 00:00:00 2001
From: yaohunya <31456652@qq.com>
Date: Sun, 14 Jul 2024 20:04:14 +0800
Subject: [PATCH] test111
---
.idea/artifacts/AuRechargeData.xml | 8 +++
README.md | 3 -
pom.xml | 10 +++
.../com/io/yaohun/aurechargedata/Main.java | 12 ----
.../io/yaohun/aurechargedata/util/dsadas.java | 13 ----
.../java/com/yaohun/aurechargedata/Main.java | 24 +++++++
.../yaohun/aurechargedata/data/DayData.java | 4 ++
.../yaohun/aurechargedata/data/MonthData.java | 4 ++
.../yaohun/aurechargedata/data/TermData.java | 4 ++
.../aurechargedata/manage/ConsumeManage.java | 68 ++++++++++++++++++
.../aurechargedata/manage/RechargeManage.java | 72 +++++++++++++++++++
.../aurechargedata/util/UpdataTime.java | 56 +++++++++++++++
src/main/resources/config.yml | 4 ++
src/main/resources/consume.yml | 5 ++
src/main/resources/plugin.yml | 7 ++
src/main/resources/recharge.yml | 5 ++
target/classes/config.yml | 4 ++
target/classes/consume.yml | 5 ++
target/classes/plugin.yml | 7 ++
target/classes/recharge.yml | 5 ++
20 files changed, 292 insertions(+), 28 deletions(-)
create mode 100644 .idea/artifacts/AuRechargeData.xml
delete mode 100644 src/main/java/com/io/yaohun/aurechargedata/Main.java
delete mode 100644 src/main/java/com/io/yaohun/aurechargedata/util/dsadas.java
create mode 100644 src/main/java/com/yaohun/aurechargedata/Main.java
create mode 100644 src/main/java/com/yaohun/aurechargedata/data/DayData.java
create mode 100644 src/main/java/com/yaohun/aurechargedata/data/MonthData.java
create mode 100644 src/main/java/com/yaohun/aurechargedata/data/TermData.java
create mode 100644 src/main/java/com/yaohun/aurechargedata/manage/ConsumeManage.java
create mode 100644 src/main/java/com/yaohun/aurechargedata/manage/RechargeManage.java
create mode 100644 src/main/java/com/yaohun/aurechargedata/util/UpdataTime.java
create mode 100644 src/main/resources/config.yml
create mode 100644 src/main/resources/consume.yml
create mode 100644 src/main/resources/plugin.yml
create mode 100644 src/main/resources/recharge.yml
create mode 100644 target/classes/config.yml
create mode 100644 target/classes/consume.yml
create mode 100644 target/classes/plugin.yml
create mode 100644 target/classes/recharge.yml
diff --git a/.idea/artifacts/AuRechargeData.xml b/.idea/artifacts/AuRechargeData.xml
new file mode 100644
index 0000000..7e8ba29
--- /dev/null
+++ b/.idea/artifacts/AuRechargeData.xml
@@ -0,0 +1,8 @@
+
+
+ $PROJECT_DIR$/out/artifacts/AuRechargeData
+
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
index c350a34..59516ad 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1 @@
# AuRechargeData
-
-## 子标题
- #### 副标题
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 934f86b..d0787c6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -26,6 +26,16 @@
spigot-api
1.12.2
+
+ me.Demon.DemonPlugin
+ DemonAPI
+ 1.2.0
+
+
+ me.clip.placeholderapi
+ PlaceholderAPI
+ 2.9.2
+
\ No newline at end of file
diff --git a/src/main/java/com/io/yaohun/aurechargedata/Main.java b/src/main/java/com/io/yaohun/aurechargedata/Main.java
deleted file mode 100644
index 4e6ab5c..0000000
--- a/src/main/java/com/io/yaohun/aurechargedata/Main.java
+++ /dev/null
@@ -1,12 +0,0 @@
-package com.io.yaohun.aurechargedata;
-
-import org.bukkit.plugin.java.JavaPlugin;
-
-public class Main extends JavaPlugin {
-
- private Main main;
- @Override
- public void onEnable() {
- main = this;
- }
-}
diff --git a/src/main/java/com/io/yaohun/aurechargedata/util/dsadas.java b/src/main/java/com/io/yaohun/aurechargedata/util/dsadas.java
deleted file mode 100644
index a9bf305..0000000
--- a/src/main/java/com/io/yaohun/aurechargedata/util/dsadas.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.io.yaohun.aurechargedata.util;
-
-import org.bukkit.entity.Player;
-import org.bukkit.event.EventHandler;
-import org.bukkit.event.player.PlayerJoinEvent;
-
-public class dsadas {
-
- @EventHandler
- public void onjoin(PlayerJoinEvent e){
-
- }
-}
diff --git a/src/main/java/com/yaohun/aurechargedata/Main.java b/src/main/java/com/yaohun/aurechargedata/Main.java
new file mode 100644
index 0000000..c819024
--- /dev/null
+++ b/src/main/java/com/yaohun/aurechargedata/Main.java
@@ -0,0 +1,24 @@
+package com.yaohun.aurechargedata;
+
+import com.yaohun.aurechargedata.manage.ConsumeManage;
+import com.yaohun.aurechargedata.manage.RechargeManage;
+import org.bukkit.plugin.java.JavaPlugin;
+
+public class Main extends JavaPlugin {
+
+ public static Main plugin;
+ public static RechargeManage rechargeManage;
+ public static ConsumeManage consumeManage;
+ @Override
+ public void onEnable() {
+ plugin = this;
+ rechargeManage = new RechargeManage();
+ consumeManage = new ConsumeManage();
+ }
+
+ @Override
+ public void onDisable() {
+ rechargeManage.SaveData();
+ consumeManage.SaveData();
+ }
+}
diff --git a/src/main/java/com/yaohun/aurechargedata/data/DayData.java b/src/main/java/com/yaohun/aurechargedata/data/DayData.java
new file mode 100644
index 0000000..8600bd5
--- /dev/null
+++ b/src/main/java/com/yaohun/aurechargedata/data/DayData.java
@@ -0,0 +1,4 @@
+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
new file mode 100644
index 0000000..2595c46
--- /dev/null
+++ b/src/main/java/com/yaohun/aurechargedata/data/MonthData.java
@@ -0,0 +1,4 @@
+package com.yaohun.aurechargedata.data;
+
+public class MonthData {
+}
diff --git a/src/main/java/com/yaohun/aurechargedata/data/TermData.java b/src/main/java/com/yaohun/aurechargedata/data/TermData.java
new file mode 100644
index 0000000..276a009
--- /dev/null
+++ b/src/main/java/com/yaohun/aurechargedata/data/TermData.java
@@ -0,0 +1,4 @@
+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
new file mode 100644
index 0000000..c4de133
--- /dev/null
+++ b/src/main/java/com/yaohun/aurechargedata/manage/ConsumeManage.java
@@ -0,0 +1,68 @@
+package com.yaohun.aurechargedata.manage;
+
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.configuration.file.YamlConfiguration;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+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<>();
+
+ public ConsumeManage(){
+ file = new File("plugins/AuRechargeData", "consume.yml");
+ 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);
+ }
+ }
+ }
+
+ 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);
+ }
+ // 保存配置文件
+ try {
+ yml.save(file);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/com/yaohun/aurechargedata/manage/RechargeManage.java b/src/main/java/com/yaohun/aurechargedata/manage/RechargeManage.java
new file mode 100644
index 0000000..1ea6ffd
--- /dev/null
+++ b/src/main/java/com/yaohun/aurechargedata/manage/RechargeManage.java
@@ -0,0 +1,72 @@
+package com.yaohun.aurechargedata.manage;
+
+import com.yaohun.aurechargedata.data.DayData;
+import com.yaohun.aurechargedata.data.MonthData;
+import com.yaohun.aurechargedata.data.TermData;
+import org.bukkit.configuration.file.FileConfiguration;
+import org.bukkit.configuration.file.YamlConfiguration;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+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<>();
+
+ public RechargeManage(){
+ file = new File("plugins/AuRechargeData", "recharge.yml");
+ 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);
+ }
+ }
+ }
+
+ 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);
+ }
+ // 保存配置文件
+ try {
+ yml.save(file);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/com/yaohun/aurechargedata/util/UpdataTime.java b/src/main/java/com/yaohun/aurechargedata/util/UpdataTime.java
new file mode 100644
index 0000000..ab0a240
--- /dev/null
+++ b/src/main/java/com/yaohun/aurechargedata/util/UpdataTime.java
@@ -0,0 +1,56 @@
+package com.yaohun.aurechargedata.util;
+
+import com.yaohun.aurechargedata.Main;
+import me.Demon.DemonPlugin.DemonAPI;
+import org.bukkit.configuration.file.FileConfiguration;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.Date;
+
+public abstract class UpdataTime {
+
+ /*
+ * 获取 每日数据刷新的记录时间
+ * 判断是否应该刷新数据
+ */
+ public static boolean isDayDataUpdata(){
+ FileConfiguration yml = Main.plugin.getConfig();
+ long dayRecordsTime = yml.getLong("DayTime");
+ // 获取上次数据刷新时间
+ LocalDate lastUpdateDate = new Date(dayRecordsTime).toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+ // 获取当前日期
+ LocalDate currentDate = LocalDate.now();
+ if(currentDate.isAfter(lastUpdateDate)) {
+ // 如果是次日,更新配置文件中的刷新时间为当前时间
+ yml.set("DayTime", System.currentTimeMillis());
+ Main.plugin.saveConfig();
+ return true;
+ }else{
+ return false;
+ }
+ }
+
+ /*
+ * 获取 每月数据刷新的记录时间
+ * 判断是否应该刷新数据
+ * */
+ public static boolean isMonthDataUpdata(){
+ FileConfiguration yml = Main.plugin.getConfig();
+ long monthRecordsTime = yml.getLong("MonthTime");
+ // 获取上次数据刷新时间
+ LocalDate lastUpdateDate = new Date(monthRecordsTime).toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+ // 获取当前日期和时间
+ LocalDate currentDate = LocalDate.now();
+ // 判断是否进入了新的一个月
+ if (currentDate.getMonthValue() != lastUpdateDate.getMonthValue() || currentDate.getYear() != lastUpdateDate.getYear()) {
+ // 如果是新的一个月,更新配置文件中的刷新时间为当前时间
+ yml.set("MonthTime", System.currentTimeMillis());
+ Main.plugin.saveConfig();
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
new file mode 100644
index 0000000..bccfd0e
--- /dev/null
+++ b/src/main/resources/config.yml
@@ -0,0 +1,4 @@
+MonthTime: 413541384341385
+DayTime: 413546385438
+
+ Updata
\ No newline at end of file
diff --git a/src/main/resources/consume.yml b/src/main/resources/consume.yml
new file mode 100644
index 0000000..4efc1c9
--- /dev/null
+++ b/src/main/resources/consume.yml
@@ -0,0 +1,5 @@
+ConsumeData:
+ 玩家名:
+ daydata: 100 # 今日数据
+ monthdata: 100 # 本月数据
+ longTermData: 100 # 长期数据
\ No newline at end of file
diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml
new file mode 100644
index 0000000..eba735d
--- /dev/null
+++ b/src/main/resources/plugin.yml
@@ -0,0 +1,7 @@
+name: AuRechargeData
+main: com.yaohun.aurechargedata.Main
+version: 1.0.0
+depend:
+ - PlaceholderAPI
+commands:
+ apay:
\ No newline at end of file
diff --git a/src/main/resources/recharge.yml b/src/main/resources/recharge.yml
new file mode 100644
index 0000000..1dac979
--- /dev/null
+++ b/src/main/resources/recharge.yml
@@ -0,0 +1,5 @@
+RechargeData:
+ 玩家名:
+ daydata: 100 # 今日数据
+ monthdata: 100 # 本月数据
+ longTermData: 100 # 长期数据
\ No newline at end of file
diff --git a/target/classes/config.yml b/target/classes/config.yml
new file mode 100644
index 0000000..bccfd0e
--- /dev/null
+++ b/target/classes/config.yml
@@ -0,0 +1,4 @@
+MonthTime: 413541384341385
+DayTime: 413546385438
+
+ Updata
\ No newline at end of file
diff --git a/target/classes/consume.yml b/target/classes/consume.yml
new file mode 100644
index 0000000..4efc1c9
--- /dev/null
+++ b/target/classes/consume.yml
@@ -0,0 +1,5 @@
+ConsumeData:
+ 玩家名:
+ daydata: 100 # 今日数据
+ monthdata: 100 # 本月数据
+ longTermData: 100 # 长期数据
\ No newline at end of file
diff --git a/target/classes/plugin.yml b/target/classes/plugin.yml
new file mode 100644
index 0000000..eba735d
--- /dev/null
+++ b/target/classes/plugin.yml
@@ -0,0 +1,7 @@
+name: AuRechargeData
+main: com.yaohun.aurechargedata.Main
+version: 1.0.0
+depend:
+ - PlaceholderAPI
+commands:
+ apay:
\ No newline at end of file
diff --git a/target/classes/recharge.yml b/target/classes/recharge.yml
new file mode 100644
index 0000000..1dac979
--- /dev/null
+++ b/target/classes/recharge.yml
@@ -0,0 +1,5 @@
+RechargeData:
+ 玩家名:
+ daydata: 100 # 今日数据
+ monthdata: 100 # 本月数据
+ longTermData: 100 # 长期数据
\ No newline at end of file