diff --git a/Mage.Client/src/main/java/mage/client/chat/LocalCommands.java b/Mage.Client/src/main/java/mage/client/chat/LocalCommands.java index 2fd0878f8f..18cc0a65a0 100644 --- a/Mage.Client/src/main/java/mage/client/chat/LocalCommands.java +++ b/Mage.Client/src/main/java/mage/client/chat/LocalCommands.java @@ -7,18 +7,25 @@ import mage.interfaces.callback.ClientCallback; import mage.interfaces.callback.ClientCallbackMethod; import mage.view.ChatMessage; -import java.util.Date; -import java.util.Optional; -import java.util.StringTokenizer; -import java.util.UUID; +import java.util.*; public final class LocalCommands { - private LocalCommands(){} + private LocalCommands() { + } + + private static String getRemainingTokens(StringTokenizer st) { + List list = new ArrayList<>(); + while (st.hasMoreTokens()) { + list.add(st.nextToken()); + } + return String.join(" ", list); + } /** * Handler for commands that do not require server interaction, i.e settings etc + * * @param chatId * @param text * @return true if the command was handled locally, else false @@ -33,15 +40,16 @@ public final class LocalCommands { final String serverAddress = SessionHandler.getSession().getServerHostname().orElseGet(() -> ""); Optional response = Optional.empty(); - switch (st.nextToken()) { + String command = st.nextToken(); + switch (command) { case "/ignore": case "\\ignore": - final String ignoreTarget = tokens > 1 ? st.nextToken() : ""; + final String ignoreTarget = getRemainingTokens(st); response = Optional.of(IgnoreList.ignore(serverAddress, ignoreTarget)); break; case "/unignore": case "\\unignore": - final String unignoreTarget = tokens > 1 ? st.nextToken() : ""; + final String unignoreTarget = getRemainingTokens(st); response = Optional.of(IgnoreList.unignore(serverAddress, unignoreTarget)); break; // TODO: move profanity settings to here diff --git a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java index 8a253db115..ea34892d98 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java @@ -619,7 +619,7 @@ public class NewTableDialog extends MageDialog { options.setEdhPowerLevel((Integer) this.spnEdhPowerLevel.getValue()); options.setMullgianType((MulliganType) this.cbMulligan.getSelectedItem()); String serverAddress = SessionHandler.getSession().getServerHostname().orElseGet(() -> ""); - options.setBannedUsers(IgnoreList.ignoreList(serverAddress)); + options.setBannedUsers(IgnoreList.getIgnoredUsers(serverAddress)); return options; } diff --git a/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java b/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java index b8bd9e85df..648a13651a 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java @@ -1,11 +1,5 @@ package mage.client.dialog; -import java.awt.*; -import java.io.File; -import java.util.*; -import java.util.List; -import java.util.stream.Collectors; -import javax.swing.*; import mage.cards.decks.Deck; import mage.cards.decks.DeckFileFilter; import mage.cards.decks.importer.DeckImporter; @@ -32,6 +26,13 @@ import mage.view.TableView; import mage.view.TournamentTypeView; import org.apache.log4j.Logger; +import javax.swing.*; +import java.awt.*; +import java.io.File; +import java.util.List; +import java.util.*; +import java.util.stream.Collectors; + /** * @author BetaSteward_at_googlemail.com, JayDi85 */ @@ -1259,7 +1260,7 @@ public class NewTournamentDialog extends MageDialog { } String serverAddress = SessionHandler.getSession().getServerHostname().orElseGet(() -> ""); - tOptions.getMatchOptions().setBannedUsers(IgnoreList.ignoreList(serverAddress)); + tOptions.getMatchOptions().setBannedUsers(IgnoreList.getIgnoredUsers(serverAddress)); tOptions.getMatchOptions().setMatchTimeLimit((MatchTimeLimit) this.cbTimeLimit.getSelectedItem()); tOptions.getMatchOptions().setSkillLevel((SkillLevel) this.cbSkillLevel.getSelectedItem()); diff --git a/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java b/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java index 0d77f46ab1..ff27737cfa 100644 --- a/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java +++ b/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java @@ -451,10 +451,11 @@ public class CallbackClientImpl implements CallbackClient { null, MessageType.USER_INFO, ChatMessage.MessageColor.BLUE); break; case TABLES: - usedPanel.receiveMessage("", new StringBuilder("Download card images by using the \"Images\" menu to the top right .") - .append("
Download icons and symbols by using the \"Symbols\" menu to the top right.") - .append("
\\list - Show a list of available chat commands.") - .append("
").append(IgnoreList.usage()) + String serverAddress = SessionHandler.getSession().getServerHostname().orElseGet(() -> ""); + usedPanel.receiveMessage("", new StringBuilder("Download card images by using the \"Images\" main menu.") + .append("
Download icons and symbols by using the \"Symbols\" main menu.") + .append("
\\list - show a list of available chat commands.") + .append("
").append(IgnoreList.usage(serverAddress)) .append("
Type \\w yourUserName profanity 0 (or 1 or 2) to turn off/on the profanity filter").toString(), null, MessageType.USER_INFO, ChatMessage.MessageColor.BLUE); break; diff --git a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java index 097a738b7e..e7a260cd91 100644 --- a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java +++ b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java @@ -871,7 +871,7 @@ public class TablesPanel extends javax.swing.JPanel { // Hide games of ignored players java.util.List> ignoreListFilterList = new ArrayList<>(); String serverAddress = SessionHandler.getSession().getServerHostname().orElseGet(() -> ""); - final Set ignoreListCopy = IgnoreList.ignoreList(serverAddress); + final Set ignoreListCopy = IgnoreList.getIgnoredUsers(serverAddress); if (!ignoreListCopy.isEmpty()) { ignoreListFilterList.add(new RowFilter() { @Override @@ -1626,7 +1626,7 @@ public class TablesPanel extends javax.swing.JPanel { options.setQuitRatio(100); options.setMinimumRating(0); String serverAddress = SessionHandler.getSession().getServerHostname().orElseGet(() -> ""); - options.setBannedUsers(IgnoreList.ignoreList(serverAddress)); + options.setBannedUsers(IgnoreList.getIgnoredUsers(serverAddress)); table = SessionHandler.createTable(roomId, options); SessionHandler.joinTable(roomId, table.getTableId(), "Human", PlayerType.HUMAN, 1, testDeck, ""); diff --git a/Mage.Client/src/main/java/mage/client/util/IgnoreList.java b/Mage.Client/src/main/java/mage/client/util/IgnoreList.java index 7249cac157..0144e2de23 100644 --- a/Mage.Client/src/main/java/mage/client/util/IgnoreList.java +++ b/Mage.Client/src/main/java/mage/client/util/IgnoreList.java @@ -1,46 +1,51 @@ package mage.client.util; import com.google.common.collect.ImmutableSet; -import java.util.Arrays; -import java.util.Set; import mage.client.MageFrame; import mage.client.preference.MagePreferences; import mage.view.ChatMessage; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; + public final class IgnoreList { - private static final String USAGE = "
\\ignore - shows your ignore list on this server." - + "
\\ignore [username] - add username to ignore list (they won't be able to chat or join to your game)." - + "
\\unignore [username] - remove a username from your ignore list on this server.
"; + private static final String USAGE = "" + + "
\\ignore - shows your ignore list on this server." + + "
\\ignore username - add username to ignore list (they won't be able to chat or join to your new game)." + + "
\\unignore username - remove a username from your ignore list on this server.
"; - public static final int MAX_IGNORE_LIST_SIZE = 50; + public static final int MAX_IGNORE_LIST_SIZE = 100; public static final Set IGNORED_MESSAGE_TYPES = ImmutableSet.of(ChatMessage.MessageType.TALK, - ChatMessage.MessageType.WHISPER_FROM); + ChatMessage.MessageType.WHISPER_FROM); - public static String usage() { - return USAGE; + public static String usage(String serverAddress) { + return "
Your ignored list on server " + serverAddress + ": " + getIgnoredUsers(serverAddress).size() + + USAGE; } - public static Set ignoreList(String serverAddress) { + public static Set getIgnoredUsers(String serverAddress) { return MagePreferences.ignoreList(serverAddress); } - public static String ignoreListString(String serverAddress) { - final String[] list = MagePreferences.ignoreList(serverAddress).toArray(new String[0]); - Arrays.sort(list); - return "Current ignore list on " + serverAddress + ": " - + Arrays.toString(list) + public static String getIgnoreListInfo(String serverAddress) { + List list = new ArrayList<>(getIgnoredUsers(serverAddress)); + Collections.sort(list); + return "Current ignore list on " + serverAddress + " (" + list.size() + "): " + + String.join(", ", list) + ""; } public static String ignore(String serverAddress, String user) { if (user == null || user.isEmpty()) { - return ignoreListString(serverAddress); + return getIgnoreListInfo(serverAddress); } if (MagePreferences.ignoreList(serverAddress).size() >= MAX_IGNORE_LIST_SIZE) { - return "Your ignore list is too big, remove a user to be able to add a new one."; + return "Your ignore list is too big (max " + MAX_IGNORE_LIST_SIZE + "), remove a user to be able to add a new one."; } if (userIsIgnored(serverAddress, user)) { @@ -50,7 +55,7 @@ public final class IgnoreList { MagePreferences.addIgnoredUser(serverAddress, user); updateTablesTable(); - return "Added " + user + " to your ignore list on " + serverAddress; + return "Added " + user + " to your ignore list on " + serverAddress + " (total: " + getIgnoredUsers(serverAddress).size() + ")"; } private static void updateTablesTable() { @@ -62,13 +67,13 @@ public final class IgnoreList { public static String unignore(String serverAddress, String user) { if (user == null || user.isEmpty()) { - return usage(); + return usage(serverAddress); } if (MagePreferences.removeIgnoredUser(serverAddress, user)) { updateTablesTable(); - return "Removed " + user + " from your ignore list on " + serverAddress; + return "Removed " + user + " from your ignore list on " + serverAddress + " (total: " + getIgnoredUsers(serverAddress).size() + ")"; } else { - return "No such user \"" + user + "\" on your ignore list on " + serverAddress; + return "No such user \"" + user + "\" on your ignore list on " + serverAddress + " (total: " + getIgnoredUsers(serverAddress).size() + ")"; } } diff --git a/Mage.Client/src/test/java/mage/client/util/IgnoreListTest.java b/Mage.Client/src/test/java/mage/client/util/IgnoreListTest.java index c4ad2f8b44..d8d184fdbf 100644 --- a/Mage.Client/src/test/java/mage/client/util/IgnoreListTest.java +++ b/Mage.Client/src/test/java/mage/client/util/IgnoreListTest.java @@ -23,14 +23,14 @@ public class IgnoreListTest { @Test public void ignoreListEmpty() throws Exception { - assertThat(IgnoreList.ignoreListString("test.com.xx"), is("Current ignore list on test.com.xx: []")); + assertThat(IgnoreList.getIgnoreListInfo("test.com.xx"), is("Current ignore list on test.com.xx: []")); } @Test public void ignoreList() throws Exception { final String test = IgnoreList.ignore("test.com.xx", "test"); final String kranken = IgnoreList.ignore("test.com.xx", "kranken"); - assertThat(IgnoreList.ignoreListString("test.com.xx"), is("Current ignore list on test.com.xx: [kranken, test]")); + assertThat(IgnoreList.getIgnoreListInfo("test.com.xx"), is("Current ignore list on test.com.xx: [kranken, test]")); assertThat(test, is("Added test to your ignore list on test.com.xx")); assertThat(kranken, is("Added kranken to your ignore list on test.com.xx")); } @@ -56,7 +56,7 @@ public class IgnoreListTest { public void ignoreDefaultResponse() throws Exception { final String r1 = IgnoreList.ignore("test.com.xx", ""); final String r2 = IgnoreList.ignore("test.com.xx", null); - assertThat(IgnoreList.ignoreListString("test.com.xx"), is("Current ignore list on test.com.xx: []")); + assertThat(IgnoreList.getIgnoreListInfo("test.com.xx"), is("Current ignore list on test.com.xx: []")); assertEquals(r1, r2); assertEquals(r2, "Current ignore list on test.com.xx: []"); } @@ -68,7 +68,7 @@ public class IgnoreListTest { } final String r = IgnoreList.ignore("test.com.xx", "lul"); assertEquals(r, "Your ignore list is too big, remove a user to be able to add a new one."); - assertThat(IgnoreList.ignoreListString("test.com.xx"), is("Current ignore list on test.com.xx: [0, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 3, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 4, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 5, 6, 7, 8, 9]")); + assertThat(IgnoreList.getIgnoreListInfo("test.com.xx"), is("Current ignore list on test.com.xx: [0, 1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 3, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 4, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 5, 6, 7, 8, 9]")); } @Test