<commit_before>package com.laytonsmith.core.events;

import com.laytonsmith.PureUtilities.ClassLoading.ClassDiscovery;
import com.laytonsmith.PureUtilities.Common.StreamUtils;
import com.laytonsmith.abstraction.MCCommandSender;
import com.laytonsmith.abstraction.MCPlayer;
import com.laytonsmith.annotations.core;
import com.laytonsmith.annotations.hide;
import com.laytonsmith.core.Documentation;
import com.laytonsmith.core.LogLevel;
import com.laytonsmith.core.MethodScriptCompiler;
import com.laytonsmith.core.ParseTree;
import com.laytonsmith.core.Static;
import com.laytonsmith.core.constructs.CArray;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.environments.CommandHelperEnvironment;
import com.laytonsmith.core.environments.Environment;
import com.laytonsmith.core.environments.GlobalEnv;
import com.laytonsmith.core.exceptions.CRE.CREFormatException;
import com.laytonsmith.core.exceptions.CancelCommandException;
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
import com.laytonsmith.core.exceptions.EventException;
import com.laytonsmith.core.exceptions.FunctionReturnException;
import com.laytonsmith.core.exceptions.ProgramFlowManipulationException;
import com.laytonsmith.core.natives.interfaces.Mixed;
import com.laytonsmith.core.profiler.ProfilePoint;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;

/**
 * This helper class implements a few of the common functions in event, and most (all?) Events should extend this class.
 *
 */
public abstract class AbstractEvent implements Event, Comparable<Event> {

	private EventMixinInterface mixin;
//	protected EventHandlerInterface handler;
//
//	protected AbstractEvent(EventHandlerInterface handler){
//		this.handler = handler;
//	}
//

	public final void setAbstractEventMixin(EventMixinInterface mixin) {
		this.mixin = mixin;
	}

	/**
	 * If the event needs to run special code when a player binds the event, it can be done here. By default, an
	 * UnsupportedOperationException is thrown, but is caught and ignored.
	 */
	@Override
	public void bind(BoundEvent event) {

	}

	/**
	 * If the event needs to run special code when a player unbinds the event, it can be done here. By default, an
	 * UnsupportedOperationException is thrown, but is caught and ignored.
	 */
	@Override
	public void unbind(BoundEvent event) {

	}

	/**
	 * If the event needs to run special code at server startup, it can be done here. By default, nothing happens.
	 */
	@Override
	public void hook() {

	}

