Remove the isAcceptingLogins storage state in favour of just throwing exceptions on usage

This commit is contained in:
Luck
2017-12-09 19:02:23 +00:00
Unverified
parent 94b4e3d366
commit 9dd4f71526
15 changed files with 82 additions and 105 deletions
@@ -29,6 +29,8 @@ import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import me.lucko.luckperms.common.plugin.SchedulerAdapter;
import org.bukkit.scheduler.BukkitTask;
@@ -37,7 +39,8 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
public class BukkitSchedulerAdapter implements SchedulerAdapter {
@@ -69,7 +72,7 @@ public class BukkitSchedulerAdapter implements SchedulerAdapter {
this.plugin = plugin;
this.sync = new SyncExecutor();
this.asyncFallback = Executors.newCachedThreadPool();
this.asyncFallback = new FallbackAsyncExecutor();
this.asyncBukkit = new BukkitAsyncExecutor();
this.async = new AsyncExecutor();
}
@@ -144,4 +147,10 @@ public class BukkitSchedulerAdapter implements SchedulerAdapter {
}
}
private static final class FallbackAsyncExecutor extends ThreadPoolExecutor {
private FallbackAsyncExecutor() {
super(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<>(), new ThreadFactoryBuilder().setNameFormat("luckperms-fallback-%d").build());
}
}
}
@@ -134,7 +134,6 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
private ContextManager<Player> contextManager;
private CalculatorFactory calculatorFactory;
private BufferedRequest<Void> updateTaskBuffer;
private boolean started = false;
private CountDownLatch enableLatch = new CountDownLatch(1);
private VerboseHandler verboseHandler;
private BukkitSenderFactory senderFactory;
@@ -174,7 +173,6 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
try {
enable();
started = true;
} finally {
// count down the latch when onEnable has been called
// we don't care about the result here
@@ -328,8 +326,6 @@ public class LPBukkitPlugin extends JavaPlugin implements LuckPermsPlugin {
// Switch back to the fallback executor, the bukkit one won't allow new tasks
scheduler.setUseFallback(true);
started = false;
defaultsProvider.close();
permissionVault.shutdown();
verboseHandler.shutdown();
@@ -64,7 +64,7 @@ public class BukkitConnectionListener implements Listener {
/* wait for the plugin to enable. because these events are fired async, they can be called before
the plugin has enabled. */
try {
plugin.getEnableLatch().await(30, TimeUnit.SECONDS);
plugin.getEnableLatch().await(60, TimeUnit.SECONDS);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
@@ -73,21 +73,6 @@ public class BukkitConnectionListener implements Listener {
plugin.getLog().info("Processing pre-login for " + e.getUniqueId() + " - " + e.getName());
}
/* there was an issue connecting to the DB, performing file i/o, etc.
we don't let players join in this case, because it means they can connect to the server without their permissions data.
some server admins rely on negating perms to stop users from causing damage etc, so it's really important that
this data is loaded. */
if (!plugin.isStarted() || !plugin.getStorage().isAcceptingLogins()) {
// log that the user tried to login, but was denied at this stage.
deniedAsyncLogin.add(e.getUniqueId());
// actually deny the connection.
plugin.getLog().warn("Permissions storage is not loaded. Denying connection from: " + e.getUniqueId() + " - " + e.getName());
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, Message.LOADING_ERROR.asString(plugin.getLocaleManager()));
return;
}
plugin.getUniqueConnections().add(e.getUniqueId());
/* Actually process the login for the connection.
@@ -103,9 +88,10 @@ public class BukkitConnectionListener implements Listener {
User user = LoginHelper.loadUser(plugin, e.getUniqueId(), e.getName(), false);
plugin.getApiProvider().getEventFactory().handleUserLoginProcess(e.getUniqueId(), e.getName(), user);
} catch (Exception ex) {
plugin.getLog().severe("Exception occured whilst loading data for " + e.getUniqueId() + " - " + e.getName());
ex.printStackTrace();
// there was some error loading data. deny the connection
// deny the connection
deniedAsyncLogin.add(e.getUniqueId());
e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, Message.LOADING_ERROR.asString(plugin.getLocaleManager()));
}