parent
9abb342aa9
commit
c4323d3388
2 changed files with 13 additions and 7 deletions
|
@ -1,6 +1,7 @@
|
|||
package buttondevteam.discordplugin.commands;
|
||||
|
||||
import buttondevteam.discordplugin.DiscordPlayer;
|
||||
import buttondevteam.lib.TBMCCoreAPI;
|
||||
import buttondevteam.lib.player.PlayerData;
|
||||
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.");
|
||||
return;
|
||||
}
|
||||
PlayerData<Boolean> mcchat = DiscordPlayer.getUser(message.getAuthor().getStringID(), DiscordPlayer.class)
|
||||
.minecraftChat();
|
||||
try (final DiscordPlayer user = DiscordPlayer.getUser(message.getAuthor().getStringID(), DiscordPlayer.class)) {
|
||||
PlayerData<Boolean> mcchat = user.minecraftChat();
|
||||
mcchat.set(!mcchat.getOrDefault(false));
|
||||
message.reply("Minecraft chat " + (mcchat.get() ? "enabled." : "disabled."));
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("Error while setting mcchat for user" + message.getAuthor().getName(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -147,11 +147,15 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
}
|
||||
|
||||
if (dmessage.startsWith("/")) {
|
||||
DiscordPlugin.perform(() -> {
|
||||
if (!event.getMessage().isDeleted())
|
||||
event.getMessage().delete();
|
||||
});
|
||||
final String cmd = dmessage.substring(1).toLowerCase();
|
||||
if (dsender instanceof DiscordSender && !Arrays.stream(UnconnectedCmds)
|
||||
.anyMatch(s -> cmd.equals(s) || cmd.startsWith(s + " "))) {
|
||||
// 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"
|
||||
+ Arrays.stream(UnconnectedCmds).map(uc -> "/" + uc)
|
||||
.collect(Collectors.joining(", "))
|
||||
|
@ -170,8 +174,6 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
} else
|
||||
Bukkit.dispatchCommand(dsender, cmd);
|
||||
lastlistp = (short) Bukkit.getOnlinePlayers().size();
|
||||
if (!event.getMessage().isDeleted())
|
||||
event.getMessage().delete();
|
||||
} else {
|
||||
TBMCChatAPI.SendChatMessage(Channel.GlobalChat, dsender,
|
||||
dmessage + (event.getMessage().getAttachments().size() > 0 ? "\n" + event.getMessage()
|
||||
|
|
Loading…
Reference in a new issue