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

57 lines
2.2 KiB
Java
Raw Normal View History

2022-02-25 03:56:28 +00:00
package dev.plex.command.impl;
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;
2022-06-08 20:09:42 +00:00
import org.apache.commons.lang3.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"))
{
2022-05-18 10:31:15 +00:00
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(player.getUniqueId());
2022-04-07 07:37:31 +00:00
if (plexPlayer.getRankFromString().isAtLeast(Rank.ADMIN) && plexPlayer.isAdminActive())
2022-03-19 01:12:05 +00:00
{
player.sendMessage(PlexUtils.messageComponent("adminChatFormat", sender.getName(), message));
}
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
if (plugin.getPermissionHandler().hasPermission(player, "plex.adminchat"))
2022-03-19 01:12:05 +00:00
{
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
}