Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into 432-remove-public-ip-map

This commit is contained in:
ljacqu 2016-03-06 14:42:32 +01:00
commit 987c3fdb17
11 changed files with 88 additions and 86 deletions

View File

@ -241,8 +241,6 @@ public class AuthMe extends JavaPlugin {
try { try {
setupDatabase(newSettings); setupDatabase(newSettings);
} catch (Exception e) { } catch (Exception e) {
ConsoleLogger.showError("If you are using CraftBukkit/Spigot 1.9 please add the "
+ "-Dfile.encoding=UTF-8 argument in your server startup script!");
ConsoleLogger.logException("Fatal error occurred during database connection! " ConsoleLogger.logException("Fatal error occurred during database connection! "
+ "Authme initialization aborted!", e); + "Authme initialization aborted!", e);
stopOrUnload(); stopOrUnload();
@ -333,6 +331,91 @@ public class AuthMe extends JavaPlugin {
ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " correctly enabled!"); ConsoleLogger.info("AuthMe " + this.getDescription().getVersion() + " correctly enabled!");
} }
/** Temporary method for reloading all stateful entities. */
// TODO #432: Merge this with onEnable, not running things like Metrics multiple times where it would be bad
// Until then this method is a shameful copy of major parts of onEnable()...
public void reloadEntities() {
// Set various instances
server = getServer();
plugin = this;
ConsoleLogger.setLogger(getLogger());
setPluginInfos();
// Load settings and custom configurations, if it fails, stop the server due to security reasons.
newSettings = createNewSetting();
if (newSettings == null) {
ConsoleLogger.showError("Could not load configuration. Aborting.");
server.shutdown();
return;
}
ConsoleLogger.setLoggingOptions(newSettings.getProperty(SecuritySettings.USE_LOGGING),
new File(getDataFolder(), "authme.log"));
// Old settings manager
if (!loadSettings()) {
server.shutdown();
setEnabled(false);
return;
}
messages = new Messages(newSettings.getMessagesFile(), newSettings.getDefaultMessagesFile());
// Connect to the database and setup tables
try {
setupDatabase(newSettings);
} catch (Exception e) {
ConsoleLogger.logException("Fatal error occurred during database connection! "
+ "Authme initialization aborted!", e);
stopOrUnload();
return;
}
passwordSecurity = new PasswordSecurity(getDataSource(), newSettings.getProperty(SecuritySettings.PASSWORD_HASH),
Bukkit.getPluginManager(), newSettings.getProperty(SecuritySettings.SUPPORT_OLD_PASSWORD_HASH));
// Set up the permissions manager and command handler
permsMan = initializePermissionsManager();
commandHandler = initializeCommandHandler(permsMan, messages, passwordSecurity, newSettings);
// Download and load GeoIp.dat file if absent
GeoLiteAPI.isDataAvailable();
// Set up the mail API
setupMailApi();
// Hooks
// Check Combat Tag Plus Version
checkCombatTagPlus();
// Check Multiverse
checkMultiverse();
// Check Essentials
checkEssentials();
// Check if the ProtocolLib is available. If so we could listen for
// inventory protection
checkProtocolLib();
// End of Hooks
dataManager = new DataManager(this);
ProcessService processService = new ProcessService(newSettings, messages, this);
management = new Management(this, processService, database, PlayerCache.getInstance());
// Set up the BungeeCord hook
setupBungeeCordHook();
// Reload support hook
reloadSupportHook();
Spawn.reload();
// Show settings warnings
showSettingsWarnings();
}
/** /**
* Set up the mail API, if enabled. * Set up the mail API, if enabled.
*/ */

View File

@ -35,29 +35,6 @@ public class JsonCache {
.create(); .create();
} }
public void createCache(Player player, PlayerData playerData) {
if (player == null) {
return;
}
String name = player.getName().toLowerCase();
File file = new File(cacheDir, name + File.separator + "cache.json");
if (file.exists()) {
return;
}
if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) {
return;
}
try {
String data = gson.toJson(playerData);
Files.touch(file);
Files.write(data, file, Charsets.UTF_8);
} catch (IOException e) {
ConsoleLogger.writeStackTrace(e);
}
}
public PlayerData readCache(Player player) { public PlayerData readCache(Player player) {
String name = player.getName().toLowerCase(); String name = player.getName().toLowerCase();
File file = new File(cacheDir, name + File.separator + "cache.json"); File file = new File(cacheDir, name + File.separator + "cache.json");

View File

@ -13,7 +13,6 @@ import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.domain.Property; import fr.xephi.authme.settings.domain.Property;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.io.File;
import java.util.List; import java.util.List;
/** /**
@ -167,15 +166,6 @@ public class CommandService {
return messages.retrieve(key); return messages.retrieve(key);
} }
/**
* Change the messages instance to retrieve messages from the given file.
*
* @param file The new file to read messages from
*/
public void reloadMessages(File file) {
messages.reload(file);
}
/** /**
* Retrieve the given property's value. * Retrieve the given property's value.
* *

View File

@ -5,7 +5,6 @@ import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.CommandService;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.settings.Spawn;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.util.List; import java.util.List;
@ -19,13 +18,7 @@ public class ReloadCommand implements ExecutableCommand {
public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) { public void executeCommand(CommandSender sender, List<String> arguments, CommandService commandService) {
AuthMe plugin = commandService.getAuthMe(); AuthMe plugin = commandService.getAuthMe();
try { try {
commandService.getSettings().reload(); plugin.reloadEntities();
commandService.reloadMessages(commandService.getSettings().getMessagesFile());
Spawn.reload();
// TODO #432: We should not reload only certain plugin entities but actually reinitialize all elements,
// i.e. here in the future we might not have setupDatabase() but Authme.onEnable(), maybe after
// a call to some destructor method
plugin.setupDatabase(commandService.getSettings());
commandService.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS); commandService.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS);
} catch (Exception e) { } catch (Exception e) {
sender.sendMessage("Error occurred during reload of AuthMe: aborting"); sender.sendMessage("Error occurred during reload of AuthMe: aborting");

View File

@ -162,12 +162,6 @@ public class CacheDataSource implements DataSource {
} }
} }
@Override
public void reload() { // unused method
source.reload();
cachedAuths.invalidateAll();
}
@Override @Override
public synchronized boolean updateEmail(final PlayerAuth auth) { public synchronized boolean updateEmail(final PlayerAuth auth) {
boolean result = source.updateEmail(auth); boolean result = source.updateEmail(auth);

View File

@ -121,8 +121,6 @@ public interface DataSource {
*/ */
void close(); void close();
void reload();
/** /**
* Method purgeBanned. * Method purgeBanned.
* *

View File

@ -419,10 +419,6 @@ public class FlatFile implements DataSource {
public synchronized void close() { public synchronized void close() {
} }
@Override
public void reload() {
}
@Override @Override
public boolean updateEmail(PlayerAuth auth) { public boolean updateEmail(PlayerAuth auth) {
if (!isAuthAvailable(auth.getNickname())) { if (!isAuthAvailable(auth.getNickname())) {

View File

@ -3,7 +3,6 @@ package fr.xephi.authme.datasource;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.HikariDataSource;
import com.zaxxer.hikari.pool.HikariPool.PoolInitializationException; import com.zaxxer.hikari.pool.HikariPool.PoolInitializationException;
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.security.HashAlgorithm; import fr.xephi.authme.security.HashAlgorithm;
@ -695,17 +694,6 @@ public class MySQL implements DataSource {
return false; return false;
} }
@Override
public void reload() {
try {
reloadArguments();
} catch (Exception ex) {
ConsoleLogger.logException("Can't reconnect to MySQL database... " +
"Please check your MySQL configuration! Encountered", ex);
AuthMe.getInstance().stopOrUnload();
}
}
@Override @Override
public synchronized void close() { public synchronized void close() {
if (ds != null && !ds.isClosed()) { if (ds != null && !ds.isClosed()) {

View File

@ -359,10 +359,6 @@ public class SQLite implements DataSource {
} }
} }
@Override
public void reload() {
}
private void close(Statement st) { private void close(Statement st) {
if (st != null) { if (st != null) {
try { try {

View File

@ -26,7 +26,7 @@ public class GeoLiteAPI {
} }
/** /**
* Download (if absent) the GeoIpLite data file and then try to load it. * Download (if absent or old) the GeoIpLite data file and then try to load it.
* *
* @return True if the data is available, false otherwise. * @return True if the data is available, false otherwise.
*/ */

View File

@ -10,15 +10,14 @@ import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.process.Management; import fr.xephi.authme.process.Management;
import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.PasswordSecurity;
import fr.xephi.authme.settings.NewSetting; import fr.xephi.authme.settings.NewSetting;
import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.settings.domain.Property; import fr.xephi.authme.settings.domain.Property;
import fr.xephi.authme.settings.properties.SecuritySettings;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.mockito.ArgumentCaptor; import org.mockito.ArgumentCaptor;
import java.io.File;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@ -190,18 +189,6 @@ public class CommandServiceTest {
verify(settings).getProperty(property); verify(settings).getProperty(property);
} }
@Test
public void shouldReloadMessages() {
// given
File file = new File("some/bogus-file.test");
// when
commandService.reloadMessages(file);
// then
verify(messages).reload(file);
}
@Test @Test
public void shouldReturnSettings() { public void shouldReturnSettings() {
// given/when // given/when