package eu.mhsl.minecraft.pixelblocks.listeners;

import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlock;
import eu.mhsl.minecraft.pixelblocks.pixelblock.PixelBlockWorld;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerMoveEvent;


public class FallOutOfPixelBlockListener implements Listener {
    @EventHandler
    public void onPlayerMove(PlayerMoveEvent event) {
        Player player = event.getPlayer();
        if(player.getLocation().y() > -65) return;
        if(!PixelBlockWorld.isPixelWorld(player.getWorld())) return;

        PixelBlock pixelBlock = PixelBlock.getPixelBlockFromBlockWorld(player.getWorld());
        if(pixelBlock == null) return;
        player.teleport(pixelBlock.getPixelWorld().getSpawnLocation());
    }
}
