<commit_before>part of coUserver;

//handle player update events
class PlayerUpdateHandler
{
	static Map<String,Identifier> users;
	static Map<String,WebSocket> userSockets;
	
	PlayerUpdateHandler(WebSocket ws)
	{
		users = new Map();
		userSockets = new Map();
		
		ws.listen((message)
		{
			processMessage(ws, message);
	    }, 
		onError: (error)
		{
			cleanupList(ws);
		}, 
		onDone: ()
		{
			cleanupList(ws);
		});
	}
	
	cleanupList(WebSocket ws)
	{
		String leavingUser;
		
		userSockets.forEach((String username, WebSocket socket)
		{
			if(ws == socket)
			{
				socket = null;
				leavingUser = username;
			}
		});
		
		Identifier leavingID = users.remove(leavingUser);
		Map map = new Map();
		map["disconnect"] = "true";
		map["username"] = leavingUser;
		map["street"] = leavingID.currentStreet;
		sendAll(map);
	}
	
	processMessage(WebSocket ws, String message)
	{
		try
		{
			Map map = JSON.decode(message);
			String username = map["username"];
			if(users[username] != null) //we've had an update for this user before
			{
				if(users[username].currentStreet != map["street"]) //the user must have switched streets
				{
					map["changeStreet"] = map["street"];					
					users[username].currentStreet = map["street"];
				}
			}
			else //this user must have just connected
			{
				userSockets[username] = ws;
				users[username] = new Identifier(username,"",map["street"]);
			}
			
			sendAll(map);
		}<commit_msg>attempt to solve a crash with a nullpointer exception<commit_after>part of coUserver;

//handle player update events
class PlayerUpdateHandler
{
	static Map<String,Identifier> users;
	static Map<String,WebSocket> userSockets;
	
	PlayerUpdateHandler(WebSocket ws)
	{
		users = new Map();
		userSockets = new Map();
		
		ws.listen((message)
		{
			processMessage(ws, message);
	    }, 
		onError: (error)
		{
			cleanupList(ws);
		}, 
		onDone: ()
		{
			cleanupList(ws);
		});
	}
	
	cleanupList(WebSocket ws)
	{
		String leavingUser;
		
		userSockets.forEach((String username, WebSocket socket)
		{
			if(ws == socket)
			{
				socket = null;
				leavingUser = username;
			}
		});
		
		Identifier leavingID = users.remove(leavingUser);
		if(leavingID != null)
		{
			Map map = new Map();
			map["disconnect"] = "true";
			map["username"] = leavingUser;
			map["street"] = leavingID.currentStreet;
			sendAll(map);
		}
	}
	
	processMessage(WebSocket ws, String message)
	{
		try
		{
			Map map = JSON.decode(message);
			String username = map["username"];
			if(users[username] != null) //we've had an update for this user before
			{
				if(users[username].currentStreet != map["street"]) //the user must have switched streets
				{
					map["changeStreet"] = map["street"];					
					users[username].currentStreet = map["street"];
				}
			}
			else //this user must have just connected
			{
				userSockets[username] = ws;
				users[username] = new Identifier(username,"",map["street"]);
			}
			
			sendAll(map);
		}
{'fraction_non_alphanumeric': 0.13779128672745694, 'fraction_numerical': 0.0, 'mean_word_length': 3.2865412445730824, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2130380', 'n_tokens_mistral': 1205, 'n_tokens_neox': 944, 'n_words': 220}