Revert: Revert "Fix #889"

- Use constructor injection in BungeeService
This commit is contained in:
ljacqu 2016-08-08 21:23:25 +02:00
parent 0472b2b318
commit eb7487ca84
2 changed files with 17 additions and 22 deletions

View File

@ -16,7 +16,6 @@ import fr.xephi.authme.datasource.DataSourceType;
import fr.xephi.authme.datasource.FlatFile; import fr.xephi.authme.datasource.FlatFile;
import fr.xephi.authme.datasource.MySQL; import fr.xephi.authme.datasource.MySQL;
import fr.xephi.authme.datasource.SQLite; import fr.xephi.authme.datasource.SQLite;
import fr.xephi.authme.hooks.BungeeCordMessage;
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.MetricsStarter; import fr.xephi.authme.initialization.MetricsStarter;
@ -39,7 +38,6 @@ import fr.xephi.authme.settings.SettingsMigrationService;
import fr.xephi.authme.settings.SpawnLoader; import fr.xephi.authme.settings.SpawnLoader;
import fr.xephi.authme.settings.properties.DatabaseSettings; import fr.xephi.authme.settings.properties.DatabaseSettings;
import fr.xephi.authme.settings.properties.EmailSettings; import fr.xephi.authme.settings.properties.EmailSettings;
import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.settings.properties.PluginSettings; import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings; import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.settings.properties.SecuritySettings; import fr.xephi.authme.settings.properties.SecuritySettings;
@ -65,7 +63,6 @@ import org.bukkit.plugin.PluginDescriptionFile;
import org.bukkit.plugin.PluginLoader; import org.bukkit.plugin.PluginLoader;
import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.plugin.messaging.Messenger;
import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.scheduler.BukkitWorker; import org.bukkit.scheduler.BukkitWorker;
@ -244,9 +241,6 @@ public class AuthMe extends JavaPlugin {
// TODO: maybe create a backup manager? // TODO: maybe create a backup manager?
new PerformBackup(this, settings).doBackup(PerformBackup.BackupCause.START); new PerformBackup(this, settings).doBackup(PerformBackup.BackupCause.START);
// Set up the BungeeCord hook
setupBungeeCordHook();
// Reload support hook // Reload support hook
reloadSupportHook(); reloadSupportHook();
@ -360,17 +354,6 @@ public class AuthMe extends JavaPlugin {
} }
} }
/**
* Set up the BungeeCord hook.
*/
private void setupBungeeCordHook() {
if (settings.getProperty(HooksSettings.BUNGEECORD)) {
Messenger messenger = Bukkit.getMessenger();
messenger.registerOutgoingPluginChannel(this, "BungeeCord");
messenger.registerIncomingPluginChannel(this, "BungeeCord", injector.getSingleton(BungeeCordMessage.class));
}
}
/** /**
* Loads the plugin's settings. * Loads the plugin's settings.
* *

View File

@ -3,12 +3,15 @@ package fr.xephi.authme.service;
import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import fr.xephi.authme.AuthMe; import fr.xephi.authme.AuthMe;
import fr.xephi.authme.hooks.BungeeCordMessage;
import fr.xephi.authme.initialization.SettingsDependent; import fr.xephi.authme.initialization.SettingsDependent;
import fr.xephi.authme.security.crypts.HashedPassword; import fr.xephi.authme.security.crypts.HashedPassword;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.HooksSettings; import fr.xephi.authme.settings.properties.HooksSettings;
import fr.xephi.authme.util.BukkitService; import fr.xephi.authme.util.BukkitService;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.messaging.Messenger;
import javax.inject.Inject; import javax.inject.Inject;
@ -19,20 +22,19 @@ public class BungeeService implements SettingsDependent {
private AuthMe plugin; private AuthMe plugin;
private BukkitService bukkitService; private BukkitService bukkitService;
private BungeeCordMessage bungeeCordMessage;
private boolean isEnabled; private boolean isEnabled;
private String bungeeServer; private String bungeeServer;
/** /*
* Constructor. * Constructor.
*
* @param plugin AuthMe plugin.
* @param settings AuthMe settings.
*/ */
@Inject @Inject
BungeeService(AuthMe plugin, BukkitService bukkitService, Settings settings) { BungeeService(AuthMe plugin, BukkitService bukkitService, Settings settings, BungeeCordMessage bungeeCordMessage) {
this.plugin = plugin; this.plugin = plugin;
this.bukkitService = bukkitService; this.bukkitService = bukkitService;
this.bungeeCordMessage = bungeeCordMessage;
reload(settings); reload(settings);
} }
@ -103,5 +105,15 @@ public class BungeeService implements SettingsDependent {
public void reload(Settings settings) { public void reload(Settings settings) {
this.isEnabled = settings.getProperty(HooksSettings.BUNGEECORD); this.isEnabled = settings.getProperty(HooksSettings.BUNGEECORD);
this.bungeeServer = settings.getProperty(HooksSettings.BUNGEECORD_SERVER); this.bungeeServer = settings.getProperty(HooksSettings.BUNGEECORD_SERVER);
Messenger messenger = plugin.getServer().getMessenger();
if (!this.isEnabled) {
return;
}
if (!messenger.isIncomingChannelRegistered(plugin, "BungeeCord")) {
messenger.registerIncomingPluginChannel(plugin, "BungeeCord", bungeeCordMessage);
}
if (!messenger.isOutgoingChannelRegistered(plugin, "BungeeCord")) {
messenger.registerOutgoingPluginChannel(plugin, "BungeeCord");
}
} }
} }