Refactor ResourcePacks handling (#1225)

* Initial ResourcePack refactor

* Implement sendResourcePacks method

* Initializes the ResourcePackHandler at player initialization

* Move adventure to velocity resource pack conversion to the same class

* Added some internal resource pack documentation

* Refactored Modern ResourcePack handling

* Handle RemoveResourcePackPacket from backend server

* Fixed license

* Use removeIf instead of manual iteration

* Improve ModernResourcePackHandler

* fix hash conversion

* bundle resource packs

* keep old constructors of PlayerResourcePackStatusEvent

* add @Nullable to PlayerResourcePackStatusEvent#getPackId

* Use a single instance of BundleDelimiterPacket

* Throw UnSupportedOperationException on operations not supported by LegacyResourcePackHandler

* Use a single instance on empty packets

* Handle active packet bundle sending from backend server in case of sending a packet bundle of resource packs

* Improve packet bundling

* Fixed login for players with version 1.20.2

---------

Co-authored-by: Gero <gecam59@gmail.com>
This commit is contained in:
Adrian
2024-02-08 08:51:45 -05:00
committed by GitHub
parent 825c3c68d1
commit cbd07b1434
30 changed files with 945 additions and 307 deletions

View File

@@ -12,6 +12,7 @@ import com.velocitypowered.api.event.annotation.AwaitingEvent;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.player.ResourcePackInfo;
import java.util.UUID;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
@@ -24,6 +25,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
public class PlayerResourcePackStatusEvent {
private final Player player;
private final @MonotonicNonNull UUID packId;
private final Status status;
private final @MonotonicNonNull ResourcePackInfo packInfo;
private boolean overwriteKick;
@@ -32,20 +34,31 @@ public class PlayerResourcePackStatusEvent {
* Instantiates this event.
*
* @deprecated Use {@link PlayerResourcePackStatusEvent#PlayerResourcePackStatusEvent
* (Player, Status, ResourcePackInfo)} instead.
* (Player, UUID, Status, ResourcePackInfo)} instead.
*/
@Deprecated
public PlayerResourcePackStatusEvent(Player player, Status status) {
this.player = Preconditions.checkNotNull(player, "player");
this.status = Preconditions.checkNotNull(status, "status");
this.packInfo = null;
this(player, null, status, null);
}
/**
* Instantiates this event.
*
* @deprecated Use {@link PlayerResourcePackStatusEvent#PlayerResourcePackStatusEvent
* (Player, UUID, Status, ResourcePackInfo)} instead.
*/
@Deprecated
public PlayerResourcePackStatusEvent(Player player, Status status, ResourcePackInfo packInfo) {
this(player, null, status, packInfo);
}
/**
* Instantiates this event.
*/
public PlayerResourcePackStatusEvent(Player player, Status status, ResourcePackInfo packInfo) {
public PlayerResourcePackStatusEvent(
Player player, UUID packId, Status status, ResourcePackInfo packInfo) {
this.player = Preconditions.checkNotNull(player, "player");
this.packId = packId == null ? packInfo == null ? null : packInfo.getId() : packId;
this.status = Preconditions.checkNotNull(status, "status");
this.packInfo = packInfo;
}
@@ -59,6 +72,16 @@ public class PlayerResourcePackStatusEvent {
return player;
}
/**
* Returns the id of the resource pack.
*
* @return the id
*/
@Nullable
public UUID getPackId() {
return packId;
}
/**
* Returns the new status for the resource pack.
*

View File

@@ -8,13 +8,14 @@
package com.velocitypowered.api.proxy.player;
import java.util.UUID;
import net.kyori.adventure.resource.ResourcePackRequestLike;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
* Represents the information for a resource pack to apply that can be sent to the client.
*/
public interface ResourcePackInfo {
public interface ResourcePackInfo extends ResourcePackRequestLike {
/**
* Gets the id of this resource-pack.