mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-12-28 19:47:35 +01:00
Merge branch 'master' of https://github.com/AuthMe-Team/AuthMeReloaded into command-perms-refactor
This commit is contained in:
commit
bb93c7164a
@ -530,7 +530,7 @@ public class PlayerAuth {
|
||||
}
|
||||
|
||||
public Builder name(String name) {
|
||||
this.name = name;
|
||||
this.name = name.toLowerCase();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,8 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class LimboCache {
|
||||
@ -117,9 +119,8 @@ public class LimboCache {
|
||||
* @param name String
|
||||
*/
|
||||
public void deleteLimboPlayer(String name) {
|
||||
if (name == null)
|
||||
return;
|
||||
cache.remove(name);
|
||||
checkNotNull(name);
|
||||
cache.remove(name.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -130,9 +131,8 @@ public class LimboCache {
|
||||
* @return LimboPlayer
|
||||
*/
|
||||
public LimboPlayer getLimboPlayer(String name) {
|
||||
if (name == null)
|
||||
return null;
|
||||
return cache.get(name);
|
||||
checkNotNull(name);
|
||||
return cache.get(name.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -143,9 +143,8 @@ public class LimboCache {
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean hasLimboPlayer(String name) {
|
||||
if (name == null)
|
||||
return false;
|
||||
return cache.containsKey(name);
|
||||
checkNotNull(name);
|
||||
return cache.containsKey(name.toLowerCase());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -154,9 +153,8 @@ public class LimboCache {
|
||||
* @param player Player
|
||||
*/
|
||||
public void updateLimboPlayer(Player player) {
|
||||
if (this.hasLimboPlayer(player.getName().toLowerCase())) {
|
||||
this.deleteLimboPlayer(player.getName().toLowerCase());
|
||||
}
|
||||
checkNotNull(player);
|
||||
deleteLimboPlayer(player.getName().toLowerCase());
|
||||
addLimboPlayer(player);
|
||||
}
|
||||
|
||||
|
@ -108,8 +108,9 @@ public class LimboPlayer {
|
||||
* @param i BukkitTask
|
||||
*/
|
||||
public void setTimeoutTaskId(BukkitTask i) {
|
||||
if (this.timeoutTaskId != null)
|
||||
if (this.timeoutTaskId != null) {
|
||||
this.timeoutTaskId.cancel();
|
||||
}
|
||||
this.timeoutTaskId = i;
|
||||
}
|
||||
|
||||
@ -128,11 +129,27 @@ public class LimboPlayer {
|
||||
* @param messageTaskId BukkitTask
|
||||
*/
|
||||
public void setMessageTaskId(BukkitTask messageTaskId) {
|
||||
if (this.messageTaskId != null)
|
||||
if (this.messageTaskId != null) {
|
||||
this.messageTaskId.cancel();
|
||||
}
|
||||
this.messageTaskId = messageTaskId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method clearTask.
|
||||
*
|
||||
*/
|
||||
public void clearTask() {
|
||||
if (messageTaskId != null) {
|
||||
messageTaskId.cancel();
|
||||
}
|
||||
messageTaskId = null;
|
||||
if (timeoutTaskId != null) {
|
||||
timeoutTaskId.cancel();
|
||||
}
|
||||
timeoutTaskId = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method isFlying.
|
||||
*
|
||||
|
@ -9,10 +9,10 @@ import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboCache;
|
||||
import fr.xephi.authme.cache.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.GeoLiteAPI;
|
||||
import fr.xephi.authme.util.Utils;
|
||||
@ -32,8 +32,6 @@ import org.bukkit.event.player.*;
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import static fr.xephi.authme.output.MessageKey.USERNAME_ALREADY_ONLINE_ERROR;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class AuthMePlayerListener implements Listener {
|
||||
@ -56,7 +54,7 @@ public class AuthMePlayerListener implements Listener {
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
if(Utils.checkAuth(player)) {
|
||||
if (Utils.checkAuth(player)) {
|
||||
for (Player p : Utils.getOnlinePlayers()) {
|
||||
if (!PlayerCache.getInstance().isAuthenticated(p.getName())) {
|
||||
event.getRecipients().remove(p); // TODO: it should be configurable
|
||||
@ -169,20 +167,21 @@ public class AuthMePlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
if (event.getPlayer() == null || Utils.isNPC(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Player player = event.getPlayer();
|
||||
final String name = player.getName().toLowerCase();
|
||||
final String joinMsg = event.getJoinMessage();
|
||||
final boolean delay = Settings.delayJoinLeaveMessages && joinMsg != null;
|
||||
String name = player.getName().toLowerCase();
|
||||
String joinMsg = event.getJoinMessage();
|
||||
boolean delay = Settings.delayJoinLeaveMessages && joinMsg != null;
|
||||
|
||||
// Remove the join message while the player isn't logging in
|
||||
if (delay) {
|
||||
event.setJoinMessage(null);
|
||||
joinMessage.put(name, joinMsg);
|
||||
}
|
||||
|
||||
// Shedule login task so works after the prelogin
|
||||
@ -190,9 +189,6 @@ public class AuthMePlayerListener implements Listener {
|
||||
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (delay) {
|
||||
joinMessage.put(name, joinMsg);
|
||||
}
|
||||
plugin.getManagement().performJoin(player);
|
||||
}
|
||||
});
|
||||
@ -200,34 +196,48 @@ public class AuthMePlayerListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPreLogin(AsyncPlayerPreLoginEvent event) {
|
||||
if (!plugin.canConnect()) {
|
||||
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||
event.setKickMessage("Server is loading, please wait before joining!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (Settings.enableProtection) {
|
||||
String countryCode = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
|
||||
if (!Settings.countriesBlacklist.isEmpty() && Settings.countriesBlacklist.contains(countryCode)) {
|
||||
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||
event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
return;
|
||||
}
|
||||
if (!Settings.countries.isEmpty() && !Settings.countries.contains(countryCode)) {
|
||||
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||
event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
final String name = event.getName().toLowerCase();
|
||||
final Player player = Utils.getPlayer(name);
|
||||
if (player == null || Utils.isNPC(player)) {
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if forceSingleSession is set to true, so kick player that has
|
||||
// joined with same nick of online player
|
||||
if (Settings.isForceSingleSessionEnabled && player.isOnline()) {
|
||||
event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, m.retrieveSingle(USERNAME_ALREADY_ONLINE_ERROR));
|
||||
if (LimboCache.getInstance().hasLimboPlayer(name))
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
|
||||
if (limbo != null && PlayerCache.getInstance().isAuthenticated(name)) {
|
||||
Utils.addNormal(player, limbo.getGroup());
|
||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (Settings.isForceSingleSessionEnabled) {
|
||||
event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
|
||||
event.setKickMessage(m.retrieveSingle(MessageKey.USERNAME_ALREADY_ONLINE_ERROR));
|
||||
LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(name);
|
||||
if (limbo != null && PlayerCache.getInstance().isAuthenticated(name)) {
|
||||
Utils.addNormal(player, limbo.getGroup());
|
||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerLogin(PlayerLoginEvent event) {
|
||||
if (event.getPlayer() == null) {
|
||||
if (event.getPlayer() == null || Utils.isUnrestricted(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -262,31 +272,9 @@ public class AuthMePlayerListener implements Listener {
|
||||
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, PlayerPermission.BYPASS_ANTIBOT)) {
|
||||
String code = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
|
||||
if (Settings.countriesBlacklist.contains(code)) {
|
||||
event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (Settings.enableProtection && !Settings.countries.isEmpty() && !isAuthAvailable && !permsMan.hasPermission(player, PlayerPermission.BYPASS_ANTIBOT)) {
|
||||
String code = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
|
||||
if (!Settings.countries.contains(code)) {
|
||||
event.setKickMessage(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
event.setResult(PlayerLoginEvent.Result.KICK_OTHER);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add message to the messages file!!!
|
||||
if (Settings.isKickNonRegisteredEnabled && !isAuthAvailable) {
|
||||
if (Settings.antiBotInAction) {
|
||||
@ -329,7 +317,7 @@ public class AuthMePlayerListener implements Listener {
|
||||
|
||||
Player player = event.getPlayer();
|
||||
|
||||
if (!Utils.checkAuth(player) && Settings.delayJoinLeaveMessages) {
|
||||
if (Settings.delayJoinLeaveMessages && !Utils.checkAuth(player)) {
|
||||
event.setQuitMessage(null);
|
||||
}
|
||||
|
||||
@ -342,8 +330,8 @@ public class AuthMePlayerListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Settings.isForceSingleSessionEnabled && event.getReason().contains(
|
||||
m.retrieveSingle(USERNAME_ALREADY_ONLINE_ERROR))) {
|
||||
if ((!Settings.isForceSingleSessionEnabled)
|
||||
&& (event.getReason().equals(m.retrieveSingle(MessageKey.USERNAME_ALREADY_ONLINE_ERROR)))) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -354,31 +342,34 @@ public class AuthMePlayerListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
|
||||
if (Utils.checkAuth(event.getPlayer()))
|
||||
if (Utils.checkAuth(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onPlayerInteract(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player == null || Utils.checkAuth(player))
|
||||
if (Utils.checkAuth(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
|
||||
public void onPlayerConsumeItem(PlayerItemConsumeEvent event) {
|
||||
if (Utils.checkAuth(event.getPlayer()))
|
||||
if (Utils.checkAuth(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onPlayerInventoryOpen(InventoryOpenEvent event) {
|
||||
final Player player = (Player) event.getPlayer();
|
||||
if (Utils.checkAuth(player))
|
||||
if (Utils.checkAuth(player)) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
|
||||
/*
|
||||
@ -386,7 +377,6 @@ public class AuthMePlayerListener implements Listener {
|
||||
* real, cause no packet is send to server by client for the main inv
|
||||
*/
|
||||
Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
player.closeInventory();
|
||||
@ -411,50 +401,55 @@ public class AuthMePlayerListener implements Listener {
|
||||
if (!(damager instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
if (Utils.checkAuth((Player) damager))
|
||||
if (Utils.checkAuth((Player) damager)) {
|
||||
return;
|
||||
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player == null || Utils.checkAuth(player))
|
||||
if (Utils.checkAuth(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onPlayerDropItem(PlayerDropItemEvent event) {
|
||||
if (Utils.checkAuth(event.getPlayer()))
|
||||
if (Utils.checkAuth(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
|
||||
if (Utils.checkAuth(event.getPlayer()))
|
||||
if (Utils.checkAuth(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onSignChange(SignChangeEvent event) {
|
||||
if (Utils.checkAuth(event.getPlayer()))
|
||||
if (Utils.checkAuth(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player == null || Utils.checkAuth(player))
|
||||
if (Utils.checkAuth(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
String name = player.getName().toLowerCase();
|
||||
Location spawn = plugin.getSpawnLocation(player);
|
||||
if (Settings.isSaveQuitLocationEnabled && plugin.database.isAuthAvailable(name)) {
|
||||
final PlayerAuth auth = new PlayerAuth(name, spawn.getX(), spawn.getY(), spawn.getZ(), spawn.getWorld().getName(), player.getName());
|
||||
PlayerAuth auth = new PlayerAuth(name, spawn.getX(), spawn.getY(), spawn.getZ(), spawn.getWorld().getName(), player.getName());
|
||||
plugin.database.updateQuitLoc(auth);
|
||||
}
|
||||
if (spawn != null && spawn.getWorld() != null) {
|
||||
@ -464,13 +459,14 @@ public class AuthMePlayerListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
|
||||
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event) {
|
||||
if (Utils.checkAuth(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
|
||||
Player player = event.getPlayer();
|
||||
if (player == null)
|
||||
return;
|
||||
if (plugin.getPermissionsManager().hasPermission(player, PlayerPermission.BYPASS_FORCE_SURVIVAL))
|
||||
return;
|
||||
if (Utils.checkAuth(player))
|
||||
if (plugin.getPermissionsManager().hasPermission(player, PlayerPermission.BYPASS_FORCE_SURVIVAL)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String name = player.getName().toLowerCase();
|
||||
if (causeByAuthMe.containsKey(name)) {
|
||||
@ -482,17 +478,17 @@ public class AuthMePlayerListener implements Listener {
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
|
||||
public void onPlayerShear(PlayerShearEntityEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player == null || Utils.checkAuth(player))
|
||||
if (Utils.checkAuth(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.NORMAL)
|
||||
public void onPlayerFish(PlayerFishEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player == null || Utils.checkAuth(player))
|
||||
if (Utils.checkAuth(event.getPlayer())) {
|
||||
return;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
|
@ -43,19 +43,13 @@ public class AuthMeServerListener implements Listener {
|
||||
}
|
||||
|
||||
String countryCode = GeoLiteAPI.getCountryCode(event.getAddress().getHostAddress());
|
||||
if (!Settings.countriesBlacklist.isEmpty()) {
|
||||
if (Settings.countriesBlacklist.contains(countryCode)) {
|
||||
event.setMotd(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
return;
|
||||
}
|
||||
if (!Settings.countriesBlacklist.isEmpty() && Settings.countriesBlacklist.contains(countryCode)) {
|
||||
event.setMotd(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Settings.countries.isEmpty()) {
|
||||
if (Settings.countries.contains(countryCode)) {
|
||||
event.setMotd(plugin.getServer().getMotd());
|
||||
} else {
|
||||
event.setMotd(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
}
|
||||
if (!Settings.countries.isEmpty() && !Settings.countries.contains(countryCode)) {
|
||||
event.setMotd(m.retrieveSingle(MessageKey.COUNTRY_BANNED_ERROR));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -50,33 +50,16 @@ public class AsynchronousJoin {
|
||||
}
|
||||
|
||||
public void process() {
|
||||
if (AuthMePlayerListener.gameMode.containsKey(name))
|
||||
AuthMePlayerListener.gameMode.remove(name);
|
||||
AuthMePlayerListener.gameMode.putIfAbsent(name, player.getGameMode());
|
||||
|
||||
if (Utils.isNPC(player) || Utils.isUnrestricted(player)) {
|
||||
if (Utils.isUnrestricted(player)) {
|
||||
return;
|
||||
}
|
||||
|
||||
AuthMePlayerListener.gameMode.put(name, player.getGameMode());
|
||||
|
||||
if (plugin.ess != null && Settings.disableSocialSpy) {
|
||||
plugin.ess.getUser(player).setSocialSpyEnabled(false);
|
||||
}
|
||||
|
||||
if (!plugin.canConnect()) {
|
||||
final GameMode gM = AuthMePlayerListener.gameMode.get(name);
|
||||
sched.scheduleSyncDelayedTask(plugin, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
AuthMePlayerListener.causeByAuthMe.putIfAbsent(name, true);
|
||||
player.setGameMode(gM);
|
||||
player.kickPlayer("Server is loading, please wait before joining!");
|
||||
}
|
||||
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
final String ip = plugin.getIP(player);
|
||||
if (Settings.isAllowRestrictedIp && !Settings.getRestrictedIp(name, ip)) {
|
||||
final GameMode gM = AuthMePlayerListener.gameMode.get(name);
|
||||
|
@ -5,16 +5,13 @@ import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.cache.auth.PlayerAuth;
|
||||
import fr.xephi.authme.cache.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.output.MessageKey;
|
||||
import fr.xephi.authme.output.Messages;
|
||||
import fr.xephi.authme.permission.PlayerPermission;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
*/
|
||||
public class AsyncRegister {
|
||||
@ -22,7 +19,8 @@ public class AsyncRegister {
|
||||
protected final Player player;
|
||||
protected final String name;
|
||||
protected final String password;
|
||||
protected String email = "";
|
||||
private final String ip;
|
||||
private String email = "";
|
||||
private final AuthMe plugin;
|
||||
private final DataSource database;
|
||||
private final Messages m;
|
||||
@ -35,13 +33,10 @@ public class AsyncRegister {
|
||||
this.email = email;
|
||||
this.plugin = plugin;
|
||||
this.database = data;
|
||||
this.ip = plugin.getIP(player);
|
||||
}
|
||||
|
||||
protected String getIp() {
|
||||
return plugin.getIP(player);
|
||||
}
|
||||
|
||||
protected boolean preRegisterCheck() throws Exception {
|
||||
private boolean preRegisterCheck() throws Exception {
|
||||
String passLow = password.toLowerCase();
|
||||
if (PlayerCache.getInstance().isAuthenticated(name)) {
|
||||
m.send(player, MessageKey.ALREADY_LOGGED_IN_ERROR);
|
||||
@ -65,10 +60,10 @@ public class AsyncRegister {
|
||||
m.send(player, MessageKey.NAME_ALREADY_REGISTERED);
|
||||
return false;
|
||||
} else if (Settings.getmaxRegPerIp > 0
|
||||
&& !plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
|
||||
&& database.getAllAuthsByIp(getIp()).size() >= Settings.getmaxRegPerIp
|
||||
&& !getIp().equalsIgnoreCase("127.0.0.1")
|
||||
&& !getIp().equalsIgnoreCase("localhost")) {
|
||||
&& !plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
|
||||
&& !ip.equalsIgnoreCase("127.0.0.1")
|
||||
&& !ip.equalsIgnoreCase("localhost")
|
||||
&& database.getAllAuthsByIp(ip).size() >= Settings.getmaxRegPerIp) {
|
||||
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
|
||||
return false;
|
||||
}
|
||||
@ -81,16 +76,10 @@ public class AsyncRegister {
|
||||
return;
|
||||
}
|
||||
if (!email.isEmpty() && !email.equals("")) {
|
||||
if (Settings.getmaxRegPerEmail > 0
|
||||
&& !plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
|
||||
&& database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
|
||||
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
|
||||
return;
|
||||
}
|
||||
emailRegister();
|
||||
return;
|
||||
} else {
|
||||
passwordRegister();
|
||||
}
|
||||
passwordRegister();
|
||||
} catch (Exception e) {
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
ConsoleLogger.writeStackTrace(e);
|
||||
@ -98,20 +87,32 @@ public class AsyncRegister {
|
||||
}
|
||||
}
|
||||
|
||||
protected void emailRegister() throws Exception {
|
||||
private void emailRegister() throws Exception {
|
||||
if (Settings.getmaxRegPerEmail > 0
|
||||
&& !plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
|
||||
&& database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
|
||||
&& !plugin.getPermissionsManager().hasPermission(player, PlayerPermission.ALLOW_MULTIPLE_ACCOUNTS)
|
||||
&& database.getAllAuthsByEmail(email).size() >= Settings.getmaxRegPerEmail) {
|
||||
m.send(player, MessageKey.MAX_REGISTER_EXCEEDED);
|
||||
return;
|
||||
}
|
||||
PlayerAuth auth;
|
||||
final String hashNew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
|
||||
auth = new PlayerAuth(name, hashNew, getIp(), 0, (int) player.getLocation().getX(), (int) player.getLocation().getY(), (int) player.getLocation().getZ(), player.getLocation().getWorld().getName(), email, player.getName());
|
||||
if (PasswordSecurity.userSalt.containsKey(name)) {
|
||||
auth.setSalt(PasswordSecurity.userSalt.get(name));
|
||||
final String salt = PasswordSecurity.userSalt.get(name);
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
.name(name)
|
||||
.realName(player.getName())
|
||||
.hash(hashNew)
|
||||
.ip(ip)
|
||||
.locWorld(player.getLocation().getWorld().getName())
|
||||
.locX(player.getLocation().getX())
|
||||
.locY(player.getLocation().getY())
|
||||
.locZ(player.getLocation().getZ())
|
||||
.email(email)
|
||||
.salt(salt != null ? salt : "")
|
||||
.build();
|
||||
|
||||
if (!database.saveAuth(auth)) {
|
||||
m.send(player, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
database.saveAuth(auth);
|
||||
database.updateEmail(auth);
|
||||
database.updateSession(auth);
|
||||
plugin.mail.main(auth, password);
|
||||
@ -120,21 +121,21 @@ public class AsyncRegister {
|
||||
|
||||
}
|
||||
|
||||
protected void passwordRegister() {
|
||||
PlayerAuth auth;
|
||||
String hash;
|
||||
try {
|
||||
hash = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
ConsoleLogger.showError(e.getMessage());
|
||||
m.send(player, MessageKey.ERROR);
|
||||
return;
|
||||
}
|
||||
if (Settings.getMySQLColumnSalt.isEmpty() && !PasswordSecurity.userSalt.containsKey(name)) {
|
||||
auth = new PlayerAuth(name, hash, getIp(), new Date().getTime(), "your@email.com", player.getName());
|
||||
} else {
|
||||
auth = new PlayerAuth(name, hash, PasswordSecurity.userSalt.get(name), getIp(), new Date().getTime(), player.getName());
|
||||
}
|
||||
private void passwordRegister() throws Exception {
|
||||
final String hashNew = PasswordSecurity.getHash(Settings.getPasswordHash, password, name);
|
||||
final String salt = PasswordSecurity.userSalt.get(name);
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
.name(name)
|
||||
.realName(player.getName())
|
||||
.hash(hashNew)
|
||||
.ip(ip)
|
||||
.locWorld(player.getLocation().getWorld().getName())
|
||||
.locX(player.getLocation().getX())
|
||||
.locY(player.getLocation().getY())
|
||||
.locZ(player.getLocation().getZ())
|
||||
.salt(salt != null ? salt : "")
|
||||
.build();
|
||||
|
||||
if (!database.saveAuth(auth)) {
|
||||
m.send(player, MessageKey.ERROR);
|
||||
return;
|
||||
|
@ -41,15 +41,13 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
protected void forceCommands() {
|
||||
private void forceCommands() {
|
||||
for (String command : Settings.forceRegisterCommands) {
|
||||
try {
|
||||
player.performCommand(command.replace("%p", player.getName()));
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
player.performCommand(command.replace("%p", player.getName()));
|
||||
}
|
||||
for (String command : Settings.forceRegisterCommandsAsConsole) {
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), command.replace("%p", player.getName()));
|
||||
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(),
|
||||
command.replace("%p", player.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,20 +56,21 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
|
||||
*
|
||||
* @param player Player
|
||||
*/
|
||||
protected void forceLogin(Player player) {
|
||||
private void forceLogin(Player player) {
|
||||
Utils.teleportToSpawn(player);
|
||||
if (LimboCache.getInstance().hasLimboPlayer(name))
|
||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||
LimboCache.getInstance().addLimboPlayer(player);
|
||||
LimboCache cache = LimboCache.getInstance();
|
||||
cache.updateLimboPlayer(player);
|
||||
int delay = Settings.getRegistrationTimeout * 20;
|
||||
int interval = Settings.getWarnMessageInterval;
|
||||
BukkitScheduler sched = plugin.getServer().getScheduler();
|
||||
BukkitTask task;
|
||||
if (delay != 0) {
|
||||
BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay);
|
||||
LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id);
|
||||
task = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name, player), delay);
|
||||
cache.getLimboPlayer(name).setTimeoutTaskId(task);
|
||||
}
|
||||
BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, m.retrieve(MessageKey.LOGIN_MESSAGE), interval));
|
||||
LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT);
|
||||
task = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name,
|
||||
m.retrieve(MessageKey.LOGIN_MESSAGE), interval));
|
||||
cache.getLimboPlayer(name).setMessageTaskId(task);
|
||||
if (player.isInsideVehicle() && player.getVehicle() != null) {
|
||||
player.getVehicle().eject();
|
||||
}
|
||||
@ -97,33 +96,39 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
limbo.getTimeoutTaskId().cancel();
|
||||
limbo.getMessageTaskId().cancel();
|
||||
LimboCache.getInstance().deleteLimboPlayer(name);
|
||||
}
|
||||
|
||||
if (!Settings.getRegisteredGroup.isEmpty()) {
|
||||
Utils.setGroup(player, Utils.GroupType.REGISTERED);
|
||||
}
|
||||
|
||||
m.send(player, MessageKey.REGISTER_SUCCESS);
|
||||
if (!Settings.getmailAccount.isEmpty())
|
||||
|
||||
if (!Settings.getmailAccount.isEmpty()) {
|
||||
m.send(player, MessageKey.ADD_EMAIL_MESSAGE);
|
||||
}
|
||||
if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) {
|
||||
player.setAllowFlight(false);
|
||||
player.setFlying(false);
|
||||
}
|
||||
if (Settings.applyBlindEffect)
|
||||
|
||||
if (Settings.applyBlindEffect) {
|
||||
player.removePotionEffect(PotionEffectType.BLINDNESS);
|
||||
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
|
||||
player.setWalkSpeed(0.2f);
|
||||
player.setFlySpeed(0.1f);
|
||||
}
|
||||
|
||||
if (!Settings.isMovementAllowed && Settings.isRemoveSpeedEnabled) {
|
||||
player.setWalkSpeed(0.0f);
|
||||
player.setFlySpeed(0.0f);
|
||||
}
|
||||
|
||||
// The LoginEvent now fires (as intended) after everything is processed
|
||||
plugin.getServer().getPluginManager().callEvent(new LoginEvent(player, true));
|
||||
player.saveData();
|
||||
|
||||
if (!Settings.noConsoleSpam)
|
||||
if (!Settings.noConsoleSpam) {
|
||||
ConsoleLogger.info(player.getName() + " registered " + plugin.getIP(player));
|
||||
}
|
||||
|
||||
// Kick Player after Registration is enabled, kick the player
|
||||
if (Settings.forceRegKick) {
|
||||
@ -138,7 +143,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
|
||||
}
|
||||
|
||||
// Register is finish and player is logged, display welcome message
|
||||
if (Settings.useWelcomeMessage)
|
||||
if (Settings.useWelcomeMessage) {
|
||||
if (Settings.broadcastWelcomeMessage) {
|
||||
for (String s : Settings.welcomeMsg) {
|
||||
plugin.getServer().broadcastMessage(plugin.replaceAllInfo(s, player));
|
||||
@ -148,6 +153,7 @@ public class ProcessSyncronousPasswordRegister implements Runnable {
|
||||
player.sendMessage(plugin.replaceAllInfo(s, player));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Register is now finish , we can force all commands
|
||||
forceCommands();
|
||||
|
@ -110,6 +110,11 @@ public final class Settings {
|
||||
configFile = (YamlConfiguration) plugin.getConfig();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method reload.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public static void reload() throws Exception {
|
||||
plugin.getLogger().info("Loading Configuration File...");
|
||||
boolean exist = SETTINGS_FILE.exists();
|
||||
@ -184,7 +189,12 @@ public final class Settings {
|
||||
getMySQLColumnRealName = configFile.getString("DataSource.mySQLRealName", "realname");
|
||||
getNonActivatedGroup = configFile.getInt("ExternalBoardOptions.nonActivedUserGroup", -1);
|
||||
unRegisteredGroup = configFile.getString("GroupOptions.UnregisteredPlayerGroup", "");
|
||||
getUnrestrictedName = configFile.getStringList("settings.unrestrictions.UnrestrictedName");
|
||||
|
||||
getUnrestrictedName = new ArrayList<>();
|
||||
for (String name : configFile.getStringList("settings.unrestrictions.UnrestrictedName")) {
|
||||
getUnrestrictedName.add(name.toLowerCase());
|
||||
}
|
||||
|
||||
getRegisteredGroup = configFile.getString("GroupOptions.RegisteredPlayerGroup", "");
|
||||
getEnablePasswordVerifier = configFile.getBoolean("settings.restrictions.enablePasswordVerifier", true);
|
||||
|
||||
@ -328,6 +338,11 @@ public final class Settings {
|
||||
save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getPasswordHash.
|
||||
*
|
||||
* @return HashAlgorithm
|
||||
*/
|
||||
private static HashAlgorithm getPasswordHash() {
|
||||
String key = "settings.security.passwordHash";
|
||||
try {
|
||||
@ -338,6 +353,11 @@ public final class Settings {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method getDataSource.
|
||||
*
|
||||
* @return DataSourceType
|
||||
*/
|
||||
private static DataSourceType getDataSource() {
|
||||
String key = "DataSource.backend";
|
||||
try {
|
||||
@ -391,6 +411,13 @@ public final class Settings {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method checkLang.
|
||||
*
|
||||
* @param lang String
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public static String checkLang(String lang) {
|
||||
if (new File(PLUGIN_FOLDER, "messages" + File.separator + "messages_" + lang + ".yml").exists()) {
|
||||
ConsoleLogger.info("Set Language to: " + lang);
|
||||
@ -404,6 +431,11 @@ public final class Settings {
|
||||
return "en";
|
||||
}
|
||||
|
||||
/**
|
||||
* Method switchAntiBotMod.
|
||||
*
|
||||
* @param mode boolean
|
||||
*/
|
||||
public static void switchAntiBotMod(boolean mode) {
|
||||
if (mode) {
|
||||
isKickNonRegisteredEnabled = true;
|
||||
@ -445,6 +477,13 @@ public final class Settings {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method isEmailCorrect.
|
||||
*
|
||||
* @param email String
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isEmailCorrect(String email) {
|
||||
if (!email.contains("@"))
|
||||
return false;
|
||||
@ -697,7 +736,7 @@ public final class Settings {
|
||||
|
||||
/**
|
||||
* Saves current configuration (plus defaults) to disk.
|
||||
* <p/>
|
||||
* <p>
|
||||
* If defaults and configuration are empty, saves blank file.
|
||||
*
|
||||
* @return True if saved successfully
|
||||
|
@ -156,8 +156,9 @@ public final class Utils {
|
||||
}
|
||||
|
||||
public static boolean isUnrestricted(Player player) {
|
||||
return Settings.isAllowRestrictedIp && !Settings.getUnrestrictedName.isEmpty()
|
||||
&& (Settings.getUnrestrictedName.contains(player.getName()));
|
||||
return Settings.isAllowRestrictedIp
|
||||
&& !Settings.getUnrestrictedName.isEmpty()
|
||||
&& (Settings.getUnrestrictedName.contains(player.getName().toLowerCase()));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user