Applied changes and a fix

This commit is contained in:
Norbi Peti 2017-06-30 18:29:21 +02:00
parent a6244b7f9f
commit 6dd21b03c1
5 changed files with 19 additions and 22 deletions

View file

@ -18,6 +18,6 @@ public class DiscordPlayer extends ChromaGamerBase {
} }
public PlayerData<Boolean> minecraftChat() { public PlayerData<Boolean> minecraftChat() {
return data(); return data(false);
} }
} }

View file

@ -1,6 +1,7 @@
package buttondevteam.discordplugin.commands; package buttondevteam.discordplugin.commands;
import buttondevteam.discordplugin.DiscordPlayer; import buttondevteam.discordplugin.DiscordPlayer;
import buttondevteam.discordplugin.listeners.MCChatListener;
import buttondevteam.lib.TBMCCoreAPI; import buttondevteam.lib.TBMCCoreAPI;
import buttondevteam.lib.player.PlayerData; import buttondevteam.lib.player.PlayerData;
import sx.blah.discord.handle.obj.IMessage; 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)) { try (final DiscordPlayer user = DiscordPlayer.getUser(message.getAuthor().getStringID(), DiscordPlayer.class)) {
PlayerData<Boolean> mcchat = user.minecraftChat(); PlayerData<Boolean> mcchat = user.minecraftChat();
mcchat.set(!mcchat.getOrDefault(false)); mcchat.set(!mcchat.get());
message.reply("Minecraft chat " + (mcchat.getOrDefault(false) // MCChatListener.privateMCChat(message.getChannel(), mcchat.get());
message.reply("Minecraft chat " + (mcchat.get() //
? "enabled. Use '" + message.getClient().getOurUser().mention() ? "enabled. Use '" + message.getClient().getOurUser().mention()
+ " mcchat' (with the mention) to disable." // + " mcchat' (with the mention) to disable." //
: "disabled.")); : "disabled."));

View file

@ -62,8 +62,7 @@ public class CommandListener {
return; return;
if (channel.getStringID().equals(DiscordPlugin.chatchannel.getStringID())) if (channel.getStringID().equals(DiscordPlugin.chatchannel.getStringID()))
return; // The chat code already handles this - Right now while testing botchannel is the same as chatchannel 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() if (DiscordPlayer.getUser(event.getAuthor().getStringID(), DiscordPlayer.class).minecraftChat().get()) // Let the MCChatListener handle it
.getOrDefault(false)) // Let the MCChatListener handle it
return; return;
event.getMessage().getChannel().setTypingStatus(true); // Fun event.getMessage().getChannel().setTypingStatus(true); // Fun
runCommand(event.getMessage(), true); runCommand(event.getMessage(), true);
@ -81,9 +80,8 @@ public class CommandListener {
next = usableServerReadyStrings.remove(serverReadyRandom.nextInt(usableServerReadyStrings.size())); next = usableServerReadyStrings.remove(serverReadyRandom.nextInt(usableServerReadyStrings.size()));
DiscordPlugin.sendMessageToChannel(event.getMessage().getChannel(), serverReadyStrings[next]); DiscordPlugin.sendMessageToChannel(event.getMessage().getChannel(), serverReadyStrings[next]);
} }
if (!event.getMessage().getChannel().isPrivate() if (!event.getMessage().getChannel().isPrivate() || DiscordPlayer
|| DiscordPlayer.getUser(event.getAuthor().getStringID(), DiscordPlayer.class).minecraftChat() .getUser(event.getAuthor().getStringID(), DiscordPlayer.class).minecraftChat().get())
.getOrDefault(false))
return; return;
if (event.getMessage().getAuthor().isBot()) if (event.getMessage().getAuthor().isBot())
return; return;

View file

@ -65,7 +65,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
final IUser iUser = data.channel.getUsersHere().stream() final IUser iUser = data.channel.getUsersHere().stream()
.filter(u -> u.getLongID() != u.getClient().getOurUser().getLongID()).findFirst().get(); // Doesn't support group DMs .filter(u -> u.getLongID() != u.getClient().getOurUser().getLongID()).findFirst().get(); // Doesn't support group DMs
final DiscordPlayer user = DiscordPlayer.getUser(iUser.getStringID(), DiscordPlayer.class); 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); doit.accept(data);
} }
} // TODO: Author URL } // TODO: Author URL
@ -115,12 +115,9 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
*/ */
private static ArrayList<LastMsgData> lastmsgPerUser = new ArrayList<LastMsgData>(); private static ArrayList<LastMsgData> lastmsgPerUser = new ArrayList<LastMsgData>();
public static boolean startPrivateMCChat(IChannel channel) { public static boolean privateMCChat(IChannel channel, boolean start) {
return lastmsgPerUser.add(new LastMsgData(channel)); return start ? lastmsgPerUser.add(new LastMsgData(channel))
} : lastmsgPerUser.removeIf(lmd -> lmd.channel.getLongID() == channel.getLongID());
public static boolean stopPrivateMCChat(IChannel channel) {
return lastmsgPerUser.removeIf(lmd -> lmd.channel.getLongID() == channel.getLongID());
} }
public static final HashMap<String, DiscordSender> UnconnectedSenders = new HashMap<>(); 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 IUser author = event.getMessage().getAuthor();
final DiscordPlayer user = DiscordPlayer.getUser(author.getStringID(), DiscordPlayer.class); final DiscordPlayer user = DiscordPlayer.getUser(author.getStringID(), DiscordPlayer.class);
if (!event.getMessage().getChannel().getStringID().equals(DiscordPlugin.chatchannel.getStringID()) 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; return;
resetLastMessage(); resetLastMessage();
lastlist++; lastlist++;
@ -225,7 +222,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
TBMCPlayer p = dp.getAs(TBMCPlayer.class); TBMCPlayer p = dp.getAs(TBMCPlayer.class);
if (!UnconnectedSenders.containsKey(author.getStringID())) if (!UnconnectedSenders.containsKey(author.getStringID()))
UnconnectedSenders.put(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()); dsender = UnconnectedSenders.get(author.getStringID());
} }
return dsender; return dsender;

