Add adminchat

This commit is contained in:
Telesphoreo 2022-02-24 21:56:28 -06:00
parent b37cd31e98
commit b6f4ddbb4c
5 changed files with 85 additions and 19 deletions

View File

@ -0,0 +1,33 @@
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;
import dev.plex.listener.impl.ChatListener;
import dev.plex.rank.enums.Rank;
import net.kyori.adventure.text.Component;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
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)
@CommandParameters(name = "adminchat", description = "Talk privately with other admins", usage = "/<command> <message>", aliases = "o,ac,sc,staffchat")
public class AdminChatCMD extends PlexCommand
{
@Override
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args)
{
if (args.length == 0)
{
return usage();
}
ChatListener.adminChat(sender, StringUtils.join(args, " "));
return null;
}
}

View File

@ -27,6 +27,7 @@ public class CommandHandler extends PlexBase
commands.add(new DebugCMD()); commands.add(new DebugCMD());
} }
commands.add(new AdminChatCMD());
commands.add(new AdminworldCMD()); commands.add(new AdminworldCMD());
commands.add(new AdventureCMD()); commands.add(new AdventureCMD());
commands.add(new BanCMD()); commands.add(new BanCMD());

View File

@ -3,12 +3,16 @@ package dev.plex.listener.impl;
import dev.plex.cache.PlayerCache; import dev.plex.cache.PlayerCache;
import dev.plex.listener.PlexListener; import dev.plex.listener.PlexListener;
import dev.plex.player.PlexPlayer; import dev.plex.player.PlexPlayer;
import dev.plex.rank.enums.Rank;
import dev.plex.util.PlexUtils;
import io.papermc.paper.chat.ChatRenderer; import io.papermc.paper.chat.ChatRenderer;
import io.papermc.paper.event.player.AsyncChatEvent; import io.papermc.paper.event.player.AsyncChatEvent;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -31,6 +35,29 @@ public class ChatListener extends PlexListener
event.renderer(renderer); event.renderer(renderer);
} }
public static 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.tl("adminChatFormat", sender.getName(), message));
}
}
else if (plugin.getSystem().equalsIgnoreCase("permissions"))
{
if (player.hasPermission("plex.adminchat"))
{
player.sendMessage(PlexUtils.tl("adminChatFormat", sender.getName(), message));
}
}
}
Bukkit.getLogger().info(PlexUtils.tl("adminChatFormat", sender.getName(), message));
}
public static class PlexChatRenderer implements ChatRenderer public static class PlexChatRenderer implements ChatRenderer
{ {
public boolean hasPrefix; public boolean hasPrefix;

View File

@ -195,33 +195,37 @@ public class PlexUtils extends PlexBase
Bukkit.broadcast(component); Bukkit.broadcast(component);
} }
public static Object simpleGET(String url) throws IOException, ParseException public static Object simpleGET(String url)
{ {
URL u = new URL(url); try
HttpURLConnection connection = (HttpURLConnection)u.openConnection();
connection.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
StringBuilder content = new StringBuilder();
while ((line = in.readLine()) != null)
{ {
content.append(line); URL u = new URL(url);
HttpURLConnection connection = (HttpURLConnection)u.openConnection();
connection.setRequestMethod("GET");
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
StringBuilder content = new StringBuilder();
while ((line = in.readLine()) != null)
{
content.append(line);
}
in.close();
connection.disconnect();
return new JSONParser().parse(content.toString());
}
catch (IOException | ParseException ex)
{
return null;
} }
in.close();
connection.disconnect();
return new JSONParser().parse(content.toString());
} }
public static UUID getFromName(String name) public static UUID getFromName(String name)
{ {
JSONObject profile; JSONObject profile;
try profile = (JSONObject)simpleGET("https://api.ashcon.app/mojang/v2/user/" + name);
if (profile == null)
{ {
profile = (JSONObject)PlexUtils.simpleGET("https://api.ashcon.app/mojang/v2/user/" + name); PlexLog.error("Profile from Ashcon API returned null!");
}
catch (IOException | ParseException e)
{
e.printStackTrace();
return null; return null;
} }
String uuidString = (String)profile.get("uuid"); String uuidString = (String)profile.get("uuid");

View File

@ -104,3 +104,4 @@ teleportedToWorldSpawn: "<b>Teleporting to the local spawn"
toggleCommandSpy: "CommandSpy has been " toggleCommandSpy: "CommandSpy has been "
enabled: "enabled" enabled: "enabled"
disabled: "disabled" disabled: "disabled"
adminChatFormat: '&8[&9AdminChat&8] &4<v> &7» &6<v>'