Skip to content

Commit

Permalink
Add player name to parseModeratorEvent
Browse files Browse the repository at this point in the history
Changes include renaming 'fromInt' to 'fromArmy', setting default values for player names, and player name retrieval from 'armies' object'.
  • Loading branch information
magge-faf committed Apr 13, 2024
1 parent f33997d commit bc3b94d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
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) {
}
Expand Up @@ -380,20 +380,35 @@ 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
String playerNameFromArmy = "Player Name Army Missing";
String playerNameFromCommandSource = "Player Name Command Source Missing";
int activeCommandSource = -1; // Default Value
int fromArmy = -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();
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);
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 bc3b94d

Please sign in to comment.