package net.lankylord.potentialninja.listeners;

import net.lankylord.potentialninja.PotentialNinja;

import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.material.Sign;

import static net.lankylord.potentialninja.util.util.protectableBlock;
import static org.bukkit.Material.WALL_SIGN;

/**
 * Created by LankyLord on 29/10/2014.
 */
public class SignListener implements Listener {

  private final PotentialNinja plugin;

  public SignListener(PotentialNinja plugin) {
    this.plugin = plugin;
    Bukkit.getServer().getPluginManager().registerEvents(this, plugin);
  }

  @EventHandler(ignoreCancelled = true)
  public void onSignChange(SignChangeEvent event) {
    /*Player player = event.getPlayer();
    Block block = event.getBlock();
    String[] signText = event.getLines();
    if (block.getType() == (WALL_SIGN)) {
      Sign sign = (Sign) block.getState().getData();
      Block attachedBlock = block.getRelative(sign.getAttachedFace());
      if (protectableBlock(attachedBlock)) {
        //TODO: Check if block is already protected
        if (event.getLine(0).equalsIgnoreCase("[ninja]")) {
          org.bukkit.block.Sign signBlock = (org.bukkit.block.Sign) block.getState();

          int id = plugin.storageManager.lockItem(player.getUniqueId().toString());

          signBlock.setLine(0, "[Ninja Proof]");
          signBlock.setLine(1, "=======");
          signBlock.setLine(2, String.valueOf(id));
          signBlock.setLine(3, "=======");
          signBlock.update();
          event.setCancelled(true);
        }
      }
    }*/
  }
  //TODO: Quick place sign

}
