crwdns139603:0crwdne139603:0

Warning

crwdns139605:0crwdne139605:0

crwdns139607:0:javadoc:crwdne139607:0

crwdns139609:0crwdne139609:0

crwdns139611:0crwdne139611:0

  • crwdns139613:0:javadoc:crwdnd139613:0:javadoc:crwdnd139613:0:javadoc:crwdne139613:0

  • crwdns139615:0crwdne139615:0

crwdns139617:0:javadoc:crwdnd139617:0:javadoc:crwdne139617:0

  • crwdns139619:0:javadoc:crwdne139619:0

  • crwdns139621:0crwdne139621:0

crwdns139623:0crwdne139623:0

crwdns139625:0crwdne139625:0

Tip

crwdns139627:0crwdne139627:0

crwdns139629:0crwdne139629:0

crwdns139631:0crwdne139631:0

crwdns139633:0crwdne139633:0

import net.kyori.adventure.text.Component;

PluginContainer thisPlugin = ...;

PlaceholderParser parser = PlaceholderParser.builder()
    .plugin(this.thisPlugin)
    .id("defaultworld")
    .name("Default World Placeholder")
    .parser(placeholderContext -> {
        return Sponge.getServer()
            .getDefaultWorld()
            .map(x -> x.getWorldName())
            .orElse(Component.empty());
    })
    .build();

crwdns139635:0crwdne139635:0

crwdns139637:0crwdne139637:0

import net.kyori.adventure.text.TextComponent;

public class PlayerLocationPlaceholder implements PlaceholderParser {

    @Override
    public String getId() {
        return "spongedocs:location"
    }

    @Override
    public String getName() {
        return "Location Placeholder"
    }

    @Override
    public Component parse(PlaceholderContext placeholderContext) {
        placeholderContext.associatedObject()
            .filter(x -> x instanceof Player)
            .map(player -> ((Player) player).getLocation())
            .map(location -> TextComponent.ofChildren(
                Component.text("World: "),
                Component.text(location.getExtent().getName()),
                Component.text(" - "),
                Component.text(location.getPosition())))
            .orElse(Component.empty());
    }
}

crwdns139639:0crwdne139639:0

crwdns139641:0crwdne139641:0

public class CurrentTimePlaceholder implements PlaceholderParser {

    @Override
    public String getId() {
        return "spongedocs:currenttime";
    }

    @Override
    public String getName() {
        return "Current Time parser";
    }

    @Override
    public Component parse(PlaceholderContext placeholderContext) {
        if (placeholderContext.argumentString().filter(x -> x.equalsIgnoreCase("UTC")).isPresent()) {
            return Component.text(OffsetDateTime.now(ZoneOffset.UTC).format(FORMATTER));
        }
        return Component.text(OffsetDateTime.now().format(FORMATTER));
    }

}

crwdns139643:0crwdne139643:0

crwdns139645:0:javadoc:crwdnd139645:0:javadoc:crwdnd139645:0{register}crwdne139645:0

crwdns139647:0crwdne139647:0

PlaceholderParser parser = ...;

@Listener
public void registerTokensEvent(GameRegistryEvent.Register<PlaceholderParser> event) {
    event.register(this.parser);
}