mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2025-02-16 20:01:46 +01:00
update playerloginevent and some listener.
i hope it will fix the lag issues.
This commit is contained in:
parent
b4b92e5a93
commit
8e9bfc6299
@ -12,5 +12,6 @@
|
||||
</value>
|
||||
</option>
|
||||
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="GoogleStyle" />
|
||||
</component>
|
||||
</project>
|
@ -20,10 +20,10 @@ public class LoginCommand extends ExecutableCommand {
|
||||
// Get the necessary objects
|
||||
final AuthMe plugin = AuthMe.getInstance();
|
||||
final Player player = (Player) sender;
|
||||
final String playerPass = commandArguments.get(0);
|
||||
final String password = commandArguments.get(0);
|
||||
|
||||
// Log the player in
|
||||
plugin.getManagement().performLogin(player, playerPass, false);
|
||||
plugin.getManagement().performLogin(player, password, false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
/**
|
||||
*/
|
||||
@ -59,15 +58,16 @@ public class AuthMePlayerListener implements Listener {
|
||||
* @param event AsyncPlayerChatEvent
|
||||
*/
|
||||
private void handleChat(AsyncPlayerChatEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (Settings.isChatAllowed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Settings.isChatAllowed)
|
||||
return;
|
||||
if (Utils.checkAuth(player))
|
||||
Player player = event.getPlayer();
|
||||
if (Utils.checkAuth(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
if (plugin.database.isAuthAvailable(player.getName().toLowerCase())) {
|
||||
m.send(player, "login_msg");
|
||||
} else {
|
||||
@ -245,8 +245,9 @@ public class AuthMePlayerListener implements Listener {
|
||||
*/
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if (event.getPlayer() == null)
|
||||
if (event.getPlayer() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
final String name = player.getName().toLowerCase();
|
||||
@ -254,7 +255,7 @@ public class AuthMePlayerListener implements Listener {
|
||||
final boolean delay = Settings.delayJoinLeaveMessages && joinMsg != null;
|
||||
|
||||
// Remove the join message while the player isn't logging in
|
||||
if (Settings.delayJoinLeaveMessages && event.getJoinMessage() != null) {
|
||||
if (delay) {
|
||||
event.setJoinMessage(null);
|
||||
}
|
||||
|
||||
@ -263,9 +264,10 @@ public class AuthMePlayerListener implements Listener {
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (delay)
|
||||
if (delay) {
|
||||
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)
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (player == null) {
|
||||
if (event.getPlayer() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String name = player.getName().toLowerCase();
|
||||
if (Utils.isNPC(player) || Utils.isUnrestricted(player)) {
|
||||
return;
|
||||
if (event.getResult() == PlayerLoginEvent.Result.KICK_FULL) {
|
||||
int playersOnline = Utils.getOnlinePlayers().size();
|
||||
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) {
|
||||
@ -326,18 +339,32 @@ public class AuthMePlayerListener implements Listener {
|
||||
// Get the permissions manager
|
||||
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);
|
||||
|
||||
if (!Settings.countriesBlacklist.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, "authme.bypassantibot")) {
|
||||
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.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (Settings.enableProtection && !Settings.countries.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, "authme.bypassantibot")) {
|
||||
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.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
return;
|
||||
@ -357,72 +384,24 @@ public class AuthMePlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
int min = Settings.getMinNickLength;
|
||||
int max = Settings.getMaxNickLength;
|
||||
String regex = Settings.getNickRegex;
|
||||
|
||||
if (name.length() > max || name.length() < min) {
|
||||
if (name.length() > Settings.getMaxNickLength || name.length() < Settings.getMinNickLength) {
|
||||
event.setKickMessage(Arrays.toString(m.send("name_len")));
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (!player.getName().matches(regex) || name.equalsIgnoreCase("Player")) {
|
||||
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;
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
|
||||
if (!Settings.nickPattern.matcher(player.getName()).matches() || name.equalsIgnoreCase("Player")) {
|
||||
event.setKickMessage(m.send("regex")[0].replace("REG_EX", Settings.getNickRegex));
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getResult() == PlayerLoginEvent.Result.ALLOWED) {
|
||||
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;
|
||||
}
|
||||
checkAntiBotMod(player);
|
||||
|
||||
int playersOnline = Utils.getOnlinePlayers().size();
|
||||
if (playersOnline > plugin.getServer().getMaxPlayers()) {
|
||||
event.allow();
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
if (Settings.bungee) {
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("IP");
|
||||
player.sendPluginMessage(plugin, "BungeeCord", out.toByteArray());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,10 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
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 DataSourceType getDataSource;
|
||||
public static HashAlgorithm getPasswordHash;
|
||||
public static Pattern nickPattern;
|
||||
public static boolean useLogging = false;
|
||||
public static int purgeDelay = 60;
|
||||
// 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);
|
||||
getPasswordMinLen = configFile.getInt("settings.security.minPasswordLength", 4);
|
||||
getNickRegex = configFile.getString("settings.restrictions.allowedNicknameCharacters", "[a-zA-Z0-9_?]*");
|
||||
nickPattern = Pattern.compile(getNickRegex);
|
||||
isAllowRestrictedIp = configFile.getBoolean("settings.restrictions.AllowRestrictedUser", false);
|
||||
getRestrictedIp = configFile.getStringList("settings.restrictions.AllowedRestrictedUser");
|
||||
isMovementAllowed = configFile.getBoolean("settings.restrictions.allowMovement", false);
|
||||
@ -192,21 +196,13 @@ public final class Settings extends YamlConfiguration {
|
||||
isStopEnabled = configFile.getBoolean("Security.SQLProblem.stopServer", true);
|
||||
reloadSupport = configFile.getBoolean("Security.ReloadCommand.useReloadCommandSupport", true);
|
||||
allowCommands = new ArrayList<>();
|
||||
allowCommands.addAll(Arrays.asList("/login", "/l", "/register", "/reg", "/email", "/captcha"));
|
||||
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");
|
||||
rakamakUsersIp = configFile.getString("Converter.Rakamak.ipFileName", "UsersIp.rak");
|
||||
rakamakUseIp = configFile.getBoolean("Converter.Rakamak.useIp", false);
|
||||
|
@ -13,7 +13,6 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.*;
|
||||
@ -155,7 +154,7 @@ public final class Utils {
|
||||
|
||||
/**
|
||||
* TODO: This method requires better explanation.
|
||||
* <p/>
|
||||
* <p>
|
||||
* Set the normal group of a player.
|
||||
*
|
||||
* @param player The player.
|
||||
@ -332,19 +331,8 @@ public final class Utils {
|
||||
return plugin.getServer().getPlayer(name);
|
||||
}
|
||||
|
||||
public static boolean isNPC(final Entity player) {
|
||||
try {
|
||||
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 boolean isNPC(Player player) {
|
||||
return player.hasMetadata("NPC") || plugin.combatTagPlus != null && plugin.combatTagPlus.getNpcPlayerHelper().isNpc(player);
|
||||
}
|
||||
|
||||
public static void teleportToSpawn(Player player) {
|
||||
|
Loading…
Reference in New Issue
Block a user