11/*
2- * DolphinBot - https://github.com/NeonAngelThreads/DolphinBot
3- * Copyright (C) 2025 NeonAngelThreads (https://github.com/NeonAngelThreads)
2+ * DolphinBot - https://github.com/NeonAngelThreads/DolphinBot
3+ * Copyright (C) 2025 NeonAngelThreads (https://github.com/NeonAngelThreads)
44 *
5- * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6- * License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any
7- * later version.
5+ * This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6+ * License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any
7+ * later version.
88 *
9- * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10- * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
11- * License for more details. You should have received a copy of the GNU General Public License along with this
12- * program. If not, see <https://www.gnu.org/licenses/>.
9+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
10+ * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
11+ * License for more details. You should have received a copy of the GNU General Public License along with this
12+ * program. If not, see <https://www.gnu.org/licenses/>.
1313 *
14- * https://space.bilibili.com/386644641
14+ * https://space.bilibili.com/386644641
1515 */
1616
1717package org .angellock .impl ;
1818
1919
2020import com .google .gson .JsonElement ;
2121import lombok .Getter ;
22+ import lombok .Setter ;
2223import org .angellock .impl .commands .CommandSpec ;
2324import org .angellock .impl .events .IConnectListener ;
2425import org .angellock .impl .events .IDisconnectListener ;
25- import org .angellock .impl .events .handlers .ChatCommandHandler ;
26- import org .angellock .impl .events .handlers .KeepAliveHandler ;
27- import org .angellock .impl .events .handlers .PlayerEmergeHandler ;
28- import org .angellock .impl .events .handlers .ServerChatCommandHandler ;
26+ import org .angellock .impl .events .TranslatableBundle ;
27+ import org .angellock .impl .events .handlers .*;
2928import org .angellock .impl .events .packets .EntityMovePacket ;
3029import org .angellock .impl .events .packets .PlayerPositionPacket ;
3130import org .angellock .impl .events .packets .debugger .PacketDebugger ;
4039import org .angellock .impl .plugin .SessionProvider ;
4140import org .angellock .impl .util .ConsoleTokens ;
4241import org .angellock .impl .util .PlainTextSerializer ;
43- import org .angellock .impl .util .math .Position ;
4442import org .geysermc .mcprotocollib .network .BuiltinFlags ;
4543import org .geysermc .mcprotocollib .network .ProxyInfo ;
4644import org .geysermc .mcprotocollib .network .Session ;
@@ -63,18 +61,22 @@ public abstract class AbstractRobot implements ISendable, SessionProvider, IOpti
6361 protected TcpClientSession serverSession ;
6462 protected static final Logger log = LoggerFactory .getLogger (ConsoleTokens .colorizeText ("&aDolphinBot" ));
6563 private final ScheduledExecutorService reconnectScheduler = Executors .newScheduledThreadPool (1 );
64+ @ Getter
6665 protected final PluginManager pluginManager ;
6766 protected MinecraftProtocol minecraftProtocol ;
6867 protected ConfigManager globalConfig ;
6968 protected long connectDuration ;
7069 protected boolean isByPassedVerification = true ;
71- protected GameMode serverGamemode = GameMode .ADVENTURE ;
70+ @ Setter
71+ protected @ Getter GameMode serverGamemode = GameMode .ADVENTURE ;
72+ @ Getter
7273 private ChatMessageManager messageManager ;
74+ @ Getter
7375 private BotManager botManager ;
74- protected Position loginPos = new Position ();
7576 protected ProxyInfo proxyInfo ;
7677 protected @ Getter ProfileObject infoHelper = new ProfileObject ();
7778
79+ @ Getter
7880 protected final TerminalCommandManager commandManager = new TerminalCommandManager ();
7981 protected final CommandSpec commands = new CommandSpec (this );
8082
@@ -128,10 +130,6 @@ public AbstractRobot buildProtocol(){
128130 return this ;
129131 }
130132
131- public TerminalCommandManager getCommandManager () {
132- return commandManager ;
133- }
134-
135133 public DolphinConfig config () {
136134 return this .globalConfig .config ();
137135 }
@@ -140,10 +138,6 @@ public String getPassword(){
140138 return this .infoHelper .getPassword ();
141139 }
142140
143- public ChatMessageManager getMessageManager () {
144- return messageManager ;
145- }
146-
147141 public void connect (){
148142 onPreLogin ();
149143 if (this .proxyInfo != null ) {
@@ -156,21 +150,14 @@ public void connect(){
156150
157151 this .serverSession .addListener ((IConnectListener ) event -> onJoin ());
158152
159- this .serverSession .addListener ((IDisconnectListener ) event -> {
160- PlainTextSerializer serializer = new PlainTextSerializer ();
161- String text = serializer .serialize (event .getReason ());
162- if (text .isBlank ()) {
163- text = (event .getReason ().toString ());
164- }
165- onQuit (text );
166- });
153+ this .serverSession .addListener (new DisconnectReasonHandler (this ));
167154
168155 this .serverSession .addListener (new ServerChatCommandHandler (this .commands ));
169156 this .serverSession .addListener (new ChatCommandHandler (this .commands ));
170157 this .serverSession .addListener (new EntityMovePacket ());
171158 this .serverSession .addListener (new PlayerEmergeHandler ());
172- this .serverSession .addListener (new PlayerPositionPacket (this ));
173- this .serverSession .addListener (new KeepAliveHandler ());
159+ this .serverSession .addListener (new PlayerPositionPacket (( RobotPlayer ) this ));
160+ // this.serverSession.addListener(new KeepAliveHandler());
174161 if (this .config ().getDebugSettings ().isEnablePacketDebug ()) {
175162 this .serverSession .addListener (new PacketDebugger ());
176163 }
@@ -204,20 +191,21 @@ public void connect(){
204191 }
205192 }
206193 catch (InterruptedException e ){
207- this .serverSession .disconnect ("Interrupted" );
208194 throw new RuntimeException (e );
209- } catch (IllegalArgumentException ignore ) {
210- log . warn ( ConsoleTokens . colorizeText ( "&6Unregistered packet error has been triggered!" ) );
195+ } catch (IllegalArgumentException e ) {
196+ TranslatableBundle . warnTranslatableOf ( EnumSystemEvents . PACKET_ERROR , e );
211197 }
212198 }
213199 } finally {
200+ this .serverSession .disconnect ("Interrupted" );
214201 scheduleReconnect ();
215202 }
216203 }
217204
218205 public abstract boolean canSendMessages ();
219206
220207 public void scheduleReconnect () {
208+ TranslatableBundle .infoTranslatableOf (EnumSystemEvents .RECONNECT );
221209 try {
222210 Thread .sleep (this .config ().getReconnectDelay ());
223211 } catch (InterruptedException e ) {
@@ -244,10 +232,6 @@ public Session getSession(){
244232 return this .serverSession ;
245233 }
246234
247- public PluginManager getPluginManager () {
248- return pluginManager ;
249- }
250-
251235 public long getConnectTime () {
252236 return connectDuration ;
253237 }
@@ -265,14 +249,6 @@ public AbstractRobot withProfileName(String name) {
265249 return this ;
266250 }
267251
268- public GameMode getServerGamemode () {
269- return serverGamemode ;
270- }
271-
272- public void setServerGamemode (GameMode serverGamemode ) {
273- this .serverGamemode = serverGamemode ;
274- }
275-
276252 public Map <UUID , Player > getOnlinePlayers () {
277253 return PlayerTracker .getOnlinePlayers ();
278254 }
0 commit comments