aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCow <cow@volloeko.de>2020-05-04 13:25:39 +0200
committerCow <cow@volloeko.de>2020-05-04 13:25:39 +0200
commit4d45e0bc9afacc8408295aef50b8fd6530f97104 (patch)
treec06e0f2ffbf8c1fc697ee468b4a1e2bf85ee1a45 /src
parent6f33fc424111ce46dcabd85f214db68f4ddc8b9d (diff)
downloadCowlection-4d45e0bc9afacc8408295aef50b8fd6530f97104.tar.gz
Cowlection-4d45e0bc9afacc8408295aef50b8fd6530f97104.tar.bz2
Cowlection-4d45e0bc9afacc8408295aef50b8fd6530f97104.zip
Re-organized packages and files
Diffstat (limited to 'src')
-rw-r--r--src/main/java/eu/olli/cowmoonication/Cowmoonication.java12
-rw-r--r--src/main/java/eu/olli/cowmoonication/command/MooCommand.java22
-rw-r--r--src/main/java/eu/olli/cowmoonication/data/Friend.java (renamed from src/main/java/eu/olli/cowmoonication/friends/Friend.java)2
-rw-r--r--src/main/java/eu/olli/cowmoonication/data/HyStalkingData.java (renamed from src/main/java/eu/olli/cowmoonication/util/HyStalking.java)7
-rw-r--r--src/main/java/eu/olli/cowmoonication/data/SlothStalkingData.java (renamed from src/main/java/eu/olli/cowmoonication/util/SlothStalking.java)6
-rw-r--r--src/main/java/eu/olli/cowmoonication/handler/FriendsHandler.java (renamed from src/main/java/eu/olli/cowmoonication/friends/Friends.java)7
-rw-r--r--src/main/java/eu/olli/cowmoonication/handler/PlayerCache.java (renamed from src/main/java/eu/olli/cowmoonication/util/PlayerCache.java)2
-rw-r--r--src/main/java/eu/olli/cowmoonication/listener/ChatListener.java2
-rw-r--r--src/main/java/eu/olli/cowmoonication/listener/PlayerListener.java2
-rw-r--r--src/main/java/eu/olli/cowmoonication/util/ApiUtils.java19
10 files changed, 41 insertions, 40 deletions
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();