PurpleIRC-spigot/src/main/java/com/cnaude/purpleirc/IRCConsoleCommandSender.java

230 lines
6.8 KiB
Java
Raw Normal View History

2015-02-07 05:15:53 +01:00
/*
* Copyright (C) 2014 cnaude
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cnaude.purpleirc;
2016-11-17 04:40:19 +01:00
import com.cnaude.purpleirc.IRCMessage.Type;
2015-02-07 05:15:53 +01:00
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.conversations.Conversation;
import org.bukkit.conversations.ConversationAbandonedEvent;
2015-02-07 05:15:53 +01:00
import org.bukkit.permissions.Permission;
import org.bukkit.permissions.PermissionAttachment;
2015-02-07 05:15:53 +01:00
import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
2015-02-07 05:15:53 +01:00
/**
*
* @author Chris Naude We have to implement our own CommandSender so that we can
* receive output from the command dispatcher.
*/
public class IRCConsoleCommandSender implements ConsoleCommandSender {
2015-02-07 05:15:53 +01:00
private final PurpleBot ircBot;
private final String target;
private final PurpleIRC plugin;
2016-11-17 04:40:19 +01:00
private final Type type;
2015-02-07 05:15:53 +01:00
private final String name;
/**
*
* @param message
*/
@Override
public void sendMessage(String message) {
2016-01-07 06:57:44 +01:00
if (!message.isEmpty()) {
plugin.logDebug("sendMessage: " + message);
addMessageToQueue(message);
}
2015-02-07 05:15:53 +01:00
}
/**
*
* @param messages
*/
@Override
public void sendMessage(String[] messages) {
for (String message : messages) {
2016-01-07 06:57:44 +01:00
if (!message.isEmpty()) {
plugin.logDebug("sendMessage[]: " + message);
addMessageToQueue(message);
}
2015-02-07 05:15:53 +01:00
}
}
private void addMessageToQueue(String message) {
ircBot.messageQueue.add(new IRCMessage(target,
2016-11-17 04:40:19 +01:00
plugin.colorConverter.gameColorsToIrc(message), type));
2015-02-07 05:15:53 +01:00
}
/**
*
* @param ircBot
* @param target
* @param plugin the PurpleIRC plugin
2016-11-17 04:40:19 +01:00
* @param type
2015-02-07 05:15:53 +01:00
* @param name
*/
2016-11-17 04:40:19 +01:00
public IRCConsoleCommandSender(PurpleBot ircBot, String target, PurpleIRC plugin, Type type, String name) {
2015-02-07 05:15:53 +01:00
super();
this.target = target;
this.ircBot = ircBot;
this.plugin = plugin;
2016-11-17 04:40:19 +01:00
this.type = type;
2015-02-07 05:15:53 +01:00
this.name = name;
}
/**
*
* @return
*/
@Override
public Server getServer() {
return Bukkit.getServer();
}
/**
*
* @return
*/
@Override
public String getName() {
return name;
}
/**
*
* @return
*/
@Override
public Set<PermissionAttachmentInfo> getEffectivePermissions() {
return null;
}
/**
*
* @param perm
* @return
*/
@Override
public boolean hasPermission(final String perm) {
return true;
}
/**
*
* @param arg0
* @return
*/
@Override
public boolean hasPermission(final Permission arg0) {
return true;
}
/**
*
* @param arg0
* @return
*/
@Override
public boolean isPermissionSet(final String arg0) {
return true;
}
/**
*
* @param arg0
* @return
*/
@Override
public boolean isPermissionSet(final Permission arg0) {
return true;
}
2015-03-13 15:35:54 +01:00
2015-02-07 05:15:53 +01:00
@Override
public void sendRawMessage(String string) {
plugin.logDebug("sendRawMessage: " + string);
}
@Override
public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public PermissionAttachment addAttachment(Plugin plugin) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public PermissionAttachment addAttachment(Plugin plugin, String string, boolean bln, int i) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public PermissionAttachment addAttachment(Plugin plugin, int i) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void removeAttachment(PermissionAttachment pa) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void recalculatePermissions() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean isOp() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void setOp(boolean bln) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean isConversing() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void acceptConversationInput(String string) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean beginConversation(Conversation c) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void abandonConversation(Conversation c) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void abandonConversation(Conversation c, ConversationAbandonedEvent cae) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
2015-02-07 05:15:53 +01:00
}