Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public void runSync(Runnable task) {
}

@Override
public void runTaskTimer(Runnable task, long delayTicks, long periodTicks) {
public void runTaskTimer(Runnable task, long delayMs, long periodMs) {
long delayTicks = delayMs / 50;
long periodTicks = periodMs / 50;
plugin.getServer().getScheduler().runTaskTimer(plugin, task, delayTicks, periodTicks);
}

Expand All @@ -28,7 +30,9 @@ public void runAsync(Runnable task) {
}

@Override
public Task runTaskTimerAsync(Runnable task, long delayTicks, long periodTicks) {
public Task runTaskTimerAsync(Runnable task, long delayMs, long periodMs) {
long delayTicks = delayMs / 50;
long periodTicks = periodMs / 50;
return new BukkitTaskWrapper(plugin.getServer().getScheduler().runTaskTimerAsynchronously(plugin, task, delayTicks, periodTicks));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ public void runAsync(Runnable task) {
}

@Override
public Task runTaskTimerAsync(Runnable task, long delayTicks, long periodTicks) {
long delayMs = delayTicks * 50L; // 20 ticks/second = 50ms per tick
long periodMs = periodTicks * 50L;

public Task runTaskTimerAsync(Runnable task, long delayMs, long periodMs) {
return new BungeeCordTaskWrapper(
plugin.getProxy().getScheduler().schedule(plugin, task, delayMs, periodMs, TimeUnit.MILLISECONDS));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class DatabaseService implements IDatabaseService {
private volatile Task retryTask; // volatile for visibility across threads

private final int MAX_RETRIES = 5;
private final long RETRY_DELAY_TICKS = 20L * 30L; // 30 seconds
private final long RETRY_DELAY_MS = 30000L; // 30 seconds

// Use volatile as this is read/written by different threads
private volatile boolean isConnected = false;
Expand Down Expand Up @@ -193,7 +193,7 @@ public synchronized void startRetryTaskIfNeeded() {

logger.info("Retrying InfluxDB connection... Attempt " + retryCount + "/" + MAX_RETRIES);
connect(); // Note: connect() will handle setting isConnected flag and potentially stopping the task if successful.
}, RETRY_DELAY_TICKS, RETRY_DELAY_TICKS); // Start after delay, repeat at delay
}, RETRY_DELAY_MS, RETRY_DELAY_MS); // Start after delay, repeat at delay
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ default void runSync(Runnable task) {
* Runs a task timer synchronously on the main thread.
*
* @param task The task to run
* @param delayMs Delay in milliseconds before first executing
* @param periodMs Period in milliseconds between executions
* @throws UnsupportedOperationException if the implementation does not support synchronous task execution
*/
default void runTaskTimer(Runnable task, long delayTicks, long periodTicks) {
default void runTaskTimer(Runnable task, long delayMs, long periodMs) {
throw new UnsupportedOperationException("Synchronous task timer execution is not supported.");
}

Expand All @@ -35,9 +37,11 @@ default void runTaskTimer(Runnable task, long delayTicks, long periodTicks) {
* Runs a task timer asynchronously on a separate thread.
*
* @param task The task to run
* @param delayMs Delay in milliseconds before first executing
* @param periodMs Period in milliseconds between executions
* @return A Task object representing the task
*/
Task runTaskTimerAsync(Runnable task, long delayTicks, long periodTicks);
Task runTaskTimerAsync(Runnable task, long delayMs, long periodMs);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public void runSync(Runnable task) {
}

@Override
public void runTaskTimer(Runnable task, long delayTicks, long periodTicks) {
public void runTaskTimer(Runnable task, long delayMs, long periodMs) {
long delayTicks = delayMs / 50;
long periodTicks = periodMs / 50;
FabricTask fabricTask = new FabricTask(task, true, delayTicks, periodTicks);
tasks.add(fabricTask);
}
Expand All @@ -41,7 +43,10 @@ public void runAsync(Runnable task) {
}

@Override
public Task runTaskTimerAsync(Runnable task, long delayTicks, long periodTicks) {
public Task runTaskTimerAsync(Runnable task, long delayMs, long periodMs) {
long delayTicks = delayMs / 50;
long periodTicks = periodMs / 50;

FabricTask fabricTask = new FabricTask(() -> CompletableFuture.runAsync(task).exceptionally(
throwable -> {
ServerPulseFabric.LOGGER.log(java.util.logging.Level.SEVERE, "An error occurred while executing task!", throwable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
}
metricsService.load();

long intervalTicks = config.getConfig().getLong("metrics.interval", 5) * 20L;
scheduler.runTaskTimerAsync(metricsService::collectAndSendMetrics, 0L, intervalTicks);
long intervalMs = config.getConfig().getLong("metrics.interval", 5) * 1000L;
scheduler.runTaskTimerAsync(metricsService::collectAndSendMetrics, 0L, intervalMs);

CommandMeta meta = server.getCommandManager().metaBuilder("serverpulsevelocity")
.plugin(this).aliases("spv").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public void runAsync(Runnable task) {
}

@Override
public Task runTaskTimerAsync(Runnable task, long delayTicks, long periodTicks) {
public Task runTaskTimerAsync(Runnable task, long delayMs, long periodMs) {
return new VelocityTaskWrapper(plugin.getServer().getScheduler().buildTask(plugin, task)
.delay(delayTicks / 20, TimeUnit.SECONDS)
.repeat(periodTicks / 20, TimeUnit.SECONDS)
.delay(delayMs, TimeUnit.MILLISECONDS)
.repeat(periodMs, TimeUnit.MILLISECONDS)
.schedule());
}
}