Remove downloads correctly.
[xudocci.git] / src / main / java / net / pterodactylus / xdcc / core / Core.java
index 7013883..9d5dcb7 100644 (file)
@@ -46,6 +46,7 @@ import net.pterodactylus.irc.event.DccDownloadFailed;
 import net.pterodactylus.irc.event.DccDownloadFinished;
 import net.pterodactylus.irc.event.DccSendReceived;
 import net.pterodactylus.irc.event.NicknameChanged;
+import net.pterodactylus.irc.event.PrivateNoticeReceived;
 import net.pterodactylus.irc.event.PrivateMessageReceived;
 import net.pterodactylus.irc.util.MessageCleaner;
 import net.pterodactylus.irc.util.RandomNickname;
@@ -533,6 +534,22 @@ public class Core extends AbstractExecutionThreadService {
        }
 
        /**
+        * Sends a message to all console when a notice was received.
+        *
+        * @param privateNoticeReceived
+        *              The notice received event
+        */
+       @Subscribe
+       public void privateNoticeReceived(PrivateNoticeReceived privateNoticeReceived) {
+               Optional<Network> network = getNetwork(privateNoticeReceived.connection());
+               if (!network.isPresent()) {
+                       return;
+               }
+
+               eventBus.post(new GenericMessage(String.format("Notice from %s (%s): %s", privateNoticeReceived.reply().source(), network.get(), privateNoticeReceived.text())));
+       }
+
+       /**
         * Starts a DCC download.
         *
         * @param dccSendReceived
@@ -566,7 +583,7 @@ public class Core extends AbstractExecutionThreadService {
                                }
 
                                /* remove download. */
-                               downloads.remove(download);
+                               downloads.remove(download.pack().name());
                                return;
                        }
 
@@ -613,7 +630,7 @@ public class Core extends AbstractExecutionThreadService {
                                eventBus.post(new GenericError(String.format("Download %s from %s does not start at the right position!")));
                                logger.log(Level.WARNING, String.format("Download %s from %s: have %d bytes but wants to resume from %d!", dccAcceptReceived.filename(), dccAcceptReceived.source(), outputFile.length(), dccAcceptReceived.position()));
 
-                               downloads.remove(download);
+                               downloads.remove(download.pack().name());
                                return;
                        }
                        OutputStream outputStream = new FileOutputStream(outputFile, true);
@@ -647,7 +664,7 @@ public class Core extends AbstractExecutionThreadService {
                        file.renameTo(new File(finalDirectory, download.pack().name()));
                        eventBus.post(new DownloadFinished(download));
                        dccReceivers.remove(dccDownloadFinished.dccReceiver());
-                       downloads.remove(download);
+                       downloads.remove(download.pack().name());
                } catch (IOException ioe1) {
                        /* TODO - handle all the errors. */
                        logger.log(Level.WARNING, String.format("Could not move file %s to directory %s.", download.filename(), finalDirectory), ioe1);
@@ -672,7 +689,7 @@ public class Core extends AbstractExecutionThreadService {
                        Closeables.close(download.outputStream(), true);
                        eventBus.post(new DownloadFailed(download));
                        dccReceivers.remove(dccDownloadFailed.dccReceiver());
-                       downloads.remove(download);
+                       downloads.remove(download.pack().name());
                } catch (IOException ioe1) {
                        /* swallow silently. */
                }