mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
Add adminchat
This commit is contained in:
parent
b37cd31e98
commit
b6f4ddbb4c
33
src/main/java/dev/plex/command/impl/AdminChatCMD.java
Normal file
33
src/main/java/dev/plex/command/impl/AdminChatCMD.java
Normal 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;
|
||||
}
|
||||
}
|
@ -27,6 +27,7 @@ public class CommandHandler extends PlexBase
|
||||
commands.add(new DebugCMD());
|
||||
}
|
||||
|
||||
commands.add(new AdminChatCMD());
|
||||
commands.add(new AdminworldCMD());
|
||||
commands.add(new AdventureCMD());
|
||||
commands.add(new BanCMD());
|
||||
|
@ -3,12 +3,16 @@ package dev.plex.listener.impl;
|
||||
import dev.plex.cache.PlayerCache;
|
||||
import dev.plex.listener.PlexListener;
|
||||
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.event.player.AsyncChatEvent;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
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.event.EventHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -31,6 +35,29 @@ public class ChatListener extends PlexListener
|
||||
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 boolean hasPrefix;
|
||||
|
@ -195,33 +195,37 @@ public class PlexUtils extends PlexBase
|
||||
Bukkit.broadcast(component);
|
||||
}
|
||||
|
||||
public static Object simpleGET(String url) throws IOException, ParseException
|
||||
public static Object simpleGET(String url)
|
||||
{
|
||||
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)
|
||||
try
|
||||
{
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
catch (IOException | ParseException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
PlexLog.error("Profile from Ashcon API returned null!");
|
||||
return null;
|
||||
}
|
||||
String uuidString = (String)profile.get("uuid");
|
||||
|
@ -103,4 +103,5 @@ playerNotBanned: "<e>That player is not banned!"
|
||||
teleportedToWorldSpawn: "<b>Teleporting to the local spawn"
|
||||
toggleCommandSpy: "CommandSpy has been "
|
||||
enabled: "enabled"
|
||||
disabled: "disabled"
|
||||
disabled: "disabled"
|
||||
adminChatFormat: '&8[&9AdminChat&8] &4<v> &7» &6<v>'
|
Loading…
Reference in New Issue
Block a user