2022-05-08 23:34:03 +00:00
|
|
|
package dev.plex.command.sub;
|
|
|
|
|
|
|
|
import dev.plex.Guilds;
|
|
|
|
import dev.plex.command.PlexCommand;
|
|
|
|
import dev.plex.command.annotation.CommandParameters;
|
|
|
|
import dev.plex.command.annotation.CommandPermissions;
|
|
|
|
import dev.plex.command.source.RequiredCommandSource;
|
|
|
|
import dev.plex.guild.data.Member;
|
|
|
|
import net.kyori.adventure.text.Component;
|
2022-06-14 04:14:06 +00:00
|
|
|
import org.apache.commons.lang3.BooleanUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2022-05-08 23:34:03 +00:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
2022-05-09 00:52:08 +00:00
|
|
|
@CommandParameters(name = "chat", usage = "/guild <command> [message]", description = "Toggles guild chat or sends a guild chat message")
|
2023-09-08 22:40:39 +00:00
|
|
|
@CommandPermissions(source = RequiredCommandSource.IN_GAME, permission = "plex.guilds.chat")
|
2022-05-08 23:34:03 +00:00
|
|
|
public class ChatSubCommand extends PlexCommand
|
|
|
|
{
|
|
|
|
public ChatSubCommand()
|
|
|
|
{
|
|
|
|
super(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Component execute(@NotNull CommandSender commandSender, @Nullable Player player, @NotNull String[] args)
|
|
|
|
{
|
|
|
|
assert player != null;
|
|
|
|
Guilds.get().getGuildHolder().getGuild(player.getUniqueId()).ifPresentOrElse(guild ->
|
|
|
|
{
|
|
|
|
if (args.length == 0)
|
|
|
|
{
|
|
|
|
Member member = guild.getMember(player.getUniqueId());
|
|
|
|
member.setChat(!member.isChat());
|
|
|
|
send(player, messageComponent("guildChatToggled", BooleanUtils.toStringOnOff(member.isChat())));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
guild.getMembers().stream().map(Member::getPlayer).filter(Objects::nonNull).forEach(player1 ->
|
|
|
|
{
|
2022-05-09 05:39:47 +00:00
|
|
|
send(player1, messageComponent("guildChatMessage", player.getName(), StringUtils.join(args, " ")));
|
2022-05-08 23:34:03 +00:00
|
|
|
});
|
|
|
|
if (Guilds.get().getConfig().isBoolean("guilds.log-chat-message"))
|
|
|
|
{
|
2022-05-09 05:39:47 +00:00
|
|
|
send(Bukkit.getConsoleSender(), messageComponent("guildChatConsoleLog", guild.getName(), guild.getGuildUuid(), player.getName(), StringUtils.join(args, " ")));
|
2022-05-08 23:34:03 +00:00
|
|
|
}
|
|
|
|
}, () -> send(player, messageComponent("guildNotFound")));
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|