diff --git a/src/main/java/fr/xephi/authme/AntiBot.java b/src/main/java/fr/xephi/authme/AntiBot.java index 5670e90e..071842bc 100644 --- a/src/main/java/fr/xephi/authme/AntiBot.java +++ b/src/main/java/fr/xephi/authme/AntiBot.java @@ -1,6 +1,5 @@ package fr.xephi.authme; -import fr.xephi.authme.listener.AuthMePlayerListener; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.output.Messages; import fr.xephi.authme.permission.PermissionsManager; @@ -11,8 +10,6 @@ import fr.xephi.authme.util.BukkitService; import org.bukkit.entity.Player; import javax.inject.Inject; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import static fr.xephi.authme.util.BukkitService.TICKS_PER_MINUTE; diff --git a/src/main/java/fr/xephi/authme/AuthMe.java b/src/main/java/fr/xephi/authme/AuthMe.java index baeb1bfd..4553b207 100644 --- a/src/main/java/fr/xephi/authme/AuthMe.java +++ b/src/main/java/fr/xephi/authme/AuthMe.java @@ -24,7 +24,6 @@ import fr.xephi.authme.listener.AuthMeInventoryPacketAdapter; import fr.xephi.authme.listener.AuthMePlayerListener; import fr.xephi.authme.listener.AuthMePlayerListener16; import fr.xephi.authme.listener.AuthMePlayerListener18; -import fr.xephi.authme.listener.AuthMePlayerListener19; import fr.xephi.authme.listener.AuthMeServerListener; import fr.xephi.authme.listener.AuthMeTabCompletePacketAdapter; import fr.xephi.authme.listener.AuthMeTablistPacketAdapter; @@ -374,13 +373,6 @@ public class AuthMe extends JavaPlugin { pluginManager.registerEvents(initializer.get(AuthMePlayerListener18.class), this); } catch (ClassNotFoundException ignore) { } - - // Try to register 1.9 player listeners - try { - Class.forName("org.spigotmc.event.player.PlayerSpawnLocationEvent"); - pluginManager.registerEvents(initializer.get(AuthMePlayerListener19.class), this); - } catch (ClassNotFoundException ignore) { - } } private void reloadSupportHook() { diff --git a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java index 9f2843d1..12d45d20 100644 --- a/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java +++ b/src/main/java/fr/xephi/authme/datasource/CacheDataSource.java @@ -72,7 +72,7 @@ public class CacheDataSource implements DataSource { } @Override - public synchronized boolean isAuthAvailable(String user) { + public boolean isAuthAvailable(String user) { return getAuth(user) != null; } @@ -87,13 +87,13 @@ public class CacheDataSource implements DataSource { } @Override - public synchronized PlayerAuth getAuth(String user) { + public PlayerAuth getAuth(String user) { user = user.toLowerCase(); return cachedAuths.getUnchecked(user).orNull(); } @Override - public synchronized boolean saveAuth(PlayerAuth auth) { + public boolean saveAuth(PlayerAuth auth) { boolean result = source.saveAuth(auth); if (result) { cachedAuths.refresh(auth.getNickname()); @@ -102,7 +102,7 @@ public class CacheDataSource implements DataSource { } @Override - public synchronized boolean updatePassword(PlayerAuth auth) { + public boolean updatePassword(PlayerAuth auth) { boolean result = source.updatePassword(auth); if (result) { cachedAuths.refresh(auth.getNickname()); @@ -111,7 +111,7 @@ public class CacheDataSource implements DataSource { } @Override - public synchronized boolean updatePassword(String user, HashedPassword password) { + public boolean updatePassword(String user, HashedPassword password) { user = user.toLowerCase(); boolean result = source.updatePassword(user, password); if (result) { @@ -121,7 +121,7 @@ public class CacheDataSource implements DataSource { } @Override - public synchronized boolean updateSession(PlayerAuth auth) { + public boolean updateSession(PlayerAuth auth) { boolean result = source.updateSession(auth); if (result) { cachedAuths.refresh(auth.getNickname()); @@ -130,7 +130,7 @@ public class CacheDataSource implements DataSource { } @Override - public synchronized boolean updateQuitLoc(final PlayerAuth auth) { + public boolean updateQuitLoc(final PlayerAuth auth) { boolean result = source.updateQuitLoc(auth); if (result) { cachedAuths.refresh(auth.getNickname()); @@ -149,7 +149,7 @@ public class CacheDataSource implements DataSource { } @Override - public synchronized boolean removeAuth(String name) { + public boolean removeAuth(String name) { name = name.toLowerCase(); boolean result = source.removeAuth(name); if (result) { @@ -159,7 +159,7 @@ public class CacheDataSource implements DataSource { } @Override - public synchronized void close() { + public void close() { source.close(); cachedAuths.invalidateAll(); executorService.shutdown(); @@ -171,7 +171,7 @@ public class CacheDataSource implements DataSource { } @Override - public synchronized boolean updateEmail(final PlayerAuth auth) { + public boolean updateEmail(final PlayerAuth auth) { boolean result = source.updateEmail(auth); if (result) { cachedAuths.refresh(auth.getNickname()); @@ -180,17 +180,17 @@ public class CacheDataSource implements DataSource { } @Override - public synchronized List getAllAuthsByIp(final String ip) { + public List getAllAuthsByIp(final String ip) { return source.getAllAuthsByIp(ip); } @Override - public synchronized int countAuthsByEmail(final String email) { + public int countAuthsByEmail(final String email) { return source.countAuthsByEmail(email); } @Override - public synchronized void purgeBanned(final Set banned) { + public void purgeBanned(final Set banned) { source.purgeBanned(banned); cachedAuths.invalidateAll(banned); } @@ -201,17 +201,17 @@ public class CacheDataSource implements DataSource { } @Override - public synchronized boolean isLogged(String user) { + public boolean isLogged(String user) { return PlayerCache.getInstance().isAuthenticated(user); } @Override - public synchronized void setLogged(final String user) { + public void setLogged(final String user) { source.setLogged(user.toLowerCase()); } @Override - public synchronized void setUnlogged(final String user) { + public void setUnlogged(final String user) { source.setUnlogged(user.toLowerCase()); } @@ -227,7 +227,7 @@ public class CacheDataSource implements DataSource { } @Override - public synchronized boolean updateRealName(String user, String realName) { + public boolean updateRealName(String user, String realName) { boolean result = source.updateRealName(user, realName); if (result) { cachedAuths.refresh(user); @@ -236,7 +236,7 @@ public class CacheDataSource implements DataSource { } @Override - public synchronized boolean updateIp(String user, String ip) { + public boolean updateIp(String user, String ip) { boolean result = source.updateIp(user, ip); if (result) { cachedAuths.refresh(user); diff --git a/src/main/java/fr/xephi/authme/datasource/MySQL.java b/src/main/java/fr/xephi/authme/datasource/MySQL.java index 694c2fc8..94e43e00 100644 --- a/src/main/java/fr/xephi/authme/datasource/MySQL.java +++ b/src/main/java/fr/xephi/authme/datasource/MySQL.java @@ -106,34 +106,36 @@ public class MySQL implements DataSource { ds = hikariDataSource; } - private synchronized void setConnectionArguments() throws RuntimeException { + private void setConnectionArguments() throws RuntimeException { ds = new HikariDataSource(); ds.setPoolName("AuthMeMYSQLPool"); - ds.setDriverClassName("com.mysql.jdbc.Driver"); - ds.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database); - ds.addDataSourceProperty("rewriteBatchedStatements", "true"); - ds.addDataSourceProperty("jdbcCompliantTruncation", "false"); - ds.addDataSourceProperty("cachePrepStmts", "true"); - ds.addDataSourceProperty("prepStmtCacheSize", "250"); - ds.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); - //set utf-8 as default encoding + // Database URL + ds.setJdbcUrl("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database); + + // Auth + ds.setUsername(this.username); + ds.setPassword(this.password); + + // Encoding ds.addDataSourceProperty("characterEncoding", "utf8"); ds.addDataSourceProperty("encoding","UTF-8"); ds.addDataSourceProperty("useUnicode", "true"); - ds.setUsername(this.username); - ds.setPassword(this.password); - ds.setInitializationFailFast(true); // Don't start the plugin if the database is unavailable - ds.setMaxLifetime(180000); // 3 Min - ds.setIdleTimeout(60000); // 1 Min - ds.setMinimumIdle(2); - ds.setMaximumPoolSize((Runtime.getRuntime().availableProcessors() * 2) + 1); + // Random stuff + ds.addDataSourceProperty("rewriteBatchedStatements", "true"); + ds.addDataSourceProperty("jdbcCompliantTruncation", "false"); + + // Caching + ds.addDataSourceProperty("cachePrepStmts", "true"); + ds.addDataSourceProperty("prepStmtCacheSize", "250"); + ds.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); + ConsoleLogger.info("Connection arguments loaded, Hikari ConnectionPool ready!"); } @Override - public synchronized void reload() throws RuntimeException { + public void reload() throws RuntimeException { if (ds != null) { ds.close(); } @@ -141,11 +143,11 @@ public class MySQL implements DataSource { ConsoleLogger.info("Hikari ConnectionPool arguments reloaded!"); } - private synchronized Connection getConnection() throws SQLException { + private Connection getConnection() throws SQLException { return ds.getConnection(); } - private synchronized void setupConnection() throws SQLException { + private void setupConnection() throws SQLException { try (Connection con = getConnection()) { Statement st = con.createStatement(); DatabaseMetaData md = con.getMetaData(); @@ -258,7 +260,7 @@ public class MySQL implements DataSource { } @Override - public synchronized boolean isAuthAvailable(String user) { + public boolean isAuthAvailable(String user) { String sql = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.NAME + "=?;"; ResultSet rs = null; try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) { @@ -294,7 +296,7 @@ public class MySQL implements DataSource { } @Override - public synchronized PlayerAuth getAuth(String user) { + public PlayerAuth getAuth(String user) { String sql = "SELECT * FROM " + tableName + " WHERE " + col.NAME + "=?;"; PlayerAuth auth; try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) { @@ -328,7 +330,7 @@ public class MySQL implements DataSource { } @Override - public synchronized boolean saveAuth(PlayerAuth auth) { + public boolean saveAuth(PlayerAuth auth) { try (Connection con = getConnection()) { PreparedStatement pst; PreparedStatement pst2; @@ -531,12 +533,12 @@ public class MySQL implements DataSource { } @Override - public synchronized boolean updatePassword(PlayerAuth auth) { + public boolean updatePassword(PlayerAuth auth) { return updatePassword(auth.getNickname(), auth.getPassword()); } @Override - public synchronized boolean updatePassword(String user, HashedPassword password) { + public boolean updatePassword(String user, HashedPassword password) { user = user.toLowerCase(); try (Connection con = getConnection()) { boolean useSalt = !col.SALT.isEmpty(); @@ -594,7 +596,7 @@ public class MySQL implements DataSource { } @Override - public synchronized boolean updateSession(PlayerAuth auth) { + public boolean updateSession(PlayerAuth auth) { String sql = "UPDATE " + tableName + " SET " + col.IP + "=?, " + col.LAST_LOGIN + "=?, " + col.REAL_NAME + "=? WHERE " + col.NAME + "=?;"; try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) { @@ -611,7 +613,7 @@ public class MySQL implements DataSource { } @Override - public synchronized Set autoPurgeDatabase(long until) { + public Set autoPurgeDatabase(long until) { Set list = new HashSet<>(); String select = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.LAST_LOGIN + " getAllAuthsByIp(String ip) { + public List getAllAuthsByIp(String ip) { List result = new ArrayList<>(); String sql = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.IP + "=?;"; try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) { @@ -724,7 +726,7 @@ public class MySQL implements DataSource { } @Override - public synchronized int countAuthsByEmail(String email) { + public int countAuthsByEmail(String email) { String sql = "SELECT COUNT(1) FROM " + tableName + " WHERE UPPER(" + col.EMAIL + ") = UPPER(?)"; try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) { pst.setString(1, email); @@ -740,7 +742,7 @@ public class MySQL implements DataSource { } @Override - public synchronized void purgeBanned(Set banned) { + public void purgeBanned(Set banned) { String sql = "DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;"; try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) { for (String name : banned) { @@ -758,7 +760,7 @@ public class MySQL implements DataSource { } @Override - public synchronized boolean isLogged(String user) { + public boolean isLogged(String user) { String sql = "SELECT " + col.IS_LOGGED + " FROM " + tableName + " WHERE " + col.NAME + "=?;"; try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) { pst.setString(1, user); @@ -772,7 +774,7 @@ public class MySQL implements DataSource { } @Override - public synchronized void setLogged(String user) { + public void setLogged(String user) { String sql = "UPDATE " + tableName + " SET " + col.IS_LOGGED + "=? WHERE " + col.NAME + "=?;"; try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) { pst.setInt(1, 1); @@ -784,7 +786,7 @@ public class MySQL implements DataSource { } @Override - public synchronized void setUnlogged(String user) { + public void setUnlogged(String user) { String sql = "UPDATE " + tableName + " SET " + col.IS_LOGGED + "=? WHERE " + col.NAME + "=?;"; try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) { pst.setInt(1, 0); @@ -824,7 +826,7 @@ public class MySQL implements DataSource { } @Override - public synchronized boolean updateRealName(String user, String realName) { + public boolean updateRealName(String user, String realName) { String sql = "UPDATE " + tableName + " SET " + col.REAL_NAME + "=? WHERE " + col.NAME + "=?;"; try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) { pst.setString(1, realName); @@ -838,7 +840,7 @@ public class MySQL implements DataSource { } @Override - public synchronized boolean updateIp(String user, String ip) { + public boolean updateIp(String user, String ip) { String sql = "UPDATE " + tableName + " SET " + col.IP + "=? WHERE " + col.NAME + "=?;"; try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) { pst.setString(1, ip); diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index fa204a6f..8072d58f 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -64,13 +64,13 @@ public class SQLite implements DataSource { ConsoleLogger.logException("Error while executing SQL statement:", e); } - private synchronized void connect() throws ClassNotFoundException, SQLException { + private void connect() throws ClassNotFoundException, SQLException { Class.forName("org.sqlite.JDBC"); ConsoleLogger.info("SQLite driver loaded"); this.con = DriverManager.getConnection("jdbc:sqlite:plugins/AuthMe/" + database + ".db"); } - private synchronized void setup() throws SQLException { + private void setup() throws SQLException { Statement st = null; ResultSet rs = null; try { @@ -143,7 +143,7 @@ public class SQLite implements DataSource { } @Override - public synchronized boolean isAuthAvailable(String user) { + public boolean isAuthAvailable(String user) { PreparedStatement pst = null; ResultSet rs = null; try { @@ -181,7 +181,7 @@ public class SQLite implements DataSource { } @Override - public synchronized PlayerAuth getAuth(String user) { + public PlayerAuth getAuth(String user) { PreparedStatement pst = null; ResultSet rs = null; try { @@ -201,7 +201,7 @@ public class SQLite implements DataSource { } @Override - public synchronized boolean saveAuth(PlayerAuth auth) { + public boolean saveAuth(PlayerAuth auth) { PreparedStatement pst = null; try { HashedPassword password = auth.getPassword(); @@ -242,12 +242,12 @@ public class SQLite implements DataSource { } @Override - public synchronized boolean updatePassword(PlayerAuth auth) { + public boolean updatePassword(PlayerAuth auth) { return updatePassword(auth.getNickname(), auth.getPassword()); } @Override - public synchronized boolean updatePassword(String user, HashedPassword password) { + public boolean updatePassword(String user, HashedPassword password) { user = user.toLowerCase(); PreparedStatement pst = null; try { @@ -274,7 +274,7 @@ public class SQLite implements DataSource { } @Override - public synchronized boolean updateSession(PlayerAuth auth) { + public boolean updateSession(PlayerAuth auth) { PreparedStatement pst = null; try { pst = con.prepareStatement("UPDATE " + tableName + " SET " + col.IP + "=?, " + col.LAST_LOGIN + "=?, " + col.REAL_NAME + "=? WHERE " + col.NAME + "=?;"); @@ -315,7 +315,7 @@ public class SQLite implements DataSource { } @Override - public synchronized boolean removeAuth(String user) { + public boolean removeAuth(String user) { PreparedStatement pst = null; try { pst = con.prepareStatement("DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;"); @@ -331,7 +331,7 @@ public class SQLite implements DataSource { } @Override - public synchronized boolean updateQuitLoc(PlayerAuth auth) { + public boolean updateQuitLoc(PlayerAuth auth) { PreparedStatement pst = null; try { pst = con.prepareStatement("UPDATE " + tableName + " SET " + col.LASTLOC_X + "=?, " + col.LASTLOC_Y + "=?, " + col.LASTLOC_Z + "=?, " + col.LASTLOC_WORLD + "=? WHERE " + col.NAME + "=?;"); @@ -351,7 +351,7 @@ public class SQLite implements DataSource { } @Override - public synchronized boolean updateEmail(PlayerAuth auth) { + public boolean updateEmail(PlayerAuth auth) { String sql = "UPDATE " + tableName + " SET " + col.EMAIL + "=? WHERE " + col.NAME + "=?;"; try (PreparedStatement pst = con.prepareStatement(sql)) { pst.setString(1, auth.getEmail()); @@ -365,7 +365,7 @@ public class SQLite implements DataSource { } @Override - public synchronized void close() { + public void close() { try { if (con != null && !con.isClosed()) { con.close(); @@ -462,7 +462,7 @@ public class SQLite implements DataSource { } @Override - public synchronized boolean isLogged(String user) { + public boolean isLogged(String user) { PreparedStatement pst = null; ResultSet rs = null; try { @@ -481,7 +481,7 @@ public class SQLite implements DataSource { } @Override - public synchronized void setLogged(String user) { + public void setLogged(String user) { PreparedStatement pst = null; try { pst = con.prepareStatement("UPDATE " + tableName + " SET " + col.IS_LOGGED + "=? WHERE LOWER(" + col.NAME + ")=?;"); @@ -496,7 +496,7 @@ public class SQLite implements DataSource { } @Override - public synchronized void setUnlogged(String user) { + public void setUnlogged(String user) { PreparedStatement pst = null; if (user != null) try { @@ -540,7 +540,7 @@ public class SQLite implements DataSource { } @Override - public synchronized boolean updateRealName(String user, String realName) { + public boolean updateRealName(String user, String realName) { String sql = "UPDATE " + tableName + " SET " + col.REAL_NAME + "=? WHERE " + col.NAME + "=?;"; try (PreparedStatement pst = con.prepareStatement(sql)) { pst.setString(1, realName); @@ -554,7 +554,7 @@ public class SQLite implements DataSource { } @Override - public synchronized boolean updateIp(String user, String ip) { + public boolean updateIp(String user, String ip) { String sql = "UPDATE " + tableName + " SET " + col.IP + "=? WHERE " + col.NAME + "=?;"; try (PreparedStatement pst = con.prepareStatement(sql)) { pst.setString(1, ip); diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java index ed3d8912..a65177b4 100644 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java +++ b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener.java @@ -28,7 +28,6 @@ import fr.xephi.authme.util.ValidationService; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Location; -import org.bukkit.OfflinePlayer; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -37,9 +36,9 @@ import org.bukkit.event.block.SignChangeEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryOpenEvent; -import org.bukkit.event.player.AsyncPlayerChatEvent; import org.bukkit.event.player.AsyncPlayerPreLoginEvent; import org.bukkit.event.player.PlayerBedEnterEvent; +import org.bukkit.event.player.PlayerChatEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.event.player.PlayerFishEvent; @@ -57,11 +56,9 @@ import org.bukkit.event.player.PlayerShearEntityEvent; import javax.inject.Inject; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import java.util.Iterator; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; import java.util.regex.Pattern; import static fr.xephi.authme.listener.ListenerService.shouldCancelEvent; @@ -96,24 +93,6 @@ public class AuthMePlayerListener implements Listener { @Inject private ValidationService validationService; - private void handleChat(AsyncPlayerChatEvent event) { - if (settings.getProperty(RestrictionSettings.ALLOW_CHAT)) { - return; - } - - final Player player = event.getPlayer(); - if (shouldCancelEvent(player)) { - event.setCancelled(true); - sendLoginOrRegisterMessage(player); - } else if (settings.getProperty(RestrictionSettings.HIDE_CHAT)) { - for (Player p : bukkitService.getOnlinePlayers()) { - if (!PlayerCache.getInstance().isAuthenticated(p.getName())) { - event.getRecipients().remove(p); - } - } - } - } - private void sendLoginOrRegisterMessage(final Player player) { bukkitService.runTaskAsynchronously(new Runnable() { @Override @@ -151,29 +130,31 @@ public class AuthMePlayerListener implements Listener { sendLoginOrRegisterMessage(event.getPlayer()); } - @EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL) - public void onPlayerNormalChat(AsyncPlayerChatEvent event) { - handleChat(event); - } - - @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) - public void onPlayerHighChat(AsyncPlayerChatEvent event) { - handleChat(event); - } - - @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) - public void onPlayerHighestChat(AsyncPlayerChatEvent event) { - handleChat(event); - } - - @EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) - public void onPlayerEarlyChat(AsyncPlayerChatEvent event) { - handleChat(event); - } - @EventHandler(ignoreCancelled = true, priority = EventPriority.LOW) - public void onPlayerLowChat(AsyncPlayerChatEvent event) { - handleChat(event); + public void onPlayerChat(PlayerChatEvent event) { + if (settings.getProperty(RestrictionSettings.ALLOW_CHAT)) { + return; + } + + final Player player = event.getPlayer(); + if (shouldCancelEvent(player)) { + event.setCancelled(true); + bukkitService.runTaskAsynchronously(new Runnable() { + @Override + public void run() { + m.send(player, MessageKey.DENIED_CHAT_MESSAGE); + } + }); + } else if (settings.getProperty(RestrictionSettings.HIDE_CHAT)) { + Set recipients = event.getRecipients(); + Iterator iter = recipients.iterator(); + while (iter.hasNext()) { + Player p = iter.next(); + if (shouldCancelEvent(p)) { + iter.remove(); + } + } + } } @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) @@ -199,7 +180,6 @@ public class AuthMePlayerListener implements Listener { if (!settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)) { event.setTo(event.getFrom()); - // sgdc3 TODO: remove this, maybe we should set the effect every x ticks, idk! if (settings.getProperty(RestrictionSettings.REMOVE_SPEED)) { player.setFlySpeed(0.0f); player.setWalkSpeed(0.0f); diff --git a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener19.java b/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener19.java deleted file mode 100644 index f5b073cc..00000000 --- a/src/main/java/fr/xephi/authme/listener/AuthMePlayerListener19.java +++ /dev/null @@ -1,38 +0,0 @@ -package fr.xephi.authme.listener; - -import fr.xephi.authme.settings.NewSetting; -import fr.xephi.authme.settings.SpawnLoader; -import fr.xephi.authme.settings.properties.RestrictionSettings; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; -import org.spigotmc.event.player.PlayerSpawnLocationEvent; - -import javax.inject.Inject; - -/** - * Listener of player events for events introduced in Minecraft 1.9. - */ -public class AuthMePlayerListener19 implements Listener { - - @Inject - private SpawnLoader spawnLoader; - - @Inject - private NewSetting settings; - - /* WTF was that? We need to check all the settings before moving the player to the spawn! - * - * TODO: fixme please! - * - @EventHandler(priority = EventPriority.LOWEST) - public void onPlayerSpawn(PlayerSpawnLocationEvent event) { - if(settings.getProperty(RestrictionSettings.NO_TELEPORT)) { - return; - } - event.setSpawnLocation(spawnLoader.getSpawnLocation(event.getPlayer())); - } - */ - -} diff --git a/src/main/java/fr/xephi/authme/output/MessageKey.java b/src/main/java/fr/xephi/authme/output/MessageKey.java index 3fd7c747..a4ab3736 100644 --- a/src/main/java/fr/xephi/authme/output/MessageKey.java +++ b/src/main/java/fr/xephi/authme/output/MessageKey.java @@ -5,6 +5,8 @@ package fr.xephi.authme.output; */ public enum MessageKey { + DENIED_CHAT_MESSAGE("denied_chat"), + KICK_ANTIBOT("kick_antibot"), UNKNOWN_USER("unknown_user"), diff --git a/src/main/resources/messages/messages_en.yml b/src/main/resources/messages/messages_en.yml index 5b474e2d..203ce720 100644 --- a/src/main/resources/messages/messages_en.yml +++ b/src/main/resources/messages/messages_en.yml @@ -1,3 +1,4 @@ +denied_chat: '&cIn order to be able to chat you must be authenticated!' kick_antibot: 'AntiBot protection mode is enabled! You have to wait some minutes before joining the server.' unknown_user: '&cCan''t find the requested user in the database!' unsafe_spawn: '&cYour quit location was unsafe, you have been teleported to the world''s spawnpoint.'