#1449 Fix copying of Commands, add tests with command delay
This commit is contained in:
@@ -19,26 +19,21 @@ public class Command {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Creates a copy of this Command object, setting the given command text on the copy.
|
||||
*
|
||||
* @param command the command
|
||||
* @param executor the executor of the command
|
||||
* @param command the command text to use in the copy
|
||||
* @return copy of the source with the new command
|
||||
*/
|
||||
public Command(String command, Executor executor) {
|
||||
this(command, executor, 0);
|
||||
public Command copyWithCommand(String command) {
|
||||
Command copy = new Command();
|
||||
setValuesToCopyWithNewCommand(copy, command);
|
||||
return copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
protected void setValuesToCopyWithNewCommand(Command copy, String newCommand) {
|
||||
copy.command = newCommand;
|
||||
copy.executor = this.executor;
|
||||
copy.delay = this.delay;
|
||||
}
|
||||
|
||||
public String getCommand() {
|
||||
|
||||
@@ -174,15 +174,12 @@ public class CommandManager implements Reloadable {
|
||||
|
||||
private WrappedTagReplacer<Command, Player> newReplacer(Map<String, Command> commands) {
|
||||
return new WrappedTagReplacer<>(availableTags, commands.values(), Command::getCommand,
|
||||
(cmd, text) -> new Command(text, cmd.getExecutor()));
|
||||
Command::copyWithCommand);
|
||||
}
|
||||
|
||||
private WrappedTagReplacer<OnLoginCommand, Player> newOnLoginCmdReplacer(
|
||||
Map<String, OnLoginCommand> commands) {
|
||||
|
||||
private WrappedTagReplacer<OnLoginCommand, Player> newOnLoginCmdReplacer(Map<String, OnLoginCommand> commands) {
|
||||
return new WrappedTagReplacer<>(availableTags, commands.values(), Command::getCommand,
|
||||
(cmd, text) -> new OnLoginCommand(text, cmd.getExecutor(), cmd.getIfNumberOfAccountsAtLeast(),
|
||||
cmd.getIfNumberOfAccountsLessThan()));
|
||||
OnLoginCommand::copyWithCommand);
|
||||
}
|
||||
|
||||
private List<Tag<Player>> buildAvailableTags() {
|
||||
|
||||
@@ -41,8 +41,9 @@ class CommandMigrationService implements MigrationService {
|
||||
|
||||
private boolean moveOtherAccountsConfig(CommandConfig commandConfig) {
|
||||
if (settingsMigrationService.hasOldOtherAccountsCommand()) {
|
||||
OnLoginCommand command = new OnLoginCommand(
|
||||
replaceOldPlaceholdersWithNew(settingsMigrationService.getOldOtherAccountsCommand()), Executor.CONSOLE);
|
||||
OnLoginCommand command = new OnLoginCommand();
|
||||
command.setCommand(replaceOldPlaceholdersWithNew(settingsMigrationService.getOldOtherAccountsCommand()));
|
||||
command.setExecutor(Executor.CONSOLE);
|
||||
command.setIfNumberOfAccountsAtLeast(
|
||||
Optional.of(settingsMigrationService.getOldOtherAccountsCommandThreshold()));
|
||||
|
||||
|
||||
@@ -17,28 +17,18 @@ public class OnLoginCommand extends Command {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Creates a copy of this object, using the given command as new {@link Command#command command}.
|
||||
*
|
||||
* @param command the command to execute
|
||||
* @param executor the executor of the command
|
||||
* @param command the command text to use in the copy
|
||||
* @return copy of the source with the new command
|
||||
*/
|
||||
public OnLoginCommand(String command, Executor executor) {
|
||||
super(command, executor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param command the command to execute
|
||||
* @param executor the executor of the command
|
||||
* @param ifNumberOfAccountsAtLeast required number of accounts for the command to run
|
||||
* @param ifNumberOfAccountsLessThan max threshold of accounts, from which the command will not be run
|
||||
*/
|
||||
public OnLoginCommand(String command, Executor executor, Optional<Integer> ifNumberOfAccountsAtLeast,
|
||||
Optional<Integer> ifNumberOfAccountsLessThan) {
|
||||
super(command, executor);
|
||||
this.ifNumberOfAccountsAtLeast = ifNumberOfAccountsAtLeast;
|
||||
this.ifNumberOfAccountsLessThan = ifNumberOfAccountsLessThan;
|
||||
@Override
|
||||
public OnLoginCommand copyWithCommand(String command) {
|
||||
OnLoginCommand copy = new OnLoginCommand();
|
||||
setValuesToCopyWithNewCommand(copy, command);
|
||||
copy.ifNumberOfAccountsAtLeast = this.ifNumberOfAccountsAtLeast;
|
||||
copy.ifNumberOfAccountsLessThan = this.ifNumberOfAccountsLessThan;
|
||||
return copy;
|
||||
}
|
||||
|
||||
public Optional<Integer> getIfNumberOfAccountsAtLeast() {
|
||||
|
||||
Reference in New Issue
Block a user