Bunch of channel stuff
#70 is technically fixed but there's another issue #61 and #71 are definitely fixed Allowing multiple channels to be connected
This commit is contained in:
parent
a0e0890160
commit
17887707cb
7 changed files with 55 additions and 34 deletions
7
pom.xml
7
pom.xml
|
@ -94,6 +94,13 @@
|
||||||
<goals> <goal>testDelombok</goal> </goals> <configuration> <addOutputDirectory>false</addOutputDirectory>
|
<goals> <goal>testDelombok</goal> </goals> <configuration> <addOutputDirectory>false</addOutputDirectory>
|
||||||
<sourceDirectory>src/test/java</sourceDirectory> </configuration> </execution>
|
<sourceDirectory>src/test/java</sourceDirectory> </configuration> </execution>
|
||||||
</executions> </plugin> -->
|
</executions> </plugin> -->
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<useSystemClassLoader>false
|
||||||
|
</useSystemClassLoader> <!-- https://stackoverflow.com/a/53012553/2703239 -->
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ package buttondevteam.discordplugin;
|
||||||
public enum ChannelconBroadcast {
|
public enum ChannelconBroadcast {
|
||||||
JOINLEAVE,
|
JOINLEAVE,
|
||||||
AFK,
|
AFK,
|
||||||
RESTART, //TODO
|
RESTART,
|
||||||
DEATH,
|
DEATH,
|
||||||
BROADCAST;
|
BROADCAST;
|
||||||
|
|
||||||
|
|
|
@ -221,8 +221,12 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(), this);
|
TBMCCoreAPI.RegisterEventsForExceptions(new MCListener(), this);
|
||||||
TBMCChatAPI.AddCommands(this, DiscordMCCommandBase.class);
|
TBMCChatAPI.AddCommands(this, DiscordMCCommandBase.class);
|
||||||
TBMCCoreAPI.RegisterUserClass(DiscordPlayer.class);
|
TBMCCoreAPI.RegisterUserClass(DiscordPlayer.class);
|
||||||
ChromaGamerBase.addConverter(sender -> Optional.ofNullable(sender instanceof DiscordSenderBase
|
ChromaGamerBase.addConverter(sender -> {
|
||||||
? ((DiscordSenderBase) sender).getChromaUser() : null));
|
//System.out.println("Discord converter queried: "+sender+" "+sender.getName()); - TODO: Remove
|
||||||
|
//System.out.println(((DiscordSenderBase) sender).getChromaUser().channel().get().ID); //TODO: TMP
|
||||||
|
return Optional.ofNullable(sender instanceof DiscordSenderBase
|
||||||
|
? ((DiscordSenderBase) sender).getChromaUser() : null);
|
||||||
|
});
|
||||||
new Thread(this::AnnouncementGetterThreadMethod).start();
|
new Thread(this::AnnouncementGetterThreadMethod).start();
|
||||||
setupProviders();
|
setupProviders();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -86,12 +86,12 @@ public class DiscordSender extends DiscordSenderBase implements CommandSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOp() { // TODO: Connect with TBMC acc
|
public boolean isOp() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setOp(boolean value) { // TODO: Connect with TBMC acc
|
public void setOp(boolean value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -4,7 +4,6 @@ import buttondevteam.discordplugin.ChannelconBroadcast;
|
||||||
import buttondevteam.discordplugin.DiscordConnectedPlayer;
|
import buttondevteam.discordplugin.DiscordConnectedPlayer;
|
||||||
import buttondevteam.discordplugin.DiscordPlayer;
|
import buttondevteam.discordplugin.DiscordPlayer;
|
||||||
import buttondevteam.discordplugin.listeners.MCChatListener;
|
import buttondevteam.discordplugin.listeners.MCChatListener;
|
||||||
import buttondevteam.lib.TBMCChannelConnectFakeEvent;
|
|
||||||
import buttondevteam.lib.chat.Channel;
|
import buttondevteam.lib.chat.Channel;
|
||||||
import buttondevteam.lib.player.TBMCPlayer;
|
import buttondevteam.lib.player.TBMCPlayer;
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
|
@ -79,18 +78,17 @@ public class ChannelconCommand extends DiscordCommandBase {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
DiscordConnectedPlayer dcp = new DiscordConnectedPlayer(message.getAuthor(), message.getChannel(), chp.getUUID(), Bukkit.getOfflinePlayer(chp.getUUID()).getName());
|
DiscordConnectedPlayer dcp = new DiscordConnectedPlayer(message.getAuthor(), message.getChannel(), chp.getUUID(), Bukkit.getOfflinePlayer(chp.getUUID()).getName());
|
||||||
val ev = new TBMCChannelConnectFakeEvent(dcp, chan.get());
|
|
||||||
//Using a fake player with no login/logout, should be fine for this event
|
//Using a fake player with no login/logout, should be fine for this event
|
||||||
String groupid = ev.getGroupID(ev.getSender()); //We're not trying to send in a specific group, we want to know which group the user belongs to (so not getGroupID())
|
String groupid = chan.get().getGroupID(dcp);
|
||||||
if (groupid == null) {
|
if (groupid == null) {
|
||||||
message.reply("sorry, that didn't work. You cannot use that Minecraft channel.");
|
message.reply("sorry, that didn't work. You cannot use that Minecraft channel.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (MCChatListener.getCustomChats().stream().anyMatch(cc -> cc.groupID.equals(groupid) && cc.mcchannel.ID.equals(chan.get().ID))) {
|
/*if (MCChatListener.getCustomChats().stream().anyMatch(cc -> cc.groupID.equals(groupid) && cc.mcchannel.ID.equals(chan.get().ID))) {
|
||||||
message.reply("sorry, this MC chat is already connected to a different channel, multiple channels are not supported atm.");
|
message.reply("sorry, this MC chat is already connected to a different channel, multiple channels are not supported atm.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}*/ //TODO: "Channel admins" that can connect channels?
|
||||||
MCChatListener.addCustomChat(message.getChannel(), groupid, ev.getChannel(), message.getAuthor(), dcp, 0);
|
MCChatListener.addCustomChat(message.getChannel(), groupid, chan.get(), message.getAuthor(), dcp, 0);
|
||||||
message.reply("alright, connection made to group `" + groupid + "`!");
|
message.reply("alright, connection made to group `" + groupid + "`!");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,10 @@ package buttondevteam.discordplugin.listeners;
|
||||||
|
|
||||||
import buttondevteam.discordplugin.*;
|
import buttondevteam.discordplugin.*;
|
||||||
import buttondevteam.discordplugin.playerfaker.VanillaCommandListener;
|
import buttondevteam.discordplugin.playerfaker.VanillaCommandListener;
|
||||||
import buttondevteam.lib.*;
|
import buttondevteam.lib.TBMCChatEvent;
|
||||||
|
import buttondevteam.lib.TBMCChatPreprocessEvent;
|
||||||
|
import buttondevteam.lib.TBMCCoreAPI;
|
||||||
|
import buttondevteam.lib.TBMCSystemChatEvent;
|
||||||
import buttondevteam.lib.chat.Channel;
|
import buttondevteam.lib.chat.Channel;
|
||||||
import buttondevteam.lib.chat.ChatMessage;
|
import buttondevteam.lib.chat.ChatMessage;
|
||||||
import buttondevteam.lib.chat.ChatRoom;
|
import buttondevteam.lib.chat.ChatRoom;
|
||||||
|
@ -125,7 +128,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
Predicate<IChannel> isdifferentchannel = ch -> !(e.getSender() instanceof DiscordSenderBase)
|
Predicate<IChannel> isdifferentchannel = ch -> !(e.getSender() instanceof DiscordSenderBase)
|
||||||
|| ((DiscordSenderBase) e.getSender()).getChannel().getLongID() != ch.getLongID();
|
|| ((DiscordSenderBase) e.getSender()).getChannel().getLongID() != ch.getLongID();
|
||||||
|
|
||||||
if ((e.getChannel() == Channel.GlobalChat || e.getChannel().ID.equals("rp"))
|
if (e.getChannel().isGlobal()
|
||||||
&& (e.isFromcmd() || isdifferentchannel.test(DiscordPlugin.chatchannel)))
|
&& (e.isFromcmd() || isdifferentchannel.test(DiscordPlugin.chatchannel)))
|
||||||
doit.accept(lastmsgdata == null
|
doit.accept(lastmsgdata == null
|
||||||
? lastmsgdata = new LastMsgData(DiscordPlugin.chatchannel, null)
|
? lastmsgdata = new LastMsgData(DiscordPlugin.chatchannel, null)
|
||||||
|
@ -304,6 +307,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
return lastmsgCustom.stream().anyMatch(lmd -> lmd.channel.getLongID() == channel.getLongID());
|
return lastmsgCustom.stream().anyMatch(lmd -> lmd.channel.getLongID() == channel.getLongID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static CustomLMD getCustomChat(IChannel channel) {
|
public static CustomLMD getCustomChat(IChannel channel) {
|
||||||
return lastmsgCustom.stream().filter(lmd -> lmd.channel.getLongID() == channel.getLongID()).findAny().orElse(null);
|
return lastmsgCustom.stream().filter(lmd -> lmd.channel.getLongID() == channel.getLongID()).findAny().orElse(null);
|
||||||
}
|
}
|
||||||
|
@ -387,9 +391,8 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
return false; //If null then allow
|
return false; //If null then allow
|
||||||
if (sender == null)
|
if (sender == null)
|
||||||
return true;
|
return true;
|
||||||
val e = new TBMCChannelConnectFakeEvent(sender, clmd.mcchannel);
|
return clmd.groupID.equals(clmd.mcchannel.getGroupID(sender));
|
||||||
return clmd.groupID.equals(e.getGroupID(sender));
|
}).forEach(cc -> action.accept(cc.channel)); //TODO: Send error messages on channel connect
|
||||||
}).forEach(cc -> action.accept(cc.channel)); //TODO: Use getScore and getGroupID in fake event constructor - This should also send error messages on channel connect
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -403,7 +406,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
public static void forAllowedCustomAndAllMCChat(Consumer<IChannel> action, @Nullable CommandSender sender, @Nullable ChannelconBroadcast toggle, boolean hookmsg) {
|
public static void forAllowedCustomAndAllMCChat(Consumer<IChannel> action, @Nullable CommandSender sender, @Nullable ChannelconBroadcast toggle, boolean hookmsg) {
|
||||||
if (!DiscordPlugin.hooked || !hookmsg)
|
if (!DiscordPlugin.hooked || !hookmsg)
|
||||||
forAllMCChat(action);
|
forAllMCChat(action);
|
||||||
forAllowedCustomMCChat(action, sender, toggle); //TODO: Use getScore and getGroupID in fake event constructor - This should also send error messages on channel connect
|
forAllowedCustomMCChat(action, sender, toggle);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Consumer<IChannel> send(String message) {
|
public static Consumer<IChannel> send(String message) {
|
||||||
|
@ -411,7 +414,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void forAllowedMCChat(Consumer<IChannel> action, TBMCSystemChatEvent event) {
|
public static void forAllowedMCChat(Consumer<IChannel> action, TBMCSystemChatEvent event) {
|
||||||
if (Channel.GlobalChat.ID.equals(event.getChannel().ID))
|
if (event.getChannel().isGlobal())
|
||||||
action.accept(DiscordPlugin.chatchannel);
|
action.accept(DiscordPlugin.chatchannel);
|
||||||
for (LastMsgData data : lastmsgPerUser)
|
for (LastMsgData data : lastmsgPerUser)
|
||||||
if (event.shouldSendTo(getSender(data.channel, data.user)))
|
if (event.shouldSendTo(getSender(data.channel, data.user)))
|
||||||
|
@ -562,23 +565,29 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
.filter(c -> c.ID.equalsIgnoreCase(topcmd)
|
.filter(c -> c.ID.equalsIgnoreCase(topcmd)
|
||||||
|| (c.IDs != null && c.IDs.length > 0
|
|| (c.IDs != null && c.IDs.length > 0
|
||||||
&& Arrays.stream(c.IDs).anyMatch(id -> id.equalsIgnoreCase(topcmd)))).findAny();
|
&& Arrays.stream(c.IDs).anyMatch(id -> id.equalsIgnoreCase(topcmd)))).findAny();
|
||||||
if (!ch.isPresent())
|
if (!ch.isPresent()) //TODO: What if talking in the public chat while we have it on a different one
|
||||||
Bukkit.getScheduler().runTask(DiscordPlugin.plugin,
|
Bukkit.getScheduler().runTask(DiscordPlugin.plugin, //Commands need to be run sync
|
||||||
() -> {
|
() -> { //TODO: Better handling...
|
||||||
val channel = dsender.getChromaUser().channel(); //TODO: Save?
|
val channel = user.channel();
|
||||||
val chtmp = channel.get();
|
val chtmp = channel.get();
|
||||||
if (clmd != null)
|
//System.out.println("1: "+chtmp.ID);
|
||||||
|
//System.out.println("clmd: "+clmd);
|
||||||
|
if (clmd != null) {
|
||||||
channel.set(clmd.mcchannel); //Hack to send command in the channel
|
channel.set(clmd.mcchannel); //Hack to send command in the channel
|
||||||
|
//System.out.println("clmd chan: "+clmd.mcchannel.ID);
|
||||||
|
} //TODO: Permcheck isn't implemented for commands
|
||||||
|
//System.out.println("2: "+channel.get().ID);
|
||||||
VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd);
|
VanillaCommandListener.runBukkitOrVanillaCommand(dsender, cmd);
|
||||||
Bukkit.getLogger().info(dsender.getName() + " issued command from Discord: /" + cmdlowercased);
|
Bukkit.getLogger().info(dsender.getName() + " issued command from Discord: /" + cmdlowercased);
|
||||||
if (clmd != null)
|
if (clmd != null)
|
||||||
channel.set(chtmp);
|
channel.set(chtmp);
|
||||||
|
//System.out.println("3: "+channel.get().ID); - TODO: Remove
|
||||||
});
|
});
|
||||||
else {
|
else {
|
||||||
Channel chc = ch.get();
|
Channel chc = ch.get();
|
||||||
if (!chc.ID.equals(Channel.GlobalChat.ID) && !chc.ID.equals("rp") && !event.getMessage().getChannel().isPrivate())
|
if (!chc.isGlobal() && !event.getMessage().getChannel().isPrivate())
|
||||||
dsender.sendMessage(
|
dsender.sendMessage(
|
||||||
"You can only talk in global in the public chat. DM `mcchat` to enable private chat to talk in the other channels.");
|
"You can only talk in a public chat here. DM `mcchat` to enable private chat to talk in the other channels.");
|
||||||
else {
|
else {
|
||||||
if (spi == -1) // Switch channels
|
if (spi == -1) // Switch channels
|
||||||
{
|
{
|
||||||
|
@ -609,10 +618,12 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
lastlistp = (short) Bukkit.getOnlinePlayers().size();
|
lastlistp = (short) Bukkit.getOnlinePlayers().size();
|
||||||
} else {// Not a command
|
} else {// Not a command
|
||||||
if (dmessage.length() == 0 && event.getMessage().getAttachments().size() == 0
|
if (dmessage.length() == 0 && event.getMessage().getAttachments().size() == 0
|
||||||
&& !event.getChannel().isPrivate() && event.getMessage().isSystemMessage())
|
&& !event.getChannel().isPrivate() && event.getMessage().isSystemMessage()) {
|
||||||
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, 0, "everyone",
|
val rtr = clmd != null ? clmd.mcchannel.filteranderrormsg.apply(clmd.dcp) : dsender.getChromaUser().channel().get().filteranderrormsg.apply(dsender);
|
||||||
|
TBMCChatAPI.SendSystemMessage(clmd != null ? clmd.mcchannel : dsender.getChromaUser().channel().get(), rtr.score, rtr.groupID,
|
||||||
(dsender instanceof Player ? ((Player) dsender).getDisplayName()
|
(dsender instanceof Player ? ((Player) dsender).getDisplayName()
|
||||||
: dsender.getName()) + " pinned a message on Discord.");
|
: dsender.getName()) + " pinned a message on Discord.");
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
val cmb = ChatMessage.builder(dsender, user, getChatMessage.apply(dmessage)).fromCommand(false);
|
val cmb = ChatMessage.builder(dsender, user, getChatMessage.apply(dmessage)).fromCommand(false);
|
||||||
if (clmd != null)
|
if (clmd != null)
|
||||||
|
|
|
@ -137,7 +137,7 @@ public class MCListener implements Listener {
|
||||||
return;
|
return;
|
||||||
final IUser user = DiscordPlugin.dc.getUserByID(
|
final IUser user = DiscordPlugin.dc.getUserByID(
|
||||||
Long.parseLong(TBMCPlayerBase.getPlayer(source.getPlayer().getUniqueId(), TBMCPlayer.class)
|
Long.parseLong(TBMCPlayerBase.getPlayer(source.getPlayer().getUniqueId(), TBMCPlayer.class)
|
||||||
.getAs(DiscordPlayer.class).getDiscordID())); // TODO: Use long
|
.getAs(DiscordPlayer.class).getDiscordID()));
|
||||||
if (e.getValue())
|
if (e.getValue())
|
||||||
user.addRole(role);
|
user.addRole(role);
|
||||||
else
|
else
|
||||||
|
@ -163,6 +163,7 @@ public class MCListener implements Listener {
|
||||||
public void onYEEHAW(TBMCYEEHAWEvent event) { //TODO: Inherit from the chat event base to have channel support
|
public void onYEEHAW(TBMCYEEHAWEvent event) { //TODO: Inherit from the chat event base to have channel support
|
||||||
String name = event.getSender() instanceof Player ? ((Player) event.getSender()).getDisplayName()
|
String name = event.getSender() instanceof Player ? ((Player) event.getSender()).getDisplayName()
|
||||||
: event.getSender().getName();
|
: event.getSender().getName();
|
||||||
|
//Channel channel = ChromaGamerBase.getFromSender(event.getSender()).channel().get(); - TODO
|
||||||
MCChatListener.forAllMCChat(MCChatListener.send(name + " <:YEEHAW:" + DiscordPlugin.mainServer.getEmojiByName("YEEHAW").getStringID() + ">s"));
|
MCChatListener.forAllMCChat(MCChatListener.send(name + " <:YEEHAW:" + DiscordPlugin.mainServer.getEmojiByName("YEEHAW").getStringID() + ">s"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue