public void sendMessage(Download download, String text) {
   if (download == null) return;
   byte[] peerID = download.getDownloadPeerId();
   if (peerID != null) {
     controller.sendMessage(download, peerID, nick, text);
   } else {
     System.out.println("System: Torrent isn't running, message can't be delivered");
   }
 }
  public void initialize(PluginInterface pi) {
    plugin_interface = pi;
    formatters = plugin_interface.getUtilities().getFormatters();
    genericTorrent = loadTorrent(resTorrent);

    nick =
        plugin_interface
            .getPluginconfig()
            .getPluginStringParameter("nick", "Guest" + (int) (Math.random() * 100000));
    active = plugin_interface.getPluginconfig().getPluginBooleanParameter("enable", true);

    if (active) {
      listeners = new ArrayList();
      listenersDownload = new ArrayList();
      controller = new PeerControllerImpl(this, nick);
      controller.addMessageListener(this);
      controller.initialize();
      controller.startPeerProcessing();
    }
  }
  @SuppressWarnings("unchecked")
  public void addMessageListener(MessageListener listener, Download download) {
    synchronized (listeners) {
      listeners.add(listener);
      listenersDownload.add(download);
    }

    listener.downloadAdded(download);
    if (controller.isDownloadActive(download)) {
      listener.downloadActive(download);
    } else {
      listener.downloadInactive(download);
    }
  }
  public Download addChannel(String channelName) {
    Torrent torrent = getChannelTorrent(channelName);
    String savePath = plugin_interface.getPluginDirectoryName();
    try {
      File saveDir = new File(savePath, "channels" + File.separator);
      saveDir.mkdir();
      Download dl = plugin_interface.getDownloadManager().addDownload(torrent, null, saveDir);
      dl.setForceStart(true);

      File dest = new File(savePath, "channels" + File.separator + channelName);
      File src = new File(savePath, "channels" + File.separator + "channel");
      copyFile(src, dest);

      controller.addBridge(dl, channelName);
      return dl;
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
 public void closeBridge(String channelName) {
   controller.removeBridge(channelName);
 }