mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-29 21:53:56 +01:00
#761 Restore permission group in sync with limbo players
- Couple AuthGroupHandler closer to the LimboService: whenever a limbo player is restored, the auth group should be restored as well. This fixes some consistency issues. - Move AuthGroupHandler into limbo package and make it package-private - Change permission handler to skip any empty groups (prevents odd command output e.g. for BukkitPermissions)
This commit is contained in:
parent
d4c1370da6
commit
e0e4cd112d
@ -1,16 +1,14 @@
|
|||||||
package fr.xephi.authme.permission;
|
package fr.xephi.authme.data.limbo;
|
||||||
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.data.limbo.LimboPlayer;
|
|
||||||
import fr.xephi.authme.data.limbo.LimboService;
|
|
||||||
import fr.xephi.authme.initialization.Reloadable;
|
import fr.xephi.authme.initialization.Reloadable;
|
||||||
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes the permission group according to the auth status of the player and the configuration.
|
* Changes the permission group according to the auth status of the player and the configuration.
|
||||||
@ -24,7 +22,7 @@ import java.util.Optional;
|
|||||||
* exist for the replacement to take place. Furthermore, since some permission groups require that players
|
* exist for the replacement to take place. Furthermore, since some permission groups require that players
|
||||||
* be in at least one group, this will mean that the player is not removed from his primary group.
|
* be in at least one group, this will mean that the player is not removed from his primary group.
|
||||||
*/
|
*/
|
||||||
public class AuthGroupHandler implements Reloadable {
|
class AuthGroupHandler implements Reloadable {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PermissionsManager permissionsManager;
|
private PermissionsManager permissionsManager;
|
||||||
@ -32,9 +30,6 @@ public class AuthGroupHandler implements Reloadable {
|
|||||||
@Inject
|
@Inject
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private LimboService limboService;
|
|
||||||
|
|
||||||
private String unregisteredGroup;
|
private String unregisteredGroup;
|
||||||
private String registeredGroup;
|
private String registeredGroup;
|
||||||
|
|
||||||
@ -45,17 +40,15 @@ public class AuthGroupHandler implements Reloadable {
|
|||||||
* Sets the group of a player by its authentication status.
|
* Sets the group of a player by its authentication status.
|
||||||
*
|
*
|
||||||
* @param player the player
|
* @param player the player
|
||||||
|
* @param limbo the associated limbo player (nullable)
|
||||||
* @param groupType the group type
|
* @param groupType the group type
|
||||||
*/
|
*/
|
||||||
public void setGroup(Player player, AuthGroupType groupType) {
|
void setGroup(Player player, LimboPlayer limbo, AuthGroupType groupType) {
|
||||||
if (!useAuthGroups()) {
|
if (!useAuthGroups()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String primaryGroup = Optional
|
String primaryGroup = limbo == null ? "" : limbo.getGroup();
|
||||||
.ofNullable(limboService.getLimboPlayer(player.getName()))
|
|
||||||
.map(LimboPlayer::getGroup)
|
|
||||||
.orElse("");
|
|
||||||
|
|
||||||
switch (groupType) {
|
switch (groupType) {
|
||||||
// Implementation note: some permission systems don't support players not being in any group,
|
// Implementation note: some permission systems don't support players not being in any group,
|
@ -1,9 +1,9 @@
|
|||||||
package fr.xephi.authme.permission;
|
package fr.xephi.authme.data.limbo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the group type based on the user's auth status.
|
* Represents the group type based on the user's auth status.
|
||||||
*/
|
*/
|
||||||
public enum AuthGroupType {
|
enum AuthGroupType {
|
||||||
|
|
||||||
/** Player does not have an account. */
|
/** Player does not have an account. */
|
||||||
UNREGISTERED,
|
UNREGISTERED,
|
@ -34,6 +34,9 @@ public class LimboService {
|
|||||||
@Inject
|
@Inject
|
||||||
private LimboPersistence persistence;
|
private LimboPersistence persistence;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private AuthGroupHandler authGroupHandler;
|
||||||
|
|
||||||
LimboService() {
|
LimboService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,6 +66,8 @@ public class LimboService {
|
|||||||
taskManager.registerMessageTask(player, limboPlayer, isRegistered);
|
taskManager.registerMessageTask(player, limboPlayer, isRegistered);
|
||||||
taskManager.registerTimeoutTask(player, limboPlayer);
|
taskManager.registerTimeoutTask(player, limboPlayer);
|
||||||
helper.revokeLimboStates(player);
|
helper.revokeLimboStates(player);
|
||||||
|
authGroupHandler.setGroup(player, limboPlayer,
|
||||||
|
isRegistered ? AuthGroupType.REGISTERED_UNAUTHENTICATED : AuthGroupType.UNREGISTERED);
|
||||||
entries.put(name, limboPlayer);
|
entries.put(name, limboPlayer);
|
||||||
persistence.saveLimboPlayer(player, limboPlayer);
|
persistence.saveLimboPlayer(player, limboPlayer);
|
||||||
}
|
}
|
||||||
@ -91,7 +96,7 @@ public class LimboService {
|
|||||||
* Restores the limbo data and subsequently deletes the entry.
|
* Restores the limbo data and subsequently deletes the entry.
|
||||||
* <p>
|
* <p>
|
||||||
* Note that teleportation on the player is performed by {@link fr.xephi.authme.service.TeleportationService} and
|
* Note that teleportation on the player is performed by {@link fr.xephi.authme.service.TeleportationService} and
|
||||||
* changing the permission group is handled by {@link fr.xephi.authme.permission.AuthGroupHandler}.
|
* changing the permission group is handled by {@link fr.xephi.authme.data.limbo.AuthGroupHandler}.
|
||||||
*
|
*
|
||||||
* @param player the player whose data should be restored
|
* @param player the player whose data should be restored
|
||||||
*/
|
*/
|
||||||
@ -110,6 +115,7 @@ public class LimboService {
|
|||||||
ConsoleLogger.debug("Restored LimboPlayer stats for `{0}`", lowerName);
|
ConsoleLogger.debug("Restored LimboPlayer stats for `{0}`", lowerName);
|
||||||
persistence.removeLimboPlayer(player);
|
persistence.removeLimboPlayer(player);
|
||||||
}
|
}
|
||||||
|
authGroupHandler.setGroup(player, limbo, AuthGroupType.LOGGED_IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -119,11 +125,12 @@ public class LimboService {
|
|||||||
* @param player the player to reset the tasks for
|
* @param player the player to reset the tasks for
|
||||||
*/
|
*/
|
||||||
public void replaceTasksAfterRegistration(Player player) {
|
public void replaceTasksAfterRegistration(Player player) {
|
||||||
getLimboOrLogError(player, "reset tasks")
|
Optional<LimboPlayer> limboPlayer = getLimboOrLogError(player, "reset tasks");
|
||||||
.ifPresent(limbo -> {
|
limboPlayer.ifPresent(limbo -> {
|
||||||
taskManager.registerTimeoutTask(player, limbo);
|
taskManager.registerTimeoutTask(player, limbo);
|
||||||
taskManager.registerMessageTask(player, limbo, true);
|
taskManager.registerMessageTask(player, limbo, true);
|
||||||
});
|
});
|
||||||
|
authGroupHandler.setGroup(player, limboPlayer.orElse(null), AuthGroupType.REGISTERED_UNAUTHENTICATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -49,7 +49,7 @@ class LimboServiceHelper {
|
|||||||
* Removes the data that is saved in a LimboPlayer from the player.
|
* Removes the data that is saved in a LimboPlayer from the player.
|
||||||
* <p>
|
* <p>
|
||||||
* Note that teleportation on the player is performed by {@link fr.xephi.authme.service.TeleportationService} and
|
* Note that teleportation on the player is performed by {@link fr.xephi.authme.service.TeleportationService} and
|
||||||
* changing the permission group is handled by {@link fr.xephi.authme.permission.AuthGroupHandler}.
|
* changing the permission group is handled by {@link fr.xephi.authme.data.limbo.AuthGroupHandler}.
|
||||||
*
|
*
|
||||||
* @param player the player to set defaults to
|
* @param player the player to set defaults to
|
||||||
*/
|
*/
|
||||||
|
@ -342,19 +342,20 @@ public class PermissionsManager implements Reloadable {
|
|||||||
* @param player The player
|
* @param player The player
|
||||||
* @param groupNames The name of the groups to add.
|
* @param groupNames The name of the groups to add.
|
||||||
*
|
*
|
||||||
* @return True if succeed, false otherwise.
|
* @return True if at least one group was removed, false otherwise.
|
||||||
* False is also returned if this feature isn't supported for the current permissions system.
|
* False is also returned if this feature isn't supported for the current permissions system.
|
||||||
*/
|
*/
|
||||||
public boolean removeGroups(Player player, String... groupNames) {
|
public boolean removeGroups(Player player, String... groupNames) {
|
||||||
// If no permissions system is used, return false
|
// If no permissions system is used, return false
|
||||||
if (!isEnabled())
|
if (!isEnabled()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Add each group to the user
|
// Add each group to the user
|
||||||
boolean result = true;
|
boolean result = false;
|
||||||
for (String groupName : groupNames) {
|
for (String groupName : groupNames) {
|
||||||
if (!handler.removeFromGroup(player, groupName)) {
|
if (!groupName.isEmpty()) {
|
||||||
result = false;
|
result |= handler.removeFromGroup(player, groupName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ import fr.xephi.authme.datasource.DataSource;
|
|||||||
import fr.xephi.authme.events.ProtectInventoryEvent;
|
import fr.xephi.authme.events.ProtectInventoryEvent;
|
||||||
import fr.xephi.authme.events.RestoreSessionEvent;
|
import fr.xephi.authme.events.RestoreSessionEvent;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.permission.AuthGroupType;
|
|
||||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
import fr.xephi.authme.permission.PlayerStatePermission;
|
||||||
import fr.xephi.authme.process.AsynchronousProcess;
|
import fr.xephi.authme.process.AsynchronousProcess;
|
||||||
import fr.xephi.authme.process.login.AsynchronousLogin;
|
import fr.xephi.authme.process.login.AsynchronousLogin;
|
||||||
@ -111,8 +110,6 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
final boolean isAuthAvailable = database.isAuthAvailable(name);
|
final boolean isAuthAvailable = database.isAuthAvailable(name);
|
||||||
|
|
||||||
if (isAuthAvailable) {
|
if (isAuthAvailable) {
|
||||||
service.setGroup(player, AuthGroupType.REGISTERED_UNAUTHENTICATED);
|
|
||||||
|
|
||||||
// Protect inventory
|
// Protect inventory
|
||||||
if (service.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
|
if (service.getProperty(PROTECT_INVENTORY_BEFORE_LOGIN)) {
|
||||||
ProtectInventoryEvent ev = bukkitService.createAndCallEvent(
|
ProtectInventoryEvent ev = bukkitService.createAndCallEvent(
|
||||||
@ -129,15 +126,10 @@ public class AsynchronousJoin implements AsynchronousProcess {
|
|||||||
bukkitService.runTaskOptionallyAsync(() -> asynchronousLogin.forceLogin(player));
|
bukkitService.runTaskOptionallyAsync(() -> asynchronousLogin.forceLogin(player));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else if (!service.getProperty(RegistrationSettings.FORCE)) {
|
||||||
// Groups logic
|
|
||||||
service.setGroup(player, AuthGroupType.UNREGISTERED);
|
|
||||||
|
|
||||||
// Skip if registration is optional
|
// Skip if registration is optional
|
||||||
if (!service.getProperty(RegistrationSettings.FORCE)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
final int registrationTimeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
final int registrationTimeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
|
||||||
|
|
||||||
|
@ -6,8 +6,6 @@ import fr.xephi.authme.data.limbo.LimboService;
|
|||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.events.LoginEvent;
|
import fr.xephi.authme.events.LoginEvent;
|
||||||
import fr.xephi.authme.events.RestoreInventoryEvent;
|
import fr.xephi.authme.events.RestoreInventoryEvent;
|
||||||
import fr.xephi.authme.listener.PlayerListener;
|
|
||||||
import fr.xephi.authme.permission.AuthGroupType;
|
|
||||||
import fr.xephi.authme.process.SynchronousProcess;
|
import fr.xephi.authme.process.SynchronousProcess;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.service.BungeeService;
|
import fr.xephi.authme.service.BungeeService;
|
||||||
@ -17,7 +15,6 @@ import fr.xephi.authme.service.TeleportationService;
|
|||||||
import fr.xephi.authme.settings.WelcomeMessageConfiguration;
|
import fr.xephi.authme.settings.WelcomeMessageConfiguration;
|
||||||
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
import fr.xephi.authme.settings.commandconfig.CommandManager;
|
||||||
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
import fr.xephi.authme.settings.properties.RegistrationSettings;
|
||||||
import fr.xephi.authme.util.StringUtils;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.potion.PotionEffectType;
|
import org.bukkit.potion.PotionEffectType;
|
||||||
|
|
||||||
@ -68,9 +65,8 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
|
|||||||
|
|
||||||
public void processPlayerLogin(Player player) {
|
public void processPlayerLogin(Player player) {
|
||||||
final String name = player.getName().toLowerCase();
|
final String name = player.getName().toLowerCase();
|
||||||
|
|
||||||
commonService.setGroup(player, AuthGroupType.LOGGED_IN);
|
|
||||||
final LimboPlayer limbo = limboService.getLimboPlayer(name);
|
final LimboPlayer limbo = limboService.getLimboPlayer(name);
|
||||||
|
|
||||||
// Limbo contains the State of the Player before /login
|
// Limbo contains the State of the Player before /login
|
||||||
if (limbo != null) {
|
if (limbo != null) {
|
||||||
limboService.restoreData(player);
|
limboService.restoreData(player);
|
||||||
|
@ -6,7 +6,6 @@ import fr.xephi.authme.data.limbo.LimboService;
|
|||||||
import fr.xephi.authme.events.LogoutEvent;
|
import fr.xephi.authme.events.LogoutEvent;
|
||||||
import fr.xephi.authme.listener.protocollib.ProtocolLibService;
|
import fr.xephi.authme.listener.protocollib.ProtocolLibService;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.permission.AuthGroupType;
|
|
||||||
import fr.xephi.authme.process.SynchronousProcess;
|
import fr.xephi.authme.process.SynchronousProcess;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
@ -75,7 +74,6 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
|
|||||||
|
|
||||||
// Set player's data to unauthenticated
|
// Set player's data to unauthenticated
|
||||||
limboService.createLimboPlayer(player, true);
|
limboService.createLimboPlayer(player, true);
|
||||||
service.setGroup(player, AuthGroupType.REGISTERED_UNAUTHENTICATED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package fr.xephi.authme.process.register;
|
|||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.data.limbo.LimboService;
|
import fr.xephi.authme.data.limbo.LimboService;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.permission.AuthGroupType;
|
|
||||||
import fr.xephi.authme.process.SynchronousProcess;
|
import fr.xephi.authme.process.SynchronousProcess;
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
import fr.xephi.authme.util.PlayerUtils;
|
import fr.xephi.authme.util.PlayerUtils;
|
||||||
@ -24,9 +23,7 @@ public class ProcessSyncEmailRegister implements SynchronousProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void processEmailRegister(Player player) {
|
public void processEmailRegister(Player player) {
|
||||||
service.setGroup(player, AuthGroupType.REGISTERED_UNAUTHENTICATED);
|
|
||||||
service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
|
service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
|
||||||
|
|
||||||
limboService.replaceTasksAfterRegistration(player);
|
limboService.replaceTasksAfterRegistration(player);
|
||||||
|
|
||||||
player.saveData();
|
player.saveData();
|
||||||
|
@ -3,7 +3,6 @@ package fr.xephi.authme.process.register;
|
|||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.data.limbo.LimboService;
|
import fr.xephi.authme.data.limbo.LimboService;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.permission.AuthGroupType;
|
|
||||||
import fr.xephi.authme.process.SynchronousProcess;
|
import fr.xephi.authme.process.SynchronousProcess;
|
||||||
import fr.xephi.authme.service.BungeeService;
|
import fr.xephi.authme.service.BungeeService;
|
||||||
import fr.xephi.authme.service.CommonService;
|
import fr.xephi.authme.service.CommonService;
|
||||||
@ -48,7 +47,6 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void processPasswordRegister(Player player) {
|
public void processPasswordRegister(Player player) {
|
||||||
service.setGroup(player, AuthGroupType.REGISTERED_UNAUTHENTICATED);
|
|
||||||
service.send(player, MessageKey.REGISTER_SUCCESS);
|
service.send(player, MessageKey.REGISTER_SUCCESS);
|
||||||
|
|
||||||
if (!service.getProperty(EmailSettings.MAIL_ACCOUNT).isEmpty()) {
|
if (!service.getProperty(EmailSettings.MAIL_ACCOUNT).isEmpty()) {
|
||||||
|
@ -8,8 +8,6 @@ import fr.xephi.authme.datasource.DataSource;
|
|||||||
import fr.xephi.authme.events.UnregisterByAdminEvent;
|
import fr.xephi.authme.events.UnregisterByAdminEvent;
|
||||||
import fr.xephi.authme.events.UnregisterByPlayerEvent;
|
import fr.xephi.authme.events.UnregisterByPlayerEvent;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.permission.AuthGroupHandler;
|
|
||||||
import fr.xephi.authme.permission.AuthGroupType;
|
|
||||||
import fr.xephi.authme.process.AsynchronousProcess;
|
import fr.xephi.authme.process.AsynchronousProcess;
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
@ -50,9 +48,6 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private TeleportationService teleportationService;
|
private TeleportationService teleportationService;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private AuthGroupHandler authGroupHandler;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private CommandManager commandManager;
|
private CommandManager commandManager;
|
||||||
|
|
||||||
@ -123,7 +118,6 @@ public class AsynchronousUnregister implements AsynchronousProcess {
|
|||||||
applyBlindEffect(player);
|
applyBlindEffect(player);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
authGroupHandler.setGroup(player, AuthGroupType.UNREGISTERED);
|
|
||||||
service.send(player, MessageKey.UNREGISTERED_SUCCESS);
|
service.send(player, MessageKey.UNREGISTERED_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,8 +3,6 @@ package fr.xephi.authme.service;
|
|||||||
import ch.jalu.configme.properties.Property;
|
import ch.jalu.configme.properties.Property;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.message.Messages;
|
import fr.xephi.authme.message.Messages;
|
||||||
import fr.xephi.authme.permission.AuthGroupHandler;
|
|
||||||
import fr.xephi.authme.permission.AuthGroupType;
|
|
||||||
import fr.xephi.authme.permission.PermissionNode;
|
import fr.xephi.authme.permission.PermissionNode;
|
||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
@ -27,9 +25,6 @@ public class CommonService {
|
|||||||
@Inject
|
@Inject
|
||||||
private PermissionsManager permissionsManager;
|
private PermissionsManager permissionsManager;
|
||||||
|
|
||||||
@Inject
|
|
||||||
private AuthGroupHandler authGroupHandler;
|
|
||||||
|
|
||||||
CommonService() {
|
CommonService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,16 +80,4 @@ public class CommonService {
|
|||||||
public boolean hasPermission(Player player, PermissionNode node) {
|
public boolean hasPermission(Player player, PermissionNode node) {
|
||||||
return permissionsManager.hasPermission(player, node);
|
return permissionsManager.hasPermission(player, node);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the permission group of the given player.
|
|
||||||
*
|
|
||||||
* @param player the player to process
|
|
||||||
* @param group the group to add the player to
|
|
||||||
*/
|
|
||||||
// TODO ljacqu 20170304: Move this out of CommonService
|
|
||||||
public void setGroup(Player player, AuthGroupType group) {
|
|
||||||
authGroupHandler.setGroup(player, group);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,9 @@ public class LimboServiceTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private LimboPersistence limboPersistence;
|
private LimboPersistence limboPersistence;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private AuthGroupHandler authGroupHandler;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void initLogger() {
|
public static void initLogger() {
|
||||||
TestHelper.setupLogger();
|
TestHelper.setupLogger();
|
||||||
@ -92,6 +95,7 @@ public class LimboServiceTest {
|
|||||||
|
|
||||||
assertThat(limboService.hasLimboPlayer("Bobby"), equalTo(true));
|
assertThat(limboService.hasLimboPlayer("Bobby"), equalTo(true));
|
||||||
LimboPlayer limbo = limboService.getLimboPlayer("Bobby");
|
LimboPlayer limbo = limboService.getLimboPlayer("Bobby");
|
||||||
|
verify(authGroupHandler).setGroup(player, limbo, AuthGroupType.REGISTERED_UNAUTHENTICATED);
|
||||||
assertThat(limbo, not(nullValue()));
|
assertThat(limbo, not(nullValue()));
|
||||||
assertThat(limbo.isOperator(), equalTo(true));
|
assertThat(limbo.isOperator(), equalTo(true));
|
||||||
assertThat(limbo.getWalkSpeed(), equalTo(0.3f));
|
assertThat(limbo.getWalkSpeed(), equalTo(0.3f));
|
||||||
@ -121,6 +125,7 @@ public class LimboServiceTest {
|
|||||||
verify(player).setWalkSpeed(0.0f);
|
verify(player).setWalkSpeed(0.0f);
|
||||||
|
|
||||||
LimboPlayer limbo = limboService.getLimboPlayer("charles");
|
LimboPlayer limbo = limboService.getLimboPlayer("charles");
|
||||||
|
verify(authGroupHandler).setGroup(player, limbo, AuthGroupType.UNREGISTERED);
|
||||||
assertThat(limbo, not(nullValue()));
|
assertThat(limbo, not(nullValue()));
|
||||||
assertThat(limbo.isOperator(), equalTo(false));
|
assertThat(limbo.isOperator(), equalTo(false));
|
||||||
assertThat(limbo.getWalkSpeed(), equalTo(0.1f));
|
assertThat(limbo.getWalkSpeed(), equalTo(0.1f));
|
||||||
@ -143,6 +148,7 @@ public class LimboServiceTest {
|
|||||||
// then
|
// then
|
||||||
verify(existingLimbo).clearTasks();
|
verify(existingLimbo).clearTasks();
|
||||||
LimboPlayer newLimbo = limboService.getLimboPlayer("Carlos");
|
LimboPlayer newLimbo = limboService.getLimboPlayer("Carlos");
|
||||||
|
verify(authGroupHandler).setGroup(player, newLimbo, AuthGroupType.UNREGISTERED);
|
||||||
assertThat(newLimbo, not(nullValue()));
|
assertThat(newLimbo, not(nullValue()));
|
||||||
assertThat(newLimbo, not(sameInstance(existingLimbo)));
|
assertThat(newLimbo, not(sameInstance(existingLimbo)));
|
||||||
}
|
}
|
||||||
@ -168,6 +174,7 @@ public class LimboServiceTest {
|
|||||||
verify(player).setAllowFlight(true);
|
verify(player).setAllowFlight(true);
|
||||||
verify(player).setFlySpeed(LimboPlayer.DEFAULT_FLY_SPEED);
|
verify(player).setFlySpeed(LimboPlayer.DEFAULT_FLY_SPEED);
|
||||||
verify(limbo).clearTasks();
|
verify(limbo).clearTasks();
|
||||||
|
verify(authGroupHandler).setGroup(player, limbo, AuthGroupType.LOGGED_IN);
|
||||||
assertThat(limboService.hasLimboPlayer("John"), equalTo(false));
|
assertThat(limboService.hasLimboPlayer("John"), equalTo(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,6 +188,7 @@ public class LimboServiceTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
verify(player, only()).getName();
|
verify(player, only()).getName();
|
||||||
|
verify(authGroupHandler).setGroup(player, null, AuthGroupType.LOGGED_IN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -197,6 +205,7 @@ public class LimboServiceTest {
|
|||||||
// then
|
// then
|
||||||
verify(taskManager).registerTimeoutTask(player, limbo);
|
verify(taskManager).registerTimeoutTask(player, limbo);
|
||||||
verify(taskManager).registerMessageTask(player, limbo, true);
|
verify(taskManager).registerMessageTask(player, limbo, true);
|
||||||
|
verify(authGroupHandler).setGroup(player, limbo, AuthGroupType.REGISTERED_UNAUTHENTICATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -209,6 +218,7 @@ public class LimboServiceTest {
|
|||||||
|
|
||||||
// then
|
// then
|
||||||
verifyZeroInteractions(taskManager);
|
verifyZeroInteractions(taskManager);
|
||||||
|
verify(authGroupHandler).setGroup(player, null, AuthGroupType.REGISTERED_UNAUTHENTICATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Player newPlayer(String name) {
|
private static Player newPlayer(String name) {
|
||||||
|
@ -7,8 +7,6 @@ import fr.xephi.authme.data.limbo.LimboService;
|
|||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.events.AbstractUnregisterEvent;
|
import fr.xephi.authme.events.AbstractUnregisterEvent;
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.permission.AuthGroupHandler;
|
|
||||||
import fr.xephi.authme.permission.AuthGroupType;
|
|
||||||
import fr.xephi.authme.security.PasswordSecurity;
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||||
import fr.xephi.authme.service.BukkitService;
|
import fr.xephi.authme.service.BukkitService;
|
||||||
@ -62,8 +60,6 @@ public class AsynchronousUnregisterTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private TeleportationService teleportationService;
|
private TeleportationService teleportationService;
|
||||||
@Mock
|
@Mock
|
||||||
private AuthGroupHandler authGroupHandler;
|
|
||||||
@Mock
|
|
||||||
private CommandManager commandManager;
|
private CommandManager commandManager;
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
@ -90,7 +86,7 @@ public class AsynchronousUnregisterTest {
|
|||||||
// then
|
// then
|
||||||
verify(service).send(player, MessageKey.WRONG_PASSWORD);
|
verify(service).send(player, MessageKey.WRONG_PASSWORD);
|
||||||
verify(passwordSecurity).comparePassword(userPassword, password, name);
|
verify(passwordSecurity).comparePassword(userPassword, password, name);
|
||||||
verifyZeroInteractions(dataSource, limboService, authGroupHandler, teleportationService, bukkitService);
|
verifyZeroInteractions(dataSource, limboService, teleportationService, bukkitService);
|
||||||
verify(player, only()).getName();
|
verify(player, only()).getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,7 +115,6 @@ public class AsynchronousUnregisterTest {
|
|||||||
verify(dataSource).removeAuth(name);
|
verify(dataSource).removeAuth(name);
|
||||||
verify(playerCache).removePlayer(name);
|
verify(playerCache).removePlayer(name);
|
||||||
verify(teleportationService).teleportOnJoin(player);
|
verify(teleportationService).teleportOnJoin(player);
|
||||||
verify(authGroupHandler).setGroup(player, AuthGroupType.UNREGISTERED);
|
|
||||||
verify(bukkitService).scheduleSyncTaskFromOptionallyAsyncTask(any(Runnable.class));
|
verify(bukkitService).scheduleSyncTaskFromOptionallyAsyncTask(any(Runnable.class));
|
||||||
verifyCalledUnregisterEventFor(player);
|
verifyCalledUnregisterEventFor(player);
|
||||||
verify(commandManager).runCommandsOnUnregister(player);
|
verify(commandManager).runCommandsOnUnregister(player);
|
||||||
@ -150,7 +145,6 @@ public class AsynchronousUnregisterTest {
|
|||||||
verify(dataSource).removeAuth(name);
|
verify(dataSource).removeAuth(name);
|
||||||
verify(playerCache).removePlayer(name);
|
verify(playerCache).removePlayer(name);
|
||||||
verify(teleportationService).teleportOnJoin(player);
|
verify(teleportationService).teleportOnJoin(player);
|
||||||
verify(authGroupHandler).setGroup(player, AuthGroupType.UNREGISTERED);
|
|
||||||
verify(bukkitService).scheduleSyncTaskFromOptionallyAsyncTask(any(Runnable.class));
|
verify(bukkitService).scheduleSyncTaskFromOptionallyAsyncTask(any(Runnable.class));
|
||||||
verifyCalledUnregisterEventFor(player);
|
verifyCalledUnregisterEventFor(player);
|
||||||
verify(commandManager).runCommandsOnUnregister(player);
|
verify(commandManager).runCommandsOnUnregister(player);
|
||||||
@ -179,7 +173,6 @@ public class AsynchronousUnregisterTest {
|
|||||||
verify(passwordSecurity).comparePassword(userPassword, password, name);
|
verify(passwordSecurity).comparePassword(userPassword, password, name);
|
||||||
verify(dataSource).removeAuth(name);
|
verify(dataSource).removeAuth(name);
|
||||||
verify(playerCache).removePlayer(name);
|
verify(playerCache).removePlayer(name);
|
||||||
verify(authGroupHandler).setGroup(player, AuthGroupType.UNREGISTERED);
|
|
||||||
verifyZeroInteractions(teleportationService, limboService);
|
verifyZeroInteractions(teleportationService, limboService);
|
||||||
verify(bukkitService, never()).runTask(any(Runnable.class));
|
verify(bukkitService, never()).runTask(any(Runnable.class));
|
||||||
verifyCalledUnregisterEventFor(player);
|
verifyCalledUnregisterEventFor(player);
|
||||||
@ -207,7 +200,7 @@ public class AsynchronousUnregisterTest {
|
|||||||
verify(passwordSecurity).comparePassword(userPassword, password, name);
|
verify(passwordSecurity).comparePassword(userPassword, password, name);
|
||||||
verify(dataSource).removeAuth(name);
|
verify(dataSource).removeAuth(name);
|
||||||
verify(service).send(player, MessageKey.ERROR);
|
verify(service).send(player, MessageKey.ERROR);
|
||||||
verifyZeroInteractions(teleportationService, authGroupHandler, bukkitService);
|
verifyZeroInteractions(teleportationService, bukkitService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -232,7 +225,7 @@ public class AsynchronousUnregisterTest {
|
|||||||
verify(passwordSecurity).comparePassword(userPassword, password, name);
|
verify(passwordSecurity).comparePassword(userPassword, password, name);
|
||||||
verify(dataSource).removeAuth(name);
|
verify(dataSource).removeAuth(name);
|
||||||
verify(playerCache).removePlayer(name);
|
verify(playerCache).removePlayer(name);
|
||||||
verifyZeroInteractions(teleportationService, authGroupHandler);
|
verifyZeroInteractions(teleportationService);
|
||||||
verifyCalledUnregisterEventFor(player);
|
verifyCalledUnregisterEventFor(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,7 +249,6 @@ public class AsynchronousUnregisterTest {
|
|||||||
verify(dataSource).removeAuth(name);
|
verify(dataSource).removeAuth(name);
|
||||||
verify(playerCache).removePlayer(name);
|
verify(playerCache).removePlayer(name);
|
||||||
verify(teleportationService).teleportOnJoin(player);
|
verify(teleportationService).teleportOnJoin(player);
|
||||||
verify(authGroupHandler).setGroup(player, AuthGroupType.UNREGISTERED);
|
|
||||||
verify(bukkitService).scheduleSyncTaskFromOptionallyAsyncTask(any(Runnable.class));
|
verify(bukkitService).scheduleSyncTaskFromOptionallyAsyncTask(any(Runnable.class));
|
||||||
verifyCalledUnregisterEventFor(player);
|
verifyCalledUnregisterEventFor(player);
|
||||||
verify(commandManager).runCommandsOnUnregister(player);
|
verify(commandManager).runCommandsOnUnregister(player);
|
||||||
@ -274,7 +266,7 @@ public class AsynchronousUnregisterTest {
|
|||||||
// then
|
// then
|
||||||
verify(dataSource).removeAuth(name);
|
verify(dataSource).removeAuth(name);
|
||||||
verify(playerCache).removePlayer(name);
|
verify(playerCache).removePlayer(name);
|
||||||
verifyZeroInteractions(authGroupHandler, teleportationService);
|
verifyZeroInteractions(teleportationService);
|
||||||
verifyCalledUnregisterEventFor(null);
|
verifyCalledUnregisterEventFor(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,7 +283,7 @@ public class AsynchronousUnregisterTest {
|
|||||||
// then
|
// then
|
||||||
verify(dataSource).removeAuth(name);
|
verify(dataSource).removeAuth(name);
|
||||||
verify(service).send(initiator, MessageKey.ERROR);
|
verify(service).send(initiator, MessageKey.ERROR);
|
||||||
verifyZeroInteractions(playerCache, teleportationService, authGroupHandler, bukkitService);
|
verifyZeroInteractions(playerCache, teleportationService, bukkitService);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
@ -2,8 +2,6 @@ package fr.xephi.authme.service;
|
|||||||
|
|
||||||
import fr.xephi.authme.message.MessageKey;
|
import fr.xephi.authme.message.MessageKey;
|
||||||
import fr.xephi.authme.message.Messages;
|
import fr.xephi.authme.message.Messages;
|
||||||
import fr.xephi.authme.permission.AuthGroupHandler;
|
|
||||||
import fr.xephi.authme.permission.AuthGroupType;
|
|
||||||
import fr.xephi.authme.permission.PermissionNode;
|
import fr.xephi.authme.permission.PermissionNode;
|
||||||
import fr.xephi.authme.permission.PermissionsManager;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.permission.PlayerPermission;
|
import fr.xephi.authme.permission.PlayerPermission;
|
||||||
@ -41,9 +39,6 @@ public class CommonServiceTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private PermissionsManager permissionsManager;
|
private PermissionsManager permissionsManager;
|
||||||
|
|
||||||
@Mock
|
|
||||||
private AuthGroupHandler authGroupHandler;
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldGetProperty() {
|
public void shouldGetProperty() {
|
||||||
// given
|
// given
|
||||||
@ -113,17 +108,4 @@ public class CommonServiceTest {
|
|||||||
verify(permissionsManager).hasPermission(player, permission);
|
verify(permissionsManager).hasPermission(player, permission);
|
||||||
assertThat(result, equalTo(true));
|
assertThat(result, equalTo(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void shouldSetPermissionGroup() {
|
|
||||||
// given
|
|
||||||
Player player = mock(Player.class);
|
|
||||||
AuthGroupType type = AuthGroupType.LOGGED_IN;
|
|
||||||
|
|
||||||
// when
|
|
||||||
commonService.setGroup(player, type);
|
|
||||||
|
|
||||||
// then
|
|
||||||
verify(authGroupHandler).setGroup(player, type);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user