aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCow <cow@volloeko.de>2020-12-18 13:41:20 +0100
committerCow <cow@volloeko.de>2020-12-18 13:41:20 +0100
commitca1cf885f9c7e2c6fcdf31c697a22f0e984d7525 (patch)
tree443a6089020e1d3e4a3ff8bb6c62d1b5e504c190
parent1b1b1c6293a184066e30cb98349f472a41e1c66d (diff)
downloadCowlection-ca1cf885f9c7e2c6fcdf31c697a22f0e984d7525.tar.gz
Cowlection-ca1cf885f9c7e2c6fcdf31c697a22f0e984d7525.tar.bz2
Cowlection-ca1cf885f9c7e2c6fcdf31c697a22f0e984d7525.zip
Fixed some possible problems with bad server connection
- Fixed sending offline messages - Fixed rare occurrence of repeated triggering of server join and leave events
-rw-r--r--CHANGELOG.md5
-rw-r--r--src/main/java/de/cowtipper/cowlection/listener/PlayerListener.java25
-rw-r--r--src/main/java/de/cowtipper/cowlection/util/ChatHelper.java43
-rw-r--r--src/main/java/de/cowtipper/cowlection/util/VersionChecker.java3
4 files changed, 51 insertions, 25 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1ab1798..70f6142 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Changed
- Item age: show timestamp in the local timezone instead of "SkyBlock"-timezone (Eastern Time; also fixed the incorrect 12h ↔ 24h clock conversion)
+### Fixed
+- Fixed some possible problems with bad server connection
+ - Fixed sending 'offline' messages (new version notification and online best friends)
+ - Fixed rare occurrence of repeated triggering of server join and leave events
+
## [1.8.9-0.11.0] - 28.09.2020
### Added
- SkyBlock Dungeons Party: new command `/moo dungeon party`
diff --git a/src/main/java/de/cowtipper/cowlection/listener/PlayerListener.java b/src/main/java/de/cowtipper/cowlection/listener/PlayerListener.java
index 0507766..d92dd6f 100644
--- a/src/main/java/de/cowtipper/cowlection/listener/PlayerListener.java
+++ b/src/main/java/de/cowtipper/cowlection/listener/PlayerListener.java
@@ -34,6 +34,7 @@ public class PlayerListener {
private final Cowlection main;
private static DungeonsListener dungeonsListener;
private static SkyBlockListener skyBlockListener;
+ private boolean isPlayerJoiningServer;
private boolean isOnSkyBlock;
public PlayerListener(Cowlection main) {
@@ -89,13 +90,14 @@ public class PlayerListener {
@SubscribeEvent
public void onServerJoin(FMLNetworkEvent.ClientConnectedToServerEvent e) {
- main.getVersionChecker().runUpdateCheck(false);
- new TickDelay(() -> main.getChatHelper().sendOfflineMessages(), 6 * 20);
- if (MooConfig.doBestFriendsOnlineCheck && CredentialStorage.isMooValid && main.getFriendsHandler().getBestFriends().size() > 0) {
- main.getFriendsHandler().runBestFriendsOnlineCheck(false);
+ if (!isPlayerJoiningServer) {
+ isOnSkyBlock = false;
+ isPlayerJoiningServer = true;
+ main.getVersionChecker().runUpdateCheck(false);
+ if (MooConfig.doBestFriendsOnlineCheck && CredentialStorage.isMooValid && main.getFriendsHandler().getBestFriends().size() > 0) {
+ main.getFriendsHandler().runBestFriendsOnlineCheck(false);
+ }
}
- isOnSkyBlock = false;
- main.getLogger().info("Joined the server");
}
@SubscribeEvent
@@ -105,6 +107,7 @@ public class PlayerListener {
@SubscribeEvent
public void onWorldEnter(PlayerSetSpawnEvent e) {
+ isPlayerJoiningServer = false;
// check if player is on SkyBlock or on another gamemode
new TickDelay(() -> {
ScoreObjective scoreboardSidebar = e.entityPlayer.worldObj.getScoreboard().getObjectiveInDisplaySlot(1);
@@ -145,9 +148,11 @@ public class PlayerListener {
@SubscribeEvent
public void onServerLeave(FMLNetworkEvent.ClientDisconnectionFromServerEvent e) {
- main.getFriendsHandler().saveBestFriends();
- main.getPlayerCache().clearAllCaches();
- unregisterSkyBlockListeners();
- main.getLogger().info("Left the server");
+ // check if player actually was on the server
+ if (!isPlayerJoiningServer) {
+ main.getFriendsHandler().saveBestFriends();
+ main.getPlayerCache().clearAllCaches();
+ unregisterSkyBlockListeners();
+ }
}
}
diff --git a/src/main/java/de/cowtipper/cowlection/util/ChatHelper.java b/src/main/java/de/cowtipper/cowlection/util/ChatHelper.java
index 42a5790..eef9ca7 100644
--- a/src/main/java/de/cowtipper/cowlection/util/ChatHelper.java
+++ b/src/main/java/de/cowtipper/cowlection/util/ChatHelper.java
@@ -8,9 +8,10 @@ import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.event.entity.EntityJoinWorldEvent;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -30,27 +31,43 @@ public class ChatHelper {
}
public void sendMessage(IChatComponent chatComponent) {
- ClientChatReceivedEvent event = new ClientChatReceivedEvent((byte) 1, chatComponent);
- MinecraftForge.EVENT_BUS.post(event);
- if (!event.isCanceled()) {
- if (Minecraft.getMinecraft().thePlayer == null) {
- offlineMessages.add(event.message);
- } else {
+ if (Minecraft.getMinecraft().thePlayer == null) {
+ putOfflineMessage(chatComponent);
+ } else {
+ ClientChatReceivedEvent event = new ClientChatReceivedEvent((byte) 1, chatComponent);
+ MinecraftForge.EVENT_BUS.post(event);
+ if (!event.isCanceled()) {
Minecraft.getMinecraft().thePlayer.addChatMessage(event.message);
}
}
}
- public void sendOfflineMessages() {
+ private void putOfflineMessage(IChatComponent chatComponent) {
+ if (offlineMessages.size() == 0) {
+ // had no offline messages before
+ MinecraftForge.EVENT_BUS.register(this);
+ }
+ offlineMessages.add(chatComponent);
+ }
+
+ @SubscribeEvent
+ public void onPlayerWorldJoin(EntityJoinWorldEvent e) {
+ if (e.entity == Minecraft.getMinecraft().thePlayer) {
+ new TickDelay(this::sendOfflineMessages, 6 * 20);
+ }
+ }
+
+ private void sendOfflineMessages() {
if (Minecraft.getMinecraft().thePlayer != null) {
- Iterator<IChatComponent> offlineMessages = this.offlineMessages.iterator();
- if (offlineMessages.hasNext()) {
+ if (offlineMessages.size() > 0) {
Minecraft.getMinecraft().thePlayer.playSound("random.levelup", 0.4F, 0.8F);
}
- while (offlineMessages.hasNext()) {
- Minecraft.getMinecraft().thePlayer.addChatMessage(offlineMessages.next());
- offlineMessages.remove();
+
+ for (IChatComponent offlineMessage : offlineMessages) {
+ sendMessage(offlineMessage);
}
+ offlineMessages.clear();
+ MinecraftForge.EVENT_BUS.unregister(this);
}
}
diff --git a/src/main/java/de/cowtipper/cowlection/util/VersionChecker.java b/src/main/java/de/cowtipper/cowlection/util/VersionChecker.java
index 7f859a6..4fd465e 100644
--- a/src/main/java/de/cowtipper/cowlection/util/VersionChecker.java
+++ b/src/main/java/de/cowtipper/cowlection/util/VersionChecker.java
@@ -124,8 +124,7 @@ public class VersionChecker {
main.getChatHelper().sendMessage(statusMsg);
} else {
IChatComponent finalStatusMsg = statusMsg;
- new TickDelay(() -> main.getChatHelper().sendMessage(finalStatusMsg)
- , 6 * 20);
+ new TickDelay(() -> main.getChatHelper().sendMessage(finalStatusMsg), 6 * 20);
}
}
}