diff options
11 files changed, 44 insertions, 43 deletions
@@ -5,12 +5,12 @@ A client-side only Forge mod by [Cow](https://namemc.com/profile/Cow) providing | Feature | Command/Usage | |-------------------------------------------------------------------------|-----------------------------------------| | 'Best friends' list to limit the amount of join and leave notifications (always up-to-date names even after player name changes) | `/moo add/remove/list` | -| Toggle join/leave notifications for friends, guild members or best friends separately | `/moo toggle` | | Stalk a player (check online status, current game, ...) | `/moo stalk` | -| Change guiScale to any value | `/moo guiscale [newValue]` | +| Toggle join/leave notifications for friends, guild members or best friends separately | `/moo toggle` | +| Copy chat component | <kbd>ALT</kbd> + <kbd>right click</kbd><br>Hold <kbd>shift</kbd> to copy full component | | Tab-completable usernames for several commands (e.g. `/party`, `/invite`, ...) | `/moo config` → `Commands with Tab-completable usernames` for full list of commands | | Auto-replace `/r` with `/w <latest username>` | `/r ` | -| Copy chat component | <kbd>ALT</kbd> + <kbd>right click</kbd><br>Hold <kbd>shift</kbd> to copy full component | +| Change guiScale to any value | `/moo guiscale [newValue]` | | Check for mod updates on server login and via command | `/moo update` | ➜ Use `/moo help` to see all available commands. diff --git a/src/main/java/eu/olli/cowmoonication/Cowmoonication.java b/src/main/java/eu/olli/cowmoonication/Cowmoonication.java index e44ab23..ae61781 100644 --- a/src/main/java/eu/olli/cowmoonication/Cowmoonication.java +++ b/src/main/java/eu/olli/cowmoonication/Cowmoonication.java @@ -4,11 +4,11 @@ import eu.olli.cowmoonication.command.MooCommand; import eu.olli.cowmoonication.command.ShrugCommand; import eu.olli.cowmoonication.command.TabCompletableCommand; import eu.olli.cowmoonication.config.MooConfig; -import eu.olli.cowmoonication.friends.Friends; +import eu.olli.cowmoonication.handler.FriendsHandler; import eu.olli.cowmoonication.listener.ChatListener; import eu.olli.cowmoonication.listener.PlayerListener; import eu.olli.cowmoonication.util.ChatHelper; -import eu.olli.cowmoonication.util.PlayerCache; +import eu.olli.cowmoonication.handler.PlayerCache; import eu.olli.cowmoonication.util.VersionChecker; import net.minecraftforge.client.ClientCommandHandler; import net.minecraftforge.common.MinecraftForge; @@ -33,7 +33,7 @@ public class Cowmoonication { public static final String GITURL = "@GITURL@"; private File modsDir; private MooConfig config; - private Friends friends; + private FriendsHandler friendsHandler; private VersionChecker versionChecker; private ChatHelper chatHelper; private PlayerCache playerCache; @@ -48,7 +48,7 @@ public class Cowmoonication { modDir.mkdirs(); } - friends = new Friends(this, new File(modDir, "friends.json")); + friendsHandler = new FriendsHandler(this, new File(modDir, "friends.json")); config = new MooConfig(this, new Configuration(new File(modDir, MODID + ".cfg"))); chatHelper = new ChatHelper(); @@ -76,8 +76,8 @@ public class Cowmoonication { return config; } - public Friends getFriends() { - return friends; + public FriendsHandler getFriendsHandler() { + return friendsHandler; } public VersionChecker getVersionChecker() { diff --git a/src/main/java/eu/olli/cowmoonication/command/MooCommand.java b/src/main/java/eu/olli/cowmoonication/command/MooCommand.java index c0a822b..8800ff2 100644 --- a/src/main/java/eu/olli/cowmoonication/command/MooCommand.java +++ b/src/main/java/eu/olli/cowmoonication/command/MooCommand.java @@ -4,9 +4,9 @@ import com.mojang.realmsclient.util.Pair; import eu.olli.cowmoonication.Cowmoonication; import eu.olli.cowmoonication.config.MooConfig; import eu.olli.cowmoonication.config.MooGuiConfig; -import eu.olli.cowmoonication.friends.Friend; +import eu.olli.cowmoonication.data.Friend; import eu.olli.cowmoonication.util.ApiUtils; -import eu.olli.cowmoonication.util.HyStalking; +import eu.olli.cowmoonication.data.HyStalkingData; import eu.olli.cowmoonication.util.TickDelay; import eu.olli.cowmoonication.util.Utils; import net.minecraft.client.Minecraft; @@ -53,7 +53,7 @@ public class MooCommand extends CommandBase { handleListBestFriends(); } else if (args[0].equalsIgnoreCase("nameChangeCheck")) { main.getChatHelper().sendMessage(EnumChatFormatting.GOLD, "Looking for best friends that have changed their name... This will take a few seconds..."); - main.getFriends().updateBestFriends(true); + main.getFriendsHandler().updateBestFriends(true); } // sub-commands: miscellaneous else if (args[0].equalsIgnoreCase("config") || args[0].equalsIgnoreCase("toggle")) { @@ -147,9 +147,9 @@ public class MooCommand extends CommandBase { return; } main.getChatHelper().sendMessage(EnumChatFormatting.GRAY, "Stalking " + EnumChatFormatting.WHITE + playerName + EnumChatFormatting.GRAY + ". This may take a few seconds."); - boolean isBestFriend = main.getFriends().isBestFriend(playerName, true); + boolean isBestFriend = main.getFriendsHandler().isBestFriend(playerName, true); if (isBestFriend) { - Friend stalkedPlayer = main.getFriends().getBestFriend(playerName); + Friend stalkedPlayer = main.getFriendsHandler().getBestFriend(playerName); // we have the uuid already, so stalk the player stalkPlayer(stalkedPlayer); } else { @@ -170,7 +170,7 @@ public class MooCommand extends CommandBase { private void stalkPlayer(Friend stalkedPlayer) { ApiUtils.fetchPlayerStatus(stalkedPlayer, hyStalking -> { if (hyStalking != null && hyStalking.isSuccess()) { - HyStalking.HySession session = hyStalking.getSession(); + HyStalkingData.HySession session = hyStalking.getSession(); if (session.isOnline()) { main.getChatHelper().sendMessage(EnumChatFormatting.YELLOW, EnumChatFormatting.GOLD + stalkedPlayer.getName() + EnumChatFormatting.YELLOW + " is currently playing " + EnumChatFormatting.GOLD + session.getGameType() + EnumChatFormatting.YELLOW + (session.getMode() != null ? ": " + EnumChatFormatting.GOLD + session.getMode() : "") @@ -214,12 +214,12 @@ public class MooCommand extends CommandBase { } // TODO Add check if 'best friend' is on normal friend list - if (main.getFriends().isBestFriend(username, true)) { + if (main.getFriendsHandler().isBestFriend(username, true)) { main.getChatHelper().sendMessage(EnumChatFormatting.RED, EnumChatFormatting.DARK_RED + username + EnumChatFormatting.RED + " is a best friend already."); } else { main.getChatHelper().sendMessage(EnumChatFormatting.GOLD, "Fetching " + EnumChatFormatting.YELLOW + username + EnumChatFormatting.GOLD + "'s unique user id. This may take a few seconds..."); // add friend async - main.getFriends().addBestFriend(username); + main.getFriendsHandler().addBestFriend(username); } } @@ -229,7 +229,7 @@ public class MooCommand extends CommandBase { return; } - boolean removed = main.getFriends().removeBestFriend(username); + boolean removed = main.getFriendsHandler().removeBestFriend(username); if (removed) { main.getChatHelper().sendMessage(EnumChatFormatting.GREEN, "Removed " + EnumChatFormatting.DARK_GREEN + username + EnumChatFormatting.GREEN + " from best friends list."); } else { @@ -238,7 +238,7 @@ public class MooCommand extends CommandBase { } private void handleListBestFriends() { - Set<String> bestFriends = main.getFriends().getBestFriends(); + Set<String> bestFriends = main.getFriendsHandler().getBestFriends(); // TODO show fancy gui with list of best friends; maybe with buttons to delete them main.getChatHelper().sendMessage(EnumChatFormatting.GREEN, "\u279C Best friends: " + EnumChatFormatting.DARK_GREEN + String.join(EnumChatFormatting.GREEN + ", " + EnumChatFormatting.DARK_GREEN, bestFriends)); @@ -303,7 +303,7 @@ public class MooCommand extends CommandBase { /* update mod */ "update", "updateHelp", "version", "folder", /* help */ "help"); } else if (args.length == 2 && args[0].equalsIgnoreCase("remove")) { - return getListOfStringsMatchingLastWord(args, main.getFriends().getBestFriends()); + return getListOfStringsMatchingLastWord(args, main.getFriendsHandler().getBestFriends()); } else if (args.length == 2 && args[0].equalsIgnoreCase("stalk")) { return getListOfStringsMatchingLastWord(args, main.getPlayerCache().getAllNamesSorted()); } diff --git a/src/main/java/eu/olli/cowmoonication/friends/Friend.java b/src/main/java/eu/olli/cowmoonication/data/Friend.java index 88b9d87..69741e2 100644 --- a/src/main/java/eu/olli/cowmoonication/friends/Friend.java +++ b/src/main/java/eu/olli/cowmoonication/data/Friend.java @@ -1,4 +1,4 @@ -package eu.olli.cowmoonication.friends; +package eu.olli.cowmoonication.data; import java.util.Objects; import java.util.UUID; diff --git a/src/main/java/eu/olli/cowmoonication/util/HyStalking.java b/src/main/java/eu/olli/cowmoonication/data/HyStalkingData.java index 19f2362..fdb5543 100644 --- a/src/main/java/eu/olli/cowmoonication/util/HyStalking.java +++ b/src/main/java/eu/olli/cowmoonication/data/HyStalkingData.java @@ -1,8 +1,9 @@ -package eu.olli.cowmoonication.util; +package eu.olli.cowmoonication.data; +import eu.olli.cowmoonication.util.Utils; import org.apache.commons.lang3.StringUtils; -public class HyStalking { +public class HyStalkingData { private boolean success; private String cause; private HySession session; @@ -10,7 +11,7 @@ public class HyStalking { /** * No-args constructor for GSON */ - private HyStalking() { + private HyStalkingData() { } public boolean isSuccess() { diff --git a/src/main/java/eu/olli/cowmoonication/util/SlothStalking.java b/src/main/java/eu/olli/cowmoonication/data/SlothStalkingData.java index 9e659ec..1072634 100644 --- a/src/main/java/eu/olli/cowmoonication/util/SlothStalking.java +++ b/src/main/java/eu/olli/cowmoonication/data/SlothStalkingData.java @@ -1,6 +1,6 @@ -package eu.olli.cowmoonication.util; +package eu.olli.cowmoonication.data; -public class SlothStalking { +public class SlothStalkingData { private String username; private String rank; private String rank_formatted; @@ -12,7 +12,7 @@ public class SlothStalking { /** * No-args constructor for GSON */ - public SlothStalking() { + public SlothStalkingData() { } public String getPlayerNameFormatted() { diff --git a/src/main/java/eu/olli/cowmoonication/friends/Friends.java b/src/main/java/eu/olli/cowmoonication/handler/FriendsHandler.java index 2fb80f0..119e289 100644 --- a/src/main/java/eu/olli/cowmoonication/friends/Friends.java +++ b/src/main/java/eu/olli/cowmoonication/handler/FriendsHandler.java @@ -1,8 +1,9 @@ -package eu.olli.cowmoonication.friends; +package eu.olli.cowmoonication.handler; import com.google.gson.JsonParseException; import com.google.gson.reflect.TypeToken; import eu.olli.cowmoonication.Cowmoonication; +import eu.olli.cowmoonication.data.Friend; import eu.olli.cowmoonication.util.ApiUtils; import eu.olli.cowmoonication.util.GsonUtils; import eu.olli.cowmoonication.util.TickDelay; @@ -24,7 +25,7 @@ import java.util.UUID; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -public class Friends { +public class FriendsHandler { private static final long UPDATE_FREQUENCY_DEFAULT = TimeUnit.HOURS.toMillis(15); private static final long UPDATE_FREQUENCY_MINIMUM = TimeUnit.MINUTES.toMillis(5); private final Cowmoonication main; @@ -32,7 +33,7 @@ public class Friends { private File bestFriendsFile; private UpdateStatus updateStatus; - public Friends(Cowmoonication main, File friendsFile) { + public FriendsHandler(Cowmoonication main, File friendsFile) { this.main = main; this.bestFriendsFile = friendsFile; this.updateStatus = UpdateStatus.IDLE; diff --git a/src/main/java/eu/olli/cowmoonication/util/PlayerCache.java b/src/main/java/eu/olli/cowmoonication/handler/PlayerCache.java index 383ca03..fd1062d 100644 --- a/src/main/java/eu/olli/cowmoonication/util/PlayerCache.java +++ b/src/main/java/eu/olli/cowmoonication/handler/PlayerCache.java @@ -1,4 +1,4 @@ -package eu.olli.cowmoonication.util; +package eu.olli.cowmoonication.handler; import com.google.common.collect.EvictingQueue; import eu.olli.cowmoonication.Cowmoonication; diff --git a/src/main/java/eu/olli/cowmoonication/listener/ChatListener.java b/src/main/java/eu/olli/cowmoonication/listener/ChatListener.java index 855166a..c71b35c 100644 --- a/src/main/java/eu/olli/cowmoonication/listener/ChatListener.java +++ b/src/main/java/eu/olli/cowmoonication/listener/ChatListener.java @@ -56,7 +56,7 @@ public class ChatListener { String joinedLeft = notificationMatcher.group("joinedLeft"); - boolean isBestFriend = main.getFriends().isBestFriend(playerName, false); + boolean isBestFriend = main.getFriendsHandler().isBestFriend(playerName, false); if (isBestFriend) { switch (joinedLeft) { case "joined": diff --git a/src/main/java/eu/olli/cowmoonication/listener/PlayerListener.java b/src/main/java/eu/olli/cowmoonication/listener/PlayerListener.java index 95c35c6..9a443b1 100644 --- a/src/main/java/eu/olli/cowmoonication/listener/PlayerListener.java +++ b/src/main/java/eu/olli/cowmoonication/listener/PlayerListener.java @@ -20,7 +20,7 @@ public class PlayerListener { @SubscribeEvent public void onServerLeave(FMLNetworkEvent.ClientDisconnectionFromServerEvent e) { - main.getFriends().saveBestFriends(); + main.getFriendsHandler().saveBestFriends(); main.getPlayerCache().clearAllCaches(); } } 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(); |