[Solved] Some Questions + Short Introduction

Hey SpongeCommunity,
I am DarkIce and comming from Bukkit/Spigot.
I came here because the DMCA of Bukkit and the many Buggs and Laggs in the 1.8 Spigot release.

I am curently enjoying the Sponge Dev Builds but it is not very clear to me how i can broadcast a message for all Users playing.
And my next question is if these is any other way to use chatcolors except for Color(ChatColor.RED)

Keep the eyes open maybe a Plugin get released by me soon. :smile:

@Inject Game game;

public void broadcast(String msg) {
    for (Player player : this.game.getServer().getOnlinePlayers()) {
        player.sendMessage(Texts.of(msg));
    }
}
2 Likes

Ferus and his elite response times.

/offtopic

I thought there was a method for this?

Wow how quich was that ! :smile:

Thanks for the reply

Possibly. I tend to for-loop through mine, though, in case there’s a specific guideline I want to abide to.

@Inject private Game game;
private final List<UUID> admins = new HashMap<UUID>();

public void broadcastAdministrators(String msg) {
    for (Player player : this.game.getServer().getOnlinePlayers()) {
        if (this.admins.contains(player.getUniqueId()) {
            player.sendMessage(Texts.of(msg));
        }
    }
}
1 Like
public void sendPlayerMessage(Player player, String msg) {
    Text message = Texts.builder(msg)
                             .color(TextColors.RED)
                             .style(TextStyles.ITALIC)
                             .build();

    player.sendMessage(message);
}

And what is about the chatcolors can i still use somthing like “§cMessage”

Text message = Texts.fromLegacy(msg, "§");

And when i want to have a prefix the first [ in red then the actual prefix in green the the secound ] again in red

You would just append.

Text message = Texts.builder("[").color(TextColors.RED)
                         .append(Texts.builder(prefix).color(TextColors.GREEN).build()
                         .append(Texts.builder("]").color(TextColors.RED).build()
                         .build();

After this, go read the Docs. Don’t want to be spoon-fed everything, ya? :stuck_out_tongue:

2 Likes

Thanks for everything (Solved)

1 Like

You came to try Sponge’s Alpha Dev Builds because Spigot is too buggy for you? Then good luck ^^ Welcome at Sponge, though :blush:

3 Likes

Alternately, some one liners:

game.getServer().getOnlinePlayers().forEach(player -> player.sendMessage(Texts.of("Meow!")));
game.getServer().getOnlinePlayers().stream().filter(player -> player.hasPermission("kitty")).forEach(player -> player.sendMessage(Texts.of("Meow!")));
3 Likes

If you’re using Java8. :stuck_out_tongue:

1 Like

Java is slowly learning why .NET implemented Lamba. Hence the Java 8.

Func<int,int> doublez = x => x*x;
Console.WriteLine(doublez(7));

I prefer to use a JDK/JRE that isn’t EOL. :blush:

2 Likes

you could also just do this:

game.getServer().broadcastMessage(Texts.of("Some message"))
1 Like

Yup, we all know that method. :stuck_out_tongue:

The examples that @mbaxter and I were given in the case that a pre-requisite was required. Such as @mbaxter checking for a permission, or in my post where I checked if a player was an admin.