From 19ab706cc40b685fa36196afc461d9d02003c5e0 Mon Sep 17 00:00:00 2001 From: Brianna Date: Sun, 2 Jun 2019 18:48:51 -0400 Subject: [PATCH] You can no longer ban or mute a player who is already banned or muted. --- .../ultimatemoderation/command/commands/CommandBan.java | 6 ++++++ .../ultimatemoderation/command/commands/CommandMute.java | 6 ++++++ .../ultimatemoderation/command/commands/CommandUnBan.java | 6 ++++++ .../ultimatemoderation/command/commands/CommandUnMute.java | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandBan.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandBan.java index 753ea1e..df4dca2 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandBan.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandBan.java @@ -50,6 +50,12 @@ public class CommandBan extends AbstractCommand { return ReturnType.FAILURE; } + if (instance.getPunishmentManager().getPlayer(player).getActivePunishments() + .stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.BAN)) { + sender.sendMessage(instance.getReferences().getPrefix() + "That player is already banned."); + return ReturnType.FAILURE; + } + new Punishment(PunishmentType.BAN, duration == 0 ? -1 : duration, reason.equals("") ? null : reason) .execute(sender, player); diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandMute.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandMute.java index b06876e..1a6207e 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandMute.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandMute.java @@ -50,6 +50,12 @@ public class CommandMute extends AbstractCommand { return ReturnType.FAILURE; } + if (instance.getPunishmentManager().getPlayer(player).getActivePunishments() + .stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.MUTE)) { + sender.sendMessage(instance.getReferences().getPrefix() + "That player is already muted."); + return ReturnType.FAILURE; + } + new Punishment(PunishmentType.MUTE, duration == 0 ? -1 : duration, reason.equals("") ? null : reason) .execute(sender, player); diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandUnBan.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandUnBan.java index 705806d..1f4a0ed 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandUnBan.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandUnBan.java @@ -33,6 +33,12 @@ public class CommandUnBan extends AbstractCommand { return ReturnType.FAILURE; } + if (!instance.getPunishmentManager().getPlayer(player).getActivePunishments() + .stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.BAN)) { + sender.sendMessage(instance.getReferences().getPrefix() + "That player isn't banned."); + return ReturnType.FAILURE; + } + PlayerPunishData playerPunishData = instance.getPunishmentManager().getPlayer(player); playerPunishData.expirePunishments(PunishmentType.BAN); diff --git a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandUnMute.java b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandUnMute.java index f696acc..1184347 100644 --- a/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandUnMute.java +++ b/src/main/java/com/songoda/ultimatemoderation/command/commands/CommandUnMute.java @@ -32,6 +32,12 @@ public class CommandUnMute extends AbstractCommand { return ReturnType.FAILURE; } + if (!instance.getPunishmentManager().getPlayer(player).getActivePunishments() + .stream().anyMatch(appliedPunishment -> appliedPunishment.getPunishmentType() == PunishmentType.MUTE)) { + sender.sendMessage(instance.getReferences().getPrefix() + "That player isn't muted."); + return ReturnType.FAILURE; + } + PlayerPunishData playerPunishData = instance.getPunishmentManager().getPlayer(player); playerPunishData.expirePunishments(PunishmentType.MUTE);