<commit_before>package me.nallar.patched;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.relauncher.Side;
import me.nallar.tickthreading.Log;
import me.nallar.tickthreading.minecraft.ChunkGarbageCollector;
import me.nallar.tickthreading.minecraft.DeadLockDetector;
import me.nallar.tickthreading.minecraft.ThreadManager;
import me.nallar.tickthreading.minecraft.TickThreading;
import me.nallar.tickthreading.patcher.Declare;
import me.nallar.tickthreading.util.FakeServerThread;
import net.minecraft.crash.CrashReport;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet4UpdateTime;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.gui.IUpdatePlayerListBox;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.ReportedException;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;

public abstract class PatchMinecraftServer extends MinecraftServer {
	public ThreadManager threadManager;
	private static float tickTime = 0;
	private static float networkTickTime = 0;
	private AtomicInteger currentWorld;
	private Integer[] dimensionIdsToTick;
	private Runnable tickRunnable;
	private static int TARGET_TPS;
	private static int TARGET_TICK_TIME;
	private static int NETWORK_TPS;
	private static int NETWORK_TICK_TIME;
	private static double currentTPS = 0;
	private static double networkTPS = 0;
	private Map<Integer, Integer> exceptionCount;
	private boolean tickNetworkInMainThread;
	@Declare
	public boolean currentlySaving_;

	public void construct() {
		currentlySaving = false;
		tickNetworkInMainThread = true;
		exceptionCount = new HashMap<Integer, Integer>();
	}

	public static void staticConstruct() {
		setTargetTPS(20);
		setNetworkTPS(40);
	}

	public PatchMinecraftServer(File par1File) {
		super(par1File);
	}

	@Declare
	public static void setTargetTPS(int targetTPS) {
		assert targetTPS > 0 : "Target TPS must be greater than 0";
		TARGET_TPS = targetTPS;
		TARGET_TICK_TIME = 1000000000 / TARGET_TPS;
	}

	@Declare
	public static void setNetworkTPS(int targetTPS) {
		assert targetTPS > 0 : "Target TPS must be greater than 0";
		NETWORK_TPS = targetTPS;
		NETWORK_TICK_TIME = 1000000000 / NETWORK_TPS;
	}

	@Override
	public void run() {
		try {
			if (this.startServer()) {
				FMLCommonHandler.instance().handleServerStarted();
				FMLCommonHandler.instance().onWorldLoadTick(worldServers);
				// This block is derived from Spigot code,
				// LGPL
				this.serverIsRunning = true;
				this.tick();
				if (TickThreading.instance.concurrentNetworkTicks) {
					tickNetworkInMainThread = false;
					new FakeServerThread(new NetworkTickRunnable(this), "Network Tick", false).start();
				}
				for (long lastTick = 0L; this.serverRunning; ) {
					long curTime = System.nanoTime();
					long wait = TARGET_TICK_TIME - (curTime - lastTick);
					if (wait > 0 && (currentTPS > TARGET_TPS || !TickThreading.instance.aggressiveTicks)) {
						Thread.sleep(wait / 1000000);
						continue;
					}
					currentTPS = (currentTPS * 0.99) + (1E9 / (curTime - lastTick) * 0.01);
					lastTick = curTime;
					tickCounter++;
					this.tick();
				}
				FMLCommonHandler.instance().handleServerStopping();
			} else {
				this.finalTick(null);
			}
		} catch (Throwable throwable) {
			DeadLockDetector.sendChatSafely("The server has crashed - sorry about that. :(");
			try {
				Thread.sleep(1000);
			} catch (InterruptedException ignored) {
			}<commit_msg>Try to continue after exception in main tick loop<commit_after>package me.nallar.patched;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;

import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.relauncher.Side;
import me.nallar.tickthreading.Log;
import me.nallar.tickthreading.minecraft.ChunkGarbageCollector;
import me.nallar.tickthreading.minecraft.DeadLockDetector;
import me.nallar.tickthreading.minecraft.ThreadManager;
import me.nallar.tickthreading.minecraft.TickThreading;
import me.nallar.tickthreading.patcher.Declare;
import me.nallar.tickthreading.util.FakeServerThread;
import net.minecraft.crash.CrashReport;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet4UpdateTime;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.gui.IUpdatePlayerListBox;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.util.ReportedException;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;

public abstract class PatchMinecraftServer extends MinecraftServer {
	public ThreadManager threadManager;
	private static float tickTime = 0;
	private static float networkTickTime = 0;
	private AtomicInteger currentWorld;
	private Integer[] dimensionIdsToTick;
	private Runnable tickRunnable;
	private static int TARGET_TPS;
	private static int TARGET_TICK_TIME;
	private static int NETWORK_TPS;
	private static int NETWORK_TICK_TIME;
	private static double currentTPS = 0;
	private static double networkTPS = 0;
	private Map<Integer, Integer> exceptionCount;
	private boolean tickNetworkInMainThread;
	@Declare
	public boolean currentlySaving_;

	public void construct() {
		currentlySaving = false;
		tickNetworkInMainThread = true;
		exceptionCount = new HashMap<Integer, Integer>();
	}

	public static void staticConstruct() {
		setTargetTPS(20);
		setNetworkTPS(40);
	}

	public PatchMinecraftServer(File par1File) {
		super(par1File);
	}

	@Declare
	public static void setTargetTPS(int targetTPS) {
		assert targetTPS > 0 : "Target TPS must be greater than 0";
		TARGET_TPS = targetTPS;
		TARGET_TICK_TIME = 1000000000 / TARGET_TPS;
	}

	@Declare
	public static void setNetworkTPS(int targetTPS) {
		assert targetTPS > 0 : "Target TPS must be greater than 0";
		NETWORK_TPS = targetTPS;
		NETWORK_TICK_TIME = 1000000000 / NETWORK_TPS;
	}

	@Override
	public void run() {
		try {
			if (this.startServer()) {
				FMLCommonHandler.instance().handleServerStarted();
				FMLCommonHandler.instance().onWorldLoadTick(worldServers);
				// This block is derived from Spigot code,
				// LGPL
				this.serverIsRunning = true;
				this.tick();
				if (TickThreading.instance.concurrentNetworkTicks) {
					tickNetworkInMainThread = false;
					new FakeServerThread(new NetworkTickRunnable(this), "Network Tick", false).start();
				}
				for (long lastTick = 0L; this.serverRunning; ) {
					long curTime = System.nanoTime();
					long wait = TARGET_TICK_TIME - (curTime - lastTick);
					if (wait > 0 && (currentTPS > TARGET_TPS || !TickThreading.instance.aggressiveTicks)) {
						Thread.sleep(wait / 1000000);
						continue;
					}
					currentTPS = (currentTPS * 0.99) + (1E9 / (curTime - lastTick) * 0.01);
					lastTick = curTime;
					tickCounter++;
					try {
						this.tick();
					} catch (Exception e) {
						Log.severe("Exception in main tick loop", e);
					}
				}
				FMLCommonHandler.instance().handleServerStopping();
			} else {
				this.finalTick(null);
			}
		} catch (Throwable throwable) {
			DeadLockDetector.sendChatSafely("The server has crashed - sorry about that. :(");
			try {
				Thread.sleep(1000);
			} catch (InterruptedException ignored) {
			}
{'fraction_non_alphanumeric': 0.09725459725459726, 'fraction_numerical': 0.014504014504014505, 'mean_word_length': 4.6290087463556855, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '6341721', 'n_tokens_mistral': 2810, 'n_tokens_neox': 2471, 'n_words': 548}