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

Add killed player's names to screenshot filenames. #6338

Closed
wants to merge 1 commit into from
Closed
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 @@ -124,9 +124,16 @@ public class ScreenshotPlugin extends Plugin
"You have a funny feeling like you would have been followed");

private static final ImmutableList<String> KILL_MESSAGES = ImmutableList.of("into tiny pieces and sat on them", "you have obliterated",
"falls before your might", "A humiliating defeat for", "With a crushing blow you", "thinking challenging you",
"Can anyone defeat you? Certainly", "was no match for you", "You were clearly a better fighter than", "RIP",
"You have defeated", "What an embarrassing performance by", "was no match for your awesomeness");
"falls before your might", "A humiliating defeat for", "With a crushing blow you finish", "thinking challenging you",
"Can anyone defeat you? Certainly not", "was no match for you", "You were clearly a better fighter than", "RIP",
"You have defeated", "What an embarrassing performance by", "was no match for your awesomeness", "" + "You have defeated",
"didn't stand a chance against you", "will probably tell you", "wanted a free teleport after that performance",
"probably logged out after that beating", "Such a shame that", "can't play this game", "How not to do it right: Written by",
"A certain, crouching-over-face animation would be suitable for", "got rekt", "was made to sit down",
"The struggle for", "MUM! GET THE CAMERA, I JUST KILLED", "should take lessons from you. You're clearly too good for");

private static final ImmutableList<String> KILL_MESSAGE_TRIM = ImmutableList.of("him", "her", "he", "she", "is real",
"right now.", "What was", ".", "?", ",");

static String format(Date date)
{
Expand Down Expand Up @@ -351,7 +358,8 @@ public void onChatMessage(ChatMessage event)

if (config.screenshotKills() && KILL_MESSAGES.stream().anyMatch(chatMessage::contains))
{
String fileName = "Kill " + format(new Date());
String killedPlayer = killedPlayerName(chatMessage);
String fileName = "Kill " + killedPlayer + " " + format(new Date());
takeScreenshot(fileName);
}

Expand Down Expand Up @@ -643,6 +651,33 @@ public void onResponse(Call call, Response response) throws IOException
});
}

/**
* Extracts the name of the player the user killed in a PvP environment and returns it as a string.
* Specifically, this is necessary to add the player's name to the file name.
*
* @param chatMessage Message to parse for killed player's name
* @return String This returns the killed player's name
*/
private String killedPlayerName(String chatMessage)
{
for (String killMessage:KILL_MESSAGES)
{
while (chatMessage.contains(killMessage))
{
chatMessage = chatMessage.replace(killMessage, "");
}
}
for (String killMessageTrim:KILL_MESSAGE_TRIM)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this won't work if the player's name contains any of these strings

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, jumped the gun on this one thinking I had a solid solution. I'll give it another look over in the morning to fix that.

{
while (chatMessage.contains(killMessageTrim))
{
chatMessage = chatMessage.replace(killMessageTrim, "");
}
}
chatMessage = chatMessage.trim();
return chatMessage;
}

@VisibleForTesting
int getClueNumber()
{
Expand Down