Skip to content

Commit

Permalink
Fixed code smells.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Feb 3, 2020
1 parent 4a33603 commit dbf3a6a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public boolean execute(User user, String label, List<String> args) {

// Send the message directly into island chat without the need of toggling it
// if there is existence of more arguments
if (args.size() > 0) {
if (!args.isEmpty()) {
addon.getListener().islandChat(island, user.getPlayer(), String.join(" ", args));
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean execute(User user, String label, List<String> args) {

// Send the message directly into team chat without the need of toggling it
// if there is existence of more arguments
if (args.size() > 0) {
if (!args.isEmpty()) {
addon.getListener().teamChat(user.getPlayer(), String.join(" ", args));
return true;
}
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/world/bentobox/chat/listeners/ChatListener.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package world.bentobox.chat.listeners;

import java.util.*;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.World;
Expand All @@ -24,6 +28,7 @@
*/
public class ChatListener implements Listener {

private static final String MESSAGE = "[message]";
private final Chat addon;
private final Set<UUID> teamChatUsers;
private final Map<Island, Set<Player>> islands;
Expand Down Expand Up @@ -91,7 +96,7 @@ public void islandChat(Island i, Player player, String message) {
Bukkit.getOnlinePlayers().stream().map(User::getInstance)
.filter(u -> i.onIsland(u.getLocation()))
// Send message to island
.forEach(u -> u.sendMessage("chat.island-chat.syntax", TextVariables.NAME, player.getName(), "[message]", message));
.forEach(u -> u.sendMessage("chat.island-chat.syntax", TextVariables.NAME, player.getName(), MESSAGE, message));
// Log if required
if (addon.getSettings().isLogTeamChats()) {
addon.log("[Team Chat Log] " + player.getName() + ": " + message);
Expand All @@ -100,7 +105,7 @@ public void islandChat(Island i, Player player, String message) {
Bukkit.getOnlinePlayers().stream()
.filter(p -> islandSpies.contains(p.getUniqueId()))
.map(User::getInstance)
.forEach(a -> a.sendMessage("chat.island-chat.spy.syntax", TextVariables.NAME, player.getName(), "[message]", message));
.forEach(a -> a.sendMessage("chat.island-chat.spy.syntax", TextVariables.NAME, player.getName(), MESSAGE, message));
}

public void teamChat(final Player player, String message) {
Expand All @@ -111,7 +116,7 @@ public void teamChat(final Player player, String message) {
// Filter for online only
.filter(User::isOnline)
// Send the message to them
.forEach(target -> target.sendMessage("chat.team-chat.syntax", TextVariables.NAME, player.getName(), "[message]", message));
.forEach(target -> target.sendMessage("chat.team-chat.syntax", TextVariables.NAME, player.getName(), MESSAGE, message));
// Log if required
if (addon.getSettings().isLogTeamChats()) {
addon.log("[Team Chat Log] " + player.getName() + ": " + message);
Expand All @@ -120,7 +125,7 @@ public void teamChat(final Player player, String message) {
Bukkit.getOnlinePlayers().stream()
.filter(p -> spies.contains(p.getUniqueId()))
.map(User::getInstance)
.forEach(u -> u.sendMessage("chat.team-chat.spy.syntax", TextVariables.NAME, player.getName(), "[message]", message));
.forEach(u -> u.sendMessage("chat.team-chat.spy.syntax", TextVariables.NAME, player.getName(), MESSAGE, message));
}

/**
Expand Down

0 comments on commit dbf3a6a

Please sign in to comment.