package net.knarcraft.minigames.arena.dropper; import net.knarcraft.minigames.MiniGames; import net.knarcraft.minigames.arena.ArenaData; import net.knarcraft.minigames.arena.ArenaGameMode; import net.knarcraft.minigames.arena.ArenaRecordsRegistry; import net.knarcraft.minigames.container.SerializableContainer; import net.knarcraft.minigames.container.SerializableUUID; import net.knarcraft.minigames.util.SerializableConverter; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; import java.util.Set; import java.util.UUID; /** * Data stored for an arena */ public class DropperArenaData extends ArenaData { /** * Instantiates a new dropper arena data object * * @param arenaId

The id of the arena this data belongs to

* @param recordRegistries

The registries of this arena's records

* @param playersCompleted

The set of the players that have cleared this arena for each game-mode

*/ public DropperArenaData(@NotNull UUID arenaId, @NotNull Map recordRegistries, @NotNull Map> playersCompleted) { super(arenaId, recordRegistries, playersCompleted); } @Override public void saveData() { MiniGames.getInstance().getDropperArenaHandler().saveData(this.arenaId); } /** * Deserializes a dropper arena data from the given data * * @param data

The data to deserialize

* @return

The deserialized dropper arena data

*/ @SuppressWarnings({"unused", "unchecked"}) public static @NotNull DropperArenaData deserialize(@NotNull Map data) { SerializableUUID serializableUUID = (SerializableUUID) data.get("arenaId"); Map recordsRegistry = (Map) data.get("recordsRegistry"); Map>> playersCompletedData = (Map>>) data.get("playersCompleted"); if (recordsRegistry == null) { recordsRegistry = new HashMap<>(); } else if (playersCompletedData == null) { playersCompletedData = new HashMap<>(); } // Convert the serializable UUIDs to normal UUIDs Map> allPlayersCompleted = new HashMap<>(); SerializableConverter.getRawValue(playersCompletedData, allPlayersCompleted); for (ArenaGameMode arenaGameMode : playersCompletedData.keySet()) { if (!recordsRegistry.containsKey(arenaGameMode) || recordsRegistry.get(arenaGameMode) == null) { recordsRegistry.put(arenaGameMode, new DropperArenaRecordsRegistry(serializableUUID.getRawValue())); } } return new DropperArenaData(serializableUUID.getRawValue(), recordsRegistry, allPlayersCompleted); } }