forked from PaperMC/Velocity
-
Notifications
You must be signed in to change notification settings - Fork 64
Add PlayerConfigurationResourcePackEvent to apply resource packs during configuration
#992
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
111 changes: 111 additions & 0 deletions
111
.../com/velocityctd/api/event/player/configuration/PlayerConfigurationResourcePackEvent.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /* | ||
| * Copyright (C) 2026 Velocity-CTD Contributors | ||
| * | ||
| * The Velocity API is licensed under the terms of the MIT License. For more details, | ||
| * reference the LICENSE file in the api top-level directory. | ||
| */ | ||
|
|
||
| package com.velocityctd.api.event.player.configuration; | ||
|
|
||
| import com.google.common.base.Preconditions; | ||
| import com.velocitypowered.api.event.annotation.AwaitingEvent; | ||
| import com.velocitypowered.api.proxy.Player; | ||
| import com.velocitypowered.api.proxy.ServerConnection; | ||
| import net.kyori.adventure.resource.ResourcePackRequest; | ||
| import net.kyori.adventure.resource.ResourcePackRequestLike; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| /** | ||
| * Fired while a player is in the configuration state, allowing plugins to apply resource packs | ||
| * before the player enters play. | ||
| * | ||
| * <p>If a resource pack is set, the player is held in configuration until every pack reaches a | ||
| * terminal status. The event is fired on every (re)configuration; use {@link #isFirstJoin()} to | ||
| * tell the initial post-login configuration (e.g. network-wide packs) from a server-switch | ||
| * reconfiguration (e.g. per-server packs).</p> | ||
| * | ||
| * @since Minecraft 1.20.2 | ||
| */ | ||
| @AwaitingEvent | ||
| public final class PlayerConfigurationResourcePackEvent { | ||
|
|
||
| private final Player player; | ||
| private final ServerConnection server; | ||
| private final boolean firstJoin; | ||
|
|
||
| private @Nullable ResourcePackRequest resourcePack; | ||
|
|
||
| /** | ||
| * Constructs a new {@link PlayerConfigurationResourcePackEvent}. | ||
| * | ||
| * @param player the player being configured | ||
| * @param server the server (re-)configuring the player | ||
| * @param firstJoin whether this is the initial configuration following login | ||
| */ | ||
| public PlayerConfigurationResourcePackEvent(Player player, | ||
| ServerConnection server, | ||
| boolean firstJoin) { | ||
| this.player = Preconditions.checkNotNull(player, "player"); | ||
| this.server = server; | ||
| this.firstJoin = firstJoin; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the player being configured. | ||
| * | ||
| * @return the player | ||
| */ | ||
| public Player getPlayer() { | ||
| return this.player; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the server (re-)configuring the player. | ||
| * | ||
| * @return the configuring server connection | ||
| */ | ||
| public ServerConnection getServer() { | ||
| return this.server; | ||
| } | ||
|
|
||
| /** | ||
| * Gets whether this is the initial configuration following login, rather than a server-switch | ||
| * reconfiguration. | ||
| * | ||
| * @return {@code true} if this is the player's first configuration this session | ||
| */ | ||
| public boolean isFirstJoin() { | ||
| return this.firstJoin; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the resource pack request to apply during this configuration, if any. | ||
| * | ||
| * @return the resource pack request, or {@code null} if none has been set | ||
| */ | ||
| public @Nullable ResourcePackRequest getResourcePack() { | ||
| return this.resourcePack; | ||
| } | ||
|
|
||
| /** | ||
| * Sets the resource pack(s) to apply during this configuration. | ||
| * | ||
| * <p>Accepts a single {@link com.velocitypowered.api.proxy.player.ResourcePackInfo} or a | ||
| * {@link ResourcePackRequest}; pass {@code null} to apply none.</p> | ||
| * | ||
| * @param resourcePack the resource pack request to apply, or {@code null} to apply none | ||
| */ | ||
| public void setResourcePack(@Nullable ResourcePackRequestLike resourcePack) { | ||
| this.resourcePack = resourcePack == null ? null : resourcePack.asResourcePackRequest(); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "PlayerConfigurationResourcePackEvent{" | ||
| + "player=" + player | ||
| + ", server=" + server | ||
| + ", firstJoin=" + firstJoin | ||
| + ", resourcePack=" + resourcePack | ||
| + '}'; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.