Getting sender for receiving messages too
This commit is contained in:
parent
cb8eeb20c2
commit
173bc40a1d
1 changed files with 26 additions and 22 deletions
|
@ -61,12 +61,12 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
doit.accept(lastmsgdata);
|
doit.accept(lastmsgdata);
|
||||||
|
|
||||||
for (LastMsgData data : lastmsgPerUser) {
|
for (LastMsgData data : lastmsgPerUser) {
|
||||||
final DiscordPlayer user = DiscordPlayer.getUser(data.channel.getUsersHere().stream()
|
final IUser iUser = data.channel.getUsersHere().stream()
|
||||||
.filter(u -> u.getLongID() != u.getClient().getOurUser().getLongID()).findFirst().get()
|
.filter(u -> u.getLongID() != u.getClient().getOurUser().getLongID()).findFirst().get(); // Doesn't support group DMs
|
||||||
.getStringID(), DiscordPlayer.class);
|
final DiscordPlayer user = DiscordPlayer.getUser(iUser.getStringID(), DiscordPlayer.class);
|
||||||
if (user.minecraftChat().get() && e.shouldSendTo()) // TODO!
|
if (user.minecraftChat().get() && e.shouldSendTo(getSender(data.channel, iUser, user)))
|
||||||
doit.accept(data);
|
doit.accept(data);
|
||||||
} // TODO: CHeck if user should get the message (get user from channel)
|
}
|
||||||
} // TODO: Author URL
|
} // TODO: Author URL
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,22 +138,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
try {
|
try {
|
||||||
DiscordPlayer dp = ChromaGamerBase.getUser(author.getStringID(), DiscordPlayer.class);
|
DiscordPlayer dp = ChromaGamerBase.getUser(author.getStringID(), DiscordPlayer.class);
|
||||||
final DiscordSenderBase dsender;
|
final DiscordSenderBase dsender = getSender(event.getMessage().getChannel(), author, dp);
|
||||||
Player mcp = null; // Offline players can't really run commands, or can they? No, they can't, really.
|
|
||||||
final String cid;
|
|
||||||
if ((cid = dp.getConnectedID(TBMCPlayer.class)) != null // Connected?
|
|
||||||
&& (mcp = Bukkit.getPlayer(UUID.fromString(cid))) != null) { // Execute as ingame player
|
|
||||||
if (!ConnectedSenders.containsKey(author.getStringID()))
|
|
||||||
ConnectedSenders.put(author.getStringID(),
|
|
||||||
new DiscordPlayerSender(author, event.getMessage().getChannel(), mcp));
|
|
||||||
dsender = ConnectedSenders.get(author.getStringID());
|
|
||||||
} else {
|
|
||||||
TBMCPlayer p = dp.getAs(TBMCPlayer.class);
|
|
||||||
if (!UnconnectedSenders.containsKey(author.getStringID()))
|
|
||||||
UnconnectedSenders.put(author.getStringID(), new DiscordSender(author,
|
|
||||||
event.getMessage().getChannel(), p == null ? null : p.PlayerName().get())); // Display the playername, if found
|
|
||||||
dsender = UnconnectedSenders.get(author.getStringID());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (IUser u : event.getMessage().getMentions()) {
|
for (IUser u : event.getMessage().getMentions()) {
|
||||||
dmessage = dmessage.replace(u.mention(false), "@" + u.getName()); // TODO: IG Formatting
|
dmessage = dmessage.replace(u.mention(false), "@" + u.getName()); // TODO: IG Formatting
|
||||||
|
@ -163,7 +148,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
|
|
||||||
if (dmessage.startsWith("/")) {
|
if (dmessage.startsWith("/")) {
|
||||||
final String cmd = dmessage.substring(1).toLowerCase();
|
final String cmd = dmessage.substring(1).toLowerCase();
|
||||||
if (mcp == null && !Arrays.stream(UnconnectedCmds)
|
if (dsender instanceof DiscordSender && !Arrays.stream(UnconnectedCmds)
|
||||||
.anyMatch(s -> cmd.equals(s) || cmd.startsWith(s + " "))) {
|
.anyMatch(s -> cmd.equals(s) || cmd.startsWith(s + " "))) {
|
||||||
// Command not whitelisted
|
// Command not whitelisted
|
||||||
DiscordPlugin.sendMessageToChannel(event.getMessage().getChannel(), // TODO
|
DiscordPlugin.sendMessageToChannel(event.getMessage().getChannel(), // TODO
|
||||||
|
@ -209,4 +194,23 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DiscordSenderBase getSender(IChannel channel, final IUser author, DiscordPlayer dp) {
|
||||||
|
final DiscordSenderBase dsender;
|
||||||
|
Player mcp = null; // Offline players can't really run commands, or can they? No, they can't, really.
|
||||||
|
final String cid;
|
||||||
|
if ((cid = dp.getConnectedID(TBMCPlayer.class)) != null // Connected?
|
||||||
|
&& (mcp = Bukkit.getPlayer(UUID.fromString(cid))) != null) { // Execute as ingame player
|
||||||
|
if (!ConnectedSenders.containsKey(author.getStringID()))
|
||||||
|
ConnectedSenders.put(author.getStringID(), new DiscordPlayerSender(author, channel, mcp));
|
||||||
|
dsender = ConnectedSenders.get(author.getStringID());
|
||||||
|
} else {
|
||||||
|
TBMCPlayer p = dp.getAs(TBMCPlayer.class);
|
||||||
|
if (!UnconnectedSenders.containsKey(author.getStringID()))
|
||||||
|
UnconnectedSenders.put(author.getStringID(),
|
||||||
|
new DiscordSender(author, channel, p == null ? null : p.PlayerName().get())); // Display the playername, if found
|
||||||
|
dsender = UnconnectedSenders.get(author.getStringID());
|
||||||
|
}
|
||||||
|
return dsender;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue