Dateien nach "src/main/java/de/mviper/adventskalender" hochladen
This commit is contained in:
68
src/main/java/de/mviper/adventskalender/CalendarData.java
Normal file
68
src/main/java/de/mviper/adventskalender/CalendarData.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package de.mviper.adventskalender;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class CalendarData {
|
||||
|
||||
private static File file;
|
||||
private static FileConfiguration customFile;
|
||||
|
||||
public static void setup() {
|
||||
file = new File(Adventskalender.getInstance().getDataFolder(), "calendar.yml");
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
Adventskalender.getInstance().getLogger().severe("Konnte calendar.yml nicht erstellen: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
customFile = YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
public static void save() {
|
||||
try {
|
||||
customFile.save(file);
|
||||
} catch (IOException e) {
|
||||
Adventskalender.getInstance().getLogger().severe("Konnte calendar.yml nicht speichern: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean hasClaimed(Player player, int day) {
|
||||
boolean isGlobal = Adventskalender.getInstance().getConfig().getBoolean("calendar.use_global_calendar");
|
||||
if (isGlobal) {
|
||||
List<Integer> claimedDays = customFile.getIntegerList("global_claimed_days");
|
||||
return claimedDays.contains(day);
|
||||
} else {
|
||||
List<Integer> claimedDays = customFile.getIntegerList(player.getUniqueId().toString());
|
||||
return claimedDays.contains(day);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setClaimed(Player player, int day) {
|
||||
boolean isGlobal = Adventskalender.getInstance().getConfig().getBoolean("calendar.use_global_calendar");
|
||||
if (isGlobal) {
|
||||
List<Integer> claimedDays = customFile.getIntegerList("global_claimed_days");
|
||||
claimedDays.add(day);
|
||||
customFile.set("global_claimed_days", claimedDays);
|
||||
} else {
|
||||
List<Integer> claimedDays = customFile.getIntegerList(player.getUniqueId().toString());
|
||||
claimedDays.add(day);
|
||||
customFile.set(player.getUniqueId().toString(), claimedDays);
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
public static int getClaimedCount(Player player) {
|
||||
if (Adventskalender.getInstance().getConfig().getBoolean("calendar.use_global_calendar")) {
|
||||
return customFile.getIntegerList("global_claimed_days").size();
|
||||
} else {
|
||||
return customFile.getIntegerList(player.getUniqueId().toString()).size();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user