Skip to content

Commit

Permalink
fix: ensure that bridge is loaded before property access (#1317)
Browse files Browse the repository at this point in the history
### Motivation
The method to fill common placeholders is used for cloudnet signs too
and as the service is starting the signs are trying to resolve some of
the bridge properties. That fails because the service is just starting
and the bridge is not loaded yet.

### Modification
Added a check that makes sure that we are only replacing placeholders if
they are present.

### Result
Signs are working correctly again.
  • Loading branch information
0utplay authored Dec 6, 2023
1 parent 61dbda8 commit 5148392
Showing 1 changed file with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,24 @@ public BridgeServiceHelper(
value = value.replace(
"%cpu_usage%",
ResourceFormatter.formatTwoDigitPrecision(service.processSnapshot().cpuUsage()));

// bridge information
value = value.replace("%online%", service.readProperty(BridgeDocProperties.IS_ONLINE) ? "Online" : "Offline");
value = value.replace(
"%online_players%",
Integer.toString(service.readProperty(BridgeDocProperties.ONLINE_COUNT)));
value = value.replace(
"%max_players%",
Integer.toString(service.readProperty(BridgeDocProperties.MAX_PLAYERS)));
value = value.replace("%motd%", service.readProperty(BridgeDocProperties.MOTD));
value = value.replace("%extra%", service.readProperty(BridgeDocProperties.EXTRA));
value = value.replace("%state%", service.readProperty(BridgeDocProperties.STATE));
value = value.replace("%version%", service.readProperty(BridgeDocProperties.VERSION));
var online = service.readProperty(BridgeDocProperties.IS_ONLINE);
value = value.replace("%online%", online ? "Online" : "Offline");

// make sure that the bridge is loaded before accessing any of the properties
if (online) {
value = value.replace(
"%online_players%",
Integer.toString(service.readProperty(BridgeDocProperties.ONLINE_COUNT)));
value = value.replace(
"%max_players%",
Integer.toString(service.readProperty(BridgeDocProperties.MAX_PLAYERS)));
value = value.replace("%motd%", service.readProperty(BridgeDocProperties.MOTD));
value = value.replace("%extra%", service.readProperty(BridgeDocProperties.EXTRA));
value = value.replace("%state%", service.readProperty(BridgeDocProperties.STATE));
value = value.replace("%version%", service.readProperty(BridgeDocProperties.VERSION));
}
// done
return value;
}
Expand Down

0 comments on commit 5148392

Please sign in to comment.