mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-10-04 09:27:29 +02:00
Add support for delaying commands.
This commit is contained in:
parent
dfb2d72d28
commit
f7e9ac9685
@ -9,6 +9,8 @@ public class Command {
|
|||||||
private String command;
|
private String command;
|
||||||
/** The executor of the command. */
|
/** The executor of the command. */
|
||||||
private Executor executor = Executor.PLAYER;
|
private Executor executor = Executor.PLAYER;
|
||||||
|
/** Delay before executing the command (in ticks) */
|
||||||
|
private long delay = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor (for bean mapping).
|
* Default constructor (for bean mapping).
|
||||||
@ -27,6 +29,19 @@ public class Command {
|
|||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*
|
||||||
|
* @param command the command
|
||||||
|
* @param executor the executor of the command
|
||||||
|
* @param delay the delay (in ticks) before executing command
|
||||||
|
*/
|
||||||
|
public Command(String command, Executor executor, long delay) {
|
||||||
|
this.command = command;
|
||||||
|
this.executor = executor;
|
||||||
|
this.delay = delay;
|
||||||
|
}
|
||||||
|
|
||||||
public String getCommand() {
|
public String getCommand() {
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
@ -43,6 +58,14 @@ public class Command {
|
|||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getDelay() {
|
||||||
|
return delay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDelay(int delay) {
|
||||||
|
this.delay = delay;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return command + " (" + executor + ")";
|
return command + " (" + executor + ")";
|
||||||
|
@ -127,11 +127,13 @@ public class CommandManager implements Reloadable {
|
|||||||
for (T command : commands) {
|
for (T command : commands) {
|
||||||
if (predicate.test(command)) {
|
if (predicate.test(command)) {
|
||||||
final String execution = command.getCommand();
|
final String execution = command.getCommand();
|
||||||
if (Executor.CONSOLE.equals(command.getExecutor())) {
|
bukkitService.scheduleSyncDelayedTask(() -> {
|
||||||
bukkitService.dispatchConsoleCommand(execution);
|
if (Executor.CONSOLE.equals(command.getExecutor())) {
|
||||||
} else {
|
bukkitService.dispatchConsoleCommand(execution);
|
||||||
bukkitService.dispatchCommand(player, execution);
|
} else {
|
||||||
}
|
bukkitService.dispatchCommand(player, execution);
|
||||||
|
}
|
||||||
|
}, command.getDelay());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -175,9 +177,9 @@ public class CommandManager implements Reloadable {
|
|||||||
|
|
||||||
private List<Tag<Player>> buildAvailableTags() {
|
private List<Tag<Player>> buildAvailableTags() {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
createTag("%p", pl -> pl.getName()),
|
createTag("%p", Player::getName),
|
||||||
createTag("%nick", pl -> pl.getDisplayName()),
|
createTag("%nick", Player::getDisplayName),
|
||||||
createTag("%ip", pl -> PlayerUtils.getPlayerIp(pl)),
|
createTag("%ip", PlayerUtils::getPlayerIp),
|
||||||
createTag("%country", pl -> geoIpService.getCountryName(PlayerUtils.getPlayerIp(pl))));
|
createTag("%country", pl -> geoIpService.getCountryName(PlayerUtils.getPlayerIp(pl))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,13 @@ public final class CommandSettingsHolder implements SettingsHolder {
|
|||||||
" command: 'broadcast %p has joined, welcome back!'",
|
" command: 'broadcast %p has joined, welcome back!'",
|
||||||
" executor: CONSOLE",
|
" executor: CONSOLE",
|
||||||
"",
|
"",
|
||||||
|
"You can also add delay to command. It will run after the specified ticks. Example:",
|
||||||
|
"onLogin:",
|
||||||
|
" rules:",
|
||||||
|
" command: 'rules'",
|
||||||
|
" executor: PLAYER",
|
||||||
|
" delay: 200",
|
||||||
|
"",
|
||||||
"Supported command events: onLogin, onSessionLogin, onFirstLogin, onJoin, onLogout, onRegister, "
|
"Supported command events: onLogin, onSessionLogin, onFirstLogin, onJoin, onLogout, onRegister, "
|
||||||
+ "onUnregister",
|
+ "onUnregister",
|
||||||
"",
|
"",
|
||||||
|
Loading…
Reference in New Issue
Block a user