mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-04 09:40:05 +01:00
Change from PlayerLoginEvent to AsyncPlayerPreLoginEvent
This commit is contained in:
parent
5548004fd0
commit
427fe9fb4f
@ -20,6 +20,7 @@ import org.bukkit.event.block.SignChangeEvent;
|
|||||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
import org.bukkit.event.inventory.InventoryOpenEvent;
|
import org.bukkit.event.inventory.InventoryOpenEvent;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
import org.bukkit.event.player.AsyncPlayerPreLoginEvent;
|
||||||
import org.bukkit.event.player.PlayerBedEnterEvent;
|
import org.bukkit.event.player.PlayerBedEnterEvent;
|
||||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||||
import org.bukkit.event.player.PlayerDropItemEvent;
|
import org.bukkit.event.player.PlayerDropItemEvent;
|
||||||
@ -28,8 +29,6 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
|
|||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerKickEvent;
|
import org.bukkit.event.player.PlayerKickEvent;
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
|
||||||
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
|
||||||
import org.bukkit.event.player.PlayerMoveEvent;
|
import org.bukkit.event.player.PlayerMoveEvent;
|
||||||
import org.bukkit.event.player.PlayerPickupItemEvent;
|
import org.bukkit.event.player.PlayerPickupItemEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
@ -72,7 +71,7 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
private DataSource data;
|
private DataSource data;
|
||||||
private FileCache playerBackup;
|
private FileCache playerBackup;
|
||||||
public static HashMap<String, Boolean> causeByAuthMe = new HashMap<String, Boolean>();
|
public static HashMap<String, Boolean> causeByAuthMe = new HashMap<String, Boolean>();
|
||||||
private HashMap<String, PlayerLoginEvent> antibot = new HashMap<String, PlayerLoginEvent>();
|
private HashMap<String, AsyncPlayerPreLoginEvent> antibot = new HashMap<String, AsyncPlayerPreLoginEvent>();
|
||||||
|
|
||||||
public AuthMePlayerListener(AuthMe plugin, DataSource data) {
|
public AuthMePlayerListener(AuthMe plugin, DataSource data) {
|
||||||
this.plugin = plugin;
|
this.plugin = plugin;
|
||||||
@ -381,9 +380,16 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
public void onAsyncLogin(AsyncPlayerPreLoginEvent event)
|
||||||
|
{
|
||||||
final Player player = event.getPlayer();
|
Player player = null;
|
||||||
|
try {
|
||||||
|
player = Bukkit.getPlayer(event.getUniqueId());
|
||||||
|
} catch (Exception e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (player == null)
|
||||||
|
return;
|
||||||
final String name = player.getName().toLowerCase();
|
final String name = player.getName().toLowerCase();
|
||||||
|
|
||||||
if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) {
|
if (plugin.getCitizensCommunicator().isNPC(player, plugin) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) {
|
||||||
@ -393,27 +399,31 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
if (!Settings.countriesBlacklist.isEmpty()) {
|
if (!Settings.countriesBlacklist.isEmpty()) {
|
||||||
String code = plugin.getCountryCode(event.getAddress().getHostAddress());
|
String code = plugin.getCountryCode(event.getAddress().getHostAddress());
|
||||||
if (((code == null) || (Settings.countriesBlacklist.contains(code) && !API.isRegistered(name))) && !plugin.authmePermissible(player, "authme.bypassantibot")) {
|
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]);
|
event.setKickMessage(m._("country_banned")[0]);
|
||||||
|
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Settings.enableProtection && !Settings.countries.isEmpty()) {
|
if (Settings.enableProtection && !Settings.countries.isEmpty()) {
|
||||||
String code = plugin.getCountryCode(event.getAddress().getHostAddress());
|
String code = plugin.getCountryCode(event.getAddress().getHostAddress());
|
||||||
if (((code == null) || (!Settings.countries.contains(code) && !API.isRegistered(name))) && !plugin.authmePermissible(player, "authme.bypassantibot")) {
|
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]);
|
event.setKickMessage(m._("country_banned")[0]);
|
||||||
|
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings.isKickNonRegisteredEnabled) {
|
if (Settings.isKickNonRegisteredEnabled) {
|
||||||
if (!data.isAuthAvailable(name)) {
|
if (!data.isAuthAvailable(name)) {
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("reg_only")[0]);
|
event.setKickMessage(m._("reg_only")[0]);
|
||||||
|
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (player.isOnline() && Settings.isForceSingleSessionEnabled) {
|
if (player.isOnline() && Settings.isForceSingleSessionEnabled) {
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("same_nick")[0]);
|
event.setKickMessage(m._("same_nick")[0]);
|
||||||
|
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -430,7 +440,8 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
// joined with same nick of online player
|
// joined with same nick of online player
|
||||||
if (player.isOnline() && Settings.isForceSingleSessionEnabled) {
|
if (player.isOnline() && Settings.isForceSingleSessionEnabled) {
|
||||||
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase());
|
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase());
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("same_nick")[0]);
|
event.setKickMessage(m._("same_nick")[0]);
|
||||||
|
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||||
if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) {
|
if (PlayerCache.getInstance().isAuthenticated(player.getName().toLowerCase())) {
|
||||||
utils.addNormal(player, limbo.getGroup());
|
utils.addNormal(player, limbo.getGroup());
|
||||||
LimboCache.getInstance().deleteLimboPlayer(player.getName().toLowerCase());
|
LimboCache.getInstance().deleteLimboPlayer(player.getName().toLowerCase());
|
||||||
@ -444,33 +455,39 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
|
|
||||||
if (name.length() > max || name.length() < min) {
|
if (name.length() > max || name.length() < min) {
|
||||||
|
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("name_len")[0]);
|
event.setKickMessage(m._("name_len")[0]);
|
||||||
|
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (!player.getName().matches(regex) || name.equals("Player")) {
|
if (!player.getName().matches(regex) || name.equals("Player")) {
|
||||||
try {
|
try {
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("regex")[0].replace("REG_EX", regex));
|
event.setKickMessage(m._("regex")[0].replace("REG_EX", regex));
|
||||||
|
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||||
} catch (Exception exc) {
|
} catch (Exception exc) {
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "allowed char : " + regex);
|
event.setKickMessage("allowed char : " + regex);
|
||||||
|
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (PatternSyntaxException pse) {
|
} catch (PatternSyntaxException pse) {
|
||||||
if (regex == null || regex.isEmpty()) {
|
if (regex == null || regex.isEmpty()) {
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Your nickname do not match");
|
event.setKickMessage("Your nickname do not match");
|
||||||
|
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, m._("regex")[0].replace("REG_EX", regex));
|
event.setKickMessage(m._("regex")[0].replace("REG_EX", regex));
|
||||||
|
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||||
} catch (Exception exc) {
|
} catch (Exception exc) {
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "allowed char : " + regex);
|
event.setKickMessage("allowed char : " + regex);
|
||||||
|
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.getResult() == PlayerLoginEvent.Result.ALLOWED) {
|
if (event.getLoginResult() == AsyncPlayerPreLoginEvent.Result.ALLOWED) {
|
||||||
checkAntiBotMod(event);
|
checkAntiBotMod(event, player);
|
||||||
if (Settings.bungee) {
|
if (Settings.bungee) {
|
||||||
final ByteArrayOutputStream b = new ByteArrayOutputStream();
|
final ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||||
DataOutputStream out = new DataOutputStream(b);
|
DataOutputStream out = new DataOutputStream(b);
|
||||||
@ -483,12 +500,13 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (event.getResult() != PlayerLoginEvent.Result.KICK_FULL)
|
if (event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.KICK_FULL)
|
||||||
return;
|
return;
|
||||||
if (player.isBanned())
|
if (player.isBanned())
|
||||||
return;
|
return;
|
||||||
if (!plugin.authmePermissible(player, "authme.vip")) {
|
if (!plugin.authmePermissible(player, "authme.vip")) {
|
||||||
event.disallow(Result.KICK_FULL, m._("kick_fullserver")[0]);
|
event.setKickMessage(m._("kick_fullserver")[0]);
|
||||||
|
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_FULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,16 +521,17 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
ConsoleLogger.info("The player " + player.getName() + " wants to join, but the server is full");
|
ConsoleLogger.info("The player " + player.getName() + " wants to join, but the server is full");
|
||||||
event.disallow(Result.KICK_FULL, m._("kick_fullserver")[0]);
|
event.setKickMessage(m._("kick_fullserver")[0]);
|
||||||
|
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_FULL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkAntiBotMod(final PlayerLoginEvent event) {
|
private void checkAntiBotMod(final AsyncPlayerPreLoginEvent event, final Player player) {
|
||||||
if (plugin.delayedAntiBot || plugin.antibotMod)
|
if (plugin.delayedAntiBot || plugin.antibotMod)
|
||||||
return;
|
return;
|
||||||
if (plugin.authmePermissible(event.getPlayer(), "authme.bypassantibot"))
|
if (plugin.authmePermissible(player, "authme.bypassantibot"))
|
||||||
return;
|
return;
|
||||||
if (antibot.keySet().size() > Settings.antiBotSensibility) {
|
if (antibot.keySet().size() > Settings.antiBotSensibility) {
|
||||||
plugin.switchAntiBotMod(true);
|
plugin.switchAntiBotMod(true);
|
||||||
@ -532,12 +551,12 @@ public class AuthMePlayerListener implements Listener {
|
|||||||
}, Settings.antiBotDuration * 1200);
|
}, Settings.antiBotDuration * 1200);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
antibot.put(event.getPlayer().getName().toLowerCase(), event);
|
antibot.put(player.getName().toLowerCase(), event);
|
||||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
antibot.remove(event.getPlayer().getName().toLowerCase());
|
antibot.remove(player.getName().toLowerCase());
|
||||||
}
|
}
|
||||||
}, 300);
|
}, 300);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user