Skip to content
Open
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
5 changes: 3 additions & 2 deletions folia/src/main/java/io/tebex/plugin/TebexFoliaPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ public void onEnable() {
});
}, 1, 60 * 20);

// start the initial check, which is rescheduled according to the next_check from remote
platform.checkCommandQueue(true);
// Initial check is started by initStore() when getServerInformation() completes (see BasePluginPlatform).
// Do not call checkCommandQueue here to avoid running it twice on Folia (once from here and once from
// initStore's callback), which would process online players' commands twice.
}

/**
Expand Down
14 changes: 14 additions & 0 deletions sdk/src/main/java/io/tebex/sdk/platform/BasePluginPlatform.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;

import static io.tebex.sdk.util.ResourceUtil.getBundledFile;
Expand All @@ -43,6 +44,7 @@ public abstract class BasePluginPlatform implements PluginPlatform {
protected List<ServerEvent> serverEvents = Collections.synchronizedList(new ArrayList<>());

private final ArrayList<PluginEvent> PLUGIN_EVENTS = new ArrayList<>();
private final AtomicBoolean commandCheckInProgress = new AtomicBoolean(false);

/**
* Checks if the configured store is Geyser/Offline
Expand Down Expand Up @@ -113,10 +115,19 @@ public final CompletableFuture<String[]> checkCommandQueue(boolean useRemoteNext
return forceCheckOutput;
}

if (!commandCheckInProgress.compareAndSet(false, true)) {
debug("Command queue check already in progress. Skipping to avoid duplicate execution.");
if (useRemoteNextCheck) {
executeAsyncLater(this::performCheck, 60, TimeUnit.SECONDS);
}
return forceCheckOutput;
}

debug("Checking for due players...");
getQueuedPlayers().clear();

getSDK().getDuePlayers().whenComplete((duePlayersResponse, ex) -> {
try {
ArrayList<String> output = new ArrayList<>();
if (ex != null) {
if (ex.getMessage().contains("429")) { // handling for rate limits
Expand Down Expand Up @@ -156,6 +167,9 @@ public final CompletableFuture<String[]> checkCommandQueue(boolean useRemoteNext

if(! duePlayersResponse.isExecuteOffline()) return;
handleOfflineCommands();
} finally {
commandCheckInProgress.set(false);
}
});

return forceCheckOutput;
Expand Down