diff --git a/bungee/src/main/java/com/livemotdmanager/bungee/LiveMotdBungee.java b/bungee/src/main/java/com/livemotdmanager/bungee/LiveMotdBungee.java
index a1edc3d..683810b 100644
--- a/bungee/src/main/java/com/livemotdmanager/bungee/LiveMotdBungee.java
+++ b/bungee/src/main/java/com/livemotdmanager/bungee/LiveMotdBungee.java
@@ -87,8 +87,7 @@ private void loadConfig() {
public void onPing(ProxyPingEvent event) {
Component comp = manager.provide();
String legacy = LegacyComponentSerializer.legacySection().serialize(comp);
- // TextComponent.fromLegacyText returns an array; wrap in a single component
- event.getResponse().setDescriptionComponent(new TextComponent(TextComponent.fromLegacyText(legacy)));
+ event.getResponse().setDescriptionComponent(TextComponent.fromLegacyText(legacy));
}
// ServerInfoProvider
diff --git a/bungee/src/main/resources/config.yml b/bungee/src/main/resources/config.yml
index 3dd5122..33e0a32 100644
--- a/bungee/src/main/resources/config.yml
+++ b/bungee/src/main/resources/config.yml
@@ -10,7 +10,7 @@ motd:
- when: "event"
text: "Special event today — /warp event"
- when: "default"
- text: "Welcome to ChaosCraftMHX — %online%/%maxplayers% playing! Weather in Riga: %weather_riga%"
+ text: "Welcome to ChaosCraftMHX — %online%/%maxplayers% playing! Weather in Riga: %weather_motd%"
weather:
enable: true
diff --git a/config.yml b/config.yml
index 3dd5122..33e0a32 100644
--- a/config.yml
+++ b/config.yml
@@ -10,7 +10,7 @@ motd:
- when: "event"
text: "Special event today — /warp event"
- when: "default"
- text: "Welcome to ChaosCraftMHX — %online%/%maxplayers% playing! Weather in Riga: %weather_riga%"
+ text: "Welcome to ChaosCraftMHX — %online%/%maxplayers% playing! Weather in Riga: %weather_motd%"
weather:
enable: true
diff --git a/core/src/main/java/com/livemotdmanager/core/MotdManager.java b/core/src/main/java/com/livemotdmanager/core/MotdManager.java
index 12ba8a5..5cc64f2 100644
--- a/core/src/main/java/com/livemotdmanager/core/MotdManager.java
+++ b/core/src/main/java/com/livemotdmanager/core/MotdManager.java
@@ -102,7 +102,7 @@ private String defaultPlaceholders(String text, MotdContext ctx) {
out = out.replace("%maxplayers%", Integer.toString(ctx.max));
out = out.replace("%tps%", String.format(Locale.US, "%.2f", ctx.tps));
if (ctx.weather != null) {
- out = out.replace("%weather_" + config.weather.city.toLowerCase(Locale.ROOT) + "%", ctx.weather);
+ out = out.replace("%weather_motd%", ctx.weather);
out = out.replace("%weather_city%", ctx.weather);
}
out = out.replace("%discord_online%", Integer.toString(ctx.discordOnline));
diff --git a/core/src/main/java/com/livemotdmanager/core/WeatherService.java b/core/src/main/java/com/livemotdmanager/core/WeatherService.java
index e866a11..5d7b914 100644
--- a/core/src/main/java/com/livemotdmanager/core/WeatherService.java
+++ b/core/src/main/java/com/livemotdmanager/core/WeatherService.java
@@ -11,9 +11,6 @@
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Locale;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeUnit;
/**
* Fetches real world weather information using the OpenWeather API.
@@ -22,35 +19,38 @@ public class WeatherService {
private final boolean enabled;
private final String city;
private final String apiKey;
- private final int updateIntervalMinutes;
- private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
private volatile String cached = "";
private final HttpClient http = HttpClient.newBuilder().connectTimeout(Duration.ofSeconds(5)).build();
+ private volatile long lastFetch = 0L;
+ private final long cacheDurationMs;
public WeatherService(MotdConfig.WeatherSettings settings) {
this.enabled = settings.enable;
this.city = settings.city;
this.apiKey = settings.apiKey;
- this.updateIntervalMinutes = settings.updateIntervalMinutes;
+ this.cacheDurationMs = Math.max(1, settings.updateIntervalMinutes) * 60L * 1000L;
}
public void start() {
if (!enabled) return;
- // Initial fetch for startup verification
update();
System.out.println("[LiveMotdManager] Weather API test: " + (cached.isEmpty() ? "unavailable" : cached));
- scheduler.scheduleAtFixedRate(this::update, updateIntervalMinutes, updateIntervalMinutes, TimeUnit.MINUTES);
}
public void stop() {
- scheduler.shutdownNow();
+ // no background tasks to stop
}
public String getCachedWeather() {
+ if (!enabled) return "";
+ long now = System.currentTimeMillis();
+ if (now - lastFetch > cacheDurationMs) {
+ update();
+ }
return cached;
}
- private void update() {
+ private synchronized void update() {
if (!enabled || city == null || city.isEmpty() || apiKey == null || apiKey.isEmpty()) return;
try {
String encodedCity = URLEncoder.encode(city, StandardCharsets.UTF_8);
@@ -67,6 +67,7 @@ private void update() {
desc = desc.substring(0,1).toUpperCase(Locale.ROOT) + desc.substring(1);
}
cached = String.format(Locale.US, "%s %.1f°C", desc, temp);
+ lastFetch = System.currentTimeMillis();
} catch (Exception e) {
// ignore but keep cached
}
diff --git a/spigot/src/main/resources/config.yml b/spigot/src/main/resources/config.yml
index 3dd5122..33e0a32 100644
--- a/spigot/src/main/resources/config.yml
+++ b/spigot/src/main/resources/config.yml
@@ -10,7 +10,7 @@ motd:
- when: "event"
text: "Special event today — /warp event"
- when: "default"
- text: "Welcome to ChaosCraftMHX — %online%/%maxplayers% playing! Weather in Riga: %weather_riga%"
+ text: "Welcome to ChaosCraftMHX — %online%/%maxplayers% playing! Weather in Riga: %weather_motd%"
weather:
enable: true
diff --git a/velocity/src/main/java/com/livemotdmanager/velocity/LiveMotdVelocity.java b/velocity/src/main/java/com/livemotdmanager/velocity/LiveMotdVelocity.java
index 242b40c..0775540 100644
--- a/velocity/src/main/java/com/livemotdmanager/velocity/LiveMotdVelocity.java
+++ b/velocity/src/main/java/com/livemotdmanager/velocity/LiveMotdVelocity.java
@@ -83,7 +83,7 @@ private void loadConfig() {
@Subscribe
public void onPing(ProxyPingEvent event) {
Component comp = manager.provide();
- event.getPing().asBuilder().description(comp).build();
+ event.setPing(event.getPing().asBuilder().description(comp).build());
}
@Override
diff --git a/velocity/src/main/resources/config.yml b/velocity/src/main/resources/config.yml
index 3dd5122..33e0a32 100644
--- a/velocity/src/main/resources/config.yml
+++ b/velocity/src/main/resources/config.yml
@@ -10,7 +10,7 @@ motd:
- when: "event"
text: "Special event today — /warp event"
- when: "default"
- text: "Welcome to ChaosCraftMHX — %online%/%maxplayers% playing! Weather in Riga: %weather_riga%"
+ text: "Welcome to ChaosCraftMHX — %online%/%maxplayers% playing! Weather in Riga: %weather_motd%"
weather:
enable: true
diff --git a/wiki/Home.md b/wiki/Home.md
index 07e7893..5ea8a73 100644
--- a/wiki/Home.md
+++ b/wiki/Home.md
@@ -16,8 +16,9 @@ and the MiniMessage formatted `text` to display.
### Weather
-Set `weather.enable` to `true` and specify `city`. Use `%weather_city%` or `%weather_%`
-placeholders in your templates.
+Set `weather.enable` to `true` and specify `city`. Use `%weather_motd%` or `%weather_city%`
+placeholders in your templates. The `weather.update-interval-minutes` option controls how often
+new data is fetched (default 10 minutes).
### Discord