Change calls to Messages to use the MessageKey enum

This commit is contained in:
ljacqu 2015-11-24 23:27:28 +01:00
parent cb11ae9610
commit d2b3d416a9
5 changed files with 47 additions and 80 deletions

View File

@ -1,5 +1,6 @@
package fr.xephi.authme; package fr.xephi.authme;
import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -47,7 +48,7 @@ public class AntiBot {
public static void activateAntiBot() { public static void activateAntiBot() {
antiBotStatus = AntiBotStatus.ACTIVE; antiBotStatus = AntiBotStatus.ACTIVE;
for (String s : messages.send("antibot_auto_enabled")) { for (String s : messages.retrieve(MessageKey.ANTIBOT_AUTO_ENABLED_MESSAGE)) {
Bukkit.broadcastMessage(s); Bukkit.broadcastMessage(s);
} }
@ -57,18 +58,14 @@ public class AntiBot {
if (antiBotStatus == AntiBotStatus.ACTIVE) { if (antiBotStatus == AntiBotStatus.ACTIVE) {
antiBotStatus = AntiBotStatus.LISTENING; antiBotStatus = AntiBotStatus.LISTENING;
antibotPlayers.clear(); antibotPlayers.clear();
for (String s : messages.send("antibot_auto_disabled")) for (String s : messages.retrieve(MessageKey.ANTIBOT_AUTO_DISABLED_MESSAGE)) {
Bukkit.broadcastMessage(s.replace("%m", "" + Settings.antiBotDuration)); Bukkit.broadcastMessage(s.replace("%m", "" + Settings.antiBotDuration));
}
} }
} }
}, Settings.antiBotDuration * 1200); }, Settings.antiBotDuration * 1200);
} }
/**
* Method checkAntiBotMod.
*
* @param player Player
*/
public static void checkAntiBot(final Player player) { public static void checkAntiBot(final Player player) {
if (antiBotStatus == AntiBotStatus.ACTIVE || antiBotStatus == AntiBotStatus.DISABLED) { if (antiBotStatus == AntiBotStatus.ACTIVE || antiBotStatus == AntiBotStatus.DISABLED) {
return; return;

View File

@ -6,6 +6,7 @@ import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.cache.limbo.LimboCache; import fr.xephi.authme.cache.limbo.LimboCache;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.task.MessageTask; import fr.xephi.authme.task.MessageTask;
@ -46,18 +47,17 @@ public class UnregisterCommand extends ExecutableCommand {
// Make sure the user is valid // Make sure the user is valid
if (!plugin.database.isAuthAvailable(playerNameLowerCase)) { if (!plugin.database.isAuthAvailable(playerNameLowerCase)) {
m.send(sender, "user_unknown"); m.send(sender, MessageKey.UNKNOWN_USER);
return true; return true;
} }
// Remove the player // Remove the player
if (!plugin.database.removeAuth(playerNameLowerCase)) { if (!plugin.database.removeAuth(playerNameLowerCase)) {
m.send(sender, "error"); m.send(sender, MessageKey.ERROR);
return true; return true;
} }
// Unregister the player // Unregister the player
@SuppressWarnings("deprecation")
Player target = Bukkit.getPlayer(playerNameLowerCase); Player target = Bukkit.getPlayer(playerNameLowerCase);
PlayerCache.getInstance().removePlayer(playerNameLowerCase); PlayerCache.getInstance().removePlayer(playerNameLowerCase);
Utils.setGroup(target, Utils.GroupType.UNREGISTERED); Utils.setGroup(target, Utils.GroupType.UNREGISTERED);
@ -71,19 +71,21 @@ public class UnregisterCommand extends ExecutableCommand {
BukkitTask id = scheduler.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, playerNameLowerCase, target), delay); BukkitTask id = scheduler.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, playerNameLowerCase, target), delay);
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setTimeoutTaskId(id); LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setTimeoutTaskId(id);
} }
LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTaskId(scheduler.runTaskAsynchronously(plugin, new MessageTask(plugin, playerNameLowerCase, m.send("reg_msg"), interval))); LimboCache.getInstance().getLimboPlayer(playerNameLowerCase).setMessageTaskId(
scheduler.runTaskAsynchronously(plugin,
new MessageTask(plugin, playerNameLowerCase, m.retrieve(MessageKey.REGISTER_MESSAGE), interval)));
if (Settings.applyBlindEffect) if (Settings.applyBlindEffect)
target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2)); target.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2));
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) { if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
target.setWalkSpeed(0.0f); target.setWalkSpeed(0.0f);
target.setFlySpeed(0.0f); target.setFlySpeed(0.0f);
} }
m.send(target, "unregistered"); m.send(target, MessageKey.UNREGISTERED_SUCCESS);
} }
// Show a status message // Show a status message
m.send(sender, "unregistered"); m.send(sender, MessageKey.UNREGISTERED_SUCCESS);
ConsoleLogger.info(playerName + " unregistered"); ConsoleLogger.info(playerName + " unregistered");
return true; return true;
} }

