diff --git a/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java b/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java index c6c75df8a..11bf095ff 100644 --- a/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java +++ b/api/src/main/java/com/velocitypowered/api/proxy/ProxyServer.java @@ -8,6 +8,7 @@ import com.velocitypowered.api.proxy.messages.ChannelRegistrar; import com.velocitypowered.api.proxy.server.RegisteredServer; import com.velocitypowered.api.proxy.server.ServerInfo; import com.velocitypowered.api.scheduler.Scheduler; +import net.kyori.text.Component; import java.net.InetSocketAddress; import java.util.Collection; @@ -32,6 +33,12 @@ public interface ProxyServer { */ Optional getPlayer(UUID uuid); + /** + * Broadcasts a message to all players currently online. + * @param component the message to send + */ + void broadcast(Component component); + /** * Retrieves all players currently connected to this proxy. This call may or may not be a snapshot of all players * online. diff --git a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java index 7eaf8eaf3..3c66d1c2d 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/VelocityServer.java @@ -26,6 +26,7 @@ import com.velocitypowered.proxy.network.ConnectionManager; import com.velocitypowered.proxy.network.http.NettyHttpClient; import com.velocitypowered.proxy.plugin.VelocityEventManager; import com.velocitypowered.proxy.plugin.VelocityPluginManager; +import com.velocitypowered.proxy.protocol.packet.Chat; import com.velocitypowered.proxy.protocol.util.FaviconSerializer; import com.velocitypowered.proxy.scheduler.VelocityScheduler; import com.velocitypowered.proxy.server.ServerMap; @@ -253,6 +254,14 @@ public class VelocityServer implements ProxyServer { return Optional.ofNullable(connectionsByUuid.get(uuid)); } + @Override + public void broadcast(Component component) { + Chat chat = Chat.createClientbound(component); + for (ConnectedPlayer player : connectionsByUuid.values()) { + player.getConnection().write(chat); + } + } + @Override public Collection getAllPlayers() { return ImmutableList.copyOf(connectionsByUuid.values());