From 535c96738d11fb577796a0a5bf67db89b71dcdbe Mon Sep 17 00:00:00 2001 From: Xephi Date: Fri, 25 Jul 2014 02:06:56 +0200 Subject: [PATCH] Add Blindness effect (configurable) --- src/main/java/fr/xephi/authme/commands/AdminCommand.java | 5 ++++- .../java/fr/xephi/authme/commands/LogoutCommand.java | 4 ++++ .../java/fr/xephi/authme/commands/UnregisterCommand.java | 4 ++++ .../fr/xephi/authme/listener/AuthMePlayerListener.java | 4 ++++ .../process/login/ProcessSyncronousPlayerLogin.java | 4 ++++ .../process/register/ProcessSyncronousEmailRegister.java | 3 +++ .../register/ProcessSyncronousPasswordRegister.java | 3 +++ src/main/java/fr/xephi/authme/settings/Settings.java | 9 ++++++++- src/main/resources/config.yml | 2 ++ 9 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/xephi/authme/commands/AdminCommand.java b/src/main/java/fr/xephi/authme/commands/AdminCommand.java index aa6ddd522..f75667a27 100644 --- a/src/main/java/fr/xephi/authme/commands/AdminCommand.java +++ b/src/main/java/fr/xephi/authme/commands/AdminCommand.java @@ -17,11 +17,12 @@ import org.bukkit.OfflinePlayer; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; - import org.bukkit.command.ConsoleCommandSender; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitScheduler; import fr.xephi.authme.AuthMe; @@ -513,6 +514,8 @@ public class AdminCommand implements CommandExecutor { LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); } LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(sched.scheduleSyncDelayedTask(plugin, new MessageTask(plugin, name, m._("reg_msg"), interval))); + if (Settings.applyBlindEffect) + target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2)); m._(target, "unregistered"); } else { // Player isn't online, do nothing else diff --git a/src/main/java/fr/xephi/authme/commands/LogoutCommand.java b/src/main/java/fr/xephi/authme/commands/LogoutCommand.java index 5d2e613f5..98c56abdd 100644 --- a/src/main/java/fr/xephi/authme/commands/LogoutCommand.java +++ b/src/main/java/fr/xephi/authme/commands/LogoutCommand.java @@ -7,6 +7,8 @@ import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitScheduler; import fr.xephi.authme.AuthMe; @@ -104,6 +106,8 @@ public class LogoutCommand implements CommandExecutor { player.getVehicle().eject(); } catch (NullPointerException npe) { } + if (Settings.applyBlindEffect) + player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2)); m._(player, "logout"); ConsoleLogger.info(player.getDisplayName() + " logged out"); if(plugin.notifications != null) { diff --git a/src/main/java/fr/xephi/authme/commands/UnregisterCommand.java b/src/main/java/fr/xephi/authme/commands/UnregisterCommand.java index 39dc9e2b0..fea1a6fbc 100644 --- a/src/main/java/fr/xephi/authme/commands/UnregisterCommand.java +++ b/src/main/java/fr/xephi/authme/commands/UnregisterCommand.java @@ -10,6 +10,8 @@ import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitScheduler; import fr.xephi.authme.AuthMe; @@ -108,6 +110,8 @@ public class UnregisterCommand implements CommandExecutor { if(playerCache.doesCacheExist(name)) { playerCache.removeCache(name); } + if (Settings.applyBlindEffect) + player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2)); m._(player, "unregistered"); ConsoleLogger.info(player.getDisplayName() + " unregistered himself"); if(plugin.notifications != null) { diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index 5a6ee3bbd..ad4988ca8 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -34,6 +34,8 @@ import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerRespawnEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitScheduler; import fr.xephi.authme.AuthMe; @@ -711,6 +713,8 @@ public class AuthMePlayerListener implements Listener { player.setNoDamageTicks(Settings.getRegistrationTimeout * 20); if (Settings.useEssentialsMotd) player.performCommand("motd"); + if (Settings.applyBlindEffect) + player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2)); // Remove the join message while the player isn't logging in if (Settings.enableProtection || Settings.delayJoinMessage) { diff --git a/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java b/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java index 56c4e80c2..d409dfbe9 100644 --- a/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java +++ b/src/main/java/fr/xephi/authme/process/login/ProcessSyncronousPlayerLogin.java @@ -5,6 +5,7 @@ import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Player; import org.bukkit.plugin.PluginManager; +import org.bukkit.potion.PotionEffectType; import fr.xephi.authme.AuthMe; import fr.xephi.authme.Utils; @@ -172,6 +173,9 @@ public class ProcessSyncronousPlayerLogin implements Runnable { AuthMePlayerListener.joinMessage.remove(name); } + if (Settings.applyBlindEffect) + player.removePotionEffect(PotionEffectType.BLINDNESS); + // The Loginevent now fires (as intended) after everything is processed Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player, true)); player.saveData(); diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousEmailRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousEmailRegister.java index fa42713cc..cd3875933 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousEmailRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousEmailRegister.java @@ -6,6 +6,7 @@ import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffectType; import fr.xephi.authme.AuthMe; import fr.xephi.authme.ConsoleLogger; @@ -61,6 +62,8 @@ public class ProcessSyncronousEmailRegister implements Runnable { player.setAllowFlight(false); player.setFlying(false); } + if (Settings.applyBlindEffect) + player.removePotionEffect(PotionEffectType.BLINDNESS); player.saveData(); if (!Settings.noConsoleSpam) ConsoleLogger.info(player.getName() + " registered "+plugin.getIP(player)); diff --git a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java index 5730c28f7..de5001510 100644 --- a/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java +++ b/src/main/java/fr/xephi/authme/process/register/ProcessSyncronousPasswordRegister.java @@ -6,6 +6,7 @@ import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffectType; import org.bukkit.scheduler.BukkitScheduler; import fr.xephi.authme.AuthMe; @@ -104,6 +105,8 @@ public class ProcessSyncronousPasswordRegister implements Runnable { player.setAllowFlight(false); player.setFlying(false); } + if (Settings.applyBlindEffect) + player.removePotionEffect(PotionEffectType.BLINDNESS); // The Loginevent now fires (as intended) after everything is processed Bukkit.getServer().getPluginManager().callEvent(new LoginEvent(player, true)); player.saveData(); diff --git a/src/main/java/fr/xephi/authme/settings/Settings.java b/src/main/java/fr/xephi/authme/settings/Settings.java index 756a2fbf6..7fe72cc42 100644 --- a/src/main/java/fr/xephi/authme/settings/Settings.java +++ b/src/main/java/fr/xephi/authme/settings/Settings.java @@ -60,7 +60,7 @@ public final class Settings extends YamlConfiguration { usePurge, purgePlayerDat, purgeEssentialsFile, supportOldPassword, purgeLimitedCreative, purgeAntiXray, purgePermissions, enableProtection, enableAntiBot, recallEmail, useWelcomeMessage, broadcastWelcomeMessage, forceRegKick, forceRegLogin, checkVeryGames, delayJoinMessage, - noTeleport; + noTeleport, applyBlindEffect; public static String getNickRegex, getUnloggedinGroup, getMySQLHost, getMySQLPort, getMySQLUsername, getMySQLPassword, getMySQLDatabase, getMySQLTablename, @@ -248,6 +248,7 @@ public void loadConfigOptions() { noTeleport = configFile.getBoolean("settings.restrictions.noTeleport", false); crazyloginFileName = configFile.getString("Converter.CrazyLogin.fileName", "accounts.db"); getPassRegex = configFile.getString("settings.restrictions.allowedPasswordCharacters","[a-zA-Z0-9_?!@+&-]*"); + applyBlindEffect = configFile.getBoolean("settings.applyBlindEffect", false); // Load the welcome message getWelcomeMessage(plugin); @@ -410,6 +411,7 @@ public static void reloadConfigOptions(YamlConfiguration newConfig) { noTeleport = configFile.getBoolean("settings.restrictions.noTeleport", false); crazyloginFileName = configFile.getString("Converter.CrazyLogin.fileName", "accounts.db"); getPassRegex = configFile.getString("settings.restrictions.allowedPasswordCharacters","[a-zA-Z0-9_?!@+&-]*"); + applyBlindEffect = configFile.getBoolean("settings.applyBlindEffect", false); // Reload the welcome message getWelcomeMessage(AuthMe.getInstance()); @@ -528,6 +530,11 @@ public static void reloadConfigOptions(YamlConfiguration newConfig) { } if(!contains("settings.restrictions.allowedPasswordCharacters")) { set("settings.restrictions.allowedPasswordCharacters", "[a-zA-Z0-9_?!@+&-]*"); + changes = true; + } + if(!contains("settings.applyBlindEffect")) { + set("settings.applyBlindEffect", false); + changes = true; } if (changes) { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 8e9c5243b..c03e22ac9 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -260,6 +260,8 @@ settings: broadcastWelcomeMessage: false # Do we need to delay the X has joined the game after /login ? delayJoinMessage: false + # Do we need to add potion effect Blinding before login/register ? + applyBlindEffect: false ExternalBoardOptions: # MySQL column for the salt , needed for some forum/cms support mySQLColumnSalt: ''