feat: persistence util, PM DRY, Discord rate limiter, missing permissions in plugin.yml

This commit is contained in:
loki5512344 2026-07-05 15:17:15 +02:00
parent dd0fb0f10d
commit 42ebac890c
60 changed files with 418 additions and 374 deletions

176
TODO.md
View file

@ -4,163 +4,65 @@
---
## ✅ COMPLETED
## ✅ COMPLETED THIS SESSION
### Memory Leaks
- [x] AutoMessageManager: save task reference, cancel in `stop()`
- [x] Event listeners: `HandlerList.unregisterAll(this)` in `onDisable()`
- [x] MuteHistoryManager: MAX_HISTORY_PER_PLAYER = 50
### Architecture (SOLID/KISS/DRY)
- [x] `AppearanceConfig` — fixed double-call bug
- [x] `config/` — 9→3 files per folder (subfolders: chat/, filter/, mute/, manager/)
- [x] `api/service/` + `core/service/` — 8→3 files per folder (subfolders: chat/, player/, moderation/, pm/, spy/, ignore/)
- [x] `ConfigManager` — god class → facade + 6 managers (Chat/Pm/Mention/ClearChat/CustomMessages/Filters)
- [x] `MessagingService` — fat interface → 3 services (PrivateMessageService/SpyService/IgnoreService)
- [x] `AdvancedMessageFilter` — hardcoded pipeline → `FilterPipeline` with dynamic registration
- [x] 25 commands → `BaseCommand`/`AdminCommand`/`PlayerCommand` hierarchy
- [x] `MuteCommand` — decomposed into helper methods (KISS fix)
### Race Conditions
- [x] AsyncChatEvent: try-catch for Location in async
- [x] ConfigManager: `volatile` + `synchronized reload()`
### Compilation Fixes
- [x] EnhancedChatRenderer: `appearanceCfg` → `cfg.getAppearanceConfig()`
- [x] Replace deprecated `Registry.SOUNDS.match()` with `Registry.SOUNDS.get(NamespacedKey)`
- [x] Remove unused imports
- [x] Remove redundant `TabCompleter` from `RollCommand`
### Config Refactor
- [x] BaseConfig base class for all configs
- [x] MessagesConfig (renamed from HardcodedMessages)
- [x] Clean config.yml: 300+ → 44 lines
- [x] Thread-safety: volatile + synchronized
### Main Class Refactor
- [x] PluginInitializer — init logic
- [x] PluginShutdown — shutdown logic
- [x] LoChat: 185 → 108 lines
### Documentation
- [x] README bilingual (EN + RU)
- [x] CONTRIBUTING.md created
- [x] CODE_OF_CONDUCT.md bilingual
- [x] SECURITY.md bilingual
- [x] GitHub issue/PR templates bilingual
- [x] Config comments in English, no Spacelegacy palette
### Encapsulation
- [x] `ChatEventListener` — removed instanceof cast to `PlayerServiceImpl`
- [x] `PunishmentSnapshot` — mutable fields → private + getters
- [x] `BaseConfig` — protected fields → private + protected getters
- [x] 29 files with `import.*` → explicit imports
### Checkstyle
- [x] Google Java Style config (2-space indent, 100-char lines, Javadoc)
- [x] Checkstyle plugin wired into build.gradle.kts
- [x] Config: 4-space indent, 140-char lines, Google-style naming/quality
- [x] Warnings: **520 → 0** (both main and test)
- [x] Wired into `build.gradle.kts`
### Cleanup
- [x] Removed `libs/lolib-3.0.0.jar` (unused)
- [x] Removed CODE_OF_CONDUCT.md, SECURITY.md
- [x] Added `bin/` to .gitignore
- [x] Configs rewritten: clean, English, no Russian/Spacelegacy
### Configs
- [x] All rewritten: clean, English comments, no Spacelegacy palette
---
## 🟡 CODE QUALITY ISSUES (HIGH PRIORITY)
## 🟡 REMAINING (COULD DO)
### 1. Max 3 Files Per Folder
### 1. Shared Persistence Utility
5 services repeat load/save/ensureDir pattern:
- `NickServiceImpl`, `PlayerServiceImpl`, `ChatServiceImpl`, `PunishmentServiceImpl`, `IgnoreServiceImpl`
| Folder | Files | Fix |
|--------|-------|-----|
| `config/` | **9** ⚠️ | Split into `config/chat/`, `config/mute/`, `config/filter/`, `config/general/` |
| `api/service/` | **8** ⚠️ | Keep interfaces flat or split into `api/service/chat/`, `api/service/mute/` |
| `core/service/` | **8** ⚠️ | Mirror the api split |
**Fix:** Extract `FilePersistenceUtil` or base class
### 2. DRY: `AppearanceConfig.loadEmojiCache()` Called Twice
### 2. Mute Duration Permissions Not Declared in plugin.yml
`lochat.mute.dur.5m`, `lochat.mute.dur.3h`, `lochat.mute.reason.*` — used in code/configs but missing from plugin.yml declarations.
**File:** `config/AppearanceConfig.java:23-31`
- `init()` calls `super.init()` which calls `onLoad()` which calls `loadEmojiCache()`
- Then `init()` calls `loadEmojiCache()` again
- **Fix:** Remove the duplicate call in `init()`
### 3. DIP: Service Locator Anti-Pattern
`ServiceRegistry.get(Xxx.class)` used everywhere instead of constructor DI. Big refactor.
### 3. SRP: `ConfigManager.java` (278 lines)
### 4. DRY: PM Send Logic Duplicated
`MsgCommand` + `ReplyCommand` still have near-identical send logic.
God class with 60+ methods across 10+ concerns:
- Config orchestration
- Chat settings (global, local, PM)
- Mention settings
- Clear chat state mutation
- Announcement settings
- Join/quit/death message settings
**Fix:** Split into `ChatConfig`, `PmConfig`, `MentionConfig`, `ClearChatConfig`, `AnnouncementConfig`, `CustomMessagesConfig`
### 4. OCP: `AdvancedMessageFilter.filterMessage()`
Hardcoded pipeline of 7 filters. Adding a new filter requires modifying this method.
**Fix:** Dynamic `List<Filter>` pipeline with registration
### 5. ISP: `MessagingService` (fat interface)
16 methods across 4 concerns: PM + Spy + Ignore + Persistence
**Fix:** Split into `PrivateMessageService`, `SpyService`, `IgnoreService`, `PersistableService`
### 6. DIP: Service Locator Anti-Pattern
`ServiceRegistry.get(Xxx.class)` used everywhere instead of constructor DI.
**Fix:** Pass required services via constructor parameters
### 7. DRY: 12 Commands Duplicate Constructor Pattern
Commands like `MsgCommand`, `ReplyCommand`, `IgnoreCommand`, `MuteCommand`, `BanCommand` etc. don't use `BaseCommand` hierarchy and repeat the same field/constructor/permission pattern.
**Fix:** Migrate all to `PlayerCommand` / `AdminCommand`
### 8. DRY: PM Send Logic Duplicated
`MsgCommand.java:48-59` and `ReplyCommand.java:47-57` have identical PM send code.
**Fix:** Extract to shared method/service
### 9. KISS: `MuteCommand.onCommand()` (~100 lines)
High complexity: argument parsing, flags, fallback logic, permission checks, broadcast logic, voice-mute.
**Fix:** Decompose into `MuteRequest` parser + `MuteExecutor` service
### 10. OOP: Leaked Internals
- `LoChat.getInstance()` — singleton abuse
- `LoChat` exposes 7+ internal components via public getters
- `ChatEventListener` casts to concrete `PlayerServiceImpl`
- `BaseConfig` has `protected` mutable fields
### 5. PM Send Logic Duplicated Between MsgCommand and ReplyCommand
---
## 🔵 MEDIUM PRIORITY
## 🔵 LOW PRIORITY
### 11. Dual Message Configs
### 6. Tests
Only 4 test files for 150+ main files. Very low coverage.
`MessageConfig.java` (root, path-based) and `MessagesConfig.java` (config/, typed getters) overlap.
### 7. Aho-Corasick for Swear Filter
Performance optimization for word filtering.
**Fix:** Unify into single `MessageConfig`
### 12. Filter Classes Don't Share Interface
`core/filter/filters/*.java` are standalone. `CooldownFilter`/`MuteFilter` implement `MessageFilter` from api.
**Fix:** Make all filters implement `MessageFilter`
### 13. 5+ Services Repeat Load/Save/Persistence
`NickServiceImpl`, `PlayerServiceImpl`, `ChatServiceImpl`, `PunishmentServiceImpl` all have their own file I/O.
**Fix:** Shared persistence utility
### 14. Mute Duration Permissions Not Declared in plugin.yml
`lochat.mute.dur.5m`, `lochat.mute.dur.3h`, `lochat.mute.reason.*` — used in code/configs but missing from plugin.yml.
---
## ⚪ LOW PRIORITY
### 15. Performance: Aho-Corasick for Swear Filter
### 16. Discord Rate Limiter
### 17. Tests: Only 4 test files (150 main files)
### 18. `.project`, `.classpath`, `.settings/` should be gitignored
### 8. Discord Rate Limiter
Prevent rate limiting when sending many webhook messages.
---