#1035 Fix handling of new login command constraints

- Incorporate ConfigMe fix
- Various fixes in the integration
This commit is contained in:
ljacqu 2018-01-15 22:39:29 +01:00
parent 8dbba1dc93
commit 3c0236e15e
4 changed files with 20 additions and 5 deletions

View File

@ -709,7 +709,7 @@
<dependency>
<groupId>ch.jalu</groupId>
<artifactId>configme</artifactId>
<version>0.4</version>
<version>0.4.1</version>
<scope>compile</scope>
<optional>true</optional>
<exclusions>

View File

@ -136,9 +136,9 @@ public class CommandManager implements Reloadable {
private static boolean shouldCommandBeRun(OnLoginCommand command, int numberOfOtherAccounts) {
return (!command.getNumberOfOtherAccountsAtLeast().isPresent()
|| command.getNumberOfOtherAccountsAtLeast().get() >= numberOfOtherAccounts)
|| command.getNumberOfOtherAccountsAtLeast().get() <= numberOfOtherAccounts)
&& (!command.getNumberOfOtherAccountsLessThan().isPresent()
|| command.getNumberOfOtherAccountsLessThan().get() <= numberOfOtherAccounts);
|| command.getNumberOfOtherAccountsLessThan().get() >= numberOfOtherAccounts);
}
@Override
@ -167,7 +167,8 @@ public class CommandManager implements Reloadable {
Map<String, OnLoginCommand> commands) {
return new WrappedTagReplacer<>(availableTags, commands.values(), Command::getCommand,
(cmd, text) -> new OnLoginCommand(text, cmd.getExecutor()));
(cmd, text) -> new OnLoginCommand(text, cmd.getExecutor(), cmd.getNumberOfOtherAccountsAtLeast(),
cmd.getNumberOfOtherAccountsLessThan()));
}
private List<Tag<Player>> buildAvailableTags() {

View File

@ -26,6 +26,21 @@ public class OnLoginCommand extends Command {
super(command, executor);
}
/**
* Constructor.
*
* @param command the command to execute
* @param executor the executor of the command
* @param numberOfOtherAccountsAtLeast required number of accounts for the command to run
* @param numberOfOtherAccountsLessThan max threshold of accounts, from which the command will not be run
*/
public OnLoginCommand(String command, Executor executor, Optional<Integer> numberOfOtherAccountsAtLeast,
Optional<Integer> numberOfOtherAccountsLessThan) {
super(command, executor);
this.numberOfOtherAccountsAtLeast = numberOfOtherAccountsAtLeast;
this.numberOfOtherAccountsLessThan = numberOfOtherAccountsLessThan;
}
public Optional<Integer> getNumberOfOtherAccountsAtLeast() {
return numberOfOtherAccountsAtLeast;
}

View File

@ -31,7 +31,6 @@ import static org.mockito.Mockito.verifyZeroInteractions;
/**
* Test for {@link CommandManager}.
*/
// TODO #1035: Tests currently fail because ConfigMe can't handle Optional fields
@RunWith(MockitoJUnitRunner.class)
public class CommandManagerTest {