	/**
	 * This function is run when the actual event occurs.
	 *
	 * @param tree The compiled parse tree
	 * @param b The bound event
	 * @param env The operating environment
	 * @param activeEvent The active event being executed
	 */
	@Override
	public final void execute(ParseTree tree, BoundEvent b, Environment env, BoundEvent.ActiveEvent activeEvent) throws ConfigRuntimeException {
		preExecution(env, activeEvent);
		// Various events have a player to put into the env.
		// Do this after preExcecution() in case the particular event needs to inject the player first.
		Mixed c = activeEvent.getParsedEvent().get("player");
		if(c != null) {
			MCCommandSender p = Static.getServer().getPlayer(c.val());
			if(p == null) {
				p = Static.GetInjectedPlayer(c.val());
			}
			if(p != null) {
				env.getEnv(CommandHelperEnvironment.class).SetPlayer((MCPlayer) p);
			} else {
				Static.getLogger().log(Level.WARNING, "Player missing from player event: " + b.getEventName());
				// Set env CommandSender to prevent incorrect inherited player from being used in a player event.
				if(env.getEnv(CommandHelperEnvironment.class).GetPlayer() != null) {
					env.getEnv(CommandHelperEnvironment.class).SetCommandSender(Static.getServer().getConsole());
				}
			}
		}
		ProfilePoint event = null;
		if(env.getEnv(GlobalEnv.class).GetProfiler() != null) {
			event = env.getEnv(GlobalEnv.class).GetProfiler().start("Event " + b.getEventName() + " (defined at " + b.getTarget().toString() + ")", LogLevel.ERROR);
		}
		try {
			try {
				//Get the label from the bind time environment, and put it in the current environment.<commit_msg>Fix incorrect warnings of missing players in events.<commit_after>package com.laytonsmith.core.events;

import com.laytonsmith.PureUtilities.ClassLoading.ClassDiscovery;
import com.laytonsmith.PureUtilities.Common.StreamUtils;
import com.laytonsmith.abstraction.MCCommandSender;
import com.laytonsmith.abstraction.MCPlayer;
import com.laytonsmith.annotations.core;
import com.laytonsmith.annotations.hide;
import com.laytonsmith.core.Documentation;
import com.laytonsmith.core.LogLevel;
import com.laytonsmith.core.MethodScriptCompiler;
import com.laytonsmith.core.ParseTree;
import com.laytonsmith.core.Static;
import com.laytonsmith.core.constructs.CArray;
import com.laytonsmith.core.constructs.CNull;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.environments.CommandHelperEnvironment;
import com.laytonsmith.core.environments.Environment;
import com.laytonsmith.core.environments.GlobalEnv;
import com.laytonsmith.core.exceptions.CRE.CREFormatException;
import com.laytonsmith.core.exceptions.CancelCommandException;
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
import com.laytonsmith.core.exceptions.EventException;
import com.laytonsmith.core.exceptions.FunctionReturnException;
import com.laytonsmith.core.exceptions.ProgramFlowManipulationException;
import com.laytonsmith.core.natives.interfaces.Mixed;
import com.laytonsmith.core.profiler.ProfilePoint;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;

/**
 * This helper class implements a few of the common functions in event, and most (all?) Events should extend this class.
 *
 */
public abstract class AbstractEvent implements Event, Comparable<Event> {

	private EventMixinInterface mixin;
//	protected EventHandlerInterface handler;
//
//	protected AbstractEvent(EventHandlerInterface handler){
//		this.handler = handler;
//	}
//

	public final void setAbstractEventMixin(EventMixinInterface mixin) {
		this.mixin = mixin;
	}

	/**
	 * If the event needs to run special code when a player binds the event, it can be done here. By default, an
	 * UnsupportedOperationException is thrown, but is caught and ignored.
	 */
	@Override
	public void bind(BoundEvent event) {

	}

	/**
	 * If the event needs to run special code when a player unbinds the event, it can be done here. By default, an
	 * UnsupportedOperationException is thrown, but is caught and ignored.
	 */
	@Override
	public void unbind(BoundEvent event) {

	}

	/**
	 * If the event needs to run special code at server startup, it can be done here. By default, nothing happens.
	 */
	@Override
	public void hook() {

	}

	/**
	 * This function is run when the actual event occurs.
	 *
	 * @param tree The compiled parse tree
	 * @param b The bound event
	 * @param env The operating environment
	 * @param activeEvent The active event being executed
	 */
	@Override
	public final void execute(ParseTree tree, BoundEvent b, Environment env, BoundEvent.ActiveEvent activeEvent) throws ConfigRuntimeException {
		preExecution(env, activeEvent);
		// Various events have a player to put into the env.
		// Do this after preExcecution() in case the particular event needs to inject the player first.
		Mixed c = activeEvent.getParsedEvent().get("player");
		if(c != null) {
			if(c instanceof CNull) {
				// This is a CNull "player", likely from an entity event, so we need to ensure player() does
				// not return a player inherited from the bind's parent environment.
				if(env.getEnv(CommandHelperEnvironment.class).GetPlayer() != null) {
					env.getEnv(CommandHelperEnvironment.class).SetCommandSender(Static.getServer().getConsole());
				}
			} else {
				MCCommandSender p = Static.getServer().getPlayer(c.val());
				if(p == null) {
					p = Static.GetInjectedPlayer(c.val());
				}
				if(p != null) {
					env.getEnv(CommandHelperEnvironment.class).SetPlayer((MCPlayer) p);
				} else {
					Static.getLogger().log(Level.WARNING, "Player missing in player event (NPC?): " + b.getEventName());
					// Set env CommandSender to prevent incorrect inherited player from being used in a player event.
					if(env.getEnv(CommandHelperEnvironment.class).GetPlayer() != null) {
						env.getEnv(CommandHelperEnvironment.class).SetCommandSender(Static.getServer().getConsole());
					}
				}
			}
		}
		ProfilePoint event = null;
		if(env.getEnv(GlobalEnv.class).GetProfiler() != null) {
			event = env.getEnv(GlobalEnv.class).GetProfiler().start("Event " + b.getEventName() + " (defined at " + b.getTarget().toString() + ")", LogLevel.ERROR);
		}
		try {
			try {
				//Get the label from the bind time environment, and put it in the current environment.
{'fraction_non_alphanumeric': 0.10139702568724651, 'fraction_numerical': 0.0, 'mean_word_length': 4.558547276142768, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5998651', 'n_tokens_mistral': 2784, 'n_tokens_neox': 2546, 'n_words': 725}