diff options
| author | Cow <cow@volloeko.de> | 2020-05-04 13:25:39 +0200 |
|---|---|---|
| committer | Cow <cow@volloeko.de> | 2020-05-04 13:25:39 +0200 |
| commit | 4d45e0bc9afacc8408295aef50b8fd6530f97104 (patch) | |
| tree | c06e0f2ffbf8c1fc697ee468b4a1e2bf85ee1a45 /src/main/java/eu/olli/cowmoonication/util | |
| parent | 6f33fc424111ce46dcabd85f214db68f4ddc8b9d (diff) | |
| download | Cowlection-4d45e0bc9afacc8408295aef50b8fd6530f97104.tar.gz Cowlection-4d45e0bc9afacc8408295aef50b8fd6530f97104.tar.bz2 Cowlection-4d45e0bc9afacc8408295aef50b8fd6530f97104.zip | |
Re-organized packages and files
Diffstat (limited to 'src/main/java/eu/olli/cowmoonication/util')
4 files changed, 9 insertions, 272 deletions
diff --git a/src/main/java/eu/olli/cowmoonication/util/ApiUtils.java b/src/main/java/eu/olli/cowmoonication/util/ApiUtils.java index 2dc41b2..aca1819 100644 --- a/src/main/java/eu/olli/cowmoonication/util/ApiUtils.java +++ b/src/main/java/eu/olli/cowmoonication/util/ApiUtils.java @@ -1,13 +1,13 @@ package eu.olli.cowmoonication.util; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonParser; import com.mojang.util.UUIDTypeAdapter; import eu.olli.cowmoonication.Cowmoonication; import eu.olli.cowmoonication.config.MooConfig; -import eu.olli.cowmoonication.friends.Friend; +import eu.olli.cowmoonication.data.Friend; +import eu.olli.cowmoonication.data.HyStalkingData; +import eu.olli.cowmoonication.data.SlothStalkingData; import org.apache.http.HttpStatus; import java.io.BufferedReader; @@ -16,7 +16,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; -import java.util.UUID; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.function.Consumer; @@ -69,14 +68,14 @@ public class ApiUtils { return null; } - public static void fetchPlayerStatus(Friend friend, Consumer<HyStalking> action) { + public static void fetchPlayerStatus(Friend friend, Consumer<HyStalkingData> action) { pool.execute(() -> action.accept(stalkPlayer(friend))); } - private static HyStalking stalkPlayer(Friend friend) { + private static HyStalkingData stalkPlayer(Friend friend) { try (BufferedReader reader = makeApiCall(String.format(STALKING_URL_OFFICIAL, MooConfig.moo, UUIDTypeAdapter.fromUUID(friend.getUuid())))) { if (reader != null) { - return GsonUtils.fromJson(reader, HyStalking.class); + return GsonUtils.fromJson(reader, HyStalkingData.class); } } catch (IOException e) { e.printStackTrace(); @@ -84,14 +83,14 @@ public class ApiUtils { return null; } - public static void fetchPlayerOfflineStatus(Friend stalkedPlayer, Consumer<SlothStalking> action) { + public static void fetchPlayerOfflineStatus(Friend stalkedPlayer, Consumer<SlothStalkingData> action) { pool.execute(() -> action.accept(stalkOfflinePlayer(stalkedPlayer))); } - private static SlothStalking stalkOfflinePlayer(Friend stalkedPlayer) { + private static SlothStalkingData stalkOfflinePlayer(Friend stalkedPlayer) { try (BufferedReader reader = makeApiCall(String.format(STALKING_URL_UNOFFICIAL, UUIDTypeAdapter.fromUUID(stalkedPlayer.getUuid())))) { if (reader != null) { - return GsonUtils.fromJson(reader, SlothStalking.class); + return GsonUtils.fromJson(reader, SlothStalkingData.class); } } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/eu/olli/cowmoonication/util/HyStalking.java b/src/main/java/eu/olli/cowmoonication/util/HyStalking.java deleted file mode 100644 index 19f2362..0000000 --- a/src/main/java/eu/olli/cowmoonication/util/HyStalking.java +++ /dev/null @@ -1,167 +0,0 @@ -package eu.olli.cowmoonication.util; - -import org.apache.commons.lang3.StringUtils; - -public class HyStalking { - private boolean success; - private String cause; - private HySession session; - - /** - * No-args constructor for GSON - */ - private HyStalking() { - } - - public boolean isSuccess() { - return success; - } - - public String getCause() { - return cause; - } - - public HySession getSession() { - return session; - } - - public static class HySession { - private boolean online; - private String gameType; - private String mode; - private String map; - - /** - * No-args constructor for GSON - */ - private HySession() { - } - - public boolean isOnline() { - return online; - } - - 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; - } - - public String getMode() { - // modes partially taken from https://api.hypixel.net/gameCounts?key=MOO - if (mode == null) { - return null; - } - String gameType = getGameType(); - if (GameType.BEDWARS.cleanName.equals(gameType)) { - // BedWars related - String playerMode; - String specialMode; - int specialModeStart = StringUtils.ordinalIndexOf(mode, "_", 2); - if (specialModeStart > -1) { - playerMode = mode.substring(0, specialModeStart); - specialMode = mode.substring(specialModeStart + 1) + " "; - } else { - playerMode = mode; - specialMode = ""; - } - String playerModeClean; - switch (playerMode) { - case "EIGHT_ONE": - playerModeClean = "Solo"; - break; - case "EIGHT_TWO": - playerModeClean = "Doubles"; - break; - case "FOUR_THREE": - playerModeClean = "3v3v3v3"; - break; - case "FOUR_FOUR": - playerModeClean = "4v4v4v4"; - break; - case "TWO_FOUR": - playerModeClean = "4v4"; - break; - default: - playerModeClean = playerMode; - } - return Utils.fancyCase(specialMode + playerModeClean); - } else if (GameType.SKYBLOCK.cleanName.equals(gameType)) { - // SkyBlock related - switch (mode) { - case "dynamic": - return "Private Island"; - case "hub": - return "Hub"; - case "combat_1": - return "Spider's Den"; - case "combat_2": - return "Blazing Fortress"; - case "combat_3": - return "The End"; - case "farming_1": - return "The Barn"; - case "farming_2": - return "Mushroom Desert"; - case "foraging_1": - return "The Park"; - case "mining_1": - return "Gold Mine"; - case "mining_2": - return "Deep Caverns"; - } - } - return Utils.fancyCase(mode); - } - - 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/cowmoonication/util/PlayerCache.java b/src/main/java/eu/olli/cowmoonication/util/PlayerCache.java deleted file mode 100644 index 383ca03..0000000 --- a/src/main/java/eu/olli/cowmoonication/util/PlayerCache.java +++ /dev/null @@ -1,47 +0,0 @@ -package eu.olli.cowmoonication.util; - -import com.google.common.collect.EvictingQueue; -import eu.olli.cowmoonication.Cowmoonication; - -import java.util.SortedSet; -import java.util.TreeSet; - -public class PlayerCache { - @SuppressWarnings("UnstableApiUsage") - private final EvictingQueue<String> nameCache = EvictingQueue.create(50); - @SuppressWarnings("UnstableApiUsage") - private final EvictingQueue<String> bestFriendCache = EvictingQueue.create(50); - private final Cowmoonication main; - - public PlayerCache(Cowmoonication main) { - this.main = main; - } - - public void add(String name) { - // remove old entry (if exists) to 'push' name to the end of the queue - nameCache.remove(name); - nameCache.add(name); - } - - public void addBestFriend(String name) { - // remove old entry (if exists) to 'push' name to the end of the queue - bestFriendCache.remove(name); - bestFriendCache.add(name); - } - - public void removeBestFriend(String name) { - bestFriendCache.remove(name); - } - - public SortedSet<String> getAllNamesSorted() { - SortedSet<String> nameList = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); - nameList.addAll(bestFriendCache); - nameList.addAll(nameCache); - return nameList; - } - - public void clearAllCaches() { - nameCache.clear(); - bestFriendCache.clear(); - } -} diff --git a/src/main/java/eu/olli/cowmoonication/util/SlothStalking.java b/src/main/java/eu/olli/cowmoonication/util/SlothStalking.java deleted file mode 100644 index 9e659ec..0000000 --- a/src/main/java/eu/olli/cowmoonication/util/SlothStalking.java +++ /dev/null @@ -1,48 +0,0 @@ -package eu.olli.cowmoonication.util; - -public class SlothStalking { - 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 SlothStalking() { - } - - 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; - } -} |
