How to set to the creative mod a player?


#1

Hi, i search how to set a player to the creative mod, how can I ?
@Listener
public void onJoin(ClientConnectionEvent.Join e) {
Player p = e.getTargetEntity();
e.setMessage(Text.of("§a§l" + p.getName() + “§a a rejoint le jeu.”));
p.getGameModeData().set()
}

Thank you,

maxou54200.


#2

So two things:

  1. IIRC, you should be using something like p.offer(Keys.GAME_MODE, GameModes.SURVIVAL);
  2. Please for the love of everything, do NOT use the § symbol to denotate color. The chat API exists, use it. Use a Text.Builder to set things like color and style and text… https://jd.spongepowered.org/7.0.0/org/spongepowered/api/text/Text.Builder.html

#3

Thank you ! I will do this.


#4

If the text is small enough that a full builder call is overkill, you can pass sequential arguments to the Text.of method.

e.setMessage(Text.of(TextColors.GREEN, TextStyles.BOLD, p.getName(), " a rejoint le jeu."));