From e272a3bfb5ae15e7fe084573780ba8f18e3492bf Mon Sep 17 00:00:00 2001 From: Xephi Date: Mon, 21 Dec 2015 12:04:28 +0100 Subject: [PATCH] Add a way to kick players before a server stop --- src/main/java/fr/xephi/authme/AuthMe.java | 8 +++++++ .../authme/listener/AuthMeServerStop.java | 23 +++++++++++++++++++ .../fr/xephi/authme/settings/Settings.java | 7 ++++++ src/main/resources/config.yml | 4 ++++ 4 files changed, 42 insertions(+) create mode 100644 src/main/java/fr/xephi/authme/listener/AuthMeServerStop.java diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index 6a25a5325..d53fb6b11 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -27,6 +27,7 @@ import fr.xephi.authme.listener.AuthMePlayerListener; import fr.xephi.authme.listener.AuthMePlayerListener16; import fr.xephi.authme.listener.AuthMePlayerListener18; import fr.xephi.authme.listener.AuthMeServerListener; +import fr.xephi.authme.listener.AuthMeServerStop; import fr.xephi.authme.modules.ModuleManager; import fr.xephi.authme.output.ConsoleFilter; import fr.xephi.authme.output.Log4JFilter; @@ -288,6 +289,13 @@ public class AuthMe extends JavaPlugin { // Show settings warnings showSettingsWarnings(); + // Register a server shutdown hook + try { + Runtime.getRuntime().addShutdownHook(new AuthMeServerStop(this)); + } catch (Exception e){ + e.printStackTrace(); + } + // Sponsor messages ConsoleLogger.info("AuthMe hooks perfectly with the VeryGames server hosting!"); ConsoleLogger.info("Development builds are available on our jenkins, thanks to f14stelt."); diff --git a/src/main/java/fr/xephi/authme/listener/AuthMeServerStop.java b/src/main/java/fr/xephi/authme/listener/AuthMeServerStop.java new file mode 100644 index 000000000..86697191a --- /dev/null +++ b/src/main/java/fr/xephi/authme/listener/AuthMeServerStop.java @@ -0,0 +1,23 @@ +package fr.xephi.authme.listener; + +import org.bukkit.entity.Player; + +import fr.xephi.authme.AuthMe; +import fr.xephi.authme.settings.Settings; + +public class AuthMeServerStop extends Thread { + + private AuthMe plugin; + + public AuthMeServerStop(AuthMe plugin) + { + this.plugin = plugin; + } + + public void run() { + // TODO: add a MessageKey + if (Settings.kickPlayersBeforeStoping) + for (Player p : plugin.getServer().getOnlinePlayers()) + p.kickPlayer("Server is restarting"); + } +} diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index 58fde0cc4..7714eb4db 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -79,6 +79,7 @@ public final class Settings { enableProtection, enableAntiBot, recallEmail, useWelcomeMessage, broadcastWelcomeMessage, forceRegKick, forceRegLogin, checkVeryGames, delayJoinLeaveMessages, noTeleport, applyBlindEffect, + kickPlayersBeforeStoping, customAttributes, generateImage, isRemoveSpeedEnabled, preventOtherCase; public static String helpHeader, getNickRegex, getUnloggedinGroup, getMySQLHost, getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase, @@ -300,6 +301,7 @@ public final class Settings { customAttributes = configFile.getBoolean("Hooks.customAttributes"); generateImage = configFile.getBoolean("Email.generateImage", false); preventOtherCase = configFile.getBoolean("settings.preventOtherCase", false); + kickPlayersBeforeStoping = configFile.getBoolean("Security.stop.kickPlayersBeforeStoping", true); // Load the welcome message getWelcomeMessage(); @@ -727,6 +729,11 @@ public final class Settings { ConsoleLogger.showError("Remove Email.mailText from config, we now use the email.html file"); } + if (!contains("Security.stop.kickPlayersBeforeStoping")) { + set("Security.stop.kickPlayersBeforeStoping", true); + changed = true; + } + if (changes) { plugin.getLogger().warning("Merged new Config Options - I'm not an error, please don't report me"); plugin.getLogger().warning("Please check your config.yml file for new configs!"); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 344df77ce..25988de23 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -316,6 +316,10 @@ Security: maxLoginTry: 5 # Captcha length captchaLength: 5 + stop: + # Kick players before stoping the server, that allow us to save position of players, and all needed + # informations correctly without any corruption. + kickPlayersBeforeStoping: true Converter: Rakamak: # Rakamak file name