累积充值、累积消费数据统计
This commit is contained in:
parent
72a2864b7c
commit
ae55259223
|
@ -1,9 +1,12 @@
|
||||||
package com.yaohun.aurechargedata;
|
package com.yaohun.aurechargedata;
|
||||||
|
|
||||||
import com.yaohun.aurechargedata.api.RechargeAPI;
|
import com.yaohun.aurechargedata.api.RechargeAPI;
|
||||||
|
import com.yaohun.aurechargedata.cmd.KpayToCmd;
|
||||||
|
import com.yaohun.aurechargedata.cmd.MainCmd;
|
||||||
import com.yaohun.aurechargedata.manage.ConsumeManage;
|
import com.yaohun.aurechargedata.manage.ConsumeManage;
|
||||||
import com.yaohun.aurechargedata.manage.RechargeManage;
|
import com.yaohun.aurechargedata.manage.RechargeManage;
|
||||||
import com.yaohun.aurechargedata.util.TimeType;
|
import com.yaohun.aurechargedata.util.TimeType;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class Main extends JavaPlugin {
|
public class Main extends JavaPlugin {
|
||||||
|
@ -17,6 +20,11 @@ public class Main extends JavaPlugin {
|
||||||
saveDefaultConfig();
|
saveDefaultConfig();
|
||||||
rechargeManage = new RechargeManage();
|
rechargeManage = new RechargeManage();
|
||||||
consumeManage = new ConsumeManage();
|
consumeManage = new ConsumeManage();
|
||||||
|
getCommand("apayk").setExecutor(new KpayToCmd());
|
||||||
|
getCommand("apay").setExecutor(new MainCmd());
|
||||||
|
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) {
|
||||||
|
new RechargeExpansion(this).register();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -0,0 +1,74 @@
|
||||||
|
package com.yaohun.aurechargedata;
|
||||||
|
|
||||||
|
import com.yaohun.aurechargedata.api.RechargeAPI;
|
||||||
|
import com.yaohun.aurechargedata.manage.RechargeManage;
|
||||||
|
import com.yaohun.aurechargedata.util.TimeType;
|
||||||
|
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author: Baka
|
||||||
|
* @Date: 2019/12/23 13:20
|
||||||
|
*/
|
||||||
|
public class RechargeExpansion extends PlaceholderExpansion {
|
||||||
|
private Plugin plugin;
|
||||||
|
|
||||||
|
public RechargeExpansion(Plugin plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean persist() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRegister() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAuthor() {
|
||||||
|
return plugin.getDescription().getAuthors().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getIdentifier() {
|
||||||
|
return "aurecharge";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getVersion() {
|
||||||
|
return plugin.getDescription().getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String onPlaceholderRequest(Player player, String identifier) {
|
||||||
|
if (identifier.equalsIgnoreCase("day")) {
|
||||||
|
String playerName = player.getName();
|
||||||
|
int val = RechargeAPI.getRechargeData(playerName, TimeType.Daily);
|
||||||
|
return String.valueOf(val);
|
||||||
|
}else if (identifier.equalsIgnoreCase("month")) {
|
||||||
|
String playerName = player.getName();
|
||||||
|
int val = RechargeAPI.getRechargeData(playerName, TimeType.Monthly);
|
||||||
|
return String.valueOf(val);
|
||||||
|
}else if (identifier.equalsIgnoreCase("me")) {
|
||||||
|
String playerName = player.getName();
|
||||||
|
int val = RechargeAPI.getRechargeData(playerName, TimeType.Annual);
|
||||||
|
return String.valueOf(val);
|
||||||
|
} else {
|
||||||
|
String[] sp = identifier.split("_");
|
||||||
|
// %recharge_1_name%
|
||||||
|
// %recharge_1_value%
|
||||||
|
if (sp.length == 2) {
|
||||||
|
int num = Integer.parseInt(sp[0]);
|
||||||
|
RechargeManage manage = Main.rechargeManage;
|
||||||
|
return manage.getRankingPlayer(num, sp[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -8,6 +8,26 @@ import org.bukkit.configuration.file.FileConfiguration;
|
||||||
|
|
||||||
public abstract class RechargeAPI {
|
public abstract class RechargeAPI {
|
||||||
|
|
||||||
|
public static PlayerData getRechargePlayer(String name){
|
||||||
|
RechargeManage manage = Main.rechargeManage; // 获取充值管理实例
|
||||||
|
return manage.getPlayerData(name); // 获取玩家的充值数据实例
|
||||||
|
}
|
||||||
|
public static int getRechargeData(String name, TimeType timeType) {
|
||||||
|
RechargeManage manage = Main.rechargeManage; // 获取充值管理实例
|
||||||
|
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 setRechargeData(String name, int money) {
|
public static void setRechargeData(String name, int money) {
|
||||||
RechargeManage manage = Main.rechargeManage; // 获取充值管理实例
|
RechargeManage manage = Main.rechargeManage; // 获取充值管理实例
|
||||||
PlayerData dataAPI = manage.getPlayerData(name); // 获取玩家的充值数据实例
|
PlayerData dataAPI = manage.getPlayerData(name); // 获取玩家的充值数据实例
|
||||||
|
|
33
src/main/java/com/yaohun/aurechargedata/cmd/KpayToCmd.java
Normal file
33
src/main/java/com/yaohun/aurechargedata/cmd/KpayToCmd.java
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
131
src/main/java/com/yaohun/aurechargedata/cmd/MainCmd.java
Normal file
131
src/main/java/com/yaohun/aurechargedata/cmd/MainCmd.java
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
package com.yaohun.aurechargedata.cmd;
|
||||||
|
|
||||||
|
import com.yaohun.aurechargedata.Main;
|
||||||
|
import com.yaohun.aurechargedata.api.RechargeAPI;
|
||||||
|
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.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
|
import org.bukkit.entity.HumanEntity;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MainCmd 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/apay look §e[玩家] §f- §2查询插件数据");
|
||||||
|
sender.sendMessage("§2/apay give §e[玩家] §2<金额> §f- §2增加累积§f(日、月、年)");
|
||||||
|
sender.sendMessage("§2/apay givemonth §e[玩家] §2<金额> §f- §2增加累积§f(月、年)");
|
||||||
|
sender.sendMessage("§2/apay giveannual §e[玩家] §2<金额> §f- §2增加累积§f(年)");
|
||||||
|
sender.sendMessage("§e------- ======= §6充值数据统计 §e======= -------");
|
||||||
|
sender.sendMessage("§r");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(args.length == 1 && args[0].equalsIgnoreCase("rank")){
|
||||||
|
Main.rechargeManage.upDataMonthlyRechargesTop();
|
||||||
|
sender.sendMessage("§f[§c消息§f] §a累计充值月排行榜已刷新.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(args.length == 1 && args[0].equalsIgnoreCase("top")){
|
||||||
|
RechargeManage manage = Main.rechargeManage;
|
||||||
|
sender.sendMessage("§f[§c消息§f] §a正在查看累积充值月排行榜.");
|
||||||
|
sender.sendMessage("第一名: "+manage.getRankingPlayer(1,"name")+" 金额: "+manage.getRankingPlayer(1,"value"));
|
||||||
|
sender.sendMessage("第二名: "+manage.getRankingPlayer(2,"name")+" 金额: "+manage.getRankingPlayer(2,"value"));
|
||||||
|
sender.sendMessage("第三名: "+manage.getRankingPlayer(3,"name")+" 金额: "+manage.getRankingPlayer(3,"value"));
|
||||||
|
sender.sendMessage("第四名: "+manage.getRankingPlayer(4,"name")+" 金额: "+manage.getRankingPlayer(4,"value"));
|
||||||
|
sender.sendMessage("第五名: "+manage.getRankingPlayer(5,"name")+" 金额: "+manage.getRankingPlayer(5,"value"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(args.length == 2 && args[0].equalsIgnoreCase("look")){
|
||||||
|
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.Monthly)+"元");
|
||||||
|
sender.sendMessage("§a累计充值§f: §e"+RechargeAPI.getRechargeData(playName,TimeType.Annual)+"元");
|
||||||
|
sender.sendMessage("§a累计消费§f: §b0软");
|
||||||
|
sender.sendMessage("§a最后一次充值§f: §d"+RechargeAPI.getRechargePlayer(playName).getLastOperationShow());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if(args.length == 3){
|
||||||
|
// 获取指定参数
|
||||||
|
String giveType = args[0]; // 操作类型(give, givemonth, giveannual)
|
||||||
|
String playerName = args[1]; // 玩家名字
|
||||||
|
// 判断并转换第三个参数为整数
|
||||||
|
int amount;
|
||||||
|
try {
|
||||||
|
amount = Integer.parseInt(args[2]); // 尝试将第三个参数转换为整数
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// 如果无法转换为整数,可以进行错误处理或日志记录
|
||||||
|
Bukkit.getConsoleSender().sendMessage("[日志-错误-AuRechargeData] args[2] 无法转换为整数.");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// 根据操作类型执行相应的充值操作
|
||||||
|
if (giveType.equalsIgnoreCase("cz")) {
|
||||||
|
// 执行每日、每月和年度充值操作,默认为每日
|
||||||
|
RechargeAPI.addRechargeData(playerName, amount);
|
||||||
|
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);
|
||||||
|
int setVal = RechargeAPI.getRechargeData(playerName,TimeType.Daily);
|
||||||
|
sender.sendMessage("§7[§6累积充值§7] §f已增加 §6" + playerName + " §f每日 §b" + amount + "累计 §f已累积充值: §e" + setVal);
|
||||||
|
} else if (giveType.equalsIgnoreCase("givemonth")) {
|
||||||
|
// 执行每月充值操作
|
||||||
|
RechargeAPI.addRechargeData(playerName, amount, TimeType.Monthly);
|
||||||
|
int setVal = RechargeAPI.getRechargeData(playerName,TimeType.Monthly);
|
||||||
|
sender.sendMessage("§7[§6累积充值§7] §f已增加 §6" + playerName + " §f每月 §b" + amount + "累计 §f已累积充值: §e" + setVal);
|
||||||
|
} else if (giveType.equalsIgnoreCase("giveannual")) {
|
||||||
|
// 执行年度充值操作
|
||||||
|
RechargeAPI.addRechargeData(playerName, amount, TimeType.Annual);
|
||||||
|
int setVal = RechargeAPI.getRechargeData(playerName,TimeType.Annual);
|
||||||
|
sender.sendMessage("§7[§6累积充值§7] §f已增加 §6" + playerName + " §f永久 §b" + amount + "累计 §f已累积充值: §e" + setVal);
|
||||||
|
} else if (giveType.equalsIgnoreCase("take")) {
|
||||||
|
RechargeAPI.takeRechargeData(playerName,amount);
|
||||||
|
int setVal = RechargeAPI.getRechargeData(playerName,TimeType.Annual);
|
||||||
|
sender.sendMessage("§7[§6累积充值§7] §f已扣除 §6" + playerName + " §f永久 §c-" + amount + "累计 §f已累积充值: §e" + setVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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("cz");
|
||||||
|
completions.add("give");
|
||||||
|
completions.add("givemonth");
|
||||||
|
completions.add("giveannual");
|
||||||
|
completions.add("take");
|
||||||
|
}else if(args.length == 2){
|
||||||
|
// 获取全服在线玩家名字数组
|
||||||
|
String[] onlinePlayers = Bukkit.getOnlinePlayers().stream().map(HumanEntity::getName).toArray(String[]::new);
|
||||||
|
completions.addAll(Arrays.asList(onlinePlayers));
|
||||||
|
}else if(args.length == 3){
|
||||||
|
completions.add("5");
|
||||||
|
completions.add("10");
|
||||||
|
completions.add("30");
|
||||||
|
completions.add("50");
|
||||||
|
completions.add("100");
|
||||||
|
completions.add("300");
|
||||||
|
completions.add("500");
|
||||||
|
completions.add("980");
|
||||||
|
completions.add("128");
|
||||||
|
}
|
||||||
|
return completions;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ package com.yaohun.aurechargedata.data;
|
||||||
|
|
||||||
import com.yaohun.aurechargedata.util.TimeType;
|
import com.yaohun.aurechargedata.util.TimeType;
|
||||||
import com.yaohun.aurechargedata.util.UpdataTime;
|
import com.yaohun.aurechargedata.util.UpdataTime;
|
||||||
|
import me.Demon.DemonPlugin.DemonAPI;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -10,6 +11,7 @@ public class PlayerData {
|
||||||
|
|
||||||
private String name; // 玩家名称
|
private String name; // 玩家名称
|
||||||
private HashMap<TimeType, Integer> valueMap; // 存储时间类型和对应值的映射
|
private HashMap<TimeType, Integer> valueMap; // 存储时间类型和对应值的映射
|
||||||
|
private long lastOperation = -1;
|
||||||
|
|
||||||
// 构造函数,从配置节中加载玩家数据
|
// 构造函数,从配置节中加载玩家数据
|
||||||
public PlayerData(String name, ConfigurationSection section) {
|
public PlayerData(String name, ConfigurationSection section) {
|
||||||
|
@ -25,8 +27,10 @@ public class PlayerData {
|
||||||
valueMap.put(TimeType.Daily, value); // 每日数据
|
valueMap.put(TimeType.Daily, value); // 每日数据
|
||||||
} else if (dataKey.equalsIgnoreCase("monthdata")) {
|
} else if (dataKey.equalsIgnoreCase("monthdata")) {
|
||||||
valueMap.put(TimeType.Monthly, value); // 每月数据
|
valueMap.put(TimeType.Monthly, value); // 每月数据
|
||||||
} else {
|
} else if(dataKey.equalsIgnoreCase("annualData")){
|
||||||
valueMap.put(TimeType.Annual, value); // 年度数据
|
valueMap.put(TimeType.Annual, value); // 年度数据
|
||||||
|
} else if(dataKey.equalsIgnoreCase("lastOperation")){
|
||||||
|
lastOperation = section.getLong(dataKey);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
|
@ -57,12 +61,24 @@ public class PlayerData {
|
||||||
Integer currentValue = valueMap.getOrDefault(timeType, 0);
|
Integer currentValue = valueMap.getOrDefault(timeType, 0);
|
||||||
int newAmount = currentValue + amount;
|
int newAmount = currentValue + amount;
|
||||||
valueMap.put(timeType, newAmount);
|
valueMap.put(timeType, newAmount);
|
||||||
|
lastOperation = System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HashMap<TimeType, Integer> getValueMap() {
|
public HashMap<TimeType, Integer> getValueMap() {
|
||||||
return valueMap;
|
return valueMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getLastOperation() {
|
||||||
|
return lastOperation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastOperationShow(){
|
||||||
|
if(this.lastOperation >= 1000){
|
||||||
|
return DemonAPI.LongToStringData(this.lastOperation,"yyyy年MM月dd日 HH:mm");
|
||||||
|
}
|
||||||
|
return "无";
|
||||||
|
}
|
||||||
|
|
||||||
// 根据时间类型返回对应的数据键名
|
// 根据时间类型返回对应的数据键名
|
||||||
public String getTimeToString(TimeType timeType) {
|
public String getTimeToString(TimeType timeType) {
|
||||||
if (timeType == TimeType.Daily) {
|
if (timeType == TimeType.Daily) {
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
package com.yaohun.aurechargedata.event;
|
||||||
|
|
||||||
|
import org.bukkit.event.Event;
|
||||||
|
import org.bukkit.event.HandlerList;
|
||||||
|
|
||||||
|
public class RechargeEvent extends Event {
|
||||||
|
private static HandlerList handlers = new HandlerList();
|
||||||
|
private String playerName;
|
||||||
|
private int money;
|
||||||
|
@Override
|
||||||
|
public HandlerList getHandlers() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
public static HandlerList getHandlerList() {
|
||||||
|
return handlers;
|
||||||
|
}
|
||||||
|
public RechargeEvent(String playerName, int money) {
|
||||||
|
this.playerName = playerName;
|
||||||
|
this.money = money;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlayerName() {
|
||||||
|
return playerName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMoney() {
|
||||||
|
return money;
|
||||||
|
}
|
||||||
|
}
|
|
@ -102,6 +102,10 @@ public class ConsumeManage {
|
||||||
yml.set(dataKey + "." + name + "." + timeKey, value);
|
yml.set(dataKey + "." + name + "." + timeKey, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
long lastOperation = playerData.getLastOperation();
|
||||||
|
if(lastOperation >= 1000){
|
||||||
|
yml.set(dataKey+"."+name+".lastOperation",lastOperation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 保存配置文件
|
// 保存配置文件
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -13,8 +13,8 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class RechargeManage {
|
public class RechargeManage {
|
||||||
|
|
||||||
|
@ -89,6 +89,7 @@ public class RechargeManage {
|
||||||
dataHashMap.put(name, new PlayerData(name, section));
|
dataHashMap.put(name, new PlayerData(name, section));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
upDataMonthlyRechargesTop();
|
||||||
}
|
}
|
||||||
Bukkit.getConsoleSender().sendMessage("§6[充值数据] §f已有充值记录的玩家: §a" + dataHashMap.size() + "名");
|
Bukkit.getConsoleSender().sendMessage("§6[充值数据] §f已有充值记录的玩家: §a" + dataHashMap.size() + "名");
|
||||||
}
|
}
|
||||||
|
@ -103,6 +104,11 @@ public class RechargeManage {
|
||||||
if(value >= 1) {
|
if(value >= 1) {
|
||||||
yml.set(dataKey + "." + name + "." + timeKey, value);
|
yml.set(dataKey + "." + name + "." + timeKey, value);
|
||||||
}
|
}
|
||||||
|
Bukkit.getConsoleSender().sendMessage("[调试] "+name+" value: "+timeKey+" = "+value);
|
||||||
|
}
|
||||||
|
long lastOperation = playerData.getLastOperation();
|
||||||
|
if(lastOperation >= 1000){
|
||||||
|
yml.set(dataKey+"."+name+".lastOperation",lastOperation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 保存配置文件
|
// 保存配置文件
|
||||||
|
@ -120,4 +126,55 @@ public class RechargeManage {
|
||||||
}
|
}
|
||||||
return dataHashMap.get(name);
|
return dataHashMap.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private LinkedHashMap<String, Integer> monthRechargeTop = new LinkedHashMap<>();
|
||||||
|
// 获取每月玩家充值排行数据
|
||||||
|
public void upDataMonthlyRechargesTop(){
|
||||||
|
HashMap<String,Integer> hashMap = new HashMap<>();
|
||||||
|
// 遍历 dataHashMap 中的所有玩家数据
|
||||||
|
for (PlayerData playerData : dataHashMap.values()) {
|
||||||
|
// 获取玩家名称和每月充值金额
|
||||||
|
String playerName = playerData.getName();
|
||||||
|
int monthlyRecharge = playerData.getValueData(TimeType.Monthly);
|
||||||
|
// 创建 PlayerMonthlyRecharge 对象,并添加到列表中
|
||||||
|
hashMap.put(playerName,monthlyRecharge);
|
||||||
|
}
|
||||||
|
this.monthRechargeTop = hashMap.entrySet()
|
||||||
|
.stream()
|
||||||
|
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
Map.Entry::getKey,
|
||||||
|
Map.Entry::getValue,
|
||||||
|
(e1, e2) -> e1,
|
||||||
|
LinkedHashMap::new
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMonthlyRankingName(int rank){
|
||||||
|
List<String> playerNames = new ArrayList<>(monthRechargeTop.keySet());
|
||||||
|
if (rank <= playerNames.size()) {
|
||||||
|
String playerName = playerNames.get(rank - 1);
|
||||||
|
int monthlyRecharge = monthRechargeTop.get(playerName);
|
||||||
|
return playerName;
|
||||||
|
} else {
|
||||||
|
return "ERROR";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public int getMonthlyRankingValue(int rank){
|
||||||
|
List<String> playerNames = new ArrayList<>(monthRechargeTop.keySet());
|
||||||
|
if (rank <= playerNames.size()) {
|
||||||
|
String playerName = playerNames.get(rank - 1);
|
||||||
|
return monthRechargeTop.get(playerName);
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRankingPlayer(int rank,String type){
|
||||||
|
if(type.equalsIgnoreCase("name")){
|
||||||
|
return getMonthlyRankingName(rank);
|
||||||
|
}
|
||||||
|
return ""+getMonthlyRankingValue(rank);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,4 +2,5 @@ ConsumeData:
|
||||||
玩家名:
|
玩家名:
|
||||||
daydata: 100 # 今日数据
|
daydata: 100 # 今日数据
|
||||||
monthdata: 100 # 本月数据
|
monthdata: 100 # 本月数据
|
||||||
longTermData: 100 # 长期数据
|
longTermData: 100 # 长期数据
|
||||||
|
lastOperation: -1
|
|
@ -4,4 +4,5 @@ version: 1.0.0
|
||||||
depend:
|
depend:
|
||||||
- PlaceholderAPI
|
- PlaceholderAPI
|
||||||
commands:
|
commands:
|
||||||
apay:
|
apay:
|
||||||
|
apayk:
|
|
@ -2,4 +2,5 @@ RechargeData:
|
||||||
玩家名:
|
玩家名:
|
||||||
daydata: 100 # 今日数据
|
daydata: 100 # 今日数据
|
||||||
monthdata: 100 # 本月数据
|
monthdata: 100 # 本月数据
|
||||||
annualData: 100 # 长期数据
|
annualData: 100 # 长期数据
|
||||||
|
lastOperation: -1
|
|
@ -2,4 +2,5 @@ ConsumeData:
|
||||||
玩家名:
|
玩家名:
|
||||||
daydata: 100 # 今日数据
|
daydata: 100 # 今日数据
|
||||||
monthdata: 100 # 本月数据
|
monthdata: 100 # 本月数据
|
||||||
longTermData: 100 # 长期数据
|
longTermData: 100 # 长期数据
|
||||||
|
lastOperation: -1
|
|
@ -4,4 +4,5 @@ version: 1.0.0
|
||||||
depend:
|
depend:
|
||||||
- PlaceholderAPI
|
- PlaceholderAPI
|
||||||
commands:
|
commands:
|
||||||
apay:
|
apay:
|
||||||
|
apayk:
|
|
@ -2,4 +2,5 @@ RechargeData:
|
||||||
玩家名:
|
玩家名:
|
||||||
daydata: 100 # 今日数据
|
daydata: 100 # 今日数据
|
||||||
monthdata: 100 # 本月数据
|
monthdata: 100 # 本月数据
|
||||||
annualData: 100 # 长期数据
|
annualData: 100 # 长期数据
|
||||||
|
lastOperation: -1
|
Loading…
Reference in New Issue
Block a user