Applied changes and a fix
This commit is contained in:
parent
a6244b7f9f
commit
6dd21b03c1
5 changed files with 19 additions and 22 deletions
|
@ -18,6 +18,6 @@ public class DiscordPlayer extends ChromaGamerBase {
|
|||
}
|
||||
|
||||
public PlayerData<Boolean> minecraftChat() {
|
||||
return data();
|
||||
return data(false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.discordplugin.listeners.MCChatListener;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.player.PlayerData;
|
||||
import sx.blah.discord.handle.obj.IMessage;
|
||||
|
@ -20,8 +21,9 @@ public class MCChatCommand extends DiscordCommandBase {
|
|||
}
|
||||
try (final DiscordPlayer user = DiscordPlayer.getUser(message.getAuthor().getStringID(), DiscordPlayer.class)) {
|
||||
PlayerData<Boolean> mcchat = user.minecraftChat();
|
||||
mcchat.set(!mcchat.getOrDefault(false));
|
||||
message.reply("Minecraft chat " + (mcchat.getOrDefault(false) //
|
||||
mcchat.set(!mcchat.get());
|
||||
MCChatListener.privateMCChat(message.getChannel(), mcchat.get());
|
||||
message.reply("Minecraft chat " + (mcchat.get() //
|
||||
? "enabled. Use '" + message.getClient().getOurUser().mention()
|
||||
+ " mcchat' (with the mention) to disable." //
|
||||
: "disabled."));
|
||||
|
|
|
@ -62,8 +62,7 @@ public class CommandListener {
|
|||
return;
|
||||
if (channel.getStringID().equals(DiscordPlugin.chatchannel.getStringID()))
|
||||
return; // The chat code already handles this - Right now while testing botchannel is the same as chatchannel
|
||||
if (DiscordPlayer.getUser(event.getAuthor().getStringID(), DiscordPlayer.class).minecraftChat()
|
||||
.getOrDefault(false)) // Let the MCChatListener handle it
|
||||
if (DiscordPlayer.getUser(event.getAuthor().getStringID(), DiscordPlayer.class).minecraftChat().get()) // Let the MCChatListener handle it
|
||||
return;
|
||||
event.getMessage().getChannel().setTypingStatus(true); // Fun
|
||||
runCommand(event.getMessage(), true);
|
||||
|
@ -81,9 +80,8 @@ public class CommandListener {
|
|||
next = usableServerReadyStrings.remove(serverReadyRandom.nextInt(usableServerReadyStrings.size()));
|
||||
DiscordPlugin.sendMessageToChannel(event.getMessage().getChannel(), serverReadyStrings[next]);
|
||||
}
|
||||
if (!event.getMessage().getChannel().isPrivate()
|
||||
|| DiscordPlayer.getUser(event.getAuthor().getStringID(), DiscordPlayer.class).minecraftChat()
|
||||
.getOrDefault(false))
|
||||
if (!event.getMessage().getChannel().isPrivate() || DiscordPlayer
|
||||
.getUser(event.getAuthor().getStringID(), DiscordPlayer.class).minecraftChat().get())
|
||||
return;
|
||||
if (event.getMessage().getAuthor().isBot())
|
||||
return;
|
||||
|
|
|
@ -65,7 +65,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
final IUser iUser = data.channel.getUsersHere().stream()
|
||||
.filter(u -> u.getLongID() != u.getClient().getOurUser().getLongID()).findFirst().get(); // Doesn't support group DMs
|
||||
final DiscordPlayer user = DiscordPlayer.getUser(iUser.getStringID(), DiscordPlayer.class);
|
||||
if (user.minecraftChat().getOrDefault(false) && e.shouldSendTo(getSender(data.channel, iUser, user)))
|
||||
if (user.minecraftChat().get() && e.shouldSendTo(getSender(data.channel, iUser, user)))
|
||||
doit.accept(data);
|
||||
}
|
||||
} // TODO: Author URL
|
||||
|
@ -115,12 +115,9 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
*/
|
||||
private static ArrayList<LastMsgData> lastmsgPerUser = new ArrayList<LastMsgData>();
|
||||
|
||||
public static boolean startPrivateMCChat(IChannel channel) {
|
||||
return lastmsgPerUser.add(new LastMsgData(channel));
|
||||
}
|
||||
|
||||
public static boolean stopPrivateMCChat(IChannel channel) {
|
||||
return lastmsgPerUser.removeIf(lmd -> lmd.channel.getLongID() == channel.getLongID());
|
||||
public static boolean privateMCChat(IChannel channel, boolean start) {
|
||||
return start ? lastmsgPerUser.add(new LastMsgData(channel))
|
||||
: lastmsgPerUser.removeIf(lmd -> lmd.channel.getLongID() == channel.getLongID());
|
||||
}
|
||||
|
||||
public static final HashMap<String, DiscordSender> UnconnectedSenders = new HashMap<>();
|
||||
|
@ -136,7 +133,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
final IUser author = event.getMessage().getAuthor();
|
||||
final DiscordPlayer user = DiscordPlayer.getUser(author.getStringID(), DiscordPlayer.class);
|
||||
if (!event.getMessage().getChannel().getStringID().equals(DiscordPlugin.chatchannel.getStringID())
|
||||
&& !(event.getMessage().getChannel().isPrivate() && user.minecraftChat().getOrDefault(false)))
|
||||
&& !(event.getMessage().getChannel().isPrivate() && user.minecraftChat().get()))
|
||||
return;
|
||||
resetLastMessage();
|
||||
lastlist++;
|
||||
|
@ -225,7 +222,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
TBMCPlayer p = dp.getAs(TBMCPlayer.class);
|
||||
if (!UnconnectedSenders.containsKey(author.getStringID()))
|
||||
UnconnectedSenders.put(author.getStringID(),
|
||||
new DiscordSender(author, channel, p == null ? null : p.PlayerName().getOrDefault(null))); // Display the playername, if found
|
||||
new DiscordSender(author, channel, p == null ? null : p.PlayerName().get())); // Display the playername, if found
|
||||
dsender = UnconnectedSenders.get(author.getStringID());
|
||||
}
|
||||
return dsender;
|
||||
|
|
|
@ -25,22 +25,22 @@ public class MCListener implements Listener {
|
|||
@EventHandler
|
||||
public void onPlayerJoin(TBMCPlayerJoinEvent e) {
|
||||
final Player p = Bukkit.getPlayer(e.GetPlayer().getUUID());
|
||||
if (ConnectCommand.WaitingToConnect.containsKey(e.GetPlayer().PlayerName().getOrDefault(null))) {
|
||||
IUser user = DiscordPlugin.dc.getUserByID(
|
||||
Long.parseLong(ConnectCommand.WaitingToConnect.get(e.GetPlayer().PlayerName().getOrDefault(null))));
|
||||
if (ConnectCommand.WaitingToConnect.containsKey(e.GetPlayer().PlayerName().get())) {
|
||||
IUser user = DiscordPlugin.dc
|
||||
.getUserByID(Long.parseLong(ConnectCommand.WaitingToConnect.get(e.GetPlayer().PlayerName().get())));
|
||||
p.sendMessage("§bTo connect with the Discord account @" + user.getName() + "#" + user.getDiscriminator()
|
||||
+ " do /discord accept");
|
||||
p.sendMessage("§bIf it wasn't you, do /discord decline");
|
||||
}
|
||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
|
||||
e.GetPlayer().PlayerName().getOrDefault(null) + " joined the game");
|
||||
e.GetPlayer().PlayerName().get() + " joined the game");
|
||||
MCChatListener.ListC = 0;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(TBMCPlayerQuitEvent e) {
|
||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
|
||||
e.GetPlayer().PlayerName().getOrDefault(null) + " left the game");
|
||||
e.GetPlayer().PlayerName().get() + " left the game");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
|
Loading…
Reference in a new issue