Get prefixes, display name, and gc toggle when initializing a new user object

This commit is contained in:
Teriuihi 2021-05-15 03:02:52 +02:00
parent 2475197526
commit b8ff682748
4 changed files with 105 additions and 7 deletions

View File

@ -41,16 +41,33 @@
</build>
<dependencies>
<dependency><!--TODO update to version 4.0.0-->
<groupId>org.spongepowered</groupId>
<artifactId>configurate-yaml</artifactId>
<version>3.7.1</version>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>1.1.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.luckperms</groupId>
<artifactId>api</artifactId>
<version>5.3</version>
<scope>provided</scope>
</dependency>
<dependency><!--TODO update to version 4.0.0-->
<groupId>org.spongepowered</groupId>
<artifactId>configurate-yaml</artifactId>
<version>3.7.1</version>
<dependency>
<groupId>com.alttd.chat</groupId>
<artifactId>velocity-chat</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>

View File

@ -150,9 +150,12 @@ public final class Config {
/** ONLY EDIT ANYTHING BELOW THIS LINE **/
public static List<String> PREFIXGROUPS = new ArrayList<>();
public static List<String> STAFFGROUPS = new ArrayList<>();
private static void settings() {
PREFIXGROUPS = getList("settings.prefix-groups",
Lists.newArrayList("discord", "socialmedia", "eventteam", "eventleader", "youtube", "twitch", "developer"));
STAFFGROUPS = getList("settings.staff-groups",
Lists.newArrayList("trainee", "moderator", "headmod", "admin", "manager", "owner"));
}
public static List<String> MESSAGECOMMANDALIASES = new ArrayList<>();

View File

@ -1,6 +1,7 @@
package com.alttd.chat.objects;
import com.alttd.chat.database.Queries;
import com.alttd.chat.util.Utility;
import java.util.UUID;
@ -21,13 +22,17 @@ public class ChatUser {
this.toggledChat = toggled_chat;
this.forceTp = force_tp;
//TODO Get the user somehow and use that to check their prefixes
displayName = Queries.getNickname(uuid);
if (displayName == null) {
//TODO displayName = player.getName() or something
displayName = Utility.getDisplayName(uuid);
}
//TODO Get the user somehow and use that to check the toggleGc permission
prefix = Utility.getPrefix(uuid, true);
staffPrefix = Utility.getStaffPrefix(uuid);
prefixAll = prefix + staffPrefix; //TODO test what this does cus I barely understand lp api
toggleGc = Utility.checkPermission(uuid, "chat.gc"); //TODO put the actual permission here, I don't know what it is...
}
public UUID getUuid() {
@ -90,6 +95,7 @@ public class ChatUser {
public void toggleGc() {
toggleGc = !toggleGc;
Utility.setPermission(uuid, "chat.gc", toggleGc); //TODO put the actual permission here, I don't know what it is...
}
public boolean isGcOn() {

View File

@ -0,0 +1,72 @@
package com.alttd.chat.util;
import com.alttd.chat.ChatPlugin;
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();
LuckPerms luckPerms = ChatPlugin.getPlugin().API().getLuckPerms();
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();
}
public static String getStaffPrefix(UUID uuid) {
StringBuilder prefix = new StringBuilder();
LuckPerms luckPerms = ChatPlugin.getPlugin().API().getLuckPerms();
User user = luckPerms.getUserManager().getUser(uuid);
if(user == null) return "";
if(!Config.STAFFGROUPS.contains(user.getPrimaryGroup())) return "";
prefix.append("<white>[").append(user.getCachedData().getMetaData().getPrefix()).append("]</white>");
return prefix.toString();
}
public static boolean checkPermission(UUID uuid, String permission) {
ProxyServer proxy = ChatPlugin.getPlugin().getProxy();
if (proxy.getPlayer(uuid).isEmpty()) return false;
Player player = proxy.getPlayer(uuid).get();
return player.hasPermission(permission);
}
public static String getDisplayName(UUID uuid) {
ProxyServer proxy = ChatPlugin.getPlugin().getProxy();
if (proxy.getPlayer(uuid).isEmpty()) return "";
Player player = proxy.getPlayer(uuid).get();
return player.getUsername();
}
public static void setPermission(UUID uuid, String permission, boolean toggleGc) {
LuckPerms luckPerms = ChatPlugin.getPlugin().API().getLuckPerms();
luckPerms.getUserManager().modifyUser(uuid, user -> {
user.data().add(Node.builder(permission).value(toggleGc).build());
});
}
}