Skip to content

Commit 837ab3b

Browse files
committed
Add Fetch Monitoring, bump to 1.1.0
1 parent c162366 commit 837ab3b

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.earthpol</groupId>
88
<artifactId>NameMCAPI</artifactId>
9-
<version>1.0.0</version>
9+
<version>1.1.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>NameMCAPI</name>

src/main/java/com/earthpol/namemc/NameMCAPI.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import org.bukkit.Bukkit;
55
import org.bukkit.configuration.file.FileConfiguration;
66
import org.bukkit.plugin.java.JavaPlugin;
7-
import org.bukkit.scheduler.BukkitScheduler;
87
import java.io.InputStreamReader;
98
import java.net.HttpURLConnection;
109
import java.net.URL;
@@ -24,16 +23,22 @@ public final class NameMCAPI extends JavaPlugin implements UUIDFetcherAPI {
2423
private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
2524
private List<UUID> uuidList = new CopyOnWriteArrayList<>();
2625
private String fetchUrl;
26+
private long lastFetchTime = 0;
27+
private int fetchIntervalSeconds;
28+
2729
@Override
2830
public void onEnable() {
2931
this.saveDefaultConfig();
3032
FileConfiguration config = this.getConfig();
3133

32-
int interval = config.getInt("fetch-interval", 60) * 20; // Convert to ticks
34+
fetchIntervalSeconds = config.getInt("fetch-interval", 60); // Fetch interval in seconds
3335
fetchUrl = config.getString("uuid-fetch-url", "");
3436

3537
// Start fetching UUIDs asynchronously
36-
scheduler.scheduleAtFixedRate(this::fetchUUIDs, 0, interval, TimeUnit.SECONDS);
38+
scheduler.scheduleAtFixedRate(this::fetchUUIDs, 0, fetchIntervalSeconds, TimeUnit.SECONDS);
39+
40+
// Start the monitoring task
41+
scheduler.scheduleAtFixedRate(this::monitorFetch, fetchIntervalSeconds, fetchIntervalSeconds, TimeUnit.SECONDS);
3742

3843
Bukkit.getServicesManager().register(UUIDFetcherAPI.class, this, this, org.bukkit.plugin.ServicePriority.Normal);
3944
}
@@ -55,6 +60,7 @@ private void fetchUUIDs() {
5560
// Only clear and update the uuidList if fetching was successful
5661
uuidList.clear();
5762
uuidList.addAll(fetchedUuids);
63+
lastFetchTime = System.currentTimeMillis(); // Update last fetch time
5864
}
5965
} catch (Exception e) {
6066
// Log the error but do not clear the uuidList
@@ -64,6 +70,13 @@ private void fetchUUIDs() {
6470
}
6571
}
6672

73+
private void monitorFetch() {
74+
long currentTime = System.currentTimeMillis();
75+
if (currentTime - lastFetchTime > fetchIntervalSeconds * 2000) { // Allowing some buffer time
76+
getLogger().warning("Fetch task may not be running as expected. Last fetch was more than twice the interval ago.");
77+
}
78+
}
79+
6780
@Override
6881
public List<UUID> getFetchedUUIDs() {
6982
return new ArrayList<>(uuidList); // Return a copy to avoid modification
@@ -80,4 +93,4 @@ public void onDisable() {
8093
scheduler.shutdownNow();
8194
}
8295
}
83-
}
96+
}

0 commit comments

Comments
 (0)