<commit_before>package com.karanumcoding.adamantineshield;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandManager;
import org.spongepowered.api.command.args.GenericArguments;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.event.EventManager;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GamePostInitializationEvent;
import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.text.Text;

import com.google.inject.Inject;
import com.karanumcoding.adamantineshield.commands.*;
import com.karanumcoding.adamantineshield.commands.arguments.TimeStringArgument;
import com.karanumcoding.adamantineshield.commands.lookup.*;
import com.karanumcoding.adamantineshield.commands.pages.*;
import com.karanumcoding.adamantineshield.commands.rollback.*;
import com.karanumcoding.adamantineshield.db.Database;
import com.karanumcoding.adamantineshield.enums.Permissions;
import com.karanumcoding.adamantineshield.listeners.MobBlockChangeListener;
import com.karanumcoding.adamantineshield.listeners.InventoryChangeListener;
import com.karanumcoding.adamantineshield.listeners.LiquidFlowListener;
import com.karanumcoding.adamantineshield.listeners.PlayerBlockChangeListener;
import com.karanumcoding.adamantineshield.listeners.PlayerInspectListener;
import com.karanumcoding.adamantineshield.lookup.InspectManager;
import com.karanumcoding.adamantineshield.lookup.LookupResultManager;
import com.karanumcoding.adamantineshield.util.FilterParser;

@Plugin(id = "adamantineshield", name = "AdamantineShield", version = "0.2.0", authors = { "Karanum", "Snootiful" },
	description = "Action logging and rollback plugin for Sponge"
)
public class AdamantineShield {
	
	@Inject
	private Logger logger;
	public Logger getLogger() {
		return logger;
	}
	
	private ConfigHandler config;
	private Database db;
	
	private InspectManager inspectManager;
	
	@Listener
	public void onPreInit(GamePreInitializationEvent e) {
		try {
			config = new ConfigHandler(this);
		} catch (IOException ioEx) {
			ioEx.printStackTrace();
			logger.error("Could not load configuration file! Plugin was not loaded!");
			return;
		}
		FilterParser.setConfig(config);
		LookupResultManager.instance().setLinesPerPage(config.getInt("logging", "lines-per-page"));
		
		try {
			db = new Database(this, config.getJdbcString());
		} catch (SQLException sqlEx) {
			sqlEx.printStackTrace();
			logger.error("Could not connect to the database! Plugin was not loaded!");
			return;
		}
		
		if (config.getBool("purge", "auto-purge")) {
			int days = config.getInt("purge", "auto-purge-days");
			logger.info("Purging entries older than " + days + " days");
			if (!db.purgeEntries(new Date().getTime() - TimeUnit.DAYS.toMillis(days))) {
				logger.warn("Automatic purge failed!");
			}
		}
		
		inspectManager = new InspectManager(db);
		
		logger.info("Registering event listeners");
		registerListeners(Sponge.getEventManager());
	}
	
	@Listener
	public void onPostInit(GamePostInitializationEvent e) {
		if (db == null) return;
		logger.info("Registering plugin commands");
		registerCommands(Sponge.getCommandManager());
	}
	
	@Listener
	public void onServerStopping(GameStoppingServerEvent e) {
		if (db == null) return;
		db.stop();
	}
	
	public Database getDatabase() {
		return db;
	}
	
	public ConfigHandler getConfig() {
		return config;
	}
	
	public InspectManager getInspectManager() {
		return inspectManager;
	}
	
