From 717f962473f372d42e51c84f45427baca8a7696e Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Sat, 5 Mar 2016 18:16:57 +0100 Subject: [PATCH 1/4] Revert "Add a message about the workaround with MC 1.9" This reverts commit aa914b9aa7f92300899957024123ddf0f49177f6. --- src/main/java/fr/xephi/authme/AuthMe.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index cff146830..571fdbbe5 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -242,8 +242,6 @@ public class AuthMe extends JavaPlugin { try { setupDatabase(newSettings); } 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! " + "Authme initialization aborted!", e); stopOrUnload(); From 9b13366e5f0e0afd1e96bbe1b5384e99f9803fc1 Mon Sep 17 00:00:00 2001 From: FabioZumbi12 Date: Sat, 5 Mar 2016 16:11:09 -0300 Subject: [PATCH 2/4] To use local shooter --- .../authme/listener/AuthMeEntityListener.java | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java index c5c0b2a68..ac2358d8c 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java @@ -1,6 +1,5 @@ package fr.xephi.authme.listener; -import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; @@ -16,22 +15,11 @@ import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.projectiles.ProjectileSource; -import java.lang.reflect.Method; - import static fr.xephi.authme.listener.ListenerService.shouldCancelEvent; public class AuthMeEntityListener implements Listener { - private static Method getShooter; - private static boolean shooterIsProjectileSource; - - public AuthMeEntityListener() { - try { - Method m = Projectile.class.getDeclaredMethod("getShooter"); - shooterIsProjectileSource = m.getReturnType() != LivingEntity.class; - } catch (Exception ignored) { - } - } + public AuthMeEntityListener() {} // TODO #360: npc status can be used to bypass security!!! @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) @@ -96,22 +84,12 @@ public class AuthMeEntityListener implements Listener { Player player = null; Projectile projectile = event.getEntity(); - if (shooterIsProjectileSource) { + if (projectile != null && (projectile.getShooter() instanceof ProjectileSource)) { ProjectileSource shooter = projectile.getShooter(); if (shooter == null || !(shooter instanceof Player)) { return; } player = (Player) shooter; - } else { - // TODO ljacqu 20151220: Invoking getShooter() with null but method isn't static - try { - if (getShooter == null) { - getShooter = Projectile.class.getMethod("getShooter"); - } - Object obj = getShooter.invoke(null); - player = (Player) obj; - } catch (Exception ignored) { - } } if (ListenerService.shouldCancelEvent(player)) { From 9a5c84f3fc35fac6770d238dac5d2d5b7caefd11 Mon Sep 17 00:00:00 2001 From: Gabriele C Date: Sat, 5 Mar 2016 21:33:56 +0100 Subject: [PATCH 3/4] Revert "Use local shooter" --- .../authme/listener/AuthMeEntityListener.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java b/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java index ac2358d8c..c5c0b2a68 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMeEntityListener.java @@ -1,5 +1,6 @@ package fr.xephi.authme.listener; +import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Projectile; import org.bukkit.event.EventHandler; @@ -15,11 +16,22 @@ import org.bukkit.event.entity.FoodLevelChangeEvent; import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.projectiles.ProjectileSource; +import java.lang.reflect.Method; + import static fr.xephi.authme.listener.ListenerService.shouldCancelEvent; public class AuthMeEntityListener implements Listener { - public AuthMeEntityListener() {} + private static Method getShooter; + private static boolean shooterIsProjectileSource; + + public AuthMeEntityListener() { + try { + Method m = Projectile.class.getDeclaredMethod("getShooter"); + shooterIsProjectileSource = m.getReturnType() != LivingEntity.class; + } catch (Exception ignored) { + } + } // TODO #360: npc status can be used to bypass security!!! @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) @@ -84,12 +96,22 @@ public class AuthMeEntityListener implements Listener { Player player = null; Projectile projectile = event.getEntity(); - if (projectile != null && (projectile.getShooter() instanceof ProjectileSource)) { + if (shooterIsProjectileSource) { ProjectileSource shooter = projectile.getShooter(); if (shooter == null || !(shooter instanceof Player)) { return; } player = (Player) shooter; + } else { + // TODO ljacqu 20151220: Invoking getShooter() with null but method isn't static + try { + if (getShooter == null) { + getShooter = Projectile.class.getMethod("getShooter"); + } + Object obj = getShooter.invoke(null); + player = (Player) obj; + } catch (Exception ignored) { + } } if (ListenerService.shouldCancelEvent(player)) { From 98df21d75a7699a3faf50ecf3c10afab83d77f10 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sat, 5 Mar 2016 22:30:35 +0100 Subject: [PATCH 4/4] #575 Hotfix for reload support - Create temporary method for reloading any stateful entities -> a lot of duplicated code, to be fixed soon within #432 - Remove unused methods --- src/main/java/fr/xephi/authme/AuthMe.java | 85 +++++++++++++++++++ .../xephi/authme/cache/backup/JsonCache.java | 23 ----- .../xephi/authme/command/CommandService.java | 10 --- .../executable/authme/ReloadCommand.java | 9 +- .../authme/datasource/CacheDataSource.java | 6 -- .../xephi/authme/datasource/DataSource.java | 2 - .../fr/xephi/authme/datasource/FlatFile.java | 4 - .../fr/xephi/authme/datasource/MySQL.java | 12 --- .../fr/xephi/authme/datasource/SQLite.java | 4 - .../java/fr/xephi/authme/util/GeoLiteAPI.java | 2 +- .../authme/command/CommandServiceTest.java | 15 +--- 11 files changed, 88 insertions(+), 84 deletions(-) diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 571fdbbe5..688213cf7 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -330,6 +330,91 @@ public class AuthMe extends JavaPlugin { 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. */ diff --git a/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java b/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java index 177ccce56..81e305432 100644 --- a/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java +++ b/src/main/java/fr/xephi/authme/cache/backup/JsonCache.java @@ -35,29 +35,6 @@ public class JsonCache { .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) { String name = player.getName().toLowerCase(); File file = new File(cacheDir, name + File.separator + "cache.json"); diff --git a/src/main/java/fr/xephi/authme/command/CommandService.java b/src/main/java/fr/xephi/authme/command/CommandService.java index 5b8b5e490..5a9378dba 100644 --- a/src/main/java/fr/xephi/authme/command/CommandService.java +++ b/src/main/java/fr/xephi/authme/command/CommandService.java @@ -12,7 +12,6 @@ import fr.xephi.authme.settings.NewSetting; import fr.xephi.authme.settings.domain.Property; import org.bukkit.command.CommandSender; -import java.io.File; import java.util.List; /** @@ -163,15 +162,6 @@ public class CommandService { 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. * diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java index 0c7adf2ff..7353abc73 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/ReloadCommand.java @@ -5,7 +5,6 @@ import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.output.MessageKey; -import fr.xephi.authme.settings.Spawn; import org.bukkit.command.CommandSender; import java.util.List; @@ -19,13 +18,7 @@ public class ReloadCommand implements ExecutableCommand { public void executeCommand(CommandSender sender, List arguments, CommandService commandService) { AuthMe plugin = commandService.getAuthMe(); try { - commandService.getSettings().reload(); - 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()); + plugin.reloadEntities(); commandService.send(sender, MessageKey.CONFIG_RELOAD_SUCCESS); } catch (Exception e) { sender.sendMessage("Error occurred during reload of AuthMe: aborting"); diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index ad02c99f2..bb6049fa3 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -162,12 +162,6 @@ public class CacheDataSource implements DataSource { } } - @Override - public void reload() { // unused method - source.reload(); - cachedAuths.invalidateAll(); - } - @Override public synchronized boolean updateEmail(final PlayerAuth auth) { boolean result = source.updateEmail(auth); diff --git a/src/main/java/fr/xephi/authme/datasource/DataSource.java b/src/main/java/fr/xephi/authme/datasource/DataSource.java index 6e3bc09b4..29157480b 100644 --- a/src/main/java/fr/xephi/authme/datasource/DataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/DataSource.java @@ -121,8 +121,6 @@ public interface DataSource { */ void close(); - void reload(); - /** * Method purgeBanned. * diff --git a/src/main/java/fr/xephi/authme/datasource/FlatFile.java b/src/main/java/fr/xephi/authme/datasource/FlatFile.java index 72b301842..10f8a9a09 100644 --- a/src/main/java/fr/xephi/authme/datasource/FlatFile.java +++ b/src/main/java/fr/xephi/authme/datasource/FlatFile.java @@ -419,10 +419,6 @@ public class FlatFile implements DataSource { public synchronized void close() { } - @Override - public void reload() { - } - @Override public boolean updateEmail(PlayerAuth auth) { if (!isAuthAvailable(auth.getNickname())) { diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index 84927fe64..7d21fa856 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -3,7 +3,6 @@ package fr.xephi.authme.datasource; import com.google.common.annotations.VisibleForTesting; import com.zaxxer.hikari.HikariDataSource; import com.zaxxer.hikari.pool.HikariPool.PoolInitializationException; -import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.security.HashAlgorithm; @@ -695,17 +694,6 @@ public class MySQL implements DataSource { 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 public synchronized void close() { if (ds != null && !ds.isClosed()) { diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index 2868a59a6..d526bc858 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -359,10 +359,6 @@ public class SQLite implements DataSource { } } - @Override - public void reload() { - } - private void close(Statement st) { if (st != null) { try { diff --git a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java b/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java index f878d85a7..002eeb655 100644 --- a/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java +++ b/src/main/java/fr/xephi/authme/util/GeoLiteAPI.java @@ -23,7 +23,7 @@ public class GeoLiteAPI { private static Thread downloadTask; /** - * 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. */ diff --git a/src/test/java/fr/xephi/authme/command/CommandServiceTest.java b/src/test/java/fr/xephi/authme/command/CommandServiceTest.java index 929fd26a1..32c9825d1 100644 --- a/src/test/java/fr/xephi/authme/command/CommandServiceTest.java +++ b/src/test/java/fr/xephi/authme/command/CommandServiceTest.java @@ -9,15 +9,14 @@ import fr.xephi.authme.permission.PermissionsManager; import fr.xephi.authme.process.Management; import fr.xephi.authme.security.PasswordSecurity; 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.properties.SecuritySettings; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; -import java.io.File; import java.util.Arrays; import java.util.List; @@ -187,18 +186,6 @@ public class CommandServiceTest { 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 public void shouldReturnSettings() { // given/when