package app.entities; import app.entities.server.Server; import com.fasterxml.jackson.annotation.JsonGetter; import lombok.Data; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import java.time.Instant; import java.time.LocalDate; import java.util.HashMap; @Data @Component @Scope(value = "singleton") public class Stats { long ban_count = 0; int discord_users = 0; long freevip_players = 0; long server_uptime = Instant.now().getEpochSecond(); long vip_players = 0; int vk_users = 0; HashMap countries = new HashMap<>(); HashMap servers = new HashMap<>(); HashMap uniq = new HashMap<>(); HashMap updates = new HashMap<>(); Statistic statistic = new Statistic(); String builddate = ""; HashMap donate = new HashMap<>(); public Stats(){ try { builddate = System.getenv("BUILDDATE"); } catch (Exception err) { builddate = "0"; } } @JsonGetter public Statistic getStatistic() { statistic.setTotal_servers(servers.size()); statistic.setWorking_servers((int) servers.entrySet().stream().filter(x -> x.getValue().isStatus() == true).count()); statistic.setPlayer_now(servers.entrySet().stream().mapToInt(x -> x.getValue().getPlayer_count()).sum()); if (LocalDate.now().getDayOfMonth() != statistic.getCurrent_day()) { statistic.setCurrent_day(LocalDate.now().getDayOfMonth()); statistic.setPlayer_max(0); } if (statistic.getPlayer_max() < statistic.getPlayer_now()) { statistic.setPlayer_max(statistic.getPlayer_now()); } return statistic; } @JsonGetter public long getServer_uptime() { return Instant.now().getEpochSecond() - server_uptime; } public void UpdateUniq(String key, Long value) { uniq.merge(key, value, (x, y) -> y); } }