crwdns119181:0crwdne119181:0

crwdns119183:0:javadoc:crwdne119183:0

crwdns119185:0crwdne119185: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), "!"
);

crwdns119187:0:javadoc:crwdnd119187:0:javadoc:crwdne119187:0

Note

crwdns119189:0:javadoc:crwdne119189:0

Note

crwdns119191:0crwdne119191:0

crwdns119193:0:javadoc:crwdne119193:0

Tip

crwdns119195:0:doc:crwdne119195: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);

crwdns119197:0crwdne119197: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="{"
    }
}

crwdns119199:0crwdne119199:0

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

crwdns119201:0crwdne119201:0

Tip

crwdns119203:0:doc:crwdne119203: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);
    }
}