mirror of
https://github.com/cnaude/PurpleIRC-spigot.git
synced 2025-01-23 16:01:29 +01:00
Add output option for custom commands. See SamepleBot.yml.
This commit is contained in:
parent
8ec2a46c0a
commit
529ac427a1
@ -19,6 +19,7 @@ package com.cnaude.purpleirc;
|
||||
import com.cnaude.purpleirc.Events.IRCCommandEvent;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandException;
|
||||
|
||||
/**
|
||||
@ -66,7 +67,7 @@ public class CommandQueueWatcher {
|
||||
plugin.logDebug("Dispatching command as ConsoleSender: " + ircCommand.getGameCommand());
|
||||
|
||||
plugin.getServer().dispatchCommand(ircCommand.getIRCConsoleCommandSender(), ircCommand.getGameCommand());
|
||||
ircCommand.getIRCConsoleCommandSender().sendMessage("Command sent: " + ircCommand.getGameCommand());
|
||||
ircCommand.getIRCConsoleCommandSender().sendMessage("Command sent: " + ircCommand.getGameCommand());
|
||||
} else {
|
||||
plugin.logDebug("Dispatching command as IRCCommandSender: " + ircCommand.getGameCommand());
|
||||
plugin.getServer().dispatchCommand(ircCommand.getIRCCommandSender(), ircCommand.getGameCommand());
|
||||
|
@ -37,6 +37,7 @@ public class IRCCommandSender implements CommandSender {
|
||||
private final PurpleIRC plugin;
|
||||
private final boolean ctcpResponse;
|
||||
private final String name;
|
||||
private final String template;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -45,7 +46,7 @@ public class IRCCommandSender implements CommandSender {
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
plugin.logDebug("sendMessage: " + message);
|
||||
addMessageToQueue(message);
|
||||
addMessageToQueue(template.replace("%RESULT%", message));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -56,7 +57,7 @@ public class IRCCommandSender implements CommandSender {
|
||||
public void sendMessage(String[] messages) {
|
||||
for (String message : messages) {
|
||||
plugin.logDebug("sendMessage[]: " + message);
|
||||
addMessageToQueue(message);
|
||||
addMessageToQueue(template.replace("%RESULT%", message));
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,14 +73,16 @@ public class IRCCommandSender implements CommandSender {
|
||||
* @param plugin
|
||||
* @param ctcpResponse
|
||||
* @param name
|
||||
* @param template
|
||||
*/
|
||||
public IRCCommandSender(PurpleBot ircBot, String target, PurpleIRC plugin, boolean ctcpResponse, String name) {
|
||||
public IRCCommandSender(PurpleBot ircBot, String target, PurpleIRC plugin, boolean ctcpResponse, String name, String template) {
|
||||
super();
|
||||
this.target = target;
|
||||
this.ircBot = ircBot;
|
||||
this.plugin = plugin;
|
||||
this.ctcpResponse = ctcpResponse;
|
||||
this.name = name;
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,6 +110,7 @@ public class IRCMessageHandler {
|
||||
gameCommands.addAll(extraCommands);
|
||||
String modes = (String) ircBot.commandMap.get(channelName).get(command).get("modes");
|
||||
String perm = (String) ircBot.commandMap.get(channelName).get(command).get("perm");
|
||||
String outputTemplate = (String) ircBot.commandMap.get(channelName).get(command).get("output");
|
||||
boolean privateCommand = Boolean.parseBoolean(ircBot.commandMap.get(channelName).get(command).get("private"));
|
||||
boolean ctcpResponse = Boolean.parseBoolean(ircBot.commandMap.get(channelName).get(command).get("ctcp"));
|
||||
String senderName = ircBot.commandMap.get(channelName).get(command).get("sender").replace("%NICK%", user.getNick());
|
||||
@ -230,9 +231,10 @@ public class IRCMessageHandler {
|
||||
plugin.logDebug("GM: \"" + gameCommand.trim() + "\"");
|
||||
try {
|
||||
plugin.commandQueue.add(new IRCCommand(
|
||||
new IRCCommandSender(ircBot, target, plugin, ctcpResponse, senderName),
|
||||
new IRCCommandSender(ircBot, target, plugin, ctcpResponse, senderName, outputTemplate),
|
||||
new IRCConsoleCommandSender(ircBot, target, plugin, ctcpResponse, senderName),
|
||||
gameCommand.trim()));
|
||||
gameCommand.trim()
|
||||
));
|
||||
} catch (Exception ex) {
|
||||
plugin.logError(ex.getMessage());
|
||||
}
|
||||
|
@ -16,7 +16,6 @@
|
||||
*/
|
||||
package com.cnaude.purpleirc;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
@ -1001,6 +1001,7 @@ public final class PurpleBot {
|
||||
optionPair.put("private_listen", config.getString(commandKey + "private_listen", "true"));
|
||||
optionPair.put("channel_listen", config.getString(commandKey + "channel_listen", "true"));
|
||||
optionPair.put("perm", config.getString(commandKey + "perm", ""));
|
||||
optionPair.put("output", config.getString(commandKey + "output", "%RESULT%"));
|
||||
for (String s : optionPair.keySet()) {
|
||||
config.set(commandKey + s, optionPair.get(s));
|
||||
}
|
||||
@ -3362,7 +3363,7 @@ public final class PurpleBot {
|
||||
String myMessage = ChatColor.translateAlternateColorCodes('&', plugin.colorConverter.gameColorsToIrc(joinNoticeMessage.replace("%NAME%", user.getNick())));
|
||||
if (joinNoticeMessage.startsWith("/")) {
|
||||
plugin.commandQueue.add(new IRCCommand(
|
||||
new IRCCommandSender(this, target, plugin, joinNoticeCtcp, "CONSOLE"),
|
||||
new IRCCommandSender(this, target, plugin, joinNoticeCtcp, "CONSOLE", "%RESULT%"),
|
||||
new IRCConsoleCommandSender(this, target, plugin, joinNoticeCtcp, "CONSOLE"),
|
||||
myMessage.trim().substring(1)));
|
||||
} else if (joinNoticeCtcp) {
|
||||
|
@ -382,6 +382,7 @@ channels:
|
||||
channel_listen: true
|
||||
user_masks: []
|
||||
perm: ''
|
||||
output: '%RESULT%'
|
||||
mb:
|
||||
modes: 'o'
|
||||
private: 'false'
|
||||
@ -421,6 +422,7 @@ channels:
|
||||
# private_listen: true
|
||||
# channel_listen: true
|
||||
# user_masks: []
|
||||
# output: '%RESULT%'
|
||||
## Sample of %ARGX% and %ARGX+% with game_command_usage
|
||||
# mute:
|
||||
# modes: o
|
||||
@ -435,3 +437,4 @@ channels:
|
||||
# perm: ''
|
||||
# sender: CONSOLE
|
||||
# user_masks: []
|
||||
# output: '%RESULT%'
|
||||
|
Loading…
Reference in New Issue
Block a user