mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-06-09 06:51:46 +00:00
179 lines
4.8 KiB
Java
179 lines
4.8 KiB
Java
package me.totalfreedom.totalfreedommod.rank;
|
|
|
|
import me.totalfreedom.totalfreedommod.TotalFreedomMod;
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
|
import net.kyori.adventure.text.Component;
|
|
import net.kyori.adventure.text.format.TextColor;
|
|
import net.luckperms.api.model.data.DataType;
|
|
import net.luckperms.api.model.group.Group;
|
|
import net.luckperms.api.node.types.InheritanceNode;
|
|
import net.luckperms.api.node.types.PrefixNode;
|
|
import net.luckperms.api.node.types.WeightNode;
|
|
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
|
|
{
|
|
private final Group group;
|
|
|
|
private final Component name;
|
|
|
|
private final Component abbr;
|
|
private final Component plural;
|
|
private final Component article;
|
|
private final int weight;
|
|
|
|
private final Component tag;
|
|
|
|
private final Component coloredTag;
|
|
|
|
private final TextColor color;
|
|
|
|
private final org.bukkit.ChatColor teamColor;
|
|
|
|
private final boolean hasTeam;
|
|
|
|
private final boolean hasDefaultLoginMessage;
|
|
|
|
public DisplayableGroup(String group,
|
|
Component plural,
|
|
Component tag,
|
|
int weight,
|
|
TextColor color,
|
|
org.bukkit.ChatColor teamColor,
|
|
boolean hasTeam,
|
|
boolean hasDefaultLoginMessage)
|
|
{
|
|
Group matched = TotalFreedomMod.getPlugin().lpb.getAPI().getGroupManager().getGroup(group);
|
|
|
|
if (matched == null)
|
|
{
|
|
CompletableFuture<Group> cfg = TotalFreedomMod.getPlugin()
|
|
.lpb
|
|
.getAPI()
|
|
.getGroupManager()
|
|
.createAndLoadGroup(group);
|
|
|
|
cfg.thenAcceptAsync(g ->
|
|
{
|
|
WeightNode weightNode = WeightNode.builder(weight).build();
|
|
PrefixNode prefixNode = PrefixNode.builder()
|
|
.prefix(FUtil.miniMessage(GroupProvider.OPEN.append(tag.color(color)).append(GroupProvider.CLOSE)))
|
|
.priority(1)
|
|
.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;
|
|
this.name = (matched.getDisplayName() != null) ? FUtil.miniMessage(matched.getDisplayName()) : FUtil.miniMessage(matched.getName());
|
|
this.plural = plural;
|
|
this.article = StringUtils.startsWithAny(this.name.toString().toLowerCase(Locale.ROOT), new String[]{"a", "e", "i", "o", "u"}) ? Component.text("an") : Component.text("a");
|
|
this.abbr = tag;
|
|
this.weight = weight;
|
|
this.tag = GroupProvider.OPEN.append(tag).append(GroupProvider.CLOSE);
|
|
this.color = color;
|
|
this.teamColor = teamColor;
|
|
this.hasTeam = hasTeam;
|
|
this.coloredTag = tag.color(color);
|
|
this.hasDefaultLoginMessage = hasDefaultLoginMessage;
|
|
}
|
|
|
|
public boolean isAtLeast(@NotNull DisplayableGroup rank)
|
|
{
|
|
return rank.getLuckPermsGroup().getWeight().orElse(0)
|
|
<= getLuckPermsGroup().getWeight().orElse(0);
|
|
}
|
|
|
|
public int getWeight()
|
|
{
|
|
return weight;
|
|
}
|
|
|
|
public Group getLuckPermsGroup()
|
|
{
|
|
return this.group;
|
|
}
|
|
|
|
@Override
|
|
public Component getArticle()
|
|
{
|
|
return this.article;
|
|
}
|
|
|
|
@Override
|
|
public Component getName()
|
|
{
|
|
return name;
|
|
}
|
|
|
|
@Override
|
|
public Component getTag()
|
|
{
|
|
return tag;
|
|
}
|
|
|
|
@Override
|
|
public Component getAbbr()
|
|
{
|
|
return abbr;
|
|
}
|
|
|
|
@Override
|
|
public Component getPlural()
|
|
{
|
|
return plural;
|
|
}
|
|
|
|
@Override
|
|
public TextColor getColor()
|
|
{
|
|
return color;
|
|
}
|
|
|
|
@Override
|
|
public org.bukkit.ChatColor getTeamColor()
|
|
{
|
|
return teamColor;
|
|
}
|
|
|
|
@Override
|
|
public Component getColoredName()
|
|
{
|
|
return name.color(color);
|
|
}
|
|
|
|
@Override
|
|
public Component getColoredTag()
|
|
{
|
|
return coloredTag;
|
|
}
|
|
|
|
@Override
|
|
public Component getColoredLoginMessage()
|
|
{
|
|
return article.append(Component.text(" ")).append(name.color(color));
|
|
}
|
|
|
|
@Override
|
|
public boolean hasTeam()
|
|
{
|
|
return hasTeam;
|
|
}
|
|
|
|
@Override
|
|
public boolean hasDefaultLoginMessage()
|
|
{
|
|
return hasDefaultLoginMessage;
|
|
}
|
|
}
|