+ //
+ // EVENT HANDLERS
+ //
+
+ /**
+ * Called when a download was started.
+ *
+ * @param downloadStarted
+ * The download started event
+ */
+ @Subscribe
+ public void downloadStarted(DownloadStarted downloadStarted) {
+ Download download = downloadStarted.download();
+ try {
+ writeLine(String.format("Download of %s (from %s, %s) has started.", bold(download.pack().name()), download.bot().name(), download.bot().network().name()));
+ } catch (IOException ioe1) {
+ /* ignore. */
+ }
+ }
+
+ /**
+ * Called when a download is finished.
+ *
+ * @param downloadFinished
+ * The download finished event
+ */
+ @Subscribe
+ public void downloadFinished(DownloadFinished downloadFinished) {
+ Download download = downloadFinished.download();
+ removeFailedDownloads(download.pack().name());
+ try {
+ writeLine(green(String.format("Download of %s (from %s, %s) has finished, at %s/s.", download.pack().name(), download.bot().name(), download.bot().network().name(), f(download.dccReceiver().overallRate()))));
+ } catch (IOException ioe1) {
+ /* ignore. */
+ }
+ }
+
+ private void removeFailedDownloads(String name) {
+ List<Download> failedDownloadsToRemove = new ArrayList<>();
+ for (Download failedDownload : failedDownloads) {
+ if (failedDownload.pack().name().equals(name)) {
+ failedDownloadsToRemove.add(failedDownload);
+ }
+ }
+ failedDownloads.removeAll(failedDownloadsToRemove);
+ }
+
+ /**
+ * Called when a download fails.
+ *
+ * @param downloadFailed
+ * The download failed event
+ */
+ @Subscribe
+ public void downloadFailed(DownloadFailed downloadFailed) {
+ Download download = downloadFailed.download();
+ failedDownloads.add(download);
+ try {
+ writeLine(red(String.format("Download of %s (from %s, %s) has failed at %.1f%% and %s/s.", download.filename(), download.bot().name(), download.bot().network().name(), download.dccReceiver().progress() * 100.0 / download.dccReceiver().size(), f(download.dccReceiver().overallRate()))));
+ } catch (IOException ioe1) {
+ /* ignore. */
+ }
+ }
+
+ /**
+ * Displays the received message on the console.
+ *
+ * @param messageReceived
+ * The message received event
+ */
+ @Subscribe
+ public void messageReceived(MessageReceived messageReceived) {
+ try {
+ writeLine(String.format("Message from %s: %s", messageReceived.source(), MessageCleaner.getDefaultInstance().clean(messageReceived.message())));
+ } catch (IOException e) {
+ /* ignore. */