Skip to content

Commit

Permalink
Enhanced robustness of method parseModeratorEvent (#124) (#128)
Browse files Browse the repository at this point in the history
* Enhanced robustness of method parseModeratorEvent (#124)

* Use pattern matching for instanceof
  • Loading branch information
magge-faf authored Apr 13, 2024
1 parent e6b26cb commit 3cda12c
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,23 @@ private void parseGiveResourcesToPlayer(Map<String, Object> lua) {


void parseModeratorEvent(Map<String, Object> lua, Integer player) {
String messageContent = (String) lua.get("Message");
int fromInt = ((Number) lua.get("From")).intValue();
int activeCommandSource = player;
String messageContent = "Content of Message Missing";
int fromInt = -1; // Default Value
int activeCommandSource = -1; // Default Value

if (lua.containsKey("Message") && lua.get("Message") instanceof String value) {
messageContent = value;
}
if (lua.containsKey("From") && lua.get("From") instanceof Number value) {
fromInt = value.intValue();
}
if (player != null) {
activeCommandSource = player;
}

moderatorEvents.add(new ModeratorEvent(tickToTime(ticks), Integer.toString(fromInt), messageContent, activeCommandSource));
}


private Duration tickToTime(int tick) {
return Duration.ofSeconds(tick / 10);
}
Expand Down

0 comments on commit 3cda12c

Please sign in to comment.