Add sender option for custom commands.

This commit is contained in:
cnaude 2015-01-25 22:37:44 -07:00
parent abb7b75920
commit c4a1e78be1
4 changed files with 11 additions and 7 deletions

View File

@ -54,8 +54,8 @@ public class CommandQueueWatcher {
IRCCommand ircCommand = queue.poll();
if (ircCommand != null) {
try {
if (plugin.getServer().getVersion().contains("MC: 1.8")
&& plugin.getServer().getPluginCommand(ircCommand.getGameCommand()) == null) {
String cmd = ircCommand.getGameCommand().split(" ")[0];
if (plugin.getServer().getVersion().contains("MC: 1.8") && plugin.getServer().getPluginCommand(cmd) == null) {
plugin.logDebug("Dispatching command as ConsoleSender: " + ircCommand.getGameCommand());
plugin.getServer().dispatchCommand(plugin.getServer().getConsoleSender(), ircCommand.getGameCommand());
ircCommand.getIRCCommandSender().sendMessage("Command sent: " + ircCommand.getGameCommand());

View File

@ -36,6 +36,7 @@ public class IRCCommandSender implements CommandSender {
private final String target;
private final PurpleIRC plugin;
private final boolean ctcpResponse;
private final String name;
/**
*
@ -70,14 +71,15 @@ public class IRCCommandSender implements CommandSender {
* @param target
* @param plugin
* @param ctcpResponse
* @param name
*/
public IRCCommandSender(PurpleBot ircBot, String target, PurpleIRC plugin, boolean ctcpResponse) {
public IRCCommandSender(PurpleBot ircBot, String target, PurpleIRC plugin, boolean ctcpResponse, String name) {
super();
this.target = target;
this.ircBot = ircBot;
this.plugin = plugin;
this.ctcpResponse = ctcpResponse;
this.name = name;
}
/**
@ -95,7 +97,7 @@ public class IRCCommandSender implements CommandSender {
*/
@Override
public String getName() {
return "CONSOLE";
return name;
}
/**

View File

@ -863,6 +863,7 @@ public final class PurpleBot {
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("sender", config.getString(commandKey + "sender", "CONSOLE"));
extraCommands.addAll(config.getStringList(commandKey + "extra_commands"));
plugin.logDebug("extra_commands: " + extraCommands.toString());
optionPair.put("private_listen", config.getString(commandKey + "private_listen", "true"));
@ -2948,7 +2949,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), myMessage.trim().substring(1)));
plugin.commandQueue.add(new IRCCommand(new IRCCommandSender(this, target, plugin, joinNoticeCtcp, "CONSOLE"), myMessage.trim().substring(1)));
} else {
if (joinNoticeCtcp) {
asyncCTCPMessage(target, myMessage);

View File

@ -97,6 +97,7 @@ public class IRCMessageHandler {
String perm = (String) ircBot.commandMap.get(myChannel).get(command).get("perm");
boolean privateCommand = Boolean.parseBoolean(ircBot.commandMap.get(myChannel).get(command).get("private"));
boolean ctcpResponse = Boolean.parseBoolean(ircBot.commandMap.get(myChannel).get(command).get("ctcp"));
String senderName = ircBot.commandMap.get(myChannel).get(command).get("sender").replace("%NICK%", user.getNick());
if (privateCommand || privateMessage) {
target = user.getNick();
@ -179,7 +180,7 @@ public class IRCMessageHandler {
}
plugin.logDebug("GM: \"" + gameCommand.trim() + "\"");
try {
plugin.commandQueue.add(new IRCCommand(new IRCCommandSender(ircBot, target, plugin, ctcpResponse), gameCommand.trim()));
plugin.commandQueue.add(new IRCCommand(new IRCCommandSender(ircBot, target, plugin, ctcpResponse, senderName), gameCommand.trim()));
} catch (Exception ex) {
plugin.logError(ex.getMessage());
}