Cleanup: avoid injecting Injector directly
- Inject SingletonStore to restrict the possible functions - Refactor PasswordSecurityTest to correspond to the usual way of testing
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
package fr.xephi.authme.command.executable.authme;
|
||||
|
||||
import ch.jalu.injector.Injector;
|
||||
import fr.xephi.authme.AuthMe;
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.initialization.Reloadable;
|
||||
import fr.xephi.authme.initialization.SettingsDependent;
|
||||
import fr.xephi.authme.initialization.factory.SingletonStore;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
@@ -25,9 +25,6 @@ public class ReloadCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private AuthMe plugin;
|
||||
|
||||
@Inject
|
||||
private Injector injector;
|
||||
|
||||
@Inject
|
||||
private Settings settings;
|
||||
|
||||
@@ -37,6 +34,12 @@ public class ReloadCommand implements ExecutableCommand {
|
||||
@Inject
|
||||
private CommonService commonService;
|
||||
|
||||
@Inject
|
||||
private SingletonStore<Reloadable> reloadableStore;
|
||||
|
||||
@Inject
|
||||
private SingletonStore<SettingsDependent> settingsDependentStore;
|
||||
|
||||
@Override
|
||||
public void executeCommand(CommandSender sender, List<String> arguments) {
|
||||
try {
|
||||
@@ -56,10 +59,10 @@ public class ReloadCommand implements ExecutableCommand {
|
||||
}
|
||||
|
||||
private void performReloadOnServices() {
|
||||
injector.retrieveAllOfType(Reloadable.class)
|
||||
reloadableStore.retrieveAllOfType()
|
||||
.forEach(r -> r.reload());
|
||||
|
||||
injector.retrieveAllOfType(SettingsDependent.class)
|
||||
settingsDependentStore.retrieveAllOfType()
|
||||
.forEach(s -> s.reload(settings));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package fr.xephi.authme.task;
|
||||
|
||||
import ch.jalu.injector.Injector;
|
||||
import fr.xephi.authme.initialization.HasCleanup;
|
||||
import fr.xephi.authme.initialization.factory.SingletonStore;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import javax.inject.Inject;
|
||||
@@ -12,15 +12,14 @@ import javax.inject.Inject;
|
||||
public class CleanupTask extends BukkitRunnable {
|
||||
|
||||
@Inject
|
||||
private Injector injector;
|
||||
private SingletonStore<HasCleanup> hasCleanupStore;
|
||||
|
||||
CleanupTask() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (HasCleanup service : injector.retrieveAllOfType(HasCleanup.class)) {
|
||||
service.performCleanup();
|
||||
}
|
||||
hasCleanupStore.retrieveAllOfType()
|
||||
.forEach(HasCleanup::performCleanup);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user