<commit_before>package net.amigocraft.TTT.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import net.amigocraft.TTT.TTT;
import net.amigocraft.TTT.Variables;

import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

public class WorldUtils {

	// world checking method from Multiverse
	public static boolean isWorld(File worldFolder){
		File[] files = worldFolder.listFiles(new FilenameFilter(){
			@Override
			public boolean accept(File file, String name){
				return name.equalsIgnoreCase("level.dat");
			}
		});
		if (files != null && files.length > 0){
			return true;
		}
		return false;
	}

	public static void teleportPlayer(Player p){
		try {
			File spawnFile = new File(TTT.plugin.getDataFolder() + File.separator + "spawn.yml");
			if (spawnFile.exists()){
				YamlConfiguration spawnYaml = new YamlConfiguration();
				spawnYaml.load(spawnFile);
				if (spawnYaml.isSet("world") && spawnYaml.isSet("x") &&
						spawnYaml.isSet("y") && spawnYaml.isSet("z"));
				Location l = new Location(TTT.plugin.getServer().getWorld(spawnYaml.getString("world")),
						spawnYaml.getDouble("x"), spawnYaml.getDouble("y"), spawnYaml.getDouble("z"));
				if (spawnYaml.isSet("pitch"))
					l.setPitch((float)spawnYaml.getDouble("pitch"));
				if (spawnYaml.isSet("yaw"))
					l.setYaw((float)spawnYaml.getDouble("yaw"));
				p.teleport(l);
			}
			else
				p.teleport(TTT.plugin.getServer().getWorlds().get(0).getSpawnLocation());
		}
		catch (Exception ex){
			ex.printStackTrace();
		}
	}

	public static void rollbackWorld(final String worldName){
		TTT.plugin.getServer().getScheduler().scheduleSyncDelayedTask(TTT.plugin, new Runnable(){
			public void run(){
				File folder = new File(worldName);
				if (folder.exists()){
					if (WorldUtils.isWorld(folder)){
						File newFolder = new File("TTT_" + worldName);
						try {
							copyFile(folder, newFolder);
							if (Variables.VERBOSE_LOGGING)
								TTT.log.info(TTT.local.getMessage("rollback") + " \"" + worldName + "\"!");
						}
						catch (IOException ex){
							TTT.log.info(TTT.local.getMessage("folder-error") + " " + worldName);
							ex.printStackTrace();
						}
					}
					else
						TTT.log.info(TTT.local.getMessage("cannot-load-world"));
				}
			}
		}, 100L);
	}

	public static void importWorld(CommandSender sender, String worldName){
		File folder = new File(worldName);
		if (folder.exists()){
			if (!worldName.substring(0, 3).equalsIgnoreCase("TTT_")){
				if (isWorld(folder)){
					File newFolder = new File("TTT_" + worldName);
					if (!newFolder.exists()){
						try {
							File sessionLock = new File(folder + File.separator + "session.lock");
							File uidDat = new File(folder + File.separator + "uid.dat");
							sessionLock.delete();<commit_msg>Fix bug with scheduler<commit_after>package net.amigocraft.TTT.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import net.amigocraft.TTT.TTT;
import net.amigocraft.TTT.Variables;

import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;

public class WorldUtils {

	// world checking method from Multiverse
	public static boolean isWorld(File worldFolder){
		File[] files = worldFolder.listFiles(new FilenameFilter(){
			@Override
			public boolean accept(File file, String name){
				return name.equalsIgnoreCase("level.dat");
			}
		});
		if (files != null && files.length > 0){
			return true;
		}
		return false;
	}

	public static void teleportPlayer(Player p){
		try {
			File spawnFile = new File(TTT.plugin.getDataFolder() + File.separator + "spawn.yml");
			if (spawnFile.exists()){
				YamlConfiguration spawnYaml = new YamlConfiguration();
				spawnYaml.load(spawnFile);
				if (spawnYaml.isSet("world") && spawnYaml.isSet("x") &&
						spawnYaml.isSet("y") && spawnYaml.isSet("z"));
				Location l = new Location(TTT.plugin.getServer().getWorld(spawnYaml.getString("world")),
						spawnYaml.getDouble("x"), spawnYaml.getDouble("y"), spawnYaml.getDouble("z"));
				if (spawnYaml.isSet("pitch"))
					l.setPitch((float)spawnYaml.getDouble("pitch"));
				if (spawnYaml.isSet("yaw"))
					l.setYaw((float)spawnYaml.getDouble("yaw"));
				p.teleport(l);
			}
			else
				p.teleport(TTT.plugin.getServer().getWorlds().get(0).getSpawnLocation());
		}
		catch (Exception ex){
			ex.printStackTrace();
		}
	}

	public static void rollbackWorld(final String worldName){
				File folder = new File(worldName);
				if (folder.exists()){
					if (WorldUtils.isWorld(folder)){
						File newFolder = new File("TTT_" + worldName);
						try {
							copyFile(folder, newFolder);
							if (Variables.VERBOSE_LOGGING)
								TTT.log.info(TTT.local.getMessage("rollback") + " \"" + worldName + "\"!");
						}
						catch (IOException ex){
							TTT.log.info(TTT.local.getMessage("folder-error") + " " + worldName);
							ex.printStackTrace();
						}
					}
					else
						TTT.log.info(TTT.local.getMessage("cannot-load-world"));
				}
	}

	public static void importWorld(CommandSender sender, String worldName){
		File folder = new File(worldName);
		if (folder.exists()){
			if (!worldName.substring(0, 3).equalsIgnoreCase("TTT_")){
				if (isWorld(folder)){
					File newFolder = new File("TTT_" + worldName);
					if (!newFolder.exists()){
						try {
							File sessionLock = new File(folder + File.separator + "session.lock");
							File uidDat = new File(folder + File.separator + "uid.dat");
							sessionLock.delete();
{'fraction_non_alphanumeric': 0.14773869346733667, 'fraction_numerical': 0.0018425460636515912, 'mean_word_length': 3.8387358184764993, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6606408', 'n_tokens_mistral': 2375, 'n_tokens_neox': 1950, 'n_words': 373}