Skip to content

Commit

Permalink
Fix auto ping bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamesuta committed Feb 6, 2018
1 parent 898cb60 commit 4449296
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ public class DefaultServerList {
public final Gson gson = new Gson();

public ServerListModel loadModel(final File file) {
try (JsonReader reader = new JsonReader(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8))) {
return this.gson.fromJson(reader, ServerListModel.class);
} catch (final Exception e) {
Log.log.warn("Could not load "+file.getName(), e);
return null;
}
if (file.exists())
try (JsonReader reader = new JsonReader(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8))) {
return this.gson.fromJson(reader, ServerListModel.class);
} catch (final Exception e) {
Log.log.warn("Could not load "+file.getName(), e);
}
return null;
}

public static class ServerListModel {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/net/teamfruit/serverobserver/GuiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ public void action(final ActionPerformedEvent.Post e) {

public class TargetServer {
private ServerData target;
private GuiMultiplayer mpgui_cache;
private String targetIP_cache;

public void set(final ServerData serverData) {
if (serverData==null) {
Expand All @@ -219,8 +221,11 @@ public void set(final ServerData serverData) {
final String targetServerIP = getServerIP();
if (targetServerIP==null)
return null;
if (this.target==null||!StringUtils.equals(this.target.serverIP, targetServerIP))
if (mpgui!=this.mpgui_cache||!StringUtils.equals(this.targetIP_cache, targetServerIP)) {
this.target = getServerData(mpgui, getServerName(), targetServerIP, true);
this.targetIP_cache = targetServerIP;
this.mpgui_cache = mpgui;
}
return this.target;
}

Expand Down

0 comments on commit 4449296

Please sign in to comment.