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
|
@Getter
|
||||||
private static class ImportCommand extends DummySender {
|
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 CommandManager commandManager;
|
||||||
private final int id;
|
private final int id;
|
||||||
@ -231,13 +232,9 @@ public class Importer implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CommandResult result = commandManager.onCommand(
|
List<String> args = CommandManager.stripQuotes(ARGUMENT_SPLITTER.splitToList(getCommand()));
|
||||||
this,
|
CommandResult result = commandManager.onCommand(this, "lp", args, Runnable::run).get();
|
||||||
"lp",
|
|
||||||
CommandManager.stripQuotes(Splitter.on(CommandManager.COMMAND_SEPARATOR_PATTERN).omitEmptyStrings().splitToList(getCommand()))
|
|
||||||
).get();
|
|
||||||
setResult(result);
|
setResult(result);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
setResult(CommandResult.FAILURE);
|
setResult(CommandResult.FAILURE);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -253,7 +250,7 @@ public class Importer implements Runnable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String targetUser = SPACE_SPLIT.split(subCmd).iterator().next();
|
String targetUser = SPACE_SPLITTER.split(subCmd).iterator().next();
|
||||||
return "u:" + targetUser;
|
return "u:" + targetUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,7 +260,7 @@ public class Importer implements Runnable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String targetGroup = SPACE_SPLIT.split(subCmd).iterator().next();
|
String targetGroup = SPACE_SPLITTER.split(subCmd).iterator().next();
|
||||||
return "g:" + targetGroup;
|
return "g:" + targetGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +270,7 @@ public class Importer implements Runnable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
String targetTrack = SPACE_SPLIT.split(subCmd).iterator().next();
|
String targetTrack = SPACE_SPLITTER.split(subCmd).iterator().next();
|
||||||
return "t:" + targetTrack;
|
return "t:" + targetTrack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,6 +72,9 @@ import java.util.ListIterator;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
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.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -90,6 +93,9 @@ public class CommandManager {
|
|||||||
@Getter
|
@Getter
|
||||||
private final LuckPermsPlugin plugin;
|
private final LuckPermsPlugin plugin;
|
||||||
|
|
||||||
|
// the default executor to run commands on
|
||||||
|
private final ExecutorService executor = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private final List<Command> mainCommands;
|
private final List<Command> mainCommands;
|
||||||
|
|
||||||
@ -126,14 +132,11 @@ public class CommandManager {
|
|||||||
.build();
|
.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) {
|
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(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
try {
|
try {
|
||||||
return execute(sender, label, args);
|
return execute(sender, label, args);
|
||||||
@ -142,7 +145,7 @@ public class CommandManager {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}, plugin.getScheduler().async());
|
}, executor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
Loading…
Reference in New Issue
Block a user