Add a way to kick players before a server stop

This commit is contained in:
Xephi 2015-12-21 12:04:28 +01:00
parent 5c2547cd82
commit e272a3bfb5
4 changed files with 42 additions and 0 deletions

View File

@ -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.");

View File

@ -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");
}
}

View File

@ -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!");

View File

@ -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