mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-16 10:34:49 +00:00
Make more events records
This commit is contained in:
1 parent
6915753b5a
commit
219abfed22
22 files changed
+188
-522
No files matched your search
@@ -8,8 +8,9 @@ package net.minecraftforge.event;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraftforge.eventbus.api.bus.EventBus;
|
||||
import net.minecraftforge.eventbus.api.event.MutableEvent;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import net.minecraftforge.eventbus.api.event.RecordEvent;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -17,41 +18,19 @@ 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.
|
||||
*
|
||||
* @param getPlayerList The server's player list to get a view of all players.
|
||||
* @param getPlayer The player to sync datapacks to. Null when syncing for all players, such as when the reload command runs.
|
||||
*/
|
||||
public final class OnDatapackSyncEvent extends MutableEvent {
|
||||
@NullMarked
|
||||
public record OnDatapackSyncEvent(PlayerList getPlayerList, @Nullable ServerPlayer getPlayer) implements RecordEvent {
|
||||
public static final EventBus<OnDatapackSyncEvent> BUS = EventBus.create(OnDatapackSyncEvent.class);
|
||||
|
||||
private final PlayerList playerList;
|
||||
|
||||
@Nullable
|
||||
private final ServerPlayer player;
|
||||
|
||||
public OnDatapackSyncEvent(PlayerList playerList, @Nullable ServerPlayer player) {
|
||||
this.playerList = playerList;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The server's player list to get a view of all players.
|
||||
*/
|
||||
public PlayerList getPlayerList() {
|
||||
return this.playerList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The player to sync datapacks to. Null when syncing for all players,
|
||||
* such as when the reload command runs.
|
||||
*/
|
||||
@Nullable
|
||||
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);
|
||||
return getPlayer == null ? getPlayerList.getPlayers() : List.of(this.getPlayer);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user