@@ -25,33 +25,43 @@ public void onInitialize() {
2525 LOGGER .info ("Ping Remote initialized." );
2626 config = ConfigBuilder .load (PingRemoteConfig .class , MOD_ID );
2727
28- ServerTickEvents .START_SERVER_TICK .register ((serverWorld ) -> {
29- PingRemote .counter ++;
30- });
31-
32- ServerTickEvents .END_WORLD_TICK .register ((serverWorld ) -> {
33- if (counter == config .getTickAmount ()) {
34- counter = 0 ;
35-
36- try (HttpClient client = HttpClient .newBuilder ()
37- .version (HttpClient .Version .HTTP_2 )
38- .connectTimeout (Duration .ofSeconds (10 ))
39- .build ()) {
40-
41- try {
42- HttpRequest request = HttpRequest .newBuilder ()
43- .uri (config .getRemoteHost ().toURI ())
44- .timeout (Duration .ofMinutes (1 ))
45- .build ();
46-
47- client .sendAsync (request , HttpResponse .BodyHandlers .ofString ())
48- .thenApply (HttpResponse ::body )
49- .thenAccept (System .out ::println );
50- } catch (URISyntaxException e ) {
51- LOGGER .warn ("Cannot ping remote host" );
28+ if (config .getRemoteHost () != null ) {
29+ ServerTickEvents .START_SERVER_TICK .register ((serverWorld ) -> {
30+ PingRemote .counter ++;
31+ });
32+
33+ ServerTickEvents .END_WORLD_TICK .register ((serverWorld ) -> {
34+ if (counter == config .getTickAmount ()) {
35+ counter = 0 ;
36+
37+ try (HttpClient client = HttpClient .newBuilder ()
38+ .version (HttpClient .Version .HTTP_2 )
39+ .connectTimeout (Duration .ofSeconds (10 ))
40+ .build ()) {
41+
42+ try {
43+ HttpRequest request = HttpRequest .newBuilder ()
44+ .uri (config .getRemoteHost ().toURI ())
45+ .timeout (Duration .ofMinutes (1 ))
46+ .build ();
47+
48+ client .sendAsync (request , HttpResponse .BodyHandlers .ofString ())
49+ .thenApply (HttpResponse ::body )
50+ .thenAccept ((response ) -> {
51+ if (config .isDebug ()) {
52+ LOGGER .info ("Response body from remote host" );
53+ LOGGER .info (response );
54+ }
55+ });
56+ } catch (URISyntaxException e ) {
57+ LOGGER .warn ("Cannot ping remote host, invalid uri" );
58+ }
5259 }
5360 }
54- }
55- });
61+ });
62+ } else {
63+ LOGGER .warn ("Remote host is not provided" );
64+ LOGGER .warn ("Skipping mod event registration" );
65+ }
5666 }
5767}
0 commit comments