mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-03 09:10:01 +01:00
#736 Remove use of service getters and deprecate them
This commit is contained in:
parent
be4b3a8605
commit
0977558924
@ -297,7 +297,7 @@ public class AuthMe extends JavaPlugin {
|
|||||||
|
|
||||||
|
|
||||||
// Set up the BungeeCord hook
|
// Set up the BungeeCord hook
|
||||||
setupBungeeCordHook(newSettings);
|
setupBungeeCordHook(newSettings, initializer);
|
||||||
|
|
||||||
// Reload support hook
|
// Reload support hook
|
||||||
reloadSupportHook();
|
reloadSupportHook();
|
||||||
@ -396,11 +396,11 @@ public class AuthMe extends JavaPlugin {
|
|||||||
/**
|
/**
|
||||||
* Set up the BungeeCord hook.
|
* Set up the BungeeCord hook.
|
||||||
*/
|
*/
|
||||||
private void setupBungeeCordHook(NewSetting settings) {
|
private void setupBungeeCordHook(NewSetting settings, AuthMeServiceInitializer initializer) {
|
||||||
if (settings.getProperty(HooksSettings.BUNGEECORD)) {
|
if (settings.getProperty(HooksSettings.BUNGEECORD)) {
|
||||||
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
|
||||||
Bukkit.getMessenger().registerIncomingPluginChannel(
|
Bukkit.getMessenger().registerIncomingPluginChannel(
|
||||||
this, "BungeeCord", new BungeeCordMessage(this));
|
this, "BungeeCord", initializer.get(BungeeCordMessage.class));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -750,37 +750,57 @@ public class AuthMe extends JavaPlugin {
|
|||||||
return commandHandler.processCommand(sender, commandLabel, args);
|
return commandHandler.processCommand(sender, commandLabel, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void notifyAutoPurgeEnd() {
|
||||||
|
this.autoPurging = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// -------------
|
||||||
|
// Service getters (deprecated)
|
||||||
|
// Use @Inject fields instead
|
||||||
|
// -------------
|
||||||
/**
|
/**
|
||||||
* Get the permissions manager instance.
|
* @return permission manager
|
||||||
*
|
* @deprecated should be used in API classes only (temporarily)
|
||||||
* @return Permissions Manager instance.
|
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public PermissionsManager getPermissionsManager() {
|
public PermissionsManager getPermissionsManager() {
|
||||||
return this.permsMan;
|
return this.permsMan;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the management instance.
|
* @return process manager
|
||||||
*
|
* @deprecated should be used in API classes only (temporarily)
|
||||||
* @return management The Management
|
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Management getManagement() {
|
public Management getManagement() {
|
||||||
return management;
|
return management;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the datasource
|
||||||
|
* @deprecated should be used in API classes only (temporarily)
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public DataSource getDataSource() {
|
public DataSource getDataSource() {
|
||||||
return database;
|
return database;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return password manager
|
||||||
|
* @deprecated should be used in API classes only (temporarily)
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public PasswordSecurity getPasswordSecurity() {
|
public PasswordSecurity getPasswordSecurity() {
|
||||||
return passwordSecurity;
|
return passwordSecurity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return plugin hooks
|
||||||
|
* @deprecated should be used in API classes only (temporarily)
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
public PluginHooks getPluginHooks() {
|
public PluginHooks getPluginHooks() {
|
||||||
return pluginHooks;
|
return pluginHooks;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void notifyAutoPurgeEnd() {
|
|
||||||
this.autoPurging = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,14 @@
|
|||||||
package fr.xephi.authme.api;
|
package fr.xephi.authme.api;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.Server;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||||
import fr.xephi.authme.util.Utils;
|
import fr.xephi.authme.util.Utils;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
@ -35,15 +33,6 @@ public class NewAPI {
|
|||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for NewAPI.
|
|
||||||
*
|
|
||||||
* @param server The server instance
|
|
||||||
*/
|
|
||||||
public NewAPI(Server server) {
|
|
||||||
this.plugin = (AuthMe) server.getPluginManager().getPlugin("AuthMe");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the API object for AuthMe.
|
* Get the API object for AuthMe.
|
||||||
*
|
*
|
||||||
|
@ -5,6 +5,7 @@ import fr.xephi.authme.cache.auth.PlayerCache;
|
|||||||
import fr.xephi.authme.command.CommandService;
|
import fr.xephi.authme.command.CommandService;
|
||||||
import fr.xephi.authme.command.PlayerCommand;
|
import fr.xephi.authme.command.PlayerCommand;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.task.ChangePasswordTask;
|
import fr.xephi.authme.task.ChangePasswordTask;
|
||||||
import fr.xephi.authme.util.BukkitService;
|
import fr.xephi.authme.util.BukkitService;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -23,6 +24,10 @@ public class ChangePasswordCommand extends PlayerCommand {
|
|||||||
@Inject
|
@Inject
|
||||||
private BukkitService bukkitService;
|
private BukkitService bukkitService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
// TODO ljacqu 20160531: Remove this once change password task runs as a process (via Management)
|
||||||
|
private PasswordSecurity passwordSecurity;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
public void runCommand(Player player, List<String> arguments, CommandService commandService) {
|
||||||
String oldPassword = arguments.get(0);
|
String oldPassword = arguments.get(0);
|
||||||
@ -43,6 +48,7 @@ public class ChangePasswordCommand extends PlayerCommand {
|
|||||||
|
|
||||||
AuthMe plugin = AuthMe.getInstance();
|
AuthMe plugin = AuthMe.getInstance();
|
||||||
// TODO ljacqu 20160117: Call async task via Management
|
// TODO ljacqu 20160117: Call async task via Management
|
||||||
bukkitService.runTaskAsynchronously(new ChangePasswordTask(plugin, player, oldPassword, newPassword));
|
bukkitService.runTaskAsynchronously(
|
||||||
|
new ChangePasswordTask(plugin, player, oldPassword, newPassword, passwordSecurity));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package fr.xephi.authme.converter;
|
package fr.xephi.authme.converter;
|
||||||
|
|
||||||
import fr.xephi.authme.AuthMe;
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
@ -24,17 +23,18 @@ import java.util.Map.Entry;
|
|||||||
*/
|
*/
|
||||||
public class RakamakConverter implements Converter {
|
public class RakamakConverter implements Converter {
|
||||||
|
|
||||||
private final AuthMe instance;
|
|
||||||
private final DataSource database;
|
private final DataSource database;
|
||||||
private final NewSetting settings;
|
private final NewSetting settings;
|
||||||
private final File pluginFolder;
|
private final File pluginFolder;
|
||||||
|
private final PasswordSecurity passwordSecurity;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
RakamakConverter(@DataFolder File dataFolder, AuthMe instance, DataSource dataSource, NewSetting settings) {
|
RakamakConverter(@DataFolder File dataFolder, DataSource dataSource, NewSetting settings,
|
||||||
this.instance = instance;
|
PasswordSecurity passwordSecurity) {
|
||||||
this.database = dataSource;
|
this.database = dataSource;
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.pluginFolder = dataFolder;
|
this.pluginFolder = dataFolder;
|
||||||
|
this.passwordSecurity = passwordSecurity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -64,7 +64,6 @@ public class RakamakConverter implements Converter {
|
|||||||
ipFile.close();
|
ipFile.close();
|
||||||
|
|
||||||
users = new BufferedReader(new FileReader(source));
|
users = new BufferedReader(new FileReader(source));
|
||||||
PasswordSecurity passwordSecurity = instance.getPasswordSecurity();
|
|
||||||
while ((line = users.readLine()) != null) {
|
while ((line = users.readLine()) != null) {
|
||||||
if (line.contains("=")) {
|
if (line.contains("=")) {
|
||||||
String[] arguments = line.split("=");
|
String[] arguments = line.split("=");
|
||||||
|
@ -2,29 +2,31 @@ package fr.xephi.authme.hooks;
|
|||||||
|
|
||||||
import com.google.common.io.ByteArrayDataInput;
|
import com.google.common.io.ByteArrayDataInput;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
import fr.xephi.authme.AuthMe;
|
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||||
|
import fr.xephi.authme.util.BukkitService;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.plugin.messaging.PluginMessageListener;
|
import org.bukkit.plugin.messaging.PluginMessageListener;
|
||||||
|
|
||||||
/**
|
import javax.inject.Inject;
|
||||||
*/
|
|
||||||
|
|
||||||
public class BungeeCordMessage implements PluginMessageListener {
|
public class BungeeCordMessage implements PluginMessageListener {
|
||||||
|
|
||||||
private final AuthMe plugin;
|
@Inject
|
||||||
|
private DataSource dataSource;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private BukkitService bukkitService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PlayerCache playerCache;
|
||||||
|
|
||||||
|
BungeeCordMessage() { }
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor for BungeeCordMessage.
|
|
||||||
*
|
|
||||||
* @param plugin The plugin instance
|
|
||||||
*/
|
|
||||||
public BungeeCordMessage(AuthMe plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
public void onPluginMessageReceived(String channel, Player player, byte[] message) {
|
||||||
@ -38,8 +40,7 @@ public class BungeeCordMessage implements PluginMessageListener {
|
|||||||
final String[] args = str.split(";");
|
final String[] args = str.split(";");
|
||||||
final String act = args[0];
|
final String act = args[0];
|
||||||
final String name = args[1];
|
final String name = args[1];
|
||||||
final DataSource dataSource = plugin.getDataSource();
|
bukkitService.runTaskAsynchronously(new Runnable() {
|
||||||
plugin.getServer().getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
PlayerAuth auth = dataSource.getAuth(name);
|
PlayerAuth auth = dataSource.getAuth(name);
|
||||||
@ -47,12 +48,12 @@ public class BungeeCordMessage implements PluginMessageListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ("login".equals(act)) {
|
if ("login".equals(act)) {
|
||||||
PlayerCache.getInstance().updatePlayer(auth);
|
playerCache.updatePlayer(auth);
|
||||||
dataSource.setLogged(name);
|
dataSource.setLogged(name);
|
||||||
ConsoleLogger.info("Player " + auth.getNickname()
|
ConsoleLogger.info("Player " + auth.getNickname()
|
||||||
+ " has logged in from one of your server!");
|
+ " has logged in from one of your server!");
|
||||||
} else if ("logout".equals(act)) {
|
} else if ("logout".equals(act)) {
|
||||||
PlayerCache.getInstance().removePlayer(name);
|
playerCache.removePlayer(name);
|
||||||
dataSource.setUnlogged(name);
|
dataSource.setUnlogged(name);
|
||||||
ConsoleLogger.info("Player " + auth.getNickname()
|
ConsoleLogger.info("Player " + auth.getNickname()
|
||||||
+ " has logged out from one of your server!");
|
+ " has logged out from one of your server!");
|
||||||
@ -63,7 +64,7 @@ public class BungeeCordMessage implements PluginMessageListener {
|
|||||||
final String password = args[2];
|
final String password = args[2];
|
||||||
final String salt = args.length >= 4 ? args[3] : null;
|
final String salt = args.length >= 4 ? args[3] : null;
|
||||||
auth.setPassword(new HashedPassword(password, salt));
|
auth.setPassword(new HashedPassword(password, salt));
|
||||||
PlayerCache.getInstance().updatePlayer(auth);
|
playerCache.updatePlayer(auth);
|
||||||
dataSource.updatePassword(auth);
|
dataSource.updatePassword(auth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@ import fr.xephi.authme.permission.PlayerStatePermission;
|
|||||||
import fr.xephi.authme.process.AsynchronousProcess;
|
import fr.xephi.authme.process.AsynchronousProcess;
|
||||||
import fr.xephi.authme.process.ProcessService;
|
import fr.xephi.authme.process.ProcessService;
|
||||||
import fr.xephi.authme.process.SyncProcessManager;
|
import fr.xephi.authme.process.SyncProcessManager;
|
||||||
|
import fr.xephi.authme.security.PasswordSecurity;
|
||||||
import fr.xephi.authme.security.RandomString;
|
import fr.xephi.authme.security.RandomString;
|
||||||
import fr.xephi.authme.settings.Settings;
|
import fr.xephi.authme.settings.Settings;
|
||||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||||
@ -62,6 +63,9 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private BukkitService bukkitService;
|
private BukkitService bukkitService;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PasswordSecurity passwordSecurity;
|
||||||
|
|
||||||
|
|
||||||
AsynchronousLogin() { }
|
AsynchronousLogin() { }
|
||||||
|
|
||||||
@ -150,8 +154,8 @@ public class AsynchronousLogin implements AsynchronousProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String email = pAuth.getEmail();
|
String email = pAuth.getEmail();
|
||||||
boolean passwordVerified = forceLogin || plugin.getPasswordSecurity()
|
boolean passwordVerified = forceLogin || passwordSecurity.comparePassword(
|
||||||
.comparePassword(password, pAuth.getPassword(), player.getName());
|
password, pAuth.getPassword(), player.getName());
|
||||||
|
|
||||||
final String name = player.getName().toLowerCase();
|
final String name = player.getName().toLowerCase();
|
||||||
if (passwordVerified && player.isOnline()) {
|
if (passwordVerified && player.isOnline()) {
|
||||||
|
@ -5,7 +5,7 @@ import fr.xephi.authme.cache.auth.PlayerAuth;
|
|||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
import fr.xephi.authme.datasource.DataSource;
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.output.MessageKey;
|
import fr.xephi.authme.output.MessageKey;
|
||||||
import fr.xephi.authme.permission.PlayerStatePermission;
|
import fr.xephi.authme.permission.PermissionsManager;
|
||||||
import fr.xephi.authme.process.AsynchronousProcess;
|
import fr.xephi.authme.process.AsynchronousProcess;
|
||||||
import fr.xephi.authme.process.ProcessService;
|
import fr.xephi.authme.process.ProcessService;
|
||||||
import fr.xephi.authme.process.SyncProcessManager;
|
import fr.xephi.authme.process.SyncProcessManager;
|
||||||
@ -26,6 +26,8 @@ import org.bukkit.entity.Player;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static fr.xephi.authme.permission.PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS;
|
||||||
|
|
||||||
public class AsyncRegister implements AsynchronousProcess {
|
public class AsyncRegister implements AsynchronousProcess {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -46,6 +48,9 @@ public class AsyncRegister implements AsynchronousProcess {
|
|||||||
@Inject
|
@Inject
|
||||||
private SyncProcessManager syncProcessManager;
|
private SyncProcessManager syncProcessManager;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private PermissionsManager permissionsManager;
|
||||||
|
|
||||||
AsyncRegister() { }
|
AsyncRegister() { }
|
||||||
|
|
||||||
private boolean preRegisterCheck(Player player, String password) {
|
private boolean preRegisterCheck(Player player, String password) {
|
||||||
@ -78,7 +83,7 @@ public class AsyncRegister implements AsynchronousProcess {
|
|||||||
if (maxRegPerIp > 0
|
if (maxRegPerIp > 0
|
||||||
&& !"127.0.0.1".equalsIgnoreCase(ip)
|
&& !"127.0.0.1".equalsIgnoreCase(ip)
|
||||||
&& !"localhost".equalsIgnoreCase(ip)
|
&& !"localhost".equalsIgnoreCase(ip)
|
||||||
&& !plugin.getPermissionsManager().hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)) {
|
&& !permissionsManager.hasPermission(player, ALLOW_MULTIPLE_ACCOUNTS)) {
|
||||||
List<String> otherAccounts = database.getAllAuthsByIp(ip);
|
List<String> otherAccounts = database.getAllAuthsByIp(ip);
|
||||||
if (otherAccounts.size() >= maxRegPerIp) {
|
if (otherAccounts.size() >= maxRegPerIp) {
|
||||||
service.send(player, MessageKey.MAX_REGISTER_EXCEEDED, Integer.toString(maxRegPerIp),
|
service.send(player, MessageKey.MAX_REGISTER_EXCEEDED, Integer.toString(maxRegPerIp),
|
||||||
@ -102,8 +107,7 @@ public class AsyncRegister implements AsynchronousProcess {
|
|||||||
private void emailRegister(Player player, String password, String email) {
|
private void emailRegister(Player player, String password, String email) {
|
||||||
final String name = player.getName().toLowerCase();
|
final String name = player.getName().toLowerCase();
|
||||||
final int maxRegPerEmail = service.getProperty(EmailSettings.MAX_REG_PER_EMAIL);
|
final int maxRegPerEmail = service.getProperty(EmailSettings.MAX_REG_PER_EMAIL);
|
||||||
if (maxRegPerEmail > 0
|
if (maxRegPerEmail > 0 && !permissionsManager.hasPermission(player, ALLOW_MULTIPLE_ACCOUNTS)) {
|
||||||
&& !plugin.getPermissionsManager().hasPermission(player, PlayerStatePermission.ALLOW_MULTIPLE_ACCOUNTS)) {
|
|
||||||
int otherAccounts = database.countAuthsByEmail(email);
|
int otherAccounts = database.countAuthsByEmail(email);
|
||||||
if (otherAccounts >= maxRegPerEmail) {
|
if (otherAccounts >= maxRegPerEmail) {
|
||||||
service.send(player, MessageKey.MAX_REGISTER_EXCEEDED, Integer.toString(maxRegPerEmail),
|
service.send(player, MessageKey.MAX_REGISTER_EXCEEDED, Integer.toString(maxRegPerEmail),
|
||||||
|
@ -3,6 +3,7 @@ package fr.xephi.authme.settings;
|
|||||||
import fr.xephi.authme.AuthMe;
|
import fr.xephi.authme.AuthMe;
|
||||||
import fr.xephi.authme.ConsoleLogger;
|
import fr.xephi.authme.ConsoleLogger;
|
||||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||||
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.hooks.PluginHooks;
|
import fr.xephi.authme.hooks.PluginHooks;
|
||||||
import fr.xephi.authme.initialization.DataFolder;
|
import fr.xephi.authme.initialization.DataFolder;
|
||||||
import fr.xephi.authme.initialization.SettingsDependent;
|
import fr.xephi.authme.initialization.SettingsDependent;
|
||||||
@ -32,6 +33,7 @@ public class SpawnLoader implements SettingsDependent {
|
|||||||
|
|
||||||
private final File authMeConfigurationFile;
|
private final File authMeConfigurationFile;
|
||||||
private final PluginHooks pluginHooks;
|
private final PluginHooks pluginHooks;
|
||||||
|
private final DataSource dataSource;
|
||||||
private FileConfiguration authMeConfiguration;
|
private FileConfiguration authMeConfiguration;
|
||||||
private String[] spawnPriority;
|
private String[] spawnPriority;
|
||||||
private Location essentialsSpawn;
|
private Location essentialsSpawn;
|
||||||
@ -44,12 +46,14 @@ public class SpawnLoader implements SettingsDependent {
|
|||||||
* @param pluginHooks The plugin hooks instance
|
* @param pluginHooks The plugin hooks instance
|
||||||
*/
|
*/
|
||||||
@Inject
|
@Inject
|
||||||
public SpawnLoader(@DataFolder File pluginFolder, NewSetting settings, PluginHooks pluginHooks) {
|
public SpawnLoader(@DataFolder File pluginFolder, NewSetting settings, PluginHooks pluginHooks,
|
||||||
|
DataSource dataSource) {
|
||||||
File spawnFile = new File(pluginFolder, "spawn.yml");
|
File spawnFile = new File(pluginFolder, "spawn.yml");
|
||||||
// TODO ljacqu 20160312: Check if resource could be copied and handle the case if not
|
// TODO ljacqu 20160312: Check if resource could be copied and handle the case if not
|
||||||
FileUtils.copyFileFromResource(spawnFile, "spawn.yml");
|
FileUtils.copyFileFromResource(spawnFile, "spawn.yml");
|
||||||
this.authMeConfigurationFile = new File(pluginFolder, "spawn.yml");
|
this.authMeConfigurationFile = new File(pluginFolder, "spawn.yml");
|
||||||
this.pluginHooks = pluginHooks;
|
this.pluginHooks = pluginHooks;
|
||||||
|
this.dataSource = dataSource;
|
||||||
loadSettings(settings);
|
loadSettings(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +170,7 @@ public class SpawnLoader implements SettingsDependent {
|
|||||||
if (PlayerCache.getInstance().isAuthenticated(playerNameLower)) {
|
if (PlayerCache.getInstance().isAuthenticated(playerNameLower)) {
|
||||||
spawnLoc = getSpawn();
|
spawnLoc = getSpawn();
|
||||||
} else if (getFirstSpawn() != null && (!player.hasPlayedBefore() ||
|
} else if (getFirstSpawn() != null && (!player.hasPlayedBefore() ||
|
||||||
!plugin.getDataSource().isAuthAvailable(playerNameLower))) {
|
!dataSource.isAuthAvailable(playerNameLower))) {
|
||||||
spawnLoc = getFirstSpawn();
|
spawnLoc = getFirstSpawn();
|
||||||
} else {
|
} else {
|
||||||
spawnLoc = getSpawn();
|
spawnLoc = getSpawn();
|
||||||
|
@ -19,19 +19,20 @@ public class ChangePasswordTask implements Runnable {
|
|||||||
private final Player player;
|
private final Player player;
|
||||||
private final String oldPassword;
|
private final String oldPassword;
|
||||||
private final String newPassword;
|
private final String newPassword;
|
||||||
|
private final PasswordSecurity passwordSecurity;
|
||||||
|
|
||||||
public ChangePasswordTask(AuthMe plugin, Player player, String oldPassword, String newPassword) {
|
public ChangePasswordTask(AuthMe plugin, Player player, String oldPassword, String newPassword,
|
||||||
|
PasswordSecurity passwordSecurity) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.oldPassword = oldPassword;
|
this.oldPassword = oldPassword;
|
||||||
this.newPassword = newPassword;
|
this.newPassword = newPassword;
|
||||||
|
this.passwordSecurity = passwordSecurity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Messages m = plugin.getMessages();
|
Messages m = plugin.getMessages();
|
||||||
PasswordSecurity passwordSecurity = plugin.getPasswordSecurity();
|
|
||||||
|
|
||||||
final String name = player.getName().toLowerCase();
|
final String name = player.getName().toLowerCase();
|
||||||
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
PlayerAuth auth = PlayerCache.getInstance().getAuth(name);
|
||||||
if (passwordSecurity.comparePassword(oldPassword, auth.getPassword(), player.getName())) {
|
if (passwordSecurity.comparePassword(oldPassword, auth.getPassword(), player.getName())) {
|
||||||
|
@ -2,6 +2,7 @@ package fr.xephi.authme.settings;
|
|||||||
|
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
import fr.xephi.authme.TestHelper;
|
import fr.xephi.authme.TestHelper;
|
||||||
|
import fr.xephi.authme.datasource.DataSource;
|
||||||
import fr.xephi.authme.hooks.PluginHooks;
|
import fr.xephi.authme.hooks.PluginHooks;
|
||||||
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
import fr.xephi.authme.settings.properties.RestrictionSettings;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -11,6 +12,8 @@ import org.junit.Before;
|
|||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.TemporaryFolder;
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -23,6 +26,7 @@ import static org.mockito.Mockito.mock;
|
|||||||
/**
|
/**
|
||||||
* Test for {@link SpawnLoader}.
|
* Test for {@link SpawnLoader}.
|
||||||
*/
|
*/
|
||||||
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class SpawnLoaderTest {
|
public class SpawnLoaderTest {
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
@ -48,7 +52,8 @@ public class SpawnLoaderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldSetSpawn() {
|
public void shouldSetSpawn() {
|
||||||
// given
|
// given
|
||||||
SpawnLoader spawnLoader = new SpawnLoader(testFolder, settings, mock(PluginHooks.class));
|
SpawnLoader spawnLoader =
|
||||||
|
new SpawnLoader(testFolder, settings, mock(PluginHooks.class), mock(DataSource.class));
|
||||||
World world = mock(World.class);
|
World world = mock(World.class);
|
||||||
given(world.getName()).willReturn("new_world");
|
given(world.getName()).willReturn("new_world");
|
||||||
Location newSpawn = new Location(world, 123, 45.0, -67.89);
|
Location newSpawn = new Location(world, 123, 45.0, -67.89);
|
||||||
|
Loading…
Reference in New Issue
Block a user