test111
This commit is contained in:
parent
35709f08fe
commit
e1a3d0d045
8
.idea/artifacts/AuRechargeData.xml
Normal file
8
.idea/artifacts/AuRechargeData.xml
Normal file
|
@ -0,0 +1,8 @@
|
|||
<component name="ArtifactManager">
|
||||
<artifact type="jar" name="AuRechargeData">
|
||||
<output-path>$PROJECT_DIR$/out/artifacts/AuRechargeData</output-path>
|
||||
<root id="archive" name="AuRechargeData.jar">
|
||||
<element id="module-output" name="AuRechargeData" />
|
||||
</root>
|
||||
</artifact>
|
||||
</component>
|
10
pom.xml
10
pom.xml
|
@ -26,6 +26,16 @@
|
|||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.12.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.Demon.DemonPlugin</groupId>
|
||||
<artifactId>DemonAPI</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>me.clip.placeholderapi</groupId>
|
||||
<artifactId>PlaceholderAPI</artifactId>
|
||||
<version>2.9.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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){
|
||||
|
||||
}
|
||||
}
|
24
src/main/java/com/yaohun/aurechargedata/Main.java
Normal file
24
src/main/java/com/yaohun/aurechargedata/Main.java
Normal file
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package com.yaohun.aurechargedata.data;
|
||||
|
||||
public class DayData {
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package com.yaohun.aurechargedata.data;
|
||||
|
||||
public class MonthData {
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
package com.yaohun.aurechargedata.data;
|
||||
|
||||
public class TermData {
|
||||
}
|
|
@ -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<String,Double> consumeData = new HashMap<>();
|
||||
private HashMap<String, Double> dayDataMap = new HashMap<>();
|
||||
private HashMap<String, Double> 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<String, Double> entry : dayDataMap.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
double dayData = entry.getValue();
|
||||
yml.set(dataKey+"." + name + ".daydata", dayData);
|
||||
}
|
||||
// 保存 monthDataMap 到配置文件
|
||||
for (Map.Entry<String, Double> entry : monthDataMap.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
double monthData = entry.getValue();
|
||||
yml.set(dataKey+"." + name + ".monthdata", monthData);
|
||||
}
|
||||
// 保存 rechargeData 到配置文件
|
||||
for (Map.Entry<String, Double> 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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<String,Double> rechargeData = new HashMap<>();
|
||||
private HashMap<String, Double> dayDataMap = new HashMap<>();
|
||||
private HashMap<String, Double> 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<String, Double> entry : dayDataMap.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
double dayData = entry.getValue();
|
||||
yml.set(dataKey+"." + name + ".daydata", dayData);
|
||||
}
|
||||
// 保存 monthDataMap 到配置文件
|
||||
for (Map.Entry<String, Double> entry : monthDataMap.entrySet()) {
|
||||
String name = entry.getKey();
|
||||
double monthData = entry.getValue();
|
||||
yml.set(dataKey+"." + name + ".monthdata", monthData);
|
||||
}
|
||||
// 保存 rechargeData 到配置文件
|
||||
for (Map.Entry<String, Double> 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();
|
||||
}
|
||||
}
|
||||
}
|
56
src/main/java/com/yaohun/aurechargedata/util/UpdataTime.java
Normal file
56
src/main/java/com/yaohun/aurechargedata/util/UpdataTime.java
Normal file
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
4
src/main/resources/config.yml
Normal file
4
src/main/resources/config.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
MonthTime: 413541384341385
|
||||
DayTime: 413546385438
|
||||
|
||||
Updata
|
5
src/main/resources/consume.yml
Normal file
5
src/main/resources/consume.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
ConsumeData:
|
||||
玩家名:
|
||||
daydata: 100 # 今日数据
|
||||
monthdata: 100 # 本月数据
|
||||
longTermData: 100 # 长期数据
|
7
src/main/resources/plugin.yml
Normal file
7
src/main/resources/plugin.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
name: AuRechargeData
|
||||
main: com.yaohun.aurechargedata.Main
|
||||
version: 1.0.0
|
||||
depend:
|
||||
- PlaceholderAPI
|
||||
commands:
|
||||
apay:
|
5
src/main/resources/recharge.yml
Normal file
5
src/main/resources/recharge.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
RechargeData:
|
||||
玩家名:
|
||||
daydata: 100 # 今日数据
|
||||
monthdata: 100 # 本月数据
|
||||
longTermData: 100 # 长期数据
|
4
target/classes/config.yml
Normal file
4
target/classes/config.yml
Normal file
|
@ -0,0 +1,4 @@
|
|||
MonthTime: 413541384341385
|
||||
DayTime: 413546385438
|
||||
|
||||
Updata
|
5
target/classes/consume.yml
Normal file
5
target/classes/consume.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
ConsumeData:
|
||||
玩家名:
|
||||
daydata: 100 # 今日数据
|
||||
monthdata: 100 # 本月数据
|
||||
longTermData: 100 # 长期数据
|
7
target/classes/plugin.yml
Normal file
7
target/classes/plugin.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
name: AuRechargeData
|
||||
main: com.yaohun.aurechargedata.Main
|
||||
version: 1.0.0
|
||||
depend:
|
||||
- PlaceholderAPI
|
||||
commands:
|
||||
apay:
|
5
target/classes/recharge.yml
Normal file
5
target/classes/recharge.yml
Normal file
|
@ -0,0 +1,5 @@
|
|||
RechargeData:
|
||||
玩家名:
|
||||
daydata: 100 # 今日数据
|
||||
monthdata: 100 # 本月数据
|
||||
longTermData: 100 # 长期数据
|
Loading…
Reference in New Issue
Block a user