mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-02-20 14:01:46 +01: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
|
// Session logic
|
||||||
if (canResumeSession(player)) {
|
if (canResumeSession(player)) {
|
||||||
service.send(player, MessageKey.SESSION_RECONNECTION);
|
service.send(player, MessageKey.SESSION_RECONNECTION);
|
||||||
|
// Run commands
|
||||||
|
bukkitService.scheduleSyncTaskFromOptionallyAsyncTask(() -> commandManager.runCommandsOnSessionLogin(player));
|
||||||
bukkitService.runTaskOptionallyAsync(() -> asynchronousLogin.forceLogin(player));
|
bukkitService.runTaskOptionallyAsync(() -> asynchronousLogin.forceLogin(player));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ public class CommandConfig {
|
|||||||
|
|
||||||
private Map<String, Command> onJoin = new LinkedHashMap<>();
|
private Map<String, Command> onJoin = new LinkedHashMap<>();
|
||||||
private Map<String, Command> onLogin = 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> onRegister = new LinkedHashMap<>();
|
||||||
private Map<String, Command> onUnregister = new LinkedHashMap<>();
|
private Map<String, Command> onUnregister = new LinkedHashMap<>();
|
||||||
|
|
||||||
@ -31,6 +32,14 @@ public class CommandConfig {
|
|||||||
this.onLogin = onLogin;
|
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() {
|
public Map<String, Command> getOnRegister() {
|
||||||
return onRegister;
|
return onRegister;
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ public class CommandManager implements Reloadable {
|
|||||||
|
|
||||||
private WrappedTagReplacer<Command, Player> onJoinCommands;
|
private WrappedTagReplacer<Command, Player> onJoinCommands;
|
||||||
private WrappedTagReplacer<Command, Player> onLoginCommands;
|
private WrappedTagReplacer<Command, Player> onLoginCommands;
|
||||||
|
private WrappedTagReplacer<Command, Player> onSessionLoginCommands;
|
||||||
private WrappedTagReplacer<Command, Player> onRegisterCommands;
|
private WrappedTagReplacer<Command, Player> onRegisterCommands;
|
||||||
private WrappedTagReplacer<Command, Player> onUnregisterCommands;
|
private WrappedTagReplacer<Command, Player> onUnregisterCommands;
|
||||||
|
|
||||||
@ -73,6 +74,16 @@ public class CommandManager implements Reloadable {
|
|||||||
executeCommands(player, onLoginCommands.getAdaptedItems(player));
|
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.
|
* 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);
|
CommandConfig commandConfig = settingsManager.getProperty(CommandSettingsHolder.COMMANDS);
|
||||||
onJoinCommands = newReplacer(commandConfig.getOnJoin());
|
onJoinCommands = newReplacer(commandConfig.getOnJoin());
|
||||||
onLoginCommands = newReplacer(commandConfig.getOnLogin());
|
onLoginCommands = newReplacer(commandConfig.getOnLogin());
|
||||||
|
onSessionLoginCommands = newReplacer(commandConfig.getOnSessionLogin());
|
||||||
onRegisterCommands = newReplacer(commandConfig.getOnRegister());
|
onRegisterCommands = newReplacer(commandConfig.getOnRegister());
|
||||||
onUnregisterCommands = newReplacer(commandConfig.getOnUnregister());
|
onUnregisterCommands = newReplacer(commandConfig.getOnUnregister());
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,7 @@ public final class CommandSettingsHolder implements SettingsHolder {
|
|||||||
" command: 'broadcast %p has joined, welcome back!'",
|
" command: 'broadcast %p has joined, welcome back!'",
|
||||||
" executor: CONSOLE",
|
" executor: CONSOLE",
|
||||||
"",
|
"",
|
||||||
"Supported command events: onLogin, onJoin, onRegister, onUnregister"
|
"Supported command events: onLogin, onSessionLogin, onJoin, onRegister, onUnregister"
|
||||||
};
|
};
|
||||||
Map<String, String[]> commentMap = new HashMap<>();
|
Map<String, String[]> commentMap = new HashMap<>();
|
||||||
commentMap.put("", comments);
|
commentMap.put("", comments);
|
||||||
|
@ -24,9 +24,10 @@
|
|||||||
# command: 'broadcast %p has joined, welcome back!'
|
# command: 'broadcast %p has joined, welcome back!'
|
||||||
# executor: CONSOLE
|
# executor: CONSOLE
|
||||||
#
|
#
|
||||||
# Supported command events: onLogin, onJoin, onRegister, onUnregister
|
# Supported command events: onLogin, onSessionLogin, onJoin, onRegister, onUnregister
|
||||||
onJoin: {}
|
onJoin: {}
|
||||||
onLogin: {}
|
onLogin: {}
|
||||||
|
onSessionLogin: {}
|
||||||
onRegister: {}
|
onRegister: {}
|
||||||
# Commands to run whenever a player is unregistered (by himself, or by an admin)
|
# 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);
|
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
|
@Test
|
||||||
public void shouldExecuteCommandsOnJoin() {
|
public void shouldExecuteCommandsOnJoin() {
|
||||||
// given
|
// given
|
||||||
|
@ -21,3 +21,7 @@ onLogin:
|
|||||||
display_list:
|
display_list:
|
||||||
command: 'list'
|
command: 'list'
|
||||||
executor: PLAYER
|
executor: PLAYER
|
||||||
|
onSessionLogin:
|
||||||
|
welcome:
|
||||||
|
command: 'msg %p Session login!'
|
||||||
|
executor: CONSOLE
|
||||||
|
Loading…
Reference in New Issue
Block a user