Player listener - migrate legacy setting use to new settings

This commit is contained in:
ljacqu 2016-04-22 21:55:25 +02:00
parent 2cd43d599d
commit 1182b58b99
2 changed files with 50 additions and 74 deletions

View File

@ -56,6 +56,9 @@ import org.bukkit.event.player.PlayerShearEntityEvent;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import static fr.xephi.authme.listener.ListenerService.shouldCancelEvent; import static fr.xephi.authme.listener.ListenerService.shouldCancelEvent;
import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOWED_MOVEMENT_RADIUS;
import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOW_ALL_COMMANDS_IF_REGISTRATION_IS_OPTIONAL;
import static fr.xephi.authme.settings.properties.RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT;
/** /**
* Listener class for player events. * Listener class for player events.
@ -90,20 +93,18 @@ public class AuthMePlayerListener implements Listener {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
if (Utils.checkAuth(player)) { if (Utils.checkAuth(player)) {
if (settings.getProperty(RestrictionSettings.HIDE_CHAT)) {
for (Player p : Utils.getOnlinePlayers()) { for (Player p : Utils.getOnlinePlayers()) {
if(!settings.getProperty(RestrictionSettings.HIDE_CHAT)) {
break;
}
if (!PlayerCache.getInstance().isAuthenticated(p.getName())) { if (!PlayerCache.getInstance().isAuthenticated(p.getName())) {
event.getRecipients().remove(p); event.getRecipients().remove(p);
} }
} }
return;
} }
} else {
event.setCancelled(true); event.setCancelled(true);
sendLoginOrRegisterMessage(player); sendLoginOrRegisterMessage(player);
} }
}
private void sendLoginOrRegisterMessage(final Player player) { private void sendLoginOrRegisterMessage(final Player player) {
bukkitService.runTaskAsynchronously(new Runnable() { bukkitService.runTaskAsynchronously(new Runnable() {
@ -125,13 +126,14 @@ public class AuthMePlayerListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) { public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
String cmd = event.getMessage().split(" ")[0].toLowerCase(); String cmd = event.getMessage().split(" ")[0].toLowerCase();
if (settings.getProperty(HooksSettings.USE_ESSENTIALS_MOTD) && cmd.equals("/motd")) { if (settings.getProperty(HooksSettings.USE_ESSENTIALS_MOTD) && "/motd".equals(cmd)) {
return; return;
} }
if (!Settings.isForcedRegistrationEnabled && Settings.allowAllCommandsIfRegIsOptional) { if (!settings.getProperty(RegistrationSettings.FORCE)
&& settings.getProperty(ALLOW_ALL_COMMANDS_IF_REGISTRATION_IS_OPTIONAL)) {
return; return;
} }
if (Settings.allowCommands.contains(cmd)) { if (settings.getProperty(RestrictionSettings.ALLOW_COMMANDS).contains(cmd)) {
return; return;
} }
if (Utils.checkAuth(event.getPlayer())) { if (Utils.checkAuth(event.getPlayer())) {
@ -168,7 +170,7 @@ public class AuthMePlayerListener implements Listener {
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
if (Settings.isMovementAllowed && Settings.getMovementRadius <= 0) { if (settings.getProperty(ALLOW_UNAUTHED_MOVEMENT) && settings.getProperty(ALLOWED_MOVEMENT_RADIUS) <= 0) {
return; return;
} }
@ -187,17 +189,17 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
if (!Settings.isMovementAllowed) { if (!settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)) {
event.setTo(event.getFrom()); event.setTo(event.getFrom());
// sgdc3 TODO: remove this, maybe we should set the effect every x ticks, idk! // sgdc3 TODO: remove this, maybe we should set the effect every x ticks, idk!
if (Settings.isRemoveSpeedEnabled) { if (settings.getProperty(RestrictionSettings.REMOVE_SPEED)) {
player.setFlySpeed(0.0f); player.setFlySpeed(0.0f);
player.setWalkSpeed(0.0f); player.setWalkSpeed(0.0f);
} }
return; return;
} }
if (Settings.noTeleport) { if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) {
return; return;
} }
@ -207,7 +209,7 @@ public class AuthMePlayerListener implements Listener {
player.teleport(spawn); player.teleport(spawn);
return; return;
} }
if (spawn.distance(player.getLocation()) > Settings.getMovementRadius) { if (spawn.distance(player.getLocation()) > settings.getProperty(ALLOWED_MOVEMENT_RADIUS)) {
player.teleport(spawn); player.teleport(spawn);
} }
} }
@ -220,11 +222,11 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
if (Settings.removeJoinMessage) { if (settings.getProperty(RegistrationSettings.REMOVE_JOIN_MESSAGE)) {
event.setJoinMessage(null); event.setJoinMessage(null);
return; return;
} }
if (!Settings.delayJoinMessage) { if (!settings.getProperty(RegistrationSettings.DELAY_JOIN_MESSAGE)) {
return; return;
} }
@ -232,12 +234,11 @@ public class AuthMePlayerListener implements Listener {
String joinMsg = event.getJoinMessage(); String joinMsg = event.getJoinMessage();
// Remove the join message while the player isn't logging in // Remove the join message while the player isn't logging in
if (joinMsg == null) { if (joinMsg != null) {
return;
}
event.setJoinMessage(null); event.setJoinMessage(null);
joinMessage.put(name, joinMsg); joinMessage.put(name, joinMsg);
} }
}
@EventHandler(priority = EventPriority.LOW) @EventHandler(priority = EventPriority.LOW)
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
@ -246,7 +247,7 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
if (Settings.isForceSurvivalModeEnabled if (settings.getProperty(RestrictionSettings.FORCE_SURVIVAL_MODE)
&& !player.hasPermission(PlayerStatePermission.BYPASS_FORCE_SURVIVAL.getNode())) { && !player.hasPermission(PlayerStatePermission.BYPASS_FORCE_SURVIVAL.getNode())) {
player.setGameMode(GameMode.SURVIVAL); player.setGameMode(GameMode.SURVIVAL);
} }
@ -264,7 +265,7 @@ public class AuthMePlayerListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPreLogin(AsyncPlayerPreLoginEvent event) { public void onPreLogin(AsyncPlayerPreLoginEvent event) {
PlayerAuth auth = dataSource.getAuth(event.getName()); PlayerAuth auth = dataSource.getAuth(event.getName());
if (Settings.preventOtherCase && auth != null && auth.getRealName() != null) { if (settings.getProperty(RegistrationSettings.PREVENT_OTHER_CASE) && auth != null && auth.getRealName() != null) {
String realName = auth.getRealName(); String realName = auth.getRealName();
if (!realName.isEmpty() && !realName.equals("Player") && !realName.equals(event.getName())) { if (!realName.isEmpty() && !realName.equals("Player") && !realName.equals(event.getName())) {
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER); event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
@ -297,7 +298,7 @@ public class AuthMePlayerListener implements Listener {
final Player player = bukkitService.getPlayerExact(name); final Player player = bukkitService.getPlayerExact(name);
// Check if forceSingleSession is set to true, so kick player that has // Check if forceSingleSession is set to true, so kick player that has
// joined with same nick of online player // joined with same nick of online player
if (player != null && Settings.isForceSingleSessionEnabled) { if (player != null && settings.getProperty(RestrictionSettings.FORCE_SINGLE_SESSION)) {
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER); event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
event.setKickMessage(m.retrieveSingle(MessageKey.USERNAME_ALREADY_ONLINE_ERROR)); event.setKickMessage(m.retrieveSingle(MessageKey.USERNAME_ALREADY_ONLINE_ERROR));
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name); LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
@ -354,7 +355,7 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
if (Settings.isKickNonRegisteredEnabled && !isAuthAvailable) { if (settings.getProperty(RestrictionSettings.KICK_NON_REGISTERED) && !isAuthAvailable) {
event.setKickMessage(m.retrieveSingle(MessageKey.MUST_REGISTER_MESSAGE)); event.setKickMessage(m.retrieveSingle(MessageKey.MUST_REGISTER_MESSAGE));
event.setResult(PlayerLoginEvent.Result.KICK_OTHER); event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
return; return;
@ -374,7 +375,7 @@ public class AuthMePlayerListener implements Listener {
antiBot.checkAntiBot(player); antiBot.checkAntiBot(player);
if (Settings.bungee) { if (settings.getProperty(HooksSettings.BUNGEECORD)) {
ByteArrayDataOutput out = ByteStreams.newDataOutput(); ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("IP"); out.writeUTF("IP");
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray()); player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
@ -389,7 +390,7 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
if (Settings.removeLeaveMessage) { if (settings.getProperty(RegistrationSettings.REMOVE_LEAVE_MESSAGE)) {
event.setQuitMessage(null); event.setQuitMessage(null);
} }
@ -404,8 +405,8 @@ public class AuthMePlayerListener implements Listener {
return; return;
} }
if ((!Settings.isForceSingleSessionEnabled) if (!settings.getProperty(RestrictionSettings.FORCE_SINGLE_SESSION)
&& (event.getReason().equals(m.retrieveSingle(MessageKey.USERNAME_ALREADY_ONLINE_ERROR)))) { && event.getReason().equals(m.retrieveSingle(MessageKey.USERNAME_ALREADY_ONLINE_ERROR))) {
event.setCancelled(true); event.setCancelled(true);
return; return;
} }

View File

@ -29,34 +29,25 @@ public final class Settings {
public static List<String> getForcedWorlds; public static List<String> getForcedWorlds;
public static List<String> countries; public static List<String> countries;
public static List<String> countriesBlacklist; public static List<String> countriesBlacklist;
public static List<String> forceRegisterCommands;
public static List<String> forceRegisterCommandsAsConsole;
public static HashAlgorithm getPasswordHash; public static HashAlgorithm getPasswordHash;
public static Pattern nickPattern; public static Pattern nickPattern;
public static boolean isChatAllowed, isPermissionCheckEnabled, public static boolean isChatAllowed, isPermissionCheckEnabled,
isForcedRegistrationEnabled, isTeleportToSpawnEnabled, isForcedRegistrationEnabled, isTeleportToSpawnEnabled,
isSessionsEnabled, isAllowRestrictedIp, isSessionsEnabled, isAllowRestrictedIp, isMovementAllowed,
isMovementAllowed, isKickNonRegisteredEnabled,
isForceSingleSessionEnabled, isForceSpawnLocOnJoinEnabled, isForceSingleSessionEnabled, isForceSpawnLocOnJoinEnabled,
isSaveQuitLocationEnabled, isForceSurvivalModeEnabled, isSaveQuitLocationEnabled, protectInventoryBeforeLogInEnabled,
protectInventoryBeforeLogInEnabled, isStopEnabled, reloadSupport, isStopEnabled, reloadSupport, rakamakUseIp, noConsoleSpam,
rakamakUseIp, noConsoleSpam, removePassword, displayOtherAccounts, removePassword, displayOtherAccounts, emailRegistration,
emailRegistration, multiverse, bungee, multiverse, bungee, banUnsafeIp, sessionExpireOnIpChange,
banUnsafeIp, sessionExpireOnIpChange, useEssentialsMotd, enableProtection, recallEmail, forceRegLogin, noTeleport,
enableProtection, recallEmail, useWelcomeMessage, allowAllCommandsIfRegIsOptional, isRemoveSpeedEnabled;
broadcastWelcomeMessage, forceRegKick, forceRegLogin,
removeJoinMessage, removeLeaveMessage, delayJoinMessage,
noTeleport, allowAllCommandsIfRegIsOptional,
isRemoveSpeedEnabled, preventOtherCase, hideChat;
public static String getNickRegex, getUnloggedinGroup, public static String getNickRegex, getUnloggedinGroup,
unRegisteredGroup, backupWindowsPath, getRegisteredGroup, unRegisteredGroup, backupWindowsPath, getRegisteredGroup,
rakamakUsers, rakamakUsersIp, defaultWorld, rakamakUsers, rakamakUsersIp, defaultWorld, crazyloginFileName;
spawnPriority, crazyloginFileName;
public static int getWarnMessageInterval, getSessionTimeout, public static int getWarnMessageInterval, getSessionTimeout,
getRegistrationTimeout, getMaxNickLength, getMinNickLength, getRegistrationTimeout, getMaxNickLength, getMinNickLength,
getMovementRadius, getNonActivatedGroup, getNonActivatedGroup, maxLoginTry, captchaLength, saltLength,
maxLoginTry, captchaLength, saltLength, bCryptLog2Rounds, getMaxLoginPerIp;
bCryptLog2Rounds, getMaxLoginPerIp, getMaxJoinPerIp;
protected static FileConfiguration configFile; protected static FileConfiguration configFile;
/** /**
@ -71,7 +62,7 @@ public final class Settings {
private static void loadVariables() { private static void loadVariables() {
isPermissionCheckEnabled = load(PluginSettings.ENABLE_PERMISSION_CHECK); isPermissionCheckEnabled = load(PluginSettings.ENABLE_PERMISSION_CHECK);
isForcedRegistrationEnabled = configFile.getBoolean("settings.registration.force", true); isForcedRegistrationEnabled = load(RegistrationSettings.FORCE);
isTeleportToSpawnEnabled = load(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN); isTeleportToSpawnEnabled = load(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN);
getWarnMessageInterval = load(RegistrationSettings.MESSAGE_INTERVAL); getWarnMessageInterval = load(RegistrationSettings.MESSAGE_INTERVAL);
isSessionsEnabled = load(PluginSettings.SESSIONS_ENABLED); isSessionsEnabled = load(PluginSettings.SESSIONS_ENABLED);
@ -83,14 +74,11 @@ public final class Settings {
getNickRegex = configFile.getString("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_?]*"); getNickRegex = configFile.getString("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_?]*");
nickPattern = Pattern.compile(getNickRegex); nickPattern = Pattern.compile(getNickRegex);
isAllowRestrictedIp = load(RestrictionSettings.ENABLE_RESTRICTED_USERS); isAllowRestrictedIp = load(RestrictionSettings.ENABLE_RESTRICTED_USERS);
isMovementAllowed = configFile.getBoolean("settings.restrictions.allowMovement", false); isMovementAllowed = load(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT);
isRemoveSpeedEnabled = configFile.getBoolean("settings.restrictions.removeSpeed", true); isRemoveSpeedEnabled = load(RestrictionSettings.REMOVE_SPEED);
getMovementRadius = configFile.getInt("settings.restrictions.allowedMovementRadius", 100); isForceSingleSessionEnabled = load(RestrictionSettings.FORCE_SINGLE_SESSION);
isKickNonRegisteredEnabled = configFile.getBoolean("settings.restrictions.kickNonRegistered", false); isForceSpawnLocOnJoinEnabled = load(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN);
isForceSingleSessionEnabled = configFile.getBoolean("settings.restrictions.ForceSingleSession", true);
isForceSpawnLocOnJoinEnabled = configFile.getBoolean("settings.restrictions.ForceSpawnLocOnJoinEnabled", false);
isSaveQuitLocationEnabled = configFile.getBoolean("settings.restrictions.SaveQuitLocation", false); isSaveQuitLocationEnabled = configFile.getBoolean("settings.restrictions.SaveQuitLocation", false);
isForceSurvivalModeEnabled = configFile.getBoolean("settings.GameMode.ForceSurvivalMode", false);
getPasswordHash = load(SecuritySettings.PASSWORD_HASH); getPasswordHash = load(SecuritySettings.PASSWORD_HASH);
getUnloggedinGroup = load(SecuritySettings.UNLOGGEDIN_GROUP); getUnloggedinGroup = load(SecuritySettings.UNLOGGEDIN_GROUP);
getNonActivatedGroup = configFile.getInt("ExternalBoardOptions.nonActivedUserGroup", -1); getNonActivatedGroup = configFile.getInt("ExternalBoardOptions.nonActivedUserGroup", -1);
@ -107,7 +95,7 @@ public final class Settings {
isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true); isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true);
reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true); reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true);
allowAllCommandsIfRegIsOptional = configFile.getBoolean("settings.restrictions.allowAllCommandsIfRegistrationIsOptional", false); allowAllCommandsIfRegIsOptional = load(RestrictionSettings.ALLOW_ALL_COMMANDS_IF_REGISTRATION_IS_OPTIONAL);
allowCommands = new ArrayList<>(); allowCommands = new ArrayList<>();
allowCommands.addAll(Arrays.asList("/login", "/l", "/register", "/reg", "/email", "/captcha")); allowCommands.addAll(Arrays.asList("/login", "/l", "/register", "/reg", "/email", "/captcha"));
for (String cmd : configFile.getStringList("settings.restrictions.allowCommands")) { for (String cmd : configFile.getStringList("settings.restrictions.allowCommands")) {
@ -128,33 +116,20 @@ public final class Settings {
emailRegistration = load(RegistrationSettings.USE_EMAIL_REGISTRATION); emailRegistration = load(RegistrationSettings.USE_EMAIL_REGISTRATION);
saltLength = configFile.getInt("settings.security.doubleMD5SaltLength", 8); saltLength = configFile.getInt("settings.security.doubleMD5SaltLength", 8);
multiverse = load(HooksSettings.MULTIVERSE); multiverse = load(HooksSettings.MULTIVERSE);
bungee = configFile.getBoolean("Hooks.bungeecord", false); bungee = load(HooksSettings.BUNGEECORD);
getForcedWorlds = configFile.getStringList("settings.restrictions.ForceSpawnOnTheseWorlds"); getForcedWorlds = configFile.getStringList("settings.restrictions.ForceSpawnOnTheseWorlds");
banUnsafeIp = configFile.getBoolean("settings.restrictions.banUnsafedIP", false); banUnsafeIp = configFile.getBoolean("settings.restrictions.banUnsafedIP", false);
sessionExpireOnIpChange = configFile.getBoolean("settings.sessions.sessionExpireOnIpChange", true); sessionExpireOnIpChange = configFile.getBoolean("settings.sessions.sessionExpireOnIpChange", true);
bCryptLog2Rounds = configFile.getInt("ExternalBoardOptions.bCryptLog2Round", 10); bCryptLog2Rounds = configFile.getInt("ExternalBoardOptions.bCryptLog2Round", 10);
useEssentialsMotd = configFile.getBoolean("Hooks.useEssentialsMotd", false);
defaultWorld = configFile.getString("Purge.defaultWorld", "world"); defaultWorld = configFile.getString("Purge.defaultWorld", "world");
enableProtection = configFile.getBoolean("Protection.enableProtection", false); enableProtection = configFile.getBoolean("Protection.enableProtection", false);
countries = configFile.getStringList("Protection.countries"); countries = configFile.getStringList("Protection.countries");
recallEmail = configFile.getBoolean("Email.recallPlayers", false); recallEmail = configFile.getBoolean("Email.recallPlayers", false);
useWelcomeMessage = load(RegistrationSettings.USE_WELCOME_MESSAGE);
countriesBlacklist = configFile.getStringList("Protection.countriesBlacklist"); countriesBlacklist = configFile.getStringList("Protection.countriesBlacklist");
broadcastWelcomeMessage = load(RegistrationSettings.BROADCAST_WELCOME_MESSAGE);
forceRegKick = configFile.getBoolean("settings.registration.forceKickAfterRegister", false);
forceRegLogin = load(RegistrationSettings.FORCE_LOGIN_AFTER_REGISTER); forceRegLogin = load(RegistrationSettings.FORCE_LOGIN_AFTER_REGISTER);
spawnPriority = load(RestrictionSettings.SPAWN_PRIORITY);
getMaxLoginPerIp = load(RestrictionSettings.MAX_LOGIN_PER_IP); getMaxLoginPerIp = load(RestrictionSettings.MAX_LOGIN_PER_IP);
getMaxJoinPerIp = load(RestrictionSettings.MAX_JOIN_PER_IP);
removeJoinMessage = load(RegistrationSettings.REMOVE_JOIN_MESSAGE);
removeLeaveMessage = load(RegistrationSettings.REMOVE_LEAVE_MESSAGE);
delayJoinMessage = load(RegistrationSettings.DELAY_JOIN_MESSAGE);
noTeleport = load(RestrictionSettings.NO_TELEPORT); noTeleport = load(RestrictionSettings.NO_TELEPORT);
crazyloginFileName = configFile.getString("Converter.CrazyLogin.fileName", "accounts.db"); crazyloginFileName = configFile.getString("Converter.CrazyLogin.fileName", "accounts.db");
forceRegisterCommands = configFile.getStringList("settings.forceRegisterCommands");
forceRegisterCommandsAsConsole = configFile.getStringList("settings.forceRegisterCommandsAsConsole");
preventOtherCase = configFile.getBoolean("settings.preventOtherCase", false);
hideChat = load(RestrictionSettings.HIDE_CHAT);
} }
/** /**