LuckPerms Integration (1.5/2)

This commit is contained in:
Paul Reilly
2023-03-29 22:00:35 -05:00
parent 65540b7f3a
commit cc244fc4f7
24 changed files with 230 additions and 209 deletions

View File

@ -1,12 +1,17 @@
package me.totalfreedom.totalfreedommod.rank;
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
import net.kyori.adventure.text.Component;
import net.luckperms.api.model.data.DataType;
import net.luckperms.api.model.group.Group;
import net.luckperms.api.node.types.PrefixNode;
import net.luckperms.api.node.types.WeightNode;
import net.md_5.bungee.api.ChatColor;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Locale;
import java.util.concurrent.CompletableFuture;
public class DisplayableGroup implements Displayable
{
@ -17,10 +22,11 @@ public class DisplayableGroup implements Displayable
private final String abbr;
private final String plural;
private final String article;
private final int weight;
private final String tag;
private final String coloredTag;
private final Component coloredTag;
private final ChatColor color;
@ -33,6 +39,7 @@ public class DisplayableGroup implements Displayable
public DisplayableGroup(String group,
String plural,
String tag,
int weight,
ChatColor color,
org.bukkit.ChatColor teamColor,
boolean hasTeam,
@ -41,7 +48,22 @@ public class DisplayableGroup implements Displayable
Group matched = TotalFreedomMod.getPlugin().lpb.getAPI().getGroupManager().getGroup(group);
if (matched == null) {
throw new IllegalArgumentException("Group " + group + " does not exist!");
CompletableFuture<Group> cfg = TotalFreedomMod.getPlugin()
.lpb
.getAPI()
.getGroupManager()
.createAndLoadGroup(group);
cfg.thenAcceptAsync(g -> {
WeightNode weightNode = WeightNode.builder(weight).build();
PrefixNode prefixNode = PrefixNode.builder().prefix(ChatColor.DARK_GRAY + "[" + color + tag + ChatColor.DARK_GRAY + "]" + getColor()).build();
g.getData(DataType.NORMAL).add(prefixNode);
g.getData(DataType.NORMAL).add(weightNode);
}).join(); // Block until the group is created and loaded.
matched = TotalFreedomMod.getPlugin().lpb.getAPI().getGroupManager().getGroup(group);
if (matched == null) throw new IllegalArgumentException("Group " + group + " does not exist and could not be created.");
}
this.group = matched;
@ -49,11 +71,12 @@ public class DisplayableGroup implements Displayable
this.plural = plural;
this.article = StringUtils.startsWithAny(this.name.toLowerCase(Locale.ROOT), new String[]{"a", "e", "i", "o", "u"}) ? "an" : "a";
this.abbr = tag;
this.weight = weight;
this.tag = "[" + tag + "]";
this.color = color;
this.teamColor = teamColor;
this.hasTeam = hasTeam;
this.coloredTag = ChatColor.DARK_GRAY + "[" + getColor() + getTag() + ChatColor.DARK_GRAY + "]" + getColor();
this.coloredTag = generateColoredTag(color + tag);
this.hasDefaultLoginMessage = hasDefaultLoginMessage;
}
@ -116,7 +139,7 @@ public class DisplayableGroup implements Displayable
}
@Override
public String getColoredTag()
public Component getColoredTag()
{
return coloredTag;
}