View file

@ -25,22 +25,22 @@ public class MCListener implements Listener {
@EventHandler @EventHandler
public void onPlayerJoin(TBMCPlayerJoinEvent e) { public void onPlayerJoin(TBMCPlayerJoinEvent e) {
final Player p = Bukkit.getPlayer(e.GetPlayer().getUUID()); final Player p = Bukkit.getPlayer(e.GetPlayer().getUUID());
if (ConnectCommand.WaitingToConnect.containsKey(e.GetPlayer().PlayerName().getOrDefault(null))) { if (ConnectCommand.WaitingToConnect.containsKey(e.GetPlayer().PlayerName().get())) {
IUser user = DiscordPlugin.dc.getUserByID( IUser user = DiscordPlugin.dc
Long.parseLong(ConnectCommand.WaitingToConnect.get(e.GetPlayer().PlayerName().getOrDefault(null)))); .getUserByID(Long.parseLong(ConnectCommand.WaitingToConnect.get(e.GetPlayer().PlayerName().get())));
p.sendMessage("§bTo connect with the Discord account @" + user.getName() + "#" + user.getDiscriminator() p.sendMessage("§bTo connect with the Discord account @" + user.getName() + "#" + user.getDiscriminator()
+ " do /discord accept"); + " do /discord accept");
p.sendMessage("§bIf it wasn't you, do /discord decline"); p.sendMessage("§bIf it wasn't you, do /discord decline");
} }
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel, DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
e.GetPlayer().PlayerName().getOrDefault(null) + " joined the game"); e.GetPlayer().PlayerName().get() + " joined the game");
MCChatListener.ListC = 0; MCChatListener.ListC = 0;
} }
@EventHandler @EventHandler
public void onPlayerLeave(TBMCPlayerQuitEvent e) { public void onPlayerLeave(TBMCPlayerQuitEvent e) {
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel, DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
e.GetPlayer().PlayerName().getOrDefault(null) + " left the game"); e.GetPlayer().PlayerName().get() + " left the game");
} }
@EventHandler @EventHandler