Java Code Examples for org.bukkit.event.player.AsyncPlayerPreLoginEvent#disallow()

The following examples show how to use org.bukkit.event.player.AsyncPlayerPreLoginEvent#disallow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BukkitConnectionListener.java    From LuckPerms with MIT License 7 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerPreLoginMonitor(AsyncPlayerPreLoginEvent e) {
    /* Listen to see if the event was cancelled after we initially handled the connection
       If the connection was cancelled here, we need to do something to clean up the data that was loaded. */

    // Check to see if this connection was denied at LOW.
    if (this.deniedAsyncLogin.remove(e.getUniqueId())) {
        // their data was never loaded at LOW priority, now check to see if they have been magically allowed since then.

        // This is a problem, as they were denied at low priority, but are now being allowed.
        if (e.getLoginResult() == AsyncPlayerPreLoginEvent.Result.ALLOWED) {
            this.plugin.getLogger().severe("Player connection was re-allowed for " + e.getUniqueId());
            e.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "");
        }
    }
}
 
Example 2
Source File: PlayerListener.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onAsyncPlayerPreLoginEventLowest(AsyncPlayerPreLoginEvent event) {
    if (event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
        return;
    }
    final String name = event.getName();

    // NOTE: getAddress() sometimes returning null, we don't want to handle this race condition
    if (event.getAddress() == null) {
        event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER,
            messages.retrieveSingle(name, MessageKey.KICK_UNRESOLVED_HOSTNAME));
        return;
    }

    if (validationService.isUnrestricted(name)) {
        return;
    }

    // Non-blocking checks
    try {
        onJoinVerifier.checkIsValidName(name);
    } catch (FailedVerificationException e) {
        event.setKickMessage(messages.retrieveSingle(name, e.getReason(), e.getArgs()));
        event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
    }
}
 
Example 3
Source File: StartupListener.java    From VoxelGamesLibv2 with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onLogin(AsyncPlayerPreLoginEvent event) {
    if (!startupHandler.isReady()) {
        event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "Server is starting, please gimme a second!");
    }

    if (startupHandler.isInterrupted()) {
        event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "Server start was interrupted, please try again later");
    }
}
 
Example 4
Source File: UserListener.java    From VoxelGamesLibv2 with MIT License 5 votes vote down vote up
@EventHandler
public void onAsyncLogin(@Nonnull AsyncPlayerPreLoginEvent event) {
    if (!handler.login(event.getUniqueId())) {
        // something went horribly wrong
        // we don't have a locale here since the data was not loaded :/
        event.disallow(Result.KICK_OTHER, Lang.legacyColors(Lang.string(LangKey.DATA_NOT_LOADED)));
    }
}
 
Example 5
Source File: LoginListener.java    From Bukkit-Connect with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onAsyncPlayerPreLogin(AsyncPlayerPreLoginEvent event) {
	LoginPayload payload = payloadCache.getByName(event.getName());
	if (payload == null) {
		event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "LilyPad: Internal server error");
		return;
	}
}
 
Example 6
Source File: LoginListener.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void preLogin(final AsyncPlayerPreLoginEvent event) {
    this.logger.info(event.getName() + " pre-login: uuid=" + event.getUniqueId() + " ip=" + event.getAddress());

    try(Locker _ = Locker.lock(connectedLock.readLock())) {
        this.logins.invalidate(event.getUniqueId());

        if(!connected) {
            event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, SERVER_IS_RESTARTING);
            return;
        }

        LoginResponse response = this.userService.login(
            new LoginRequest(event.getName(),
                             event.getUniqueId(),
                             event.getAddress(),
                             minecraftService.getLocalServer(),
                             true)
        ).get();

        if(response.kick() != null) switch(response.kick()) {
            case "error":
                this.logger.info(event.getName() + " login error: " + response.message());
                event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, response.message());
                break;

            case "banned": // Only used for IP bans right now
                this.logger.info(event.getName() + " is banned");
                event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_BANNED, response.message());
                break;
        }

        if(event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) return;

        this.logins.put(event.getUniqueId(), response);

        eventBus.callEvent(new AsyncUserLoginEvent(response));
    } catch(Exception e) {
        this.logger.log(Level.SEVERE, e.toString(), e);
        event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER, INTERNAL_SERVER_ERROR);
    }
}
 
Example 7
Source File: AOListener.java    From AlwaysOnline with GNU General Public License v2.0 2 votes vote down vote up
@EventHandler(priority = EventPriority.LOWEST)
public void onAsyncPreLogin(AsyncPlayerPreLoginEvent event) {

	if (AlwaysOnline.MOJANG_OFFLINE_MODE) {

		String username = event.getName();

		if (!this.validate(username)) {

			event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER,
					this.spigotLoader.alwaysOnline.config.getProperty("message-kick-invalid", "Invalid username. Hacking?"));
			return;

		}

		String ip = event.getAddress().getHostAddress();

		String lastIP = this.spigotLoader.alwaysOnline.database.getIP(username);

		if (lastIP == null) {

			event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER,
					this.spigotLoader.alwaysOnline.config.getProperty("message-kick-new", "We can not let you join because the mojang servers are offline!"));

		} else {

			if (!lastIP.equals(ip)) {

				event.disallow(AsyncPlayerPreLoginEvent.Result.KICK_OTHER,
						this.spigotLoader.alwaysOnline.config.getProperty("message-kick-ip",
								"We can not let you join since you are not on the same computer you logged on before!"));

			} else {

				this.spigotLoader.log(Level.INFO, username + " was successfully authenticated while mojang servers were offline. Connecting IP is " + ip + " and the last authenticated known IP was " + lastIP);

			}

		}

	}

}