44import org .bukkit .Bukkit ;
55import org .bukkit .configuration .file .FileConfiguration ;
66import org .bukkit .plugin .java .JavaPlugin ;
7- import org .bukkit .scheduler .BukkitScheduler ;
87import java .io .InputStreamReader ;
98import java .net .HttpURLConnection ;
109import 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