Skip to content

Commit e4d3a69

Browse files
committed
Add /unmute command and broadcast on unmute
/unmute always unmutes (never toggles to mute). Tells the sender if the player is already unmuted. Unmuting now also broadcasts to players with essentials.mute.notify, matching the mute behavior. Fixes #6419
1 parent 218e004 commit e4d3a69

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

Essentials/src/main/java/com/earth2me/essentials/commands/Commandmute.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public Commandmute() {
2121

2222
@Override
2323
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
24+
final boolean isUnmute = commandLabel.toLowerCase(java.util.Locale.ENGLISH).contains("unmute");
2425
boolean nomatch = false;
2526
if (args.length < 1) {
2627
throw new NotEnoughArgumentsException();
@@ -32,19 +33,25 @@ public void run(final Server server, final CommandSource sender, final String co
3233
nomatch = true;
3334
user = ess.getUser(new OfflinePlayerStub(args[0], ess.getServer()));
3435
}
36+
37+
if (isUnmute && !user.getMuted()) {
38+
sender.sendTl("playerNotMuted", user.getDisplayName());
39+
return;
40+
}
41+
3542
if (!user.getBase().isOnline() && sender.isPlayer()) {
3643
if (!sender.isAuthorized("essentials.mute.offline")) {
3744
throw new TranslatableException("muteExemptOffline");
3845
}
39-
} else if (user.isAuthorized("essentials.mute.exempt")) {
46+
} else if (!isUnmute && user.isAuthorized("essentials.mute.exempt")) {
4047
throw new TranslatableException("muteExempt");
4148
}
4249

4350
long muteTimestamp = 0;
4451
final String time;
4552
String muteReason = null;
4653

47-
if (args.length > 1) {
54+
if (!isUnmute && args.length > 1) {
4855
time = args[1];
4956
try {
5057
muteTimestamp = DateUtil.parseDateDiff(time, true);
@@ -59,7 +66,7 @@ public void run(final Server server, final CommandSource sender, final String co
5966
}
6067
}
6168

62-
final boolean willMute = (args.length > 1) || !user.getMuted();
69+
final boolean willMute = !isUnmute && ((args.length > 1) || !user.getMuted());
6370
final User controller = sender.isPlayer() ? ess.getUser(sender.getPlayer()) : null;
6471
final MuteStatusChangeEvent event = new MuteStatusChangeEvent(user, controller, willMute, muteTimestamp, muteReason);
6572
ess.getServer().getPluginManager().callEvent(event);
@@ -121,6 +128,8 @@ public void run(final Server server, final CommandSource sender, final String co
121128
} else {
122129
sender.sendTl("unmutedPlayer", user.getDisplayName());
123130
user.sendTl("playerUnmuted");
131+
ess.getLogger().log(Level.INFO, ess.getAdventureFacet().miniToLegacy(tlLiteral("unmuteNotify", sender.getSender().getName(), user.getName())));
132+
ess.broadcastTl(null, "essentials.mute.notify", "unmuteNotify", new Object[]{sender.getSender().getName(), user.getName()});
124133
}
125134
}
126135
}

Essentials/src/main/resources/messages.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,9 @@ unlinkCommandDescription=Unlinks your Minecraft account from the currently linke
14801480
unlinkCommandUsage=/<command>
14811481
unlinkCommandUsage1=/<command>
14821482
unlinkCommandUsage1Description=Unlinks your Minecraft account from the currently linked Discord account.
1483+
unmuteNotify=<secondary>{0} <primary>unmuted<secondary> {1}<primary>.
14831484
unmutedPlayer=<primary>Player<secondary> {0} <primary>unmuted.
1485+
playerNotMuted=<secondary>{0} <primary>is not muted.
14841486
unsafeTeleportDestination=<dark_red>The teleport destination is unsafe and teleport-safety is disabled.
14851487
unsupportedBrand=<dark_red>The server platform you are currently running does not provide the capabilities for this feature.
14861488
unsupportedFeature=<dark_red>This feature is not supported on the current server version.

Essentials/src/main/resources/messages_en.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,9 @@ unlinkCommandDescription=Unlinks your Minecraft account from the currently linke
14631463
unlinkCommandUsage=/<command>
14641464
unlinkCommandUsage1=/<command>
14651465
unlinkCommandUsage1Description=Unlinks your Minecraft account from the currently linked Discord account.
1466+
unmuteNotify=<secondary>{0} <primary>unmuted<secondary> {1}<primary>.
14661467
unmutedPlayer=<primary>Player<secondary> {0} <primary>unmuted.
1468+
playerNotMuted=<secondary>{0} <primary>is not muted.
14671469
unsafeTeleportDestination=<dark_red>The teleport destination is unsafe and teleport-safety is disabled.
14681470
unsupportedBrand=<dark_red>The server platform you are currently running does not provide the capabilities for this feature.
14691471
unsupportedFeature=<dark_red>This feature is not supported on the current server version.

Essentials/src/main/resources/plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ commands:
314314
mute:
315315
description: Mutes or unmutes a player.
316316
usage: /<command> <player> [datediff] [reason]
317-
aliases: [emute,silence,esilence]
317+
aliases: [emute,silence,esilence,unmute,eunmute]
318318
near:
319319
description: Lists the players near by or around a player.
320320
usage: /<command> [playername] [radius]

0 commit comments

Comments
 (0)