crwdns119989:0crwdne119989:0

crwdns119991:0:javadoc:crwdne119991:0

crwdns119993:0crwdne119993:0

crwdns119995:0crwdne119995:0

  • crwdns119997:0:javadoc:crwdnd119997:0:javadoc:crwdne119997:0

  • crwdns119999:0crwdne119999:0

Note

crwdns120001:0:doc:crwdnd120001:0[pluginid]crwdnd120001:0[placeholderid]crwdne120001:0

crwdns120003:0:javadoc:crwdnd120003:0:javadoc:crwdnd120003:0:javadoc:crwdne120003:0

  • crwdns120005:0:javadoc:crwdne120005:0

  • crwdns120007:0crwdne120007:0

crwdns120009:0crwdne120009:0

crwdns120011:0crwdne120011:0

Tip

crwdns120013:0crwdne120013:0

crwdns120015:0crwdne120015:0

crwdns120017:0crwdne120017:0

crwdns120019:0crwdne120019:0

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(Text.EMPTY);
    })
    .build();

crwdns120021:0crwdne120021:0

crwdns120023:0:javadoc:crwdne120023:0

public class PlayerLocationPlaceholder implements PlaceholderParser {

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

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

    @Override
    public Text parse(PlaceholderText placeholderText) {
        placeholderText.getAssociatedReceiver()
            .filter(x -> x instanceof Player)
            .map(player -> ((Player) player).getLocation())
            .map(location -> Text.of("World: ", location.getExtent().getName(), " - ", location.getPosition()))
            .orElse(Text.EMPTY);
    }
}

crwdns120025:0crwdne120025:0

crwdns120027:0crwdne120027:0

public class CurrentTimePlaceholder implements PlaceholderParser {

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

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

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

}

crwdns120029:0crwdne120029:0

crwdns120031:0:javadoc:crwdnd120031:0:javadoc:crwdnd120031:0{register}crwdne120031:0

crwdns120033:0crwdne120033:0

PlaceholderParser parser = ...;

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