misc: Replaced some Components with native MiniPlaceholders components

This commit is contained in:
4drian3d 2022-06-16 22:16:31 +00:00
parent d93ffb4f2e
commit a41d22d762
2 changed files with 14 additions and 19 deletions

View File

@ -3,27 +3,25 @@ package com.glyart.authmevelocity.proxy;
import com.velocitypowered.api.proxy.Player;
import me.dreamerzero.miniplaceholders.api.Expansion;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.tag.Tag;
import static me.dreamerzero.miniplaceholders.api.utils.Components.*;
final class AuthmePlaceholders {
private AuthmePlaceholders(){}
private static final Component TRUE = Component.text("true", NamedTextColor.GREEN);
private static final Component FALSE = Component.text("false", NamedTextColor.RED);
static Expansion getExpansion(AuthMeVelocityPlugin plugin){
return Expansion.builder("authme")
.filter(Player.class)
.audiencePlaceholder("is_logged", (aud, queue, ctx) ->
Tag.selfClosingInserting(plugin.getAPI().isLogged((Player)aud) ? TRUE : FALSE))
Tag.selfClosingInserting(plugin.getAPI().isLogged((Player)aud) ? TRUE_COMPONENT : FALSE_COMPONENT))
.globalPlaceholder("is_player_logged", (queue, ctx) -> {
String playerName = queue.popOr(() -> "you need to provide a player").value();
return Tag.selfClosingInserting(
plugin.getProxy().getPlayer(playerName).map(pl -> plugin.getAPI().isLogged(pl)).orElse(false)
? TRUE
: FALSE);
plugin.getProxy().getPlayer(playerName).map(pl -> plugin.getAPI().isLogged(pl)).isPresent()
? TRUE_COMPONENT
: FALSE_COMPONENT
);
})
.build();
}

View File

@ -5,30 +5,27 @@ import org.bukkit.entity.Player;
import fr.xephi.authme.api.v3.AuthMeApi;
import me.dreamerzero.miniplaceholders.api.Expansion;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.tag.Tag;
import static me.dreamerzero.miniplaceholders.api.utils.Components.*;
final class AuthmePlaceholders {
private AuthmePlaceholders(){}
private static final Component TRUE = Component.text("true", NamedTextColor.GREEN);
private static final Component FALSE = Component.text("false", NamedTextColor.RED);
static Expansion getExpansion(){
return Expansion.builder("authme")
.audiencePlaceholder("is_logged", (aud, queue, ctx) ->
Tag.selfClosingInserting(AuthMeApi.getInstance().isAuthenticated((Player)aud)
? TRUE
: FALSE)
? TRUE_COMPONENT
: FALSE_COMPONENT)
)
.globalPlaceholder("is_player_logged", (queue, ctx) -> {
String playerName = queue.popOr(() -> "you need to provide a player name").value();
Player player = Bukkit.getPlayer(playerName);
if(player == null) return Tag.selfClosingInserting(FALSE);
if(player == null) return Tag.selfClosingInserting(FALSE_COMPONENT);
return Tag.selfClosingInserting(AuthMeApi.getInstance().isAuthenticated(player)
? TRUE
: FALSE);
? TRUE_COMPONENT
: FALSE_COMPONENT);
})
.build();
}