From b83c25a5e5c619a908045c608bf16260cbdcd0c2 Mon Sep 17 00:00:00 2001 From: nickreesdev Date: Sat, 20 Feb 2021 12:25:02 -0600 Subject: [PATCH] Made it where players can't message or reply if they're muted. --- .../java/zone/themcgamer/arcade/Arcade.java | 2 +- .../zone/themcgamer/buildServer/Build.java | 2 +- .../core/account/AccountManager.java | 4 ---- .../themcgamer/core/chat/ChatManager.java | 6 ++++- .../command/message}/MessageCommand.java | 24 +++++++++++++++---- .../command/message}/ReplyCommand.java | 20 ++++++++++++++-- .../themcgamer/core/plugin/MGZPlugin.java | 3 ++- .../main/java/zone/themcgamer/hub/Hub.java | 2 +- .../zone/themcgamer/skyblock/Skyblock.java | 2 +- 9 files changed, 49 insertions(+), 16 deletions(-) rename core/src/main/java/zone/themcgamer/core/{command/impl/social => chat/command/message}/MessageCommand.java (70%) rename core/src/main/java/zone/themcgamer/core/{command/impl/social => chat/command/message}/ReplyCommand.java (77%) diff --git a/arcade/src/main/java/zone/themcgamer/arcade/Arcade.java b/arcade/src/main/java/zone/themcgamer/arcade/Arcade.java index 26a31ec..f4a605f 100644 --- a/arcade/src/main/java/zone/themcgamer/arcade/Arcade.java +++ b/arcade/src/main/java/zone/themcgamer/arcade/Arcade.java @@ -39,7 +39,7 @@ public class Arcade extends MGZPlugin { new ScoreboardHandler(this, ArcadeScoreboard.class, 3L); - new ChatManager(this, badSportSystem, new IChatComponent[] { + new ChatManager(this, accountManager, badSportSystem, new IChatComponent[] { new BasicRankComponent(), new BasicNameComponent() }); diff --git a/buildserver/src/main/java/zone/themcgamer/buildServer/Build.java b/buildserver/src/main/java/zone/themcgamer/buildServer/Build.java index adf64be..eedc6d6 100644 --- a/buildserver/src/main/java/zone/themcgamer/buildServer/Build.java +++ b/buildserver/src/main/java/zone/themcgamer/buildServer/Build.java @@ -33,7 +33,7 @@ public class Build extends MGZPlugin { WorldManager worldManager = new WorldManager(this); new PlayerListener(this, worldManager); - new ChatManager(this, badSportSystem, new IChatComponent[] { + new ChatManager(this, accountManager, badSportSystem, new IChatComponent[] { new BasicRankComponent(), new BasicNameComponent() }); diff --git a/core/src/main/java/zone/themcgamer/core/account/AccountManager.java b/core/src/main/java/zone/themcgamer/core/account/AccountManager.java index 973961e..fb5a2ef 100644 --- a/core/src/main/java/zone/themcgamer/core/account/AccountManager.java +++ b/core/src/main/java/zone/themcgamer/core/account/AccountManager.java @@ -23,8 +23,6 @@ import zone.themcgamer.core.account.command.rank.arguments.ListArgument; import zone.themcgamer.core.account.command.rank.arguments.SetArgument; import zone.themcgamer.core.account.event.AccountLoadEvent; import zone.themcgamer.core.account.event.AccountUnloadEvent; -import zone.themcgamer.core.command.impl.social.MessageCommand; -import zone.themcgamer.core.command.impl.social.ReplyCommand; import zone.themcgamer.core.common.MojangUtils; import zone.themcgamer.core.common.Style; import zone.themcgamer.core.module.Module; @@ -99,8 +97,6 @@ public class AccountManager extends Module { registerCommand(new GoldCommand(this)); registerCommand(new GemsCommand(this)); - registerCommand(new MessageCommand(this, cacheRepository)); - registerCommand(new ReplyCommand(this, cacheRepository)); registerCommand(new PlayerInfoCommand(this, cacheRepository)); registerCommand(new zone.themcgamer.core.command.impl.staff.StaffChatCommand()); diff --git a/core/src/main/java/zone/themcgamer/core/chat/ChatManager.java b/core/src/main/java/zone/themcgamer/core/chat/ChatManager.java index 51a626e..63d9479 100644 --- a/core/src/main/java/zone/themcgamer/core/chat/ChatManager.java +++ b/core/src/main/java/zone/themcgamer/core/chat/ChatManager.java @@ -16,6 +16,8 @@ import zone.themcgamer.core.badSportSystem.BadSportSystem; import zone.themcgamer.core.badSportSystem.Punishment; import zone.themcgamer.core.badSportSystem.PunishmentCategory; import zone.themcgamer.core.chat.command.ClearChatCommand; +import zone.themcgamer.core.chat.command.message.MessageCommand; +import zone.themcgamer.core.chat.command.message.ReplyCommand; import zone.themcgamer.core.chat.component.IChatComponent; import zone.themcgamer.core.common.Style; import zone.themcgamer.core.cooldown.CooldownHandler; @@ -41,11 +43,13 @@ public class ChatManager extends Module { emotes.put("unflip", "┬─┬ ノ( ゜-゜ノ)"); } - public ChatManager(JavaPlugin plugin, BadSportSystem badSportSystem, IChatComponent[] chatComponents) { + public ChatManager(JavaPlugin plugin, AccountManager accountManager, BadSportSystem badSportSystem, IChatComponent[] chatComponents) { super(plugin); this.badSportSystem = badSportSystem; this.chatComponents = chatComponents; registerCommand(new ClearChatCommand()); + registerCommand(new MessageCommand(accountManager, badSportSystem)); + registerCommand(new ReplyCommand(accountManager, badSportSystem)); /* TODO /chatmanager blackwords add diff --git a/core/src/main/java/zone/themcgamer/core/command/impl/social/MessageCommand.java b/core/src/main/java/zone/themcgamer/core/chat/command/message/MessageCommand.java similarity index 70% rename from core/src/main/java/zone/themcgamer/core/command/impl/social/MessageCommand.java rename to core/src/main/java/zone/themcgamer/core/chat/command/message/MessageCommand.java index 939b2fb..02a66e4 100644 --- a/core/src/main/java/zone/themcgamer/core/command/impl/social/MessageCommand.java +++ b/core/src/main/java/zone/themcgamer/core/chat/command/message/MessageCommand.java @@ -1,10 +1,14 @@ -package zone.themcgamer.core.command.impl.social; +package zone.themcgamer.core.chat.command.message; import com.cryptomorin.xseries.XSound; import lombok.AllArgsConstructor; import org.bukkit.entity.Player; import zone.themcgamer.core.account.Account; import zone.themcgamer.core.account.AccountManager; +import zone.themcgamer.core.badSportSystem.BadSportClient; +import zone.themcgamer.core.badSportSystem.BadSportSystem; +import zone.themcgamer.core.badSportSystem.Punishment; +import zone.themcgamer.core.badSportSystem.PunishmentCategory; import zone.themcgamer.core.command.Command; import zone.themcgamer.core.command.CommandProvider; import zone.themcgamer.core.common.Style; @@ -12,6 +16,7 @@ import zone.themcgamer.data.jedis.cache.CacheRepository; import zone.themcgamer.data.jedis.cache.impl.PlayerStatusCache; import zone.themcgamer.data.jedis.command.JedisCommandHandler; import zone.themcgamer.data.jedis.command.impl.player.PlayerDirectMessageEvent; +import zone.themcgamer.data.jedis.repository.RedisRepository; import java.util.Arrays; import java.util.Optional; @@ -20,20 +25,31 @@ import java.util.stream.Collectors; @AllArgsConstructor public class MessageCommand { private final AccountManager accountManager; - private final CacheRepository cacheRepository; + private final BadSportSystem badSportSystem; @Command(name = "msg", aliases = { "whisper", "m", "message", "dm", "w" }, description = "Sent a private message to a player.", playersOnly = true) public void onCommand(CommandProvider command) { Player player = command.getPlayer(); + CacheRepository cacheRepository = RedisRepository.getRepository(CacheRepository.class).orElse(null); + if (cacheRepository == null) + return; + Optional optionalBadSportClient = badSportSystem.lookup(player.getUniqueId()); + if (optionalBadSportClient.isEmpty()) + return; String[] args = command.getArgs(); if (args.length < 2) { - player.sendMessage(Style.main("Chat", "&7Please use &b/" + command.getLabel() + " (player) (message)")); + player.sendMessage(Style.error("Chat", "Usage: &b/" + command.getLabel() + " (player) (message)")); + return; + } + Optional optionalMute = optionalBadSportClient.get().getMute(); + if (optionalMute.isPresent()) { + player.sendMessage(Style.error("Bad Sport", PunishmentCategory.format(optionalMute.get()))); return; } String target = args[0]; if (player.getName().equalsIgnoreCase(target)) { - player.sendMessage(Style.main("Chat", "&7You can not message yourself.")); + player.sendMessage(Style.error("Chat", "You can not message yourself.")); return; } String message = Arrays.stream(args).skip(1).collect(Collectors.joining(" ")); diff --git a/core/src/main/java/zone/themcgamer/core/command/impl/social/ReplyCommand.java b/core/src/main/java/zone/themcgamer/core/chat/command/message/ReplyCommand.java similarity index 77% rename from core/src/main/java/zone/themcgamer/core/command/impl/social/ReplyCommand.java rename to core/src/main/java/zone/themcgamer/core/chat/command/message/ReplyCommand.java index d72dca4..2136fb2 100644 --- a/core/src/main/java/zone/themcgamer/core/command/impl/social/ReplyCommand.java +++ b/core/src/main/java/zone/themcgamer/core/chat/command/message/ReplyCommand.java @@ -1,10 +1,14 @@ -package zone.themcgamer.core.command.impl.social; +package zone.themcgamer.core.chat.command.message; import com.cryptomorin.xseries.XSound; import lombok.RequiredArgsConstructor; import org.bukkit.entity.Player; import zone.themcgamer.core.account.Account; import zone.themcgamer.core.account.AccountManager; +import zone.themcgamer.core.badSportSystem.BadSportClient; +import zone.themcgamer.core.badSportSystem.BadSportSystem; +import zone.themcgamer.core.badSportSystem.Punishment; +import zone.themcgamer.core.badSportSystem.PunishmentCategory; import zone.themcgamer.core.command.Command; import zone.themcgamer.core.command.CommandProvider; import zone.themcgamer.core.common.Style; @@ -12,6 +16,7 @@ import zone.themcgamer.data.jedis.cache.CacheRepository; import zone.themcgamer.data.jedis.cache.impl.PlayerStatusCache; import zone.themcgamer.data.jedis.command.JedisCommandHandler; import zone.themcgamer.data.jedis.command.impl.player.PlayerDirectMessageEvent; +import zone.themcgamer.data.jedis.repository.RedisRepository; import java.util.Arrays; import java.util.Optional; @@ -20,16 +25,27 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class ReplyCommand { private final AccountManager accountManager; - private final CacheRepository cacheRepository; + private final BadSportSystem badSportSystem; @Command(name = "reply", aliases = { "r" }, description = "Reply to a player that sent you a private message.", playersOnly = true) public void onCommand(CommandProvider command) { Player player = command.getPlayer(); + CacheRepository cacheRepository = RedisRepository.getRepository(CacheRepository.class).orElse(null); + if (cacheRepository == null) + return; String[] args = command.getArgs(); if (args.length < 1) { player.sendMessage(Style.main("Chat", "&7Please use &b/" + command.getLabel() + " (message)")); return; } + Optional optionalBadSportClient = badSportSystem.lookup(player.getUniqueId()); + if (optionalBadSportClient.isEmpty()) + return; + Optional optionalMute = optionalBadSportClient.get().getMute(); + if (optionalMute.isPresent()) { + player.sendMessage(Style.error("Bad Sport", PunishmentCategory.format(optionalMute.get()))); + return; + } String message = Arrays.stream(args).skip(0).collect(Collectors.joining(" ")); Optional optionalPlayerStatusCache = cacheRepository.lookup(PlayerStatusCache.class, player.getUniqueId()); if (optionalPlayerStatusCache.isEmpty()) { diff --git a/core/src/main/java/zone/themcgamer/core/plugin/MGZPlugin.java b/core/src/main/java/zone/themcgamer/core/plugin/MGZPlugin.java index c84fa1c..06e4f5b 100644 --- a/core/src/main/java/zone/themcgamer/core/plugin/MGZPlugin.java +++ b/core/src/main/java/zone/themcgamer/core/plugin/MGZPlugin.java @@ -50,6 +50,7 @@ public abstract class MGZPlugin extends JavaPlugin { protected MySQLController mySQLController; protected CommandManager commandManager; protected ServerTraveler traveler; + protected AccountManager accountManager; protected BadSportSystem badSportSystem; protected NametagManager nametagManager; @@ -169,7 +170,7 @@ public abstract class MGZPlugin extends JavaPlugin { new CooldownHandler(this); nametagManager = new NametagManager(this); - AccountManager accountManager = new AccountManager(this, mySQLController, nametagManager); + accountManager = new AccountManager(this, mySQLController, nametagManager); traveler = new ServerTraveler(this); new ServerUpdater(this, traveler); new ServerManager(this, traveler); diff --git a/hub/src/main/java/zone/themcgamer/hub/Hub.java b/hub/src/main/java/zone/themcgamer/hub/Hub.java index c307c4b..73e14e6 100644 --- a/hub/src/main/java/zone/themcgamer/hub/Hub.java +++ b/hub/src/main/java/zone/themcgamer/hub/Hub.java @@ -50,7 +50,7 @@ public class Hub extends MGZPlugin { new WorldListener(this); new ScoreboardHandler(this, HubScoreboard.class, 3L); - new ChatManager(this, badSportSystem, new IChatComponent[] { + new ChatManager(this, accountManager, badSportSystem, new IChatComponent[] { new BasicRankComponent(), new BasicNameComponent() }); diff --git a/skyblock/src/main/java/zone/themcgamer/skyblock/Skyblock.java b/skyblock/src/main/java/zone/themcgamer/skyblock/Skyblock.java index 845bad6..3558dc0 100644 --- a/skyblock/src/main/java/zone/themcgamer/skyblock/Skyblock.java +++ b/skyblock/src/main/java/zone/themcgamer/skyblock/Skyblock.java @@ -34,7 +34,7 @@ public class Skyblock extends MGZPlugin { new PlayerListener(this); new ScoreboardHandler(this, SkyblockScoreboard.class, 3L); - new ChatManager(this, badSportSystem, new IChatComponent[] { + new ChatManager(this, accountManager, badSportSystem, new IChatComponent[] { new SkyblockChatLevelComponent(), new BasicRankComponent(), new BasicNameComponent()