From d31b0fdbf6cd101a5e09d2fe681acf718b94eeee Mon Sep 17 00:00:00 2001
From: A_D <aunderscored@gmail.com>
Date: Wed, 26 Aug 2020 18:48:23 +0200
Subject: [PATCH] Fixed system link updating on FSDTarget

FSDTarget contains the target system under `SystemAddress`, meaning that
any time you selected a star other than the current one, plugins'
`this.system_address` was updated to that target, rather than the
current system. Said updating causes the links provided from system_url
to reflect that update (for providers that support ID64s).

This changes the journal_entry behaviour to only update
`this.system_address` when the event is any of Location, Docked,
or FSDJump, all of which contain only the current system.
---
 plugins/eddb.py  | 8 +++++---
 plugins/edsm.py  | 8 +++++---
 plugins/inara.py | 8 +++++---
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/plugins/eddb.py b/plugins/eddb.py
index b9dc6b78..c0ef35fc 100644
--- a/plugins/eddb.py
+++ b/plugins/eddb.py
@@ -83,9 +83,11 @@ def prefs_changed(cmdr, is_beta):
     pass
 
 def journal_entry(cmdr, is_beta, system, station, entry, state):
-    # Always update, even if we're not the *current* system or station provider.
-    this.system_address = entry.get('SystemAddress') or this.system_address
-    this.system = entry.get('StarSystem') or this.system
+    # Always update our system address even if we're not currently the provider for system or station, but dont update
+    # on events that contain "future" data, such as FSDTarget
+    if entry['event'] in ('Location', 'Docked', 'CarrierJump', 'FSDJump'):
+        this.system_address = entry.get('SystemAddress') or this.system_address
+        this.system = entry.get('StarSystem') or this.system
 
     # We need pop == 0 to set the value so as to clear 'x' in systems with
     # no stations.
diff --git a/plugins/edsm.py b/plugins/edsm.py
index 1f25f76d..806536cb 100644
--- a/plugins/edsm.py
+++ b/plugins/edsm.py
@@ -217,9 +217,11 @@ def credentials(cmdr):
 
 
 def journal_entry(cmdr, is_beta, system, station, entry, state):
-    # Always update, even if we're not the *current* system or station provider.
-    this.system_address = entry.get('SystemAddress') or this.system_address
-    this.system = entry.get('StarSystem') or this.system
+    # Always update our system address even if we're not currently the provider for system or station, but dont update
+    # on events that contain "future" data, such as FSDTarget
+    if entry['event'] in ('Location', 'Docked', 'CarrierJump', 'FSDJump'):
+        this.system_address = entry.get('SystemAddress') or this.system_address
+        this.system = entry.get('StarSystem') or this.system
 
     # We need pop == 0 to set the value so as to clear 'x' in systems with
     # no stations.
diff --git a/plugins/inara.py b/plugins/inara.py
index d1d5903d..e78287d1 100644
--- a/plugins/inara.py
+++ b/plugins/inara.py
@@ -329,9 +329,11 @@ def journal_entry(cmdr: str, is_beta: bool, system: str, station: str, entry: Di
     elif event_name in ('ShipyardNew', 'ShipyardSwap') or (event_name == 'Location' and entry['Docked']):
         this.suppress_docked = True
 
-    # Always update, even if we're not the *current* system or station provider.
-    this.system_address = entry.get('SystemAddress', this.system_address)
-    this.system = entry.get('StarSystem', this.system)
+    # Always update our system address even if we're not currently the provider for system or station, but dont update
+    # on events that contain "future" data, such as FSDTarget
+    if entry['event'] in ('Location', 'Docked', 'CarrierJump', 'FSDJump'):
+        this.system_address = entry.get('SystemAddress') or this.system_address
+        this.system = entry.get('StarSystem') or this.system
 
     # We need pop == 0 to set the value so as to clear 'x' in systems with
     # no stations.