/* (non-Javadoc)
   * @see org.bukkit.event.player.PlayerListener#onPlayerInteract(org.bukkit.event.player.PlayerInteractEvent)
   */
  @Override
  public void onPlayerInteract(PlayerInteractEvent event) {
    Block clicked = event.getClickedBlock();
    Player player = event.getPlayer();

    if (clicked != null
        && (clicked.getType() == Material.STONE_BUTTON || clicked.getType() == Material.LEVER)) {
      if (!this.ButtonLeverHit(player, clicked, null)) {
        event.setCancelled(true);
      }
    } else if (clicked != null && clicked.getType() == Material.WALL_SIGN) {
      Stargate stargate = StargateManager.getGateFromBlock(clicked);

      if (stargate != null) {
        if (WXPermissions.checkWXPermissions(player, stargate, PermissionType.SIGN)) {
          if (stargate.TryClickTeleportSign(clicked)) {
            String target = "";
            if (stargate.SignTarget != null) {
              target = stargate.SignTarget.Name;
            }
            player.sendMessage("Dialer set to: " + target);
          }
        } else {
          player.sendMessage(ConfigManager.output_strings.get(StringTypes.PERMISSION_NO));
          event.setCancelled(true);
        }
      }
    }
  }
  /**
   * Handle gate activation switch.
   *
   * @param stargate the stargate
   * @param player the player
   * @return true, if successful
   */
  private boolean HandleGateActivationSwitch(Stargate stargate, Player player) {
    if (stargate.Active || stargate.LitGate) {
      if (stargate.Target != null) {
        // Shutdown stargate
        stargate.ShutdownStargate();
        player.sendMessage(ConfigManager.output_strings.get(StringTypes.GATE_SHUTDOWN));
        return true;
      } else {
        Stargate s2 = StargateManager.RemoveActivatedStargate(player);
        if (s2 != null && stargate.GateId == s2.GateId) {
          stargate.StopActivationTimer(player);
          stargate.DeActivateStargate();
          stargate.UnLightStargate();
          player.sendMessage(ConfigManager.output_strings.get(StringTypes.GATE_DEACTIVATED));
          return true;
        } else {
          if (stargate.LitGate && !stargate.Active) {
            player.sendMessage(
                ConfigManager.errorheader + "Gate has been activated by someone else already.");
          } else {
            player.sendMessage(ConfigManager.output_strings.get(StringTypes.GATE_REMOTE_ACTIVE));
          }
          return false;
        }
      }
    } else {
      if (stargate.IsSignPowered) {
        if (WXPermissions.checkWXPermissions(player, stargate, PermissionType.SIGN)) {
          if (stargate.TeleportSign == null && stargate.TeleportSignBlock != null) {
            stargate.TryClickTeleportSign(stargate.TeleportSignBlock);
          }

          if (stargate.SignTarget != null) {
            if (stargate.DialStargate(stargate.SignTarget)) {
              player.sendMessage(ConfigManager.normalheader + "Stargates connected!");
              return true;
            } else {
              player.sendMessage(ConfigManager.output_strings.get(StringTypes.GATE_REMOTE_ACTIVE));
              return false;
            }
          } else {
            player.sendMessage(ConfigManager.output_strings.get(StringTypes.TARGET_INVALID));
            return false;
          }
        } else {
          player.sendMessage(ConfigManager.output_strings.get(StringTypes.PERMISSION_NO));
          return false;
        }
      } else {
        // Activate Stargate
        player.sendMessage(ConfigManager.output_strings.get(StringTypes.GATE_ACTIVATED));
        player.sendMessage(
            ConfigManager.normalheader
                + "Chevrons Locked! \u00A73:: \u00A7B<required> \u00A76[optional]");
        player.sendMessage(
            ConfigManager.normalheader
                + "Type \'\u00A7F/dial \u00A7B<gatename> \u00A76[idc]\u00A77\'");
        StargateManager.AddActivatedStargate(player, stargate);
        stargate.StartActivationTimer(player);
        stargate.LightStargate();
        return true;
      }
    }
  }