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 * @param executor the executor of the command
*/ */
public Command(String command, Executor executor) { public Command(String command, Executor executor) {
this.command = command; this(command, executor, 0);
this.executor = executor;
} }
/** /**

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