<commit_before>package nallar.patched.world.tracking;

import java.util.ArrayList;

import nallar.collections.ConcurrentLinkedQueueList;
import nallar.tickthreading.Log;
import nallar.tickthreading.patcher.Declare;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerInstance;
import net.minecraft.server.management.PlayerManager;
import net.minecraft.world.WorldServer;

public abstract class PatchPlayerManager extends PlayerManager {
	public Object chunkWatcherLock;
	private ConcurrentLinkedQueueList<PlayerInstance> chunkWatcherWithPlayersQ;

	public void construct() {
		chunkWatcherLock = new Object();
		try {
			chunkWatcherWithPlayers = chunkWatcherWithPlayersQ = new ConcurrentLinkedQueueList<PlayerInstance>();
		} catch (NoSuchFieldError e) {
			// MCPC+.
		}
	}

	@Override
	@Declare
	public net.minecraft.util.LongHashMap getChunkWatchers() {
		return this.playerInstances;
	}

	@Override
	public void updatePlayerInstances() {
		int currentTick = MinecraftServer.currentTick;
		boolean squash = currentTick % 800 == 0;
		ArrayList<PlayerInstance> postponed = new ArrayList<PlayerInstance>();
		PlayerInstance playerInstance;
		while ((playerInstance = chunkWatcherWithPlayersQ.poll()) != null) {
			try {
				if (playerInstance.shouldPostPone(squash, currentTick)) {
					postponed.add(playerInstance);
				} else {
					playerInstance.sendChunkUpdate();
				}
			} catch (Exception e) {
				Log.severe("Failed to send " + playerInstance, e);
				playerInstance.clearTileCount();
			}
		}

		chunkWatcherWithPlayersQ.addAll(postponed);

		if (currentTick % 300 == 0 && this.players.isEmpty()) {
			this.theWorldServer.theChunkProviderServer.unloadAllChunks();
		}
	}

	@Override
	public PlayerInstance getOrCreateChunkWatcher(int par1, int par2, boolean par3) {
		long var4 = (long) par1 + 2147483647L | (long) par2 + 2147483647L << 32;
		PlayerInstance var6 = (PlayerInstance) this.playerInstances.getValueByKey(var4);

		if (var6 == null && par3) {
			synchronized (chunkWatcherLock) {
				var6 = (PlayerInstance) this.playerInstances.getValueByKey(var4);
				if (var6 == null) {<commit_msg>Distribute chunk updates more evenly<commit_after>package nallar.patched.world.tracking;

import java.util.ArrayList;

import nallar.collections.ConcurrentLinkedQueueList;
import nallar.tickthreading.Log;
import nallar.tickthreading.patcher.Declare;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.management.PlayerInstance;
import net.minecraft.server.management.PlayerManager;
import net.minecraft.world.WorldServer;

public abstract class PatchPlayerManager extends PlayerManager {
	public Object chunkWatcherLock;
	private ConcurrentLinkedQueueList<PlayerInstance> chunkWatcherWithPlayersQ;

	public void construct() {
		chunkWatcherLock = new Object();
		try {
			chunkWatcherWithPlayers = chunkWatcherWithPlayersQ = new ConcurrentLinkedQueueList<PlayerInstance>();
		} catch (NoSuchFieldError e) {
			// MCPC+.
		}
	}

	@Override
	@Declare
	public net.minecraft.util.LongHashMap getChunkWatchers() {
		return this.playerInstances;
	}

	@Override
	public void updatePlayerInstances() {
		int currentTick = MinecraftServer.currentTick;
		ArrayList<PlayerInstance> postponed = new ArrayList<PlayerInstance>();
		PlayerInstance playerInstance;
		while ((playerInstance = chunkWatcherWithPlayersQ.poll()) != null) {
			try {
				if (playerInstance.shouldPostPone(currentTick++ % 800 == 0, currentTick)) {
					postponed.add(playerInstance);
				} else {
					playerInstance.sendChunkUpdate();
				}
			} catch (Exception e) {
				Log.severe("Failed to send " + playerInstance, e);
				playerInstance.clearTileCount();
			}
		}

		chunkWatcherWithPlayersQ.addAll(postponed);

		if (currentTick % 300 == 0 && this.players.isEmpty()) {
			this.theWorldServer.theChunkProviderServer.unloadAllChunks();
		}
	}

	@Override
	public PlayerInstance getOrCreateChunkWatcher(int par1, int par2, boolean par3) {
		long var4 = (long) par1 + 2147483647L | (long) par2 + 2147483647L << 32;
		PlayerInstance var6 = (PlayerInstance) this.playerInstances.getValueByKey(var4);

		if (var6 == null && par3) {
			synchronized (chunkWatcherLock) {
				var6 = (PlayerInstance) this.playerInstances.getValueByKey(var4);
				if (var6 == null) {
{'fraction_non_alphanumeric': 0.10251630941286113, 'fraction_numerical': 0.020037278657968314, 'mean_word_length': 5.159253945480631, 'pattern_counts': {'":': 0, '<': 15, '<?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': '2496323', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1302, 'n_words': 263}