Files
SteamWar/LobbySystem/src/de/steamwar/lobby/special/advent/AdventsCalendar.java
T
2025-10-23 17:56:43 +02:00

76 lines
2.5 KiB
Java

/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2025 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package de.steamwar.lobby.special.advent;
import de.steamwar.lobby.LobbySystem;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File;
import java.io.IOException;
import java.time.LocalDate;
import java.time.Month;
import java.util.ArrayList;
import java.util.List;
public class AdventsCalendar {
private static List<Present> presentList = new ArrayList<>();
private static File file = new File(LobbySystem.getInstance().getDataFolder(), "presents.yml");
private static FileConfiguration fileConfiguration = YamlConfiguration.loadConfiguration(file);
static {
for (int i = 1; i <= 31; i++) {
if (i > 24 && i < 31) continue;
ConfigurationSection section = fileConfiguration.getConfigurationSection(i + "");
if (section == null) {
section = fileConfiguration.createSection(i + "");
}
presentList.add(new Present(i, section));
if (i == 24) {
presentList.add(new Present(25, section));
presentList.add(new Present(26, section));
}
}
}
public static List<Present> getPresentList() {
return presentList;
}
public static void save() {
long time = System.currentTimeMillis();
try {
fileConfiguration.save(file);
} catch (IOException e) {
// Ignore
}
System.out.println("Save time: " + (System.currentTimeMillis() - time) + "ms");
}
public static boolean active() {
LocalDate localDate = LocalDate.now();
Month month = localDate.getMonth();
return month == Month.DECEMBER;
}
}