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