From 09689ae799ac8c98b8e760ae3e985c4492d42745 Mon Sep 17 00:00:00 2001 From: loki5512344 Date: Sun, 5 Jul 2026 16:16:18 +0200 Subject: [PATCH] =?UTF-8?q?refactor:=20DIP=20=E2=80=94=20core=20services?= =?UTF-8?q?=20&=20listeners=20use=20constructor=20injection,=20ServiceRegi?= =?UTF-8?q?stry=20removed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/main/com/loki/lochat/LoChat.class | Bin 3692 -> 5522 bytes .../loki/lochat/core/PluginInitializer.class | Bin 5378 -> 4376 bytes .../core/registry/ServiceRegistry.class | Bin 4235 -> 4419 bytes .../lochat/listener/ChatEventListener.class | Bin 3741 -> 3494 bytes .../lochat/listener/ModerationListener.class | Bin 1516 -> 1371 bytes .../lochat/listener/PlayerEventListener.class | Bin 3411 -> 3070 bytes src/main/java/com/loki/lochat/LoChat.java | 11 +++++++++- .../loki/lochat/core/PluginInitializer.java | 19 ++++++++++++------ .../lochat/core/registry/ServiceRegistry.java | 9 ++++----- .../lochat/core/service/ChatServiceImpl.java | 3 +-- .../core/service/MessageServiceImpl.java | 10 +++------ .../lochat/listener/ChatEventListener.java | 11 +++++----- .../lochat/listener/ModerationListener.java | 5 ++--- .../lochat/listener/PlayerEventListener.java | 10 ++++----- 14 files changed, 44 insertions(+), 34 deletions(-) diff --git a/bin/main/com/loki/lochat/LoChat.class b/bin/main/com/loki/lochat/LoChat.class index 0ea54569cad3b4f7cf84aa7aa5e229d95029cd51..424ce2074d2d7112c517fa05b8624174f750dc95 100644 GIT binary patch delta 425 zcmaDOGf8{HKPD!&1Cy95C)+Vw!|-N1=0L{DJ?sgRzNy8Ole^iI#BvfVQ;U$~1Hb}M=|owG^31$+BqeY$m?~kv%;an&1t2a|Zt3KBR$ZV| zmH_GPOe_qOn3X3du$xb2W$79m4qU$ZFWWvAM)S!HyrPpYa_caLgIU5nI*hTC9e5lW z3nw@6m@}4wMb868E5R&5ULD3-Fe@0yY6P+z8C${p>p*@dm?g=l!`M67jZX~#TmXo% delta 153 zcmbQF{YGZPKPD!o?UNO`lqV}Qhiy(}5o4UZi^Y7h0C(u*ySy%wce3aL`P!2YaKalfMh;F#3U6mclxWA(PXD9T_twuMjq8%$fWE$SwfOnTzN! hmVjB6Kvo5qwHwH)0ki%BSq)&8y{Haj%j6tUH2_``G4lWb diff --git a/bin/main/com/loki/lochat/core/PluginInitializer.class b/bin/main/com/loki/lochat/core/PluginInitializer.class index 3c2bd2c8605c98867b277765403c450baea21ef7..a9d3ec1b3995a5ad731fe71f99d1a3fe78c20145 100644 GIT binary patch delta 717 zcmZWnO-~b16g`h24l{JxnW=zAlL{iyiArjS8=|IE7n&ApkeF_if{)>)b(+kyD1M>+eJ$ZA^N{{~K*XAbx3A|s` zml6041L!7Vz+Qd#cc+w=)3*n<$PY0`YXe5KZLuOrLW-= zo%b2^p|a<4o-F!T+wlPNDjw3|h@(8hW6DM@vPJq3$<97!Flu=vi{7MgRlHybH%F*q znZf)&HxWm?*~YjS!6HyNBY81}sl%qi99I@0#S uI!0F|u>}!%hNUd9AZJ;W8$4+c?5zp5NVLL!ij^vV2cBUGFYyYm@%A^r2gWo2 delta 1409 zcma)6U2qds6#j0DO|sdfKZ>0)BUJt-Nz+*h=m3RbN-cv-0#1>1f+IsnE@5p*W_Hs; z`3p@|s^U+$psj$2f`Y$kfu^M+FTVM-dG(Da--LG<#2ze-2^a4f5& zR6WbnTvNK~)icP`*^sS~FoO5Z>drEZijB^d%;qF;URu7{A8`{~AISI+A2E0}o;1TW z3qfbtFs~hM;wn|(PVxA;C0+iA10OR47cA(FRBXrwtVT*WhfmFtK4UmlIN9=SMcYik z^9*eZ0){gQUKz;0cm-TA@h&o~t&IHlnwF?PA|Zw^WQ-w1Q&#n!bnIY?Cmi^ap?yL8 z*Hk^8(Gve5aU7S;3|AP|`$UR1$RBayD#OdRd#goGYszN5waO$o2r;)31-fN9T8)8sGcHM<$ zub?JnhB{hH8X4sf4_)g-(A^@rF^rosZs7-U!M)|hpBSWV1L-8E#nlpS{DPtbzly)y zf!Ya7iWlTJ*&U(E(Z*>8Pnhd^ENQQ}*x>1Py@W+r3Ky0M;R&-<;(@1&`NRru7gGfH zZe<(A4R1HwLi)wxsdsN<4$U8E)^~fNkg*TX<1H-1+al2L zYL4wd9VG!KXQ4*}ci@@AfO(ZLw5#$wIfF9{vly|=ZS5tzXBuWOT8sG}=jJ>8mO1t;%1M++L)zYf(?(0Ai3Ng_wW7zS}2Lnz`n8VDv(;e#NX=ta!n8+;39 zN&ASp8cK7OB5qLf{iJn*J;8McAu)VM1k=KkHbPc2X60OO-_yr~cx(D`20vGs>j^jA qrdB4%vBv7eOJSfLYDOL_==)(7WI_^}i^?*SQ|)vVPz5}53vx6!v$3w_WOZcVVQ`vk$*(>6F<&67Cy?g_o{Z bGw?G6FeoqtO+L$C${NPN$q+u-UBCqZv+F0t delta 87 zcmX@C)UCL|o|%a?ZL%Y?|KwXN5tAn{&zKy<(lJ?%jcxNW)}@@RP7FK@&XYg#Yfqld qAIRzj{0xB%3Jk%MTLns4!x=akA}0SAZ~*{^r5I!Y diff --git a/bin/main/com/loki/lochat/listener/ChatEventListener.class b/bin/main/com/loki/lochat/listener/ChatEventListener.class index 1ccea7de74312b12181a1bcc120d807a45ed6d77..58a69063e2eb3ca6ecc07fc88c0bedbc2537b9fc 100644 GIT binary patch delta 820 zcmaKpOD_Xa6vzK(I{Fw>t$Nm@>QSwF)caM>g^iF9Dd}#sQY}l;GFVbi(QL4a^Y)YzC6QM4Q;7vlJJ8&y zA;+y=pe_B4cAQ^OeO2hx7lqz`Wm122Z|WDKuOy~^vLcd%0P1A;P@j7#ixWleU4EkO zT&4S##024;D@Sv$o*;=sgk@GCX)-K%ihV?`}MAm(ZrF^j1aq8`0QmB=GCgA4Vm^LRWSS}wZn!Qv7rj+M3hP2eL4OmEZ7k;h@tBj z;^%2`niy#)8=(8bQln{=M=?Lh@fGuLs260`2FbE?57lSi`QKLMw#&}Jz QbB48(ZzeH?S<}gPpN*z~u>b%7 delta 1080 zcmc(d&1=+96vfX=UOUrFIx~)1t^F|VsGS*|iCSy@D3vPitke%sH-$7jr zn8Qp*+wOc^P#%>!>&4m?+gmkVZ^fa*UbaHh_IzRbqV5Et-!^Xuf6cMQ^;pX`yD+$m zA=j|hEYr1`b@Q_Cdwv?b8Q0}owkR7)RSv6Fsim_^rAw|A1T!~h%ZAf5!ewEE?Upe9 zfErF;EJ1Mlj_`Zy$A&8*g1c z%$OT03P>SMzfu8x(7H7PooX)_&7Gw)N9q(*aH`sKnuDFyptC+O{d>UHvy z3xha7m0<|Oa3i;09In1~1) z^l3C&&kmxL5MnVAQNhvQLi}3Ju>`_{L_!TKW+LKv0^)H3g5x9wS1?IKL|bQ=qGy_R Oe~vV#{tV8?-P8|39O4N8 diff --git a/bin/main/com/loki/lochat/listener/ModerationListener.class b/bin/main/com/loki/lochat/listener/ModerationListener.class index 40517d62a69e982be8851b8084e8f09bc56a482b..bd02c1967f156e4150cc611ab153c82a4521e36b 100644 GIT binary patch delta 52 zcmaFEeVc2-QV}r?pMcW5%;JpP)Vz}5)S|M?#!(KmSvnhxt=9{ave*; I;x|mp02B2SWB>pF delta 203 zcmcc3^@e-GQUfCmpXB^p{ha*lOdye*kyxUioL`ixUzD1jSzJ<7sUMtLRF;{X8U*D} z+^NF&Y2v+o^&uIl3c0Bz8Tly+>8T|e&N+$2#Wo>!nhKeD3MD|flFEWq1vJeHnZ*iu z`6UX81qC^o$%#ohsS0WNMPTKLMd_uvsd**E3Q(g0O7k*{GeAO6L+muUI1z%APcXMm Me#>mIIGTwW08_qATmS$7 diff --git a/bin/main/com/loki/lochat/listener/PlayerEventListener.class b/bin/main/com/loki/lochat/listener/PlayerEventListener.class index 68f82381491c77b6722b066b7d2aa888fe4a67b4..8050db1774c0bac5606684e9c5828f7f72c4938b 100644 GIT binary patch delta 111 zcmcaC^-p|52P0FB#>83)U7vuQ#LCp7;MAhB%;Z#SAK%pC;>7gKymYvTUuJSPlrwoD zqxj_KjP^{-4wG{^ls9`bB{5EpXVag2pH*wJF85Q$%2exl0~WMnZ+eVmHNS{MP-@EsXq9b96>?KcGV)Ut(o;(`oO2S3i)}*eG!-)Q6iR?{C6xuK3TP%NWELyr z<(DWV78K-UCMPE4q$;H47lD;07NwWwrskCtD?p73$VseBErJ?gr^&^MBA_t2kJ*>z zZtzVlE>29(%u7dd29nrh8y3G@T8D#QW^y*%`pN6rv?p(1(*omq=9tNAnDsWNv&OJ6 LvTQ!WX~hHpGwP*% diff --git a/src/main/java/com/loki/lochat/LoChat.java b/src/main/java/com/loki/lochat/LoChat.java index b1687e5..d8bc22f 100644 --- a/src/main/java/com/loki/lochat/LoChat.java +++ b/src/main/java/com/loki/lochat/LoChat.java @@ -1,5 +1,9 @@ package com.loki.lochat; +import com.loki.lochat.api.service.MessageService; +import com.loki.lochat.api.service.MessagingService; +import com.loki.lochat.api.service.NickService; +import com.loki.lochat.api.service.PlayerService; import com.loki.lochat.api.service.PunishmentService; import com.loki.lochat.commands.CommandManager; import com.loki.lochat.config.ConfigManager; @@ -65,7 +69,12 @@ public final class LoChat extends JavaPlugin { // Команды и слушатели commandManager = new CommandManager(this); commandManager.registerCommands(); - initializer.registerListeners(serviceRegistry, discordIntegration); + initializer.registerListeners(serviceRegistry, discordIntegration, + serviceRegistry.get(MessageService.class), + serviceRegistry.get(PlayerService.class), + serviceRegistry.get(MessagingService.class), + serviceRegistry.get(NickService.class), + serviceRegistry.get(PunishmentService.class)); initializer.registerPluginChannels(); // Автосообщения diff --git a/src/main/java/com/loki/lochat/core/PluginInitializer.java b/src/main/java/com/loki/lochat/core/PluginInitializer.java index 7e77964..24ab0d8 100644 --- a/src/main/java/com/loki/lochat/core/PluginInitializer.java +++ b/src/main/java/com/loki/lochat/core/PluginInitializer.java @@ -1,6 +1,11 @@ package com.loki.lochat.core; import com.loki.lochat.LoChat; +import com.loki.lochat.api.service.MessageService; +import com.loki.lochat.api.service.MessagingService; +import com.loki.lochat.api.service.NickService; +import com.loki.lochat.api.service.PlayerService; +import com.loki.lochat.api.service.PunishmentService; import com.loki.lochat.config.ConfigManager; import com.loki.lochat.config.MessageConfig; import com.loki.lochat.core.filter.AdvancedMessageFilter; @@ -96,18 +101,20 @@ public class PluginInitializer { /** * Зарегистрировать слушатели событий */ - public AdvancedMessageFilter registerListeners(ServiceRegistry serviceRegistry, DiscordIntegration discordIntegration) { - // Создаём один экземпляр фильтра и передаём в оба листенера + public AdvancedMessageFilter registerListeners(ServiceRegistry serviceRegistry, DiscordIntegration discordIntegration, + MessageService messageService, PlayerService playerService, + MessagingService messagingService, NickService nickService, + PunishmentService punishmentService) { AdvancedMessageFilter filter = new AdvancedMessageFilter(plugin.getConfig(), plugin); - + plugin.getServer().getPluginManager().registerEvents( - new ChatEventListener(plugin, serviceRegistry, filter), plugin + new ChatEventListener(plugin, messageService, playerService, filter), plugin ); plugin.getServer().getPluginManager().registerEvents( - new PlayerEventListener(plugin, serviceRegistry, filter), plugin + new PlayerEventListener(plugin, playerService, messagingService, nickService, filter), plugin ); plugin.getServer().getPluginManager().registerEvents( - new ModerationListener(serviceRegistry), plugin + new ModerationListener(punishmentService), plugin ); // Discord listener diff --git a/src/main/java/com/loki/lochat/core/registry/ServiceRegistry.java b/src/main/java/com/loki/lochat/core/registry/ServiceRegistry.java index 6cd5fc7..d0cb829 100644 --- a/src/main/java/com/loki/lochat/core/registry/ServiceRegistry.java +++ b/src/main/java/com/loki/lochat/core/registry/ServiceRegistry.java @@ -41,16 +41,15 @@ public class ServiceRegistry { } private void registerServicesWithDeps(ConfigManager configManager, MessageConfig messageConfig) { - register(ChatService.class, new ChatServiceImpl(plugin, this)); - register(MuteService.class, ServiceFactory.createMuteService(plugin)); + MuteService muteService = ServiceFactory.createMuteService(plugin); + register(MuteService.class, muteService); - // ✅ NEW: Объединённый PlayerService (Cooldown + PlayerData) PlayerService playerService = new PlayerServiceImpl(plugin); register(PlayerService.class, playerService); - register(MessageService.class, new MessageServiceImpl(plugin, this)); + register(ChatService.class, new ChatServiceImpl(plugin)); + register(MessageService.class, new MessageServiceImpl(plugin, muteService, playerService)); - // ✅ NEW: Объединённый MessagingService (PM + Spy + Ignore) через фабрику PrivateMessageServiceImpl pmService = new PrivateMessageServiceImpl((LoChat) plugin); MessagingService messagingService = ServiceFactory.createMessagingService(plugin, messageConfig, pmService); pmService.init(messagingService); diff --git a/src/main/java/com/loki/lochat/core/service/ChatServiceImpl.java b/src/main/java/com/loki/lochat/core/service/ChatServiceImpl.java index 1cf050a..42ebbd0 100644 --- a/src/main/java/com/loki/lochat/core/service/ChatServiceImpl.java +++ b/src/main/java/com/loki/lochat/core/service/ChatServiceImpl.java @@ -1,7 +1,6 @@ package com.loki.lochat.core.service; import com.loki.lochat.api.service.ChatService; -import com.loki.lochat.core.registry.ServiceRegistry; import com.loki.lochat.renderer.EnhancedChatRenderer; import com.loki.lochat.utils.format.ChatFormatter; import com.loki.lochat.utils.persistence.FilePersistence; @@ -29,7 +28,7 @@ public class ChatServiceImpl implements ChatService { private final JavaPlugin plugin; private final Set globalChatDisabled = ConcurrentHashMap.newKeySet(); - public ChatServiceImpl(JavaPlugin plugin, ServiceRegistry registry) { + public ChatServiceImpl(JavaPlugin plugin) { this.plugin = plugin; loadDisabled(); } diff --git a/src/main/java/com/loki/lochat/core/service/MessageServiceImpl.java b/src/main/java/com/loki/lochat/core/service/MessageServiceImpl.java index 98b06d6..bac7afa 100644 --- a/src/main/java/com/loki/lochat/core/service/MessageServiceImpl.java +++ b/src/main/java/com/loki/lochat/core/service/MessageServiceImpl.java @@ -6,7 +6,6 @@ import com.loki.lochat.api.service.MuteService; import com.loki.lochat.api.service.PlayerService; import com.loki.lochat.core.filter.CooldownFilter; import com.loki.lochat.core.filter.MuteFilter; -import com.loki.lochat.core.registry.ServiceRegistry; import com.loki.lochat.data.model.ChatMessage; import org.bukkit.entity.Player; @@ -21,13 +20,10 @@ import java.util.List; public class MessageServiceImpl implements MessageService { private final List filters; - public MessageServiceImpl(JavaPlugin plugin, ServiceRegistry registry) { + public MessageServiceImpl(JavaPlugin plugin, MuteService muteService, PlayerService playerService) { this.filters = new ArrayList<>(); - - // Регистрируем фильтры в порядке применения - // MuteFilter теперь получает plugin для доступа к HardcodedMessages - filters.add(new MuteFilter(registry.get(MuteService.class), plugin)); - filters.add(new CooldownFilter(registry.get(PlayerService.class), plugin)); + filters.add(new MuteFilter(muteService, plugin)); + filters.add(new CooldownFilter(playerService, plugin)); } @Override diff --git a/src/main/java/com/loki/lochat/listener/ChatEventListener.java b/src/main/java/com/loki/lochat/listener/ChatEventListener.java index 6c0834c..23e4483 100644 --- a/src/main/java/com/loki/lochat/listener/ChatEventListener.java +++ b/src/main/java/com/loki/lochat/listener/ChatEventListener.java @@ -2,9 +2,9 @@ package com.loki.lochat.listener; import com.loki.lochat.LoChat; import com.loki.lochat.api.service.MessageService; +import com.loki.lochat.api.service.PlayerService; import com.loki.lochat.core.filter.AdvancedMessageFilter; import com.loki.lochat.core.filter.FilterResult; -import com.loki.lochat.core.registry.ServiceRegistry; import com.loki.lochat.renderer.EnhancedChatRenderer; import com.loki.lochat.utils.format.ChatFormatter; @@ -22,11 +22,14 @@ import io.papermc.paper.event.player.AsyncChatEvent; public class ChatEventListener implements Listener { private final JavaPlugin plugin; private final MessageService messageService; + private final PlayerService playerService; private final AdvancedMessageFilter advancedFilter; - public ChatEventListener(JavaPlugin plugin, ServiceRegistry registry, com.loki.lochat.core.filter.AdvancedMessageFilter filter) { + public ChatEventListener(JavaPlugin plugin, MessageService messageService, PlayerService playerService, + AdvancedMessageFilter filter) { this.plugin = plugin; - this.messageService = registry.get(MessageService.class); + this.messageService = messageService; + this.playerService = playerService; this.advancedFilter = filter; } @@ -148,8 +151,6 @@ public class ChatEventListener implements Listener { } private void recordStatistics(LoChat loChat, Player sender, boolean isGlobal) { - com.loki.lochat.api.service.PlayerService playerService = - loChat.getServiceRegistry().get(com.loki.lochat.api.service.PlayerService.class); playerService.recordMessage(sender.getUniqueId(), isGlobal ? "global" : "local"); } diff --git a/src/main/java/com/loki/lochat/listener/ModerationListener.java b/src/main/java/com/loki/lochat/listener/ModerationListener.java index 639385d..9bd513b 100644 --- a/src/main/java/com/loki/lochat/listener/ModerationListener.java +++ b/src/main/java/com/loki/lochat/listener/ModerationListener.java @@ -1,7 +1,6 @@ package com.loki.lochat.listener; import com.loki.lochat.api.service.PunishmentService; -import com.loki.lochat.core.registry.ServiceRegistry; import com.loki.lochat.data.model.BanRecord; import org.bukkit.event.EventHandler; @@ -16,8 +15,8 @@ public class ModerationListener implements Listener { private final PunishmentService punishmentService; - public ModerationListener(ServiceRegistry registry) { - this.punishmentService = registry.get(PunishmentService.class); + public ModerationListener(PunishmentService punishmentService) { + this.punishmentService = punishmentService; } @EventHandler(priority = EventPriority.LOWEST) diff --git a/src/main/java/com/loki/lochat/listener/PlayerEventListener.java b/src/main/java/com/loki/lochat/listener/PlayerEventListener.java index 9fb6d24..8e96066 100644 --- a/src/main/java/com/loki/lochat/listener/PlayerEventListener.java +++ b/src/main/java/com/loki/lochat/listener/PlayerEventListener.java @@ -6,7 +6,6 @@ import com.loki.lochat.api.service.NickService; import com.loki.lochat.api.service.PlayerService; import com.loki.lochat.config.ConfigManager; import com.loki.lochat.core.filter.AdvancedMessageFilter; -import com.loki.lochat.core.registry.ServiceRegistry; import com.loki.lochat.utils.format.ChatFormatter; import net.kyori.adventure.text.Component; @@ -32,11 +31,12 @@ public class PlayerEventListener implements Listener { private final AdvancedMessageFilter advancedFilter; private final ConfigManager configManager; - public PlayerEventListener(LoChat plugin, ServiceRegistry registry, AdvancedMessageFilter advancedFilter) { + public PlayerEventListener(LoChat plugin, PlayerService playerService, MessagingService messagingService, + NickService nickService, AdvancedMessageFilter advancedFilter) { this.plugin = plugin; - this.playerService = registry.get(PlayerService.class); - this.messagingService = registry.get(MessagingService.class); - this.nickService = registry.get(NickService.class); + this.playerService = playerService; + this.messagingService = messagingService; + this.nickService = nickService; this.advancedFilter = advancedFilter; this.configManager = plugin.getConfigManager(); }