mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-28 03:57:36 +01:00
Fix non-daemon command manager thread sometimes preventing shutdown
This commit is contained in:
parent
73230bc9b6
commit
2a44572fb2
@ -72,8 +72,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -83,16 +82,13 @@ import java.util.stream.Collectors;
|
||||
public class CommandManager {
|
||||
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
// the default executor to run commands on
|
||||
private final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
|
||||
private final ReentrantLock lock;
|
||||
private final TabCompletions tabCompletions;
|
||||
|
||||
private final Map<String, Command<?>> mainCommands;
|
||||
|
||||
public CommandManager(LuckPermsPlugin plugin) {
|
||||
this.plugin = plugin;
|
||||
this.lock = new ReentrantLock(true); // enable fairness
|
||||
this.tabCompletions = new TabCompletions(plugin);
|
||||
this.mainCommands = ImmutableList.<Command<?>>builder()
|
||||
.add(new UserParentCommand())
|
||||
@ -134,13 +130,16 @@ public class CommandManager {
|
||||
|
||||
public CompletableFuture<CommandResult> executeCommand(Sender sender, String label, List<String> args) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
this.lock.lock();
|
||||
try {
|
||||
return execute(sender, label, args);
|
||||
} catch (Throwable e) {
|
||||
this.plugin.getLogger().severe("Exception whilst executing command: " + args, e);
|
||||
return null;
|
||||
} finally {
|
||||
this.lock.unlock();
|
||||
}
|
||||
}, this.executor);
|
||||
}, this.plugin.getBootstrap().getScheduler().async());
|
||||
}
|
||||
|
||||
public boolean hasPermissionForAny(Sender sender) {
|
||||
|
Loading…
Reference in New Issue
Block a user