充值数据统计

This commit is contained in:
yaohunya 2024-07-15 23:34:24 +08:00
parent fcf61f966c
commit 05e953ca7e
11 changed files with 244 additions and 45 deletions

View File

@ -1,12 +1,10 @@
package com.yaohun.aurechargedata;
import com.yaohun.aurechargedata.api.RechargeAPI;
import com.yaohun.aurechargedata.cmd.KpayToCmd;
import com.yaohun.aurechargedata.cmd.DataMigrationCmd;
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;
@ -15,13 +13,14 @@ public class Main extends JavaPlugin {
public static String version = "1.0.1";
public static Main plugin;
public static boolean Debug = true;
public static RechargeManage rechargeManage;
public static ConsumeManage consumeManage;
@Override
public void onEnable() {
plugin = this;
saveDefaultConfig();
getCommand("apayk").setExecutor(new KpayToCmd());
getCommand("apaydata").setExecutor(new DataMigrationCmd());
getCommand("apay").setExecutor(new MainCmd());
DemonAPI.sendConsoleMessage("§f[§6!§f] §aAuRechargeData ("+version+") §f开始加载");
rechargeManage = new RechargeManage();

View File

@ -1,4 +1,148 @@
package com.yaohun.aurechargedata.api;
public class ConsumeAPI {
import com.yaohun.aurechargedata.Main;
import com.yaohun.aurechargedata.data.PlayerData;
import com.yaohun.aurechargedata.manage.ConsumeManage;
import com.yaohun.aurechargedata.util.TimeType;
public abstract class ConsumeAPI {
public static PlayerData getConsumePlayer(String name){
ConsumeManage manage = Main.consumeManage; // 获取消费管理实例
return manage.getPlayerData(name); // 获取玩家的消费数据实例
}
public static int getConsumeData(String name, TimeType timeType) {
ConsumeManage manage = Main.consumeManage; // 获取消费管理实例
PlayerData dataAPI = manage.getPlayerData(name); // 获取玩家的消费数据实例
// 根据时间类型获取玩家的累积消费数据
switch (timeType) {
case DAILY:
return dataAPI.getValueData(TimeType.DAILY); // 获取每日累积消费数据
case MONTHLY:
return dataAPI.getValueData(TimeType.MONTHLY); // 获取每月累积消费数据
case ANNUAL:
return dataAPI.getValueData(TimeType.ANNUAL); // 获取年度累积消费数据
default:
return -1; // 如果时间类型不匹配则返回默认值或进行适当处理
}
}
public static void setConsumeData(String name, int money) {
ConsumeManage manage = Main.consumeManage; // 获取消费管理实例
PlayerData dataAPI = manage.getPlayerData(name); // 获取玩家的消费数据实例
// 设置玩家的每日每月和年度消费数据为指定金额
dataAPI.setValueData(TimeType.DAILY, money); // 设置每日消费数据
dataAPI.setValueData(TimeType.MONTHLY, money); // 设置每月消费数据
dataAPI.setValueData(TimeType.ANNUAL, money); // 设置年度消费数据
}
// 增加累积消费金额
public static void addConsumeData(String name, int money) {
ConsumeManage manage = Main.consumeManage; // 获取消费管理实例
PlayerData dataAPI = manage.getPlayerData(name); // 获取玩家的消费数据实例
// 向玩家的每日每月和年度消费数据中添加指定金额
dataAPI.addValueData(TimeType.DAILY, money); // 增加每日消费数据
dataAPI.addValueData(TimeType.MONTHLY, money); // 增加每月消费数据
dataAPI.addValueData(TimeType.ANNUAL, money); // 增加年度消费数据
}
public static void takeConsumeData(String name, int money) {
ConsumeManage manage = Main.consumeManage; // 获取消费管理实例
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 addConsumeData(String name,int money,TimeType timeType) {
ConsumeManage manage = Main.consumeManage; // 获取消费管理实例
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 setConsumeData(String name, int money, TimeType timeType) {
ConsumeManage manage = Main.consumeManage; // 获取消费管理实例
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 takeConsumeData(String name, int money, TimeType timeType) {
ConsumeManage manage = Main.consumeManage; // 获取消费管理实例
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
}
}
}
}

View File

@ -2,8 +2,10 @@ package com.yaohun.aurechargedata.api;
import com.yaohun.aurechargedata.Main;
import com.yaohun.aurechargedata.data.PlayerData;
import com.yaohun.aurechargedata.event.RechargeEvent;
import com.yaohun.aurechargedata.manage.RechargeManage;
import com.yaohun.aurechargedata.util.TimeType;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
public abstract class RechargeAPI {
@ -45,6 +47,19 @@ public abstract class RechargeAPI {
dataAPI.addValueData(TimeType.MONTHLY, money); // 增加每月充值数据
dataAPI.addValueData(TimeType.ANNUAL, money); // 增加年度充值数据
}
// 增加累积充值金额 - 启动监听事件
public static void addRechargeData(String name, int money,boolean eventSwitch) {
RechargeManage manage = Main.rechargeManage; // 获取充值管理实例
PlayerData dataAPI = manage.getPlayerData(name); // 获取玩家的充值数据实例
// 向玩家的每日每月和年度充值数据中添加指定金额
dataAPI.addValueData(TimeType.DAILY, money); // 增加每日充值数据
dataAPI.addValueData(TimeType.MONTHLY, money); // 增加每月充值数据
dataAPI.addValueData(TimeType.ANNUAL, money); // 增加年度充值数据
if (eventSwitch) {
RechargeEvent rechargeEvent = new RechargeEvent(name, money);
Bukkit.getPluginManager().callEvent(rechargeEvent);
}
}
public static void takeRechargeData(String name, int money) {
RechargeManage manage = Main.rechargeManage; // 获取充值管理实例
PlayerData dataAPI = manage.getPlayerData(name); // 获取玩家的充值数据实例

View File

@ -0,0 +1,63 @@
package com.yaohun.aurechargedata.cmd;
import com.yaohun.aurechargedata.Main;
import com.yaohun.aurechargedata.api.ConsumeAPI;
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.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
public class DataMigrationCmd implements CommandExecutor , TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!sender.isOp()){return true;}
if(args.length == 0){
sender.sendMessage("§r");
sender.sendMessage("§e------- ======= §6数据迁移管理 §e======= -------");
sender.sendMessage("§2/apaydata DemonRechargeOrConsume §f- §2迁移消费数据至本插件");
sender.sendMessage("§e------- ======= §6数据迁移管理 §e======= -------");
sender.sendMessage("§r");
return true;
}
if(args.length == 1 && args[0].equalsIgnoreCase("DemonRechargeOrConsume")){
sender.sendMessage("§a插件数据正在统计...");
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
File file = new File("./plugins/DemonRechargeOrConsume","config.yml");
FileConfiguration yml = YamlConfiguration.loadConfiguration(file);
ConfigurationSection section = yml.getConfigurationSection("PlayerData");
if(section == null){
sender.sendMessage("§c未检测到PlayerData相关数据.");
return;
}
Bukkit.getScheduler().runTaskLater(Main.plugin, () -> {
int amount = 0;
for (String name : section.getKeys(false)) {
int consume = section.getInt(name+".consume");
sender.sendMessage("§a已导入消费数据: §f"+name+" ---> "+consume);
ConsumeAPI.setConsumeData(name,consume);
amount++;
}
sender.sendMessage("§a已导入数据§e["+amount+"]§a条");
}, (long) 10);
}, (long) 10);
}
return false;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
List<String> completions = new ArrayList<>();
if(args.length == 1){
completions.add("DemonRechargeOrConsume");
}
return completions;
}
}

View File

@ -1,33 +0,0 @@
package com.yaohun.aurechargedata.cmd;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import java.util.ArrayList;
import java.util.List;
public class KpayToCmd implements CommandExecutor , TabCompleter {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(!sender.isOp()){return true;}
if(args.length == 0){
return true;
}
return false;
}
@Override
public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
List<String> completions = new ArrayList<>();
if(args.length == 1){
completions.add("XXXXXXXXX");
completions.add("XXXXXXXXX");
completions.add("XXXXXXXXX");
completions.add("XXXXXXXXX");
}
return completions;
}
}

View File

@ -1,6 +1,7 @@
package com.yaohun.aurechargedata.cmd;
import com.yaohun.aurechargedata.Main;
import com.yaohun.aurechargedata.api.ConsumeAPI;
import com.yaohun.aurechargedata.api.RechargeAPI;
import com.yaohun.aurechargedata.event.RechargeEvent;
import com.yaohun.aurechargedata.manage.RechargeManage;
@ -53,9 +54,10 @@ public class MainCmd implements CommandExecutor , TabCompleter {
String playName = args[1];
sender.sendMessage("§f[§c消息§f] §a玩家充值信息查询:");
sender.sendMessage("§a玩家名称§f: §6"+playName);
sender.sendMessage("§a今日充值§f: §e"+RechargeAPI.getRechargeData(playName,TimeType.DAILY)+"");
sender.sendMessage("§a本月充值§f: §e"+RechargeAPI.getRechargeData(playName,TimeType.MONTHLY)+"");
sender.sendMessage("§a累计充值§f: §e"+RechargeAPI.getRechargeData(playName,TimeType.ANNUAL)+"");
sender.sendMessage("§a累计消费§f: §b0");
sender.sendMessage("§a累计消费§f: §b"+ ConsumeAPI.getConsumeData(playName,TimeType.ANNUAL)+"");
sender.sendMessage("§a最后一次充值§f: §d"+RechargeAPI.getRechargePlayer(playName).getLastOperationShow());
return true;
}
@ -75,11 +77,9 @@ public class MainCmd implements CommandExecutor , TabCompleter {
// 根据操作类型执行相应的充值操作
if (giveType.equalsIgnoreCase("cz")) {
// 执行每日每月和年度充值操作默认为每日
RechargeAPI.addRechargeData(playerName, amount);
RechargeAPI.addRechargeData(playerName, amount,true);
int setVal = RechargeAPI.getRechargeData(playerName,TimeType.DAILY);
sender.sendMessage("§7[§6累积充值§7] §f已增加 §6" + playerName + " §f每日 §b" + amount + "累计 §f已累积充值: §e" + setVal);
RechargeEvent rechargeEvent = new RechargeEvent(playerName,amount);
Bukkit.getPluginManager().callEvent(rechargeEvent);
} else if (giveType.equalsIgnoreCase("give")) {
// 执行每日每月和年度充值操作默认为每日
RechargeAPI.addRechargeData(playerName, amount);

View File

@ -1,5 +1,7 @@
package com.yaohun.aurechargedata.listener;
import com.yaohun.aurechargedata.Main;
import com.yaohun.aurechargedata.api.ConsumeAPI;
import me.Demon.DemonCoins.evant.ConsumeEvent;
import me.Demon.DemonCoins.evant.ConsumePointsEvent;
import org.bukkit.event.EventHandler;
@ -11,5 +13,9 @@ public class CoinsConsumeEvent implements Listener {
public void onCoins(ConsumeEvent e){
String name = e.getPlayerName();
int money = e.getMoney();
ConsumeAPI.addConsumeData(name,money);
if(Main.Debug){
System.out.println("[调试 - 消费监听] name: "+name+" money: "+money);
}
}
}

View File

@ -110,6 +110,9 @@ public class ConsumeManage {
if (value >= 1) {
yml.set(dataKey + "." + name + "." + timeKey, value);
}
if(Main.Debug){
System.out.println("[调试 - 消费保存] name: "+name+" value: "+timeKey+" = "+value);
}
}
long lastOperation = playerData.getLastOperation();
if (lastOperation >= 1000) {

View File

@ -114,7 +114,9 @@ public class RechargeManage {
if(value >= 1) {
yml.set(dataKey + "." + name + "." + timeKey, value);
}
Bukkit.getConsoleSender().sendMessage("[调试] "+name+" value: "+timeKey+" = "+value);
if(Main.Debug){
System.out.println("[调试 - 充值保存] name: "+name+" value: "+timeKey+" = "+value);
}
}
long lastOperation = playerData.getLastOperation();
if (lastOperation >= 1000) {

View File

@ -6,4 +6,4 @@ depend:
- PlaceholderAPI
commands:
apay:
apayk:
apaydata:

View File

@ -6,4 +6,4 @@ depend:
- PlaceholderAPI
commands:
apay:
apayk:
apaydata: