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 ability for notifications to only go to accepters. #3560

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,18 @@ private void activateTriggers(final UserActionAttachment uaa) {
private void notifySuccess(final UserActionAttachment uaa) {
// play a sound
getSoundChannel().playSoundForAll(SoundPath.CLIP_USER_ACTION_SUCCESSFUL, player);
sendNotification(UserActionText.getInstance().getNotificationSucccess(uaa.getText()));
notifyOtherPlayers(UserActionText.getInstance().getNotificationSuccessOthers(uaa.getText()));
final UserActionText uat = UserActionText.getInstance();
sendNotification(uat.getNotificationSucccess(uaa.getText()));
notifyOtherPlayers(uat.getNotificationSuccessOthers(uaa.getText()), getOtherNotificationPlayers(uaa));
}

private Collection<PlayerID> getOtherNotificationPlayers(final UserActionAttachment uaa) {
if (UserActionText.getInstance().shouldNotifyAcceptersOnly()) {
return uaa.getActionAccept();
}
final Collection<PlayerID> otherPlayers = getData().getPlayerList().getPlayers();
otherPlayers.remove(player);
return otherPlayers;
}

/**
Expand All @@ -219,13 +229,10 @@ private void sendNotification(final String text) {
* Send a notification to the other players involved in this action (all
* players except the player starting the action).
*/
private void notifyOtherPlayers(final String notification) {
private void notifyOtherPlayers(final String notification, final Collection<PlayerID> otherPlayers) {
if (!"NONE".equals(notification)) {
// we can send it to just uaa.getOtherPlayers(), or we can send it to all players. both are good options.
final Collection<PlayerID> currentPlayer = new ArrayList<>();
currentPlayer.add(player);
final Collection<PlayerID> otherPlayers = getData().getPlayerList().getPlayers();
otherPlayers.removeAll(currentPlayer);
this.getDisplay().reportMessageToPlayers(otherPlayers, currentPlayer, notification, notification);
}
}
Expand All @@ -242,8 +249,9 @@ private void notifyFailure(final UserActionAttachment uaa) {
final String transcriptText =
bridge.getPlayerId().getName() + " fails on action: " + MyFormatter.attachmentNameToText(uaa.getName());
bridge.getHistoryWriter().addChildToEvent(transcriptText);
sendNotification(UserActionText.getInstance().getNotificationFailure(uaa.getText()));
notifyOtherPlayers(UserActionText.getInstance().getNotificationFailureOthers(uaa.getText()));
final UserActionText uat = UserActionText.getInstance();
sendNotification(uat.getNotificationFailure(uaa.getText()));
notifyOtherPlayers(uat.getNotificationFailureOthers(uaa.getText()), getOtherNotificationPlayers(uaa));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class UserActionText {
private static final String NOTIFICATION_FAILURE = "NOTIFICATION_FAILURE";
private static final String OTHER_NOTIFICATION_FAILURE = "OTHER_NOTIFICATION_FAILURE";
private static final String ACCEPT_QUESTION = "ACCEPT_QUESTION";
private static final String OTHER_NOTIFICATIONS_GO_TO_ACCEPTERS_ONLY = "OTHER_NOTIFICATIONS_GO_TO_ACCEPTERS_ONLY";

protected UserActionText() {
final ResourceLoader loader = AbstractUiContext.getResourceLoader();
Expand Down Expand Up @@ -86,4 +87,8 @@ public String getNotificationFailureOthers(final String actionKey) {
public String getAcceptanceQuestion(final String actionKey) {
return getMessage(actionKey, ACCEPT_QUESTION);
}

public boolean shouldNotifyAcceptersOnly() {
return "true".equalsIgnoreCase(properties.getProperty(OTHER_NOTIFICATIONS_GO_TO_ACCEPTERS_ONLY));
}
}