View File

@ -5,6 +5,7 @@ import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.command.CommandParts; import fr.xephi.authme.command.CommandParts;
import fr.xephi.authme.command.ExecutableCommand; import fr.xephi.authme.command.ExecutableCommand;
import fr.xephi.authme.security.RandomString; import fr.xephi.authme.security.RandomString;
import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -14,15 +15,6 @@ import org.bukkit.entity.Player;
*/ */
public class CaptchaCommand extends ExecutableCommand { public class CaptchaCommand extends ExecutableCommand {
/**
* Execute the command.
*
* @param sender The command sender.
* @param commandReference The command reference.
* @param commandArguments The command arguments.
*
* @return True if the command was executed successfully, false otherwise.
*/
@Override @Override
public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) { public boolean executeCommand(CommandSender sender, CommandParts commandReference, CommandParts commandArguments) {
// Make sure the current command executor is a player // Make sure the current command executor is a player
@ -42,12 +34,12 @@ public class CaptchaCommand extends ExecutableCommand {
// Command logic // Command logic
if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) { if (PlayerCache.getInstance().isAuthenticated(playerNameLowerCase)) {
m.send(player, "logged_in"); m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
return true; return true;
} }
if (!Settings.useCaptcha) { if (!Settings.useCaptcha) {
m.send(player, "usage_log"); m.send(player, MessageKey.USAGE_LOGIN);
return true; return true;
} }
@ -55,7 +47,7 @@ public class CaptchaCommand extends ExecutableCommand {
final AuthMe plugin = AuthMe.getInstance(); final AuthMe plugin = AuthMe.getInstance();
if (!plugin.cap.containsKey(playerNameLowerCase)) { if (!plugin.cap.containsKey(playerNameLowerCase)) {
m.send(player, "usage_log"); m.send(player, MessageKey.USAGE_LOGIN);
return true; return true;
} }
@ -63,7 +55,7 @@ public class CaptchaCommand extends ExecutableCommand {
plugin.cap.remove(playerNameLowerCase); plugin.cap.remove(playerNameLowerCase);
String randStr = new RandomString(Settings.captchaLength).nextString(); String randStr = new RandomString(Settings.captchaLength).nextString();
plugin.cap.put(playerNameLowerCase, randStr); plugin.cap.put(playerNameLowerCase, randStr);
for (String s : m.send("wrong_captcha")) { for (String s : m.retrieve(MessageKey.CAPTCHA_WRONG_ERROR)) {
player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(playerNameLowerCase))); player.sendMessage(s.replace("THE_CAPTCHA", plugin.cap.get(playerNameLowerCase)));
} }
return true; return true;
@ -73,8 +65,8 @@ public class CaptchaCommand extends ExecutableCommand {
plugin.cap.remove(playerNameLowerCase); plugin.cap.remove(playerNameLowerCase);
// Show a status message // Show a status message
m.send(player, "valid_captcha"); m.send(player, MessageKey.CAPTCHA_SUCCESS);
m.send(player, "login_msg"); m.send(player, MessageKey.LOGIN_MESSAGE);
return true; return true;
} }
} }

View File

