From 338b371e4c8f8e5f656f440431f5fdc39040c258 Mon Sep 17 00:00:00 2001 From: pop4959 Date: Sat, 14 Mar 2020 15:12:43 -0700 Subject: [PATCH] Implement max mute time feature (#2807) --- .../com/earth2me/essentials/ISettings.java | 2 ++ .../src/com/earth2me/essentials/Settings.java | 5 +++ .../essentials/commands/Commandmute.java | 31 ++++++++++++------- Essentials/src/config.yml | 4 +++ Essentials/src/messages.properties | 1 + 5 files changed, 32 insertions(+), 11 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/ISettings.java b/Essentials/src/com/earth2me/essentials/ISettings.java index 11ec1e227..7d0963041 100644 --- a/Essentials/src/com/earth2me/essentials/ISettings.java +++ b/Essentials/src/com/earth2me/essentials/ISettings.java @@ -238,6 +238,8 @@ public interface ISettings extends IConf { void setEssentialsChatActive(boolean b); + long getMaxMute(); + long getMaxTempban(); Map getListGroupConfig(); diff --git a/Essentials/src/com/earth2me/essentials/Settings.java b/Essentials/src/com/earth2me/essentials/Settings.java index d90b6e125..6469aa27b 100644 --- a/Essentials/src/com/earth2me/essentials/Settings.java +++ b/Essentials/src/com/earth2me/essentials/Settings.java @@ -1133,6 +1133,11 @@ public class Settings implements net.ess3.api.ISettings { return permissionsLagWarning; } + @Override + public long getMaxMute() { + return config.getLong("max-mute-time", -1); + } + @Override public long getMaxTempban() { return config.getLong("max-tempban-time", -1); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java index 2fac8ce92..a6b9fa90c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java @@ -7,6 +7,7 @@ import com.earth2me.essentials.utils.DateUtil; import net.ess3.api.events.MuteStatusChangeEvent; import org.bukkit.Server; +import java.util.GregorianCalendar; import java.util.List; import java.util.logging.Level; @@ -40,6 +41,25 @@ public class Commandmute extends EssentialsCommand { throw new Exception(tl("muteExempt")); } } + + long muteTimestamp = 0; + String time; + String muteReason = ""; + + if (args.length > 1) { + time = args[1]; + try { + muteTimestamp = DateUtil.parseDateDiff(time, true); + muteReason = getFinalArg(args, 2); + } catch (Exception e) { + muteReason = getFinalArg(args, 1); + } + final long maxMuteLength = ess.getSettings().getMaxMute() * 1000; + if (maxMuteLength > 0 && ((muteTimestamp - GregorianCalendar.getInstance().getTimeInMillis()) > maxMuteLength) && sender.isPlayer() && !(ess.getUser(sender.getPlayer()).isAuthorized("essentials.mute.unlimited"))) { + sender.sendMessage(tl("oversizedMute")); + throw new NoChargeException(); + } + } final boolean willMute = (args.length > 1) || !user.getMuted(); final User controller = sender.isPlayer() ? ess.getUser(sender.getPlayer()) : null; @@ -47,18 +67,7 @@ public class Commandmute extends EssentialsCommand { ess.getServer().getPluginManager().callEvent(event); if (!event.isCancelled()) { - long muteTimestamp = 0; - if (args.length > 1) { - final String time = args[1]; - String muteReason; - try { - muteTimestamp = DateUtil.parseDateDiff(time, true); - muteReason = getFinalArg(args, 2); - } catch (Exception e) { - muteReason = getFinalArg(args, 1); - } - user.setMuteReason(muteReason.isEmpty() ? null : muteReason); user.setMuted(true); } else { diff --git a/Essentials/src/config.yml b/Essentials/src/config.yml index 4d1bfd4bd..fd9b8c345 100644 --- a/Essentials/src/config.yml +++ b/Essentials/src/config.yml @@ -491,6 +491,10 @@ max-walk-speed: 0.8 #Set the maximum amount of mail that can be sent within a minute. mails-per-minute: 1000 +# Set the maximum time /mute can be used for in seconds. +# Set to -1 to disable, and essentials.mute.unlimited can be used to override. +max-mute-time: -1 + # Set the maximum time /tempban can be used for in seconds. # Set to -1 to disable, and essentials.tempban.unlimited can be used to override. max-tempban-time: -1 diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index ec6beab41..523395b40 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -376,6 +376,7 @@ onlyPlayerSkulls=\u00a74You can only set the owner of player skulls (\u00a7c397\ onlySunStorm=\u00a74/weather only supports sun/storm. openingDisposal=\u00a76Opening disposal menu... orderBalances=\u00a76Ordering balances of\u00a7c {0} \u00a76users, please wait... +oversizedMute=§4You may not mute a player for this period of time. oversizedTempban=\u00a74You may not ban a player for this period of time. payConfirmToggleOff=\u00a76You will no longer be prompted to confirm payments. payConfirmToggleOn=\u00a76You will now be prompted to confirm payments.