Skip to content

Commit 59eafa1

Browse files
RogerstalkerBrutus5000
authored andcommitted
Removed unnecessary null checks from parseGiveResourcesToPlayer
1 parent d199104 commit 59eafa1

1 file changed

Lines changed: 33 additions & 39 deletions

File tree

data/src/main/java/com/faforever/commons/replay/ReplayDataParser.java

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -359,42 +359,36 @@ private void interpretEvents(List<Event> events) {
359359
}
360360

361361
private void parseGiveResourcesToPlayer(LuaData.Table lua) {
362-
LuaData msg;
363-
LuaData from;
364-
LuaData sender;
365-
if ((msg = lua.value().get("Msg")) != null && (from = lua.value().get("From")) != null && (sender = lua.value().get("Sender")) != null) {
366-
367-
// TODO: use the command source (player value) instead of the values from the callback. The values from the callback can be manipulated
368-
if (!(from instanceof LuaData.Number(float luaFromArmy))) {
369-
return;
370-
}
362+
// TODO: use the command source (player value) instead of the values from the callback. The values from the callback can be manipulated
363+
if (!(lua.value().get("From") instanceof LuaData.Number(float luaFromArmy))) {
364+
return;
365+
}
371366

372-
int fromArmy = (int) luaFromArmy - 1;
373-
if (fromArmy == -2) {
374-
return;
375-
}
367+
int fromArmy = (int) luaFromArmy - 1;
368+
if (fromArmy == -2) {
369+
return;
370+
}
376371

377-
if (!(msg instanceof LuaData.Table(Map<String, LuaData> luaMsg))) {
378-
return;
379-
}
372+
if (!(lua.value().get("Msg") instanceof LuaData.Table(Map<String, LuaData> luaMsg))) {
373+
return;
374+
}
380375

381-
if (!(sender instanceof LuaData.String(String luaSender))) {
382-
return;
383-
}
376+
if (!(lua.value().get("Sender") instanceof LuaData.String(String luaSender))) {
377+
return;
378+
}
384379

385-
// This can either be a player name or a Map of something, in which case it's actually giving resources
386-
if (!(luaMsg.get("to") instanceof LuaData.String(String luaMsgReceiver))) {
387-
return;
388-
}
380+
// This can either be a player name or a Map of something, in which case it's actually giving resources
381+
if (!(luaMsg.get("to") instanceof LuaData.String(String luaMsgReceiver))) {
382+
return;
383+
}
389384

390-
if (!(luaMsg.get("text") instanceof LuaData.String(String luaMsgText))) {
391-
return;
392-
}
385+
if (!(luaMsg.get("text") instanceof LuaData.String(String luaMsgText))) {
386+
return;
387+
}
393388

394-
Map<String, Object> army = armies.get(fromArmy);
395-
if (army != null && Objects.equals(army.get("PlayerName"), luaSender)) {
396-
chatMessages.add(new ChatMessage(tickToTime(ticks), luaSender, String.valueOf(luaMsgReceiver), luaMsgText));
397-
}
389+
Map<String, Object> army = armies.get(fromArmy);
390+
if (army != null && Objects.equals(army.get("PlayerName"), luaSender)) {
391+
chatMessages.add(new ChatMessage(tickToTime(ticks), luaSender, String.valueOf(luaMsgReceiver), luaMsgText));
398392
}
399393
}
400394

@@ -440,18 +434,18 @@ private Duration tickToTime(int tick) {
440434
}
441435

442436
private void parse() throws IOException, CompressorException {
443-
readReplayData(path);
437+
readReplayData(path);
444438

445-
final ByteBuffer buffer = ByteBuffer.wrap(data);
446-
buffer.order(ByteOrder.LITTLE_ENDIAN);
439+
final ByteBuffer buffer = ByteBuffer.wrap(data);
440+
buffer.order(ByteOrder.LITTLE_ENDIAN);
447441

448-
parseHeader(buffer);
442+
parseHeader(buffer);
449443

450-
var rewindPosition = buffer.position();
451-
tokens = ReplayBodyTokenizer.tokenize(buffer);
452-
buffer.position(rewindPosition);
444+
var rewindPosition = buffer.position();
445+
tokens = ReplayBodyTokenizer.tokenize(buffer);
446+
buffer.position(rewindPosition);
453447

454-
events = ReplayBodyParser.parseTokens(tokens, buffer);
455-
interpretEvents(events);
448+
events = ReplayBodyParser.parseTokens(tokens, buffer);
449+
interpretEvents(events);
456450
}
457451
}

0 commit comments

Comments
 (0)