From 4cc661ae0ef2046fde205df259f676e9a3b35cda Mon Sep 17 00:00:00 2001 From: M_Viper Date: Sun, 24 May 2026 19:43:35 +0000 Subject: [PATCH] Delete src/main/java/net/viper/status/modules/forum/ForumNotifStorage.java via Git Manager GUI --- .../modules/forum/ForumNotifStorage.java | 127 ------------------ 1 file changed, 127 deletions(-) delete mode 100644 src/main/java/net/viper/status/modules/forum/ForumNotifStorage.java diff --git a/src/main/java/net/viper/status/modules/forum/ForumNotifStorage.java b/src/main/java/net/viper/status/modules/forum/ForumNotifStorage.java deleted file mode 100644 index 8a283ca..0000000 --- a/src/main/java/net/viper/status/modules/forum/ForumNotifStorage.java +++ /dev/null @@ -1,127 +0,0 @@ -package net.viper.status.modules.forum; - -import java.io.*; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.logging.Logger; - -/** - * Speichert ausstehende Forum-Benachrichtigungen (Datei-basiert). - * Benachrichtigungen die nicht sofort zugestellt werden konnten (Spieler offline) - * werden hier gespeichert und beim nächsten Login zugestellt. - */ -public class ForumNotifStorage { - - private final File file; - private final Logger logger; - - // UUID -> Liste ausstehender Notifications - private final ConcurrentHashMap> pending = new ConcurrentHashMap<>(); - - public ForumNotifStorage(File pluginFolder, Logger logger) { - if (!pluginFolder.exists()) pluginFolder.mkdirs(); - this.file = new File(pluginFolder, "forum_notifications.dat"); - this.logger = logger; - } - - /** - * Fügt eine Benachrichtigung hinzu. - */ - public void add(ForumNotification notification) { - pending.computeIfAbsent(notification.getPlayerUuid(), k -> new CopyOnWriteArrayList<>()) - .add(notification); - } - - /** - * Gibt alle ausstehenden (nicht zugestellten) Benachrichtigungen eines Spielers zurück. - */ - public List getPending(UUID playerUuid) { - CopyOnWriteArrayList list = pending.get(playerUuid); - if (list == null) return Collections.emptyList(); - List result = new ArrayList<>(); - for (ForumNotification n : list) { - if (!n.isDelivered()) result.add(n); - } - return result; - } - - /** - * Anzahl ausstehender Benachrichtigungen. - */ - public int getPendingCount(UUID playerUuid) { - CopyOnWriteArrayList list = pending.get(playerUuid); - if (list == null) return 0; - int count = 0; - for (ForumNotification n : list) { - if (!n.isDelivered()) count++; - } - return count; - } - - /** - * Markiert alle Benachrichtigungen eines Spielers als zugestellt und entfernt sie. - */ - public void clearDelivered(UUID playerUuid) { - CopyOnWriteArrayList list = pending.get(playerUuid); - if (list == null) return; - list.removeIf(ForumNotification::isDelivered); - if (list.isEmpty()) pending.remove(playerUuid); - } - - /** - * Markiert alle als zugestellt. - */ - public void markAllDelivered(UUID playerUuid) { - CopyOnWriteArrayList list = pending.get(playerUuid); - if (list == null) return; - for (ForumNotification n : list) { - n.setDelivered(true); - } - } - - /** - * Entfernt Benachrichtigungen die älter als maxDays Tage sind. - */ - public void purgeOld(int maxDays) { - long cutoff = System.currentTimeMillis() - ((long) maxDays * 24 * 60 * 60 * 1000); - for (Map.Entry> entry : pending.entrySet()) { - entry.getValue().removeIf(n -> n.getTimestamp() < cutoff); - if (entry.getValue().isEmpty()) pending.remove(entry.getKey()); - } - } - - // ===== Datei-Operationen ===== - - public void save() { - try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"))) { - for (CopyOnWriteArrayList list : pending.values()) { - for (ForumNotification n : list) { - if (!n.isDelivered()) { - bw.write(n.toLine()); - bw.newLine(); - } - } - } - bw.flush(); - } catch (IOException e) { - logger.warning("Fehler beim Speichern der Forum-Benachrichtigungen: " + e.getMessage()); - } - } - - public void load() { - if (!file.exists()) return; - try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"))) { - String line; - while ((line = br.readLine()) != null) { - ForumNotification n = ForumNotification.fromLine(line); - if (n != null && !n.isDelivered()) { - pending.computeIfAbsent(n.getPlayerUuid(), k -> new CopyOnWriteArrayList<>()) - .add(n); - } - } - } catch (IOException e) { - logger.warning("Fehler beim Laden der Forum-Benachrichtigungen: " + e.getMessage()); - } - } -}