9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-30 04:19:25 +00:00

1.5.19-PRE1

This commit is contained in:
Xiao-MoMi
2022-07-29 23:57:43 +08:00
parent e6b8523a3b
commit 4f348fc884
41 changed files with 427 additions and 1577 deletions

View File

@@ -30,10 +30,14 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Set;
public record SeasonManager(CustomCrops plugin) {
public class SeasonManager{
public static HashMap<String, String> SEASON = new HashMap<>();
/**
* 读取文件中的季节
* @param file 季节数据文件
*/
private YamlConfiguration readData(File file) {
if (!file.exists()) {
try {
@@ -47,6 +51,9 @@ public record SeasonManager(CustomCrops plugin) {
return YamlConfiguration.loadConfiguration(file);
}
/**
* 载入数据
*/
public void loadData() {
SEASON.clear();
YamlConfiguration data = readData(new File(CustomCrops.instance.getDataFolder(), "data" + File.separator + "season.yml"));
@@ -68,8 +75,11 @@ public record SeasonManager(CustomCrops plugin) {
ConfigReader.Config.worlds.forEach(this::getSeason);
}
/**
* 计算某个世界的季节
* @param world 世界
*/
public void getSeason(World world) {
int season = (int) ((world.getFullTime() / 24000L) % (ConfigReader.Season.duration * 4)) / ConfigReader.Season.duration;
switch (season) {
case 0 -> SEASON.put(world.getName(), "spring");
@@ -80,6 +90,9 @@ public record SeasonManager(CustomCrops plugin) {
}
}
/**
* 保存数据
*/
public void saveData() {
SEASON.forEach((key, value) -> {
File file = new File(CustomCrops.instance.getDataFolder(), "data" + File.separator + "season.yml");
@@ -94,6 +107,11 @@ public record SeasonManager(CustomCrops plugin) {
});
}
/**
* 设置季节
* @param worldName 世界名
* @param season 季节
*/
public boolean setSeason(String worldName, String season){
if (!ConfigReader.Config.worldNames.contains(worldName)){
return false;