Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

Commit

Permalink
Add AdminPrivateChat listener. (game-a-chat)
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed Dec 14, 2014
1 parent dcc63bd commit 4d59de6
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 13 deletions.
2 changes: 1 addition & 1 deletion dependency-reduced-pom.xml
Expand Up @@ -282,7 +282,7 @@
<dependency>
<groupId>com.cnaude.adminprivatechat</groupId>
<artifactId>AdminPrivateChat</artifactId>
<version>2.0</version>
<version>2.1</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -264,7 +264,7 @@
<dependency>
<groupId>com.cnaude.adminprivatechat</groupId>
<artifactId>AdminPrivateChat</artifactId>
<version>2.0</version>
<version>2.1</version>
</dependency>

<!-- Testing only -->
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/cnaude/purpleirc/CommandQueueWatcher.java
Expand Up @@ -19,6 +19,7 @@
import com.cnaude.purpleirc.Events.IRCCommandEvent;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.bukkit.command.CommandSender;

/**
*
Expand Down Expand Up @@ -75,6 +76,6 @@ public String clearQueue() {
*/
public void add(IRCCommand command) {
plugin.logDebug("Adding command to queue: " + command.getGameCommand());
queue.offer(command);
queue.offer(command);
}
}
@@ -0,0 +1,51 @@
/*
* 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.GameListeners;

import com.ammaraskar.adminonly.AdminChatEvent;
import com.cnaude.purpleirc.PurpleBot;
import com.cnaude.purpleirc.PurpleIRC;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;

/**
*
* @author cnaude
*/
public class AdminChatListener implements Listener {

private final PurpleIRC plugin;

/**
*
* @param plugin
*/
public AdminChatListener(PurpleIRC plugin) {
this.plugin = plugin;
}

/**
*
* @param event
*/
@EventHandler
public void onAdminChatEvent(AdminChatEvent event) {
for (PurpleBot ircBot : plugin.ircBots.values()) {
ircBot.adminChat(event.getName(), event.getMessage(), event.getWorld());
}
}
}
Expand Up @@ -40,6 +40,6 @@ public AdminPrivateChatHook(PurpleIRC plugin) {

public void sendMessage(String message, String playername) {
plugin.logDebug("AdminPrivateChatHook: " + message);
ac.methods.MessageBuild(message, playername);
ac.methods.MessageBuild(message, playername, "");
}
}
38 changes: 30 additions & 8 deletions src/main/java/com/cnaude/purpleirc/IRCCommandSender.java
Expand Up @@ -43,9 +43,8 @@ public class IRCCommandSender implements CommandSender {
*/
@Override
public void sendMessage(String message) {
plugin.logDebug("sendMessage[single]: " + message);
ircBot.messageQueue.add(new IRCMessage(target,
plugin.colorConverter.gameColorsToIrc(message), ctcpResponse));
plugin.logDebug("sendMessage: " + message);
addMessageToQueue(message);
}

/**
Expand All @@ -54,13 +53,19 @@ public void sendMessage(String message) {
*/
@Override
public void sendMessage(String[] messages) {

for (String message : messages) {
plugin.logDebug("sendMessage[multi]: " + message);
ircBot.messageQueue.add(new IRCMessage(target,
plugin.colorConverter.gameColorsToIrc(message), ctcpResponse));
plugin.logDebug("sendMessage[]: " + message);
addMessageToQueue(message);
}
}

private void addMessageToQueue(String message) {

ircBot.messageQueue.add(new IRCMessage(target,
plugin.colorConverter.gameColorsToIrc(message), ctcpResponse));
}

/**
*
* @param ircBot
Expand All @@ -69,10 +74,12 @@ public void sendMessage(String[] messages) {
* @param ctcpResponse
*/
public IRCCommandSender(PurpleBot ircBot, String target, PurpleIRC plugin, boolean ctcpResponse) {
super();
this.target = target;
this.ircBot = ircBot;
this.plugin = plugin;
this.ctcpResponse = ctcpResponse;

}

/**
Expand All @@ -81,6 +88,7 @@ public IRCCommandSender(PurpleBot ircBot, String target, PurpleIRC plugin, boole
*/
@Override
public Server getServer() {

return Bukkit.getServer();
}

Expand All @@ -90,6 +98,7 @@ public Server getServer() {
*/
@Override
public String getName() {

return "CONSOLE";
}

Expand All @@ -99,16 +108,18 @@ public String getName() {
*/
@Override
public Set<PermissionAttachmentInfo> getEffectivePermissions() {

return null;
}

/**
*
* @param arg0
* @param perm
* @return
*/
@Override
public boolean hasPermission(final String arg0) {
public boolean hasPermission(final String perm) {
System.out.println("Perm: " + perm);
return true;
}

Expand All @@ -119,6 +130,7 @@ public boolean hasPermission(final String arg0) {
*/
@Override
public boolean hasPermission(final Permission arg0) {

return true;
}

Expand All @@ -129,6 +141,7 @@ public boolean hasPermission(final Permission arg0) {
*/
@Override
public boolean isPermissionSet(final String arg0) {

return true;
}

Expand All @@ -139,6 +152,7 @@ public boolean isPermissionSet(final String arg0) {
*/
@Override
public boolean isPermissionSet(final Permission arg0) {

return true;
}

Expand All @@ -147,6 +161,7 @@ public boolean isPermissionSet(final Permission arg0) {
*/
@Override
public void recalculatePermissions() {

}

/**
Expand All @@ -155,6 +170,7 @@ public void recalculatePermissions() {
*/
@Override
public void removeAttachment(final PermissionAttachment arg0) {

}

/**
Expand All @@ -163,6 +179,7 @@ public void removeAttachment(final PermissionAttachment arg0) {
*/
@Override
public boolean isOp() {

return true;
}

Expand All @@ -172,6 +189,7 @@ public boolean isOp() {
*/
@Override
public void setOp(final boolean op) {

}

/**
Expand All @@ -181,6 +199,7 @@ public void setOp(final boolean op) {
*/
@Override
public PermissionAttachment addAttachment(final Plugin arg0) {

return null;
}

Expand All @@ -192,6 +211,7 @@ public PermissionAttachment addAttachment(final Plugin arg0) {
*/
@Override
public PermissionAttachment addAttachment(final Plugin arg0, final int arg1) {

return null;
}

Expand All @@ -204,6 +224,7 @@ public PermissionAttachment addAttachment(final Plugin arg0, final int arg1) {
*/
@Override
public PermissionAttachment addAttachment(final Plugin arg0, final String arg1, final boolean arg2) {

return null;
}

Expand All @@ -217,6 +238,7 @@ public PermissionAttachment addAttachment(final Plugin arg0, final String arg1,
*/
@Override
public PermissionAttachment addAttachment(final Plugin arg0, final String arg1, final boolean arg2, final int arg3) {

return null;
}
}
23 changes: 22 additions & 1 deletion src/main/java/com/cnaude/purpleirc/PurpleBot.java
Expand Up @@ -843,7 +843,7 @@ private void loadConfig() {
optionPair.put("modes", config.getString(commandKey + "modes", "*"));
optionPair.put("private", config.getString(commandKey + "private", "false"));
optionPair.put("ctcp", config.getString(commandKey + "ctcp", "false"));
optionPair.put("game_command", config.getString(commandKey + "game_command", ""));
optionPair.put("game_command", config.getString(commandKey + "game_command", ""));
extraCommands.addAll(config.getStringList(commandKey + "extra_commands"));
plugin.logDebug("extra_commands: " + extraCommands.toString());
optionPair.put("private_listen", config.getString(commandKey + "private_listen", "true"));
Expand Down Expand Up @@ -1165,6 +1165,27 @@ public void cleverChat(String cleverBotName, String message) {
}
}

// Called from AdminChatEvent
/**
*
* @param name
* @param message
* @param world
*/
public void adminChat(String name, String message, String world) {
if (!this.isConnected() || world.isEmpty()) {
return;
}
for (String channelName : botChannels) {
if (isMessageEnabled(channelName, TemplateName.GAME_A_CHAT)) {
asyncIRCMessage(channelName, plugin.tokenizer
.gameChatToIRCTokenizer(name, plugin.getMsgTemplate(botNick, TemplateName.GAME_A_CHAT), message)
.replace("%WORLD%", world)
);
}
}
}

// Called from ReportRTS event
/**
*
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/cnaude/purpleirc/PurpleIRC.java
Expand Up @@ -16,6 +16,7 @@
*/
package com.cnaude.purpleirc;

import com.cnaude.purpleirc.GameListeners.AdminChatListener;
import com.cnaude.purpleirc.GameListeners.CleverNotchListener;
import com.cnaude.purpleirc.GameListeners.DeathMessagesListener;
import com.cnaude.purpleirc.GameListeners.DynmapListener;
Expand Down Expand Up @@ -292,6 +293,7 @@ public void onEnable() {
if (isPluginEnabled("AdminPrivateChat")) {
logInfo("Enabling AdminPrivateChat support.");
adminPrivateChatHook = new AdminPrivateChatHook(this);
getServer().getPluginManager().registerEvents(new AdminChatListener(this), this);
} else {
logInfo("AdminPrivateChat not detected.");
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/cnaude/purpleirc/TemplateName.java
Expand Up @@ -123,5 +123,6 @@ public class TemplateName {
public final static String REDDIT_MESSAGES = "reddit-messages";

public final static String IRC_A_RESPONSE = "irc-a-response";
public final static String GAME_A_CHAT = "game-a-chat";

}
2 changes: 2 additions & 0 deletions src/main/resources/SampleBot.yml
Expand Up @@ -177,6 +177,8 @@ channels:
#- broadcast-message
# RedditStream
#- reddit-messages
# AdminPrivateChat messages
#- game-a-chat
# Hero channel destination for IRC messages
hero-channel: admin
# Towny channel destination for IRC messages
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/config.yml
Expand Up @@ -115,6 +115,8 @@ message-format:
irc-notice: '[&4IRC&r] [notice(%CHANNEL%)] %NOTICE% '
# AdminPrivateChat response message in IRC. Set to '' to disable.
irc-a-response: ' &6-> &7[AdminChat]: %MESSAGE%'
# AdinPrivateChat message from game to IRC
game-a-chat: '[%WORLD%] <%NAME%> -> [AdminChat]: %MESSAGE%'
# Message template for Clevernotch bot to IRC messages
clever-send: '[&4BOT]<%NAME%> %MESSAGE%'
# Message templates for mcMMO to IRC messages
Expand Down

0 comments on commit 4d59de6

Please sign in to comment.