Plex/src/main/java/dev/plex/command/impl/AdminChatCMD.java

58 lines
2.2 KiB
Java
Raw Normal View History

2022-02-25 03:56:28 +00:00
package dev.plex.command.impl;
2022-03-19 01:12:05 +00:00
import dev.plex.cache.PlayerCache;
2022-02-25 03:56:28 +00:00
import dev.plex.command.PlexCommand;
import dev.plex.command.annotation.CommandParameters;
import dev.plex.command.annotation.CommandPermissions;
import dev.plex.command.source.RequiredCommandSource;
2022-03-19 01:12:05 +00:00
import dev.plex.player.PlexPlayer;
2022-02-25 03:56:28 +00:00
import dev.plex.rank.enums.Rank;
2022-03-19 01:12:05 +00:00
import dev.plex.util.PlexUtils;
2022-02-25 03:56:28 +00:00
import net.kyori.adventure.text.Component;
import org.apache.commons.lang.StringUtils;
2022-03-19 01:12:05 +00:00
import org.bukkit.Bukkit;
2022-02-25 03:56:28 +00:00
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@CommandPermissions(level = Rank.ADMIN, permission = "plex.adminchat", source = RequiredCommandSource.ANY)
2022-02-26 06:26:42 +00:00
@CommandParameters(name = "adminchat", description = "Talk privately with other admins", usage = "/<command> <message>", aliases = "o,ac,sc,staffchat")
2022-02-25 03:56:28 +00:00
public class AdminChatCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{
return usage();
}
2022-03-19 01:12:05 +00:00
adminChat(sender, StringUtils.join(args, " "));
2022-02-25 03:56:28 +00:00
return null;
}
2022-03-19 01:12:05 +00:00
private void adminChat(CommandSender sender, String message)
{
for (Player player : Bukkit.getOnlinePlayers())
{
if (plugin.getSystem().equalsIgnoreCase("ranks"))
{
PlexPlayer plexPlayer = PlayerCache.getPlexPlayerMap().get(player.getUniqueId());
if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN))
{
player.sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
}
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
if (player.hasPermission("plex.adminchat"))
{
player.sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
}
}
}
plugin.getServer().getConsoleSender().sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
}
2022-02-25 03:56:28 +00:00
}