#32, progress with mcchat (#12)

This commit is contained in:
Norbi Peti 2017-05-31 22:42:19 +02:00
parent 9abb342aa9
commit c4323d3388
2 changed files with 13 additions and 7 deletions

View file

@ -1,6 +1,7 @@
package buttondevteam.discordplugin.commands; package buttondevteam.discordplugin.commands;
import buttondevteam.discordplugin.DiscordPlayer; import buttondevteam.discordplugin.DiscordPlayer;
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;
@ -17,10 +18,13 @@ public class MCChatCommand extends DiscordCommandBase {
message.reply("This command can only be issued while DMing the bot."); message.reply("This command can only be issued while DMing the bot.");
return; return;
} }
PlayerData<Boolean> mcchat = DiscordPlayer.getUser(message.getAuthor().getStringID(), DiscordPlayer.class) try (final DiscordPlayer user = DiscordPlayer.getUser(message.getAuthor().getStringID(), DiscordPlayer.class)) {
.minecraftChat(); PlayerData<Boolean> mcchat = user.minecraftChat();
mcchat.set(!mcchat.getOrDefault(false)); mcchat.set(!mcchat.getOrDefault(false));
message.reply("Minecraft chat " + (mcchat.get() ? "enabled." : "disabled.")); message.reply("Minecraft chat " + (mcchat.get() ? "enabled." : "disabled."));
} catch (Exception e) {
TBMCCoreAPI.SendException("Error while setting mcchat for user" + message.getAuthor().getName(), e);
}
} }
@Override @Override

View file

@ -147,11 +147,15 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
} }
if (dmessage.startsWith("/")) { if (dmessage.startsWith("/")) {
DiscordPlugin.perform(() -> {
if (!event.getMessage().isDeleted())
event.getMessage().delete();
});
final String cmd = dmessage.substring(1).toLowerCase(); final String cmd = dmessage.substring(1).toLowerCase();
if (dsender instanceof DiscordSender && !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 dsender.sendMessage( // TODO
"Sorry, you need to be online on the server and have your accounts connected, you can only access these commands:\n" "Sorry, you need to be online on the server and have your accounts connected, you can only access these commands:\n"
+ Arrays.stream(UnconnectedCmds).map(uc -> "/" + uc) + Arrays.stream(UnconnectedCmds).map(uc -> "/" + uc)
.collect(Collectors.joining(", ")) .collect(Collectors.joining(", "))
@ -170,8 +174,6 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
} else } else
Bukkit.dispatchCommand(dsender, cmd); Bukkit.dispatchCommand(dsender, cmd);
lastlistp = (short) Bukkit.getOnlinePlayers().size(); lastlistp = (short) Bukkit.getOnlinePlayers().size();
if (!event.getMessage().isDeleted())
event.getMessage().delete();
} else { } else {
TBMCChatAPI.SendChatMessage(Channel.GlobalChat, dsender, TBMCChatAPI.SendChatMessage(Channel.GlobalChat, dsender,
dmessage + (event.getMessage().getAttachments().size() > 0 ? "\n" + event.getMessage() dmessage + (event.getMessage().getAttachments().size() > 0 ? "\n" + event.getMessage()