feat: Implement authme_in_auth_server and authme_player_in_auth_server placeholders

This commit is contained in:
4drian3d 2022-07-02 18:46:24 +00:00
parent a41d22d762
commit 6365866e59
2 changed files with 16 additions and 4 deletions

View File

@ -44,7 +44,7 @@ public class AuthMeVelocityPlugin {
@Subscribe @Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) { public void onProxyInitialization(ProxyInitializeEvent event) {
Toml toml = this.loadConfig(pluginDirectory); Toml toml = this.loadConfig(pluginDirectory);
if(toml == null){ if (toml == null) {
logger.warn("Failed to load config.toml. Shutting down."); logger.warn("Failed to load config.toml. Shutting down.");
return; return;
} }

View File

@ -13,14 +13,26 @@ final class AuthmePlaceholders {
static Expansion getExpansion(AuthMeVelocityPlugin plugin){ static Expansion getExpansion(AuthMeVelocityPlugin plugin){
return Expansion.builder("authme") return Expansion.builder("authme")
.filter(Player.class) .filter(Player.class)
// Logged Placeholders
.audiencePlaceholder("is_logged", (aud, queue, ctx) -> .audiencePlaceholder("is_logged", (aud, queue, ctx) ->
Tag.selfClosingInserting(plugin.getAPI().isLogged((Player)aud) ? TRUE_COMPONENT : FALSE_COMPONENT)) 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)).isPresent() plugin.getProxy().getPlayer(playerName)
? TRUE_COMPONENT .map(plugin.getAPI()::isLogged)
: FALSE_COMPONENT .orElse(false) ? TRUE_COMPONENT : FALSE_COMPONENT
);
})
// In Auth Server placeholders
.audiencePlaceholder("in_auth_server", (aud, queue, ctx) ->
Tag.selfClosingInserting(plugin.getAPI().isInAuthServer((Player)aud) ? TRUE_COMPONENT : FALSE_COMPONENT))
.globalPlaceholder("player_in_auth_server", (queue, ctx) -> {
String playerName = queue.popOr(() -> "you need to provide a player").value();
return Tag.selfClosingInserting(
plugin.getProxy().getPlayer(playerName)
.map(plugin.getAPI()::isInAuthServer)
.orElse(false) ? TRUE_COMPONENT : FALSE_COMPONENT
); );
}) })
.build(); .build();