From 92a2244650542b4ded18454192c6f0f4bc996395 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sun, 18 Aug 2013 21:02:47 +0100 Subject: Add muting offline players Permission: essentials.mute.offline --- .../earth2me/essentials/commands/Commandmute.java | 57 ++++++++++++++++------ Essentials/src/messages.properties | 12 ++--- Essentials/src/messages_en.properties | 12 ++--- 3 files changed, 54 insertions(+), 27 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java index ccaa76275..9ef7f5662 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandmute.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandmute.java @@ -1,6 +1,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.OfflinePlayer; import com.earth2me.essentials.User; import com.earth2me.essentials.utils.DateUtil; import org.bukkit.Server; @@ -18,50 +19,76 @@ public class Commandmute extends EssentialsCommand @Override public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception { + boolean nomatch = false; if (args.length < 1) { throw new NotEnoughArgumentsException(); } - - final User player = getPlayer(server, sender, args, 0); - if (sender instanceof Player && !player.isMuted() && player.isAuthorized("essentials.mute.exempt")) + User user; + try + { + user = getPlayer(server, args, 0, true, true); + } + catch (NoSuchFieldException e) + { + nomatch = true; + user = ess.getUser(new OfflinePlayer(args[0], ess)); + } + if (!user.isOnline()) + { + if (sender instanceof Player + && !ess.getUser(sender).isAuthorized("essentials.mute.offline")) + { + throw new Exception(_("muteExempt")); + } + } + else { - throw new Exception(_("muteExempt")); + if (user.isAuthorized("essentials.mute.exempt") && sender instanceof Player) + { + throw new Exception(_("muteExempt")); + } } + long muteTimestamp = 0; if (args.length > 1) { final String time = getFinalArg(args, 1); muteTimestamp = DateUtil.parseDateDiff(time, true); - player.setMuted(true); + user.setMuted(true); } else { - player.setMuted(!player.getMuted()); + user.setMuted(!user.getMuted()); } - player.setMuteTimeout(muteTimestamp); - final boolean muted = player.getMuted(); + user.setMuteTimeout(muteTimestamp); + final boolean muted = user.getMuted(); String muteTime = DateUtil.formatDateDiff(muteTimestamp); + if (nomatch) + { + sender.sendMessage(_("userUnknown", user.getName())); + } + if (muted) { if (muteTimestamp > 0) { - sender.sendMessage(_("mutedPlayerFor", player.getDisplayName(), muteTime)); - player.sendMessage(_("playerMutedFor", muteTime)); + sender.sendMessage(_("mutedPlayerFor", user.getDisplayName(), muteTime)); + user.sendMessage(_("playerMutedFor", muteTime)); } else { - sender.sendMessage(_("mutedPlayer", player.getDisplayName())); - player.sendMessage(_("playerMuted")); + sender.sendMessage(_("mutedPlayer", user.getDisplayName())); + user.sendMessage(_("playerMuted")); } - ess.broadcastMessage("essentials.mute.notify", _("muteNotify", sender.getName(), player.getName(), muteTime)); + ess.broadcastMessage("essentials.mute.notify", _("muteNotify", sender.getName(), user.getName(), muteTime)); } else { - sender.sendMessage(_("unmutedPlayer", player.getDisplayName())); - player.sendMessage(_("playerUnmuted")); + sender.sendMessage(_("unmutedPlayer", user.getDisplayName())); + user.sendMessage(_("playerUnmuted")); } } } diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index 2440392c7..280172058 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -250,9 +250,9 @@ msgFormat=\u00a76[{0}\u00a76 -> {1}\u00a76] \u00a7r{2} multipleCharges=\u00a74You cannot apply more than one charge to this firework. multiplePotionEffects=\u00a74You cannot apply more than one effect to this potion. muteExempt=\u00a74You may not mute that player. -muteNotify=\u00a74{0} \u00a76has muted \u00a74{1}\u00a76. -mutedPlayer=\u00a76Player {0} \u00a76muted. -mutedPlayerFor=\u00a76Player {0} \u00a76muted for {1}. +muteNotify=\u00a7c{0} \u00a76has muted \u00a7c{1}\u00a76. +mutedPlayer=\u00a76Player\u00a7c {0} \u00a76muted. +mutedPlayerFor=\u00a76Player\u00a7c {0} \u00a76muted for\u00a7c {1}\u00a76. mutedUserSpeaks={0} tried to speak, but is muted. nearbyPlayers=\u00a76Players nearby\:\u00a7r {0} negativeBalanceError=\u00a74User is not allowed to have a negative balance. @@ -319,8 +319,8 @@ pWeatherPlayers=\u00a76These players have their own weather\:\u00a7r pWeatherReset=\u00a76Player weather has been reset for\: \u00a7c{0} pWeatherSet=\u00a76Player weather is set to \u00a7c{0}\u00a76 for\: \u00a7c{1}. pendingTeleportCancelled=\u00a74Pending teleportation request cancelled. -playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address {1}\u00a76. -playerBanned=\u00a76Player\u00a7c {0} \u00a76banned {1} \u00a76for {2}. +playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address\u00a7c {1}\u00a76. +playerBanned=\u00a76Player\u00a7c {0} \u00a76banned\u00a7c {1} \u00a76for {2}. playerInJail=\u00a74Player is already in jail\u00a7c {0}\u00a76. playerJailed=\u00a76Player\u00a7c {0} \u00a76jailed. playerJailedFor=\u00a76Player\u00a7c {0} \u00a76jailed for {1}. @@ -330,7 +330,7 @@ playerMutedFor=\u00a76You have been muted for\u00a7c {0}. playerNeverOnServer=\u00a74Player\u00a7c {0} \u00a74was never on this server. playerNotFound=\u00a74Player not found. playerUnbanIpAddress=\u00a76Player\u00a7c {0} \u00a76unbanned IP\: {1}. -playerUnbanned=\u00a76Player\u00a7c {0} \u00a76unbanned {1}. +playerUnbanned=\u00a76Player\u00a7c {0} \u00a76unbanned\u00a7c {1}. playerUnmuted=\u00a76You have been unmuted. pong=Pong\! posPitch=\u00a76Pitch\: {0} (Head angle) diff --git a/Essentials/src/messages_en.properties b/Essentials/src/messages_en.properties index 2440392c7..280172058 100644 --- a/Essentials/src/messages_en.properties +++ b/Essentials/src/messages_en.properties @@ -250,9 +250,9 @@ msgFormat=\u00a76[{0}\u00a76 -> {1}\u00a76] \u00a7r{2} multipleCharges=\u00a74You cannot apply more than one charge to this firework. multiplePotionEffects=\u00a74You cannot apply more than one effect to this potion. muteExempt=\u00a74You may not mute that player. -muteNotify=\u00a74{0} \u00a76has muted \u00a74{1}\u00a76. -mutedPlayer=\u00a76Player {0} \u00a76muted. -mutedPlayerFor=\u00a76Player {0} \u00a76muted for {1}. +muteNotify=\u00a7c{0} \u00a76has muted \u00a7c{1}\u00a76. +mutedPlayer=\u00a76Player\u00a7c {0} \u00a76muted. +mutedPlayerFor=\u00a76Player\u00a7c {0} \u00a76muted for\u00a7c {1}\u00a76. mutedUserSpeaks={0} tried to speak, but is muted. nearbyPlayers=\u00a76Players nearby\:\u00a7r {0} negativeBalanceError=\u00a74User is not allowed to have a negative balance. @@ -319,8 +319,8 @@ pWeatherPlayers=\u00a76These players have their own weather\:\u00a7r pWeatherReset=\u00a76Player weather has been reset for\: \u00a7c{0} pWeatherSet=\u00a76Player weather is set to \u00a7c{0}\u00a76 for\: \u00a7c{1}. pendingTeleportCancelled=\u00a74Pending teleportation request cancelled. -playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address {1}\u00a76. -playerBanned=\u00a76Player\u00a7c {0} \u00a76banned {1} \u00a76for {2}. +playerBanIpAddress=\u00a76Player\u00a7c {0} \u00a76banned IP address\u00a7c {1}\u00a76. +playerBanned=\u00a76Player\u00a7c {0} \u00a76banned\u00a7c {1} \u00a76for {2}. playerInJail=\u00a74Player is already in jail\u00a7c {0}\u00a76. playerJailed=\u00a76Player\u00a7c {0} \u00a76jailed. playerJailedFor=\u00a76Player\u00a7c {0} \u00a76jailed for {1}. @@ -330,7 +330,7 @@ playerMutedFor=\u00a76You have been muted for\u00a7c {0}. playerNeverOnServer=\u00a74Player\u00a7c {0} \u00a74was never on this server. playerNotFound=\u00a74Player not found. playerUnbanIpAddress=\u00a76Player\u00a7c {0} \u00a76unbanned IP\: {1}. -playerUnbanned=\u00a76Player\u00a7c {0} \u00a76unbanned {1}. +playerUnbanned=\u00a76Player\u00a7c {0} \u00a76unbanned\u00a7c {1}. playerUnmuted=\u00a76You have been unmuted. pong=Pong\! posPitch=\u00a76Pitch\: {0} (Head angle) -- cgit v1.2.3