<commit_before>package protocolsupport.protocol.packet.middleimpl.clientbound.play.v_4_5_6_7_8_9r1_9r2_10_11_12r1_12r2;

import org.bukkit.ChatColor;

import protocolsupport.api.chat.components.TextComponent;
import protocolsupport.api.utils.Any;
import protocolsupport.protocol.packet.middle.clientbound.play.MiddleScoreboardTeam;
import protocolsupport.protocol.packet.middle.clientbound.play.MiddleScoreboardTeam.ScoreboardTeamsTracker.TrackedScoreboardTeam;
import protocolsupport.protocol.storage.netcache.ClientCache;
import protocolsupport.protocol.typeremapper.legacy.LegacyChat;

public abstract class AbstractScoreboardTeam extends MiddleScoreboardTeam {

	public AbstractScoreboardTeam(MiddlePacketInit init) {
		super(init);
	}

	protected final ClientCache clientCache = cache.getClientCache();


	protected final Any<String, String> formatPrefixSuffix() {
		return isDisplayLineTeam() ? formatDisplayLinePrefixSuffix() : new Any<>(formatLegacyClampedPrefix(), formatLegacyClampedSuffix());
	}

	protected boolean isDisplayLineTeam() {
		if (
			suffix.isSimple() &&
			(suffix instanceof TextComponent) &&
			((TextComponent) suffix).getText().isEmpty()
		) {
			TrackedScoreboardTeam team = teamsTracker.getTeam(name);
			for (String player : team.getPlayers()) {
				if (!LegacyChat.isEmpty(player)) {
					return false;
				}
			}
			return true;
		}
		return false;
	}

	protected static final int FORMAT_CODE_LENGTH = 2;
	protected static final int NFIX_LIMIT = 16;
	protected static final int NFIX_LIMIT_1F = NFIX_LIMIT - FORMAT_CODE_LENGTH;
	protected static final int NFIX_LIMIT_2F = NFIX_LIMIT_1F - FORMAT_CODE_LENGTH;
	protected static final int NFIX_LIMIT_FCUT = NFIX_LIMIT - 1;

	protected String formatLegacyClampedPrefix() {
		String prefix = this.prefix.toLegacyText(clientCache.getLocale());

		if ((format != ChatColor.RESET) && !prefix.isEmpty() && !isStringFormatOverride(prefix, format)) {
			prefix = format + prefix;
		}

		String prefixLastFormatString = ChatColor.getLastColors(prefix);
		String formatString = format.toString();
		if (
			(format != ChatColor.RESET) && (prefixLastFormatString.isEmpty() ||
			!formatString.equals(prefixLastFormatString))
		) {
			if (format.isColor()) {
				return LegacyChat.clampLegacyText(prefix, NFIX_LIMIT_1F) + formatString;
			} else {
				return LegacyChat.clampLegacyText(prefix, NFIX_LIMIT_2F) + ChatColor.RESET + formatString;
			}
		}
		return LegacyChat.clampLegacyText(prefix, NFIX_LIMIT);
	}

	protected String formatLegacyClampedSuffix() {
		String suffix = this.suffix.toLegacyText(clientCache.getLocale());

		if (!isStringFormatOverride(suffix, format)) {
			suffix = format + suffix;
			if (format.isFormat()) {
				suffix = ChatColor.RESET + suffix;
			}
		}

		return LegacyChat.clampLegacyText(suffix, NFIX_LIMIT);
	}

