Partially added #16
This commit is contained in:
parent
fbfa5c9b26
commit
0636cb8f33
1 changed files with 13 additions and 6 deletions
|
@ -46,6 +46,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
if (!event.getMessage().getChannel().getID().equals(DiscordPlugin.chatchannel.getID())
|
if (!event.getMessage().getChannel().getID().equals(DiscordPlugin.chatchannel.getID())
|
||||||
/* && !(event.getMessage().getChannel().isPrivate() && privatechat) */)
|
/* && !(event.getMessage().getChannel().isPrivate() && privatechat) */)
|
||||||
return;
|
return;
|
||||||
|
String dmessage = event.getMessage().getContent();
|
||||||
try {
|
try {
|
||||||
Optional<? extends Player> player = Bukkit.getOnlinePlayers().stream().filter(p -> { // TODO: Support offline players
|
Optional<? extends Player> player = Bukkit.getOnlinePlayers().stream().filter(p -> { // TODO: Support offline players
|
||||||
DiscordPlayer dp = TBMCPlayer.getPlayerAs(p, DiscordPlayer.class); // Online player, already loaded
|
DiscordPlayer dp = TBMCPlayer.getPlayerAs(p, DiscordPlayer.class); // Online player, already loaded
|
||||||
|
@ -63,8 +64,15 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
UnconnectedSenders.put(author.getID(), new DiscordSender(author, event.getMessage().getChannel()));
|
UnconnectedSenders.put(author.getID(), new DiscordSender(author, event.getMessage().getChannel()));
|
||||||
dsender = UnconnectedSenders.get(author.getID());
|
dsender = UnconnectedSenders.get(author.getID());
|
||||||
}
|
}
|
||||||
if (event.getMessage().getContent().startsWith("/")) {
|
|
||||||
final String cmd = event.getMessage().getContent().substring(1).toLowerCase();
|
for (IUser u : event.getMessage().getMentions()) {
|
||||||
|
dmessage = dmessage.replace(u.mention(false), "@" + u.getName()); // TODO: IG Formatting
|
||||||
|
final Optional<String> nick = u.getNicknameForGuild(DiscordPlugin.mainServer);
|
||||||
|
dmessage = dmessage.replace(u.mention(true), "@" + (nick.isPresent() ? nick.get() : u.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dmessage.startsWith("/")) {
|
||||||
|
final String cmd = dmessage.substring(1).toLowerCase();
|
||||||
if (!player.isPresent()
|
if (!player.isPresent()
|
||||||
&& !Arrays.stream(UnconnectedCmds).anyMatch(s -> cmd.equals(s) || cmd.startsWith(s + " "))) {
|
&& !Arrays.stream(UnconnectedCmds).anyMatch(s -> cmd.equals(s) || cmd.startsWith(s + " "))) {
|
||||||
// Command not whitelisted
|
// Command not whitelisted
|
||||||
|
@ -78,13 +86,12 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
Bukkit.dispatchCommand(dsender, cmd);
|
Bukkit.dispatchCommand(dsender, cmd);
|
||||||
} else
|
} else
|
||||||
TBMCChatAPI.SendChatMessage(Channel.GlobalChat, dsender,
|
TBMCChatAPI.SendChatMessage(Channel.GlobalChat, dsender,
|
||||||
event.getMessage().getContent()
|
dmessage + (event.getMessage().getAttachments().size() > 0 ? event.getMessage().getAttachments()
|
||||||
+ (event.getMessage().getAttachments().size() > 0 ? event.getMessage().getAttachments()
|
.stream().map(a -> a.getUrl()).collect(Collectors.joining("\n")) : ""));
|
||||||
.stream().map(a -> a.getUrl()).collect(Collectors.joining("\n")) : ""));
|
|
||||||
} catch (
|
} catch (
|
||||||
|
|
||||||
Exception e) {
|
Exception e) {
|
||||||
TBMCCoreAPI.SendException("An error occured while handling " + event.getMessage().getContent() + "!", e);
|
TBMCCoreAPI.SendException("An error occured while handling " + dmessage + "!", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue