Java Code Examples for org.spongepowered.api.event.network.ClientConnectionEvent#Login

The following examples show how to use org.spongepowered.api.event.network.ClientConnectionEvent#Login . 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: PlayerEventHandler.java    From GriefDefender with MIT License 6 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerLogin(ClientConnectionEvent.Login event) {
    GDTimings.PLAYER_LOGIN_EVENT.startTimingIfSync();
    User player = event.getTargetUser();
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(event.getToTransform().getExtent().getUniqueId())) {
        GDTimings.PLAYER_LOGIN_EVENT.stopTimingIfSync();
        return;
    }

    final WorldProperties worldProperties = event.getToTransform().getExtent().getProperties();
    final UUID playerUniqueId = player.getUniqueId();
    final GDClaimManager claimWorldManager = this.dataStore.getClaimWorldManager(worldProperties.getUniqueId());
    final Instant dateNow = Instant.now();
    for (Claim claim : claimWorldManager.getWorldClaims()) {
        if (claim.getType() != ClaimTypes.ADMIN && claim.getOwnerUniqueId().equals(playerUniqueId)) {
            claim.getData().setDateLastActive(dateNow);
            for (Claim subdivision : ((GDClaim) claim).children) {
                subdivision.getData().setDateLastActive(dateNow);
            }
            ((GDClaim) claim).getInternalClaimData().setRequiresSave(true);
            ((GDClaim) claim).getInternalClaimData().save();
        }
    }
    GDTimings.PLAYER_LOGIN_EVENT.stopTimingIfSync();
}
 
Example 2
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.POST)
public void onLogin(ClientConnectionEvent.Login event) {
    try {
        actOnLoginEvent(event);
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event).build());
    }
}
 
Example 3
Source File: SpongeConnectionListener.java    From LuckPerms with MIT License 5 votes vote down vote up
@Listener(order = Order.FIRST)
@IsCancelled(Tristate.UNDEFINED)
public void onClientLogin(ClientConnectionEvent.Login e) {
    /* Called when the player starts logging into the server.
       At this point, the users data should be present and loaded.
       Listening on LOW priority to allow plugins to further modify data here. (auth plugins, etc.) */

    final GameProfile profile = e.getProfile();

    if (this.plugin.getConfiguration().get(ConfigKeys.DEBUG_LOGINS)) {
        this.plugin.getLogger().info("Processing login event for " + profile.getUniqueId() + " - " + profile.getName());
    }

    final User user = this.plugin.getUserManager().getIfLoaded(profile.getUniqueId());

    /* User instance is null for whatever reason. Could be that it was unloaded between asyncpre and now. */
    if (user == null) {
        this.deniedLogin.add(profile.getUniqueId());

        if (!getUniqueConnections().contains(profile.getUniqueId())) {
            this.plugin.getLogger().warn("User " + profile.getUniqueId() + " - " + profile.getName() +
                    " doesn't have data pre-loaded, they have never been processed during pre-login in this session." +
                    " - denying login.");
        } else {
            this.plugin.getLogger().warn("User " + profile.getUniqueId() + " - " + profile.getName() +
                    " doesn't currently have data pre-loaded, but they have been processed before in this session." +
                    " - denying login.");
        }

        e.setCancelled(true);
        e.setMessageCancelled(false);
        //noinspection deprecation
        e.setMessage(TextSerializers.LEGACY_FORMATTING_CODE.deserialize(Message.LOADING_STATE_ERROR.asString(this.plugin.getLocaleManager())));
    }
}
 
