<commit_before>package com.censoredsoftware.demigods.engine.util;

import com.censoredsoftware.demigods.engine.Demigods;
import com.censoredsoftware.demigods.engine.listener.DemigodsChatEvent;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;

import java.util.logging.Logger;

/**
 * Module to handle all common messages sent to players or the console.
 */
public class Messages
{
	private static final Logger LOGGER;
	private static String PLUGIN_NAME;
	private static int LINE_SIZE;

	/**
	 * Constructor for the Messages.
	 * 
	 * @param instance The current instance of the Plugin running this module.
	 */
	static
	{
		LOGGER = Demigods.PLUGIN.getLogger();
		PLUGIN_NAME = Demigods.PLUGIN.getName();
		LINE_SIZE = 59 - PLUGIN_NAME.length();
	}

	/**
	 * Sends the message <code>msg</code> as a tagged message to the <code>sender</code>.
	 * 
	 * @param sender The CommandSender to send the message to (allows console messages).
	 */
	public static void tagged(CommandSender sender, String msg)
	{
		sender.sendMessage(ChatColor.RED + "[" + PLUGIN_NAME + "] " + ChatColor.RESET + msg);
	}

	/**
	 * Sends the console message <code>msg</code> with "info" tag.
	 * 
	 * @param msg The message to be sent.
	 */
	public static void info(String msg)
	{
		if(msg.length() > LINE_SIZE)
		{
			for(String line : wrap(msg))
				LOGGER.info(line);
			return;
		}
		LOGGER.info(msg);
	}

	/**
	 * Sends the console message <code>msg</code> with "warning" tag.
	 * 
	 * @param msg The message to be sent.
	 */
	public static void warning(String msg)
	{
		if(msg.length() > LINE_SIZE)
		{
			for(String line : wrap(msg))
				LOGGER.warning(line);
			return;
		}
		LOGGER.warning(msg);
	}

	/**
	 * Sends the console message <code>msg</code> with "severe" tag.
	 * 
	 * @param msg The message to be sent.
	 */
	public static void severe(String msg)
	{
		if(msg.length() >= LINE_SIZE)
		{
			for(String line : wrap(msg))
				LOGGER.severe(line);
			return;
		}
		LOGGER.severe(msg);
	}

	public static String[] wrap(String msg)
	{
		return WordUtils.wrap(msg, LINE_SIZE, "/n", false).split("/n");
	}

	/**
	 * Broadcast to the entire server (all players and the console) the message <code>msg</code>.
	 * 
	 * @param msg The message to be sent.
	 */
	public static void broadcast(String msg)
	{
		DemigodsChatEvent chatEvent = new DemigodsChatEvent(msg);
		Bukkit.getPluginManager().callEvent(chatEvent);
		if(!chatEvent.isCancelled()) Demigods.PLUGIN.getServer().broadcastMessage(msg);
	}

	/**
	 * Let the <code>sender</code> know it does not have permission.<commit_msg>Update to new version of Messages.<commit_after>package com.censoredsoftware.demigods.engine.util;

import com.censoredsoftware.demigods.engine.Demigods;
import com.censoredsoftware.demigods.engine.listener.DemigodsChatEvent;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;

import java.util.logging.Logger;

/**
 * Module to handle all common messages sent to players or the console.
 */
public class Messages
{
	private static final Logger LOGGER;
	private static final String PLUGIN_NAME;
	private static final int LINE_SIZE, IN_GAME_LINE_SIZE;

	/**
	 * Constructor for the Messages.
	 * 
	 * @param instance The current instance of the Plugin running this module.
	 */
	static
	{
		LOGGER = Demigods.PLUGIN.getLogger();
		PLUGIN_NAME = Demigods.PLUGIN.getName();
		LINE_SIZE = 59 - PLUGIN_NAME.length();
		IN_GAME_LINE_SIZE = 54;
	}

	/**
	 * Sends the message <code>msg</code> as a tagged message to the <code>sender</code>.
	 * 
	 * @param sender The CommandSender to send the message to (allows console messages).
	 */
	public static void tagged(CommandSender sender, String msg)
	{
		if(msg.length() + PLUGIN_NAME.length() + 3 > IN_GAME_LINE_SIZE)
		{
			for(String line : wrapInGame(ChatColor.RED + "[" + PLUGIN_NAME + "] " + ChatColor.RESET + msg))
				sender.sendMessage(line);
			return;
		}
		sender.sendMessage(ChatColor.RED + "[" + PLUGIN_NAME + "] " + ChatColor.RESET + msg);
	}

	/**
	 * Sends the console message <code>msg</code> with "info" tag.
	 * 
	 * @param msg The message to be sent.
	 */
	public static void info(String msg)
	{
		if(msg.length() > LINE_SIZE)
		{
			for(String line : wrapConsole(msg))
				LOGGER.info(line);
			return;
		}
		LOGGER.info(msg);
	}

	/**
	 * Sends the console message <code>msg</code> with "warning" tag.
	 * 
	 * @param msg The message to be sent.
	 */
	public static void warning(String msg)
	{
		if(msg.length() > LINE_SIZE)
		{
			for(String line : wrapConsole(msg))
				LOGGER.warning(line);
			return;
		}
		LOGGER.warning(msg);
	}

	/**
	 * Sends the console message <code>msg</code> with "severe" tag.
	 * 
	 * @param msg The message to be sent.
	 */
	public static void severe(String msg)
	{
		if(msg.length() >= LINE_SIZE)
		{
			for(String line : wrapConsole(msg))
				LOGGER.severe(line);
			return;
		}
		LOGGER.severe(msg);
	}

	public static String[] wrapConsole(String msg)
	{
		return WordUtils.wrap(msg, LINE_SIZE, "/n", false).split("/n");
	}

	/**
	 * Broadcast to the entire server (all players and the console) the message <code>msg</code>.
	 * 
	 * @param msg The message to be sent.
	 */
	public static void broadcast(String msg)
	{
		if(ChatColor.stripColor(msg).length() > IN_GAME_LINE_SIZE)
		{
			Server server = Demigods.PLUGIN.getServer();
			for(String line : wrapInGame(msg))
			{
				DemigodsChatEvent chatEvent = new DemigodsChatEvent(line);
				Bukkit.getPluginManager().callEvent(chatEvent);
				if(!chatEvent.isCancelled()) server.broadcastMessage(line);
			}
			return;
		}
		DemigodsChatEvent chatEvent = new DemigodsChatEvent(msg);
		Bukkit.getPluginManager().callEvent(chatEvent);
		if(!chatEvent.isCancelled()) Demigods.PLUGIN.getServer().broadcastMessage(msg);
	}

	public static String[] wrapInGame(String msg)
	{
		return WordUtils.wrap(msg, IN_GAME_LINE_SIZE, "/n", false).split("/n");
	}

	/**
	 * Let the <code>sender</code> know it does not have permission.
{'fraction_non_alphanumeric': 0.1272842841252185, 'fraction_numerical': 0.0011123470522803114, 'mean_word_length': 3.7863117870722434, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 39, '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': '6747665', 'n_tokens_mistral': 2360, 'n_tokens_neox': 2103, 'n_words': 529}