Skip to content

Commit

Permalink
Add method to send a packet to everyone on a server
Browse files Browse the repository at this point in the history
  • Loading branch information
Sollace committed Apr 26, 2024
1 parent b153e3d commit 3db02fc
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.listener.ClientCommonPacketListener;
import net.minecraft.network.packet.CustomPayload;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.World;
Expand Down Expand Up @@ -42,6 +43,14 @@ public void sendToSurroundingPlayers(T packet, Entity entity) {
}
}

public void sendToAllPlayers(T packet, MinecraftServer server) {
Objects.requireNonNull(server, "Server cannot be null");
var p = toPacket(packet);
server.getPlayerManager().getPlayerList().forEach(recipient -> {
recipient.networkHandler.sendPacket(p);
});
}

/**
* Repackages a fabwork packet into a normal Minecraft protocol packet suitable for sending to a connected client.
*/
Expand Down

0 comments on commit 3db02fc

Please sign in to comment.