	private void registerListeners(EventManager man) {
		man.registerListeners(this, new PlayerInspectListener(this));
		if (config.getBool("logging", "blocks")) {
			man.registerListeners(this, new PlayerBlockChangeListener(db));
		}
		if (config.getBool("logging", "mobs")) {
			man.registerListeners(this, new MobBlockChangeListener(db));
		}
		if (config.getBool("logging", "flow")) {
			man.registerListeners(this, new LiquidFlowListener(db));
		}<commit_msg>Added lookup result disposing on player disconnect<commit_after>package com.karanumcoding.adamantineshield;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandManager;
import org.spongepowered.api.command.args.GenericArguments;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.event.EventManager;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GamePostInitializationEvent;
import org.spongepowered.api.event.game.state.GamePreInitializationEvent;
import org.spongepowered.api.event.game.state.GameStoppingServerEvent;
import org.spongepowered.api.event.network.ClientConnectionEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.text.Text;

import com.google.inject.Inject;
import com.karanumcoding.adamantineshield.commands.*;
import com.karanumcoding.adamantineshield.commands.arguments.TimeStringArgument;
import com.karanumcoding.adamantineshield.commands.lookup.*;
import com.karanumcoding.adamantineshield.commands.pages.*;
import com.karanumcoding.adamantineshield.commands.rollback.*;
import com.karanumcoding.adamantineshield.db.Database;
import com.karanumcoding.adamantineshield.enums.Permissions;
import com.karanumcoding.adamantineshield.listeners.MobBlockChangeListener;
import com.karanumcoding.adamantineshield.listeners.InventoryChangeListener;
import com.karanumcoding.adamantineshield.listeners.LiquidFlowListener;
import com.karanumcoding.adamantineshield.listeners.PlayerBlockChangeListener;
import com.karanumcoding.adamantineshield.listeners.PlayerInspectListener;
import com.karanumcoding.adamantineshield.lookup.InspectManager;
import com.karanumcoding.adamantineshield.lookup.LookupResultManager;
import com.karanumcoding.adamantineshield.util.FilterParser;

@Plugin(id = "adamantineshield", name = "AdamantineShield", version = "0.2.0", authors = { "Karanum", "Snootiful" },
	description = "Action logging and rollback plugin for Sponge"
)
public class AdamantineShield {
	
	@Inject
	private Logger logger;
	public Logger getLogger() {
		return logger;
	}
	
	private ConfigHandler config;
	private Database db;
	
	private InspectManager inspectManager;
	
	@Listener
	public void onPreInit(GamePreInitializationEvent e) {
		try {
			config = new ConfigHandler(this);
		} catch (IOException ioEx) {
			ioEx.printStackTrace();
			logger.error("Could not load configuration file! Plugin was not loaded!");
			return;
		}
		FilterParser.setConfig(config);
		LookupResultManager.instance().setLinesPerPage(config.getInt("logging", "lines-per-page"));
		
		try {
			db = new Database(this, config.getJdbcString());
		} catch (SQLException sqlEx) {
			sqlEx.printStackTrace();
			logger.error("Could not connect to the database! Plugin was not loaded!");
			return;
		}
		
		if (config.getBool("purge", "auto-purge")) {
			int days = config.getInt("purge", "auto-purge-days");
			logger.info("Purging entries older than " + days + " days");
			if (!db.purgeEntries(new Date().getTime() - TimeUnit.DAYS.toMillis(days))) {
				logger.warn("Automatic purge failed!");
			}
		}
		
		inspectManager = new InspectManager(db);
		
		logger.info("Registering event listeners");
		registerListeners(Sponge.getEventManager());
	}
	
	@Listener
	public void onPostInit(GamePostInitializationEvent e) {
		if (db == null) return;
		logger.info("Registering plugin commands");
		registerCommands(Sponge.getCommandManager());
	}
	
	@Listener
	public void onServerStopping(GameStoppingServerEvent e) {
		if (db == null) return;
		db.stop();
	}
	
	@Listener
	public void onPlayerLeave(ClientConnectionEvent.Disconnect e) {
		LookupResultManager.instance().clearLookupResult(e.getTargetEntity());
	}
	
	public Database getDatabase() {
		return db;
	}
	
	public ConfigHandler getConfig() {
		return config;
	}
	
	public InspectManager getInspectManager() {
		return inspectManager;
	}
	
	private void registerListeners(EventManager man) {
		man.registerListeners(this, new PlayerInspectListener(this));
		if (config.getBool("logging", "blocks")) {
			man.registerListeners(this, new PlayerBlockChangeListener(db));
		}
		if (config.getBool("logging", "mobs")) {
			man.registerListeners(this, new MobBlockChangeListener(db));
		}
		if (config.getBool("logging", "flow")) {
			man.registerListeners(this, new LiquidFlowListener(db));
		}
{'fraction_non_alphanumeric': 0.11211119972655804, 'fraction_numerical': 0.000911473168508602, 'mean_word_length': 5.82051282051282, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1566474', 'n_tokens_mistral': 2977, 'n_tokens_neox': 2694, 'n_words': 494}