	protected Any<String, String> formatDisplayLinePrefixSuffix() {
		String prefix = this.prefix.toLegacyText(clientCache.getLocale());

		if ((format != ChatColor.RESET) && !isStringFormatOverride(prefix, format)) {
			prefix = format + prefix;
		}

		if (prefix.length() <= NFIX_LIMIT) {
			return new Any<>(prefix, "");<commit_msg>Add only one reset<commit_after>package protocolsupport.protocol.packet.middleimpl.clientbound.play.v_4_5_6_7_8_9r1_9r2_10_11_12r1_12r2;

import org.bukkit.ChatColor;

import protocolsupport.api.chat.components.TextComponent;
import protocolsupport.api.utils.Any;
import protocolsupport.protocol.packet.middle.clientbound.play.MiddleScoreboardTeam;
import protocolsupport.protocol.packet.middle.clientbound.play.MiddleScoreboardTeam.ScoreboardTeamsTracker.TrackedScoreboardTeam;
import protocolsupport.protocol.storage.netcache.ClientCache;
import protocolsupport.protocol.typeremapper.legacy.LegacyChat;

public abstract class AbstractScoreboardTeam extends MiddleScoreboardTeam {

	public AbstractScoreboardTeam(MiddlePacketInit init) {
		super(init);
	}

	protected final ClientCache clientCache = cache.getClientCache();


	protected final Any<String, String> formatPrefixSuffix() {
		return isDisplayLineTeam() ? formatDisplayLinePrefixSuffix() : new Any<>(formatLegacyClampedPrefix(), formatLegacyClampedSuffix());
	}

	protected boolean isDisplayLineTeam() {
		if (
			suffix.isSimple() &&
			(suffix instanceof TextComponent) &&
			((TextComponent) suffix).getText().isEmpty()
		) {
			TrackedScoreboardTeam team = teamsTracker.getTeam(name);
			for (String player : team.getPlayers()) {
				if (!LegacyChat.isEmpty(player)) {
					return false;
				}
			}
			return true;
		}
		return false;
	}

	protected static final int FORMAT_CODE_LENGTH = 2;
	protected static final int NFIX_LIMIT = 16;
	protected static final int NFIX_LIMIT_1F = NFIX_LIMIT - FORMAT_CODE_LENGTH;
	protected static final int NFIX_LIMIT_2F = NFIX_LIMIT_1F - FORMAT_CODE_LENGTH;
	protected static final int NFIX_LIMIT_FCUT = NFIX_LIMIT - 1;

	protected String formatLegacyClampedPrefix() {
		String prefix = this.prefix.toLegacyText(clientCache.getLocale());

		if ((format != ChatColor.RESET) && !prefix.isEmpty() && !isStringFormatOverride(prefix, format)) {
			prefix = format + prefix;
		}

		String prefixLastFormatString = ChatColor.getLastColors(prefix);
		String formatString = format.toString();
		if (
			(prefixLastFormatString.isEmpty() && (format != ChatColor.RESET)) ||
			!formatString.equals(prefixLastFormatString)
		) {
			if (format.isColor() || format == ChatColor.RESET) {
				return LegacyChat.clampLegacyText(prefix, NFIX_LIMIT_1F) + formatString;
			} else {
				return LegacyChat.clampLegacyText(prefix, NFIX_LIMIT_2F) + ChatColor.RESET + formatString;
			}
		}
		return LegacyChat.clampLegacyText(prefix, NFIX_LIMIT);
	}

	protected String formatLegacyClampedSuffix() {
		String suffix = this.suffix.toLegacyText(clientCache.getLocale());

		if (!isStringFormatOverride(suffix, format)) {
			suffix = format + suffix;
			if (format.isFormat()) {
				suffix = ChatColor.RESET + suffix;
			}
		}

		return LegacyChat.clampLegacyText(suffix, NFIX_LIMIT);
	}

	protected Any<String, String> formatDisplayLinePrefixSuffix() {
		String prefix = this.prefix.toLegacyText(clientCache.getLocale());

		if ((format != ChatColor.RESET) && !isStringFormatOverride(prefix, format)) {
			prefix = format + prefix;
		}

		if (prefix.length() <= NFIX_LIMIT) {
			return new Any<>(prefix, "");
{'fraction_non_alphanumeric': 0.10631911532385466, 'fraction_numerical': 0.008846761453396525, 'mean_word_length': 5.375629405840886, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '2022425', 'n_tokens_mistral': 2144, 'n_tokens_neox': 1953, 'n_words': 369}