Limit the total number of running threads

(Related #304)
This commit is contained in:
games647
2020-03-14 18:20:34 +01:00
parent e0bc7d914c
commit 57b84509da
12 changed files with 88 additions and 31 deletions
@@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentMap;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.PluginMessageRecipient;
@@ -68,6 +69,14 @@ public class FastLoginBukkit extends JavaPlugin implements PlatformPlugin<Comman
}
PluginManager pluginManager = getServer().getPluginManager();
Plugin protocolLib = pluginManager.getPlugin("ProtocolLib");
if (protocolLib != null && !protocolLib.isEnabled()) {
logger.warn("Dependency graph issue. ProtocolLib should be loaded first.");
logger.warn(getDescription().getSoftDepend().toString());
logger.warn(getDescription().getDepend().toString());
logger.warn(getDescription().getLoadBefore().toString());
}
if (bungeeCord) {
setServerStarted();
@@ -3,7 +3,6 @@ package com.github.games647.fastlogin.bukkit.command;
import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import com.github.games647.fastlogin.core.StoredProfile;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
@@ -44,7 +43,7 @@ public class CrackedCommand extends ToggleCommand {
profile.setPremium(false);
profile.setId(null);
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
plugin.getCore().getAsyncScheduler().runAsync(() -> {
plugin.getCore().getStorage().save(profile);
});
} else {
@@ -76,7 +75,7 @@ public class CrackedCommand extends ToggleCommand {
plugin.getCore().sendLocaleMessage("remove-premium", sender);
profile.setPremium(false);
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
plugin.getCore().getAsyncScheduler().runAsync(() -> {
plugin.getCore().getStorage().save(profile);
});
}
@@ -5,7 +5,6 @@ import com.github.games647.fastlogin.core.StoredProfile;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@@ -56,7 +55,7 @@ public class PremiumCommand extends ToggleCommand {
} else {
//todo: resolve uuid
profile.setPremium(true);
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
plugin.getCore().getAsyncScheduler().runAsync(() -> {
plugin.getCore().getStorage().save(profile);
});
@@ -85,7 +84,7 @@ public class PremiumCommand extends ToggleCommand {
} else {
//todo: resolve uuid
profile.setPremium(true);
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
plugin.getCore().getAsyncScheduler().runAsync(() -> {
plugin.getCore().getStorage().save(profile);
});
@@ -11,7 +11,6 @@ import com.github.games647.fastlogin.bukkit.FastLoginBukkit;
import java.security.KeyPair;
import java.security.SecureRandom;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import static com.comphenix.protocol.PacketType.Login.Client.ENCRYPTION_BEGIN;
@@ -67,7 +66,7 @@ public class ProtocolLibListener extends PacketAdapter {
packetEvent.getAsyncMarker().incrementProcessingDelay();
Runnable verifyTask = new VerifyResponseTask(plugin, packetEvent, sender, sharedSecret, keyPair);
Bukkit.getScheduler().runTaskAsynchronously(plugin, verifyTask);
plugin.getCore().getAsyncScheduler().runAsync(verifyTask);
}
private void onLogin(PacketEvent packetEvent, Player player) {
@@ -85,6 +84,6 @@ public class ProtocolLibListener extends PacketAdapter {
packetEvent.getAsyncMarker().incrementProcessingDelay();
Runnable nameCheckTask = new NameCheckTask(plugin, packetEvent, random, player, username, keyPair.getPublic());
Bukkit.getScheduler().runTaskAsynchronously(plugin, nameCheckTask);
plugin.getCore().getAsyncScheduler().runAsync(nameCheckTask);
}
}
+5 -12
View File
@@ -11,21 +11,14 @@ description: |
website: ${project.url}
dev-url: ${project.url}
# Load the plugin as early as possible to inject it for all players
load: STARTUP
# This plugin don't have to be transformed for compatibility with Minecraft >= 1.13
api-version: '1.13'
softdepend:
# We depend either ProtocolLib or ProtocolSupport
- ProtocolSupport
- ProtocolLib
- PlaceholderAPI
# Auth plugins
- AuthMe
- LoginSecurity
- xAuth
- LogIt
- UltraAuth
- CrazyLogin
# We depend either ProtocolLib or ProtocolSupport
depend: [ProtocolLib]
commands:
${project.parent.name}: