Finished private Minecraft chat, lots of bug fixes #42
3 changed files with 29 additions and 6 deletions
|
@ -16,13 +16,13 @@ public class MCChatCommand extends DiscordCommandBase {
|
|||
@Override
|
||||
public void run(IMessage message, String args) {
|
||||
if (!message.getChannel().isPrivate()) {
|
||||
message.reply("This command can only be issued while DMing the bot.");
|
||||
message.reply("This command can only be issued in a direct message with the bot.");
|
||||
return;
|
||||
}
|
||||
try (final DiscordPlayer user = DiscordPlayer.getUser(message.getAuthor().getStringID(), DiscordPlayer.class)) {
|
||||
PlayerData<Boolean> mcchat = user.minecraftChat();
|
||||
mcchat.set(!mcchat.get());
|
||||
MCChatListener.privateMCChat(message.getChannel(), mcchat.get());
|
||||
MCChatListener.privateMCChat(message.getChannel(), mcchat.get(), message.getAuthor(), user);
|
||||
message.reply("Minecraft chat " + (mcchat.get() //
|
||||
? "enabled. Use '" + message.getClient().getOurUser().mention()
|
||||
+ " mcchat' (with the mention) to disable." //
|
||||
|
|
|
@ -13,6 +13,8 @@ import org.bukkit.Bukkit;
|
|||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
import buttondevteam.discordplugin.*;
|
||||
import buttondevteam.lib.*;
|
||||
|
@ -123,8 +125,20 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
*/
|
||||
private static ArrayList<LastMsgData> lastmsgPerUser = new ArrayList<LastMsgData>();
|
||||
|
||||
public static boolean privateMCChat(IChannel channel, boolean start) {
|
||||
return start ? lastmsgPerUser.add(new LastMsgData(channel))
|
||||
public static boolean privateMCChat(IChannel channel, boolean start, IUser user, DiscordPlayer dp) {
|
||||
if (start) {
|
||||
val sender = new DiscordConnectedPlayer(user, channel,
|
||||
UUID.fromString(dp.getConnectedID(TBMCPlayer.class)));
|
||||
ConnectedSenders.put(user.getStringID(), sender);
|
||||
if (!OnlineSenders.containsKey(user.getStringID()))// If the player is online, that takes precedence
|
||||
Bukkit.getPluginManager().callEvent(new PlayerJoinEvent(sender, ""));
|
||||
} else {
|
||||
val sender = ConnectedSenders.remove(user.getStringID());
|
||||
if (!OnlineSenders.containsKey(user.getStringID()))// If the player is online, that takes precedence
|
||||
Bukkit.getPluginManager().callEvent(new PlayerQuitEvent(sender, ""));
|
||||
}
|
||||
return start //
|
||||
? lastmsgPerUser.add(new LastMsgData(channel)) //
|
||||
: lastmsgPerUser.removeIf(lmd -> lmd.channel.getLongID() == channel.getLongID());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package buttondevteam.discordplugin.listeners;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
|
@ -10,7 +9,9 @@ import org.bukkit.event.server.ServerCommandEvent;
|
|||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
|
||||
import buttondevteam.discordplugin.DiscordConnectedPlayer;
|
||||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.discordplugin.DiscordPlayerSender;
|
||||
import buttondevteam.discordplugin.DiscordPlugin;
|
||||
import buttondevteam.discordplugin.commands.ConnectCommand;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
|
@ -24,7 +25,12 @@ import sx.blah.discord.util.MissingPermissionsException;
|
|||
public class MCListener implements Listener {
|
||||
@EventHandler
|
||||
public void onPlayerJoin(TBMCPlayerJoinEvent e) {
|
||||
final Player p = Bukkit.getPlayer(e.GetPlayer().getUUID());
|
||||
if (e.getPlayer() instanceof DiscordConnectedPlayer)
|
||||
return; // Don't show the joined message for the fake player
|
||||
final Player p = e.getPlayer();
|
||||
DiscordPlayer dp = e.GetPlayer().getAs(DiscordPlayer.class);
|
||||
// if(dp!=null) //TODO
|
||||
// MCChatListener.OnlineSenders.put(dp.getDiscordID(), new DiscordPlayerSender(DiscordPlugin.dc.getUserByID(Long.parseLong(dp.getDiscordID()), channel, player))
|
||||
if (ConnectCommand.WaitingToConnect.containsKey(e.GetPlayer().PlayerName().get())) {
|
||||
IUser user = DiscordPlugin.dc
|
||||
.getUserByID(Long.parseLong(ConnectCommand.WaitingToConnect.get(e.GetPlayer().PlayerName().get())));
|
||||
|
@ -39,6 +45,9 @@ public class MCListener implements Listener {
|
|||
|
||||
@EventHandler
|
||||
public void onPlayerLeave(TBMCPlayerQuitEvent e) {
|
||||
if (MCChatListener.OnlineSenders.entrySet()
|
||||
.removeIf(entry -> entry.getValue().getUniqueId().equals(e.getPlayer().getUniqueId())))
|
||||
; // TODO
|
||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
|
||||
e.GetPlayer().PlayerName().get() + " left the game");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue