package net.mc_pandacraft.java.plugin.pandacraftutils.cheat_protect.creative;

import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;

public class CreativCheatManager implements Listener {
	private PandacraftUtils plugin;
	
	public CreativCheatManager(PandacraftUtils pl)
	{
		plugin = pl;
		plugin.getServer().getPluginManager().registerEvents(this, plugin);
	}
	
	@EventHandler
	public void onPlayerMove (PlayerMoveEvent e)
	{
		if (e.getTo().getY() > -60.0)
			return;

		e.getPlayer().setFallDistance(0);
		e.getPlayer().setHealth(20);
		e.getPlayer().teleport(e.getTo().getWorld().getSpawnLocation());
		
		plugin.getLogger().info("§7"+e.getPlayer().getDisplayName()+"§r teleported to §7"+e.getTo().getWorld().getName()+"§r's spawn to avoid a bug exploit");
		e.getPlayer().sendMessage("§dVous avez été téléporté au spawn de cette map car vous alliez tomber dans le vide.");
	}
}
