Search in sources :

Example 1 with UserListBans

use of net.minecraft.server.management.UserListBans in project SpongeCommon by SpongePowered.

the class SpongeBanService method getBanFor.

@Override
public Optional<Ban.Profile> getBanFor(GameProfile profile) {
    UserListBans bans = this.getUserBanList();
    bans.removeExpired();
    return Optional.ofNullable((Ban.Profile) bans.getValues().get(bans.getObjectKey((com.mojang.authlib.GameProfile) profile)));
}
Also used : GameProfile(org.spongepowered.api.profile.GameProfile) Ban(org.spongepowered.api.util.ban.Ban) UserListBans(net.minecraft.server.management.UserListBans)

Example 2 with UserListBans

use of net.minecraft.server.management.UserListBans in project SpongeCommon by SpongePowered.

the class UserDiscoverer method getFromBanlist.

private static User getFromBanlist(UUID uniqueId) {
    GameProfile profile = null;
    UserListBans banList = SpongeImpl.getServer().getPlayerList().getBannedPlayers();
    UserListEntryBan<GameProfile> banData = banList.getEntry(new GameProfile(uniqueId, ""));
    if (banData != null) {
        profile = banData.value;
    }
    if (profile != null) {
        return create(profile);
    }
    return null;
}
Also used : GameProfile(com.mojang.authlib.GameProfile) UserListBans(net.minecraft.server.management.UserListBans)

Example 3 with UserListBans

use of net.minecraft.server.management.UserListBans in project SpongeCommon by SpongePowered.

the class UserDiscoverer method getAllProfiles.

static Collection<org.spongepowered.api.profile.GameProfile> getAllProfiles() {
    Preconditions.checkState(Sponge.isServerAvailable(), "Server is not available!");
    Set<org.spongepowered.api.profile.GameProfile> profiles = Sets.newHashSet();
    // Add all cached profiles
    profiles.addAll(userCache.asMap().values().stream().map(User::getProfile).collect(Collectors.toList()));
    // Add all known profiles from the data files
    SaveHandler saveHandler = (SaveHandler) WorldManager.getWorldByDimensionId(0).get().getSaveHandler();
    String[] uuids = saveHandler.getAvailablePlayerDat();
    for (String playerUuid : uuids) {
        // before passing that back in getAvailablePlayerDat. It doesn't remove non ".dat" filenames from the list.
        if (playerUuid.contains(".")) {
            continue;
        }
        // At this point, we have a filename who has no extension. This doesn't mean it is actually a UUID. We trap the exception and ignore
        // any filenames that fail the UUID check.
        UUID uuid;
        try {
            uuid = UUID.fromString(playerUuid);
        } catch (Exception ex) {
            continue;
        }
        final GameProfile profile = SpongeImpl.getServer().getPlayerProfileCache().getProfileByUUID(uuid);
        if (profile != null) {
            profiles.add((org.spongepowered.api.profile.GameProfile) profile);
        }
    }
    // Add all whitelisted users
    final UserListWhitelist whiteList = SpongeImpl.getServer().getPlayerList().getWhitelistedPlayers();
    profiles.addAll(whiteList.getValues().values().stream().map(entry -> (org.spongepowered.api.profile.GameProfile) entry.value).collect(Collectors.toList()));
    // Add all banned users
    final UserListBans banList = SpongeImpl.getServer().getPlayerList().getBannedPlayers();
    profiles.addAll(banList.getValues().values().stream().filter(entry -> entry != null).map(entry -> (org.spongepowered.api.profile.GameProfile) entry.value).collect(Collectors.toList()));
    return profiles;
}
Also used : SpongeImpl(org.spongepowered.common.SpongeImpl) SaveHandler(net.minecraft.world.storage.SaveHandler) GameProfile(com.mojang.authlib.GameProfile) UserListBans(net.minecraft.server.management.UserListBans) SpongeUser(org.spongepowered.common.entity.player.SpongeUser) HashSet(java.util.HashSet) IMixinEntityPlayerMP(org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayerMP) Locale(java.util.Locale) UserListEntryBan(net.minecraft.server.management.UserListEntryBan) SpongeUsernameCache(org.spongepowered.common.util.SpongeUsernameCache) PlayerProfileCache(net.minecraft.server.management.PlayerProfileCache) WorldServer(net.minecraft.world.WorldServer) User(org.spongepowered.api.entity.living.player.User) WorldManager(org.spongepowered.common.world.WorldManager) Collection(java.util.Collection) Sponge(org.spongepowered.api.Sponge) Set(java.util.Set) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) UUID(java.util.UUID) PlayerList(net.minecraft.server.management.PlayerList) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) CompressedStreamTools(net.minecraft.nbt.CompressedStreamTools) UserListWhitelist(net.minecraft.server.management.UserListWhitelist) UserListWhitelistEntry(net.minecraft.server.management.UserListWhitelistEntry) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) CacheBuilder(com.google.common.cache.CacheBuilder) Cache(com.google.common.cache.Cache) SpongeUser(org.spongepowered.common.entity.player.SpongeUser) User(org.spongepowered.api.entity.living.player.User) IOException(java.io.IOException) SaveHandler(net.minecraft.world.storage.SaveHandler) GameProfile(com.mojang.authlib.GameProfile) UserListWhitelist(net.minecraft.server.management.UserListWhitelist) UUID(java.util.UUID) UserListBans(net.minecraft.server.management.UserListBans)

Example 4 with UserListBans

use of net.minecraft.server.management.UserListBans in project SpongeCommon by SpongePowered.

the class UserDiscoverer method deleteBanlistEntry.

private static boolean deleteBanlistEntry(UUID uniqueId) {
    UserListBans banList = SpongeImpl.getServer().getPlayerList().getBannedPlayers();
    banList.removeEntry(new GameProfile(uniqueId, ""));
    return true;
}
Also used : GameProfile(com.mojang.authlib.GameProfile) UserListBans(net.minecraft.server.management.UserListBans)

Example 5 with UserListBans

use of net.minecraft.server.management.UserListBans in project SpongeCommon by SpongePowered.

the class SpongeBanService method isBanned.

@Override
public boolean isBanned(GameProfile profile) {
    UserListBans bans = this.getUserBanList();
    bans.removeExpired();
    return bans.values.containsKey(bans.getObjectKey((com.mojang.authlib.GameProfile) profile));
}
Also used : GameProfile(org.spongepowered.api.profile.GameProfile) UserListBans(net.minecraft.server.management.UserListBans)

Aggregations

UserListBans (net.minecraft.server.management.UserListBans)5 GameProfile (com.mojang.authlib.GameProfile)3 GameProfile (org.spongepowered.api.profile.GameProfile)2 Preconditions (com.google.common.base.Preconditions)1 Cache (com.google.common.cache.Cache)1 CacheBuilder (com.google.common.cache.CacheBuilder)1 Sets (com.google.common.collect.Sets)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Locale (java.util.Locale)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 CompressedStreamTools (net.minecraft.nbt.CompressedStreamTools)1 PlayerList (net.minecraft.server.management.PlayerList)1