Skip to content

Instantly share code, notes, and snippets.

@dualspiral
Last active February 2, 2017 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dualspiral/93404e8d1bbc95c89a7a06a50f53d820 to your computer and use it in GitHub Desktop.
Save dualspiral/93404e8d1bbc95c89a7a06a50f53d820 to your computer and use it in GitHub Desktop.
Display Name
package uk.co.drnaylor.sponge.test;
import com.google.inject.Inject;
import org.slf4j.Logger;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.data.key.Keys;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.game.state.GameInitializationEvent;
import org.spongepowered.api.plugin.Plugin;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.format.TextColors;
@Plugin(id = "ndebug", name = "test", version = "0.1")
public class TestCmds {
@Inject private Logger log;
private Text testText = Text.of(TextColors.BLUE, "test");
@Listener
public void onStart(GameInitializationEvent event) {
Sponge.getCommandManager().register(
this, CommandSpec.builder()
.executor((c, a) -> {
if (c instanceof Player) {
Player p = (Player)c;
p.sendMessage(Text.of("Offering: " + p.offer(Keys.DISPLAY_NAME, testText).isSuccessful())); // Offering: true
// Should return "test" in blue.
p.sendMessage(Text.of("Text is now: " + p.get(Keys.DISPLAY_NAME).orElse(Text.EMPTY))); // Text is now: dualspiral
}
return CommandResult.success();
})
.build(), "testname");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment