package de.steamwar.lobby.jumpandrun;

import de.steamwar.command.SWCommand;
import de.steamwar.lobby.LobbySystem;
import de.steamwar.sql.UserConfig;
import org.bukkit.entity.Player;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class JumpAndRunCommand extends SWCommand {

    public JumpAndRunCommand() {
        super("jumpandrun");
    }

    @Register
    public void genericCommand(Player player, String... args) {
        String time = UserConfig.getConfig(player.getUniqueId(), JumpAndRun.JUMP_AND_RUN_CONFIG);
        if (time == null) {
            LobbySystem.getMessage().sendPrefixless("JUMP_AND_RUN_PERSONAL_BEST_NO_TIME", player);
            return;
        }
        long timeLong = Long.parseLong(time);
        SimpleDateFormat format = new SimpleDateFormat(LobbySystem.getMessage().parse("JUMP_AND_RUN_TIME", player), Locale.ROOT);
        String parsed = format.format(new Date(timeLong));
        LobbySystem.getMessage().sendPrefixless("JUMP_AND_RUN_PERSONAL_BEST_TIME", player, parsed);
    }
}
