From 1b856db2979a1cc1a7f7caa585becaa3b3ed9b80 Mon Sep 17 00:00:00 2001 From: Taah Date: Fri, 25 Feb 2022 00:59:48 -0800 Subject: [PATCH] - Add unmute & mute and some checks as well as fix prefix bug --- .../java/dev/plex/command/impl/BanCMD.java | 7 +- .../java/dev/plex/command/impl/FreezeCMD.java | 20 +++++ .../java/dev/plex/command/impl/MuteCMD.java | 74 +++++++++++++++++++ .../dev/plex/command/impl/UnfreezeCMD.java | 3 +- .../java/dev/plex/command/impl/UnmuteCMD.java | 47 ++++++++++++ .../dev/plex/handlers/CommandHandler.java | 2 + .../dev/plex/listener/impl/ChatListener.java | 6 ++ .../plex/punishment/PunishmentManager.java | 7 +- src/main/java/dev/plex/rank/enums/Rank.java | 7 ++ src/main/java/dev/plex/rank/enums/Title.java | 7 ++ src/main/java/dev/plex/util/PlexUtils.java | 4 +- src/main/resources/messages.yml | 18 +++++ 12 files changed, 197 insertions(+), 5 deletions(-) create mode 100644 src/main/java/dev/plex/command/impl/MuteCMD.java create mode 100644 src/main/java/dev/plex/command/impl/UnmuteCMD.java diff --git a/src/main/java/dev/plex/command/impl/BanCMD.java b/src/main/java/dev/plex/command/impl/BanCMD.java index 2ce06c6..b116fb0 100644 --- a/src/main/java/dev/plex/command/impl/BanCMD.java +++ b/src/main/java/dev/plex/command/impl/BanCMD.java @@ -62,6 +62,11 @@ public class BanCMD extends PlexCommand } } + if (plugin.getPunishmentManager().isBanned(targetUUID)) + { + return messageComponent("playerBanned"); + } + PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(targetUUID) == null ? new PunishedPlayer(targetUUID) : PlayerCache.getPunishedPlayer(targetUUID); Punishment punishment = new Punishment(targetUUID, getUUID(sender)); punishment.setType(PunishmentType.BAN); @@ -78,7 +83,7 @@ public class BanCMD extends PlexCommand LocalDateTime date = LocalDateTime.now(); punishment.setEndDate(date.plusDays(1)); punishment.setCustomTime(false); - punishment.setActive(true); + punishment.setActive(!isAdmin(plexPlayer)); plugin.getPunishmentManager().doPunishment(punishedPlayer, punishment); PlexUtils.broadcast(messageComponent("banningPlayer", sender.getName(), plexPlayer.getName())); if (player != null) diff --git a/src/main/java/dev/plex/command/impl/FreezeCMD.java b/src/main/java/dev/plex/command/impl/FreezeCMD.java index dc9e119..5fbdc69 100644 --- a/src/main/java/dev/plex/command/impl/FreezeCMD.java +++ b/src/main/java/dev/plex/command/impl/FreezeCMD.java @@ -5,6 +5,7 @@ import dev.plex.cache.PlayerCache; import dev.plex.command.PlexCommand; import dev.plex.command.annotation.CommandParameters; import dev.plex.command.annotation.CommandPermissions; +import dev.plex.player.PlexPlayer; import dev.plex.player.PunishedPlayer; import dev.plex.punishment.Punishment; import dev.plex.punishment.PunishmentType; @@ -32,6 +33,25 @@ public class FreezeCMD extends PlexCommand } Player player = getNonNullPlayer(args[0]); PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId()); + + if (punishedPlayer.isFrozen()) + { + return messageComponent("playerFrozen"); + } + + if (isAdmin(getPlexPlayer(player))) + { + if (!isConsole(sender)) + { + assert playerSender != null; + PlexPlayer plexPlayer1 = getPlexPlayer(playerSender); + if (!plexPlayer1.getRankFromString().isAtLeast(getPlexPlayer(player).getRankFromString())) + { + return messageComponent("higherRankThanYou"); + } + } + } + Punishment punishment = new Punishment(UUID.fromString(punishedPlayer.getUuid()), getUUID(sender)); punishment.setCustomTime(false); LocalDateTime date = LocalDateTime.now(); diff --git a/src/main/java/dev/plex/command/impl/MuteCMD.java b/src/main/java/dev/plex/command/impl/MuteCMD.java new file mode 100644 index 0000000..b76adef --- /dev/null +++ b/src/main/java/dev/plex/command/impl/MuteCMD.java @@ -0,0 +1,74 @@ +package dev.plex.command.impl; + +import com.google.common.collect.ImmutableList; +import dev.plex.cache.PlayerCache; +import dev.plex.command.PlexCommand; +import dev.plex.command.annotation.CommandParameters; +import dev.plex.command.annotation.CommandPermissions; +import dev.plex.player.PlexPlayer; +import dev.plex.player.PunishedPlayer; +import dev.plex.punishment.Punishment; +import dev.plex.punishment.PunishmentType; +import dev.plex.rank.enums.Rank; +import dev.plex.util.PlexUtils; +import net.kyori.adventure.text.Component; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.time.LocalDateTime; +import java.util.List; +import java.util.UUID; + +@CommandParameters(name = "mute", description = "Mute a player on the server", usage = "/ ", aliases = "stfu") +@CommandPermissions(level = Rank.ADMIN, permission = "plex.mute") +public class MuteCMD extends PlexCommand +{ + @Override + protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) + { + if (args.length != 1) + { + return usage(); + } + Player player = getNonNullPlayer(args[0]); + PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId()); + + if (punishedPlayer.isMuted()) + { + return messageComponent("playerMuted"); + } + + if (isAdmin(getPlexPlayer(player))) + { + if (!isConsole(sender)) + { + assert playerSender != null; + PlexPlayer plexPlayer1 = getPlexPlayer(playerSender); + if (!plexPlayer1.getRankFromString().isAtLeast(getPlexPlayer(player).getRankFromString())) + { + return messageComponent("higherRankThanYou"); + } + } + } + + Punishment punishment = new Punishment(UUID.fromString(punishedPlayer.getUuid()), getUUID(sender)); + punishment.setCustomTime(false); + LocalDateTime date = LocalDateTime.now(); + punishment.setEndDate(date.plusMinutes(5)); + punishment.setType(PunishmentType.MUTE); + punishment.setPunishedUsername(player.getName()); + punishment.setReason(""); + + plugin.getPunishmentManager().doPunishment(punishedPlayer, punishment); + PlexUtils.broadcast(messageComponent("mutedPlayer", sender.getName(), player.getName())); + return null; + } + + @Override + public @NotNull List tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException + { + return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.mute") ? PlexUtils.getPlayerNameList() : ImmutableList.of(); + } +} \ No newline at end of file diff --git a/src/main/java/dev/plex/command/impl/UnfreezeCMD.java b/src/main/java/dev/plex/command/impl/UnfreezeCMD.java index 727b8e3..e933b5b 100644 --- a/src/main/java/dev/plex/command/impl/UnfreezeCMD.java +++ b/src/main/java/dev/plex/command/impl/UnfreezeCMD.java @@ -34,7 +34,8 @@ public class UnfreezeCMD extends PlexCommand throw new CommandFailException(PlexUtils.messageString("playerNotFrozen")); } punishedPlayer.setFrozen(false); - return messageComponent("unfrozePlayer", sender.getName(), player.getName()); + PlexUtils.broadcast(messageComponent("unfrozePlayer", sender.getName(), player.getName())); + return null; } @Override diff --git a/src/main/java/dev/plex/command/impl/UnmuteCMD.java b/src/main/java/dev/plex/command/impl/UnmuteCMD.java new file mode 100644 index 0000000..da1cec2 --- /dev/null +++ b/src/main/java/dev/plex/command/impl/UnmuteCMD.java @@ -0,0 +1,47 @@ +package dev.plex.command.impl; + +import com.google.common.collect.ImmutableList; +import dev.plex.cache.PlayerCache; +import dev.plex.command.PlexCommand; +import dev.plex.command.annotation.CommandParameters; +import dev.plex.command.annotation.CommandPermissions; +import dev.plex.command.exception.CommandFailException; +import dev.plex.player.PunishedPlayer; +import dev.plex.rank.enums.Rank; +import dev.plex.util.PlexUtils; +import net.kyori.adventure.text.Component; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +@CommandPermissions(level = Rank.ADMIN, permission = "plex.unmute") +@CommandParameters(name = "unmute", description = "Unmute a player", usage = "/ ") +public class UnmuteCMD extends PlexCommand +{ + @Override + protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) + { + if (args.length != 1) + { + return usage(); + } + Player player = getNonNullPlayer(args[0]); + PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(player.getUniqueId()); + if (!punishedPlayer.isMuted()) + { + throw new CommandFailException(PlexUtils.messageString("playerNotMuted")); + } + punishedPlayer.setMuted(false); + PlexUtils.broadcast(messageComponent("unmutedPlayer", sender.getName(), player.getName())); + return null; + } + + @Override + public @NotNull List tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException + { + return args.length == 1 && checkTab(sender, Rank.ADMIN, "plex.unfreeze") ? PlexUtils.getPlayerNameList() : ImmutableList.of(); + } +} diff --git a/src/main/java/dev/plex/handlers/CommandHandler.java b/src/main/java/dev/plex/handlers/CommandHandler.java index 404aa9f..8916560 100644 --- a/src/main/java/dev/plex/handlers/CommandHandler.java +++ b/src/main/java/dev/plex/handlers/CommandHandler.java @@ -38,6 +38,7 @@ public class CommandHandler extends PlexBase commands.add(new ListCMD()); commands.add(new LocalSpawnCMD()); commands.add(new MasterbuilderworldCMD()); + commands.add(new MuteCMD()); commands.add(new NameHistoryCMD()); commands.add(new PlexCMD()); commands.add(new PunishmentsCMD()); @@ -47,6 +48,7 @@ public class CommandHandler extends PlexBase commands.add(new TagCMD()); commands.add(new UnbanCMD()); commands.add(new UnfreezeCMD()); + commands.add(new UnmuteCMD()); commands.add(new WorldCMD()); PlexLog.log(String.format("Registered %s commands!", commands.size())); } diff --git a/src/main/java/dev/plex/listener/impl/ChatListener.java b/src/main/java/dev/plex/listener/impl/ChatListener.java index 82588b6..7aaa501 100644 --- a/src/main/java/dev/plex/listener/impl/ChatListener.java +++ b/src/main/java/dev/plex/listener/impl/ChatListener.java @@ -26,6 +26,12 @@ public class ChatListener extends PlexListener public void onChat(AsyncChatEvent event) { PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(event.getPlayer().getUniqueId()); + if (PlayerCache.getPunishedPlayer(event.getPlayer().getUniqueId()).isMuted()) + { + event.getPlayer().sendMessage(PlexUtils.messageComponent("muted")); + event.setCancelled(true); + return; + } String prefix = plugin.getRankManager().getPrefix(plexPlayer); if (!prefix.isEmpty()) diff --git a/src/main/java/dev/plex/punishment/PunishmentManager.java b/src/main/java/dev/plex/punishment/PunishmentManager.java index b111f74..79b93ef 100644 --- a/src/main/java/dev/plex/punishment/PunishmentManager.java +++ b/src/main/java/dev/plex/punishment/PunishmentManager.java @@ -219,7 +219,6 @@ public class PunishmentManager extends PlexBase } player.setFrozen(false); Bukkit.broadcast(PlexUtils.messageComponent("unfrozePlayer", "Plex", Bukkit.getOfflinePlayer(UUID.fromString(player.getUuid())).getName())); - Bukkit.getLogger().info("Unfroze"); } }.runTaskLater(Plex.get(), 20 * seconds); } @@ -234,7 +233,13 @@ public class PunishmentManager extends PlexBase @Override public void run() { + if (!player.isMuted()) + { + this.cancel(); + return; + } player.setMuted(false); + Bukkit.broadcast(PlexUtils.messageComponent("unmutedPlayer", "Plex", Bukkit.getOfflinePlayer(UUID.fromString(player.getUuid())).getName())); } }.runTaskLater(Plex.get(), 20 * seconds); } diff --git a/src/main/java/dev/plex/rank/enums/Rank.java b/src/main/java/dev/plex/rank/enums/Rank.java index 6edab2a..9d68429 100644 --- a/src/main/java/dev/plex/rank/enums/Rank.java +++ b/src/main/java/dev/plex/rank/enums/Rank.java @@ -2,6 +2,8 @@ package dev.plex.rank.enums; import lombok.Getter; import lombok.Setter; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.ChatColor; import org.json.JSONObject; @@ -39,6 +41,11 @@ public enum Rank return this.level >= rank.getLevel(); } + public String getPrefix() + { + return MiniMessage.miniMessage().serialize(LegacyComponentSerializer.legacyAmpersand().deserialize(this.prefix)); + } + public JSONObject toJSON() { JSONObject object = new JSONObject(); diff --git a/src/main/java/dev/plex/rank/enums/Title.java b/src/main/java/dev/plex/rank/enums/Title.java index 7962737..447465e 100644 --- a/src/main/java/dev/plex/rank/enums/Title.java +++ b/src/main/java/dev/plex/rank/enums/Title.java @@ -2,6 +2,8 @@ package dev.plex.rank.enums; import lombok.Getter; import lombok.Setter; +import net.kyori.adventure.text.minimessage.MiniMessage; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.bukkit.ChatColor; import org.json.JSONObject; @@ -31,6 +33,11 @@ public enum Title this.prefix = prefix; } + public String getPrefix() + { + return MiniMessage.miniMessage().serialize(LegacyComponentSerializer.legacyAmpersand().deserialize(this.prefix)); + } + public JSONObject toJSON() { JSONObject object = new JSONObject(); diff --git a/src/main/java/dev/plex/util/PlexUtils.java b/src/main/java/dev/plex/util/PlexUtils.java index 8951cb2..2106fa4 100644 --- a/src/main/java/dev/plex/util/PlexUtils.java +++ b/src/main/java/dev/plex/util/PlexUtils.java @@ -40,8 +40,8 @@ public class PlexUtils extends PlexBase public static Map CHAT_COLOR_NAMES; public static List CHAT_COLOR_POOL; public static List DEVELOPERS = - Arrays.asList("78408086-1991-4c33-a571-d8fa325465b2" // Telesphoreo -// "f5cd54c4-3a24-4213-9a56-c06c49594dff" // Taahh + Arrays.asList("78408086-1991-4c33-a571-d8fa325465b2", // Telesphoreo + "f5cd54c4-3a24-4213-9a56-c06c49594dff" // Taahh ); private static final Random RANDOM; diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index dd4867a..1499d14 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -44,6 +44,14 @@ frozePlayer: " - Froze " # 1. The person who is unfreezing # 2. The person who has been unfrozen unfrozePlayer: " - Unfroze " + +# 1. The person who is freezing +# 2. The person who has been frozen +mutedPlayer: " - Muted " +# 1. The person who is unfreezing +# 2. The person who has been unfrozen +unmutedPlayer: " - Unmuted " + noPermission: "You cannot use this command!" # 1. The rank required to use the command noPermissionRank: "You must be at least to use this command!" @@ -99,7 +107,17 @@ banningPlayer: " - Banning " # 1. The command sender # 2. The player unbanningPlayer: " - Unbanning " + playerNotBanned: "That player is not banned!" +playerNotFrozen: "That player is not frozen!" +playerNotMuted: "That player is not muted!" + +playerBanned: "That player is already banned!" +playerFrozen: "That player is already frozen!" +playerMuted: "That player is already muted!" + +muted: "You are currently muted!" + teleportedToWorldSpawn: "Teleporting to the local spawn" toggleCommandSpy: "CommandSpy has been" enabled: "enabled."