- Add unmute & mute and some checks as well as fix prefix bug

This commit is contained in:
Taah 2022-02-25 00:59:48 -08:00
parent bc461ee870
commit 1b856db297
12 changed files with 197 additions and 5 deletions

View File

@ -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)

View File

@ -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();

View File

@ -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 = "/<command> <player>", 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<String> 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();
}
}

View File

@ -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

View File

@ -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 = "/<command> <player>")
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<String> 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();
}
}

View File

@ -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()));
}

View File

@ -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())

View File

@ -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);
}

View File

@ -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();

View File

@ -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();

View File

@ -40,8 +40,8 @@ public class PlexUtils extends PlexBase
public static Map<String, ChatColor> CHAT_COLOR_NAMES;
public static List<ChatColor> CHAT_COLOR_POOL;
public static List<String> 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;

View File

@ -44,6 +44,14 @@ frozePlayer: "<aqua><v> - Froze <v>"
# 1. The person who is unfreezing
# 2. The person who has been unfrozen
unfrozePlayer: "<aqua><v> - Unfroze <v>"
# 1. The person who is freezing
# 2. The person who has been frozen
mutedPlayer: "<aqua><v> - Muted <v>"
# 1. The person who is unfreezing
# 2. The person who has been unfrozen
unmutedPlayer: "<aqua><v> - Unmuted <v>"
noPermission: "<red>You cannot use this command!"
# 1. The rank required to use the command
noPermissionRank: "<red>You must be at least <v> to use this command!"
@ -99,7 +107,17 @@ banningPlayer: "<red><v> - Banning <v>"
# 1. The command sender
# 2. The player
unbanningPlayer: "<aqua><v> - Unbanning <v>"
playerNotBanned: "<red>That player is not banned!"
playerNotFrozen: "<red>That player is not frozen!"
playerNotMuted: "<red>That player is not muted!"
playerBanned: "<red>That player is already banned!"
playerFrozen: "<red>That player is already frozen!"
playerMuted: "<red>That player is already muted!"
muted: "<red>You are currently muted!"
teleportedToWorldSpawn: "<aqua>Teleporting to the local spawn"
toggleCommandSpy: "CommandSpy has been"
enabled: "enabled."