Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @EventHandler(priority = EventPriority.HIGHEST)
- public void onPlayerLogin(PlayerLoginEvent event) {
- final Player player = event.getPlayer();
- final String lowname = player.getName().toLowerCase();
- final String name = player.getName();
- if (!lowname.equals(name)) {
- // Little workaround to be sure registered player is the same as this
- if (player.hasPlayedBefore() && !player.isOnline())
- // Make sure it's the correct player
- if (data.isAuthAvailable(lowname)) {
- if (data.getAuth(lowname).getIp().equalsIgnoreCase(player.getAddress().getAddress().getHostAddress())) {
- data.updateName(lowname, name);
- } else {
- event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
- event.setKickMessage(m._("same_nick")[0]);
- }
- }
- }
- if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) {
- return;
- }
- if (!Settings.countriesBlacklist.isEmpty()) {
- String code = plugin.getCountryCode(event.getAddress().getHostAddress());
- if (((code == null) || (Settings.countriesBlacklist.contains(code) && !API.isRegistered(name))) && !plugin.authmePermissible(player, "authme.bypassantibot")) {
- event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("country_banned")[0]);
- return;
- }
- }
- if (Settings.enableProtection && !Settings.countries.isEmpty()) {
- String code = plugin.getCountryCode(event.getAddress().getHostAddress());
- if (((code == null) || (!Settings.countries.contains(code) && !API.isRegistered(name))) && !plugin.authmePermissible(player, "authme.bypassantibot")) {
- event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("country_banned")[0]);
- return;
- }
- }
- if (Settings.isKickNonRegisteredEnabled) {
- if (!data.isAuthAvailable(name)) {
- event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("reg_only")[0]);
- return;
- }
- }
- if (player.isOnline() && Settings.isForceSingleSessionEnabled) {
- event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("same_nick")[0]);
- return;
- }
- if (data.isAuthAvailable(name) && !LimboCache.getInstance().hasLimboPlayer(name)) {
- if (!Settings.isSessionsEnabled) {
- } else if (PlayerCache.getInstance().isAuthenticated(name)) {
- if (!Settings.sessionExpireOnIpChange)
- if (LimboCache.getInstance().hasLimboPlayer(player.getName())) {
- LimboCache.getInstance().deleteLimboPlayer(name);
- }
- }
- }
- // Check if forceSingleSession is set to true, so kick player that has
- // joined with same nick of online player
- if (player.isOnline() && Settings.isForceSingleSessionEnabled) {
- LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName());
- event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("same_nick")[0]);
- if (PlayerCache.getInstance().isAuthenticated(player.getName())) {
- utils.addNormal(player, limbo.getGroup());
- LimboCache.getInstance().deleteLimboPlayer(player.getName());
- }
- return;
- }
- int min = Settings.getMinNickLength;
- int max = Settings.getMaxNickLength;
- String regex = Settings.getNickRegex;
- if (name.length() > max || name.length() < min) {
- event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("name_len")[0]);
- return;
- }
- try {
- if (!player.getName().matches(regex) || name.equals("Player")) {
- try {
- event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("regex")[0].replace("REG_EX", regex));
- } catch (Exception exc) {
- event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "allowed char : " + regex);
- }
- return;
- }
- } catch (PatternSyntaxException pse) {
- if (regex == null || regex.isEmpty()) {
- event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your nickname do not match");
- return;
- }
- try {
- event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("regex")[0].replace("REG_EX", regex));
- } catch (Exception exc) {
- event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "allowed char : " + regex);
- }
- return;
- }
- if (event.getResult() == PlayerLoginEvent.Result.ALLOWED) {
- checkAntiBotMod(event);
- if (Settings.bungee) {
- final ByteArrayOutputStream b = new ByteArrayOutputStream();
- DataOutputStream out = new DataOutputStream(b);
- try {
- out.writeUTF("IP");
- } catch (IOException e) {
- }
- player.sendPluginMessage(plugin, "BungeeCord", b.toByteArray());
- }
- return;
- }
- if (event.getResult() != PlayerLoginEvent.Result.KICK_FULL)
- return;
- if (player.isBanned())
- return;
- if (!plugin.authmePermissible(player, "authme.vip")) {
- event.disallow(Result.KICK_FULL, m._("kick_fullserver")[0]);
- return;
- }
- if (plugin.getServer().getOnlinePlayers().length > plugin.getServer().getMaxPlayers()) {
- event.allow();
- return;
- } else {
- final Player pl = plugin.generateKickPlayer(plugin.getServer().getOnlinePlayers());
- if (pl != null) {
- pl.kickPlayer(m._("kick_forvip")[0]);
- event.allow();
- return;
- } else {
- ConsoleLogger.info("The player " + player.getName() + " wants to join, but the server is full");
- event.disallow(Result.KICK_FULL, m._("kick_fullserver")[0]);
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement