aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/net/elytrium/limboauth/LimboAuth.java12
-rw-r--r--src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java10
2 files changed, 15 insertions, 7 deletions
diff --git a/src/main/java/net/elytrium/limboauth/LimboAuth.java b/src/main/java/net/elytrium/limboauth/LimboAuth.java
index 29b7e77..618877b 100644
--- a/src/main/java/net/elytrium/limboauth/LimboAuth.java
+++ b/src/main/java/net/elytrium/limboauth/LimboAuth.java
@@ -61,6 +61,7 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.regex.Pattern;
@@ -141,6 +142,7 @@ public class LimboAuth {
private final File configFile;
private final LimboFactory factory;
private final FloodgateApiHolder floodgateApi;
+ private final ThreadLocal<ScheduledExecutorService> scheduler;
@Nullable
private Component loginPremium;
@@ -175,6 +177,8 @@ public class LimboAuth {
} else {
this.floodgateApi = null;
}
+
+ this.scheduler = ThreadLocal.withInitial(() -> Executors.newSingleThreadScheduledExecutor(task -> new Thread(task, "limboauth-scheduler")));
}
@Subscribe
@@ -366,14 +370,14 @@ public class LimboAuth {
eventManager.unregisterListeners(this);
eventManager.register(this, new AuthListener(this, this.playerDao, this.floodgateApi));
- Executors.newScheduledThreadPool(1, task -> new Thread(task, "purge-cache")).scheduleAtFixedRate(
+ Executors.newSingleThreadScheduledExecutor(task -> new Thread(task, "limboauth-purge-cache")).scheduleAtFixedRate(
() -> this.checkCache(this.cachedAuthChecks, Settings.IMP.MAIN.PURGE_CACHE_MILLIS),
Settings.IMP.MAIN.PURGE_CACHE_MILLIS,
Settings.IMP.MAIN.PURGE_CACHE_MILLIS,
TimeUnit.MILLISECONDS
);
- Executors.newScheduledThreadPool(1, task -> new Thread(task, "purge-premium-cache")).scheduleAtFixedRate(
+ Executors.newSingleThreadScheduledExecutor(task -> new Thread(task, "limboauth-purge-premium-cache")).scheduleAtFixedRate(
() -> this.checkCache(this.premiumCache, Settings.IMP.MAIN.PURGE_PREMIUM_CACHE_MILLIS),
Settings.IMP.MAIN.PURGE_PREMIUM_CACHE_MILLIS,
Settings.IMP.MAIN.PURGE_PREMIUM_CACHE_MILLIS,
@@ -657,6 +661,10 @@ public class LimboAuth {
return SERIALIZER;
}
+ public ScheduledExecutorService getScheduler() {
+ return this.scheduler.get();
+ }
+
private static class CachedUser {
private final long checkTime;
diff --git a/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java b/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java
index 6a65e7f..fbb442a 100644
--- a/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java
+++ b/src/main/java/net/elytrium/limboauth/handler/AuthSessionHandler.java
@@ -20,7 +20,6 @@ package net.elytrium.limboauth.handler;
import at.favre.lib.crypto.bcrypt.BCrypt;
import com.j256.ormlite.dao.Dao;
import com.velocitypowered.api.proxy.Player;
-import com.velocitypowered.api.scheduler.ScheduledTask;
import dev.samstevens.totp.code.CodeVerifier;
import dev.samstevens.totp.code.DefaultCodeGenerator;
import dev.samstevens.totp.code.DefaultCodeVerifier;
@@ -31,6 +30,7 @@ import java.text.MessageFormat;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
+import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import net.elytrium.java.commons.mc.serialization.Serializer;
@@ -101,7 +101,7 @@ public class AuthSessionHandler implements LimboSessionHandler {
@Nullable
private RegisteredPlayer playerInfo;
- private ScheduledTask authMainTask;
+ private ScheduledFuture<?> authMainTask;
private LimboPlayer player;
private String ip;
@@ -158,7 +158,7 @@ public class AuthSessionHandler implements LimboSessionHandler {
Serializer serializer = LimboAuth.getSerializer();
int authTime = Settings.IMP.MAIN.AUTH_TIME;
float multiplier = 1000.0F / authTime;
- this.authMainTask = this.plugin.getServer().getScheduler().buildTask(this.plugin, () -> {
+ this.authMainTask = this.plugin.getScheduler().scheduleWithFixedDelay(() -> {
if (System.currentTimeMillis() - this.joinTime > authTime) {
this.proxyPlayer.disconnect(timesUp);
} else {
@@ -169,7 +169,7 @@ public class AuthSessionHandler implements LimboSessionHandler {
this.bossBar.progress(Math.min(1.0F, secondsLeft * multiplier));
}
}
- }).repeat(1, TimeUnit.SECONDS).schedule();
+ }, 0, 1, TimeUnit.SECONDS);
if (bossBarEnabled) {
this.proxyPlayer.showBossBar(this.bossBar);
@@ -249,7 +249,7 @@ public class AuthSessionHandler implements LimboSessionHandler {
@Override
public void onDisconnect() {
if (this.authMainTask != null) {
- this.authMainTask.cancel();
+ this.authMainTask.cancel(true);
}
this.proxyPlayer.hideBossBar(this.bossBar);