aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/cowtipper/cowlection/data/HyPlayerData.java
blob: 22e1eaa38fa957551d8e9670cec20d5d217affbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package de.cowtipper.cowlection.data;

import net.minecraft.util.EnumChatFormatting;

public class HyPlayerData {
    private String displayname;
    private String rank;
    private String prefix;
    private String newPackageRank;
    private String rankPlusColor;
    private String monthlyPackageRank;
    private String monthlyRankColor;
    private long lastLogin;
    private long lastLogout;
    private String mostRecentGameType;

    /**
     * No-args constructor for GSON
     */
    public HyPlayerData() {
    }

    public String getPlayerName() {
        return displayname;
    }

    public String getPlayerNameFormatted() {
        return getRankFormatted() + " " + displayname;
    }

    public long getLastLogin() {
        return lastLogin;
    }

    public long getLastLogout() {
        return lastLogout;
    }

    public String getLastGame() {
        return DataHelper.GameType.getFancyName(mostRecentGameType);
    }

    public boolean hasNeverJoinedHypixel() {
        // example player that has never joined Hypixel (as of April 2020): Joe
        return rank == null && lastLogin == 0;
    }

    public boolean hasNeverLoggedOut() {
        // example player that has no logout value (as of April 2020): Pig (in general accounts that haven't logged in for a few years)
        return lastLogin != 0 && lastLogout == 0;
    }

    public boolean isHidingOnlineStatus() {
        // example players: any higher ranked player (mods, admins, ...)
        return lastLogin == 0 && lastLogout == 0;
    }

    /**
     * Player's Rank prefix: https://github.com/HypixelDev/PublicAPI/wiki/Common-Questions#how-do-i-get-a-players-rank-prefix
     *
     * @return formatted rank
     */
    private String getRankFormatted() {
        if (prefix != null) {
            return prefix;
        }
        if (rank != null) {
            switch (rank) {
                case "HELPER":
                    return EnumChatFormatting.BLUE + "[HELPER]";
                case "MODERATOR":
                    return EnumChatFormatting.DARK_GREEN + "[MOD]";
                case "ADMIN":
                    return EnumChatFormatting.RED + "[ADMIN]";
                case "YOUTUBER":
                    return EnumChatFormatting.RED + "[" + EnumChatFormatting.WHITE + "YOUTUBE" + EnumChatFormatting.RED + "]";
            }
        }
        if (rankPlusColor == null) {
            rankPlusColor = "RED";
        }
        if (monthlyPackageRank != null && monthlyPackageRank.equals("SUPERSTAR")) {
            // MVP++
            EnumChatFormatting rankPlusPlusColor = monthlyRankColor != null ? EnumChatFormatting.getValueByName(monthlyRankColor) : EnumChatFormatting.GOLD;
            return rankPlusPlusColor + "[MVP" + EnumChatFormatting.getValueByName(rankPlusColor) + "++" + rankPlusPlusColor + "]";
        }
        if (newPackageRank != null) {
            switch (newPackageRank) {
                case "VIP":
                    return EnumChatFormatting.GREEN + "[VIP]";
                case "VIP_PLUS":
                    return EnumChatFormatting.GREEN + "[VIP" + EnumChatFormatting.GOLD + "+" + EnumChatFormatting.GREEN + "]";
                case "MVP":
                    return EnumChatFormatting.AQUA + "[MVP]";
                case "MVP_PLUS":
                    return EnumChatFormatting.AQUA + "[MVP" + EnumChatFormatting.getValueByName(rankPlusColor) + "+" + EnumChatFormatting.AQUA + "]";
                default:
                    return EnumChatFormatting.GRAY.toString();
            }
        }
        return EnumChatFormatting.GRAY.toString();
    }
}