crwdns149205:0crwdne149205:0
crwdns149207:0:javadoc:crwdne149207:0
crwdns149209:0crwdne149209: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), "!"
);
crwdns149211:0:javadoc:crwdnd149211:0:javadoc:crwdne149211:0
Note
crwdns149213:0:javadoc:crwdne149213:0
Note
crwdns149215:0crwdne149215:0
crwdns149217:0:javadoc:crwdne149217:0
Tip
crwdns149219:0:doc:crwdne149219: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);
crwdns149221:0crwdne149221: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="{"
}
}
crwdns149223:0crwdne149223:0
TextTemplate template = node.getNode("mytemplate").getValue(TypeToken.of(TextTemplate.class));
crwdns149225:0crwdne149225:0
Tip
crwdns149227:0:doc:crwdne149227: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);
}
}