More work on toggles
#75 Most channel toggles should work Needs testing
This commit is contained in:
parent
774186a600
commit
18fdbc5770
4 changed files with 45 additions and 7 deletions
|
@ -3,5 +3,13 @@ package buttondevteam.discordplugin;
|
||||||
public enum ChannelconBroadcast {
|
public enum ChannelconBroadcast {
|
||||||
JOINLEAVE,
|
JOINLEAVE,
|
||||||
AFK,
|
AFK,
|
||||||
RESTART
|
RESTART, //TODO
|
||||||
|
DEATH,
|
||||||
|
BROADCAST;
|
||||||
|
|
||||||
|
public final int flag;
|
||||||
|
|
||||||
|
ChannelconBroadcast() {
|
||||||
|
this.flag = 1 << this.ordinal();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,6 +53,17 @@ public class ChannelconCommand extends DiscordCommandBase {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
//TODO: Toggle that toggle
|
//TODO: Toggle that toggle
|
||||||
|
val cc = MCChatListener.getCustomChat(message.getChannel());
|
||||||
|
//A B | F
|
||||||
|
//------- A: original - B: mask - F: new
|
||||||
|
//0 0 | 0
|
||||||
|
//0 1 | 1
|
||||||
|
//1 0 | 1
|
||||||
|
//1 1 | 0
|
||||||
|
// XOR
|
||||||
|
cc.toggles ^= b.get().flag;
|
||||||
|
message.reply("'" + b.get().toString().toLowerCase() + "' " + ((cc.toggles & b.get().flag) == 0 ? "disabled" : "enabled"));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
message.reply("this channel is already connected to a Minecraft channel. Use `@ChromaBot channelcon remove` to remove it.");
|
message.reply("this channel is already connected to a Minecraft channel. Use `@ChromaBot channelcon remove` to remove it.");
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -33,6 +33,7 @@ import sx.blah.discord.util.DiscordException;
|
||||||
import sx.blah.discord.util.EmbedBuilder;
|
import sx.blah.discord.util.EmbedBuilder;
|
||||||
import sx.blah.discord.util.MissingPermissionsException;
|
import sx.blah.discord.util.MissingPermissionsException;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -173,6 +174,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
public final String groupID;
|
public final String groupID;
|
||||||
public final Channel mcchannel;
|
public final Channel mcchannel;
|
||||||
public final DiscordConnectedPlayer dcp;
|
public final DiscordConnectedPlayer dcp;
|
||||||
|
public int toggles;
|
||||||
|
|
||||||
public CustomLMD(@NonNull IChannel channel, @NonNull IUser user, @NonNull DiscordPlayer dp,
|
public CustomLMD(@NonNull IChannel channel, @NonNull IUser user, @NonNull DiscordPlayer dp,
|
||||||
@NonNull String groupid, @NonNull Channel mcchannel, @NonNull DiscordConnectedPlayer dcp) {
|
@NonNull String groupid, @NonNull Channel mcchannel, @NonNull DiscordConnectedPlayer dcp) {
|
||||||
|
@ -367,9 +369,20 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
lastmsgCustom.forEach(cc -> action.accept(cc.channel));
|
lastmsgCustom.forEach(cc -> action.accept(cc.channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void forAllowedCustomMCChat(Consumer<IChannel> action, CommandSender sender) {
|
/**
|
||||||
|
* Do the {@code action} for each custom chat the {@code sender} have access to and has that broadcast type enabled.
|
||||||
|
*
|
||||||
|
* @param action The action to do
|
||||||
|
* @param sender The sender to check perms of or null to send to all that has it toggled
|
||||||
|
* @param toggle The toggle to check or null to send to all allowed
|
||||||
|
*/
|
||||||
|
public static void forAllowedCustomMCChat(Consumer<IChannel> action, @Nullable CommandSender sender, @Nullable ChannelconBroadcast toggle) {
|
||||||
lastmsgCustom.stream().filter(clmd -> {
|
lastmsgCustom.stream().filter(clmd -> {
|
||||||
//new TBMCChannelConnectFakeEvent(sender, clmd.mcchannel).shouldSendTo(clmd.dcp) - Thought it was this simple hehe - Wait, it *should* be this simple
|
//new TBMCChannelConnectFakeEvent(sender, clmd.mcchannel).shouldSendTo(clmd.dcp) - Thought it was this simple hehe - Wait, it *should* be this simple
|
||||||
|
if (toggle != null && (clmd.toggles & toggle.flag) == 0)
|
||||||
|
return false; //If null then allow
|
||||||
|
if (sender == null)
|
||||||
|
return true;
|
||||||
val e = new TBMCChannelConnectFakeEvent(sender, clmd.mcchannel);
|
val e = new TBMCChannelConnectFakeEvent(sender, clmd.mcchannel);
|
||||||
return clmd.groupID.equals(e.getGroupID(sender));
|
return clmd.groupID.equals(e.getGroupID(sender));
|
||||||
}).forEach(cc -> action.accept(cc.channel)); //TODO: Use getScore and getGroupID in fake event constructor - This should also 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
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class MCListener implements Listener {
|
||||||
final String message = e.GetPlayer().PlayerName().get() + " joined the game";
|
final String message = e.GetPlayer().PlayerName().get() + " joined the game";
|
||||||
if (!DiscordPlugin.hooked)
|
if (!DiscordPlugin.hooked)
|
||||||
MCChatListener.sendSystemMessageToChat(message);
|
MCChatListener.sendSystemMessageToChat(message);
|
||||||
MCChatListener.forAllowedCustomMCChat(ch -> DiscordPlugin.sendMessageToChannel(ch, message), e.getPlayer());
|
MCChatListener.forAllowedCustomMCChat(ch -> DiscordPlugin.sendMessageToChannel(ch, message), e.getPlayer(), ChannelconBroadcast.JOINLEAVE);
|
||||||
//System.out.println("Does this appear more than once?"); //No
|
//System.out.println("Does this appear more than once?"); //No
|
||||||
MCChatListener.ListC = 0;
|
MCChatListener.ListC = 0;
|
||||||
ChromaBot.getInstance().updatePlayerList();
|
ChromaBot.getInstance().updatePlayerList();
|
||||||
|
@ -87,7 +87,7 @@ public class MCListener implements Listener {
|
||||||
final String message = e.GetPlayer().PlayerName().get() + " left the game";
|
final String message = e.GetPlayer().PlayerName().get() + " left the game";
|
||||||
if (!DiscordPlugin.hooked)
|
if (!DiscordPlugin.hooked)
|
||||||
MCChatListener.sendSystemMessageToChat(message); //TODO: Probably double sends if kicked and unhooked
|
MCChatListener.sendSystemMessageToChat(message); //TODO: Probably double sends if kicked and unhooked
|
||||||
MCChatListener.forAllowedCustomMCChat(ch -> DiscordPlugin.sendMessageToChannel(ch, message), e.getPlayer());
|
MCChatListener.forAllowedCustomMCChat(ch -> DiscordPlugin.sendMessageToChannel(ch, message), e.getPlayer(), ChannelconBroadcast.JOINLEAVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
@ -115,14 +115,18 @@ public class MCListener implements Listener {
|
||||||
public void onPlayerDeath(PlayerDeathEvent e) {
|
public void onPlayerDeath(PlayerDeathEvent e) {
|
||||||
if (!DiscordPlugin.hooked)
|
if (!DiscordPlugin.hooked)
|
||||||
MCChatListener.sendSystemMessageToChat(e.getDeathMessage());
|
MCChatListener.sendSystemMessageToChat(e.getDeathMessage());
|
||||||
|
MCChatListener.forAllowedCustomMCChat(ch -> DiscordPlugin.sendMessageToChannel(ch, e.getDeathMessage()), e.getEntity(), ChannelconBroadcast.DEATH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerAFK(AfkStatusChangeEvent e) { //TODO: Add AFK to custom chats?
|
public void onPlayerAFK(AfkStatusChangeEvent e) { //TODO: Add AFK to custom chats?
|
||||||
if (e.isCancelled() || !e.getAffected().getBase().isOnline())
|
final Player base = e.getAffected().getBase();
|
||||||
|
if (e.isCancelled() || !base.isOnline())
|
||||||
return;
|
return;
|
||||||
MCChatListener.sendSystemMessageToChat(e.getAffected().getBase().getDisplayName()
|
final String msg = base.getDisplayName()
|
||||||
+ " is " + (e.getValue() ? "now" : "no longer") + " AFK.");
|
+ " is " + (e.getValue() ? "now" : "no longer") + " AFK.";
|
||||||
|
MCChatListener.sendSystemMessageToChat(msg);
|
||||||
|
MCChatListener.forAllowedCustomMCChat(ch -> DiscordPlugin.sendMessageToChannel(ch, msg), base, ChannelconBroadcast.AFK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
|
@ -155,11 +159,13 @@ public class MCListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onChatSystemMessage(TBMCSystemChatEvent event) {
|
public void onChatSystemMessage(TBMCSystemChatEvent event) {
|
||||||
MCChatListener.sendSystemMessageToChat(event);
|
MCChatListener.sendSystemMessageToChat(event);
|
||||||
|
MCChatListener.forAllowedCustomMCChat(ch -> DiscordPlugin.sendMessageToChannel(ch, event.getMessage()), null, ChannelconBroadcast.BROADCAST); //TODO: Method to send message
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBroadcastMessage(BroadcastMessageEvent event) {
|
public void onBroadcastMessage(BroadcastMessageEvent event) {
|
||||||
MCChatListener.sendSystemMessageToChat(event.getMessage());
|
MCChatListener.sendSystemMessageToChat(event.getMessage());
|
||||||
|
MCChatListener.forAllowedCustomMCChat(ch -> DiscordPlugin.sendMessageToChannel(ch, event.getMessage()), null, ChannelconBroadcast.BROADCAST);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@EventHandler
|
/*@EventHandler
|
||||||
|
|
Loading…
Reference in a new issue