package net.knarcraft.minigames.util; import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.arena.ArenaGameMode; import net.knarcraft.minigames.arena.ArenaRecordsRegistry; import net.knarcraft.minigames.arena.parkour.ParkourArena; import net.knarcraft.minigames.arena.parkour.ParkourArenaData; import net.knarcraft.minigames.arena.parkour.ParkourArenaGameMode; import net.knarcraft.minigames.arena.parkour.ParkourArenaGroup; import net.knarcraft.minigames.arena.parkour.ParkourArenaRecordsRegistry; import net.knarcraft.minigames.arena.parkour.ParkourArenaStorageKey; import net.knarcraft.minigames.config.MiniGameMessage; import net.knarcraft.minigames.container.SerializableMaterial; import net.knarcraft.minigames.container.SerializableUUID; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.UUID; import java.util.logging.Level; import static net.knarcraft.minigames.util.ArenaStorageHelper.getArenaDataFile; /** * A helper class for saving and loading parkour arenas */ public final class ParkourArenaStorageHelper { private ParkourArenaStorageHelper() { } private final static File dataFolder = MiniGames.getInstance().getDataFolder(); private final static String parkourArenasConfigurationSection = "parkourArenas"; private final static String parkourGroupsConfigurationSection = "parkourGroups"; private static final File parkourGroupFile = new File(dataFolder, "parkour_groups.yml"); private static final File parkourArenaFile = new File(dataFolder, "parkour_arenas.yml"); private static final File parkourArenaDataFolder = new File(dataFolder, "parkour_arena_data"); /** * Saves the given parkour arena groups * * @param arenaGroups
The arena groups to save
* @throws IOExceptionIf unable to write to the file
*/ public static void saveParkourArenaGroups(@NotNull SetThe loaded arena groups
*/ public static @NotNull SetThe arenas to save
* @throws IOExceptionIf unable to write to the file
*/ public static void saveParkourArenas(@NotNull MapThe loaded arenas, or null if the arenas configuration section is missing.
*/ public static @NotNull MapThe configuration section containing arena data
* @returnThe loaded arena, or null if invalid
*/ @SuppressWarnings("unchecked") private static @Nullable ParkourArena loadParkourArena(@NotNull ConfigurationSection configurationSection) { UUID arenaId = ((SerializableUUID) configurationSection.get(ParkourArenaStorageKey.ID.getKey(), new SerializableUUID(UUID.randomUUID()))).getRawValue(); String arenaName = configurationSection.getString(ParkourArenaStorageKey.NAME.getKey()); Location spawnLocation = (Location) configurationSection.get(ParkourArenaStorageKey.SPAWN_LOCATION.getKey()); Location exitLocation = (Location) configurationSection.get(ParkourArenaStorageKey.EXIT_LOCATION.getKey()); Location winLocation = (Location) configurationSection.get(ParkourArenaStorageKey.WIN_LOCATION.getKey()); SerializableMaterial winBlockType = (SerializableMaterial) configurationSection.get( ParkourArenaStorageKey.WIN_BLOCK_TYPE.getKey()); List> killPlaneBlockNames = configurationSection.getList(ParkourArenaStorageKey.KILL_PLANE_BLOCKS.getKey()); ListThe id to get parkour data for
* @returnEmpty parkour data
*/ private static @NotNull ParkourArenaData getEmptyParkourData(@NotNull UUID arenaId) { MapThe arena data to store
*/ public static void saveParkourArenaData(@NotNull ParkourArenaData arenaData) throws IOException { YamlConfiguration configuration = new YamlConfiguration(); configuration.set(ParkourArenaStorageKey.DATA.getKey(), arenaData); configuration.save(getParkourArenaDataFile(arenaData.getArenaId())); } /** * Loads arena data for the given arena id * * @param arenaIdThe id of the arena to get data for
* @returnThe loaded arena data
*/ private static @Nullable ParkourArenaData loadParkourArenaData(@NotNull UUID arenaId) { File arenaDataFile = getParkourArenaDataFile(arenaId); YamlConfiguration configuration = YamlConfiguration.loadConfiguration(arenaDataFile); return (ParkourArenaData) configuration.get(ParkourArenaStorageKey.DATA.getKey()); } /** * Removes data for the arena with the given id * * @param arenaIdThe id of the arena to remove data for
* @returnTrue if the data was successfully removed
*/ public static boolean removeParkourArenaData(@NotNull UUID arenaId) { return getParkourArenaDataFile(arenaId).delete(); } /** * Gets the file used to store the given arena id's data * * @param arenaIdThe id of the arena to get a data file for
* @returnThe file the arena's data is/should be stored in
*/ private static @NotNull File getParkourArenaDataFile(@NotNull UUID arenaId) { return getArenaDataFile(parkourArenaDataFolder, arenaId); } }