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

45 lines
1.5 KiB
Java

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.FormatUtil;
import org.bukkit.Server;
import static com.earth2me.essentials.I18n.tl;
public class Commandr extends EssentialsCommand {
public Commandr() {
super("r");
}
@Override
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
if (args.length < 1) {
throw new NotEnoughArgumentsException();
}
String message = getFinalArg(args, 0);
IMessageRecipient messageSender;
if (sender.isPlayer()) {
User user = ess.getUser(sender.getPlayer());
message = FormatUtil.formatMessage(user, "essentials.msg", message);
messageSender = user;
} else {
message = FormatUtil.replaceFormat(message);
messageSender = Console.getInstance();
}
final IMessageRecipient target = messageSender.getReplyRecipient();
// Check to make sure the sender does have a quick-reply recipient, and that the recipient is online.
if (target == null || (target instanceof User && !((User) target).getBase().isOnline())) {
throw new Exception(tl("foreverAlone"));
}
messageSender.sendMessage(target, message);
}
}