2011-03-19 23:39:51 +01:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2013-10-16 21:59:39 +02:00
|
|
|
import com.earth2me.essentials.CommandSource;
|
2011-04-05 17:57:54 +02:00
|
|
|
import com.earth2me.essentials.Console;
|
2011-07-18 03:42:21 +02:00
|
|
|
import com.earth2me.essentials.User;
|
2015-10-27 18:34:59 +01:00
|
|
|
import com.earth2me.essentials.messaging.IMessageRecipient;
|
2020-07-06 20:52:51 +02:00
|
|
|
import com.earth2me.essentials.utils.DateUtil;
|
2013-06-08 23:31:19 +02:00
|
|
|
import com.earth2me.essentials.utils.FormatUtil;
|
2015-10-27 18:34:59 +01:00
|
|
|
import org.bukkit.Server;
|
2015-04-15 06:06:16 +02:00
|
|
|
|
2017-06-11 02:17:43 +02:00
|
|
|
import java.util.List;
|
2015-04-15 06:06:16 +02:00
|
|
|
|
2020-07-06 20:52:51 +02:00
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
public class Commandmsg extends EssentialsLoopCommand {
|
|
|
|
public Commandmsg() {
|
|
|
|
super("msg");
|
|
|
|
}
|
2013-09-28 18:21:16 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
@Override
|
|
|
|
public void run(Server server, CommandSource sender, String commandLabel, String[] args) throws Exception {
|
2020-08-11 20:09:22 +02:00
|
|
|
if (args.length < 2) {
|
2015-04-15 06:06:16 +02:00
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
2013-03-20 02:00:50 +01:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
String message = getFinalArg(args, 1);
|
2020-08-11 20:09:22 +02:00
|
|
|
boolean canWildcard = sender.isAuthorized("essentials.msg.multiple", ess);
|
2015-04-15 06:06:16 +02:00
|
|
|
if (sender.isPlayer()) {
|
|
|
|
User user = ess.getUser(sender.getPlayer());
|
|
|
|
if (user.isMuted()) {
|
2020-07-06 20:52:51 +02:00
|
|
|
String dateDiff = user.getMuteTimeout() > 0 ? DateUtil.formatDateDiff(user.getMuteTimeout()) : null;
|
|
|
|
if (dateDiff == null) {
|
|
|
|
throw new Exception(user.hasMuteReason() ? tl("voiceSilencedReason", user.getMuteReason()) : tl("voiceSilenced"));
|
|
|
|
}
|
|
|
|
throw new Exception(user.hasMuteReason() ? tl("voiceSilencedReasonTime", dateDiff, user.getMuteReason()) : tl("voiceSilencedTime", dateDiff));
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
|
|
|
message = FormatUtil.formatMessage(user, "essentials.msg", message);
|
|
|
|
} else {
|
|
|
|
message = FormatUtil.replaceFormat(message);
|
|
|
|
}
|
2013-03-20 02:00:50 +01:00
|
|
|
|
2015-10-27 18:34:59 +01:00
|
|
|
// Sending messages to console
|
2015-04-15 06:06:16 +02:00
|
|
|
if (args[0].equalsIgnoreCase(Console.NAME)) {
|
2015-10-27 18:34:59 +01:00
|
|
|
IMessageRecipient messageSender = sender.isPlayer() ? ess.getUser(sender.getPlayer()) : Console.getInstance();
|
|
|
|
messageSender.sendMessage(Console.getInstance(), message);
|
2015-04-15 06:06:16 +02:00
|
|
|
return;
|
|
|
|
}
|
2013-03-20 02:00:50 +01:00
|
|
|
|
2020-08-11 20:09:22 +02:00
|
|
|
loopOnlinePlayers(server, sender, false, canWildcard, args[0], new String[]{message});
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
2013-01-20 22:52:23 +01:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
@Override
|
2015-10-27 18:34:59 +01:00
|
|
|
protected void updatePlayer(final Server server, final CommandSource sender, final User messageReceiver, final String[] args) {
|
|
|
|
IMessageRecipient messageSender = sender.isPlayer() ? ess.getUser(sender.getPlayer()) : Console.getInstance();
|
|
|
|
messageSender.sendMessage(messageReceiver, args[0]); // args[0] is the message.
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
2017-06-11 02:17:43 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
|
|
|
|
if (args.length == 1) {
|
|
|
|
return getPlayers(server, sender);
|
|
|
|
} else {
|
|
|
|
return null; // It's a chat message, use the default chat handler
|
|
|
|
}
|
|
|
|
}
|
2011-03-19 23:39:51 +01:00
|
|
|
}
|