From c686e4daed85880f68ba85e4227b031caecd4a25 Mon Sep 17 00:00:00 2001 From: md678685 <1917406+md678685@users.noreply.github.com> Date: Sun, 30 Jun 2019 13:12:50 +0100 Subject: [PATCH 01/15] Add /ignore command + prevent PMs to/from ignored players --- .../neutron/api/command/CommandWrapper.java | 6 +++ .../neutron/api/locale/LocaleMessage.java | 6 +++ .../me/crypnotic/neutron/api/user/User.java | 9 ++++ .../manager/user/holder/ConsoleUser.java | 17 ++++++++ .../manager/user/holder/PlayerData.java | 5 +++ .../manager/user/holder/PlayerUser.java | 21 +++++++++ .../module/command/options/IgnoreCommand.java | 43 +++++++++++++++++++ .../command/options/MessageCommand.java | 8 ++++ .../module/command/options/ReplyCommand.java | 10 +++++ 9 files changed, 125 insertions(+) create mode 100644 src/main/java/me/crypnotic/neutron/module/command/options/IgnoreCommand.java diff --git a/src/main/java/me/crypnotic/neutron/api/command/CommandWrapper.java b/src/main/java/me/crypnotic/neutron/api/command/CommandWrapper.java index 7a46365..e4d82fc 100644 --- a/src/main/java/me/crypnotic/neutron/api/command/CommandWrapper.java +++ b/src/main/java/me/crypnotic/neutron/api/command/CommandWrapper.java @@ -78,6 +78,12 @@ public void assertNotNull(CommandSource source, Object value, LocaleMessage mess assertCustom(source, value != null, message, values); } + @SneakyThrows + public void assertNotIgnoring(CommandSource source, CommandSource ignoreSource, Player target, LocaleMessage message, Object... values) { + boolean ignoring = getUser(ignoreSource).map(user -> !user.isIgnoringPlayer(target)).orElse(false); + assertCustom(source, !ignoring, message, values); + } + @SneakyThrows public void assertPermission(CommandSource source, String permission) { assertCustom(source, source.hasPermission(permission), LocaleMessage.NO_PERMISSION); diff --git a/src/main/java/me/crypnotic/neutron/api/locale/LocaleMessage.java b/src/main/java/me/crypnotic/neutron/api/locale/LocaleMessage.java index a579756..2763633 100644 --- a/src/main/java/me/crypnotic/neutron/api/locale/LocaleMessage.java +++ b/src/main/java/me/crypnotic/neutron/api/locale/LocaleMessage.java @@ -37,6 +37,10 @@ public enum LocaleMessage { FIND_MESSAGE("&b{0} &7is connected to &b{1}"), + IGNORE_AMBIGUOUS_PLAYER("&cPlayer '{0}' is ambiguous; did you mean: {1}"), + IGNORE_NOW_IGNORING("&aYou are now ignoring {0}."), + IGNORE_NOW_NOT_IGNORING("&aYou are no longer ignoring {0}."), + INFO_HEADER("&l&7==> Information for player: &b{0}"), INFO_LOCALE("&7Locale: &b{0}"), INFO_PING("&7Ping: &b{0}"), @@ -49,6 +53,8 @@ public enum LocaleMessage { LIST_HEADER("&aThere are currently &b{0} &aplayers online\n&7&oHover over a server to see the players online"), LIST_MESSAGE("&a[{0}] &e{1} player{2} online"), + MESSAGE_IGNORED_BY_TARGET("&cYou can't message {0} right now."), + MESSAGE_IGNORING_TARGET("&cYou can't message {0} because you are ignoring them."), MESSAGE_SENDER("&b&lme \u00bb {0} &7> &o"), MESSAGE_RECEIVER("&b&l{0} \u00bb me &7> &o"), diff --git a/src/main/java/me/crypnotic/neutron/api/user/User.java b/src/main/java/me/crypnotic/neutron/api/user/User.java index 1db8c89..a552839 100644 --- a/src/main/java/me/crypnotic/neutron/api/user/User.java +++ b/src/main/java/me/crypnotic/neutron/api/user/User.java @@ -1,6 +1,7 @@ package me.crypnotic.neutron.api.user; import java.util.Optional; +import java.util.Set; import java.util.UUID; import com.velocitypowered.api.command.CommandSource; @@ -17,11 +18,19 @@ public interface User { String getName(); CommandSource getReplyRecipient(); + + Set getIgnoredPlayers(); Optional getUUID(); void setReplyRecipient(CommandSource source); + void setIgnoringPlayer(Player target, boolean ignore); + + default boolean isIgnoringPlayer(Player target) { + return getIgnoredPlayers().contains(target); + } + default boolean isPlayer() { return getBase().isPresent() && getBase().get() instanceof Player; } diff --git a/src/main/java/me/crypnotic/neutron/manager/user/holder/ConsoleUser.java b/src/main/java/me/crypnotic/neutron/manager/user/holder/ConsoleUser.java index d82b3b6..9a255f6 100644 --- a/src/main/java/me/crypnotic/neutron/manager/user/holder/ConsoleUser.java +++ b/src/main/java/me/crypnotic/neutron/manager/user/holder/ConsoleUser.java @@ -1,6 +1,8 @@ package me.crypnotic.neutron.manager.user.holder; +import java.util.Collections; import java.util.Optional; +import java.util.Set; import java.util.UUID; import com.velocitypowered.api.command.CommandSource; @@ -42,4 +44,19 @@ public void save() throws Exception { public Optional getUUID() { return Optional.empty(); } + + @Override + public void setIgnoringPlayer(CommandSource source) { + /* noop */ + } + + @Override + public Set getIgnoredPlayers() { + return Collections.emptySet(); + } + + @Override + public boolean isIgnoringPlayer(CommandSource source) { + return false; + } } diff --git a/src/main/java/me/crypnotic/neutron/manager/user/holder/PlayerData.java b/src/main/java/me/crypnotic/neutron/manager/user/holder/PlayerData.java index 2dec920..e7a14e4 100644 --- a/src/main/java/me/crypnotic/neutron/manager/user/holder/PlayerData.java +++ b/src/main/java/me/crypnotic/neutron/manager/user/holder/PlayerData.java @@ -6,6 +6,8 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import java.lang.ref.WeakReference; +import java.util.Set; +import java.util.UUID; @ConfigSerializable @Data @@ -19,6 +21,9 @@ class PlayerData { @Setting(comment = "The player's last known username.") private String username; + @Setting(comment = "Players that this player is ignoring") + private Set ignoredPlayers; + // Non-persisted data - this is not saved when the user is unloaded. private WeakReference replyRecipient = null; diff --git a/src/main/java/me/crypnotic/neutron/manager/user/holder/PlayerUser.java b/src/main/java/me/crypnotic/neutron/manager/user/holder/PlayerUser.java index c09fc55..d3eb5ad 100644 --- a/src/main/java/me/crypnotic/neutron/manager/user/holder/PlayerUser.java +++ b/src/main/java/me/crypnotic/neutron/manager/user/holder/PlayerUser.java @@ -3,9 +3,12 @@ import static me.crypnotic.neutron.api.Neutron.getNeutron; import java.lang.ref.WeakReference; +import java.util.Collections; import java.util.Optional; +import java.util.Set; import java.util.UUID; +import com.google.common.collect.Sets; import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.proxy.Player; @@ -67,7 +70,25 @@ public CommandSource getReplyRecipient() { return data.getReplyRecipient(); } + @Override + public Set getIgnoredPlayers() { + return Collections.unmodifiableSet(data.getIgnoredPlayers()); + } + public void setReplyRecipient(CommandSource source) { data.setReplyRecipient(source); } + + @Override + public void setIgnoringPlayer(Player target, boolean ignore) { + Set newSet = Sets.newHashSet(data.getIgnoredPlayers()); + + if (ignore) { + newSet.add(target.getUniqueId()); + } else { + newSet.remove(target.getUniqueId()); + } + + data.setIgnoredPlayers(Collections.unmodifiableSet(newSet)); + } } diff --git a/src/main/java/me/crypnotic/neutron/module/command/options/IgnoreCommand.java b/src/main/java/me/crypnotic/neutron/module/command/options/IgnoreCommand.java new file mode 100644 index 0000000..633ac7f --- /dev/null +++ b/src/main/java/me/crypnotic/neutron/module/command/options/IgnoreCommand.java @@ -0,0 +1,43 @@ +package me.crypnotic.neutron.module.command.options; + +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.proxy.Player; +import me.crypnotic.neutron.api.command.CommandContext; +import me.crypnotic.neutron.api.command.CommandWrapper; +import me.crypnotic.neutron.api.locale.LocaleMessage; +import me.crypnotic.neutron.api.user.User; + +import java.util.Collection; + +public class IgnoreCommand extends CommandWrapper { + @Override + public void handle(CommandSource source, CommandContext context) throws CommandExitException { + assertPermission(source, "neutron.command.ignore"); + assertPlayer(source, LocaleMessage.PLAYER_ONLY_COMMAND); + assertUsage(source, context.size() > 0); + + Collection matches = getNeutron().getProxy().matchPlayer(context.get(0)); + assertCustom(source, matches.size() != 0, LocaleMessage.UNKNOWN_PLAYER); + assertCustom(source, matches.size() < 2, LocaleMessage.IGNORE_AMBIGUOUS_PLAYER); + Player target = matches.stream().findFirst().get(); + + User user = getUser(source).get(); + + boolean newState = !user.isIgnoringPlayer(target); + + if (context.size() > 1) { + newState = Boolean.parseBoolean(context.get(1)); + } + + user.setIgnoringPlayer(target, newState); + + message(source, + user.isIgnoringPlayer(target) ? LocaleMessage.IGNORE_NOW_IGNORING : LocaleMessage.IGNORE_NOW_NOT_IGNORING, + target.getUsername()); + } + + @Override + public String getUsage() { + return "/ignore (player)"; + } +} diff --git a/src/main/java/me/crypnotic/neutron/module/command/options/MessageCommand.java b/src/main/java/me/crypnotic/neutron/module/command/options/MessageCommand.java index a993255..cb9e457 100644 --- a/src/main/java/me/crypnotic/neutron/module/command/options/MessageCommand.java +++ b/src/main/java/me/crypnotic/neutron/module/command/options/MessageCommand.java @@ -59,6 +59,14 @@ public void handle(CommandSource source, CommandContext context) throws CommandE final Optional> sender = getUser(source); final Optional> recipient = getUser(target); + // Ensure source is not ignoring target + assertNotIgnoring(source, source, target, LocaleMessage.MESSAGE_IGNORING_TARGET); + + // Ensure target is not ignoring source + if (source instanceof Player) { + assertNotIgnoring(source, target, (Player) source, LocaleMessage.MESSAGE_IGNORED_BY_TARGET); + } + UserPrivateMessageEvent event = new UserPrivateMessageEvent(sender, recipient, content, false); getNeutron().getProxy().getEventManager().fire(event).thenAccept(resultEvent -> { diff --git a/src/main/java/me/crypnotic/neutron/module/command/options/ReplyCommand.java b/src/main/java/me/crypnotic/neutron/module/command/options/ReplyCommand.java index ed79635..e496ca3 100644 --- a/src/main/java/me/crypnotic/neutron/module/command/options/ReplyCommand.java +++ b/src/main/java/me/crypnotic/neutron/module/command/options/ReplyCommand.java @@ -60,6 +60,16 @@ public void handle(CommandSource source, CommandContext context) throws CommandE final Optional> sender = getUser(source); final Optional> recipient = getUser(target); + // Ensure source is not ignoring target + if (target instanceof Player) { + assertNotIgnoring(source, source, (Player) target, LocaleMessage.MESSAGE_IGNORING_TARGET); + } + + // Ensure target is not ignoring source + if (source instanceof Player) { + assertNotIgnoring(source, target, (Player) source, LocaleMessage.MESSAGE_IGNORED_BY_TARGET); + } + UserPrivateMessageEvent event = new UserPrivateMessageEvent(sender, recipient, content, true); getNeutron().getProxy().getEventManager().fire(event).thenAccept(resultEvent -> { From 19a04375bcccdcd0cb4d3a605ee2219f1089f60a Mon Sep 17 00:00:00 2001 From: md678685 <1917406+md678685@users.noreply.github.com> Date: Sun, 30 Jun 2019 14:06:27 +0100 Subject: [PATCH 02/15] Show list of ignored players when running /ignore with no args --- .../neutron/api/locale/LocaleMessage.java | 4 ++ .../module/command/options/IgnoreCommand.java | 44 +++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/main/java/me/crypnotic/neutron/api/locale/LocaleMessage.java b/src/main/java/me/crypnotic/neutron/api/locale/LocaleMessage.java index 2763633..d54e0c0 100644 --- a/src/main/java/me/crypnotic/neutron/api/locale/LocaleMessage.java +++ b/src/main/java/me/crypnotic/neutron/api/locale/LocaleMessage.java @@ -38,6 +38,10 @@ public enum LocaleMessage { FIND_MESSAGE("&b{0} &7is connected to &b{1}"), IGNORE_AMBIGUOUS_PLAYER("&cPlayer '{0}' is ambiguous; did you mean: {1}"), + IGNORE_LIST_EMPTY("&aYou are not ignoring anyone."), + IGNORE_LIST_HEAD("&aYou are ignoring the following players:\n"), + IGNORE_LIST_ITEM("&f{0}&7, "), + IGNORE_LIST_ITEM_UNKNOWN("&f&ounknown&7, "), IGNORE_NOW_IGNORING("&aYou are now ignoring {0}."), IGNORE_NOW_NOT_IGNORING("&aYou are no longer ignoring {0}."), diff --git a/src/main/java/me/crypnotic/neutron/module/command/options/IgnoreCommand.java b/src/main/java/me/crypnotic/neutron/module/command/options/IgnoreCommand.java index 633ac7f..f0a016a 100644 --- a/src/main/java/me/crypnotic/neutron/module/command/options/IgnoreCommand.java +++ b/src/main/java/me/crypnotic/neutron/module/command/options/IgnoreCommand.java @@ -6,22 +6,60 @@ import me.crypnotic.neutron.api.command.CommandWrapper; import me.crypnotic.neutron.api.locale.LocaleMessage; import me.crypnotic.neutron.api.user.User; +import net.kyori.text.Component; +import net.kyori.text.TextComponent; +import net.kyori.text.event.HoverEvent; -import java.util.Collection; +import java.util.*; +import java.util.stream.Collectors; public class IgnoreCommand extends CommandWrapper { @Override public void handle(CommandSource source, CommandContext context) throws CommandExitException { assertPermission(source, "neutron.command.ignore"); assertPlayer(source, LocaleMessage.PLAYER_ONLY_COMMAND); - assertUsage(source, context.size() > 0); + if (context.size() == 0) { + handleList(source); + } else { + handleToggle(source, context); + } + } + + private void handleList(CommandSource source) throws CommandExitException { + User user = getUser(source).get(); + + if (user.getIgnoredPlayers().isEmpty()) { + message(source, LocaleMessage.IGNORE_LIST_EMPTY); + return; + } + + Component message = getMessage(source, LocaleMessage.IGNORE_LIST_HEAD); + + for (UUID uuid : user.getIgnoredPlayers()) { + Optional> optUser = getNeutron().getUserManager().getUser(uuid); + + if (optUser.isPresent()) { + User ignored = optUser.get(); + message = message.append(getMessage(source, LocaleMessage.IGNORE_LIST_ITEM, ignored.getName())); + } else { + message = message.append( + getMessage(source, LocaleMessage.IGNORE_LIST_ITEM_UNKNOWN, uuid.toString()) + .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of(uuid.toString())))); + } + + source.sendMessage(message); + } + + } + + private void handleToggle(CommandSource source, CommandContext context) throws CommandExitException { Collection matches = getNeutron().getProxy().matchPlayer(context.get(0)); assertCustom(source, matches.size() != 0, LocaleMessage.UNKNOWN_PLAYER); assertCustom(source, matches.size() < 2, LocaleMessage.IGNORE_AMBIGUOUS_PLAYER); Player target = matches.stream().findFirst().get(); - User user = getUser(source).get(); + User user = getUser(source).get(); boolean newState = !user.isIgnoringPlayer(target); From edb6ed10247cca5bbd4c00feb917fd132afaabea Mon Sep 17 00:00:00 2001 From: md678685 <1917406+md678685@users.noreply.github.com> Date: Sun, 30 Jun 2019 14:07:45 +0100 Subject: [PATCH 03/15] Change /ignore usage message to indicate username is optional --- .../crypnotic/neutron/module/command/options/IgnoreCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/crypnotic/neutron/module/command/options/IgnoreCommand.java b/src/main/java/me/crypnotic/neutron/module/command/options/IgnoreCommand.java index f0a016a..8b73c81 100644 --- a/src/main/java/me/crypnotic/neutron/module/command/options/IgnoreCommand.java +++ b/src/main/java/me/crypnotic/neutron/module/command/options/IgnoreCommand.java @@ -76,6 +76,6 @@ private void handleToggle(CommandSource source, CommandContext context) throws C @Override public String getUsage() { - return "/ignore (player)"; + return "/ignore [player]"; } } From 35d05eb8a4cb550292cfd74358e6ec04814ea6c7 Mon Sep 17 00:00:00 2001 From: md678685 <1917406+md678685@users.noreply.github.com> Date: Sun, 30 Jun 2019 14:54:30 +0100 Subject: [PATCH 04/15] Add /ignore to default config --- src/main/resources/config.conf | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/resources/config.conf b/src/main/resources/config.conf index 017d510..831ee65 100644 --- a/src/main/resources/config.conf +++ b/src/main/resources/config.conf @@ -15,6 +15,11 @@ command { enabled = true aliases = ["find"] } + + ignore { + enabled = true + aliases = ["ignore", "block"] + } info { enabled = true From 6da5899cefc1d2d77dca8c9eba3907893c1abaa1 Mon Sep 17 00:00:00 2001 From: md678685 <1917406+md678685@users.noreply.github.com> Date: Mon, 1 Jul 2019 07:54:11 +0100 Subject: [PATCH 05/15] Update en_us locale with messages --- src/main/resources/locales/en_US.conf | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/resources/locales/en_US.conf b/src/main/resources/locales/en_US.conf index 6453a19..909f096 100644 --- a/src/main/resources/locales/en_US.conf +++ b/src/main/resources/locales/en_US.conf @@ -5,6 +5,15 @@ connect_quit_message = "&b{0} &7left the network" find_message = "&b{0} &7is connected to &b{1}" + +ignore_ambiguous_player("&cplayer '{0}' is ambiguous; did you mean: {1}" +ignore_list_empty = "&aYou are not ignoring anyone." +ignore_list_head = "&aYou are ignoring the following players:\n" +ignore_list_item = "&f{0}&7, " +ignore_list_item_unknown = "&f&ounknown&7, " +ignore_now_ignoring = "&aYou are now ignoring {0}." +ignore_now_not_ignoring = "&aYou are no longer ignoring {0}." + info_header = "&l&7==> Information for player = &b{0}" info_locale = "&7Locale = &b{0}" info_ping = "&7Ping = &b{0}" @@ -17,6 +26,9 @@ invalid_usage = "&cUsage = {0}" list_header = "&aThere are currently &b{0} &aplayers online\n&7&oHover over a server to see the players online" list_message = "&a[{0}] &e{1} online" + +message_ignored_by_target = "&cYou can't message {0} right now." +message_ignoring_target = "&cYou can't message {0} because you are ignoring them." message_sender = "&b&lme » {0} &7> &o" message_receiver = "&b&l{0} » me &7> &o" From 85552e1180932748990935d5a8d3a63330ff7d57 Mon Sep 17 00:00:00 2001 From: md678685 <1917406+md678685@users.noreply.github.com> Date: Mon, 1 Jul 2019 08:04:37 +0100 Subject: [PATCH 06/15] Fix formatting goof --- src/main/resources/locales/en_US.conf | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/resources/locales/en_US.conf b/src/main/resources/locales/en_US.conf index 909f096..6d53676 100644 --- a/src/main/resources/locales/en_US.conf +++ b/src/main/resources/locales/en_US.conf @@ -5,8 +5,7 @@ connect_quit_message = "&b{0} &7left the network" find_message = "&b{0} &7is connected to &b{1}" - -ignore_ambiguous_player("&cplayer '{0}' is ambiguous; did you mean: {1}" +ignore_ambiguous_player = "&cplayer '{0}' is ambiguous; did you mean: {1}" ignore_list_empty = "&aYou are not ignoring anyone." ignore_list_head = "&aYou are ignoring the following players:\n" ignore_list_item = "&f{0}&7, " @@ -26,7 +25,6 @@ invalid_usage = "&cUsage = {0}" list_header = "&aThere are currently &b{0} &aplayers online\n&7&oHover over a server to see the players online" list_message = "&a[{0}] &e{1} online" - message_ignored_by_target = "&cYou can't message {0} right now." message_ignoring_target = "&cYou can't message {0} because you are ignoring them." message_sender = "&b&lme » {0} &7> &o" @@ -47,4 +45,4 @@ player_only_command = "&cOnly players can use this command." player_only_subcommand = "&cOnly players can use this subcommand." unknown_player = "&cUnknown player = {0}" -unknown_server = "&cUnknown server = {0}" \ No newline at end of file +unknown_server = "&cUnknown server = {0}" From e57e25f75ede5e411075680a97e7308a8fd7ef55 Mon Sep 17 00:00:00 2001 From: md678685 <1917406+md678685@users.noreply.github.com> Date: Mon, 1 Jul 2019 11:43:39 +0100 Subject: [PATCH 07/15] Register /ignore command --- src/main/java/me/crypnotic/neutron/module/command/Commands.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/me/crypnotic/neutron/module/command/Commands.java b/src/main/java/me/crypnotic/neutron/module/command/Commands.java index 69d369c..3a0339d 100644 --- a/src/main/java/me/crypnotic/neutron/module/command/Commands.java +++ b/src/main/java/me/crypnotic/neutron/module/command/Commands.java @@ -35,6 +35,7 @@ public enum Commands { ALERT("alert", AlertCommand::new), FIND("find", FindCommand::new), + IGNORE("ignore", IgnoreCommand::new), INFO("info", InfoCommand::new), GLIST("glist", GlistCommand::new), MESSAGE("message", MessageCommand::new), From caff35a796f501c51c6cfdcf41ee932d17c690f9 Mon Sep 17 00:00:00 2001 From: md678685 <1917406+md678685@users.noreply.github.com> Date: Thu, 8 Aug 2019 16:50:56 +0100 Subject: [PATCH 08/15] Add default for ignoredPlayers to PlayerData --- .../me/crypnotic/neutron/manager/user/holder/PlayerData.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/crypnotic/neutron/manager/user/holder/PlayerData.java b/src/main/java/me/crypnotic/neutron/manager/user/holder/PlayerData.java index e7a14e4..2abaef5 100644 --- a/src/main/java/me/crypnotic/neutron/manager/user/holder/PlayerData.java +++ b/src/main/java/me/crypnotic/neutron/manager/user/holder/PlayerData.java @@ -6,6 +6,7 @@ import ninja.leaping.configurate.objectmapping.serialize.ConfigSerializable; import java.lang.ref.WeakReference; +import java.util.Collections; import java.util.Set; import java.util.UUID; @@ -22,7 +23,7 @@ class PlayerData { private String username; @Setting(comment = "Players that this player is ignoring") - private Set ignoredPlayers; + private Set ignoredPlayers = Collections.emptySet(); // Non-persisted data - this is not saved when the user is unloaded. From 62f82f5dfac7528a464e5fc52bf2854510684fc6 Mon Sep 17 00:00:00 2001 From: md678685 <1917406+md678685@users.noreply.github.com> Date: Thu, 8 Aug 2019 17:15:56 +0100 Subject: [PATCH 09/15] Use List to store ignoredPlayers Avoids needing to implement a serializer for Sets --- .../neutron/manager/user/holder/PlayerData.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/crypnotic/neutron/manager/user/holder/PlayerData.java b/src/main/java/me/crypnotic/neutron/manager/user/holder/PlayerData.java index 2abaef5..a0afb4b 100644 --- a/src/main/java/me/crypnotic/neutron/manager/user/holder/PlayerData.java +++ b/src/main/java/me/crypnotic/neutron/manager/user/holder/PlayerData.java @@ -1,5 +1,7 @@ package me.crypnotic.neutron.manager.user.holder; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import com.velocitypowered.api.command.CommandSource; import lombok.Data; import ninja.leaping.configurate.objectmapping.Setting; @@ -7,6 +9,7 @@ import java.lang.ref.WeakReference; import java.util.Collections; +import java.util.List; import java.util.Set; import java.util.UUID; @@ -23,7 +26,15 @@ class PlayerData { private String username; @Setting(comment = "Players that this player is ignoring") - private Set ignoredPlayers = Collections.emptySet(); + private List ignoredPlayers = Collections.emptyList(); // Configurate includes a List TypeSerializer, so let's use that. + + public Set getIgnoredPlayers() { + return Sets.newHashSet(ignoredPlayers); + } + + public void setIgnoredPlayers(Set ignoredPlayers) { + this.ignoredPlayers = Lists.newArrayList(ignoredPlayers); + } // Non-persisted data - this is not saved when the user is unloaded. From 4d040b0253ddc39d993a79dd974cea0aa8bd00e7 Mon Sep 17 00:00:00 2001 From: md678685 <1917406+md678685@users.noreply.github.com> Date: Thu, 8 Aug 2019 17:25:08 +0100 Subject: [PATCH 10/15] Fix isIgnoringPlayer implementation --- src/main/java/me/crypnotic/neutron/api/user/User.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/crypnotic/neutron/api/user/User.java b/src/main/java/me/crypnotic/neutron/api/user/User.java index a552839..a60e7e8 100644 --- a/src/main/java/me/crypnotic/neutron/api/user/User.java +++ b/src/main/java/me/crypnotic/neutron/api/user/User.java @@ -28,7 +28,7 @@ public interface User { void setIgnoringPlayer(Player target, boolean ignore); default boolean isIgnoringPlayer(Player target) { - return getIgnoredPlayers().contains(target); + return getIgnoredPlayers().contains(target.getUniqueId()); } default boolean isPlayer() { From e369296b943238f9402e48dd4d07224239cdb499 Mon Sep 17 00:00:00 2001 From: md678685 <1917406+md678685@users.noreply.github.com> Date: Sun, 18 Aug 2019 20:07:55 +0100 Subject: [PATCH 11/15] Fix inversion in assertNotIgnoring --- .../java/me/crypnotic/neutron/api/command/CommandWrapper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/me/crypnotic/neutron/api/command/CommandWrapper.java b/src/main/java/me/crypnotic/neutron/api/command/CommandWrapper.java index e4d82fc..4ff0b21 100644 --- a/src/main/java/me/crypnotic/neutron/api/command/CommandWrapper.java +++ b/src/main/java/me/crypnotic/neutron/api/command/CommandWrapper.java @@ -80,7 +80,7 @@ public void assertNotNull(CommandSource source, Object value, LocaleMessage mess @SneakyThrows public void assertNotIgnoring(CommandSource source, CommandSource ignoreSource, Player target, LocaleMessage message, Object... values) { - boolean ignoring = getUser(ignoreSource).map(user -> !user.isIgnoringPlayer(target)).orElse(false); + boolean ignoring = getUser(ignoreSource).map(user -> user.isIgnoringPlayer(target)).orElse(false); assertCustom(source, !ignoring, message, values); } From 6cccd850ca6b89bac37fc2010a4eb965f51ba260 Mon Sep 17 00:00:00 2001 From: md678685 <1917406+md678685@users.noreply.github.com> Date: Sun, 18 Aug 2019 20:12:59 +0100 Subject: [PATCH 12/15] Add neutron.message.ignore.bypass permission --- .../neutron/module/command/options/MessageCommand.java | 2 +- .../crypnotic/neutron/module/command/options/ReplyCommand.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/crypnotic/neutron/module/command/options/MessageCommand.java b/src/main/java/me/crypnotic/neutron/module/command/options/MessageCommand.java index cb9e457..06e667a 100644 --- a/src/main/java/me/crypnotic/neutron/module/command/options/MessageCommand.java +++ b/src/main/java/me/crypnotic/neutron/module/command/options/MessageCommand.java @@ -63,7 +63,7 @@ public void handle(CommandSource source, CommandContext context) throws CommandE assertNotIgnoring(source, source, target, LocaleMessage.MESSAGE_IGNORING_TARGET); // Ensure target is not ignoring source - if (source instanceof Player) { + if (source instanceof Player && !source.hasPermission("neutron.message.ignore.bypass")) { assertNotIgnoring(source, target, (Player) source, LocaleMessage.MESSAGE_IGNORED_BY_TARGET); } diff --git a/src/main/java/me/crypnotic/neutron/module/command/options/ReplyCommand.java b/src/main/java/me/crypnotic/neutron/module/command/options/ReplyCommand.java index e496ca3..8c5cf68 100644 --- a/src/main/java/me/crypnotic/neutron/module/command/options/ReplyCommand.java +++ b/src/main/java/me/crypnotic/neutron/module/command/options/ReplyCommand.java @@ -66,7 +66,7 @@ public void handle(CommandSource source, CommandContext context) throws CommandE } // Ensure target is not ignoring source - if (source instanceof Player) { + if (source instanceof Player && !source.hasPermission("neutron.message.ignore.bypass")) { assertNotIgnoring(source, target, (Player) source, LocaleMessage.MESSAGE_IGNORED_BY_TARGET); } From 5522a5f4e4bf227ca468c0b735da4937a110b1a2 Mon Sep 17 00:00:00 2001 From: md678685 <1917406+md678685@users.noreply.github.com> Date: Sun, 18 Aug 2019 20:21:56 +0100 Subject: [PATCH 13/15] Change ignore permission node --- .../neutron/module/command/options/MessageCommand.java | 2 +- .../crypnotic/neutron/module/command/options/ReplyCommand.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/me/crypnotic/neutron/module/command/options/MessageCommand.java b/src/main/java/me/crypnotic/neutron/module/command/options/MessageCommand.java index 06e667a..f7e656c 100644 --- a/src/main/java/me/crypnotic/neutron/module/command/options/MessageCommand.java +++ b/src/main/java/me/crypnotic/neutron/module/command/options/MessageCommand.java @@ -63,7 +63,7 @@ public void handle(CommandSource source, CommandContext context) throws CommandE assertNotIgnoring(source, source, target, LocaleMessage.MESSAGE_IGNORING_TARGET); // Ensure target is not ignoring source - if (source instanceof Player && !source.hasPermission("neutron.message.ignore.bypass")) { + if (source instanceof Player && !source.hasPermission("neutron.command.message.ignore.bypass")) { assertNotIgnoring(source, target, (Player) source, LocaleMessage.MESSAGE_IGNORED_BY_TARGET); } diff --git a/src/main/java/me/crypnotic/neutron/module/command/options/ReplyCommand.java b/src/main/java/me/crypnotic/neutron/module/command/options/ReplyCommand.java index 8c5cf68..21b8a88 100644 --- a/src/main/java/me/crypnotic/neutron/module/command/options/ReplyCommand.java +++ b/src/main/java/me/crypnotic/neutron/module/command/options/ReplyCommand.java @@ -66,7 +66,7 @@ public void handle(CommandSource source, CommandContext context) throws CommandE } // Ensure target is not ignoring source - if (source instanceof Player && !source.hasPermission("neutron.message.ignore.bypass")) { + if (source instanceof Player && !source.hasPermission("neutron.command.message.ignore.bypass")) { assertNotIgnoring(source, target, (Player) source, LocaleMessage.MESSAGE_IGNORED_BY_TARGET); } From 50eb06d7aa5f5c7182d9f37b7fc1885b3b9d7e48 Mon Sep 17 00:00:00 2001 From: md678685 <1917406+md678685@users.noreply.github.com> Date: Mon, 19 Aug 2019 14:19:11 +0100 Subject: [PATCH 14/15] Fix missing username in ignore messages --- .../neutron/module/command/options/MessageCommand.java | 4 ++-- .../neutron/module/command/options/ReplyCommand.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/crypnotic/neutron/module/command/options/MessageCommand.java b/src/main/java/me/crypnotic/neutron/module/command/options/MessageCommand.java index f7e656c..5ed1fc6 100644 --- a/src/main/java/me/crypnotic/neutron/module/command/options/MessageCommand.java +++ b/src/main/java/me/crypnotic/neutron/module/command/options/MessageCommand.java @@ -60,11 +60,11 @@ public void handle(CommandSource source, CommandContext context) throws CommandE final Optional> recipient = getUser(target); // Ensure source is not ignoring target - assertNotIgnoring(source, source, target, LocaleMessage.MESSAGE_IGNORING_TARGET); + assertNotIgnoring(source, source, target, LocaleMessage.MESSAGE_IGNORING_TARGET, target.getUsername()); // Ensure target is not ignoring source if (source instanceof Player && !source.hasPermission("neutron.command.message.ignore.bypass")) { - assertNotIgnoring(source, target, (Player) source, LocaleMessage.MESSAGE_IGNORED_BY_TARGET); + assertNotIgnoring(source, target, (Player) source, LocaleMessage.MESSAGE_IGNORED_BY_TARGET, target.getUsername()); } UserPrivateMessageEvent event = new UserPrivateMessageEvent(sender, recipient, content, false); diff --git a/src/main/java/me/crypnotic/neutron/module/command/options/ReplyCommand.java b/src/main/java/me/crypnotic/neutron/module/command/options/ReplyCommand.java index 21b8a88..b2cfce2 100644 --- a/src/main/java/me/crypnotic/neutron/module/command/options/ReplyCommand.java +++ b/src/main/java/me/crypnotic/neutron/module/command/options/ReplyCommand.java @@ -62,12 +62,12 @@ public void handle(CommandSource source, CommandContext context) throws CommandE // Ensure source is not ignoring target if (target instanceof Player) { - assertNotIgnoring(source, source, (Player) target, LocaleMessage.MESSAGE_IGNORING_TARGET); + assertNotIgnoring(source, source, (Player) target, LocaleMessage.MESSAGE_IGNORING_TARGET, targetName); } // Ensure target is not ignoring source if (source instanceof Player && !source.hasPermission("neutron.command.message.ignore.bypass")) { - assertNotIgnoring(source, target, (Player) source, LocaleMessage.MESSAGE_IGNORED_BY_TARGET); + assertNotIgnoring(source, target, (Player) source, LocaleMessage.MESSAGE_IGNORED_BY_TARGET, targetName); } UserPrivateMessageEvent event = new UserPrivateMessageEvent(sender, recipient, content, true); From b0b446b987b15b214dcfb97996c6b49556806e77 Mon Sep 17 00:00:00 2001 From: md678685 <1917406+md678685@users.noreply.github.com> Date: Mon, 19 Aug 2019 14:21:42 +0100 Subject: [PATCH 15/15] Clean up ignore assert method --- .../java/me/crypnotic/neutron/api/command/CommandWrapper.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/me/crypnotic/neutron/api/command/CommandWrapper.java b/src/main/java/me/crypnotic/neutron/api/command/CommandWrapper.java index 4ff0b21..520dd8a 100644 --- a/src/main/java/me/crypnotic/neutron/api/command/CommandWrapper.java +++ b/src/main/java/me/crypnotic/neutron/api/command/CommandWrapper.java @@ -80,8 +80,7 @@ public void assertNotNull(CommandSource source, Object value, LocaleMessage mess @SneakyThrows public void assertNotIgnoring(CommandSource source, CommandSource ignoreSource, Player target, LocaleMessage message, Object... values) { - boolean ignoring = getUser(ignoreSource).map(user -> user.isIgnoringPlayer(target)).orElse(false); - assertCustom(source, !ignoring, message, values); + getUser(ignoreSource).ifPresent(u -> assertCustom(source, !u.isIgnoringPlayer(target), message, values)); } @SneakyThrows