<commit_before>package kabbage.zarena;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;
import java.util.logging.Level;

import org.bukkit.Location;
import org.bukkit.block.Block;

import kabbage.zarena.signs.ZSign;
import kabbage.zarena.signs.ZTollSign;
import kabbage.zarena.utils.LocationSer;

public class ZLevel implements Externalizable
{
	private static final long serialVersionUID = "ZLEVEL".hashCode(); // DO NOT CHANGE
	/**
	 * The version of the ZLevel class. This MUST be incremented whenever the
	 * writeExternal or readExternal methods are changed.
	 */
	private static int VERSION = 2;
	
	private LocationSer dSpawn;
	private LocationSer iSpawn;
	private Map<String, LocationSer> zSpawns;
	private List<LocationSer> activeZSpawns;
	private List<String> bossSpawns;	//List of names of zombie spawns that also act as boss spawns
	private List<ZSign> zSigns;
	private String name;
	private String world;
	//There's no real point in making them transient. But screw it, I never get to use this keyword...
	private transient Random rnd = new Random();
	private transient List<LocationSer> inactiveZSpawns = new ArrayList<LocationSer>();
	
	/**
	 * Empty constructor for externalization.
	 */
	public ZLevel()
	{
		inactiveZSpawns = new ArrayList<LocationSer>();
	}
	
	public ZLevel(String name, Location spawn)
	{
		this();
		this.name = name;
		iSpawn = LocationSer.convertFromBukkitLocation(spawn);
		dSpawn = LocationSer.convertFromBukkitLocation(spawn);
		zSpawns = new HashMap<String, LocationSer>();
		activeZSpawns = new ArrayList<LocationSer>();
		bossSpawns = new ArrayList<String>();
		zSigns = new ArrayList<ZSign>();
		world = spawn.getWorld().getName();
	}
	
	public boolean addBossSpawn(String name)
	{
		if(zSpawns.containsKey(name))
			return bossSpawns.add(name);
		return false;
	}
	
	public void addZombieSpawn(String name, Location location)
	{
		if(zSpawns.containsKey(name))
			removeZombieSpawn(name);
		zSpawns.put(name, LocationSer.convertFromBukkitLocation(location));
		activeZSpawns.add(LocationSer.convertFromBukkitLocation(location));
	}
	
	public void addZSign(ZSign sign)
	{
		zSigns.add(sign);
	}
	
	public Location getDeathSpawn()
	{
		return LocationSer.convertToBukkitLocation(dSpawn);
	}
	
	public Location getInitialSpawn()
	{
		return LocationSer.convertToBukkitLocation(iSpawn);
	}
	
	public String getName()
	{
		return name;
	}
	
	public String getNearestZombieSpawn(Location location)
	{
		String nameToReturn = null;
		LocationSer loc = LocationSer.convertFromBukkitLocation(location);
		double distance = 64; //If the nearest spawn is farther away than the preset value, then no spawn will be gotten.
		for(Entry<String, LocationSer> entry : zSpawns.entrySet())
		{
			String name = entry.getKey();
			LocationSer spawnLoc = entry.getValue();
			if(spawnLoc.distance(loc) < distance)
			{
				distance = spawnLoc.distance(loc);
				nameToReturn = name;
			}
		}
		return nameToReturn;
	}
	
	public Location getRandomBossSpawn()
	{
		if(bossSpawns.size() == 0)
			return null;
		return LocationSer.convertToBukkitLocation(zSpawns.get(bossSpawns.get(rnd.nextInt(bossSpawns.size()))));
	}
	
	public Location getRandomZombieSpawn()
	{
		if (activeZSpawns.size() == 0)
			return null;
		Location spawn = null;
		do
		{
			spawn = LocationSer.convertToBukkitLocation(activeZSpawns.get(rnd.nextInt(activeZSpawns.size())));
		} while(inactiveZSpawns.contains(LocationSer.convertFromBukkitLocation(spawn)));
		return spawn;
	}
	
	public String getWorld()
	{
		return world;
	}
	
	public Location getZombieSpawn(String name)
	{
		return LocationSer.convertToBukkitLocation(zSpawns.get(name));
	}
	
	public List<ZSign> getZSigns()
	{
		return zSigns;
	}
	
