<commit_before>package gg.uhc.uhc.modules.health;

import com.google.common.collect.ImmutableList;
import gg.uhc.uhc.command.OptionCommand;
import gg.uhc.uhc.command.converters.EnumConverter;
import gg.uhc.uhc.command.converters.LengthRestricted;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;

public class PlayerListHealthCommand extends OptionCommand {

    protected static final String CONFIRMATION = ChatColor.AQUA + "Registered health objective %s (%s) to the slot %s";
    protected static final String UNREGISTERD = ChatColor.AQUA + "Unregistered old objective `%s`";
    protected static final String INCORRECT_TYPE = ChatColor.RED + "Existing objective was of type `%s` when we were looking for `health`. You can use `-f` to register the objective with the correct type";

    protected final Scoreboard scoreboard;

    protected final OptionSpec<Void> forceSpec;
    protected final OptionSpec<String> nameSpec;
    protected final OptionSpec<String> displayNameSpec;
    protected final OptionSpec<DisplaySlot> slotSpec;

    public PlayerListHealthCommand(Scoreboard scoreboard, DisplaySlot defaultSlot, String objectiveName, String displayName) {
        this.scoreboard = scoreboard;

        forceSpec = parser
                .acceptsAll(ImmutableList.of("f", "force"), "Remove any existing objective with the same name.");

        nameSpec = parser
                .acceptsAll(ImmutableList.of("n", "name"), "Name of the objective to create/use.")
                .withRequiredArg()
                .withValuesConvertedBy(new LengthRestricted("objective name", 16))
                .defaultsTo(objectiveName);

        displayNameSpec = parser
                .acceptsAll(ImmutableList.of("d", "displayName"), "Display name of the objective.")
                .withRequiredArg()
                .withValuesConvertedBy(new LengthRestricted("display name", 32))
                .defaultsTo(displayName);

        slotSpec = parser
                .acceptsAll(ImmutableList.of("s", "slot"), "Slot to assign the objective to.")
                .withRequiredArg()
                .withValuesConvertedBy(EnumConverter.forEnum(DisplaySlot.class))
                .defaultsTo(defaultSlot);
    }

    @Override
    protected boolean runCommand(CommandSender sender, OptionSet options) {
        String objectiveName = nameSpec.value(options);
        String displayName = displayNameSpec.value(options);
        boolean force = options.has(forceSpec);
        DisplaySlot slot = slotSpec.value(options);

        Objective objective = scoreboard.getObjective(objectiveName);

        // unregister the current objective if it exists and we want to force remake it
        if (objective != null && force) {
            sender.sendMessage(String.format(UNREGISTERD, objective.getName()));
            objective.unregister();
            objective = null;
        }

        // register the objective
        if (objective == null) {
            objective = scoreboard.registerNewObjective(objectiveName, "health");

            // add all online player manually
            for (Player player : Bukkit.getOnlinePlayers()) {
                objective.getScore(player.getName()).setScore((int) Math.ceil(player.getHealth()));
            }
        } else {
            // check existing criteria is of correct type
            String existing = objective.getCriteria();

            if (!existing.equals("health")) {
                sender.sendMessage(String.format(INCORRECT_TYPE, existing));
                return true;
            }
        }

        // set display name
        objective.setDisplayName(displayName);

        // set the slot to render in
        objective.setDisplaySlot(slot);

        sender.sendMessage(String.format(CONFIRMATION, objectiveName, displayName, slot.name()));
        return true;
    }
}<commit_msg>allow colour codes in display name of player health objective command<commit_after>package gg.uhc.uhc.modules.health;

import com.google.common.collect.ImmutableList;
import gg.uhc.uhc.command.OptionCommand;
import gg.uhc.uhc.command.converters.EnumConverter;
import gg.uhc.uhc.command.converters.LengthRestricted;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.DisplaySlot;
import org.bukkit.scoreboard.Objective;
import org.bukkit.scoreboard.Scoreboard;

public class PlayerListHealthCommand extends OptionCommand {

    protected static final String CONFIRMATION = ChatColor.AQUA + "Registered health objective %s (%s) to the slot %s";
    protected static final String UNREGISTERD = ChatColor.AQUA + "Unregistered old objective `%s`";
    protected static final String INCORRECT_TYPE = ChatColor.RED + "Existing objective was of type `%s` when we were looking for `health`. You can use `-f` to register the objective with the correct type";

    protected final Scoreboard scoreboard;

    protected final OptionSpec<Void> forceSpec;
    protected final OptionSpec<String> nameSpec;
    protected final OptionSpec<String> displayNameSpec;
    protected final OptionSpec<DisplaySlot> slotSpec;

    public PlayerListHealthCommand(Scoreboard scoreboard, DisplaySlot defaultSlot, String objectiveName, String displayName) {
        this.scoreboard = scoreboard;

        forceSpec = parser
                .acceptsAll(ImmutableList.of("f", "force"), "Remove any existing objective with the same name.");

        nameSpec = parser
                .acceptsAll(ImmutableList.of("n", "name"), "Name of the objective to create/use.")
                .withRequiredArg()
                .withValuesConvertedBy(new LengthRestricted("objective name", 16))
                .defaultsTo(objectiveName);

        displayNameSpec = parser
                .acceptsAll(ImmutableList.of("d", "displayName"), "Display name of the objective.")
                .withRequiredArg()
                .withValuesConvertedBy(new LengthRestricted("display name", 32))
                .defaultsTo(displayName);

        slotSpec = parser
                .acceptsAll(ImmutableList.of("s", "slot"), "Slot to assign the objective to.")
                .withRequiredArg()
                .withValuesConvertedBy(EnumConverter.forEnum(DisplaySlot.class))
                .defaultsTo(defaultSlot);
    }

    @Override
    protected boolean runCommand(CommandSender sender, OptionSet options) {
        String objectiveName = nameSpec.value(options);
        String displayName = displayNameSpec.value(options);
        boolean force = options.has(forceSpec);
        DisplaySlot slot = slotSpec.value(options);

        Objective objective = scoreboard.getObjective(objectiveName);

        // unregister the current objective if it exists and we want to force remake it
        if (objective != null && force) {
            sender.sendMessage(String.format(UNREGISTERD, objective.getName()));
            objective.unregister();
            objective = null;
        }

        // register the objective
        if (objective == null) {
            objective = scoreboard.registerNewObjective(objectiveName, "health");

            // add all online player manually
            for (Player player : Bukkit.getOnlinePlayers()) {
                objective.getScore(player.getName()).setScore((int) Math.ceil(player.getHealth()));
            }
        } else {
            // check existing criteria is of correct type
            String existing = objective.getCriteria();

            if (!existing.equals("health")) {
                sender.sendMessage(String.format(INCORRECT_TYPE, existing));
                return true;
            }
        }

        // set display name
        objective.setDisplayName(ChatColor.translateAlternateColorCodes('&', displayName));

        // set the slot to render in
        objective.setDisplaySlot(slot);

        sender.sendMessage(String.format(CONFIRMATION, objectiveName, displayName, slot.name()));
        return true;
    }
}
{'fraction_non_alphanumeric': 0.09355109883511468, 'fraction_numerical': 0.0009607301549177375, 'mean_word_length': 2.8645011600928076, 'pattern_counts': {'":': 0, '<': 11, '<?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': '3436970', 'n_tokens_mistral': 2211, 'n_tokens_neox': 2119, 'n_words': 559}