<commit_before>package com.campmongoose.serversaturday.spigot.submission;

import com.campmongoose.serversaturday.common.MySQLHandler;
import com.campmongoose.serversaturday.common.Reference.Config;
import com.campmongoose.serversaturday.common.Reference.Messages;
import com.campmongoose.serversaturday.common.Reference.MySQL;
import com.campmongoose.serversaturday.common.submission.AbstractSubmissions;
import com.campmongoose.serversaturday.spigot.SpigotConfig;
import com.campmongoose.serversaturday.spigot.SpigotServerSaturday;
import java.io.File;
import java.sql.SQLException;
import java.util.UUID;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import org.bukkit.Location;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

public class SpigotSubmissions extends AbstractSubmissions<Player, SpigotSubmitter> {

    public SpigotSubmissions() {
        super(SpigotServerSaturday.instance().getDataFolder());
    }

    @Nonnull
    @Override
    public SpigotSubmitter getSubmitter(@Nonnull Player player) {
        return submitters.putIfAbsent(player.getUniqueId(), new SpigotSubmitter(player));
    }

    @Override
    public void load() {
        Logger logger = SpigotServerSaturday.instance().getLogger();
        if (dir.mkdirs()) {
            logger.info(Messages.newFile(dir));
        }

        File[] files = dir.listFiles();
        if (files != null) {
            for (File file : files) {
                if (!file.getName().endsWith(Config.YAML_EXT)) {
                    continue;
                }

                YamlConfiguration yaml = YamlConfiguration.loadConfiguration(file);
                UUID uuid = UUID.fromString(file.getName().replace(Config.YAML_EXT, ""));
                submitters.put(uuid, new SpigotSubmitter(uuid, yaml));
            }
        }
        else {
            logger.info("An error occurred whilst attempting to read the files in " + dir.getName());
        }
    }

    @Override
    public void save() {
        SpigotServerSaturday plugin = SpigotServerSaturday.instance();
        SpigotConfig config = plugin.getPluginConfig();
        MySQLHandler sql = plugin.getMySQLHandler();
        submitters.forEach((uuid, submitter) -> {
            if (config.getSaveFormat().equals(Config.MYSQL) && sql != null) {
                try {
                    sql.querySQL(MySQL.CREATE_TABLE);
                    sql.querySQL(MySQL.deletePlayer(uuid));
                    for (SpigotBuild build : submitter.getBuilds()) {
                        Location location = build.getLocation();
                        sql.querySQL(MySQL.addBuild(submitter.getName(), uuid, build, location.getX(), location.getY(),
                                location.getZ(), location.getYaw(), location.getPitch(), location.getWorld().getName()));
                    }
                }
                catch (ClassNotFoundException | SQLException e) {
                    e.printStackTrace();
                }
            }
            else if (config.getSaveFormat().equals(Config.YAML_EXT.replace(".", ""))) {
                submitter.save(new File(dir, Config.getYAMLFileName(uuid)));
            }
        });
    }
}
<commit_msg>Fix NPE in SpigotSubmissions.<commit_after>package com.campmongoose.serversaturday.spigot.submission;

import com.campmongoose.serversaturday.common.MySQLHandler;
import com.campmongoose.serversaturday.common.Reference.Config;
import com.campmongoose.serversaturday.common.Reference.Messages;
import com.campmongoose.serversaturday.common.Reference.MySQL;
import com.campmongoose.serversaturday.common.submission.AbstractSubmissions;
import com.campmongoose.serversaturday.spigot.SpigotConfig;
import com.campmongoose.serversaturday.spigot.SpigotServerSaturday;
import java.io.File;
import java.sql.SQLException;
import java.util.UUID;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import org.bukkit.Location;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

public class SpigotSubmissions extends AbstractSubmissions<Player, SpigotSubmitter> {

    public SpigotSubmissions() {
        super(SpigotServerSaturday.instance().getDataFolder());
    }

    @Nonnull
    @Override
    public SpigotSubmitter getSubmitter(@Nonnull Player player) {
        submitters.putIfAbsent(player.getUniqueId(), new SpigotSubmitter(player));
        return submitters.get(player.getUniqueId());
    }

    @Override
    public void load() {
        Logger logger = SpigotServerSaturday.instance().getLogger();
        if (dir.mkdirs()) {
            logger.info(Messages.newFile(dir));
        }

        File[] files = dir.listFiles();
        if (files != null) {
            for (File file : files) {
                if (!file.getName().endsWith(Config.YAML_EXT)) {
                    continue;
                }

                YamlConfiguration yaml = YamlConfiguration.loadConfiguration(file);
                UUID uuid = UUID.fromString(file.getName().replace(Config.YAML_EXT, ""));
                submitters.put(uuid, new SpigotSubmitter(uuid, yaml));
            }
        }
        else {
            logger.info("An error occurred whilst attempting to read the files in " + dir.getName());
        }
    }

    @Override
    public void save() {
        SpigotServerSaturday plugin = SpigotServerSaturday.instance();
        SpigotConfig config = plugin.getPluginConfig();
        MySQLHandler sql = plugin.getMySQLHandler();
        submitters.forEach((uuid, submitter) -> {
            if (config.getSaveFormat().equals(Config.MYSQL) && sql != null) {
                try {
                    sql.querySQL(MySQL.CREATE_TABLE);
                    sql.querySQL(MySQL.deletePlayer(uuid));
                    for (SpigotBuild build : submitter.getBuilds()) {
                        Location location = build.getLocation();
                        sql.querySQL(MySQL.addBuild(submitter.getName(), uuid, build, location.getX(), location.getY(),
                                location.getZ(), location.getYaw(), location.getPitch(), location.getWorld().getName()));
                    }
                }
                catch (ClassNotFoundException | SQLException e) {
                    e.printStackTrace();
                }
            }
            else if (config.getSaveFormat().equals(Config.YAML_EXT.replace(".", ""))) {
                submitter.save(new File(dir, Config.getYAMLFileName(uuid)));
            }
        });
    }
}

{'fraction_non_alphanumeric': 0.11090742438130156, 'fraction_numerical': 0.0, 'mean_word_length': 2.4603594080338267, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '6894997', 'n_tokens_mistral': 1823, 'n_tokens_neox': 1773, 'n_words': 296}