update playerloginevent and some listener.

i hope it will fix the lag issues.
This commit is contained in:
DNx5 2015-11-24 07:15:58 +07:00
parent b4b92e5a93
commit 8e9bfc6299
5 changed files with 69 additions and 105 deletions

View File

@ -12,5 +12,6 @@
</value> </value>
</option> </option>
<option name="USE_PER_PROJECT_SETTINGS" value="true" /> <option name="USE_PER_PROJECT_SETTINGS" value="true" />
<option name="PREFERRED_PROJECT_CODE_STYLE" value="GoogleStyle" />
</component> </component>
</project> </project>

View File

@ -20,10 +20,10 @@ public class LoginCommand extends ExecutableCommand {
// Get the necessary objects // Get the necessary objects
final AuthMe plugin = AuthMe.getInstance(); final AuthMe plugin = AuthMe.getInstance();
final Player player = (Player) sender; final Player player = (Player) sender;
final String playerPass = commandArguments.get(0); final String password = commandArguments.get(0);
// Log the player in // Log the player in
plugin.getManagement().performLogin(player, playerPass, false); plugin.getManagement().performLogin(player, password, false);
return true; return true;
} }
} }

View File

@ -31,7 +31,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.PatternSyntaxException;
/** /**
*/ */
@ -59,15 +58,16 @@ public class AuthMePlayerListener implements Listener {
* @param event AsyncPlayerChatEvent * @param event AsyncPlayerChatEvent
*/ */
private void handleChat(AsyncPlayerChatEvent event) { private void handleChat(AsyncPlayerChatEvent event) {
Player player = event.getPlayer(); if (Settings.isChatAllowed) {
return;
}
if (Settings.isChatAllowed) Player player = event.getPlayer();
return; if (Utils.checkAuth(player)) {
if (Utils.checkAuth(player))
return; return;
}
event.setCancelled(true); event.setCancelled(true);
if (plugin.database.isAuthAvailable(player.getName().toLowerCase())) { if (plugin.database.isAuthAvailable(player.getName().toLowerCase())) {
m.send(player, "login_msg"); m.send(player, "login_msg");
} else { } else {
@ -245,8 +245,9 @@ public class AuthMePlayerListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerJoin(PlayerJoinEvent event) { public void onPlayerJoin(PlayerJoinEvent event) {
if (event.getPlayer() == null) if (event.getPlayer() == null) {
return; return;
}
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final String name = player.getName().toLowerCase(); final String name = player.getName().toLowerCase();
@ -254,7 +255,7 @@ public class AuthMePlayerListener implements Listener {
final boolean delay = Settings.delayJoinLeaveMessages && joinMsg != null; final boolean delay = Settings.delayJoinLeaveMessages && joinMsg != null;
// Remove the join message while the player isn't logging in // Remove the join message while the player isn't logging in
if (Settings.delayJoinLeaveMessages && event.getJoinMessage() != null) { if (delay) {
event.setJoinMessage(null); event.setJoinMessage(null);
} }
@ -263,9 +264,10 @@ public class AuthMePlayerListener implements Listener {
Bukkit.getScheduler().runTask(plugin, new Runnable() { Bukkit.getScheduler().runTask(plugin, new Runnable() {
@Override @Override
public void run() { public void run() {
if (delay) if (delay) {
joinMessage.put(name, joinMsg); joinMessage.put(name, joinMsg);
plugin.management.performJoin(player); }
plugin.getManagement().performJoin(player);
} }
}); });
} }
@ -309,14 +311,25 @@ public class AuthMePlayerListener implements Listener {
*/ */
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerLogin(PlayerLoginEvent event) { public void onPlayerLogin(PlayerLoginEvent event) {
final Player player = event.getPlayer(); if (event.getPlayer() == null) {
if (player == null) {
return; return;
} }
final String name = player.getName().toLowerCase(); if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL) {
if (Utils.isNPC(player) || Utils.isUnrestricted(player)) { int playersOnline = Utils.getOnlinePlayers().size();
return; if (playersOnline > plugin.getServer().getMaxPlayers()) {
event.allow();
} else {
Player pl = plugin.generateKickPlayer(Utils.getOnlinePlayers());
if (pl != null) {
pl.kickPlayer(m.send("kick_forvip")[0]);
event.allow();
} else {
ConsoleLogger.info("The player " + event.getPlayer().getName() + " tryed to join, but the server was full");
event.setKickMessage(m.send("kick_fullserver")[0]);
event.setResult(PlayerLoginEvent.Result.KICK_FULL);
}
}
} }
if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) { if (event.getResult() != PlayerLoginEvent.Result.ALLOWED) {
@ -326,18 +339,32 @@ public class AuthMePlayerListener implements Listener {
// Get the permissions manager // Get the permissions manager
PermissionsManager permsMan = plugin.getPermissionsManager(); PermissionsManager permsMan = plugin.getPermissionsManager();
final Player player = event.getPlayer();
if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL && !permsMan.hasPermission(player, "authme.vip")) {
event.setKickMessage(m.send("kick_fullserver")[0]);
event.setResult(PlayerLoginEvent.Result.KICK_FULL);
return;
}
if (Utils.isNPC(player) || Utils.isUnrestricted(player)) {
return;
}
final String name = player.getName().toLowerCase();
boolean isAuthAvailable = plugin.database.isAuthAvailable(name); boolean isAuthAvailable = plugin.database.isAuthAvailable(name);
if (!Settings.countriesBlacklist.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, "authme.bypassantibot")) { if (!Settings.countriesBlacklist.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, "authme.bypassantibot")) {
String code = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress()); String code = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
if (((code == null) || Settings.countriesBlacklist.contains(code))) { if (Settings.countriesBlacklist.contains(code)) {
event.setKickMessage(m.send("country_banned")[0]); event.setKickMessage(m.send("country_banned")[0]);
event.setResult(PlayerLoginEvent.Result.KICK_OTHER); event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
return; return;
} }
} }
if (Settings.enableProtection && !Settings.countries.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, "authme.bypassantibot")) { if (Settings.enableProtection && !Settings.countries.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, "authme.bypassantibot")) {
String code = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress()); String code = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
if (((code == null) || !Settings.countries.contains(code))) { if (!Settings.countries.contains(code)) {
event.setKickMessage(m.send("country_banned")[0]); event.setKickMessage(m.send("country_banned")[0]);
event.setResult(PlayerLoginEvent.Result.KICK_OTHER); event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
return; return;
@ -357,72 +384,24 @@ public class AuthMePlayerListener implements Listener {
} }
} }
int min = Settings.getMinNickLength; if (name.length() > Settings.getMaxNickLength || name.length() < Settings.getMinNickLength) {
int max = Settings.getMaxNickLength;
String regex = Settings.getNickRegex;
if (name.length() > max || name.length() < min) {
event.setKickMessage(Arrays.toString(m.send("name_len"))); event.setKickMessage(Arrays.toString(m.send("name_len")));
event.setResult(PlayerLoginEvent.Result.KICK_OTHER); event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
return; return;
} }
try {
if (!player.getName().matches(regex) || name.equalsIgnoreCase("Player")) { if (!Settings.nickPattern.matcher(player.getName()).matches() || name.equalsIgnoreCase("Player")) {
try { event.setKickMessage(m.send("regex")[0].replace("REG_EX", Settings.getNickRegex));
event.setKickMessage(m.send("regex")[0].replace("REG_EX", regex)); event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
} catch (Exception exc) {
event.setKickMessage("allowed char : " + regex);
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
}
return;
}
} catch (PatternSyntaxException pse) {
if (regex == null || regex.isEmpty()) {
event.setKickMessage("Your nickname do not match");
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
return;
}
try {
event.setKickMessage(m.send("regex")[0].replace("REG_EX", regex));
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
} catch (Exception exc) {
event.setKickMessage("allowed char : " + regex);
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
}
return; return;
} }
if (event.getResult() == PlayerLoginEvent.Result.ALLOWED) { checkAntiBotMod(player);
checkAntiBotMod(player);
if (Settings.bungee) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("IP");
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
}
return;
}
if (event.getResult() != PlayerLoginEvent.Result.KICK_FULL)
return;
if (!permsMan.hasPermission(player, "authme.vip")) {
event.setKickMessage(m.send("kick_fullserver")[0]);
event.setResult(PlayerLoginEvent.Result.KICK_FULL);
return;
}
int playersOnline = Utils.getOnlinePlayers().size(); if (Settings.bungee) {
if (playersOnline > plugin.getServer().getMaxPlayers()) { ByteArrayDataOutput out = ByteStreams.newDataOutput();
event.allow(); out.writeUTF("IP");
} else { player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
final Player pl = plugin.generateKickPlayer(Utils.getOnlinePlayers());
if (pl != null) {
pl.kickPlayer(m.send("kick_forvip")[0]);
event.allow();
} else {
ConsoleLogger.info("The player " + player.getName() + " tryed to join, but the server was full");
event.setKickMessage(m.send("kick_fullserver")[0]);
event.setResult(PlayerLoginEvent.Result.KICK_FULL);
}
} }
} }

View File

@ -9,8 +9,10 @@ import org.bukkit.configuration.file.YamlConfiguration;
import java.io.*; import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.regex.Pattern;
/** /**
*/ */
@ -43,6 +45,7 @@ public final class Settings extends YamlConfiguration {
public static List<String> emailWhitelist; public static List<String> emailWhitelist;
public static DataSourceType getDataSource; public static DataSourceType getDataSource;
public static HashAlgorithm getPasswordHash; public static HashAlgorithm getPasswordHash;
public static Pattern nickPattern;
public static boolean useLogging = false; public static boolean useLogging = false;
public static int purgeDelay = 60; public static int purgeDelay = 60;
// Due to compatibility issues with plugins like FactionsChat // Due to compatibility issues with plugins like FactionsChat
@ -141,6 +144,7 @@ public final class Settings extends YamlConfiguration {
getMinNickLength = configFile.getInt("settings.restrictions.minNicknameLength", 3); getMinNickLength = configFile.getInt("settings.restrictions.minNicknameLength", 3);
getPasswordMinLen = configFile.getInt("settings.security.minPasswordLength", 4); getPasswordMinLen = configFile.getInt("settings.security.minPasswordLength", 4);
getNickRegex = configFile.getString("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_?]*"); getNickRegex = configFile.getString("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_?]*");
nickPattern = Pattern.compile(getNickRegex);
isAllowRestrictedIp = configFile.getBoolean("settings.restrictions.AllowRestrictedUser", false); isAllowRestrictedIp = configFile.getBoolean("settings.restrictions.AllowRestrictedUser", false);
getRestrictedIp = configFile.getStringList("settings.restrictions.AllowedRestrictedUser"); getRestrictedIp = configFile.getStringList("settings.restrictions.AllowedRestrictedUser");
isMovementAllowed = configFile.getBoolean("settings.restrictions.allowMovement", false); isMovementAllowed = configFile.getBoolean("settings.restrictions.allowMovement", false);
@ -192,21 +196,13 @@ public final class Settings extends YamlConfiguration {
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);
allowCommands = new ArrayList<>(); allowCommands = new ArrayList<>();
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")) {
allowCommands.add(cmd.toLowerCase()); cmd = cmd.toLowerCase();
if (!allowCommands.contains(cmd)) {
allowCommands.add(cmd);
}
} }
if (!allowCommands.contains("/login"))
allowCommands.add("/login");
if (!allowCommands.contains("/register"))
allowCommands.add("/register");
if (!allowCommands.contains("/l"))
allowCommands.add("/l");
if (!allowCommands.contains("/reg"))
allowCommands.add("/reg");
if (!allowCommands.contains("/email"))
allowCommands.add("/email");
if (!allowCommands.contains("/captcha"))
allowCommands.add("/captcha");
rakamakUsers = configFile.getString("Converter.Rakamak.fileName", "users.rak"); rakamakUsers = configFile.getString("Converter.Rakamak.fileName", "users.rak");
rakamakUsersIp = configFile.getString("Converter.Rakamak.ipFileName", "UsersIp.rak"); rakamakUsersIp = configFile.getString("Converter.Rakamak.ipFileName", "UsersIp.rak");
rakamakUseIp = configFile.getBoolean("Converter.Rakamak.useIp", false); rakamakUseIp = configFile.getBoolean("Converter.Rakamak.useIp", false);

View File

@ -13,7 +13,6 @@ import org.bukkit.Bukkit;
import org.bukkit.GameMode; import org.bukkit.GameMode;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.io.*; import java.io.*;
@ -155,7 +154,7 @@ public final class Utils {
/** /**
* TODO: This method requires better explanation. * TODO: This method requires better explanation.
* <p/> * <p>
* Set the normal group of a player. * Set the normal group of a player.
* *
* @param player The player. * @param player The player.
@ -332,19 +331,8 @@ public final class Utils {
return plugin.getServer().getPlayer(name); return plugin.getServer().getPlayer(name);
} }
public static boolean isNPC(final Entity player) { public static boolean isNPC(Player player) {
try { return player.hasMetadata("NPC") || plugin.combatTagPlus != null && plugin.combatTagPlus.getNpcPlayerHelper().isNpc(player);
if (player.hasMetadata("NPC")) {
return true;
} else if (plugin.combatTagPlus != null
&& player instanceof Player
&& plugin.combatTagPlus.getNpcPlayerHelper().isNpc((Player) player)) {
return true;
}
return false;
} catch (Exception e) {
return false;
}
} }
public static void teleportToSpawn(Player player) { public static void teleportToSpawn(Player player) {