public void process() { preLogout(); if (!canLogout) return; final Player p = player; BukkitScheduler sched = p.getServer().getScheduler(); PlayerAuth auth = PlayerCache.getInstance().getAuth(name); database.updateSession(auth); auth.setQuitLocX(p.getLocation().getX()); auth.setQuitLocY(p.getLocation().getY()); auth.setQuitLocZ(p.getLocation().getZ()); auth.setWorld(p.getWorld().getName()); database.updateQuitLoc(auth); PlayerCache.getInstance().removePlayer(name); database.setUnlogged(name); if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) { Location spawnLoc = plugin.getSpawnLocation(p); final AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(p, spawnLoc); sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { plugin.getServer().getPluginManager().callEvent(tpEvent); if (!tpEvent.isCancelled()) { if (tpEvent.getTo() != null) p.teleport(tpEvent.getTo()); } } }); } if (LimboCache.getInstance().hasLimboPlayer(name)) LimboCache.getInstance().deleteLimboPlayer(name); LimboCache.getInstance().addLimboPlayer(player); utils.setGroup(player, GroupType.NOTLOGGEDIN); if (Settings.protectInventoryBeforeLogInEnabled) { player.getInventory().clear(); // create cache file for handling lost of inventories on unlogged in // status DataFileCache playerData = new DataFileCache( LimboCache.getInstance().getLimboPlayer(name).getInventory(), LimboCache.getInstance().getLimboPlayer(name).getArmour()); playerBackup.createCache(player, playerData); } sched.scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerLogout(p, plugin)); }
public void process() { AuthMePlayerListener.gameMode.put(name, player.getGameMode()); BukkitScheduler sched = plugin.getServer().getScheduler(); if (plugin.getCitizensCommunicator().isNPC(player) || Utils.getInstance().isUnrestricted(player) || CombatTagComunicator.isNPC(player)) { return; } if (plugin.ess != null && Settings.disableSocialSpy) { try { plugin.ess.getUser(player.getName().toLowerCase()).setSocialSpyEnabled(false); } catch (Exception e) { } catch (NoSuchMethodError e) { } } final String ip = plugin.getIP(player); if (Settings.isAllowRestrictedIp && !Settings.getRestrictedIp(name, ip)) { final GameMode gM = AuthMePlayerListener.gameMode.get(name); sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { AuthMePlayerListener.causeByAuthMe.put(name, true); player.setGameMode(gM); AuthMePlayerListener.causeByAuthMe.put(name, false); player.kickPlayer("You are not the Owner of this account, please try another name!"); if (Settings.banUnsafeIp) plugin.getServer().banIP(ip); } }); return; } if (Settings.getMaxJoinPerIp > 0 && !plugin.authmePermissible(player, "authme.allow2accounts") && !ip.equalsIgnoreCase("127.0.0.1") && !ip.equalsIgnoreCase("localhost")) { if (plugin.hasJoinedIp(player.getName(), ip)) { player.kickPlayer("A player with the same IP is already in game!"); return; } } final Location spawnLoc = plugin.getSpawnLocation(player); if (database.isAuthAvailable(name)) { if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) { sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { AuthMePlayerListener.causeByAuthMe.put(name, true); Utils.forceGM(player); AuthMePlayerListener.causeByAuthMe.put(name, false); } }); } if (!Settings.noTeleport) if (Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) { sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { SpawnTeleportEvent tpEvent = new SpawnTeleportEvent( player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name)); plugin.getServer().getPluginManager().callEvent(tpEvent); if (!tpEvent.isCancelled()) { if (player != null && player.isOnline() && tpEvent.getTo() != null) { if (tpEvent.getTo().getWorld() != null) player.teleport(tpEvent.getTo()); } } } }); } placePlayerSafely(player, spawnLoc); LimboCache.getInstance().updateLimboPlayer(player); try { DataFileCache dataFile = new DataFileCache( LimboCache.getInstance().getLimboPlayer(name).getInventory(), LimboCache.getInstance().getLimboPlayer(name).getArmour()); playerBackup.createCache( player, dataFile, LimboCache.getInstance().getLimboPlayer(name).getGroup(), LimboCache.getInstance().getLimboPlayer(name).getOperator(), LimboCache.getInstance().getLimboPlayer(name).isFlying()); } catch (Exception e) { ConsoleLogger.showError( "Error on creating an inventory cache for " + name + ", maybe inventory wipe in preparation..."); } } else { if (Settings.isForceSurvivalModeEnabled && !Settings.forceOnlyAfterLogin) { sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { AuthMePlayerListener.causeByAuthMe.put(name, true); Utils.forceGM(player); AuthMePlayerListener.causeByAuthMe.put(name, false); } }); } if (!Settings.unRegisteredGroup.isEmpty()) { utils.setGroup(player, Utils.groupType.UNREGISTERED); } if (!Settings.isForcedRegistrationEnabled) { return; } if (!Settings.noTeleport) if (!needFirstspawn() && Settings.isTeleportToSpawnEnabled || (Settings.isForceSpawnLocOnJoinEnabled && Settings.getForcedWorlds.contains(player.getWorld().getName()))) { sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { SpawnTeleportEvent tpEvent = new SpawnTeleportEvent( player, player.getLocation(), spawnLoc, PlayerCache.getInstance().isAuthenticated(name)); plugin.getServer().getPluginManager().callEvent(tpEvent); if (!tpEvent.isCancelled()) { if (player != null && player.isOnline() && tpEvent.getTo() != null) { if (tpEvent.getTo().getWorld() != null) player.teleport(tpEvent.getTo()); } } } }); } } if (Settings.protectInventoryBeforeLogInEnabled) { sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { try { LimboPlayer limbo = LimboCache.getInstance().getLimboPlayer(player.getName().toLowerCase()); ProtectInventoryEvent ev = new ProtectInventoryEvent(player, limbo.getInventory(), limbo.getArmour()); plugin.getServer().getPluginManager().callEvent(ev); if (ev.isCancelled()) { if (!Settings.noConsoleSpam) ConsoleLogger.info( "ProtectInventoryEvent has been cancelled for " + player.getName() + " ..."); } else { plugin.api.setPlayerInventory(player, ev.getEmptyInventory(), ev.getEmptyArmor()); } } catch (NullPointerException ex) { } } }); } String[] msg; if (Settings.emailRegistration) { msg = database.isAuthAvailable(name) ? m.send("login_msg") : m.send("reg_email_msg"); } else { msg = database.isAuthAvailable(name) ? m.send("login_msg") : m.send("reg_msg"); } int time = Settings.getRegistrationTimeout * 20; int msgInterval = Settings.getWarnMessageInterval; if (time != 0) { BukkitTask id = sched.runTaskLaterAsynchronously(plugin, new TimeoutTask(plugin, name), time); if (!LimboCache.getInstance().hasLimboPlayer(name)) LimboCache.getInstance().addLimboPlayer(player); LimboCache.getInstance().getLimboPlayer(name).setTimeoutTaskId(id); } if (!LimboCache.getInstance().hasLimboPlayer(name)) LimboCache.getInstance().addLimboPlayer(player); if (database.isAuthAvailable(name)) { utils.setGroup(player, groupType.NOTLOGGEDIN); } else { utils.setGroup(player, groupType.UNREGISTERED); } sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { if (player.isOp()) player.setOp(false); if (player.getGameMode() != GameMode.CREATIVE && !Settings.isMovementAllowed) { player.setAllowFlight(true); player.setFlying(true); } player.setNoDamageTicks(Settings.getRegistrationTimeout * 20); if (Settings.useEssentialsMotd) player.performCommand("motd"); if (Settings.applyBlindEffect) player.addPotionEffect( new PotionEffect( PotionEffectType.BLINDNESS, Settings.getRegistrationTimeout * 20, 2)); } }); if (Settings.isSessionsEnabled && database.isAuthAvailable(name) && (PlayerCache.getInstance().isAuthenticated(name) || database.isLogged(name))) { if (plugin.sessions.containsKey(name)) plugin.sessions.get(name).cancel(); plugin.sessions.remove(name); PlayerAuth auth = database.getAuth(name); if (auth != null && auth.getIp().equals(ip)) { m.send(player, "valid_session"); PlayerCache.getInstance().removePlayer(name); database.setUnlogged(name); plugin.management.performLogin(player, "dontneed", true); } else if (Settings.sessionExpireOnIpChange) { PlayerCache.getInstance().removePlayer(name); database.setUnlogged(name); m.send(player, "invalid_session"); } return; } BukkitTask msgT = sched.runTaskAsynchronously(plugin, new MessageTask(plugin, name, msg, msgInterval)); LimboCache.getInstance().getLimboPlayer(name).setMessageTaskId(msgT); }
public class AsyncronousLogout { protected Player player; protected String name; protected AuthMe plugin; protected DataSource database; protected boolean canLogout = true; private Messages m = Messages.getInstance(); private Utils utils = Utils.getInstance(); private JsonCache playerBackup; public AsyncronousLogout(Player player, AuthMe plugin, DataSource database) { this.player = player; this.plugin = plugin; this.database = database; this.name = player.getName().toLowerCase(); this.playerBackup = new JsonCache(plugin); } private void preLogout() { if (!PlayerCache.getInstance().isAuthenticated(name)) { m.send(player, "not_logged_in"); canLogout = false; } } public void process() { preLogout(); if (!canLogout) return; final Player p = player; BukkitScheduler sched = p.getServer().getScheduler(); PlayerAuth auth = PlayerCache.getInstance().getAuth(name); database.updateSession(auth); auth.setQuitLocX(p.getLocation().getX()); auth.setQuitLocY(p.getLocation().getY()); auth.setQuitLocZ(p.getLocation().getZ()); auth.setWorld(p.getWorld().getName()); database.updateQuitLoc(auth); PlayerCache.getInstance().removePlayer(name); database.setUnlogged(name); if (Settings.isTeleportToSpawnEnabled && !Settings.noTeleport) { Location spawnLoc = plugin.getSpawnLocation(p); final AuthMeTeleportEvent tpEvent = new AuthMeTeleportEvent(p, spawnLoc); sched.scheduleSyncDelayedTask( plugin, new Runnable() { @Override public void run() { plugin.getServer().getPluginManager().callEvent(tpEvent); if (!tpEvent.isCancelled()) { if (tpEvent.getTo() != null) p.teleport(tpEvent.getTo()); } } }); } if (LimboCache.getInstance().hasLimboPlayer(name)) LimboCache.getInstance().deleteLimboPlayer(name); LimboCache.getInstance().addLimboPlayer(player); utils.setGroup(player, GroupType.NOTLOGGEDIN); if (Settings.protectInventoryBeforeLogInEnabled) { player.getInventory().clear(); // create cache file for handling lost of inventories on unlogged in // status DataFileCache playerData = new DataFileCache( LimboCache.getInstance().getLimboPlayer(name).getInventory(), LimboCache.getInstance().getLimboPlayer(name).getArmour()); playerBackup.createCache(player, playerData); } sched.scheduleSyncDelayedTask(plugin, new ProcessSyncronousPlayerLogout(p, plugin)); } }