mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 00:57:37 +00:00
Make the list command work with the permission system
This commit is contained in:
parent
00b6473e4d
commit
41b0076f8f
@ -21,14 +21,9 @@ import dev.plex.storage.player.MongoPlayerData;
|
||||
import dev.plex.storage.player.SQLPlayerData;
|
||||
import dev.plex.storage.punishment.SQLNotes;
|
||||
import dev.plex.storage.punishment.SQLPunishment;
|
||||
import dev.plex.util.BuildInfo;
|
||||
import dev.plex.util.BungeeUtil;
|
||||
import dev.plex.util.PlexLog;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.UpdateChecker;
|
||||
import dev.plex.util.*;
|
||||
import dev.plex.util.redis.MessageUtil;
|
||||
import dev.plex.world.CustomWorld;
|
||||
import java.io.File;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
@ -38,6 +33,8 @@ import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Plex extends JavaPlugin
|
||||
@ -76,7 +73,6 @@ public class Plex extends JavaPlugin
|
||||
private Permission permissions;
|
||||
private Chat chat;
|
||||
|
||||
|
||||
public static Plex get()
|
||||
{
|
||||
return plugin;
|
||||
|
@ -4,9 +4,8 @@ import com.google.common.collect.Lists;
|
||||
import dev.plex.command.PlexCommand;
|
||||
import dev.plex.command.annotation.CommandParameters;
|
||||
import dev.plex.command.annotation.CommandPermissions;
|
||||
import dev.plex.command.annotation.System;
|
||||
import dev.plex.hook.VaultHook;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import java.util.List;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -15,9 +14,10 @@ import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@CommandParameters(name = "list", description = "Show a list of all online players", aliases = "lsit")
|
||||
import java.util.List;
|
||||
|
||||
@CommandParameters(name = "list", description = "Show a list of all online players", aliases = "lsit,who,playerlist,online")
|
||||
@CommandPermissions(level = Rank.OP, permission = "plex.list")
|
||||
@System(value = "ranks")
|
||||
public class ListCMD extends PlexCommand
|
||||
{
|
||||
@Override
|
||||
@ -44,7 +44,14 @@ public class ListCMD extends PlexCommand
|
||||
for (int i = 0; i < players.size(); i++)
|
||||
{
|
||||
Player player = players.get(i);
|
||||
list = list.append(getPlexPlayer(player).getRankFromString().getPrefix()).append(Component.space()).append(Component.text(player.getName()).color(NamedTextColor.WHITE));
|
||||
if (plugin.getSystem().equals("ranks"))
|
||||
{
|
||||
list = list.append(getPlexPlayer(player).getRankFromString().getPrefix()).append(Component.space()).append(Component.text(player.getName()).color(NamedTextColor.WHITE));
|
||||
}
|
||||
else
|
||||
{
|
||||
list = list.append(VaultHook.getPrefix(getPlexPlayer(player))).append(Component.space()).append(Component.text(player.getName()).color(NamedTextColor.WHITE));
|
||||
}
|
||||
if (i != players.size() - 1)
|
||||
{
|
||||
list = list.append(Component.text(",")).append(Component.space());
|
||||
|
@ -1,8 +1,13 @@
|
||||
package dev.plex.hook;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.milkbowl.vault.chat.Chat;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
public class VaultHook
|
||||
@ -46,6 +51,22 @@ public class VaultHook
|
||||
return PERMISSIONS;
|
||||
}
|
||||
|
||||
public static Component getPrefix(PlexPlayer plexPlayer)
|
||||
{
|
||||
if (VaultHook.getChat() == null || VaultHook.getPermission() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
if (Plex.get().getRankManager().getConfigPrefixes(plexPlayer) != null)
|
||||
{
|
||||
return Plex.get().getRankManager().getConfigPrefixes(plexPlayer);
|
||||
}
|
||||
Player bukkitPlayer = Bukkit.getPlayer(plexPlayer.getUuid());
|
||||
String group = VaultHook.getPermission().getPrimaryGroup(bukkitPlayer);
|
||||
String vaultPrefix = VaultHook.getChat().getGroupPrefix(bukkitPlayer.getWorld(), group);
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(vaultPrefix);
|
||||
}
|
||||
|
||||
public static Permission getPermission()
|
||||
{
|
||||
return PERMISSIONS;
|
||||
|
@ -8,8 +8,6 @@ import dev.plex.util.minimessage.SafeMiniMessage;
|
||||
import dev.plex.util.redis.MessageUtil;
|
||||
import io.papermc.paper.chat.ChatRenderer;
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
@ -19,6 +17,9 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Toggleable("chat.enabled")
|
||||
public class ChatListener extends PlexListener
|
||||
{
|
||||
@ -37,7 +38,8 @@ public class ChatListener extends PlexListener
|
||||
public void onChat(AsyncChatEvent event)
|
||||
{
|
||||
PlexPlayer plexPlayer = plugin.getPlayerCache().getPlexPlayerMap().get(event.getPlayer().getUniqueId());
|
||||
if (plexPlayer.isStaffChat()) {
|
||||
if (plexPlayer.isStaffChat())
|
||||
{
|
||||
MessageUtil.sendStaffChat(event.getPlayer(), event.message(), PlexUtils.adminChat(event.getPlayer().getName(), SafeMiniMessage.mmSerialize(event.message())).toArray(UUID[]::new));
|
||||
plugin.getServer().getConsoleSender().sendMessage(PlexUtils.messageComponent("adminChatFormat", event.getPlayer().getName(), SafeMiniMessage.mmSerialize(event.message())).replaceText(URL_REPLACEMENT_CONFIG));
|
||||
event.setCancelled(true);
|
||||
|
@ -1,28 +1,28 @@
|
||||
package dev.plex.rank;
|
||||
|
||||
import dev.plex.Plex;
|
||||
import dev.plex.PlexBase;
|
||||
import dev.plex.hook.VaultHook;
|
||||
import dev.plex.player.PlexPlayer;
|
||||
import dev.plex.rank.enums.Rank;
|
||||
import dev.plex.rank.enums.Title;
|
||||
import dev.plex.util.PlexUtils;
|
||||
import dev.plex.util.minimessage.SafeMiniMessage;
|
||||
import lombok.SneakyThrows;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Collectors;
|
||||
import lombok.SneakyThrows;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.json.JSONTokener;
|
||||
|
||||
public class RankManager
|
||||
{
|
||||
@ -96,92 +96,94 @@ public class RankManager
|
||||
}
|
||||
}
|
||||
|
||||
public Component getPrefix(PlexPlayer player)
|
||||
public Component getConfigPrefixes(PlexPlayer plexPlayer)
|
||||
{
|
||||
if (player.getPrefix() != null && !player.getPrefix().isEmpty())
|
||||
{
|
||||
return SafeMiniMessage.mmDeserializeWithoutEvents(player.getPrefix());
|
||||
}
|
||||
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName()))
|
||||
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(plexPlayer.getName()))
|
||||
{
|
||||
return Title.OWNER.getPrefix();
|
||||
}
|
||||
if (PlexUtils.DEVELOPERS.contains(player.getUuid().toString())) // don't remove or we will front door ur mother
|
||||
if (PlexUtils.DEVELOPERS.contains(plexPlayer.getUuid().toString())) // don't remove or we will front door ur mother
|
||||
{
|
||||
return Title.DEV.getPrefix();
|
||||
}
|
||||
if (Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(player.getName()))
|
||||
if (Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(plexPlayer.getName()))
|
||||
{
|
||||
return Title.MASTER_BUILDER.getPrefix();
|
||||
}
|
||||
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(player))
|
||||
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(plexPlayer))
|
||||
{
|
||||
return player.getRankFromString().getPrefix();
|
||||
}
|
||||
if (Bukkit.getServer().getPluginManager().isPluginEnabled("Vault") && Plex.get().getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
if (VaultHook.getChat() == null || VaultHook.getPermission() == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
Player bukkitPlayer = Bukkit.getPlayer(player.getUuid());
|
||||
String group = VaultHook.getPermission().getPrimaryGroup(bukkitPlayer);
|
||||
String vaultPrefix = VaultHook.getChat().getGroupPrefix(bukkitPlayer.getWorld(), group);
|
||||
return LegacyComponentSerializer.legacyAmpersand().deserialize(vaultPrefix);
|
||||
return plexPlayer.getRankFromString().getPrefix();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getLoginMessage(PlexPlayer player)
|
||||
public Component getPrefix(PlexPlayer plexPlayer)
|
||||
{
|
||||
if (plexPlayer.getPrefix() != null && !plexPlayer.getPrefix().isEmpty())
|
||||
{
|
||||
return SafeMiniMessage.mmDeserializeWithoutEvents(plexPlayer.getPrefix());
|
||||
}
|
||||
if (getConfigPrefixes(plexPlayer) != null)
|
||||
{
|
||||
getConfigPrefixes(plexPlayer);
|
||||
}
|
||||
if (Bukkit.getServer().getPluginManager().isPluginEnabled("Vault") && Plex.get().getSystem().equalsIgnoreCase("permissions"))
|
||||
{
|
||||
return VaultHook.getPrefix(plexPlayer);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getLoginMessage(PlexPlayer plexPlayer)
|
||||
{
|
||||
String prepend;
|
||||
// We don't want to prepend the "<player> is" if the login message is custom
|
||||
if (!player.getLoginMessage().isEmpty())
|
||||
if (!plexPlayer.getLoginMessage().isEmpty())
|
||||
{
|
||||
return player.getLoginMessage()
|
||||
.replace("%player%", player.getName())
|
||||
.replace("%rank%", player.getRank());
|
||||
return plexPlayer.getLoginMessage()
|
||||
.replace("%player%", plexPlayer.getName())
|
||||
.replace("%rank%", plexPlayer.getRank());
|
||||
}
|
||||
else
|
||||
{
|
||||
prepend = MiniMessage.miniMessage().serialize(Component.text(player.getName() + " is ").color(NamedTextColor.AQUA));
|
||||
prepend = MiniMessage.miniMessage().serialize(Component.text(plexPlayer.getName() + " is ").color(NamedTextColor.AQUA));
|
||||
}
|
||||
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName()))
|
||||
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(plexPlayer.getName()))
|
||||
{
|
||||
return prepend + Title.OWNER.getLoginMessage();
|
||||
}
|
||||
if (PlexUtils.DEVELOPERS.contains(player.getUuid().toString())) // don't remove or we will front door ur mother
|
||||
if (PlexUtils.DEVELOPERS.contains(plexPlayer.getUuid().toString())) // don't remove or we will front door ur mother
|
||||
{
|
||||
return prepend + Title.DEV.getLoginMessage();
|
||||
}
|
||||
if (Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(player.getName()))
|
||||
if (Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(plexPlayer.getName()))
|
||||
{
|
||||
return prepend + Title.MASTER_BUILDER.getLoginMessage();
|
||||
}
|
||||
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(player))
|
||||
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(plexPlayer))
|
||||
{
|
||||
return prepend + player.getRankFromString().getLoginMessage();
|
||||
return prepend + plexPlayer.getRankFromString().getLoginMessage();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public NamedTextColor getColor(PlexPlayer player)
|
||||
public NamedTextColor getColor(PlexPlayer plexPlayer)
|
||||
{
|
||||
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(player.getName()))
|
||||
if (Plex.get().config.contains("titles.owners") && Plex.get().config.getStringList("titles.owners").contains(plexPlayer.getName()))
|
||||
{
|
||||
return Title.OWNER.getColor();
|
||||
}
|
||||
if (PlexUtils.DEVELOPERS.contains(player.getUuid().toString())) // don't remove or we will front door ur mother
|
||||
if (PlexUtils.DEVELOPERS.contains(plexPlayer.getUuid().toString())) // don't remove or we will front door ur mother
|
||||
{
|
||||
return Title.DEV.getColor();
|
||||
}
|
||||
if (Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(player.getName()))
|
||||
if (Plex.get().config.contains("titles.masterbuilders") && Plex.get().config.getStringList("titles.masterbuilders").contains(plexPlayer.getName()))
|
||||
{
|
||||
return Title.MASTER_BUILDER.getColor();
|
||||
}
|
||||
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(player))
|
||||
if (Plex.get().getSystem().equalsIgnoreCase("ranks") && isAdmin(plexPlayer))
|
||||
{
|
||||
return player.getRankFromString().getColor();
|
||||
return plexPlayer.getRankFromString().getColor();
|
||||
}
|
||||
return NamedTextColor.WHITE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user