<commit_before>/**
 * Copyright 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.zandor300.torchlight;

import com.zandor300.torchlight.commands.TorchLightCommand;
import com.zandor300.zsutilities.commandsystem.CommandManager;
import com.zandor300.zsutilities.utilities.Chat;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.mcstats.Metrics;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author <NAME>
 * @since 1.0.0
 */
public class TorchLight extends JavaPlugin {

	private static HashMap<String, BlockState> playerState = new HashMap<String, BlockState>();

	private static Chat chat = new Chat("TorchLight", ChatColor.GOLD);
	private static TorchLight plugin;
	private static BukkitTask task;

	public static Chat getChat() {
		return chat;
	}

	public static TorchLight getPlugin() {
		return plugin;
	}

	@Override
	public void onEnable() {
		chat.sendConsoleMessage("Setting things up...");

		plugin = this;

		chat.sendConsoleMessage("Starting metrics...");
		try {
			new Metrics(this).start();
			chat.sendConsoleMessage("Submitted stats to MCStats.org.");
		} catch (IOException e) {
			chat.sendConsoleMessage("Couldn't submit stats to MCStats.org...");
		}

		chat.sendConsoleMessage("Starting timers...");
		task = Bukkit.getScheduler().runTaskTimer(this, new Runnable() {
			@Override
			public void run() {
				for (Player player : Bukkit.getOnlinePlayers()) {
					if (!player.getItemInHand().getType().equals(Material.TORCH)) {
						if (playerState.get(player.getName()) != null) {
							BlockState state = playerState.get(player.getName());
							state.getLocation().getBlock().setType(state.getType());
							state.getLocation().getBlock().setData(state.getData().getData());
						}
						playerState.put(player.getName(), null);
					} else {
						BlockState state = playerState.get(player.getName());
						state.getLocation().getBlock().setType(state.getType());
						state.getLocation().getBlock().setData(state.getData().getData());
						Location location = new Location(player.getWorld(), player.getLocation().getX(), player.getLocation().getY() - 1, player.getLocation().getZ());
						playerState.put(player.getName(), location.getBlock().getState());
						location.getBlock().setType(Material.GLOWSTONE);
					}
				}
			}
		}, 20l, 1l);
		chat.sendConsoleMessage("Timers started.");

		CommandManager cm = new CommandManager();
		cm.registerCommand(new TorchLightCommand(), this);

		chat.sendConsoleMessage("Everything is setup!");<commit_msg>Big bug... But it's funny! :P<commit_after>/**
 * Copyright 2015 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.zandor300.torchlight;

import com.zandor300.torchlight.commands.TorchLightCommand;
import com.zandor300.zsutilities.commandsystem.CommandManager;
import com.zandor300.zsutilities.utilities.Chat;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import org.mcstats.Metrics;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author <NAME>
 * @since 1.0.0
 */
public class TorchLight extends JavaPlugin {

	private static HashMap<String, BlockState> playerState = new HashMap<String, BlockState>();

	private static Chat chat = new Chat("TorchLight", ChatColor.GOLD);
	private static TorchLight plugin;
	private static BukkitTask task;

	public static Chat getChat() {
		return chat;
	}

	public static TorchLight getPlugin() {
		return plugin;
	}

	@Override
	public void onEnable() {
		chat.sendConsoleMessage("Setting things up...");

		plugin = this;

		chat.sendConsoleMessage("Starting metrics...");
		try {
			new Metrics(this).start();
			chat.sendConsoleMessage("Submitted stats to MCStats.org.");
		} catch (IOException e) {
			chat.sendConsoleMessage("Couldn't submit stats to MCStats.org...");
		}

		chat.sendConsoleMessage("Starting timers...");
		task = Bukkit.getScheduler().runTaskTimer(this, new Runnable() {
			@Override
			public void run() {
				for (Player player : Bukkit.getOnlinePlayers()) {
					if (!player.getItemInHand().getType().equals(Material.TORCH)) {
						if (playerState.get(player.getName()) != null) {
							BlockState state = playerState.get(player.getName());
							if(state.getLocation().getBlock() != null) {
								state.getLocation().getBlock().setType(state.getType());
								state.getLocation().getBlock().setData(state.getData().getData());
							}
						}
						playerState.put(player.getName(), null);
					} else {
						BlockState state = playerState.get(player.getName());
						if(state != null && state.getLocation().getBlock() != null) {
							state.getLocation().getBlock().setType(state.getType());
							state.getLocation().getBlock().setData(state.getData().getData());
						}
						Location location = new Location(player.getWorld(), player.getLocation().getX(), player.getLocation().getY() - 1, player.getLocation().getZ());
						playerState.put(player.getName(), location.getBlock().getState());
						location.getBlock().setType(Material.GLOWSTONE);
					}
				}
			}
		}, 20l, 1l);
		chat.sendConsoleMessage("Timers started.");

		CommandManager cm = new CommandManager();
		cm.registerCommand(new TorchLightCommand(), this);

		chat.sendConsoleMessage("Everything is setup!");
{'fraction_non_alphanumeric': 0.13252117070271877, 'fraction_numerical': 0.008022582082900015, 'mean_word_length': 4.214562354763749, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1688620', 'n_tokens_mistral': 2269, 'n_tokens_neox': 1961, 'n_words': 492}