Added partial support for private channels and fixed response location

This commit is contained in:
Norbi Peti 2016-11-28 18:42:41 +01:00
parent f338c815f1
commit 276ab40760
2 changed files with 16 additions and 4 deletions

View file

@ -12,16 +12,26 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
import org.bukkit.plugin.Plugin;
import buttondevteam.lib.TBMCCoreAPI;
import sx.blah.discord.handle.obj.IChannel;
import sx.blah.discord.handle.obj.IUser;
public class DiscordSender implements CommandSender {
private PermissibleBase perm = new PermissibleBase(this);
private IUser user;
private IChannel channel;
public DiscordSender(IUser user) {
this.user = user;
}
public IChannel getChannel() {
return channel;
}
public void setChannel(IChannel channel) {
this.channel = channel;
}
@Override
public boolean isPermissionSet(String name) {
return perm.isPermissionSet(name);
@ -89,7 +99,7 @@ public class DiscordSender implements CommandSender {
@Override
public void sendMessage(String message) {
try {
DiscordPlugin.sendMessageToChannel(user.getOrCreatePMChannel(), message);
DiscordPlugin.sendMessageToChannel(channel, message);
} catch (Exception e) {
TBMCCoreAPI.SendException("An error occured while sending message to DiscordSender", e);
}

View file

@ -27,9 +27,11 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
public void handle(MessageReceivedEvent event) {
if (event.getMessage().getAuthor().isBot())
return;
if (!event.getMessage().getChannel().getID().equals(DiscordPlugin.chatchannel.getID()))
if (!event.getMessage().getChannel().getID().equals(DiscordPlugin.chatchannel.getID())
/* && !(event.getMessage().getChannel().isPrivate() && privatechat) */)
return;
final DiscordSender dsender = new DiscordSender(event.getMessage().getAuthor());
dsender.setChannel(event.getMessage().getChannel());
if (event.getMessage().getContent().startsWith("/")) {
final String cmd = event.getMessage().getContent().substring(1);
try {