|
5 | 5 | import java.io.IOException;
|
6 | 6 | import java.io.InputStream;
|
7 | 7 | import java.io.OutputStream;
|
| 8 | +import java.io.Writer; |
8 | 9 | import java.text.ParseException;
|
9 | 10 | import java.util.ArrayList;
|
10 | 11 | import java.util.Collection;
|
|
30 | 31 |
|
31 | 32 | import org.joda.time.DateTime;
|
32 | 33 | import org.w3c.dom.DOMException;
|
| 34 | +import org.w3c.dom.Node; |
33 | 35 |
|
34 | 36 | import mekhq.FileParser;
|
35 | 37 | import mekhq.MekHQ;
|
@@ -73,6 +75,20 @@ public void run() {
|
73 | 75 | }
|
74 | 76 | return planets;
|
75 | 77 | }
|
| 78 | + |
| 79 | + public static void reload(boolean waitForFinish) { |
| 80 | + planets = null; |
| 81 | + getInstance(); |
| 82 | + if(waitForFinish) { |
| 83 | + try { |
| 84 | + while(!planets.isInitialized()) { |
| 85 | + Thread.sleep(10); |
| 86 | + } |
| 87 | + } catch(InterruptedException iex) { |
| 88 | + MekHQ.logError(iex); |
| 89 | + } |
| 90 | + } |
| 91 | + } |
76 | 92 |
|
77 | 93 | private ConcurrentMap<String, Planet> planetList = new ConcurrentHashMap<>();
|
78 | 94 | /* organizes systems into a grid of 30lyx30ly squares so we can find
|
@@ -200,6 +216,40 @@ public void writePlanet(OutputStream out, Planet planet) {
|
200 | 216 | }
|
201 | 217 | }
|
202 | 218 |
|
| 219 | + public void writePlanet(Writer out, Planet planet) { |
| 220 | + try { |
| 221 | + marshaller.marshal(planet, out); |
| 222 | + } catch (Exception e) { |
| 223 | + MekHQ.logError(e); |
| 224 | + } |
| 225 | + } |
| 226 | + |
| 227 | + |
| 228 | + public void writePlanetaryEvent(OutputStream out, Planet.PlanetaryEvent event) { |
| 229 | + try { |
| 230 | + marshaller.marshal(event, out); |
| 231 | + } catch (Exception e) { |
| 232 | + MekHQ.logError(e); |
| 233 | + } |
| 234 | + } |
| 235 | + |
| 236 | + public void writePlanetaryEvent(Writer out, Planet.PlanetaryEvent event) { |
| 237 | + try { |
| 238 | + marshaller.marshal(event, out); |
| 239 | + } catch (Exception e) { |
| 240 | + MekHQ.logError(e); |
| 241 | + } |
| 242 | + } |
| 243 | + |
| 244 | + public Planet.PlanetaryEvent readPlanetaryEvent(Node node) { |
| 245 | + try { |
| 246 | + return (Planet.PlanetaryEvent) unmarshaller.unmarshal(node); |
| 247 | + } catch (JAXBException e) { |
| 248 | + MekHQ.logError(e); |
| 249 | + } |
| 250 | + return null; |
| 251 | + } |
| 252 | + |
203 | 253 | public void writePlanets(OutputStream out, List<Planet> planets) {
|
204 | 254 | LocalPlanetList temp = new LocalPlanetList();
|
205 | 255 | temp.list = planets;
|
|
0 commit comments