<commit_before>var items = require('items');
var utils = require('utils');
var scoreboard = require('minigames/scoreboard');
var cm = Packages.net.canarymod;
var cmSnowball = cm.api.entity.EntityType.SNOWBALL;
var cmCreative = cm.api.GameMode.CREATIVE;

function start( duration, teams, onGameOver ) {
  var players;
  var i;
  var game;
  var teamName;
  var ball;
  if ( typeof duration == 'undefined' ) {
    duration = 60;
  }
  if ( typeof teams == 'undefined' ) {
    teams =  {};
    players = utils.players(); 
    var teamNames = ['red','blue','yellow'];
    var playerCount = players.length;
    for ( i = 0; i < playerCount; i++ ) {
      var playerName = players[i].name;
      teamName = teamNames[ i % playerCount ];
      if (teams[ teamName ] == undefined){
        teams[ teamName ] = [];
      }
      teams[ teamName ].push(playerName);
    }
  }
  game = {
    teams: teams,
    duration: duration,
    teamScores: {},
    eventListener: null,
    onGameOver: onGameOver
  };

  function loop(){
    if ( game.duration-- ){
      updateScoreboard( game );
      setTimeout( loop, 1000 );
    } else {
      end( game );
    }
  }

  function onSnowballHit( event ) {
    var snowball = event.projectile;
    if (snowball.entityType != cmSnowball ){
      return;
    }
    var thrower = snowball.thrower;
    //var thrower = snowball.handle.j().getCanaryEntity();

    var damaged = event.entityHit;
    if (damaged == null){
      // snowball did not hit another player
      return;
    }
    var throwerTeam = getPlayerTeam( thrower, game.teams );
    var damagedTeam = getPlayerTeam( damaged, game.teams );

    if ( !throwerTeam || !damagedTeam ) {
      return; // thrower/damagee wasn't in game
    }
    if ( throwerTeam != damagedTeam ) {
      game.teamScores[ throwerTeam ]++;
    } else {
      game.teamScores[ throwerTeam ]--;
    }
  } // end onSnowballHit

  scoreboard.create('snowball', 'Snowball Fight!');
  ball = items.snowBall(1);
  
  for ( teamName in game.teams ) {

    scoreboard.addTeam( teamName, teamName );

    game.teamScores[ teamName ] = 0;
    team = game.teams[ teamName ];

    for ( i = 0; i < team.length; i++ ) {
      scoreboard.addPlayerToTeam( 'snowball', teamName, team[i]);
      player = server.getPlayer( team[i] );
      player.mode = cmCreative;
      player.inventory.addItem( ball.type.id, ball.amount, 0 );
    }
  }
  updateScoreboard(game);
  game.eventListener = events.projectileHit( onSnowballHit );
  setTimeout(loop, 1000);
}

function updateScoreboard( game ) {
  var teamName;
  var team;
  var teamScore;
  var i;

  for (teamName in game.teamScores) {
    teamScore = game.teamScores[ teamName ];
    team = game.teams[ teamName ];
    for (i = 0;i < team.length; i++){
      scoreboard.updateScore( 'snowball', team[i], teamScore);
    }
  }
}

function end( game ) {
  var teamName;
  scoreboard.remove('snowball');
  var winningTeam;
  var highestScore = 0;
  for ( teamName in game.teams ) {
    if (game.teamScores[teamName] > highestScore){
      highestScore = game.teamScores[teamName];
      winningTeam = teamName;
    }
    scoreboard.removeTeam( teamName );
  }
  server.broadcastMessage('The ' + winningTeam + ' team won!');
  game.eventListener.unregister();
  // who won?
  
  game.onGameOver( game, winningTeam );
}
<commit_msg>removed extraneous comment<commit_after>var items = require('items');
var utils = require('utils');
var scoreboard = require('minigames/scoreboard');
var cm = Packages.net.canarymod;
var cmSnowball = cm.api.entity.EntityType.SNOWBALL;
var cmCreative = cm.api.GameMode.CREATIVE;

function start( duration, teams, onGameOver ) {
  var players;
  var i;
  var game;
  var teamName;
  var ball;
  if ( typeof duration == 'undefined' ) {
    duration = 60;
  }
  if ( typeof teams == 'undefined' ) {
    teams =  {};
    players = utils.players(); 
    var teamNames = ['red','blue','yellow'];
    var playerCount = players.length;
    for ( i = 0; i < playerCount; i++ ) {
      var playerName = players[i].name;
      teamName = teamNames[ i % playerCount ];
      if (teams[ teamName ] == undefined){
        teams[ teamName ] = [];
      }
      teams[ teamName ].push(playerName);
    }
  }
  game = {
    teams: teams,
    duration: duration,
    teamScores: {},
    eventListener: null,
    onGameOver: onGameOver
  };

  function loop(){
    if ( game.duration-- ){
      updateScoreboard( game );
      setTimeout( loop, 1000 );
    } else {
      end( game );
    }
  }

  function onSnowballHit( event ) {
    var snowball = event.projectile;
    if (snowball.entityType != cmSnowball ){
      return;
    }
    var thrower = snowball.thrower;
    //var thrower = snowball.handle.j().getCanaryEntity();

    var damaged = event.entityHit;
    if (damaged == null){
      // snowball did not hit another player
      return;
    }
    var throwerTeam = getPlayerTeam( thrower, game.teams );
    var damagedTeam = getPlayerTeam( damaged, game.teams );

    if ( !throwerTeam || !damagedTeam ) {
      return; // thrower/damagee wasn't in game
    }
    if ( throwerTeam != damagedTeam ) {
      game.teamScores[ throwerTeam ]++;
    } else {
      game.teamScores[ throwerTeam ]--;
    }
  } // end onSnowballHit

  scoreboard.create('snowball', 'Snowball Fight!');
  ball = items.snowBall(1);
  
  for ( teamName in game.teams ) {

    scoreboard.addTeam( teamName, teamName );

    game.teamScores[ teamName ] = 0;
    team = game.teams[ teamName ];

    for ( i = 0; i < team.length; i++ ) {
      scoreboard.addPlayerToTeam( 'snowball', teamName, team[i]);
      player = server.getPlayer( team[i] );
      player.mode = cmCreative;
      player.inventory.addItem( ball.type.id, ball.amount, 0 );
    }
  }
  updateScoreboard(game);
  game.eventListener = events.projectileHit( onSnowballHit );
  setTimeout(loop, 1000);
}

function updateScoreboard( game ) {
  var teamName;
  var team;
  var teamScore;
  var i;

  for (teamName in game.teamScores) {
    teamScore = game.teamScores[ teamName ];
    team = game.teams[ teamName ];
    for (i = 0;i < team.length; i++){
      scoreboard.updateScore( 'snowball', team[i], teamScore);
    }
  }
}

function end( game ) {
  var teamName;
  scoreboard.remove('snowball');
  var winningTeam;
  var highestScore = 0;
  for ( teamName in game.teams ) {
    if (game.teamScores[teamName] > highestScore){
      highestScore = game.teamScores[teamName];
      winningTeam = teamName;
    }
    scoreboard.removeTeam( teamName );
  }
  server.broadcastMessage('The ' + winningTeam + ' team won!');
  game.eventListener.unregister();
  game.onGameOver( game, winningTeam );
}

{'fraction_non_alphanumeric': 0.1351473241130487, 'fraction_numerical': 0.005111244738424534, 'mean_word_length': 2.8390075014425853, 'pattern_counts': {'":': 0, '<': 9, '<?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': '872076', 'n_tokens_mistral': 2278, 'n_tokens_neox': 2210, 'n_words': 520}