mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-27 21:29:47 +01:00
Execute commands sequentially on a single thread executor
This commit is contained in:
parent
e09c5622f7
commit
b9dfd7db54
@ -196,7 +196,8 @@ public class Importer implements Runnable {
|
||||
|
||||
@Getter
|
||||
private static class ImportCommand extends DummySender {
|
||||
private static final Splitter SPACE_SPLIT = Splitter.on(" ");
|
||||
private static final Splitter ARGUMENT_SPLITTER = Splitter.on(CommandManager.COMMAND_SEPARATOR_PATTERN).omitEmptyStrings();
|
||||
private static final Splitter SPACE_SPLITTER = Splitter.on(" ");
|
||||
|
||||
private final CommandManager commandManager;
|
||||
private final int id;
|
||||
@ -231,13 +232,9 @@ public class Importer implements Runnable {
|
||||
}
|
||||
|
||||
try {
|
||||
CommandResult result = commandManager.onCommand(
|
||||
this,
|
||||
"lp",
|
||||
CommandManager.stripQuotes(Splitter.on(CommandManager.COMMAND_SEPARATOR_PATTERN).omitEmptyStrings().splitToList(getCommand()))
|
||||
).get();
|
||||
List<String> args = CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(getCommand()));
|
||||
CommandResult result = commandManager.onCommand(this, "lp", args, Runnable::run).get();
|
||||
setResult(result);
|
||||
|
||||
} catch (Exception e) {
|
||||
setResult(CommandResult.FAILURE);
|
||||
e.printStackTrace();
|
||||
@ -253,7 +250,7 @@ public class Importer implements Runnable {
|
||||
return null;
|
||||
}
|
||||
|
||||
String targetUser = SPACE_SPLIT.split(subCmd).iterator().next();
|
||||
String targetUser = SPACE_SPLITTER.split(subCmd).iterator().next();
|
||||
return "u:" + targetUser;
|
||||
}
|
||||
|
||||
@ -263,7 +260,7 @@ public class Importer implements Runnable {
|
||||
return null;
|
||||
}
|
||||
|
||||
String targetGroup = SPACE_SPLIT.split(subCmd).iterator().next();
|
||||
String targetGroup = SPACE_SPLITTER.split(subCmd).iterator().next();
|
||||
return "g:" + targetGroup;
|
||||
}
|
||||
|
||||
@ -273,7 +270,7 @@ public class Importer implements Runnable {
|
||||
return null;
|
||||
}
|
||||
|
||||
String targetTrack = SPACE_SPLIT.split(subCmd).iterator().next();
|
||||
String targetTrack = SPACE_SPLITTER.split(subCmd).iterator().next();
|
||||
return "t:" + targetTrack;
|
||||
}
|
||||
|
||||
|
@ -72,6 +72,9 @@ import java.util.ListIterator;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -90,6 +93,9 @@ public class CommandManager {
|
||||
@Getter
|
||||
private final LuckPermsPlugin plugin;
|
||||
|
||||
// the default executor to run commands on
|
||||
private final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||
|
||||
@Getter
|
||||
private final List<Command> mainCommands;
|
||||
|
||||
@ -126,14 +132,11 @@ public class CommandManager {
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic on command method to be called from the command executor object of the platform
|
||||
* Unlike {@link #execute(Sender, String, List)}, this method is called in a new thread
|
||||
* @param sender who sent the command
|
||||
* @param label the command label used
|
||||
* @param args the arguments provided
|
||||
*/
|
||||
public CompletableFuture<CommandResult> onCommand(Sender sender, String label, List<String> args) {
|
||||
return onCommand(sender, label, args, executor);
|
||||
}
|
||||
|
||||
public CompletableFuture<CommandResult> onCommand(Sender sender, String label, List<String> args, Executor executor) {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try {
|
||||
return execute(sender, label, args);
|
||||
@ -142,7 +145,7 @@ public class CommandManager {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}, plugin.getScheduler().async());
|
||||
}, executor);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
Loading…
Reference in New Issue
Block a user