aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/eu/olli/cowlection/data
diff options
context:
space:
mode:
authorCow <cow@volloeko.de>2020-07-26 23:41:58 +0200
committerCow <cow@volloeko.de>2020-07-26 23:41:58 +0200
commit0027466a564a9a6bebbdeed05192a616175ea6f3 (patch)
treec6d8b5f61992bd1e418d83b1301cc087f673a2e1 /src/main/java/eu/olli/cowlection/data
parentb9c5f23a671c50422303bf50e315d364b1354acf (diff)
downloadCowlection-0027466a564a9a6bebbdeed05192a616175ea6f3.tar.gz
Cowlection-0027466a564a9a6bebbdeed05192a616175ea6f3.tar.bz2
Cowlection-0027466a564a9a6bebbdeed05192a616175ea6f3.zip
Replaced 3rd party with official API
Diffstat (limited to 'src/main/java/eu/olli/cowlection/data')
-rw-r--r--src/main/java/eu/olli/cowlection/data/DataHelper.java57
-rw-r--r--src/main/java/eu/olli/cowlection/data/HyPlayerData.java103
-rw-r--r--src/main/java/eu/olli/cowlection/data/HyStalkingData.java54
-rw-r--r--src/main/java/eu/olli/cowlection/data/SlothStalkingData.java52
4 files changed, 163 insertions, 103 deletions
diff --git a/src/main/java/eu/olli/cowlection/data/DataHelper.java b/src/main/java/eu/olli/cowlection/data/DataHelper.java
index 4fa2f35..d6167b0 100644
--- a/src/main/java/eu/olli/cowlection/data/DataHelper.java
+++ b/src/main/java/eu/olli/cowlection/data/DataHelper.java
@@ -1,5 +1,7 @@
package eu.olli.cowlection.data;
+import eu.olli.cowlection.util.Utils;
+
import java.util.HashMap;
import java.util.Map;
@@ -7,6 +9,61 @@ public final class DataHelper {
private DataHelper() {
}
+ // TODO replace with api request: https://github.com/HypixelDev/PublicAPI/blob/master/Documentation/misc/GameType.md
+ public enum GameType {
+ QUAKECRAFT("Quakecraft"),
+ WALLS("Walls"),
+ PAINTBALL("Paintball"),
+ SURVIVAL_GAMES("Blitz Survival Games"),
+ TNTGAMES("The TNT Games"),
+ VAMPIREZ("VampireZ"),
+ WALLS3("Mega Walls"),
+ ARCADE("Arcade"),
+ ARENA("Arena Brawl"),
+ UHC("UHC Champions"),
+ MCGO("Cops and Crims"),
+ BATTLEGROUND("Warlords"),
+ SUPER_SMASH("Smash Heroes"),
+ GINGERBREAD("Turbo Kart Racers"),
+ HOUSING("Housing"),
+ SKYWARS("SkyWars"),
+ TRUE_COMBAT("Crazy Walls"),
+ SPEED_UHC("Speed UHC"),
+ SKYCLASH("SkyClash"),
+ LEGACY("Classic Games"),
+ PROTOTYPE("Prototype"),
+ BEDWARS("Bed Wars"),
+ MURDER_MYSTERY("Murder Mystery"),
+ BUILD_BATTLE("Build Battle"),
+ DUELS("Duels"),
+ SKYBLOCK("SkyBlock"),
+ PIT("Pit");
+
+ private final String cleanName;
+
+ GameType(String cleanName) {
+ this.cleanName = cleanName;
+ }
+
+ public static String getFancyName(String gameName) {
+ if (gameName == null) {
+ return null;
+ }
+ String cleanGameType;
+ try {
+ cleanGameType = valueOf(gameName).getCleanName();
+ } catch (IllegalArgumentException e) {
+ // no matching game type found
+ cleanGameType = Utils.fancyCase(gameName);
+ }
+ return cleanGameType;
+ }
+
+ public String getCleanName() {
+ return cleanName;
+ }
+ }
+
public static Map<String, String> getMinions() {
// key = skin id, value = minion type and tier
Map<String, String> minions = new HashMap<>();
diff --git a/src/main/java/eu/olli/cowlection/data/HyPlayerData.java b/src/main/java/eu/olli/cowlection/data/HyPlayerData.java
new file mode 100644
index 0000000..06be1e9
--- /dev/null
+++ b/src/main/java/eu/olli/cowlection/data/HyPlayerData.java
@@ -0,0 +1,103 @@
+package eu.olli.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 + "YOUTUBER" + 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();
+ }
+}
diff --git a/src/main/java/eu/olli/cowlection/data/HyStalkingData.java b/src/main/java/eu/olli/cowlection/data/HyStalkingData.java
index a592f2a..771a11d 100644
--- a/src/main/java/eu/olli/cowlection/data/HyStalkingData.java
+++ b/src/main/java/eu/olli/cowlection/data/HyStalkingData.java
@@ -43,14 +43,7 @@ public class HyStalkingData {
}
public String getGameType() {
- String cleanGameType;
- try {
- cleanGameType = GameType.valueOf(gameType).getCleanName();
- } catch (IllegalArgumentException e) {
- // no matching game type found
- cleanGameType = Utils.fancyCase(gameType);
- }
- return cleanGameType;
+ return DataHelper.GameType.getFancyName(gameType);
}
public String getMode() {
@@ -59,7 +52,7 @@ public class HyStalkingData {
return null;
}
String gameType = getGameType();
- if (GameType.BEDWARS.cleanName.equals(gameType)) {
+ if (DataHelper.GameType.BEDWARS.getCleanName().equals(gameType)) {
// BedWars related
String playerMode;
String specialMode;
@@ -92,7 +85,7 @@ public class HyStalkingData {
playerModeClean = playerMode;
}
return Utils.fancyCase(specialMode + playerModeClean);
- } else if (GameType.SKYBLOCK.cleanName.equals(gameType)) {
+ } else if (DataHelper.GameType.SKYBLOCK.getCleanName().equals(gameType)) {
// SkyBlock related
switch (mode) {
case "dynamic":
@@ -123,46 +116,5 @@ public class HyStalkingData {
public String getMap() {
return map;
}
-
- // TODO replace with api request: https://github.com/HypixelDev/PublicAPI/blob/master/Documentation/misc/GameType.md
- public enum GameType {
- QUAKECRAFT("Quakecraft"),
- WALLS("Walls"),
- PAINTBALL("Paintball"),
- SURVIVAL_GAMES("Blitz Survival Games"),
- TNTGAMES("The TNT Games"),
- VAMPIREZ("VampireZ"),
- WALLS3("Mega Walls"),
- ARCADE("Arcade"),
- ARENA("Arena Brawl"),
- UHC("UHC Champions"),
- MCGO("Cops and Crims"),
- BATTLEGROUND("Warlords"),
- SUPER_SMASH("Smash Heroes"),
- GINGERBREAD("Turbo Kart Racers"),
- HOUSING("Housing"),
- SKYWARS("SkyWars"),
- TRUE_COMBAT("Crazy Walls"),
- SPEED_UHC("Speed UHC"),
- SKYCLASH("SkyClash"),
- LEGACY("Classic Games"),
- PROTOTYPE("Prototype"),
- BEDWARS("Bed Wars"),
- MURDER_MYSTERY("Murder Mystery"),
- BUILD_BATTLE("Build Battle"),
- DUELS("Duels"),
- SKYBLOCK("SkyBlock"),
- PIT("Pit");
-
- private final String cleanName;
-
- GameType(String cleanName) {
- this.cleanName = cleanName;
- }
-
- public String getCleanName() {
- return cleanName;
- }
- }
}
}
diff --git a/src/main/java/eu/olli/cowlection/data/SlothStalkingData.java b/src/main/java/eu/olli/cowlection/data/SlothStalkingData.java
deleted file mode 100644
index 6c6085e..0000000
--- a/src/main/java/eu/olli/cowlection/data/SlothStalkingData.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package eu.olli.cowlection.data;
-
-public class SlothStalkingData {
- private String username;
- private String rank;
- private String rank_formatted;
- // private boolean online;
- private long last_login;
- private long last_logout;
- private String last_game;
-
- /**
- * No-args constructor for GSON
- */
- public SlothStalkingData() {
- }
-
- public String getPlayerName() {
- return username;
- }
-
- public String getPlayerNameFormatted() {
- return rank_formatted.replace('&', 'ยง') + " " + username;
- }
-
- public long getLastLogin() {
- return last_login;
- }
-
- public long getLastLogout() {
- return last_logout;
- }
-
- public String getLastGame() {
- return last_game;
- }
-
- public boolean hasNeverJoinedHypixel() {
- // example player that has never joined Hypixel (as of April 2020): Joe
- return rank == null && last_login == 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 last_login != 0 && last_logout == 0;
- }
-
- public boolean isHidingOnlineStatus() {
- // example players: any higher ranked player (mods, admins, ...)
- return last_login == 0 && last_logout == 0;
- }
-}