<commit_before>package com.github.games647.fastlogin.bukkit.hooks;

import de.st_ddt.crazylogin.CrazyLogin;
import de.st_ddt.crazylogin.data.LoginPlayerData;
import de.st_ddt.crazylogin.databases.CrazyLoginDataDatabase;

import org.bukkit.entity.Player;

/**
 * Github: https://github.com/ST-DDT/CrazyLogin
 * Project page: http://dev.bukkit.org/server-mods/crazylogin/
 */
public class CrazyLoginHook implements AuthPlugin {

    @Override
    public void forceLogin(Player player) {
        CrazyLogin crazyLoginPlugin = CrazyLogin.getPlugin();

        LoginPlayerData playerData = crazyLoginPlugin.getPlayerData(player.getName());
        if (playerData != null) {
            //mark the account as logged in
            playerData.setLoggedIn(true);
        }
    }

    @Override
    public boolean isRegistered(String playerName) {
        CrazyLogin crazyLoginPlugin = CrazyLogin.getPlugin();
        return crazyLoginPlugin.getPlayerData(playerName) != null;
    }

    @Override
    public void forceRegister(Player player, String password) {
        CrazyLogin crazyLoginPlugin = CrazyLogin.getPlugin();
        CrazyLoginDataDatabase crazyDatabase = crazyLoginPlugin.getCrazyDatabase();

        LoginPlayerData playerData = crazyLoginPlugin.getPlayerData(player.getName());
        if (playerData == null) {
            //create a fake account - this will be saved to the database with the password=<PASSWORD>
            //user cannot login with that password unless the admin uses plain text
            //this automatically marks the player as logged in
            playerData = new LoginPlayerData(player);
            crazyDatabase.save(playerData);
        }
    }
}<commit_msg>Fixed CrazyLogin restore actions<commit_after>package com.github.games647.fastlogin.bukkit.hooks;

import com.comphenix.protocol.reflect.FuzzyReflection;

import de.st_ddt.crazylogin.CrazyLogin;
import de.st_ddt.crazylogin.data.LoginPlayerData;
import de.st_ddt.crazylogin.databases.CrazyLoginDataDatabase;
import de.st_ddt.crazylogin.listener.PlayerListener;
import de.st_ddt.crazylogin.metadata.Authenticated;

import java.util.logging.Level;

import org.bukkit.entity.Player;

/**
 * Github: https://github.com/ST-DDT/CrazyLogin
 * Project page: http://dev.bukkit.org/server-mods/crazylogin/
 */
public class CrazyLoginHook implements AuthPlugin {

    private final PlayerListener playerListener = getListener();

    @Override
    public void forceLogin(Player player) {
        CrazyLogin crazyLoginPlugin = CrazyLogin.getPlugin();

        LoginPlayerData playerData = crazyLoginPlugin.getPlayerData(player.getName());
        if (playerData != null) {
            //mark the account as logged in
            playerData.setLoggedIn(true);

            String ip = player.getAddress().getAddress().getHostAddress();
//this should be done after login to restore the inventory, unhide players, prevent potential memory leaks...
//extracted from: https://github.com/ST-DDT/CrazyLogin/blob/master/src/main/java/de/st_ddt/crazylogin/CrazyLogin.java#L1948
            playerData.resetLoginFails();
            player.setFireTicks(0);

            if (playerListener != null) {
                playerListener.removeMovementBlocker(player);
                playerListener.disableHidenInventory(player);
                playerListener.disableSaveLogin(player);
                playerListener.unhidePlayer(player);
            }

            //loginFailuresPerIP.remove(IP);
            //illegalCommandUsesPerIP.remove(IP);
            //tempBans.remove(IP);
            playerData.addIP(ip);
            crazyLoginPlugin.getCrazyDatabase().saveWithoutPassword(playerData);
            player.setMetadata("Authenticated", new Authenticated(crazyLoginPlugin, player));
            crazyLoginPlugin.unregisterDynamicHooks();
        }
    }

    @Override
    public boolean isRegistered(String playerName) {
        CrazyLogin crazyLoginPlugin = CrazyLogin.getPlugin();
        return crazyLoginPlugin.getPlayerData(playerName) != null;
    }

    @Override
    public void forceRegister(Player player, String password) {
        CrazyLogin crazyLoginPlugin = CrazyLogin.getPlugin();
        CrazyLoginDataDatabase crazyDatabase = crazyLoginPlugin.getCrazyDatabase();

        LoginPlayerData playerData = crazyLoginPlugin.getPlayerData(player.getName());
        if (playerData == null) {
            //create a fake account - this will be saved to the database with the password=<PASSWORD>
            //user cannot login with that password unless the admin uses plain text
            //this automatically marks the player as logged in
            playerData = new LoginPlayerData(player);
            crazyDatabase.save(playerData);
        }
    }

    private PlayerListener getListener() {
        CrazyLogin pluginInstance = CrazyLogin.getPlugin();

        PlayerListener listener;
        try {
            listener = FuzzyReflection.getFieldValue(pluginInstance, PlayerListener.class, true);
        } catch (Exception ex) {
            pluginInstance.getLogger().log(Level.SEVERE, "Failed to get the listener instance for auto login", ex);
            listener = null;
        }

        return listener;
    }
}
{'fraction_non_alphanumeric': 0.09009009009009009, 'fraction_numerical': 0.0021084914701935977, 'mean_word_length': 3.01076095311299, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 3, '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': '4744098', 'n_tokens_mistral': 1414, 'n_tokens_neox': 1405, 'n_words': 308}