TF-EssentialsX/Essentials/src/com/earth2me/essentials/Console.java
Ali Moghnieh 26045e2ec0 Add isReachable API to IMessageRecipient.
Add translatable message recentlyForeverAlone.
Add behaviour that preserves reply-recipient only if they are reachable, and update reply-recipient if they are not reachable.
Fixes #248
2015-10-30 19:58:30 +00:00

78 lines
2.2 KiB
Java

package com.earth2me.essentials;
import com.earth2me.essentials.messaging.IMessageRecipient;
import com.earth2me.essentials.messaging.SimpleMessageRecipient;
import org.bukkit.Server;
import org.bukkit.command.CommandSender;
public final class Console implements IMessageRecipient {
public static final String NAME = "Console";
private static Console instance; // Set in essentials
private final IEssentials ess;
private final IMessageRecipient messageRecipient;
public static Console getInstance() {
return instance;
}
static void setInstance(IEssentials ess) { // Called in Essentials#onEnable()
instance = new Console(ess);
}
/**
* @deprecated Use {@link Console#getCommandSender()}
*/
@Deprecated
public static CommandSender getCommandSender(Server server) throws Exception {
return server.getConsoleSender();
}
private Console(IEssentials ess) {
this.ess = ess;
this.messageRecipient = new SimpleMessageRecipient(ess, this);
}
public CommandSender getCommandSender() {
return ess.getServer().getConsoleSender();
}
@Override public String getName() {
return Console.NAME;
}
@Override public String getDisplayName() {
return Console.NAME;
}
@Override public void sendMessage(String message) {
getCommandSender().sendMessage(message);
}
@Override public boolean isReachable() {
return true;
}
/* ================================
* >> DELEGATE METHODS
* ================================ */
@Override public MessageResponse sendMessage(IMessageRecipient recipient, String message) {
return this.messageRecipient.sendMessage(recipient, message);
}
@Override public MessageResponse onReceiveMessage(IMessageRecipient sender, String message) {
return this.messageRecipient.onReceiveMessage(sender, message);
}
@Override public IMessageRecipient getReplyRecipient() {
return this.messageRecipient.getReplyRecipient();
}
@Override public void setReplyRecipient(IMessageRecipient recipient) {
this.messageRecipient.setReplyRecipient(recipient);
}
}