11package sc .networking .clients ;
22
3+ import org .jetbrains .annotations .NotNull ;
4+ import org .jetbrains .annotations .Nullable ;
35import org .slf4j .Logger ;
46import org .slf4j .LoggerFactory ;
57import sc .api .plugins .IGameState ;
@@ -50,16 +52,16 @@ private static INetworkInterface createTcpNetwork(String host, int port) throws
5052 }
5153
5254 @ Override
53- protected final void onObject (ProtocolMessage o ) {
54- if (o == null ) {
55+ protected final void onObject (ProtocolMessage message ) {
56+ if (message == null ) {
5557 logger .warn ("Received null message." );
5658 return ;
5759 }
5860
59- invokeHandlers (o );
61+ invokeHandlers (message );
6062
61- if (o instanceof RoomPacket ) {
62- RoomPacket packet = (RoomPacket ) o ;
63+ if (message instanceof RoomPacket ) {
64+ RoomPacket packet = (RoomPacket ) message ;
6365 String roomId = packet .getRoomId ();
6466 ProtocolMessage data = packet .getData ();
6567 if (data instanceof MementoEvent ) {
@@ -73,24 +75,24 @@ protected final void onObject(ProtocolMessage o) {
7375 } else {
7476 onRoomMessage (roomId , data );
7577 }
76- } else if (o instanceof GamePreparedResponse ) {
77- onGamePrepared ((GamePreparedResponse ) o );
78- } else if (o instanceof JoinedRoomResponse ) {
79- onGameJoined (((JoinedRoomResponse ) o ).getRoomId ());
80- } else if (o instanceof RoomWasJoinedEvent ) {
81- onGameJoined (((RoomWasJoinedEvent ) o ).getRoomId ());
82- } else if (o instanceof LeftGameEvent ) {
83- onGameLeft (((LeftGameEvent ) o ).getRoomId ());
84- } else if (o instanceof ObservationResponse ) {
85- onGameObserved (((ObservationResponse ) o ).getRoomId ());
86- } else if (o instanceof TestModeResponse ) {
87- boolean testMode = (((TestModeResponse ) o ).getTestMode ());
78+ } else if (message instanceof GamePreparedResponse ) {
79+ onGamePrepared ((GamePreparedResponse ) message );
80+ } else if (message instanceof JoinedRoomResponse ) {
81+ onGameJoined (((JoinedRoomResponse ) message ).getRoomId ());
82+ } else if (message instanceof RoomWasJoinedEvent ) {
83+ onGameJoined (((RoomWasJoinedEvent ) message ).getRoomId ());
84+ } else if (message instanceof LeftGameEvent ) {
85+ onGameLeft (((LeftGameEvent ) message ).getRoomId ());
86+ } else if (message instanceof ObservationResponse ) {
87+ onGameObserved (((ObservationResponse ) message ).getRoomId ());
88+ } else if (message instanceof TestModeResponse ) {
89+ boolean testMode = (((TestModeResponse ) message ).getTestMode ());
8890 logger .info ("TestMode was set to {} " , testMode );
89- } else if (o instanceof ProtocolErrorMessage ) {
90- ProtocolErrorMessage response = (ProtocolErrorMessage ) o ;
91+ } else if (message instanceof ProtocolErrorMessage ) {
92+ ProtocolErrorMessage response = (ProtocolErrorMessage ) message ;
9193 onError (null , response );
9294 } else {
93- onCustomObject (o );
95+ onCustomObject (message );
9496 }
9597 }
9698
@@ -135,11 +137,8 @@ private void onGameObserved(String roomId) {
135137 }
136138 }
137139
138- private void invokeHandlers (ProtocolMessage o ) {
139- if (o == null ) {
140- throw new IllegalArgumentException ("o was null" );
141- }
142- this .asyncManager .invokeHandlers (o );
140+ private void invokeHandlers (@ NotNull ProtocolMessage message ) {
141+ this .asyncManager .invokeHandlers (message );
143142 }
144143
145144 protected void onGamePrepared (GamePreparedResponse response ) {
@@ -195,7 +194,7 @@ protected void onRoomMessage(String roomId, ProtocolMessage data) {
195194 }
196195 }
197196
198- protected void onError (String roomId , ProtocolErrorMessage error ) {
197+ protected void onError (@ Nullable String roomId , @ NotNull ProtocolErrorMessage error ) {
199198 logger .warn ("{} (room: {})" , error .getLogMessage (), roomId );
200199 for (ILobbyClientListener listener : this .listeners ) {
201200 listener .onError (roomId , error );
0 commit comments