Skip to content

Commit

Permalink
Formatting and checkstyle fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DanVanAtta committed Jul 24, 2024
1 parent 77cb980 commit 53424b1
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ public Chat(final ChatTransmitter chatTransmitter) {
}

public void addMessengersListener(IMessageListener messageListener) {
if(chatTransmitter instanceof MessengersChatTransmitter) {
if (chatTransmitter instanceof MessengersChatTransmitter) {
log.info("addming messengers listener");
((MessengersChatTransmitter) chatTransmitter).getMessengers().addMessageListener(messageListener);
((MessengersChatTransmitter) chatTransmitter)
.getMessengers()
.addMessageListener(messageListener);
}
}

Expand Down Expand Up @@ -209,5 +211,4 @@ public void sendBan(UserName userName) {
"sendDisconnect on Chat.java is to support legacy 'messengers' communication only");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public void connectionRemoved(final INode to) {
}
};

public ChatController(final String name, final Messengers messengers, ServerMessenger serverMessenger) {
public ChatController(
final String name, final Messengers messengers, ServerMessenger serverMessenger) {
chatName = name;
this.messengers = messengers;
this.serverMessenger = serverMessenger;
Expand All @@ -69,7 +70,6 @@ public void messageReceived(Serializable msg, INode from) {
.filter(node -> node.getName().equals(newModerator))
.findAny()
.ifPresent(mod -> chatters.put(mod, Tag.MODERATOR));

}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ public ChatMessagePanel(
setChat(chat);

log.info("INIT CHAT MESSAGE PANEL");
chat.addMessengersListener(new IMessageListener() {
@Override
public void messageReceived(Serializable msg, INode from) {
if(msg instanceof ModeratorPromoted) {
addGenericMessage("MODERATOR PROMOTED: " + ((ModeratorPromoted) msg).getPlayerName());
}
}
});
chat.addMessengersListener(
new IMessageListener() {
@Override
public void messageReceived(Serializable msg, INode from) {
if (msg instanceof ModeratorPromoted) {
addGenericMessage("MODERATOR PROMOTED: " + ((ModeratorPromoted) msg).getPlayerName());
}
}
});
}

private void init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,23 @@ public ChatPlayerPanel(final Chat chat) {
layoutComponents();
setupListeners();
setChat(chat);
chat.addMessengersListener(new IMessageListener() {
@Override
public void messageReceived(Serializable msg, INode from) {
if(msg instanceof ModeratorPromoted) {
String newModerator = ((ModeratorPromoted) msg).getPlayerName();
for(int i = 0; i < listModel.getSize(); i ++) {
if(listModel.get(i).getUserName().toString().equals(newModerator)) {
listModel.get(i).setModerator(true);
players.repaint();
break;
chat.addMessengersListener(
new IMessageListener() {
@Override
public void messageReceived(Serializable msg, INode from) {
if (msg instanceof ModeratorPromoted) {
String newModerator = ((ModeratorPromoted) msg).getPlayerName();
for (int i = 0; i < listModel.getSize(); i++) {
if (listModel.get(i).getUserName().toString().equals(newModerator)) {
listModel.get(i).setModerator(true);
players.repaint();
break;
}
}
repaint();
}
}
repaint();
}
}
});
});
}

/** Sets the chat whose players will be displayed in this panel. */
Expand Down Expand Up @@ -176,14 +177,16 @@ public void mouseReleased(final MouseEvent e) {
SwingAction.of(
"Slap " + clickedOn.getUserName(), e -> chat.sendSlap(clickedOn.getUserName()));


// TODO: add check for if we are moderator
final Action disconnect =
SwingAction.of("Disconnect " + clickedOn.getUserName(), e -> chat.sendDisconnect(clickedOn.getUserName()));
SwingAction.of(
"Disconnect " + clickedOn.getUserName(),
e -> chat.sendDisconnect(clickedOn.getUserName()));
// TODO: add check for if we are moderator

final Action ban =
SwingAction.of("Ban " + clickedOn.getUserName(), e -> chat.sendBan(clickedOn.getUserName()));
SwingAction.of(
"Ban " + clickedOn.getUserName(), e -> chat.sendBan(clickedOn.getUserName()));

return List.of(slap, ignore, disconnect, ban);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
@Slf4j
public class MessengersChatTransmitter implements ChatTransmitter {
private final UserName userName;
@Getter
private final Messengers messengers;
@Getter private final Messengers messengers;

private IChatChannel chatChannelSubscriber;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ public class MessageHeader implements Serializable {
@Nullable private final INode from;
private final Serializable message;

/**
* Indicates if the message is intended for everyone (true).
*/
/** Indicates if the message is intended for everyone (true). */
public boolean isBroadcast() {
return to == null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,19 @@ public void banPlayer(final String ip, final String mac) {
miniBannedMacAddresses.add(mac);
}

/** Bans & disconnects a player. */
public void banPlayer(String playerName) {
getNodes().stream()
.filter(n -> n.getName().equals(playerName))
.findAny()
.ifPresent(
nodeToBan -> {
miniBannedIpAddresses.add(nodeToBan.getIpAddress());
miniBannedMacAddresses.add(getPlayerMac(node.getPlayerName()));
removeConnection(nodeToBan);
});
}

private void forward(final MessageHeader msg) {
if (shutdown) {
return;
Expand Down Expand Up @@ -312,19 +325,6 @@ public boolean isServer() {
return true;
}

/** Bans & disconnects a player. */
public void banPlayer(String playerName) {
getNodes().stream()
.filter(n -> n.getName().equals(playerName))
.findAny()
.ifPresent(
nodeToBan -> {
miniBannedIpAddresses.add(nodeToBan.getIpAddress());
miniBannedMacAddresses.add(getPlayerMac(node.getPlayerName()));
removeConnection(nodeToBan);
});
}

public boolean isModerator(INode node) {
return getModerators().stream()
.anyMatch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import games.strategy.engine.message.unifiedmessenger.UnifiedMessenger;
import games.strategy.net.ClientMessenger;
import games.strategy.net.IMessenger;
import games.strategy.net.IServerMessenger;
import games.strategy.net.Messengers;
import games.strategy.net.ServerMessenger;
import games.strategy.net.TestServerMessenger;
Expand Down

0 comments on commit 53424b1

Please sign in to comment.