Search in sources :

Example 1 with ProxyUser

use of org.lanternpowered.server.entity.living.player.ProxyUser in project LanternServer by LanternPowered.

the class LanternUserStorageService method getUser.

@Nullable
private ProxyUser getUser(UUID uniqueId) {
    checkNotNull(uniqueId, "uniqueId");
    ProxyUser user = this.userCache.getIfPresent(uniqueId);
    if (user != null) {
        return user;
    }
    user = getFromOnlinePlayer(uniqueId);
    if (user == null) {
        user = getFromWhitelistService(uniqueId);
        if (user == null) {
            user = getFromBanService(uniqueId);
            if (user == null) {
                user = getFromOpsConfig(uniqueId);
                // included in the player data by default.
                if (user == null) {
                    user = getFromStoredData(uniqueId);
                }
            }
        }
    }
    if (user != null) {
        this.userCache.put(uniqueId, user);
    }
    return user;
}
Also used : ProxyUser(org.lanternpowered.server.entity.living.player.ProxyUser) Nullable(javax.annotation.Nullable)

Example 2 with ProxyUser

use of org.lanternpowered.server.entity.living.player.ProxyUser in project LanternServer by LanternPowered.

the class LanternUserStorageService method getFromBanService.

/**
 * Attempts to get a {@link User} from the {@link BanService}.
 *
 * @param uniqueId The unique id
 * @return The user
 */
@Nullable
private ProxyUser getFromBanService(UUID uniqueId) {
    final LanternGameProfile gameProfile;
    final BanService banService = this.banService.get();
    if (banService instanceof BanConfig) {
        gameProfile = ((BanConfig) banService).getEntryByUUID(uniqueId).map(entry -> ((BanEntry.Profile) entry).getProfile()).orElse(null);
    } else {
        gameProfile = banService.getBanFor(new LanternGameProfile(uniqueId, null)).map(entry -> ((BanEntry.Profile) entry).getProfile()).orElse(null);
    }
    return gameProfile == null ? null : new ProxyUser(gameProfile);
}
Also used : LanternGameProfile(org.lanternpowered.server.profile.LanternGameProfile) BanConfig(org.lanternpowered.server.config.user.ban.BanConfig) ProxyUser(org.lanternpowered.server.entity.living.player.ProxyUser) BanService(org.spongepowered.api.service.ban.BanService) BanEntry(org.lanternpowered.server.config.user.ban.BanEntry) Nullable(javax.annotation.Nullable)

Example 3 with ProxyUser

use of org.lanternpowered.server.entity.living.player.ProxyUser in project LanternServer by LanternPowered.

the class LanternUserStorageService method getFromWhitelistService.

/**
 * Attempts to get a {@link User} from the {@link WhitelistService}.
 *
 * @param uniqueId The unique id
 * @return The user
 */
@Nullable
private ProxyUser getFromWhitelistService(UUID uniqueId) {
    final LanternGameProfile gameProfile;
    final WhitelistService whitelistService = this.whitelistService.get();
    if (whitelistService instanceof WhitelistConfig) {
        gameProfile = ((WhitelistConfig) whitelistService).getEntryByUUID(uniqueId).map(UserEntry::getProfile).orElse(null);
    } else {
        gameProfile = (LanternGameProfile) whitelistService.getWhitelistedProfiles().stream().filter(profile -> profile.getUniqueId().equals(uniqueId)).findFirst().orElse(null);
    }
    return gameProfile == null ? null : new ProxyUser(gameProfile);
}
Also used : WhitelistService(org.spongepowered.api.service.whitelist.WhitelistService) WhitelistConfig(org.lanternpowered.server.config.user.WhitelistConfig) LanternGameProfile(org.lanternpowered.server.profile.LanternGameProfile) UserEntry(org.lanternpowered.server.config.user.UserEntry) ProxyUser(org.lanternpowered.server.entity.living.player.ProxyUser) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)3 ProxyUser (org.lanternpowered.server.entity.living.player.ProxyUser)3 LanternGameProfile (org.lanternpowered.server.profile.LanternGameProfile)2 UserEntry (org.lanternpowered.server.config.user.UserEntry)1 WhitelistConfig (org.lanternpowered.server.config.user.WhitelistConfig)1 BanConfig (org.lanternpowered.server.config.user.ban.BanConfig)1 BanEntry (org.lanternpowered.server.config.user.ban.BanEntry)1 BanService (org.spongepowered.api.service.ban.BanService)1 WhitelistService (org.spongepowered.api.service.whitelist.WhitelistService)1