mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-09-07 12:48:03 +02:00
Implement onSessionLogin trigger for commands.yml (#1198)
* Implement onSessionLogin trigger for commands.yml Needs test methods, @ljacqu any advice? * Add simple onSessionLogin test
This commit is contained in:
parent
4366e33508
commit
cff8ccd76a
@ -123,6 +123,8 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
||||
// Session logic
|
||||
if (canResumeSession(player)) {
|
||||
service.send(player, MessageKey.SESSION_RECONNECTION);
|
||||
// Run commands
|
||||
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> commandManager.runCommandsOnSessionLogin(player));
|
||||
bukkitService.runTaskOptionallyAsync(() -> asynchronousLogin.forceLogin(player));
|
||||
return;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ public class CommandConfig {
|
||||
|
||||
private Map<String, Command> onJoin = new LinkedHashMap<>();
|
||||
private Map<String, Command> onLogin = new LinkedHashMap<>();
|
||||
private Map<String, Command> onSessionLogin = new LinkedHashMap<>();
|
||||
private Map<String, Command> onRegister = new LinkedHashMap<>();
|
||||
private Map<String, Command> onUnregister = new LinkedHashMap<>();
|
||||
|
||||
@ -31,6 +32,14 @@ public class CommandConfig {
|
||||
this.onLogin = onLogin;
|
||||
}
|
||||
|
||||
public Map<String, Command> getOnSessionLogin() {
|
||||
return onSessionLogin;
|
||||
}
|
||||
|
||||
public void setOnSessionLogin(Map<String, Command> onSessionLogin) {
|
||||
this.onSessionLogin = onSessionLogin;
|
||||
}
|
||||
|
||||
public Map<String, Command> getOnRegister() {
|
||||
return onRegister;
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ public class CommandManager implements Reloadable {
|
||||
|
||||
private WrappedTagReplacer<Command, Player> onJoinCommands;
|
||||
private WrappedTagReplacer<Command, Player> onLoginCommands;
|
||||
private WrappedTagReplacer<Command, Player> onSessionLoginCommands;
|
||||
private WrappedTagReplacer<Command, Player> onRegisterCommands;
|
||||
private WrappedTagReplacer<Command, Player> onUnregisterCommands;
|
||||
|
||||
@ -73,6 +74,16 @@ public class CommandManager implements Reloadable {
|
||||
executeCommands(player, onLoginCommands.getAdaptedItems(player));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Runs the configured commands for when a player has logged in successfully due to session.
|
||||
*
|
||||
* @param player the player that logged in
|
||||
*/
|
||||
public void runCommandsOnSessionLogin(Player player) {
|
||||
executeCommands(player, onSessionLoginCommands.getAdaptedItems(player));
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the configured commands for when a player has been unregistered.
|
||||
*
|
||||
@ -103,6 +114,7 @@ public class CommandManager implements Reloadable {
|
||||
CommandConfig commandConfig = settingsManager.getProperty(CommandSettingsHolder.COMMANDS);
|
||||
onJoinCommands = newReplacer(commandConfig.getOnJoin());
|
||||
onLoginCommands = newReplacer(commandConfig.getOnLogin());
|
||||
onSessionLoginCommands = newReplacer(commandConfig.getOnSessionLogin());
|
||||
onRegisterCommands = newReplacer(commandConfig.getOnRegister());
|
||||
onUnregisterCommands = newReplacer(commandConfig.getOnUnregister());
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public final class CommandSettingsHolder implements SettingsHolder {
|
||||
" command: 'broadcast %p has joined, welcome back!'",
|
||||
" executor: CONSOLE",
|
||||
"",
|
||||
"Supported command events: onLogin, onJoin, onRegister, onUnregister"
|
||||
"Supported command events: onLogin, onSessionLogin, onJoin, onRegister, onUnregister"
|
||||
};
|
||||
Map<String, String[]> commentMap = new HashMap<>();
|
||||
commentMap.put("", comments);
|
||||
|
@ -24,9 +24,10 @@
|
||||
# command: 'broadcast %p has joined, welcome back!'
|
||||
# executor: CONSOLE
|
||||
#
|
||||
# Supported command events: onLogin, onJoin, onRegister, onUnregister
|
||||
# Supported command events: onLogin, onSessionLogin, onJoin, onRegister, onUnregister
|
||||
onJoin: {}
|
||||
onLogin: {}
|
||||
onSessionLogin: {}
|
||||
onRegister: {}
|
||||
# Commands to run whenever a player is unregistered (by himself, or by an admin)
|
||||
onUnregister: {}
|
||||
onUnregister: {}
|
||||
|
@ -92,6 +92,21 @@ public class CommandManagerTest {
|
||||
verifyZeroInteractions(geoIpService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCommandsOnSessionLogin() {
|
||||
// given
|
||||
copyJarFileAsCommandsYml(TEST_FILES_FOLDER + "commands.complete.yml");
|
||||
initManager();
|
||||
|
||||
// when
|
||||
manager.runCommandsOnSessionLogin(player);
|
||||
|
||||
// then
|
||||
verify(bukkitService).dispatchConsoleCommand("msg Bobby Session login!");
|
||||
verifyNoMoreInteractions(bukkitService);
|
||||
verifyZeroInteractions(geoIpService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldExecuteCommandsOnJoin() {
|
||||
// given
|
||||
|
@ -21,3 +21,7 @@ onLogin:
|
||||
display_list:
|
||||
command: 'list'
|
||||
executor: PLAYER
|
||||
onSessionLogin:
|
||||
welcome:
|
||||
command: 'msg %p Session login!'
|
||||
executor: CONSOLE
|
||||
|
Loading…
Reference in New Issue
Block a user