@ -4,6 +4,7 @@ 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.cache.auth.PlayerCache; import fr.xephi.authme.cache.auth.PlayerCache;
import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -21,15 +22,6 @@ public class AsyncChangeEmail {
private final String newEmailVerify; private final String newEmailVerify;
private final Messages m; private final Messages m;
/**
* Constructor for AsyncChangeEmail.
*
* @param player Player
* @param plugin AuthMe
* @param oldEmail String
* @param newEmail String
* @param newEmailVerify String
*/
public AsyncChangeEmail(Player player, AuthMe plugin, String oldEmail, String newEmail, String newEmailVerify) { public AsyncChangeEmail(Player player, AuthMe plugin, String oldEmail, String newEmail, String newEmailVerify) {
this.player = player; this.player = player;
this.plugin = plugin; this.plugin = plugin;
@ -39,14 +31,6 @@ public class AsyncChangeEmail {
this.m = Messages.getInstance(); this.m = Messages.getInstance();
} }
/**
* Constructor for AsyncChangeEmail.
*
* @param player Player
* @param plugin AuthMe
* @param oldEmail String
* @param newEmail String
*/
public AsyncChangeEmail(Player player, AuthMe plugin, String oldEmail, String newEmail) { public AsyncChangeEmail(Player player, AuthMe plugin, String oldEmail, String newEmail) {
this(player, plugin, oldEmail, newEmail, newEmail); this(player, plugin, oldEmail, newEmail, newEmail);
} }
@ -56,7 +40,9 @@ public class AsyncChangeEmail {
String playerName = player.getName().toLowerCase(); String playerName = player.getName().toLowerCase();
if (Settings.getmaxRegPerEmail > 0) { if (Settings.getmaxRegPerEmail > 0) {
if (!plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts") && plugin.database.getAllAuthsByEmail(newEmail).size() >= Settings.getmaxRegPerEmail) { if (!plugin.getPermissionsManager().hasPermission(player, "authme.allow2accounts")
&& plugin.database.getAllAuthsByEmail(newEmail).size() >= Settings.getmaxRegPerEmail) {
// TODO ljacqu 20151124: max_reg is not in enum
m.send(player, "max_reg"); m.send(player, "max_reg");
return; return;
} }
@ -64,53 +50,54 @@ public class AsyncChangeEmail {
if (PlayerCache.getInstance().isAuthenticated(playerName)) { if (PlayerCache.getInstance().isAuthenticated(playerName)) {
if (!newEmail.equals(newEmailVerify)) { if (!newEmail.equals(newEmailVerify)) {
m.send(player, "email_confirm"); m.send(player, MessageKey.CONFIRM_EMAIL_MESSAGE);
return; return;
} }
PlayerAuth auth = PlayerCache.getInstance().getAuth(playerName); PlayerAuth auth = PlayerCache.getInstance().getAuth(playerName);
if (oldEmail != null) { if (oldEmail != null) {
if (auth.getEmail() == null || auth.getEmail().equals("your@email.com") || auth.getEmail().isEmpty()) { if (auth.getEmail() == null || auth.getEmail().equals("your@email.com") || auth.getEmail().isEmpty()) {
m.send(player, "usage_email_add"); m.send(player, MessageKey.USAGE_ADD_EMAIL);
return; return;
} }
if (!oldEmail.equals(auth.getEmail())) { if (!oldEmail.equals(auth.getEmail())) {
m.send(player, "old_email_invalid"); m.send(player, MessageKey.INVALID_OLD_EMAIL);
return; return;
} }
} }
if (!Settings.isEmailCorrect(newEmail)) { if (!Settings.isEmailCorrect(newEmail)) {
m.send(player, "new_email_invalid"); m.send(player, MessageKey.INVALID_NEW_EMAIL);
return; return;
} }
String old = auth.getEmail(); String old = auth.getEmail();
auth.setEmail(newEmail); auth.setEmail(newEmail);
if (!plugin.database.updateEmail(auth)) { if (!plugin.database.updateEmail(auth)) {
m.send(player, "error"); m.send(player, MessageKey.ERROR);
auth.setEmail(old); auth.setEmail(old);
return; return;
} }
PlayerCache.getInstance().updatePlayer(auth); PlayerCache.getInstance().updatePlayer(auth);
if (oldEmail == null) { if (oldEmail == null) {
m.send(player, "email_added"); m.send(player, MessageKey.EMAIL_ADDED_SUCCESS);
player.sendMessage(auth.getEmail()); player.sendMessage(auth.getEmail());
return; return;
} }
m.send(player, "email_changed"); m.send(player, MessageKey.EMAIL_CHANGED_SUCCESS);
// TODO ljacqu 20151124: Did I really miss "email_defined" or is it not present in the 'en' messages?
player.sendMessage(Arrays.toString(m.send("email_defined")) + auth.getEmail()); player.sendMessage(Arrays.toString(m.send("email_defined")) + auth.getEmail());
} else { } else {
if (plugin.database.isAuthAvailable(playerName)) { if (plugin.database.isAuthAvailable(playerName)) {
m.send(player, "login_msg"); m.send(player, MessageKey.LOGIN_MESSAGE);
} else { } else {
if (Settings.emailRegistration) if (Settings.emailRegistration)
m.send(player, "reg_email_msg"); m.send(player, MessageKey.REGISTER_EMAIL_MESSAGE);
else else
m.send(player, "reg_msg"); m.send(player, MessageKey.REGISTER_MESSAGE);
} }
} }
} catch (Exception e) { } catch (Exception e) {
ConsoleLogger.showError(e.getMessage()); ConsoleLogger.showError(e.getMessage());
ConsoleLogger.writeStackTrace(e); ConsoleLogger.writeStackTrace(e);
m.send(player, "error"); m.send(player, MessageKey.ERROR);
} }
} }
} }