Example 4
Source File: SpongeConnectionListener.java    From LuckPerms with MIT License 5 votes vote down vote up
@Listener(order = Order.LAST)
@IsCancelled(Tristate.UNDEFINED)
public void onClientLoginMonitor(ClientConnectionEvent.Login e) {
    /* Listen to see if the event was cancelled after we initially handled the login
       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. Even if it was denied at LOW, their data will still be present.
    if (this.deniedLogin.remove(e.getProfile().getUniqueId())) {
        // This is a problem, as they were denied at low priority, but are now being allowed.
        if (!e.isCancelled()) {
            this.plugin.getLogger().severe("Player connection was re-allowed for " + e.getProfile().getUniqueId());
            e.setCancelled(true);
        }
    }
}
 
Example 5
Source File: PlayerOnlineListener.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void actOnLoginEvent(ClientConnectionEvent.Login event) {
    GameProfile profile = event.getProfile();
    UUID playerUUID = profile.getUniqueId();
    boolean banned = isBanned(profile);
    dbSystem.getDatabase().executeTransaction(new BanStatusTransaction(playerUUID, () -> banned));
}
 
Example 6
Source File: PlayerEventHandler.java    From GriefPrevention with MIT License 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerLogin(ClientConnectionEvent.Login event) {
    GPTimings.PLAYER_LOGIN_EVENT.startTimingIfSync();
    User player = event.getTargetUser();
    if (!GriefPreventionPlugin.instance.claimsEnabledForWorld(event.getToTransform().getExtent().getProperties())) {
        GPTimings.PLAYER_LOGIN_EVENT.stopTimingIfSync();
        return;
    }

    final InetAddress ipAddress = event.getConnection().getAddress().getAddress();
    // all this is anti-spam code
    if (GriefPreventionPlugin.getGlobalConfig().getConfig().spam.monitorEnabled) {
        // FEATURE: login cooldown to prevent login/logout spam with custom clients
        long now = Calendar.getInstance().getTimeInMillis();

        // if allowed to join and login cooldown enabled
        if (GriefPreventionPlugin.getGlobalConfig().getConfig().spam.loginCooldown > 0 && !player.hasPermission(GPPermissions.OVERRIDE_SPAM)) {
            // determine how long since last login and cooldown remaining
            Date lastLoginThisSession = lastLoginThisServerSessionMap.get(player.getUniqueId());
            if (lastLoginThisSession != null) {
                long millisecondsSinceLastLogin = now - lastLoginThisSession.getTime();
                long secondsSinceLastLogin = millisecondsSinceLastLogin / 1000;
                long cooldownRemaining = GriefPreventionPlugin.getGlobalConfig().getConfig().spam.loginCooldown - secondsSinceLastLogin;

                // if cooldown remaining
                if (cooldownRemaining > 0) {
                    // DAS BOOT!;
                    event.setMessage(Text.of("You must wait " + cooldownRemaining + " seconds before logging-in again."));
                    event.setCancelled(true);
                    GPTimings.PLAYER_LOGIN_EVENT.stopTimingIfSync();
                    return;
                }
            }
        }

        // if logging-in account is banned, remember IP address for later
        if (GriefPreventionPlugin.getGlobalConfig().getConfig().general.smartBan && (this.banService.isBanned(player.getProfile()) || this.banService.isBanned(ipAddress))) {
            this.tempBannedIps.add(new IpBanInfo(ipAddress, now + this.MILLISECONDS_IN_DAY, player.getName()));
        }
    }

    // remember the player's ip address
    final WorldProperties worldProperties = event.getToTransform().getExtent().getProperties();
    final UUID playerUniqueId = player.getUniqueId();
    final GPPlayerData playerData = this.dataStore.getOrCreatePlayerData(worldProperties, playerUniqueId);
    // Always reload playerdata storage on login in case a server is sharing data across servers
    playerData.getStorageData().load();
    playerData.receivedDropUnlockAdvertisement = false;
    playerData.ipAddress = ipAddress;
    final GPClaimManager claimWorldManager = this.dataStore.getClaimWorldManager(worldProperties);
    final Instant dateNow = Instant.now();
    for (Claim claim : claimWorldManager.getWorldClaims()) {
        if (claim.getType() != ClaimType.ADMIN && claim.getOwnerUniqueId().equals(playerUniqueId)) {
            // update lastActive timestamp for claim
            claim.getData().setDateLastActive(dateNow);
            // update timestamps for subdivisions
            for (Claim subdivision : ((GPClaim) claim).children) {
                subdivision.getData().setDateLastActive(dateNow);
            }
            ((GPClaim) claim).getInternalClaimData().setRequiresSave(true);
        }
    }
    GPTimings.PLAYER_LOGIN_EVENT.stopTimingIfSync();
}
 
Example 7
Source File: SpongePlugin.java    From ServerListPlus with GNU General Public License v3.0 4 votes vote down vote up
@Listener
public void onPlayerJoin(ClientConnectionEvent.Login event) {
    core.updateClient(event.getConnection().getAddress().getAddress(),
            event.getProfile().getUniqueId(), event.getProfile().getName().get());
}