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

The following examples show how to use org.bukkit.event.player.AsyncPlayerPreLoginEvent#getLoginResult() . 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: PlayerListener.java    From AuthMeReloaded with GNU General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onAsyncPlayerPreLoginEventHighest(AsyncPlayerPreLoginEvent event) {
    if (event.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED) {
        return;
    }
    final String name = event.getName();

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

    // Slow, blocking checks
    try {
        final PlayerAuth auth = dataSource.getAuth(name);
        final boolean isAuthAvailable = auth != null;
        onJoinVerifier.checkKickNonRegistered(isAuthAvailable);
        onJoinVerifier.checkAntibot(name, isAuthAvailable);
        onJoinVerifier.checkNameCasing(name, auth);
        final String ip = event.getAddress().getHostAddress();
        onJoinVerifier.checkPlayerCountry(name, ip, isAuthAvailable);
    } catch (FailedVerificationException e) {
        event.setKickMessage(messages.retrieveSingle(name, e.getReason(), e.getArgs()));
        event.setLoginResult(AsyncPlayerPreLoginEvent.Result.KICK_OTHER);
    }
}
 
Example 4
Source File: ConnectionEvent.java    From MCAuthenticator with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR)
public void onConnect(AsyncPlayerPreLoginEvent e) {
    if (e.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED)
        return;

    try {
        UserData d = instance.getDataSource().getUser(e.getUniqueId());
        if (d == null) return;
        userDataCache.put(e.getUniqueId(), d);
    } catch (IOException | SQLException e1) {
        instance.handleException(e1);
    }

}
 
Example 5
Source File: LoginListener.java    From ChangeSkin with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST)
public void onPreLogin(AsyncPlayerPreLoginEvent preLoginEvent) {
    if (preLoginEvent.getLoginResult() != Result.ALLOWED) {
        //in this event isCancelled option in the annotation doesn't work
        return;
    }

    UUID playerUuid = preLoginEvent.getUniqueId();
    String playerName = preLoginEvent.getName();

    UserPreference preferences = core.getStorage().getPreferences(playerUuid);
    if (preferences == null) {
        return;
    }

    plugin.startSession(playerUuid, preferences);

    Optional<SkinModel> optSkin = preferences.getTargetSkin();
    if (optSkin.isPresent()) {
        SkinModel targetSkin = optSkin.get();
        if (!preferences.isKeepSkin()) {
            targetSkin = core.checkAutoUpdate(targetSkin);
        }

        preferences.setTargetSkin(targetSkin);
        save(preferences);
    } else if (core.getConfig().getBoolean("restoreSkins")) {
        refetchSkin(playerName, preferences);
    }

    if (!preferences.getTargetSkin().isPresent()) {
        getRandomSkin().ifPresent(preferences::setTargetSkin);
    }
}
 
Example 6
Source File: JoinQuitListener.java    From BetonQuest with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void playerPreLogin(AsyncPlayerPreLoginEvent event) {
    // if player was kicked, don't load the data
    if (event.getLoginResult() != Result.ALLOWED) {
        return;
    }
    String playerID = event.getUniqueId().toString();
    BetonQuest plugin = BetonQuest.getInstance();
    plugin.putPlayerData(playerID, new PlayerData(playerID));
}
 
Example 7
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 8
Source File: ThreadPlayerLookupUUID.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
private void fireLoginEvents() throws Exception
{
    // CraftBukkit start - fire PlayerPreLoginEvent
    if (!this.field_151292_a.field_147333_a.isChannelOpen())
    {
        return;
    }

    String playerName = NetHandlerLoginServer.getGameProfile(this.field_151292_a).getName();
    java.net.InetAddress address = ((java.net.InetSocketAddress) this.field_151292_a.field_147333_a.getSocketAddress()).getAddress();
    java.util.UUID uniqueId = NetHandlerLoginServer.getGameProfile(this.field_151292_a).getId();
    final org.bukkit.craftbukkit.CraftServer server = this.mcServer.server;

    AsyncPlayerPreLoginEvent asyncEvent = new AsyncPlayerPreLoginEvent(playerName, address, uniqueId);
    server.getPluginManager().callEvent(asyncEvent);

    if (PlayerPreLoginEvent.getHandlerList().getRegisteredListeners().length != 0)
    {
        final PlayerPreLoginEvent event = new PlayerPreLoginEvent(playerName, address, uniqueId);

        if (asyncEvent.getResult() != PlayerPreLoginEvent.Result.ALLOWED)
        {
            event.disallow(asyncEvent.getResult(), asyncEvent.getKickMessage());
        }

        Waitable<PlayerPreLoginEvent.Result> waitable = new Waitable<PlayerPreLoginEvent.Result>()
        {
            @Override
            protected PlayerPreLoginEvent.Result evaluate()
            {
                server.getPluginManager().callEvent(event);
                return event.getResult();
            }
        };

        NetHandlerLoginServer.getMinecraftServer(this.field_151292_a).processQueue.add(waitable);

        if (waitable.get() != PlayerPreLoginEvent.Result.ALLOWED)
        {
            this.field_151292_a.func_147322_a(event.getKickMessage());
            return;
        }
    }
    else
    {
        if (asyncEvent.getLoginResult() != AsyncPlayerPreLoginEvent.Result.ALLOWED)
        {
            this.field_151292_a.func_147322_a(asyncEvent.getKickMessage());
            return;
        }
    }
    // CraftBukkit end

    NetHandlerLoginServer.getLogger().info("UUID of player " + NetHandlerLoginServer.getGameProfile(this.field_151292_a).getName() + " is " + NetHandlerLoginServer.getGameProfile(this.field_151292_a).getId());;
    NetHandlerLoginServer.setLoginState(this.field_151292_a, LoginState.READY_TO_ACCEPT);
}