View File

@ -10,6 +10,7 @@ import fr.xephi.authme.events.FirstSpawnTeleportEvent;
import fr.xephi.authme.events.ProtectInventoryEvent; import fr.xephi.authme.events.ProtectInventoryEvent;
import fr.xephi.authme.events.SpawnTeleportEvent; import fr.xephi.authme.events.SpawnTeleportEvent;
import fr.xephi.authme.listener.AuthMePlayerListener; import fr.xephi.authme.listener.AuthMePlayerListener;
import fr.xephi.authme.settings.MessageKey;
import fr.xephi.authme.settings.Messages; import fr.xephi.authme.settings.Messages;
import fr.xephi.authme.settings.Settings; import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.Spawn; import fr.xephi.authme.settings.Spawn;
@ -38,13 +39,6 @@ public class AsynchronousJoin {
private final Messages m; private final Messages m;
private final BukkitScheduler sched; private final BukkitScheduler sched;
/**
* Constructor for AsynchronousJoin.
*
* @param player Player
* @param plugin AuthMe
* @param database DataSource
*/
public AsynchronousJoin(Player player, AuthMe plugin, DataSource database) { public AsynchronousJoin(Player player, AuthMe plugin, DataSource database) {
this.player = player; this.player = player;
this.plugin = plugin; this.plugin = plugin;
@ -239,25 +233,26 @@ public class AsynchronousJoin {
database.setUnlogged(name); database.setUnlogged(name);
PlayerCache.getInstance().removePlayer(name); PlayerCache.getInstance().removePlayer(name);
if (auth != null && auth.getIp().equals(ip)) { if (auth != null && auth.getIp().equals(ip)) {
m.send(player, "valid_session"); m.send(player, MessageKey.SESSION_RECONNECTION);
plugin.management.performLogin(player, "dontneed", true); plugin.management.performLogin(player, "dontneed", true);
return; return;
} else if (Settings.sessionExpireOnIpChange) { } else if (Settings.sessionExpireOnIpChange) {
m.send(player, "invalid_session"); m.send(player, MessageKey.SESSION_EXPIRED);
} }
} }
String[] msg = isAuthAvailable ? m.send("login_msg") : String[] msg;
m.send("reg_" + (Settings.emailRegistration ? "email_" : "") + "msg"); if (isAuthAvailable) {
msg = m.retrieve(MessageKey.LOGIN_MESSAGE);
} else {
msg = Settings.emailRegistration
? m.retrieve(MessageKey.REGISTER_EMAIL_MESSAGE)
: m.retrieve(MessageKey.REGISTER_MESSAGE);
}
BukkitTask msgTask = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, msgInterval)); BukkitTask msgTask = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, msgInterval));
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgTask); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgTask);
} }
/**
* Method needFirstSpawn.
*
* @return boolean
*/
private boolean needFirstSpawn() { private boolean needFirstSpawn() {
if (player.hasPlayedBefore()) if (player.hasPlayedBefore())
return false; return false;
@ -282,12 +277,6 @@ public class AsynchronousJoin {
return true; return true;
} }
/**
* Method placePlayerSafely.
*
* @param player Player
* @param spawnLoc Location
*/
private void placePlayerSafely(final Player player, final Location spawnLoc) { private void placePlayerSafely(final Player player, final Location spawnLoc) {
if (spawnLoc == null) if (spawnLoc == null)
return; return;
@ -307,7 +296,7 @@ public class AsynchronousJoin {
Material top = player.getLocation().add(0D, 1D, 0D).getBlock().getType(); Material top = player.getLocation().add(0D, 1D, 0D).getBlock().getType();
if (cur == Material.PORTAL || cur == Material.ENDER_PORTAL if (cur == Material.PORTAL || cur == Material.ENDER_PORTAL
|| top == Material.PORTAL || top == Material.ENDER_PORTAL) { || top == Material.PORTAL || top == Material.ENDER_PORTAL) {
m.send(player, "unsafe_spawn"); m.send(player, MessageKey.UNSAFE_QUIT_LOCATION);
player.teleport(spawnLoc); player.teleport(spawnLoc);
} }
} }