#1035 Forced commands: add more tests, rename account constraints, update commands.yml comments

This commit is contained in:
ljacqu
2018-01-16 20:32:17 +01:00
parent 3c0236e15e
commit f19f8502d8
7 changed files with 118 additions and 26 deletions
@@ -135,10 +135,10 @@ public class CommandManager implements Reloadable {
}
private static boolean shouldCommandBeRun(OnLoginCommand command, int numberOfOtherAccounts) {
return (!command.getNumberOfOtherAccountsAtLeast().isPresent()
|| command.getNumberOfOtherAccountsAtLeast().get() <= numberOfOtherAccounts)
&& (!command.getNumberOfOtherAccountsLessThan().isPresent()
|| command.getNumberOfOtherAccountsLessThan().get() >= numberOfOtherAccounts);
return (!command.getIfNumberOfAccountsAtLeast().isPresent()
|| command.getIfNumberOfAccountsAtLeast().get() <= numberOfOtherAccounts)
&& (!command.getIfNumberOfAccountsLessThan().isPresent()
|| command.getIfNumberOfAccountsLessThan().get() > numberOfOtherAccounts);
}
@Override
@@ -167,8 +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.getNumberOfOtherAccountsAtLeast(),
cmd.getNumberOfOtherAccountsLessThan()));
(cmd, text) -> new OnLoginCommand(text, cmd.getExecutor(), cmd.getIfNumberOfAccountsAtLeast(),
cmd.getIfNumberOfAccountsLessThan()));
}
private List<Tag<Player>> buildAvailableTags() {
@@ -49,8 +49,17 @@ public final class CommandSettingsHolder implements SettingsHolder {
" executor: CONSOLE",
"",
"Supported command events: onLogin, onSessionLogin, onFirstLogin, onJoin, onLogout, onRegister, "
+ "onUnregister"
+ "onUnregister",
"",
"For onLogin and onFirstLogin, you can use 'ifNumberOfAccountsLessThan' and 'ifNumberOfAccountsAtLeast'",
"to specify limits to how many accounts a player can have (matched by IP) for a command to be run:",
"onLogin:",
" warnOnManyAccounts:",
" command: 'say Uh oh! %p has many alt accounts!'",
" executor: CONSOLE",
" ifNumberOfAccountsAtLeast: 5"
};
Map<String, String[]> commentMap = new HashMap<>();
commentMap.put("", rootComments);
commentMap.put("onFirstLogin", new String[]{
@@ -7,8 +7,8 @@ import java.util.Optional;
*/
public class OnLoginCommand extends Command {
private Optional<Integer> numberOfOtherAccountsAtLeast;
private Optional<Integer> numberOfOtherAccountsLessThan;
private Optional<Integer> ifNumberOfAccountsAtLeast;
private Optional<Integer> ifNumberOfAccountsLessThan;
/**
* Default constructor (for bean mapping).
@@ -31,29 +31,29 @@ public class OnLoginCommand extends Command {
*
* @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
* @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> numberOfOtherAccountsAtLeast,
Optional<Integer> numberOfOtherAccountsLessThan) {
public OnLoginCommand(String command, Executor executor, Optional<Integer> ifNumberOfAccountsAtLeast,
Optional<Integer> ifNumberOfAccountsLessThan) {
super(command, executor);
this.numberOfOtherAccountsAtLeast = numberOfOtherAccountsAtLeast;
this.numberOfOtherAccountsLessThan = numberOfOtherAccountsLessThan;
this.ifNumberOfAccountsAtLeast = ifNumberOfAccountsAtLeast;
this.ifNumberOfAccountsLessThan = ifNumberOfAccountsLessThan;
}
public Optional<Integer> getNumberOfOtherAccountsAtLeast() {
return numberOfOtherAccountsAtLeast;
public Optional<Integer> getIfNumberOfAccountsAtLeast() {
return ifNumberOfAccountsAtLeast;
}
public void setNumberOfOtherAccountsAtLeast(Optional<Integer> numberOfOtherAccountsAtLeast) {
this.numberOfOtherAccountsAtLeast = numberOfOtherAccountsAtLeast;
public void setIfNumberOfAccountsAtLeast(Optional<Integer> ifNumberOfAccountsAtLeast) {
this.ifNumberOfAccountsAtLeast = ifNumberOfAccountsAtLeast;
}
public Optional<Integer> getNumberOfOtherAccountsLessThan() {
return numberOfOtherAccountsLessThan;
public Optional<Integer> getIfNumberOfAccountsLessThan() {
return ifNumberOfAccountsLessThan;
}
public void setNumberOfOtherAccountsLessThan(Optional<Integer> numberOfOtherAccountsLessThan) {
this.numberOfOtherAccountsLessThan = numberOfOtherAccountsLessThan;
public void setIfNumberOfAccountsLessThan(Optional<Integer> ifNumberOfAccountsLessThan) {
this.ifNumberOfAccountsLessThan = ifNumberOfAccountsLessThan;
}
}