From fcf61f966cec5c0cf5cdec1d2d5ef9f991e0c934 Mon Sep 17 00:00:00 2001 From: yaohunya <31456652@qq.com> Date: Mon, 15 Jul 2024 22:39:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=85=E5=80=BC=E6=95=B0=E6=8D=AE=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yaohun/aurechargedata/Main.java | 15 ++++- .../listener/CoinsConsumeEvent.java | 15 +++++ .../aurechargedata/manage/ConsumeManage.java | 51 +++++++++------- .../aurechargedata/manage/RechargeManage.java | 58 +++++++++++-------- src/main/resources/plugin.yml | 3 +- target/classes/plugin.yml | 3 +- 6 files changed, 96 insertions(+), 49 deletions(-) create mode 100644 src/main/java/com/yaohun/aurechargedata/listener/CoinsConsumeEvent.java diff --git a/src/main/java/com/yaohun/aurechargedata/Main.java b/src/main/java/com/yaohun/aurechargedata/Main.java index 236019d..47acbea 100644 --- a/src/main/java/com/yaohun/aurechargedata/Main.java +++ b/src/main/java/com/yaohun/aurechargedata/Main.java @@ -3,14 +3,17 @@ package com.yaohun.aurechargedata; import com.yaohun.aurechargedata.api.RechargeAPI; import com.yaohun.aurechargedata.cmd.KpayToCmd; import com.yaohun.aurechargedata.cmd.MainCmd; +import com.yaohun.aurechargedata.listener.CoinsConsumeEvent; import com.yaohun.aurechargedata.manage.ConsumeManage; import com.yaohun.aurechargedata.manage.RechargeManage; import com.yaohun.aurechargedata.util.TimeType; +import me.Demon.DemonPlugin.DemonAPI; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; public class Main extends JavaPlugin { + public static String version = "1.0.1"; public static Main plugin; public static RechargeManage rechargeManage; public static ConsumeManage consumeManage; @@ -18,13 +21,21 @@ public class Main extends JavaPlugin { public void onEnable() { plugin = this; saveDefaultConfig(); - rechargeManage = new RechargeManage(); - consumeManage = new ConsumeManage(); getCommand("apayk").setExecutor(new KpayToCmd()); getCommand("apay").setExecutor(new MainCmd()); + DemonAPI.sendConsoleMessage("§f[§6!§f] §aAuRechargeData ("+version+") §f开始加载"); + rechargeManage = new RechargeManage(); + consumeManage = new ConsumeManage(); + if (Bukkit.getPluginManager().getPlugin("DemonCoins") != null) { + getServer().getPluginManager().registerEvents(new CoinsConsumeEvent(),this); + DemonAPI.sendConsoleMessage("§f[§a!§f] §fDemonCoins §8> §6完成"); + } if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { new RechargeExpansion(this).register(); + DemonAPI.sendConsoleMessage("§f[§a!§f] §fPlaceholderAPI §8> §6完成"); } + DemonAPI.sendConsoleMessage("§f[§6!§f] §aAuRechargeData §f加载完成,祝你使用愉快!"); + DemonAPI.sendConsoleMessage("§f[§6!§f] §b极光像素工作室出品"); } @Override diff --git a/src/main/java/com/yaohun/aurechargedata/listener/CoinsConsumeEvent.java b/src/main/java/com/yaohun/aurechargedata/listener/CoinsConsumeEvent.java new file mode 100644 index 0000000..7067dcb --- /dev/null +++ b/src/main/java/com/yaohun/aurechargedata/listener/CoinsConsumeEvent.java @@ -0,0 +1,15 @@ +package com.yaohun.aurechargedata.listener; + +import me.Demon.DemonCoins.evant.ConsumeEvent; +import me.Demon.DemonCoins.evant.ConsumePointsEvent; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; + +public class CoinsConsumeEvent implements Listener { + + @EventHandler + public void onCoins(ConsumeEvent e){ + String name = e.getPlayerName(); + int money = e.getMoney(); + } +} diff --git a/src/main/java/com/yaohun/aurechargedata/manage/ConsumeManage.java b/src/main/java/com/yaohun/aurechargedata/manage/ConsumeManage.java index 90d83a1..317f311 100644 --- a/src/main/java/com/yaohun/aurechargedata/manage/ConsumeManage.java +++ b/src/main/java/com/yaohun/aurechargedata/manage/ConsumeManage.java @@ -4,6 +4,7 @@ import com.yaohun.aurechargedata.Main; import com.yaohun.aurechargedata.data.PlayerData; import com.yaohun.aurechargedata.util.TimeType; import com.yaohun.aurechargedata.util.UpdataTime; +import me.Demon.DemonPlugin.DemonAPI; import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; @@ -37,29 +38,11 @@ public class ConsumeManage { if (yml.getConfigurationSection(dataKey) != null) { boolean updated = false; // 标记是否进行了数据更新 if (UpdataTime.isDayDataUpdata()) { - // 遍历 "ConsumeData" 节点下的所有键(用户名) - for (String name : yml.getConfigurationSection(dataKey).getKeys(false)) { - yml.set(dataKey+"."+name+".daydata", null);// 将每位玩家的每日充值数据置为空 - } - // 保存配置文件 - try { - yml.save(file); - } catch (IOException e) { - e.printStackTrace(); - } + resetDayData(); updated = true; // 标记数据已更新 } if (UpdataTime.isMonthDataUpdata()) { - // 遍历 "ConsumeData" 节点下的所有键(用户名) - for (String name : yml.getConfigurationSection(dataKey).getKeys(false)) { - yml.set(dataKey+"."+name+".monthdata",null);// 将每位玩家的每日充值数据置为空 - } - // 保存配置文件 - try { - yml.save(file); - } catch (IOException e) { - e.printStackTrace(); - } + resetMonthData(); updated = true; // 标记数据已更新 } // 如果数据已更新,异步定时任务重新加载数据 @@ -88,7 +71,33 @@ public class ConsumeManage { } } } - Bukkit.getConsoleSender().sendMessage("§6[充值数据] §f已有消费记录的玩家: §a" + dataHashMap.size() + "名"); + DemonAPI.sendConsoleMessage("§f[§a!§f] §f消费数据档案 §8> §6"+dataHashMap.size()+"条"); + } + public void resetDayData(){ + // 遍历 "ConsumeData" 节点下的所有键(用户名) + for (String name : yml.getConfigurationSection(dataKey).getKeys(false)) { + yml.set(dataKey+"."+name+".daydata", null);// 将每位玩家的每日充值数据置为空 + } + // 保存配置文件 + try { + yml.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + DemonAPI.sendConsoleMessage("§f[§a!§f] §f每日消费 §8> §6已重置"); + } + public void resetMonthData(){ + // 遍历 "ConsumeData" 节点下的所有键(用户名) + for (String name : yml.getConfigurationSection(dataKey).getKeys(false)) { + yml.set(dataKey+"."+name+".monthdata",null);// 将每位玩家的每日充值数据置为空 + } + // 保存配置文件 + try { + yml.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + DemonAPI.sendConsoleMessage("§f[§a!§f] §f每月消费 §8> §6已重置"); } public void saveData() { diff --git a/src/main/java/com/yaohun/aurechargedata/manage/RechargeManage.java b/src/main/java/com/yaohun/aurechargedata/manage/RechargeManage.java index dc0c89e..32ed38f 100644 --- a/src/main/java/com/yaohun/aurechargedata/manage/RechargeManage.java +++ b/src/main/java/com/yaohun/aurechargedata/manage/RechargeManage.java @@ -4,6 +4,7 @@ import com.yaohun.aurechargedata.Main; import com.yaohun.aurechargedata.data.PlayerData; import com.yaohun.aurechargedata.util.TimeType; import com.yaohun.aurechargedata.util.UpdataTime; +import me.Demon.DemonPlugin.DemonAPI; import org.bukkit.Bukkit; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; @@ -38,34 +39,16 @@ public class RechargeManage { // 检查配置文件中是否包含 "RechargeData" 节点 if (yml.getConfigurationSection(dataKey) != null) { boolean updated = false; // 标记是否进行了数据更新 - if(UpdataTime.isDayDataUpdata()){ - // 遍历 "RechargeData" 节点下的所有键(用户名) - for (String name : yml.getConfigurationSection(dataKey).getKeys(false)) { - yml.set(dataKey+"."+name+".daydata",null);// 将每位玩家的每日充值数据置为空 - } - // 保存配置文件 - try { - yml.save(file); - } catch (IOException e) { - e.printStackTrace(); - } + if (UpdataTime.isDayDataUpdata()) { + resetDayData(); updated = true; // 标记数据已更新 } - if(UpdataTime.isMonthDataUpdata()){ - // 遍历 "RechargeData" 节点下的所有键(用户名) - for (String name : yml.getConfigurationSection(dataKey).getKeys(false)) { - yml.set(dataKey+"."+name+".monthdata",null);// 将每位玩家的每日充值数据置为空 - } - // 保存配置文件 - try { - yml.save(file); - } catch (IOException e) { - e.printStackTrace(); - } + if (UpdataTime.isMonthDataUpdata()) { + resetMonthData(); updated = true; // 标记数据已更新 } // 如果数据已更新,异步定时任务重新加载数据 - if(updated){ + if (updated) { new BukkitRunnable() { @Override public void run() { @@ -91,7 +74,34 @@ public class RechargeManage { } upDataMonthlyRechargesTop(); } - Bukkit.getConsoleSender().sendMessage("§6[充值数据] §f已有充值记录的玩家: §a" + dataHashMap.size() + "名"); + DemonAPI.sendConsoleMessage("§f[§a!§f] §f充值数据档案 §8> §6"+dataHashMap.size()+"条"); + } + public void resetDayData(){ + // 遍历 "RechargeData" 节点下的所有键(用户名) + for (String name : yml.getConfigurationSection(dataKey).getKeys(false)) { + yml.set(dataKey+"."+name+".daydata",null);// 将每位玩家的每日充值数据置为空 + } + // 保存配置文件 + try { + yml.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + DemonAPI.sendConsoleMessage("§f[§a!§f] §f每日充值 §8> §6已重置"); + Bukkit.getConsoleSender().sendMessage("§6[AuRechargeData] §f每日充值数据已重置."); + } + public void resetMonthData(){ + // 遍历 "RechargeData" 节点下的所有键(用户名) + for (String name : yml.getConfigurationSection(dataKey).getKeys(false)) { + yml.set(dataKey+"."+name+".monthdata",null);// 将每位玩家的每日充值数据置为空 + } + // 保存配置文件 + try { + yml.save(file); + } catch (IOException e) { + e.printStackTrace(); + } + DemonAPI.sendConsoleMessage("§f[§a!§f] §f每月充值 §8> §6已重置"); } public void saveData() { diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 5e4b793..4b28d78 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,7 +1,8 @@ name: AuRechargeData main: com.yaohun.aurechargedata.Main -version: 1.0.0 +version: _v depend: + - DemonAPI - PlaceholderAPI commands: apay: diff --git a/target/classes/plugin.yml b/target/classes/plugin.yml index 5e4b793..4b28d78 100644 --- a/target/classes/plugin.yml +++ b/target/classes/plugin.yml @@ -1,7 +1,8 @@ name: AuRechargeData main: com.yaohun.aurechargedata.Main -version: 1.0.0 +version: _v depend: + - DemonAPI - PlaceholderAPI commands: apay: