<commit_before>package in.twizmwaz.cardinal.module.modules.blitz;


import in.twizmwaz.cardinal.Cardinal;
import in.twizmwaz.cardinal.GameHandler;
import in.twizmwaz.cardinal.chat.ChatConstant;
import in.twizmwaz.cardinal.chat.LocalizedChatMessage;
import in.twizmwaz.cardinal.event.CardinalSpawnEvent;
import in.twizmwaz.cardinal.module.Module;
import in.twizmwaz.cardinal.module.modules.team.TeamModule;
import in.twizmwaz.cardinal.util.TeamUtils;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.metadata.LazyMetadataValue;

public class Blitz implements Module {

    @Override
    public void unload() {
        HandlerList.unregisterAll(this);
    }


    private String title = null;
    private boolean broadcastLives;
    private int lives;

    protected Blitz(final String title, final boolean broadcastLives, final int lives) {
        this.title = title;
        this.broadcastLives = broadcastLives;
        this.lives = lives;
    }


    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event) {
        Player player = event.getEntity();
        TeamModule team = TeamUtils.getTeamByPlayer(player);
        if (team != null && !team.isObserver()) {
            int oldMeta = this.getLives(player);
            player.removeMetadata("lives", Cardinal.getInstance());
            player.setMetadata("lives", new LazyMetadataValue(Cardinal.getInstance(), LazyMetadataValue.CacheStrategy.NEVER_CACHE, new BlitzLives(oldMeta - 1)));
            if (this.getLives(player) == 0) {
                TeamUtils.getTeamById("observers").add(player, true);
                player.removeMetadata("lives", Cardinal.getInstance());
            }
        }
    }

    @EventHandler
    public void onPgmSpawn(CardinalSpawnEvent event) {
        if (GameHandler.getGameHandler().getMatch().isRunning()) {
            Player player = event.getPlayer();
            if (TeamUtils.getTeamByPlayer(player) != null) {
                if (!TeamUtils.getTeamByPlayer(player).isObserver()) {
                    if (!player.hasMetadata("lives")) {
                        player.setMetadata("lives", new LazyMetadataValue(Cardinal.getInstance(), LazyMetadataValue.CacheStrategy.NEVER_CACHE, new BlitzLives(this.lives)));
                    }
                    if (this.broadcastLives) {
                        int lives = this.getLives(player);
                        if (lives == 1) {
                            player.sendMessage(ChatColor.RED + new LocalizedChatMessage(ChatConstant.UI_AMOUNT_REMAINING, ChatColor.AQUA + "" + ChatColor.BOLD + new LocalizedChatMessage(ChatConstant.UI_ONE_LIFE).getMessage(player.getLocale()) + ChatColor.RED).getMessage(player.getLocale()));
                        } else {
                            player.sendMessage(ChatColor.RED + new LocalizedChatMessage(ChatConstant.UI_AMOUNT_REMAINING, ChatColor.AQUA + "" + ChatColor.BOLD + new LocalizedChatMessage(ChatConstant.UI_LIVES, lives + "").getMessage(player.getLocale()) + ChatColor.RED).getMessage(player.getLocale()));
                        }
                    }
                }
            }
        }
    }

    private int getLives(Player player){
        return player.getMetadata("lives").get(0).asInt();
    }

    public String getTitle(){
        return this.title;
    }

    public static boolean matchIsBlitz() {
        return GameHandler.getGameHandler().getMatch().getModules().getModule(Blitz.class) != null;
    }


}
<commit_msg>Remove lives metadeta when the match ends, fixes #657<commit_after>package in.twizmwaz.cardinal.module.modules.blitz;


import in.twizmwaz.cardinal.Cardinal;
import in.twizmwaz.cardinal.GameHandler;
import in.twizmwaz.cardinal.chat.ChatConstant;
import in.twizmwaz.cardinal.chat.LocalizedChatMessage;
import in.twizmwaz.cardinal.event.CardinalSpawnEvent;
import in.twizmwaz.cardinal.event.MatchEndEvent;
import in.twizmwaz.cardinal.module.Module;
import in.twizmwaz.cardinal.module.modules.team.TeamModule;
import in.twizmwaz.cardinal.util.TeamUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.metadata.LazyMetadataValue;

@SuppressWarnings({"unchecked"})
public class Blitz implements Module {

    @Override
    public void unload() {
        HandlerList.unregisterAll(this);
    }


    private String title = null;
    private boolean broadcastLives;
    private int lives;

    protected Blitz(final String title, final boolean broadcastLives, final int lives) {
        this.title = title;
        this.broadcastLives = broadcastLives;
        this.lives = lives;
    }


    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event) {
        Player player = event.getEntity();
        TeamModule team = TeamUtils.getTeamByPlayer(player);
        if (team != null && !team.isObserver()) {
            int oldMeta = this.getLives(player);
            player.removeMetadata("lives", Cardinal.getInstance());
            player.setMetadata("lives", new LazyMetadataValue(Cardinal.getInstance(), LazyMetadataValue.CacheStrategy.NEVER_CACHE, new BlitzLives(oldMeta - 1)));
            if (this.getLives(player) == 0) {
                TeamUtils.getTeamById("observers").add(player, true);
                player.removeMetadata("lives", Cardinal.getInstance());
            }
        }
    }

    @EventHandler
    public void onPgmSpawn(CardinalSpawnEvent event) {
        if (GameHandler.getGameHandler().getMatch().isRunning()) {
            Player player = event.getPlayer();
            if (TeamUtils.getTeamByPlayer(player) != null) {
                if (!TeamUtils.getTeamByPlayer(player).isObserver()) {
                    if (!player.hasMetadata("lives")) {
                        player.setMetadata("lives", new LazyMetadataValue(Cardinal.getInstance(), LazyMetadataValue.CacheStrategy.NEVER_CACHE, new BlitzLives(this.lives)));
                    }
                    if (this.broadcastLives) {
                        int lives = this.getLives(player);
                        if (lives == 1) {
                            player.sendMessage(ChatColor.RED + new LocalizedChatMessage(ChatConstant.UI_AMOUNT_REMAINING, ChatColor.AQUA + "" + ChatColor.BOLD + new LocalizedChatMessage(ChatConstant.UI_ONE_LIFE).getMessage(player.getLocale()) + ChatColor.RED).getMessage(player.getLocale()));
                        } else {
                            player.sendMessage(ChatColor.RED + new LocalizedChatMessage(ChatConstant.UI_AMOUNT_REMAINING, ChatColor.AQUA + "" + ChatColor.BOLD + new LocalizedChatMessage(ChatConstant.UI_LIVES, lives + "").getMessage(player.getLocale()) + ChatColor.RED).getMessage(player.getLocale()));
                        }
                    }
                }
            }
        }
    }

    @EventHandler
    public void onMatchEnd(MatchEndEvent event) {
        for (Player player : Bukkit.getOnlinePlayers()) {
            player.removeMetadata("lives", Cardinal.getInstance());
        }
    }

    private int getLives(Player player){
        return player.getMetadata("lives").get(0).asInt();
    }

    public String getTitle(){
        return this.title;
    }

    public static boolean matchIsBlitz() {
        return GameHandler.getGameHandler().getMatch().getModules().getModule(Blitz.class) != null;
    }


}

{'fraction_non_alphanumeric': 0.11004090249373268, 'fraction_numerical': 0.001451378809869376, 'mean_word_length': 2.771144278606965, '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': '6614876', 'n_tokens_mistral': 2231, 'n_tokens_neox': 2143, 'n_words': 360}