Skip to content

Commit

Permalink
Feature/#125 enhance parse moderator event to include player names (#134
Browse files Browse the repository at this point in the history
)

* Add player name to parseModeratorEvent

Changes include renaming 'fromInt' to 'fromArmy', setting default values for player names, and player name retrieval from 'armies' object'.

* Set string variables to default null

* Change default value from -1 to -2 for activeCommandSource and fromArmy

* Change default values from int magic number to Integer null, added null check for army related to playerNameFromCommandSource
  • Loading branch information
magge-faf authored May 2, 2024
1 parent 6bd20e6 commit e904344
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import java.time.Duration;

public record ModeratorEvent(Duration time, String sender, String message, int activeCommandSource) {

public record ModeratorEvent(Duration time,
int activeCommandSource,
int fromArmy,
String message,
String playerNameFromArmy,
String playerNameFromCommandSource) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -379,21 +379,39 @@ private void parseGiveResourcesToPlayer(Map<String, Object> lua) {


void parseModeratorEvent(Map<String, Object> lua, Integer player) {
String messageContent = "Content of Message Missing";
int fromInt = -1; // Default Value
int activeCommandSource = -1; // Default Value
String messageContent = null;
String playerNameFromArmy = null;
String playerNameFromCommandSource = null;
Integer activeCommandSource = null;
Integer fromArmy = null;

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();
fromArmy = value.intValue() - 1;

if (fromArmy != -2) {
Map<String, Object> army = armies.get(fromArmy);

if (army != null){
playerNameFromArmy = (String) army.get("PlayerName");
}
}
}

if (player != null) {
activeCommandSource = player;
Map<String, Object> army = armies.get(activeCommandSource);

if (army != null) {
playerNameFromCommandSource = (String) army.get("PlayerName");
}
}

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

private Duration tickToTime(int tick) {
Expand Down

0 comments on commit e904344

Please sign in to comment.