Search in sources :

Example 1 with StatsRange

use of me.semx11.autotip.stats.StatsRange in project Hyperium by HyperiumClient.

the class Stats method print.

public void print() {
    MessageUtil messageUtil = autotip.getMessageUtil();
    messageUtil.separator();
    gameStatistics.entrySet().stream().sorted(Map.Entry.<String, Coins>comparingByValue().reversed()).forEach(entry -> {
        String game = entry.getKey();
        Coins coins = entry.getValue();
        messageUtil.getKeyHelper("command.stats").withKey("coins", context -> context.getBuilder(game, coins.getTotal()).setHover(context.getKey("coinsHover"), game, coins.getSent(), coins.getReceived()).send());
    });
    messageUtil.getKeyHelper("command.stats").withKey("tips", context -> context.getBuilder(getTipsTotal()).setHover(context.getKey("tipsHover"), getTipsSent(), getTipsReceived()).send()).withKey("xp", context -> context.getBuilder(getXpTotal()).setHover(context.getKey("xpHover"), getXpSent(), getXpReceived()).send());
    if (this instanceof StatsDaily) {
        messageUtil.sendKey("command.stats.date", ((StatsDaily) this).getDateString());
    } else if (this instanceof StatsRange) {
        StatsRange range = (StatsRange) this;
        messageUtil.sendKey("command.stats.dateRange", range.getStartString(), range.getEndString());
    }
    messageUtil.separator();
}
Also used : Autotip(me.semx11.autotip.Autotip) GameGroup(me.semx11.autotip.config.GlobalSettings.GameGroup) Locale(java.util.Locale) DateTimeFormatter(java.time.format.DateTimeFormatter) Map(java.util.Map) MessageUtil(me.semx11.autotip.chat.MessageUtil) DecimalFormat(java.text.DecimalFormat) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GlobalSettings(me.semx11.autotip.config.GlobalSettings) Exclude(me.semx11.autotip.gson.exclusion.Exclude) GameAlias(me.semx11.autotip.config.GlobalSettings.GameAlias) NumberFormat(java.text.NumberFormat) MessageUtil(me.semx11.autotip.chat.MessageUtil)

Example 2 with StatsRange

use of me.semx11.autotip.stats.StatsRange in project Hyperium by HyperiumClient.

the class StatsManager method getRange.

/**
 * Get the {@link StatsRange} for the specified date range. This method uses {@link
 * #get(LocalDate)} to get all the {@link StatsDaily} that are contained within this range.
 *
 * @param start The starting {@link LocalDate}
 * @param end   The ending {@link LocalDate}
 * @return {@link StatsRange} for the specified date range
 */
public StatsRange getRange(LocalDate start, LocalDate end) {
    if (start.isBefore(fileUtil.getFirstDate()))
        start = fileUtil.getFirstDate();
    if (end.isAfter(LocalDate.now()))
        end = LocalDate.now();
    StatsRange range = new StatsRange(autotip, start, end);
    Stream.iterate(start, date -> date.plusDays(1)).limit(ChronoUnit.DAYS.between(start, end) + 1).forEach(date -> range.merge(get(date)));
    return range;
}
Also used : StatsRange(me.semx11.autotip.stats.StatsRange)

Example 3 with StatsRange

use of me.semx11.autotip.stats.StatsRange in project Hyperium by HyperiumClient.

the class SessionManager method login.

public void login() {
    Session session = autotip.getMinecraft().getSession();
    GameProfile profile = session.getProfile();
    String uuid = profile.getId().toString().replace("-", "");
    String serverHash = HashUtil.hash(uuid + HashUtil.getNextSalt());
    int statusCode = authenticate(session.getToken(), uuid, serverHash);
    if (statusCode / 100 != 2) {
        messageUtil.send("&cError {} during authentication: Session servers down?", statusCode);
        return;
    }
    StatsRange all = autotip.getStatsManager().getAll();
    LoginRequest request = LoginRequest.of(autotip, profile, serverHash, all.getTipsTotalInt());
    long lastLogin = autotip.getEvent(EventClientConnection.class).getLastLogin();
    long delay = lastLogin + 5000 - System.currentTimeMillis();
    delay /= 1000;
    reply = taskManager.scheduleAndAwait(request::execute, (delay < 1) ? 1 : delay);
    if (reply == null || !reply.isSuccess()) {
        messageUtil.send("&cError during login: {}", reply == null ? "null" : reply.getCause());
        return;
    }
    sessionKey = reply.getSessionKey();
    loggedIn = true;
    long keepAlive = reply.getKeepAliveRate();
    long tipWave = reply.getTipWaveRate();
    taskManager.addRepeatingTask(TaskType.KEEP_ALIVE, this::keepAlive, keepAlive, keepAlive);
    taskManager.addRepeatingTask(TaskType.TIP_WAVE, this::tipWave, 0, tipWave);
}
Also used : GameProfile(com.mojang.authlib.GameProfile) EventClientConnection(me.semx11.autotip.event.impl.EventClientConnection) StatsRange(me.semx11.autotip.stats.StatsRange) LoginRequest(me.semx11.autotip.api.request.impl.LoginRequest) Session(net.minecraft.util.Session)

Aggregations

StatsRange (me.semx11.autotip.stats.StatsRange)2 GameProfile (com.mojang.authlib.GameProfile)1 DecimalFormat (java.text.DecimalFormat)1 NumberFormat (java.text.NumberFormat)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 Locale (java.util.Locale)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Autotip (me.semx11.autotip.Autotip)1 LoginRequest (me.semx11.autotip.api.request.impl.LoginRequest)1 MessageUtil (me.semx11.autotip.chat.MessageUtil)1 GlobalSettings (me.semx11.autotip.config.GlobalSettings)1 GameAlias (me.semx11.autotip.config.GlobalSettings.GameAlias)1 GameGroup (me.semx11.autotip.config.GlobalSettings.GameGroup)1 EventClientConnection (me.semx11.autotip.event.impl.EventClientConnection)1 Exclude (me.semx11.autotip.gson.exclusion.Exclude)1 Session (net.minecraft.util.Session)1