<commit_before>package com.namelessmc.plugin.spigot;

import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Logger;

import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;

import com.namelessmc.java_api.NamelessAPI;
import com.namelessmc.java_api.NamelessException;
import com.namelessmc.java_api.NamelessUser;
import com.namelessmc.java_api.UserFilter;

public class WhitelistRegistered implements Runnable {

	public WhitelistRegistered() {
		// Return if this feature is disabled
		if (!Config.MAIN.getConfig().getBoolean("auto-whitelist-registered.enabled", false)) {
			return;
		}

		this.run();
	}

	@Override
	public void run() {
		final boolean verified = Config.MAIN.getConfig().getBoolean("auto-whitelist-registered.verified");
		final boolean log = Config.MAIN.getConfig().getBoolean("auto-whitelist-registered.log");
		final Logger logger = NamelessPlugin.getInstance().getLogger();

		if (log) {
			logger.info("Starting auto-whitelist");
		}

		Bukkit.getScheduler().runTaskAsynchronously(NamelessPlugin.getInstance(), () -> {
			UserFilter<?>[] filters;
			if (verified) {
				filters = new UserFilter<?>[] {UserFilter.VERIFIED, UserFilter.UNBANNED};
			} else {
				filters = new UserFilter<?>[] {UserFilter.UNBANNED};
			}

			if (log) {
				logger.info("Retrieving list of users...");
			}

			List<NamelessUser> users;
			try {
				final Optional<NamelessAPI> optApi = NamelessPlugin.getInstance().getNamelessApi();
				if (optApi.isPresent()) {
					users = optApi.get().getRegisteredUsers(filters);
				} else {
					logger.warning("Skipped getting list of registered users, it looks like the API is not working properly.");
					return;
				}
			} catch (final NamelessException e) {
				logger.warning(
						"An error occured while getting a list of registered users from the website for the auto-whitelist-registered feature.");
				e.printStackTrace();
				return;
			}

			final Set<UUID> uuids = new HashSet<>();
			for (final NamelessUser user : users) {
				try {
					final Optional<UUID> optUuid = user.getUniqueId();
					if (optUuid.isPresent()) {
						uuids.add(optUuid.get());
					} else {
						logger.warning("Website user " + user.getUsername() + " does not have a UUID!");
					}
				} catch (final NamelessException e) {
					logger.warning("A user has been skipped due to a website communication error");<commit_msg>auto whitelist: generate offline mode uuid if username mode enabled<commit_after>package com.namelessmc.plugin.spigot;

import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.logging.Logger;

import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;

import com.namelessmc.java_api.NamelessAPI;
import com.namelessmc.java_api.NamelessException;
import com.namelessmc.java_api.NamelessUser;
import com.namelessmc.java_api.UserFilter;

public class WhitelistRegistered implements Runnable {

	public WhitelistRegistered() {
		// Return if this feature is disabled
		if (!Config.MAIN.getConfig().getBoolean("auto-whitelist-registered.enabled", false)) {
			return;
		}

		this.run();
	}

	@Override
	public void run() {
		final boolean verified = Config.MAIN.getConfig().getBoolean("auto-whitelist-registered.verified");
		final boolean log = Config.MAIN.getConfig().getBoolean("auto-whitelist-registered.log");
		final Logger logger = NamelessPlugin.getInstance().getLogger();

		if (log) {
			logger.info("Starting auto-whitelist");
		}

		Bukkit.getScheduler().runTaskAsynchronously(NamelessPlugin.getInstance(), () -> {
			UserFilter<?>[] filters;
			if (verified) {
				filters = new UserFilter<?>[] {UserFilter.VERIFIED, UserFilter.UNBANNED};
			} else {
				filters = new UserFilter<?>[] {UserFilter.UNBANNED};
			}

			if (log) {
				logger.info("Retrieving list of users...");
			}

			List<NamelessUser> users;
			try {
				final Optional<NamelessAPI> optApi = NamelessPlugin.getInstance().getNamelessApi();
				if (optApi.isPresent()) {
					users = optApi.get().getRegisteredUsers(filters);
				} else {
					logger.warning("Skipped getting list of registered users, it looks like the API is not working properly.");
					return;
				}
			} catch (final NamelessException e) {
				logger.warning(
						"An error occured while getting a list of registered users from the website for the auto-whitelist-registered feature.");
				e.printStackTrace();
				return;
			}

			final Set<UUID> uuids = new HashSet<>();
			for (final NamelessUser user : users) {
				try {
					if (NamelessPlugin.getInstance().getApiProvider().useUuids()) {
						final Optional<UUID> optUuid = user.getUniqueId();
						if (optUuid.isPresent()) {
							uuids.add(optUuid.get());
						} else {
							logger.warning("Website user " + user.getUsername() + " does not have a UUID!");
						}
					} else {
						String name = user.getUsername();
						UUID offlineUuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(StandardCharsets.UTF_8));
						uuids.add(offlineUuid);
					}
				} catch (final NamelessException e) {
					logger.warning("A user has been skipped due to a website communication error");
{'fraction_non_alphanumeric': 0.12521278607906186, 'fraction_numerical': 0.00018914318138831096, 'mean_word_length': 3.9236499068901303, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2889008', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1631, 'n_words': 379}