	public ZSign getZSign(Block block)
	{
		for(ZSign sign : zSigns)
		{
			if(sign.isAtLocation(block.getLocation()))
				return sign;
		}<commit_msg>Fixed NullPointerException on trying to get a nonexistent zombie spawn.<commit_after>package kabbage.zarena;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;
import java.util.logging.Level;

import org.bukkit.Location;
import org.bukkit.block.Block;

import kabbage.zarena.signs.ZSign;
import kabbage.zarena.signs.ZTollSign;
import kabbage.zarena.utils.LocationSer;

public class ZLevel implements Externalizable
{
	private static final long serialVersionUID = "ZLEVEL".hashCode(); // DO NOT CHANGE
	/**
	 * The version of the ZLevel class. This MUST be incremented whenever the
	 * writeExternal or readExternal methods are changed.
	 */
	private static int VERSION = 2;
	
	private LocationSer dSpawn;
	private LocationSer iSpawn;
	private Map<String, LocationSer> zSpawns;
	private List<LocationSer> activeZSpawns;
	private List<String> bossSpawns;	//List of names of zombie spawns that also act as boss spawns
	private List<ZSign> zSigns;
	private String name;
	private String world;
	//There's no real point in making them transient. But screw it, I never get to use this keyword...
	private transient Random rnd = new Random();
	private transient List<LocationSer> inactiveZSpawns = new ArrayList<LocationSer>();
	
	/**
	 * Empty constructor for externalization.
	 */
	public ZLevel()
	{
		inactiveZSpawns = new ArrayList<LocationSer>();
	}
	
	public ZLevel(String name, Location spawn)
	{
		this();
		this.name = name;
		iSpawn = LocationSer.convertFromBukkitLocation(spawn);
		dSpawn = LocationSer.convertFromBukkitLocation(spawn);
		zSpawns = new HashMap<String, LocationSer>();
		activeZSpawns = new ArrayList<LocationSer>();
		bossSpawns = new ArrayList<String>();
		zSigns = new ArrayList<ZSign>();
		world = spawn.getWorld().getName();
	}
	
	public boolean addBossSpawn(String name)
	{
		if(zSpawns.containsKey(name))
			return bossSpawns.add(name);
		return false;
	}
	
	public void addZombieSpawn(String name, Location location)
	{
		if(zSpawns.containsKey(name))
			removeZombieSpawn(name);
		zSpawns.put(name, LocationSer.convertFromBukkitLocation(location));
		activeZSpawns.add(LocationSer.convertFromBukkitLocation(location));
	}
	
	public void addZSign(ZSign sign)
	{
		zSigns.add(sign);
	}
	
	public Location getDeathSpawn()
	{
		return LocationSer.convertToBukkitLocation(dSpawn);
	}
	
	public Location getInitialSpawn()
	{
		return LocationSer.convertToBukkitLocation(iSpawn);
	}
	
	public String getName()
	{
		return name;
	}
	
	public String getNearestZombieSpawn(Location location)
	{
		String nameToReturn = null;
		LocationSer loc = LocationSer.convertFromBukkitLocation(location);
		double distance = 64; //If the nearest spawn is farther away than the preset value, then no spawn will be gotten.
		for(Entry<String, LocationSer> entry : zSpawns.entrySet())
		{
			String name = entry.getKey();
			LocationSer spawnLoc = entry.getValue();
			if(spawnLoc.distance(loc) < distance)
			{
				distance = spawnLoc.distance(loc);
				nameToReturn = name;
			}
		}
		return nameToReturn;
	}
	
	public Location getRandomBossSpawn()
	{
		if(bossSpawns.size() == 0)
			return null;
		return LocationSer.convertToBukkitLocation(zSpawns.get(bossSpawns.get(rnd.nextInt(bossSpawns.size()))));
	}
	
	public Location getRandomZombieSpawn()
	{
		if (activeZSpawns.size() == 0)
			return null;
		Location spawn = null;
		do
		{
			spawn = LocationSer.convertToBukkitLocation(activeZSpawns.get(rnd.nextInt(activeZSpawns.size())));
		} while(inactiveZSpawns.contains(LocationSer.convertFromBukkitLocation(spawn)));
		return spawn;
	}
	
	public String getWorld()
	{
		return world;
	}
	
	public Location getZombieSpawn(String name)
	{
		if(zSpawns.get(name) == null)
			return null;
		return LocationSer.convertToBukkitLocation(zSpawns.get(name));
	}
	
	public List<ZSign> getZSigns()
	{
		return zSigns;
	}
	
	public ZSign getZSign(Block block)
	{
		for(ZSign sign : zSigns)
		{
			if(sign.isAtLocation(block.getLocation()))
				return sign;
		}
{'fraction_non_alphanumeric': 0.10388513513513513, 'fraction_numerical': 0.0012065637065637065, 'mean_word_length': 4.685185185185185, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 29, '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': '4644860', 'n_tokens_mistral': 3013, 'n_tokens_neox': 2829, 'n_words': 645}