Switched to modular role system

This commit is contained in:
Teriuihi 2021-09-16 15:35:04 +02:00
parent 0e2de7e0bb
commit 3c8173fff9

View File

@ -1,16 +1,12 @@
package com.alttd.proxydiscordlink.objects; package com.alttd.proxydiscordlink.objects;
import com.alttd.proxydiscordlink.DiscordLink; import com.alttd.proxydiscordlink.DiscordLink;
import com.alttd.proxydiscordlink.bot.api.DiscordModifyRole;
import com.alttd.proxydiscordlink.bot.objects.DiscordRole; import com.alttd.proxydiscordlink.bot.objects.DiscordRole;
import com.alttd.proxydiscordlink.config.BotConfig; import com.alttd.proxydiscordlink.config.BotConfig;
import com.alttd.proxydiscordlink.database.Database;
import com.alttd.proxydiscordlink.util.ALogger; import com.alttd.proxydiscordlink.util.ALogger;
import com.alttd.proxydiscordlink.util.Utilities; import com.alttd.proxydiscordlink.util.Utilities;
import net.luckperms.api.model.user.User; import net.luckperms.api.model.user.User;
import net.luckperms.api.node.NodeBuilder;
import net.luckperms.api.node.types.InheritanceNode; import net.luckperms.api.node.types.InheritanceNode;
import net.luckperms.api.node.types.PermissionNode;
import java.util.*; import java.util.*;
@ -19,15 +15,13 @@ public class DiscordLinkPlayer {
private final UUID uuid; private final UUID uuid;
private final String username; private final String username;
private final String discordUsername; private final String discordUsername;
private boolean isDonor; private final List<String> roleNames;
private boolean isNitro;
public DiscordLinkPlayer(long userId, UUID uuid, String username, String discordUsername, boolean isDonor, boolean isNitro) { public DiscordLinkPlayer(long userId, UUID uuid, String username, String discordUsername, List<String> roleNames) {
this.userId = userId; this.userId = userId;
this.uuid = uuid; this.uuid = uuid;
this.username = username; this.username = username;
this.isDonor = isDonor; this.roleNames = roleNames;
this.isNitro = isNitro;
this.discordUsername = discordUsername; this.discordUsername = discordUsername;
} }
@ -43,12 +37,8 @@ public class DiscordLinkPlayer {
return username; return username;
} }
public boolean isDonor() { public List<String> getRoles() {
return isDonor; return roleNames;
}
public boolean isNitro() {
return isNitro;
} }
public String getDiscordUsername() { public String getDiscordUsername() {
@ -56,16 +46,10 @@ public class DiscordLinkPlayer {
} }
public void updateDiscord(List<DiscordRole> roles, boolean added) { public void updateDiscord(List<DiscordRole> roles, boolean added) {
for (DiscordRole role : roles) { if (added)
if (role.getDisplayName().equalsIgnoreCase("nitro")) roles.stream().filter(DiscordRole::isUpdateToDiscord).forEach(role -> DiscordLink.getPlugin().getBot().addRole(userId, role.getId(), BotConfig.GUILD_ID)); //TODO test
isNitro = added; //FIXME this should be a list instead of a bool (separate table for roles they have) else
if (List.of("viceroy", "count", "duke", "archduke").contains(role.getDisplayName().toLowerCase())) roles.stream().filter(DiscordRole::isUpdateToDiscord).forEach(role -> DiscordLink.getPlugin().getBot().removeRole(userId, role.getId(), BotConfig.GUILD_ID)); //TODO test
isDonor = added; //FIXME this should be a list instead of a bool (separate table for roles they have)
if (!role.isUpdateToMinecraft())
continue;
//TODO implement
}
roles.forEach(role -> DiscordLink.getPlugin().getBot().addRole(userId, role.getId(), BotConfig.GUILD_ID)); //TODO test
DiscordLink.getPlugin().getDatabase().syncPlayer(this); DiscordLink.getPlugin().getDatabase().syncPlayer(this);
//TODO implement //TODO implement
@ -78,24 +62,25 @@ public class DiscordLinkPlayer {
return; return;
} }
for (DiscordRole role : roles) { roles.stream().filter(DiscordRole::isUpdateToMinecraft).forEach(role -> {
if (role.getDisplayName().equalsIgnoreCase("nitro"))
isNitro = added; //FIXME this should be a list instead of a bool (separate table for roles they have)
if (List.of("viceroy", "count", "duke", "archduke").contains(role.getDisplayName().toLowerCase()))
isDonor = added; //FIXME this should be a list instead of a bool (separate table for roles they have)
if (!role.isUpdateToMinecraft())
continue;
InheritanceNode group = InheritanceNode.builder(role.getLuckpermsName()).build(); InheritanceNode group = InheritanceNode.builder(role.getLuckpermsName()).build();
if (!user.getNodes().contains(group) && added) if (added && !user.getNodes().contains(group))
user.data().add(group); user.data().add(group);
else if (!added) else if (!added)
user.data().remove(group); user.data().remove(group);
} });
DiscordLink.getPlugin().getDatabase().syncPlayer(this); DiscordLink.getPlugin().getDatabase().syncPlayer(this);
//TODO implement //TODO implement
} }
public void linkedRole(boolean add) {
if (add)
DiscordLink.getPlugin().getBot().addRole(userId, BotConfig.LINKED_ROLE_ID, BotConfig.GUILD_ID); //TODO test
else
DiscordLink.getPlugin().getBot().removeRole(userId, BotConfig.LINKED_ROLE_ID, BotConfig.GUILD_ID); //TODO test
}
//Static stuff //Static stuff
private static final List<DiscordLinkPlayer> discordLinkPlayers = new ArrayList<>(); private static final List<DiscordLinkPlayer> discordLinkPlayers = new ArrayList<>();