forked from EssentialsX/Essentials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandmsg.java
More file actions
66 lines (57 loc) · 2.85 KB
/
Commandmsg.java
File metadata and controls
66 lines (57 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.Console;
import com.earth2me.essentials.User;
import com.earth2me.essentials.messaging.IMessageRecipient;
import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.FormatUtil;
import net.ess3.api.TranslatableException;
import org.bukkit.Server;
import java.util.Collections;
import java.util.List;
public class Commandmsg extends EssentialsLoopCommand {
public Commandmsg() {
super("msg");
}
@Override
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
if (args.length < 2) {
throw new NotEnoughArgumentsException();
}
String message = getFinalArg(args, 1);
final boolean canWildcard = sender.isAuthorized("essentials.msg.multiple");
if (sender.isPlayer()) {
final User user = ess.getUser(sender.getPlayer());
if (user.isMuted()) {
final String dateDiff = user.getMuteTimeout() > 0 ? DateUtil.formatDateDiff(user.getMuteTimeout()) : null;
if (dateDiff == null) {
throw new TranslatableException(user.hasMuteReason() ? "voiceSilencedReason" : "voiceSilenced", user.getMuteReason());
}
throw new TranslatableException(user.hasMuteReason() ? "voiceSilencedReasonTime" : "voiceSilencedTime", dateDiff, user.getMuteReason());
}
message = FormatUtil.formatMessage(user, "essentials.msg", message);
} else {
message = FormatUtil.replaceFormat(message);
}
// Sending messages to console
if (args[0].equalsIgnoreCase(Console.NAME) || args[0].equalsIgnoreCase(Console.displayName())) {
final IMessageRecipient messageSender = sender.isPlayer() ? ess.getUser(sender.getPlayer()) : Console.getInstance();
messageSender.sendMessage(Console.getInstance(), message);
return;
}
loopOnlinePlayers(server, sender, false, canWildcard, args[0], new String[] {message});
}
@Override
protected void updatePlayer(final Server server, final CommandSource sender, final User messageReceiver, final String[] args) {
final IMessageRecipient messageSender = sender.isPlayer() ? ess.getUser(sender.getPlayer()) : Console.getInstance();
messageSender.sendMessage(messageReceiver, args[0]); // args[0] is the message.
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
if (args.length == 1) {
return getPlayers(sender);
} else {
return Collections.emptyList(); // It's a chat message, send an empty list.
}
}
}