Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/#125 enhance parse moderator event to include player names #134

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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