misc: Replaced some Components with native MiniPlaceholders components
This commit is contained in:
parent
d93ffb4f2e
commit
a41d22d762
@ -3,27 +3,25 @@ package com.glyart.authmevelocity.proxy;
|
|||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
|
|
||||||
import me.dreamerzero.miniplaceholders.api.Expansion;
|
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 net.kyori.adventure.text.minimessage.tag.Tag;
|
||||||
|
|
||||||
|
import static me.dreamerzero.miniplaceholders.api.utils.Components.*;
|
||||||
|
|
||||||
final class AuthmePlaceholders {
|
final class AuthmePlaceholders {
|
||||||
private 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){
|
static Expansion getExpansion(AuthMeVelocityPlugin plugin){
|
||||||
return Expansion.builder("authme")
|
return Expansion.builder("authme")
|
||||||
.filter(Player.class)
|
.filter(Player.class)
|
||||||
.audiencePlaceholder("is_logged", (aud, queue, ctx) ->
|
.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) -> {
|
.globalPlaceholder("is_player_logged", (queue, ctx) -> {
|
||||||
String playerName = queue.popOr(() -> "you need to provide a player").value();
|
String playerName = queue.popOr(() -> "you need to provide a player").value();
|
||||||
return Tag.selfClosingInserting(
|
return Tag.selfClosingInserting(
|
||||||
plugin.getProxy().getPlayer(playerName).map(pl -> plugin.getAPI().isLogged(pl)).orElse(false)
|
plugin.getProxy().getPlayer(playerName).map(pl -> plugin.getAPI().isLogged(pl)).isPresent()
|
||||||
? TRUE
|
? TRUE_COMPONENT
|
||||||
: FALSE);
|
: FALSE_COMPONENT
|
||||||
|
);
|
||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
@ -5,30 +5,27 @@ import org.bukkit.entity.Player;
|
|||||||
|
|
||||||
import fr.xephi.authme.api.v3.AuthMeApi;
|
import fr.xephi.authme.api.v3.AuthMeApi;
|
||||||
import me.dreamerzero.miniplaceholders.api.Expansion;
|
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 net.kyori.adventure.text.minimessage.tag.Tag;
|
||||||
|
|
||||||
|
import static me.dreamerzero.miniplaceholders.api.utils.Components.*;
|
||||||
|
|
||||||
final class AuthmePlaceholders {
|
final class AuthmePlaceholders {
|
||||||
private 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(){
|
static Expansion getExpansion(){
|
||||||
return Expansion.builder("authme")
|
return Expansion.builder("authme")
|
||||||
.audiencePlaceholder("is_logged", (aud, queue, ctx) ->
|
.audiencePlaceholder("is_logged", (aud, queue, ctx) ->
|
||||||
Tag.selfClosingInserting(AuthMeApi.getInstance().isAuthenticated((Player)aud)
|
Tag.selfClosingInserting(AuthMeApi.getInstance().isAuthenticated((Player)aud)
|
||||||
? TRUE
|
? TRUE_COMPONENT
|
||||||
: FALSE)
|
: FALSE_COMPONENT)
|
||||||
)
|
)
|
||||||
.globalPlaceholder("is_player_logged", (queue, ctx) -> {
|
.globalPlaceholder("is_player_logged", (queue, ctx) -> {
|
||||||
String playerName = queue.popOr(() -> "you need to provide a player name").value();
|
String playerName = queue.popOr(() -> "you need to provide a player name").value();
|
||||||
Player player = Bukkit.getPlayer(playerName);
|
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)
|
return Tag.selfClosingInserting(AuthMeApi.getInstance().isAuthenticated(player)
|
||||||
? TRUE
|
? TRUE_COMPONENT
|
||||||
: FALSE);
|
: FALSE_COMPONENT);
|
||||||
})
|
})
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user