crwdns129951:0crwdne129951:0

crwdns129953:0:javadoc:crwdne129953:0

crwdns129955:0crwdne129955:0

import static org.spongepowered.api.text.TextTemplate.*;
import org.spongepowered.api.text.TextTemplate;
import org.spongepowered.api.text.format.TextColor;
import org.spongepowered.api.text.format.TextStyle;

TextTemplate template = of(
    TextColors.YELLOW, TextStyles.ITALIC, "Welcome to ",
    arg("server").color(TextColors.RED).style(TextStyles.BOLD), " ",
    arg("player").color(TextColors.AQUA).style(TextStyles.BOLD), "!"
);

crwdns129957:0:javadoc:crwdnd129957:0:javadoc:crwdne129957:0

Note

crwdns129959:0:javadoc:crwdne129959:0

Note

crwdns129961:0crwdne129961:0

crwdns129963:0:javadoc:crwdne129963:0

Tip

crwdns129965:0:doc:crwdne129965:0

import ninja.leaping.configurate.ConfigurationNode;
import com.google.common.reflect.TypeToken;

ConfigurationNode node = loader.load();
node.getNode("serverName").setValue("My Sponge Server");
node.getNode("mytemplate").setValue(TypeToken.of(TextTemplate.class), template);
loader.save(node);

crwdns129967:0crwdne129967:0

serverName="My Sponge Server"
mytemplate {
    arguments {
        player {
            optional=false
        }
        server {
            optional=false
        }
    }
    content {
        color=yellow
        extra=[
            "Welcome to ",
            {
                bold=true
                color=red
                text="{server}"
            },
            " ",
            {
                bold=true
                color=aqua
                text="{player}"
            },
            "!"
        ]
        italic=true
        text=""
    }
    options {
        closeArg="}"
        openArg="{"
    }
}

crwdns129969:0crwdne129969:0

TextTemplate template = node.getNode("mytemplate").getValue(TypeToken.of(TextTemplate.class));

crwdns129971:0crwdne129971:0

Tip

crwdns129973:0:doc:crwdne129973:0

import com.google.common.collect.ImmutableMap;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.network.ClientConnectionEvent;
import org.spongepowered.api.text.Text;
import java.time.Instant;
import java.util.Optional;

@Listener
public void onJoin(ClientConnectionEvent.Join event) {
    Player player = event.getTargetEntity();
    Instant firstPlayed = player.firstPlayed().get();
    Instant lastPlayed = player.lastPlayed().get();
    if (firstPlayed.equals(lastPlayed)) {
        // Player has not been to this server before
        // First we will get the server name from our configuration file
        String serverName = node.getNode("serverName").getString();
        // Next we will send the template to the server,
        // using the "server" and "player" template parameters
        Text message = this.template.apply(ImmutableMap.of(
                "server", Text.of(serverName), "player", Text.of(player.getName())
        )).build();
        event.setMessage(message);
    }
}