2011-07-24 21:19:12 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
|
|
|
import com.earth2me.essentials.User;
|
|
|
|
import com.earth2me.essentials.Util;
|
2011-11-18 17:42:26 +00:00
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2011-07-24 21:19:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
public class Commandmute extends EssentialsCommand
|
|
|
|
{
|
|
|
|
public Commandmute()
|
|
|
|
{
|
|
|
|
super("mute");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-11-18 13:48:31 +00:00
|
|
|
public void run(final Server server, final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
2011-07-24 21:19:12 +00:00
|
|
|
{
|
|
|
|
if (args.length < 1)
|
|
|
|
{
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
|
|
|
|
2011-11-18 13:48:31 +00:00
|
|
|
final User player = getPlayer(server, args, 0, true);
|
|
|
|
if (!player.isMuted() && player.isAuthorized("essentials.mute.exempt"))
|
2011-07-24 21:19:12 +00:00
|
|
|
{
|
2011-08-27 21:14:49 +00:00
|
|
|
throw new Exception(Util.i18n("muteExempt"));
|
2011-07-24 21:19:12 +00:00
|
|
|
}
|
|
|
|
long muteTimestamp = 0;
|
|
|
|
if (args.length > 1)
|
|
|
|
{
|
|
|
|
String time = getFinalArg(args, 1);
|
|
|
|
muteTimestamp = Util.parseDateDiff(time, true);
|
|
|
|
}
|
2011-11-18 13:48:31 +00:00
|
|
|
player.setMuteTimeout(muteTimestamp);
|
|
|
|
final boolean muted = player.toggleMuted();
|
2011-07-24 21:19:12 +00:00
|
|
|
sender.sendMessage(
|
|
|
|
muted
|
|
|
|
? (muteTimestamp > 0
|
2011-11-18 13:48:31 +00:00
|
|
|
? Util.format("mutedPlayerFor", player.getDisplayName(), Util.formatDateDiff(muteTimestamp))
|
|
|
|
: Util.format("mutedPlayer", player.getDisplayName()))
|
|
|
|
: Util.format("unmutedPlayer", player.getDisplayName()));
|
|
|
|
player.sendMessage(
|
2011-07-24 21:19:12 +00:00
|
|
|
muted
|
|
|
|
? (muteTimestamp > 0
|
|
|
|
? Util.format("playerMutedFor", Util.formatDateDiff(muteTimestamp))
|
|
|
|
: Util.i18n("playerMuted"))
|
|
|
|
: Util.i18n("playerUnmuted"));
|
|
|
|
}
|
|
|
|
}
|