2021-05-15 01:02:52 +00:00
|
|
|
package com.alttd.chat.util;
|
|
|
|
|
|
2021-05-15 10:34:19 +00:00
|
|
|
import com.alttd.chat.ChatAPI;
|
|
|
|
|
import com.alttd.chat.ChatImplementation;
|
2021-05-15 01:02:52 +00:00
|
|
|
import com.alttd.chat.config.Config;
|
|
|
|
|
import com.velocitypowered.api.proxy.Player;
|
|
|
|
|
import com.velocitypowered.api.proxy.ProxyServer;
|
|
|
|
|
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
|
|
|
|
import net.luckperms.api.LuckPerms;
|
|
|
|
|
import net.luckperms.api.model.group.Group;
|
|
|
|
|
import net.luckperms.api.model.user.User;
|
|
|
|
|
import net.luckperms.api.node.Node;
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.Comparator;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
public class Utility {
|
|
|
|
|
|
|
|
|
|
public static String getPrefix(UUID uuid, boolean highest) {
|
|
|
|
|
StringBuilder prefix = new StringBuilder();
|
2021-05-15 10:34:19 +00:00
|
|
|
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
2021-05-15 01:02:52 +00:00
|
|
|
User user = luckPerms.getUserManager().getUser(uuid);
|
|
|
|
|
if(user == null) return "";
|
|
|
|
|
if(!highest) {
|
|
|
|
|
Collection<Group> inheritedGroups = user.getInheritedGroups(user.getQueryOptions());
|
|
|
|
|
inheritedGroups.stream()
|
|
|
|
|
.sorted(Comparator.comparingInt(o -> o.getWeight().orElse(0)))
|
|
|
|
|
.forEach(group -> {
|
|
|
|
|
if (Config.PREFIXGROUPS.contains(group.getName())) {
|
|
|
|
|
prefix.append("<white>[").append(group.getCachedData().getMetaData().getPrefix()).append("]</white>");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
LegacyComponentSerializer.builder().character('&').hexColors();
|
|
|
|
|
prefix.append("<white>[").append(user.getCachedData().getMetaData().getPrefix()).append("]</white>");
|
|
|
|
|
|
|
|
|
|
return prefix.toString();
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-15 10:34:19 +00:00
|
|
|
// @teri you don't reference the plugin instance from the API instance, this creates a circular reference and breaks on compile and will never run
|
2021-05-15 01:02:52 +00:00
|
|
|
public static String getStaffPrefix(UUID uuid) {
|
|
|
|
|
StringBuilder prefix = new StringBuilder();
|
2021-05-15 10:34:19 +00:00
|
|
|
LuckPerms luckPerms = ChatAPI.get().getLuckPerms();
|
2021-05-15 01:02:52 +00:00
|
|
|
User user = luckPerms.getUserManager().getUser(uuid);
|
2021-05-15 19:39:51 +00:00
|
|
|
if(user == null) return prefix.toString();
|
|
|
|
|
if(user.getCachedData().getPermissionData().checkPermission("group." + Config.MINIMIUMSTAFFRANK).asBoolean()) {
|
|
|
|
|
prefix.append("<white>[").append(user.getCachedData().getMetaData().getPrefix()).append("]</white>");
|
|
|
|
|
}
|
2021-05-15 01:02:52 +00:00
|
|
|
return prefix.toString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getDisplayName(UUID uuid) {
|
2021-05-15 10:34:19 +00:00
|
|
|
// todo add a <T> PlayerWrapper<T> @Destro
|
|
|
|
|
/*ProxyServer proxy = ChatPlugin.getPlugin().getProxy();
|
2021-05-15 01:02:52 +00:00
|
|
|
if (proxy.getPlayer(uuid).isEmpty()) return "";
|
|
|
|
|
Player player = proxy.getPlayer(uuid).get();
|
2021-05-15 10:34:19 +00:00
|
|
|
return player.getUsername();*/
|
|
|
|
|
return "";
|
2021-05-15 01:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|