Use injection in and for LimboCache, migrate some legacy settings, remove setGroup from Utils

- New injector method allows to retrieve services if they've already been instantiated -> useful for onDisable() which might be run after aborted initialization
- Deprecate various methods that need to be removed
This commit is contained in:
ljacqu 2016-06-12 16:14:06 +02:00
parent 347d7bcf46
commit d6e1fd5ceb
19 changed files with 226 additions and 198 deletions

View File

@ -47,6 +47,7 @@ import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.PurgeSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.settings.properties.SettingsFieldRetriever;
import fr.xephi.authme.settings.propertymap.PropertyMap;
import fr.xephi.authme.task.PurgeTask;
@ -113,7 +114,6 @@ public class AuthMe extends JavaPlugin {
public DataManager dataManager;
/*
* Private instances
* TODO #432: Move instantiation and management of these services
*/
// TODO #604: Encapsulate ProtocolLib members
public AuthMeInventoryPacketAdapter inventoryProtector;
@ -131,12 +131,14 @@ public class AuthMe extends JavaPlugin {
private SpawnLoader spawnLoader;
private boolean autoPurging;
private BukkitService bukkitService;
private AuthMeServiceInitializer initializer;
/**
* Get the plugin's instance.
*
* @return AuthMe
*/
@Deprecated
public static AuthMe getInstance() {
return plugin;
}
@ -168,24 +170,6 @@ public class AuthMe extends JavaPlugin {
return pluginBuildNumber;
}
/**
* Get the Messages instance.
*
* @return Plugin's messages.
*/
public Messages getMessages() {
return messages;
}
/**
* Get the plugin's NewSetting instance.
*
* @return NewSetting.
*/
public NewSetting getSettings() {
return newSettings;
}
// Get version and build number of the plugin
private void setPluginInfos() {
String versionRaw = this.getDescription().getVersion();
@ -240,7 +224,7 @@ public class AuthMe extends JavaPlugin {
MigrationService.changePlainTextToSha256(newSettings, database, new SHA256());
AuthMeServiceInitializer initializer = new AuthMeServiceInitializer("fr.xephi.authme");
initializer = new AuthMeServiceInitializer("fr.xephi.authme");
// Register elements of the Bukkit / JavaPlugin environment
initializer.register(AuthMe.class, this);
initializer.register(Server.class, getServer());
@ -255,7 +239,11 @@ public class AuthMe extends JavaPlugin {
// Some statically injected things
initializer.register(PlayerCache.class, PlayerCache.getInstance());
initializer.register(LimboCache.class, LimboCache.getInstance());
// Note ljacqu 20160612: Instantiate LimboCache first to make sure it is instantiated
// (because sometimes it's used via LimboCache.getInstance())
// Once LimboCache#getInstance() no longer exists this can be removed!
initializer.get(LimboCache.class);
permsMan = initializer.get(PermissionsManager.class);
bukkitService = initializer.get(BukkitService.class);
@ -431,7 +419,7 @@ public class AuthMe extends JavaPlugin {
* Set up the console filter.
*/
private void setupConsoleFilter() {
if (Settings.removePassword) {
if (newSettings.getProperty(SecuritySettings.REMOVE_PASSWORD_FROM_CONSOLE)) {
ConsoleFilter filter = new ConsoleFilter();
getLogger().setFilter(filter);
Bukkit.getLogger().setFilter(filter);
@ -449,10 +437,13 @@ public class AuthMe extends JavaPlugin {
@Override
public void onDisable() {
// Save player data
if (bukkitService != null) {
BukkitService bukkitService = initializer.getIfAvailable(BukkitService.class);
LimboCache limboCache = initializer.getIfAvailable(LimboCache.class);
if (bukkitService != null && limboCache != null) {
Collection<? extends Player> players = bukkitService.getOnlinePlayers();
for (Player player : players) {
savePlayer(player);
savePlayer(player, limboCache);
}
}
@ -495,8 +486,6 @@ public class AuthMe extends JavaPlugin {
}
}, "AuthMe-DataSource#close").start();
// Close the database
// Disabled correctly
ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " disabled!");
ConsoleLogger.close();
@ -614,7 +603,7 @@ public class AuthMe extends JavaPlugin {
}
// Save Player Data
private void savePlayer(Player player) {
private void savePlayer(Player player, LimboCache limboCache) {
if (safeIsNpc(player) || Utils.isUnrestricted(player)) {
return;
}
@ -626,8 +615,8 @@ public class AuthMe extends JavaPlugin {
.location(player.getLocation()).build();
database.updateQuitLoc(auth);
}
if (LimboCache.getInstance().hasLimboPlayer(name)) {
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
if (limboCache.hasLimboPlayer(name)) {
LimboPlayer limbo = limboCache.getLimboPlayer(name);
if (!Settings.noTeleport) {
player.teleport(limbo.getLoc());
}
@ -635,7 +624,7 @@ public class AuthMe extends JavaPlugin {
Utils.addNormal(player, limbo.getGroup());
player.setOp(limbo.isOperator());
limbo.getTimeoutTask().cancel();
LimboCache.getInstance().deleteLimboPlayer(name);
limboCache.deleteLimboPlayer(name);
if (this.playerBackup.doesCacheExist(player)) {
this.playerBackup.removeCache(player);
}
@ -713,17 +702,7 @@ public class AuthMe extends JavaPlugin {
.replace("{COUNTRY}", GeoLiteAPI.getCountryName(ipAddress));
}
public boolean isLoggedIp(String name, String ip) {
int count = 0;
for (Player player : bukkitService.getOnlinePlayers()) {
if (ip.equalsIgnoreCase(Utils.getPlayerIp(player))
&& database.isLogged(player.getName().toLowerCase())
&& !player.getName().equalsIgnoreCase(name)) {
++count;
}
}
return count >= Settings.getMaxLoginPerIp;
}
/**
* Handle Bukkit commands.
@ -757,6 +736,24 @@ public class AuthMe extends JavaPlugin {
// Service getters (deprecated)
// Use @Inject fields instead
// -------------
/**
* @return Plugin's messages.
* @deprecated should be used in API classes only (temporarily)
*/
@Deprecated
public Messages getMessages() {
return messages;
}
/**
* @return NewSetting
* @deprecated should be used in API classes only (temporarily)
*/
@Deprecated
public NewSetting getSettings() {
return newSettings;
}
/**
* @return permission manager
* @deprecated should be used in API classes only (temporarily)

View File

@ -1,45 +1,47 @@
package fr.xephi.authme.cache.limbo;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.cache.backup.JsonCache;
import fr.xephi.authme.cache.backup.PlayerData;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.SpawnLoader;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import javax.inject.Inject;
import java.util.concurrent.ConcurrentHashMap;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Manages all {@link LimboPlayer} instances.
*/
public class LimboCache {
@Deprecated // TODO ljacqu 20160612: Remove this field
private volatile static LimboCache singleton;
private final ConcurrentHashMap<String, LimboPlayer> cache;
private final AuthMe plugin;
private final JsonCache jsonCache;
/**
* Constructor for LimboCache.
*
* @param plugin AuthMe
*/
private LimboCache(AuthMe plugin) {
this.plugin = plugin;
this.cache = new ConcurrentHashMap<>();
this.jsonCache = new JsonCache();
private final ConcurrentHashMap<String, LimboPlayer> cache = new ConcurrentHashMap<>();
private final JsonCache jsonCache = new JsonCache();
@Inject
private PermissionsManager permissionsManager;
@Inject
private SpawnLoader spawnLoader;
@Inject
LimboCache(PermissionsManager permissionsManager, SpawnLoader spawnLoader) {
this.permissionsManager = permissionsManager;
this.spawnLoader = spawnLoader;
singleton = this;
}
/**
* Method getInstance.
*
* @return LimboCache
* @return LimboCache instance
* @deprecated Inject the instance properly instead
*/
@Deprecated
public static LimboCache getInstance() {
if (singleton == null) {
singleton = new LimboCache(AuthMe.getInstance());
}
return singleton;
}
@ -50,13 +52,12 @@ public class LimboCache {
*/
public void addLimboPlayer(Player player) {
String name = player.getName().toLowerCase();
Location loc = player.getLocation();
Location location = player.isDead() ? spawnLoader.getSpawnLocation(player) : player.getLocation();
boolean operator = player.isOp();
boolean flyEnabled = player.getAllowFlight();
String playerGroup = "";
PermissionsManager permsMan = plugin.getPermissionsManager();
if (permsMan.hasGroupSupport()) {
playerGroup = permsMan.getPrimaryGroup(player);
if (permissionsManager.hasGroupSupport()) {
playerGroup = permissionsManager.getPrimaryGroup(player);
}
if (jsonCache.doesCacheExist(player)) {
@ -68,11 +69,8 @@ public class LimboCache {
}
}
if (player.isDead()) {
loc = plugin.getSpawnLocation(player);
}
cache.put(name, new LimboPlayer(name, loc, operator, playerGroup, flyEnabled));
cache.put(name, new LimboPlayer(name, location, operator, playerGroup, flyEnabled));
}
/**

View File

@ -8,6 +8,8 @@ import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.task.MessageTask;
@ -48,6 +50,9 @@ public class UnregisterAdminCommand implements ExecutableCommand {
@Inject
private LimboCache limboCache;
@Inject
private PermissionsManager permissionsManager;
@Override
public void executeCommand(final CommandSender sender, List<String> arguments) {
// Get the player name
@ -69,7 +74,7 @@ public class UnregisterAdminCommand implements ExecutableCommand {
// Unregister the player
Player target = bukkitService.getPlayerExact(playerNameLowerCase);
playerCache.removePlayer(playerNameLowerCase);
Utils.setGroup(target, Utils.GroupType.UNREGISTERED);
permissionsManager.setGroup(target, AuthGroupType.UNREGISTERED);
if (target != null && target.isOnline()) {
if (commandService.getProperty(RegistrationSettings.FORCE)) {
applyUnregisteredEffectsAndTasks(target);

View File

@ -96,8 +96,22 @@ public class AuthMeServiceInitializer {
}
/**
* Returns an instance of the given class or the value associated with an annotation,
* by retrieving it or by instantiating it if not yet present.
* Returns an instance of the given class if available. This simply returns the instance if present and
* otherwise {@code null}. Calling this method will not instantiate anything.
*
* @param clazz the class to retrieve the instance for
* @param <T> the class' type
* @return instance or null if none available
*/
public <T> T getIfAvailable(Class<T> clazz) {
if (Annotation.class.isAssignableFrom(clazz)) {
throw new UnsupportedOperationException("Annotations may not be retrieved in this way!");
}
return clazz.cast(objects.get(clazz));
}
/**
* Returns an instance of the given class by retrieving it or by instantiating it if not yet present.
*
* @param clazz the class to retrieve a value for
* @param traversedClasses the list of traversed classes

View File

@ -0,0 +1,20 @@
package fr.xephi.authme.permission;
/**
* Represents the group type based on the user's auth status.
*/
public enum AuthGroupType {
/** Player does not have an account. */
UNREGISTERED,
/** Registered? */
REGISTERED, // TODO #761: Remove this or the NOT_LOGGED_IN one
/** Player is registered and not logged in. */
NOT_LOGGED_IN,
/** Player is logged in. */
LOGGED_IN
}

View File

@ -1,6 +1,8 @@
package fr.xephi.authme.permission;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.permission.handlers.BPermissionsHandler;
import fr.xephi.authme.permission.handlers.GroupManagerHandler;
import fr.xephi.authme.permission.handlers.PermissionHandler;
@ -8,6 +10,7 @@ import fr.xephi.authme.permission.handlers.PermissionsBukkitHandler;
import fr.xephi.authme.permission.handlers.PermissionsExHandler;
import fr.xephi.authme.permission.handlers.VaultHandler;
import fr.xephi.authme.permission.handlers.ZPermissionsHandler;
import fr.xephi.authme.settings.Settings;
import net.milkbowl.vault.permission.Permission;
import org.anjocaido.groupmanager.GroupManager;
import org.bukkit.Bukkit;
@ -23,6 +26,7 @@ import ru.tehkode.permissions.bukkit.PermissionsEx;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
@ -349,6 +353,61 @@ public class PermissionsManager {
return result;
}
/**
* Set the group of a player, by its AuthMe group type.
*
* @param player The player.
* @param group The group type.
*
* @return True if succeeded, false otherwise. False is also returned if groups aren't supported
* with the current permissions system.
*/
public boolean setGroup(Player player, AuthGroupType group) {
// Check whether the permissions check is enabled
if (!isEnabled() || !Settings.isPermissionCheckEnabled) {
return false;
}
// Make sure group support is available
if (!handler.hasGroupSupport()) {
ConsoleLogger.showError("The current permissions system doesn't have group support, unable to set group!");
return false;
}
switch (group) {
case UNREGISTERED:
// Remove the other group type groups, set the current group
removeGroups(player, Arrays.asList(Settings.getRegisteredGroup, Settings.getUnloggedinGroup));
return addGroup(player, Settings.unRegisteredGroup);
case REGISTERED:
// Remove the other group type groups, set the current group
removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getUnloggedinGroup));
return addGroup(player, Settings.getRegisteredGroup);
case NOT_LOGGED_IN:
// Remove the other group type groups, set the current group
removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getRegisteredGroup));
return addGroup(player, Settings.getUnloggedinGroup);
case LOGGED_IN:
// Get the limbo player data
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase());
if (limbo == null)
return false;
// Get the players group
String realGroup = limbo.getGroup();
// Remove the other group types groups, set the real group
removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getRegisteredGroup, Settings.getUnloggedinGroup));
return addGroup(player, realGroup);
default:
return false;
}
}
/**
* Remove the permission group of a player, if supported.
*

View File

@ -2,6 +2,7 @@ package fr.xephi.authme.process;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.output.Messages;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.permission.PermissionNode;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.NewSetting;
@ -102,4 +103,8 @@ public class ProcessService {
return permissionsManager.hasPermission(player, node);
}
public boolean setGroup(Player player, AuthGroupType group) {
return permissionsManager.setGroup(player, group);
}
}

View File

@ -10,10 +10,10 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.ProtectInventoryEvent;
import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.permission.PlayerStatePermission;
import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.util.TeleportationService;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
@ -22,8 +22,8 @@ import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.TeleportationService;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.Utils.GroupType;
import org.apache.commons.lang.reflect.MethodUtils;
import org.bukkit.GameMode;
import org.bukkit.entity.LivingEntity;
@ -35,6 +35,7 @@ import org.bukkit.scheduler.BukkitTask;
import javax.inject.Inject;
import static fr.xephi.authme.settings.properties.RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN;
import static fr.xephi.authme.util.BukkitService.TICKS_PER_SECOND;
public class AsynchronousJoin implements AsynchronousProcess {
@ -116,7 +117,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
final boolean isAuthAvailable = database.isAuthAvailable(name);
if (isAuthAvailable) {
Utils.setGroup(player, GroupType.NOTLOGGEDIN);
service.setGroup(player, AuthGroupType.NOT_LOGGED_IN);
teleportationService.teleportOnJoin(player);
limboCache.updateLimboPlayer(player);
@ -153,7 +154,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
// Not Registered
// Groups logic
Utils.setGroup(player, GroupType.UNREGISTERED);
service.setGroup(player, AuthGroupType.UNREGISTERED);
// Skip if registration is optional
if (!service.getProperty(RegistrationSettings.FORCE)) {
@ -168,7 +169,7 @@ public class AsynchronousJoin implements AsynchronousProcess {
limboCache.addLimboPlayer(player);
}
final int registrationTimeout = service.getProperty(RestrictionSettings.TIMEOUT) * 20;
final int registrationTimeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
bukkitService.scheduleSyncDelayedTask(new Runnable() {
@Override

View File

@ -123,7 +123,7 @@ public class AsynchronousLogin implements AsynchronousProcess {
if (service.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP) > 0
&& !permissionsManager.hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)
&& !"127.0.0.1".equalsIgnoreCase(ip) && !"localhost".equalsIgnoreCase(ip)) {
if (plugin.isLoggedIp(name, ip)) {
if (isLoggedIp(name, ip)) {
service.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
return null;
}
@ -254,4 +254,16 @@ public class AsynchronousLogin implements AsynchronousProcess {
}
}
}
private boolean isLoggedIp(String name, String ip) {
int count = 0;
for (Player player : bukkitService.getOnlinePlayers()) {
if (ip.equalsIgnoreCase(Utils.getPlayerIp(player))
&& database.isLogged(player.getName().toLowerCase())
&& !player.getName().equalsIgnoreCase(name)) {
++count;
}
}
return count >= service.getProperty(RestrictionSettings.MAX_LOGIN_PER_IP);
}
}

View File

@ -10,15 +10,14 @@ import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.LoginEvent;
import fr.xephi.authme.events.RestoreInventoryEvent;
import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SynchronousProcess;
import fr.xephi.authme.util.TeleportationService;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.Utils.GroupType;
import fr.xephi.authme.util.TeleportationService;
import org.apache.commons.lang.reflect.MethodUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
@ -95,7 +94,7 @@ public class ProcessSyncPlayerLogin implements SynchronousProcess {
if (limbo != null) {
// Restore Op state and Permission Group
restoreOpState(player, limbo);
Utils.setGroup(player, GroupType.LOGGEDIN);
service.setGroup(player, AuthGroupType.LOGGED_IN);
teleportationService.teleportOnLogin(player, auth, limbo);

View File

@ -5,12 +5,12 @@ import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SyncProcessManager;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.Utils.GroupType;
import org.bukkit.entity.Player;
import javax.inject.Inject;
@ -63,7 +63,7 @@ public class AsynchronousLogout implements AsynchronousProcess {
limboCache.deleteLimboPlayer(name);
}
limboCache.addLimboPlayer(player);
Utils.setGroup(player, GroupType.NOTLOGGEDIN);
service.setGroup(player, AuthGroupType.NOT_LOGGED_IN);
syncProcessManager.processSyncPlayerLogout(player);
}
}

View File

@ -10,13 +10,12 @@ import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SynchronousProcess;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask;
import fr.xephi.authme.util.BukkitService;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@ -53,7 +52,7 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
}
private void restoreSpeedEffect(Player player) {
if (Settings.isRemoveSpeedEnabled) {
if (service.getProperty(RestrictionSettings.REMOVE_SPEED)) {
player.setWalkSpeed(0.0F);
player.setFlySpeed(0.0F);
}
@ -86,8 +85,8 @@ public class ProcessSynchronousPlayerLogout implements SynchronousProcess {
player.setOp(false);
restoreSpeedEffect(player);
// Player is now logout... Time to fire event !
Bukkit.getServer().getPluginManager().callEvent(new LogoutEvent(player));
if (Settings.bungee) {
bukkitService.callEvent(new LogoutEvent(player));
if (service.getProperty(HooksSettings.BUNGEECORD)) {
sendBungeeMessage(player);
}
service.send(player, MessageKey.LOGOUT_SUCCESS);

View File

@ -5,6 +5,7 @@ import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SynchronousProcess;
import fr.xephi.authme.settings.Settings;
@ -43,7 +44,7 @@ public class ProcessSyncEmailRegister implements SynchronousProcess {
final String name = player.getName().toLowerCase();
LimboPlayer limbo = limboCache.getLimboPlayer(name);
if (!Settings.getRegisteredGroup.isEmpty()) {
Utils.setGroup(player, Utils.GroupType.REGISTERED);
service.setGroup(player, AuthGroupType.REGISTERED);
}
service.send(player, MessageKey.ACCOUNT_NOT_ACTIVATED);
int time = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;

View File

@ -9,8 +9,9 @@ import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.events.LoginEvent;
import fr.xephi.authme.events.RestoreInventoryEvent;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.process.SynchronousProcess;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.process.SynchronousProcess;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.EmailSettings;
import fr.xephi.authme.settings.properties.HooksSettings;
@ -44,6 +45,9 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
@Inject
private BukkitService bukkitService;
@Inject
private LimboCache limboCache;
ProcessSyncPasswordRegister() { }
private void sendBungeeMessage(Player player) {
@ -73,18 +77,17 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
private void requestLogin(Player player) {
final String name = player.getName().toLowerCase();
Utils.teleportToSpawn(player);
LimboCache cache = LimboCache.getInstance();
cache.updateLimboPlayer(player);
limboCache.updateLimboPlayer(player);
int delay = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
int interval = service.getProperty(RegistrationSettings.MESSAGE_INTERVAL);
BukkitTask task;
if (delay != 0) {
task = bukkitService.runTaskLater(new TimeoutTask(plugin, name, player), delay);
cache.getLimboPlayer(name).setTimeoutTask(task);
limboCache.getLimboPlayer(name).setTimeoutTask(task);
}
task = bukkitService.runTask(new MessageTask(bukkitService, plugin.getMessages(),
name, MessageKey.LOGIN_MESSAGE, interval));
cache.getLimboPlayer(name).setMessageTask(task);
limboCache.getLimboPlayer(name).setMessageTask(task);
if (player.isInsideVehicle() && player.getVehicle() != null) {
player.getVehicle().eject();
}
@ -92,7 +95,7 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
public void processPasswordRegister(Player player) {
final String name = player.getName().toLowerCase();
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
LimboPlayer limbo = limboCache.getLimboPlayer(name);
if (limbo != null) {
if (service.getProperty(RestrictionSettings.HIDE_TABLIST_BEFORE_LOGIN) && plugin.tablistHider != null) {
plugin.tablistHider.sendTablist(player);
@ -108,11 +111,11 @@ public class ProcessSyncPasswordRegister implements SynchronousProcess {
}
}
LimboCache.getInstance().deleteLimboPlayer(name);
limboCache.deleteLimboPlayer(name);
}
if (!Settings.getRegisteredGroup.isEmpty()) {
Utils.setGroup(player, Utils.GroupType.REGISTERED);
service.setGroup(player, AuthGroupType.REGISTERED);
}
service.send(player, MessageKey.REGISTER_SUCCESS);

View File

@ -8,6 +8,7 @@ import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.permission.AuthGroupType;
import fr.xephi.authme.process.AsynchronousProcess;
import fr.xephi.authme.process.ProcessService;
import fr.xephi.authme.security.PasswordSecurity;
@ -18,7 +19,6 @@ import fr.xephi.authme.task.MessageTask;
import fr.xephi.authme.task.TimeoutTask;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.Utils;
import fr.xephi.authme.util.Utils.GroupType;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@ -62,12 +62,12 @@ public class AsynchronousUnregister implements AsynchronousProcess {
return;
}
int timeOut = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
if (Settings.isForcedRegistrationEnabled) {
if (service.getProperty(RegistrationSettings.FORCE)) {
Utils.teleportToSpawn(player);
player.saveData();
playerCache.removePlayer(player.getName().toLowerCase());
if (!Settings.getRegisteredGroup.isEmpty()) {
Utils.setGroup(player, GroupType.UNREGISTERED);
service.setGroup(player, AuthGroupType.UNREGISTERED);
}
limboCache.addLimboPlayer(player);
LimboPlayer limboPlayer = limboCache.getLimboPlayer(name);
@ -83,7 +83,7 @@ public class AsynchronousUnregister implements AsynchronousProcess {
return;
}
if (!Settings.unRegisteredGroup.isEmpty()) {
Utils.setGroup(player, Utils.GroupType.UNREGISTERED);
service.setGroup(player, AuthGroupType.UNREGISTERED);
}
playerCache.removePlayer(name);

View File

@ -14,22 +14,18 @@ import java.util.List;
/**
* Old settings manager. See {@link NewSetting} for the new manager.
*/
@Deprecated
public final class Settings {
public static List<String> getUnrestrictedName;
public static List<String> getForcedWorlds;
public static boolean isPermissionCheckEnabled;
public static boolean isForcedRegistrationEnabled;
public static boolean isTeleportToSpawnEnabled;
public static boolean isSessionsEnabled;
public static boolean isAllowRestrictedIp;
public static boolean isForceSpawnLocOnJoinEnabled;
public static boolean isSaveQuitLocationEnabled;
public static boolean protectInventoryBeforeLogInEnabled;
public static boolean isStopEnabled;
public static boolean reloadSupport;
public static boolean removePassword;
public static boolean multiverse;
public static boolean bungee;
public static boolean forceRegLogin;
public static boolean noTeleport;
@ -41,9 +37,6 @@ public final class Settings {
public static String crazyloginFileName;
public static int getSessionTimeout;
public static int getNonActivatedGroup;
public static int maxLoginTry;
public static int captchaLength;
public static int getMaxLoginPerIp;
private static FileConfiguration configFile;
/**
@ -58,13 +51,11 @@ public final class Settings {
private static void loadVariables() {
isPermissionCheckEnabled = load(PluginSettings.ENABLE_PERMISSION_CHECK);
isForcedRegistrationEnabled = load(RegistrationSettings.FORCE);
isTeleportToSpawnEnabled = load(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN);
isSessionsEnabled = load(PluginSettings.SESSIONS_ENABLED);
getSessionTimeout = configFile.getInt("settings.sessions.timeout", 10);
isAllowRestrictedIp = load(RestrictionSettings.ENABLE_RESTRICTED_USERS);
isRemoveSpeedEnabled = load(RestrictionSettings.REMOVE_SPEED);
isForceSpawnLocOnJoinEnabled = load(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN);
isSaveQuitLocationEnabled = load(RestrictionSettings.SAVE_QUIT_LOCATION);
getUnloggedinGroup = load(SecuritySettings.UNLOGGEDIN_GROUP);
getNonActivatedGroup = configFile.getInt("ExternalBoardOptions.nonActivedUserGroup", -1);
@ -74,15 +65,9 @@ public final class Settings {
protectInventoryBeforeLogInEnabled = load(RestrictionSettings.PROTECT_INVENTORY_BEFORE_LOGIN);
isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true);
reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true);
removePassword = configFile.getBoolean("Security.console.removePassword", true);
maxLoginTry = configFile.getInt("Security.captcha.maxLoginTry", 5);
captchaLength = configFile.getInt("Security.captcha.captchaLength", 5);
multiverse = load(HooksSettings.MULTIVERSE);
bungee = load(HooksSettings.BUNGEECORD);
getForcedWorlds = load(RestrictionSettings.FORCE_SPAWN_ON_WORLDS);
defaultWorld = configFile.getString("Purge.defaultWorld", "world");
forceRegLogin = load(RegistrationSettings.FORCE_LOGIN_AFTER_REGISTER);
getMaxLoginPerIp = load(RestrictionSettings.MAX_LOGIN_PER_IP);
noTeleport = load(RestrictionSettings.NO_TELEPORT);
crazyloginFileName = configFile.getString("Converter.CrazyLogin.fileName", "accounts.db");
}

View File

@ -6,7 +6,8 @@ import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.hooks.PluginHooks;
import fr.xephi.authme.initialization.DataFolder;
import fr.xephi.authme.initialization.SettingsDependent;
import fr.xephi.authme.initialization.Reloadable;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.FileUtils;
import fr.xephi.authme.util.StringUtils;
@ -29,9 +30,10 @@ import java.io.IOException;
* should be taken from. In AuthMe, we can distinguish between the regular spawn and a "first spawn",
* to which players will be teleported who have joined for the first time.
*/
public class SpawnLoader implements SettingsDependent {
public class SpawnLoader implements Reloadable {
private final File authMeConfigurationFile;
private final NewSetting settings;
private final PluginHooks pluginHooks;
private final DataSource dataSource;
private FileConfiguration authMeConfiguration;
@ -53,18 +55,17 @@ public class SpawnLoader implements SettingsDependent {
// TODO ljacqu 20160312: Check if resource could be copied and handle the case if not
FileUtils.copyFileFromResource(spawnFile, "spawn.yml");
this.authMeConfigurationFile = new File(pluginFolder, "spawn.yml");
this.settings = settings;
this.pluginHooks = pluginHooks;
this.dataSource = dataSource;
loadSettings(settings);
reload();
}
/**
* Retrieve the relevant settings and load the AuthMe spawn.yml file.
*
* @param settings The settings instance
* (Re)loads the spawn file and relevant settings.
*/
@Override
public void loadSettings(NewSetting settings) {
public void reload() {
spawnPriority = settings.getProperty(RestrictionSettings.SPAWN_PRIORITY).split(",");
authMeConfiguration = YamlConfiguration.loadConfiguration(authMeConfigurationFile);
loadEssentialsSpawn();
@ -159,7 +160,7 @@ public class SpawnLoader implements SettingsDependent {
}
break;
case "multiverse":
if (Settings.multiverse) {
if (settings.getProperty(HooksSettings.MULTIVERSE)) {
spawnLoc = pluginHooks.getMultiverseSpawn(world);
}
break;

View File

@ -2,8 +2,6 @@ package fr.xephi.authme.util;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.cache.limbo.LimboPlayer;
import fr.xephi.authme.events.AuthMeTeleportEvent;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.Settings;
@ -23,68 +21,6 @@ public final class Utils {
private Utils() {
}
/**
* Set the group of a player, by its AuthMe group type.
*
* @param player The player.
* @param group The group type.
*
* @return True if succeeded, false otherwise. False is also returned if groups aren't supported
* with the current permissions system.
*/
public static boolean setGroup(Player player, GroupType group) {
// Check whether the permissions check is enabled
if (!Settings.isPermissionCheckEnabled) {
return false;
}
// Get the permissions manager, and make sure it's valid
PermissionsManager permsMan = plugin.getPermissionsManager();
if (permsMan == null) {
ConsoleLogger.showError("Failed to access permissions manager instance, shutting down.");
return false;
}
// Make sure group support is available
if (!permsMan.hasGroupSupport()) {
ConsoleLogger.showError("The current permissions system doesn't have group support, unable to set group!");
return false;
}
switch (group) {
case UNREGISTERED:
// Remove the other group type groups, set the current group
permsMan.removeGroups(player, Arrays.asList(Settings.getRegisteredGroup, Settings.getUnloggedinGroup));
return permsMan.addGroup(player, Settings.unRegisteredGroup);
case REGISTERED:
// Remove the other group type groups, set the current group
permsMan.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getUnloggedinGroup));
return permsMan.addGroup(player, Settings.getRegisteredGroup);
case NOTLOGGEDIN:
// Remove the other group type groups, set the current group
permsMan.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getRegisteredGroup));
return permsMan.addGroup(player, Settings.getUnloggedinGroup);
case LOGGEDIN:
// Get the limbo player data
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase());
if (limbo == null)
return false;
// Get the players group
String realGroup = limbo.getGroup();
// Remove the other group types groups, set the real group
permsMan.removeGroups(player, Arrays.asList(Settings.unRegisteredGroup, Settings.getRegisteredGroup, Settings.getUnloggedinGroup));
return permsMan.addGroup(player, realGroup);
default:
return false;
}
}
/**
* TODO: This method requires better explanation.
* <p>
@ -143,13 +79,6 @@ public final class Utils {
}
}
public enum GroupType {
UNREGISTERED,
REGISTERED,
NOTLOGGEDIN,
LOGGEDIN
}
/**
* Returns the IP of the given player.
*

View File

@ -27,7 +27,7 @@ public class HashAlgorithmIntegrationTest {
private static AuthMeServiceInitializer initializer;
@BeforeClass
public static void setUpWrapper() {
public static void setUpConfigAndInjector() {
NewSetting settings = mock(NewSetting.class);
given(settings.getProperty(HooksSettings.BCRYPT_LOG2_ROUND)).willReturn(8);
given(settings.getProperty(SecuritySettings.DOUBLE_MD5_SALT_LENGTH)).willReturn(16);
@ -52,7 +52,7 @@ public class HashAlgorithmIntegrationTest {
}
@Test
public void shouldBeAbleToInstantiateEncryptionAlgorithms() throws InstantiationException, IllegalAccessException {
public void shouldBeAbleToInstantiateEncryptionAlgorithms() {
// given / when / then
for (HashAlgorithm algorithm : HashAlgorithm.values()) {
if (!HashAlgorithm.CUSTOM.equals(algorithm) && !HashAlgorithm.PLAINTEXT.equals(algorithm)) {