Skip to content

Commit 4bfab99

Browse files
committed
Fixed problem with last action list deserialization when data returned
from the game server doesn't contain any valid action.
1 parent 7c344c6 commit 4bfab99

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ocraft-s2client-protocol/src/main/java/com/github/ocraft/s2client/protocol/response/ResponseObservation.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import java.util.Collections;
3939
import java.util.List;
40+
import java.util.function.Predicate;
4041

4142
import static com.github.ocraft.s2client.protocol.DataExtractor.tryGet;
4243
import static com.github.ocraft.s2client.protocol.Errors.required;
@@ -58,7 +59,7 @@ private ResponseObservation(Sc2Api.ResponseObservation sc2ApiResponseObservation
5859
super(ResponseType.OBSERVATION, GameStatus.from(status));
5960

6061
this.actions = sc2ApiResponseObservation.getActionsList().stream()
61-
.filter(a -> a.getSerializedSize() > 0).map(Action::from)
62+
.filter(actionIsValid()).map(Action::from)
6263
.collect(collectingAndThen(toList(), Collections::unmodifiableList));
6364

6465
this.actionErrors = sc2ApiResponseObservation.getActionErrorsList().stream()
@@ -74,6 +75,15 @@ private ResponseObservation(Sc2Api.ResponseObservation sc2ApiResponseObservation
7475
.collect(collectingAndThen(toList(), Collections::unmodifiableList));
7576
}
7677

78+
private Predicate<Sc2Api.Action> actionIsValid() {
79+
return a -> a.getSerializedSize() > 0 && (
80+
a.hasActionRaw() ||
81+
a.hasActionChat() ||
82+
a.hasActionFeatureLayer() ||
83+
a.hasActionRender() ||
84+
a.hasActionUi());
85+
}
86+
7787
public static ResponseObservation from(Sc2Api.Response sc2ApiResponse) {
7888
if (!hasObservationResponse(sc2ApiResponse)) {
7989
throw new IllegalArgumentException("provided argument doesn't have observation response");

0 commit comments

Comments
 (0)