mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +00:00
Add helper method to OnDatapackSyncEvent (#9901)
Co-authored-by: blockingHD <9372035+blockinghd@users.noreply.github.com>
This commit is contained in:
1 parent
d31ea640f9
commit
a6adc58655
1 file changed
+15
-8
@@ -10,19 +10,20 @@ import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraftforge.eventbus.api.Event;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Fires when a player joins the server or when the reload command is ran,
|
||||
* before tags and crafting recipes are sent to the client. Send datapack data
|
||||
* to clients when this event fires.
|
||||
*/
|
||||
public class OnDatapackSyncEvent extends Event
|
||||
{
|
||||
public class OnDatapackSyncEvent extends Event {
|
||||
private final PlayerList playerList;
|
||||
|
||||
@Nullable
|
||||
private final ServerPlayer player;
|
||||
|
||||
public OnDatapackSyncEvent(PlayerList playerList, @Nullable ServerPlayer player)
|
||||
{
|
||||
public OnDatapackSyncEvent(PlayerList playerList, @Nullable ServerPlayer player) {
|
||||
this.playerList = playerList;
|
||||
this.player = player;
|
||||
}
|
||||
@@ -30,8 +31,7 @@ public class OnDatapackSyncEvent extends Event
|
||||
/**
|
||||
* @return The server's player list to get a view of all players.
|
||||
*/
|
||||
public PlayerList getPlayerList()
|
||||
{
|
||||
public PlayerList getPlayerList() {
|
||||
return this.playerList;
|
||||
}
|
||||
|
||||
@@ -40,8 +40,15 @@ public class OnDatapackSyncEvent extends Event
|
||||
* such as when the reload command runs.
|
||||
*/
|
||||
@Nullable
|
||||
public ServerPlayer getPlayer()
|
||||
{
|
||||
public ServerPlayer getPlayer() {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A list of players that should receive data during this event, which is the specified player (if not null)
|
||||
* or all players otherwise.
|
||||
*/
|
||||
public List<ServerPlayer> getPlayers() {
|
||||
return this.player == null ? this.playerList.getPlayers() : List.of(this.player);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user