Command with 0 delay should be run immediately

This commit is contained in:
DNx 2018-07-07 23:39:59 +07:00
parent 2e5fdb4ca0
commit b741c0da14
2 changed files with 17 additions and 12 deletions

View File

@ -25,8 +25,7 @@ public class Command {
* @param executor the executor of the command
*/
public Command(String command, Executor executor) {
this.command = command;
this.executor = executor;
this(command, executor, 0);
}
/**

View File

@ -124,20 +124,26 @@ public class CommandManager implements Reloadable {
}
private <T extends Command> void executeCommands(Player player, List<T> commands, Predicate<T> predicate) {
for (T command : commands) {
if (predicate.test(command)) {
final String execution = command.getCommand();
bukkitService.scheduleSyncDelayedTask(() -> {
if (Executor.CONSOLE.equals(command.getExecutor())) {
bukkitService.dispatchConsoleCommand(execution);
} else {
bukkitService.dispatchCommand(player, execution);
}
}, command.getDelay());
for (T cmd : commands) {
if (predicate.test(cmd)) {
long delay = cmd.getDelay();
if (delay > 0) {
bukkitService.scheduleSyncDelayedTask(() -> dispatchCommand(player, cmd), delay);
} else {
dispatchCommand(player, cmd);
}
}
}
}
private void dispatchCommand(Player player, Command command) {
if (Executor.CONSOLE.equals(command.getExecutor())) {
bukkitService.dispatchConsoleCommand(command.getCommand());
} else {
bukkitService.dispatchCommand(player, command.getCommand());
}
}
private static boolean shouldCommandBeRun(OnLoginCommand command, int numberOfOtherAccounts) {
return (!command.getIfNumberOfAccountsAtLeast().isPresent()
|| command.getIfNumberOfAccountsAtLeast().get() <= numberOfOtherAccounts)