use of net.minecraft.server.management.UserListWhitelist 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;
}
use of net.minecraft.server.management.UserListWhitelist in project SpongeCommon by SpongePowered.
the class UserDiscoverer method getFromWhitelist.
private static User getFromWhitelist(UUID uniqueId) {
GameProfile profile = null;
UserListWhitelist whiteList = SpongeImpl.getServer().getPlayerList().getWhitelistedPlayers();
UserListWhitelistEntry whiteListData = whiteList.getEntry(new GameProfile(uniqueId, ""));
if (whiteListData != null) {
profile = whiteListData.value;
}
if (profile != null) {
return create(profile);
}
return null;
}
use of net.minecraft.server.management.UserListWhitelist in project SpongeCommon by SpongePowered.
the class UserDiscoverer method deleteWhitelistEntry.
private static boolean deleteWhitelistEntry(UUID uniqueId) {
UserListWhitelist whiteList = SpongeImpl.getServer().getPlayerList().getWhitelistedPlayers();
whiteList.removeEntry(new GameProfile(uniqueId, ""));
return true;
}
use of net.minecraft.server.management.UserListWhitelist in project SpongeCommon by SpongePowered.
the class SpongeWhitelistService method isWhitelisted.
@Override
public boolean isWhitelisted(GameProfile profile) {
UserListWhitelist whitelist = getWhitelist();
whitelist.removeExpired();
return whitelist.getValues().containsKey(whitelist.getObjectKey((com.mojang.authlib.GameProfile) profile));
}
Aggregations