mirror of
https://github.com/cnaude/PurpleIRC-spigot.git
synced 2024-11-29 05:26:19 +01:00
Latest commit.
This commit is contained in:
parent
c4a1e78be1
commit
67cfbe2f2b
@ -137,6 +137,12 @@
|
||||
<version>1.8</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.cnaude.purpleirc</groupId>
|
||||
<artifactId>PurpleIRC-API</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
|
6
pom.xml
6
pom.xml
@ -84,6 +84,12 @@
|
||||
<type>jar</type>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.cnaude.purpleirc</groupId>
|
||||
<artifactId>PurpleIRC-API</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Following dependency is provided by CraftBukkit -->
|
||||
<dependency>
|
||||
|
@ -56,9 +56,10 @@ public class CommandQueueWatcher {
|
||||
try {
|
||||
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());
|
||||
plugin.logDebug("Dispatching command as ConsoleSender: " + ircCommand.getGameCommand());
|
||||
|
||||
plugin.getServer().dispatchCommand(ircCommand.getIRCConsoleCommandSender(), 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());
|
||||
|
@ -21,16 +21,19 @@ package com.cnaude.purpleirc;
|
||||
* @author cnaude
|
||||
*/
|
||||
public class IRCCommand {
|
||||
final private IRCCommandSender sender;
|
||||
final private String command;
|
||||
private final IRCCommandSender sender;
|
||||
private final IRCConsoleCommandSender consoleSender;
|
||||
private final String command;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param sender
|
||||
* @param consoleSender
|
||||
* @param command
|
||||
*/
|
||||
public IRCCommand(IRCCommandSender sender, String command) {
|
||||
public IRCCommand(IRCCommandSender sender, IRCConsoleCommandSender consoleSender, String command) {
|
||||
this.sender = sender;
|
||||
this.consoleSender = consoleSender;
|
||||
this.command = command;
|
||||
}
|
||||
|
||||
@ -42,6 +45,14 @@ public class IRCCommand {
|
||||
return sender;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public IRCConsoleCommandSender getIRCConsoleCommandSender() {
|
||||
return consoleSender;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
|
155
src/main/java/com/cnaude/purpleirc/IRCConsoleCommandSender.java
Normal file
155
src/main/java/com/cnaude/purpleirc/IRCConsoleCommandSender.java
Normal file
@ -0,0 +1,155 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.Set;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.craftbukkit.v1_8_R1.command.CraftConsoleCommandSender;
|
||||
import org.bukkit.permissions.Permission;
|
||||
import org.bukkit.permissions.PermissionAttachmentInfo;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Chris Naude We have to implement our own CommandSender so that we can
|
||||
* receive output from the command dispatcher.
|
||||
*/
|
||||
public class IRCConsoleCommandSender extends CraftConsoleCommandSender {
|
||||
|
||||
private final PurpleBot ircBot;
|
||||
private final String target;
|
||||
private final PurpleIRC plugin;
|
||||
private final boolean ctcpResponse;
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param message
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(String message) {
|
||||
plugin.logDebug("sendMessage: " + message);
|
||||
addMessageToQueue(message);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param messages
|
||||
*/
|
||||
@Override
|
||||
public void sendMessage(String[] messages) {
|
||||
for (String message : messages) {
|
||||
plugin.logDebug("sendMessage[]: " + message);
|
||||
addMessageToQueue(message);
|
||||
}
|
||||
}
|
||||
|
||||
private void addMessageToQueue(String message) {
|
||||
ircBot.messageQueue.add(new IRCMessage(target,
|
||||
plugin.colorConverter.gameColorsToIrc(message), ctcpResponse));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ircBot
|
||||
* @param target
|
||||
* @param plugin
|
||||
* @param ctcpResponse
|
||||
* @param name
|
||||
*/
|
||||
public IRCConsoleCommandSender(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;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendRawMessage(String string) {
|
||||
plugin.logDebug("sendRawMessage: " + string);
|
||||
}
|
||||
|
||||
}
|
@ -2949,7 +2949,10 @@ 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"), myMessage.trim().substring(1)));
|
||||
plugin.commandQueue.add(new IRCCommand(
|
||||
new IRCCommandSender(this, target, plugin, joinNoticeCtcp, "CONSOLE"),
|
||||
new IRCConsoleCommandSender(this, target, plugin, joinNoticeCtcp, "CONSOLE"),
|
||||
myMessage.trim().substring(1)));
|
||||
} else {
|
||||
if (joinNoticeCtcp) {
|
||||
asyncCTCPMessage(target, myMessage);
|
||||
|
@ -18,6 +18,7 @@ package com.cnaude.purpleirc.Utilities;
|
||||
|
||||
import com.cnaude.purpleirc.IRCCommand;
|
||||
import com.cnaude.purpleirc.IRCCommandSender;
|
||||
import com.cnaude.purpleirc.IRCConsoleCommandSender;
|
||||
import com.cnaude.purpleirc.PurpleBot;
|
||||
import com.cnaude.purpleirc.PurpleIRC;
|
||||
import com.cnaude.purpleirc.TemplateName;
|
||||
@ -180,7 +181,10 @@ public class IRCMessageHandler {
|
||||
}
|
||||
plugin.logDebug("GM: \"" + gameCommand.trim() + "\"");
|
||||
try {
|
||||
plugin.commandQueue.add(new IRCCommand(new IRCCommandSender(ircBot, target, plugin, ctcpResponse, senderName), gameCommand.trim()));
|
||||
plugin.commandQueue.add(new IRCCommand(
|
||||
new IRCCommandSender(ircBot, target, plugin, ctcpResponse, senderName),
|
||||
new IRCConsoleCommandSender(ircBot, target, plugin, ctcpResponse, senderName),
|
||||
gameCommand.trim()));
|
||||
} catch (Exception ex) {
|
||||
plugin.logError(ex.getMessage());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user