2021-09-01 22:26:29 +08:00
|
|
|
/*
|
2022-04-14 03:42:00 +00:00
|
|
|
* Copyright (c) Forge Development LLC and contributors
|
2022-02-28 13:41:23 -08:00
|
|
|
* SPDX-License-Identifier: LGPL-2.1-only
|
2021-09-01 22:26:29 +08:00
|
|
|
*/
|
|
|
|
|
|
2021-08-06 13:18:12 -04:00
|
|
|
package net.minecraftforge.event;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
|
|
|
import net.minecraft.server.players.PlayerList;
|
|
|
|
|
import net.minecraftforge.eventbus.api.Event;
|
2022-06-07 15:31:26 -05:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
2021-08-06 13:18:12 -04:00
|
|
|
|
2024-04-15 14:47:45 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
|
2021-08-06 13:18:12 -04:00
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2025-04-19 13:18:48 +01:00
|
|
|
public final class OnDatapackSyncEvent extends Event {
|
2021-08-06 13:18:12 -04:00
|
|
|
private final PlayerList playerList;
|
2024-04-15 14:47:45 +01:00
|
|
|
|
2021-08-06 13:18:12 -04:00
|
|
|
@Nullable
|
|
|
|
|
private final ServerPlayer player;
|
|
|
|
|
|
2024-04-15 14:47:45 +01:00
|
|
|
public OnDatapackSyncEvent(PlayerList playerList, @Nullable ServerPlayer player) {
|
2021-08-06 13:18:12 -04:00
|
|
|
this.playerList = playerList;
|
|
|
|
|
this.player = player;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return The server's player list to get a view of all players.
|
|
|
|
|
*/
|
2024-04-15 14:47:45 +01:00
|
|
|
public PlayerList getPlayerList() {
|
2021-08-06 13:18:12 -04:00
|
|
|
return this.playerList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return The player to sync datapacks to. Null when syncing for all players,
|
|
|
|
|
* such as when the reload command runs.
|
|
|
|
|
*/
|
|
|
|
|
@Nullable
|
2024-04-15 14:47:45 +01:00
|
|
|
public ServerPlayer getPlayer() {
|
2021-08-06 13:18:12 -04:00
|
|
|
return this.player;
|
|
|
|
|
}
|
2024-04-15 14:47:45 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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);
|
|
|
|
|
}
|
2021-08-06 13:18:12 -04:00
|
|
|
}
|