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

51 lines
1.4 KiB
Java
Raw Normal View History

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