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