/*
 *   This file is a part of the SteamWar software.
 *
 *   Copyright (C) 2025 SteamWar.de-Serverteam
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *   GNU Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package de.steamwar.fightsystem.fight;

import de.steamwar.fightsystem.FightSystem;
import org.bukkit.Bukkit;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.block.*;
import org.bukkit.event.entity.ItemSpawnEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerSwapHandItemsEvent;

public class FreezeWorld implements Listener {

    public FreezeWorld() {
        Bukkit.getPluginManager().registerEvents(this, FightSystem.getPlugin());
    }

    public void disable() {
        HandlerList.unregisterAll(this);
    }

    @EventHandler
    public void onBlockPhysicsEvent(BlockPhysicsEvent e) {
        e.setCancelled(true);
    }

    @EventHandler
    public void onPistonExtend(BlockPistonExtendEvent e) {
        e.setCancelled(true);
    }

    @EventHandler
    public void onPistonRetract(BlockPistonRetractEvent e) {
        e.setCancelled(true);
    }

    @EventHandler
    public void onBlockGrow(BlockGrowEvent e) {
        e.setCancelled(true);
    }

    @EventHandler
    public void onRedstoneEvent(BlockRedstoneEvent e) {
        e.setNewCurrent(e.getOldCurrent());
    }

    @EventHandler
    public void onBlockDispense(BlockDispenseEvent e) {
        e.setCancelled(true);
    }

    @EventHandler
    public void onInventoryMoveEvent(InventoryMoveItemEvent e) {
        e.setCancelled(true);
    }

    @EventHandler
    public void onBlockExplosion(BlockExplodeEvent e) {
        e.setCancelled(true);
    }

    @EventHandler
    public void onBlockExplosion(ItemSpawnEvent e) {
        e.setCancelled(true);
    }

    @EventHandler(priority = EventPriority.LOW)
    public void handlePlayerInteract(PlayerInteractEvent event) {
        event.setCancelled(true);
    }

    @EventHandler
    public void onSwapItems(PlayerSwapHandItemsEvent event) {
        if (Fight.fighting(event.getPlayer())) event.setCancelled(true);
    }
}
