brainwaves

This commit is contained in:
Shane Freeder
2023-12-14 16:25:16 +00:00
parent 79fe8c8005
commit 09677853c4
5 changed files with 49 additions and 11 deletions

View File

@@ -53,6 +53,9 @@ import com.velocitypowered.proxy.VelocityServer;
import com.velocitypowered.proxy.connection.MinecraftConnection;
import com.velocitypowered.proxy.connection.MinecraftConnectionAssociation;
import com.velocitypowered.proxy.connection.backend.VelocityServerConnection;
import com.velocitypowered.proxy.connection.player.LegacyResourcePackManager;
import com.velocitypowered.proxy.connection.player.ModernResourcePackManager;
import com.velocitypowered.proxy.connection.player.ResourcePackManager;
import com.velocitypowered.proxy.connection.player.VelocityResourcePackInfo;
import com.velocitypowered.proxy.connection.util.ConnectionMessages;
import com.velocitypowered.proxy.connection.util.ConnectionRequestResults.Impl;
@@ -150,6 +153,7 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
private ClientConnectionPhase connectionPhase;
private final CompletableFuture<Void> teardownFuture = new CompletableFuture<>();
private @MonotonicNonNull List<String> serversToTry = null;
private ResourcePackManager resourcePackManager;
private @MonotonicNonNull Boolean previousResourceResponse;
private final Queue<ResourcePackInfo> outstandingResourcePacks = new ArrayDeque<>();
private @Nullable ResourcePackInfo pendingResourcePack;
@@ -186,6 +190,13 @@ public class ConnectedPlayer implements MinecraftConnectionAssociation, Player,
} else {
this.tabList = new VelocityTabListLegacy(this, server);
}
if (connection.getProtocolVersion().getProtocol() >= ProtocolVersion.MINECRAFT_1_20_2.getProtocol()) {
this.resourcePackManager = new ModernResourcePackManager(this);
} else {
this.resourcePackManager = new LegacyResourcePackManager(this);
}
this.playerKey = playerKey;
this.chatQueue = new ChatQueue(this);
this.chatBuilderFactory = new ChatBuilderFactory(this.getProtocolVersion());

View File

@@ -0,0 +1,11 @@
package com.velocitypowered.proxy.connection.player;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
public class LegacyResourcePackManager implements ResourcePackManager {
private final ConnectedPlayer connectedPlayer;
public LegacyResourcePackManager(ConnectedPlayer connectedPlayer) {
this.connectedPlayer = connectedPlayer;
}
}

View File

@@ -0,0 +1,11 @@
package com.velocitypowered.proxy.connection.player;
import com.velocitypowered.proxy.connection.client.ConnectedPlayer;
public class ModernResourcePackManager implements ResourcePackManager {
private final ConnectedPlayer connectedPlayer;
public ModernResourcePackManager(ConnectedPlayer connectedPlayer) {
this.connectedPlayer = connectedPlayer;
}
}

View File

@@ -0,0 +1,11 @@
package com.velocitypowered.proxy.connection.player;
import com.velocitypowered.proxy.protocol.packet.ResourcePackRequest;
import com.velocitypowered.proxy.protocol.packet.ResourcePackResponse;
public interface ResourcePackManager {
void processResponse(ResourcePackResponse response);
void sendRequest(ResourcePackRequest request);
}

View File

@@ -31,7 +31,7 @@ public final class VelocityResourcePackInfo implements ResourcePackInfo {
private final UUID id;
private final String url;
private final @Nullable byte[] hash;
private final byte @Nullable [] hash;
private final boolean shouldForce;
private final @Nullable Component prompt; // 1.17+ only
private final Origin origin;
@@ -89,19 +89,13 @@ public final class VelocityResourcePackInfo implements ResourcePackInfo {
@Override
public Builder asBuilder() {
return new BuilderImpl(url)
.setId(id)
.setShouldForce(shouldForce)
.setHash(hash)
return new BuilderImpl(url).setId(id).setShouldForce(shouldForce).setHash(hash)
.setPrompt(prompt);
}
@Override
public Builder asBuilder(String newUrl) {
return new BuilderImpl(newUrl)
.setId(id)
.setShouldForce(shouldForce)
.setHash(hash)
return new BuilderImpl(newUrl).setId(id).setShouldForce(shouldForce).setHash(hash)
.setPrompt(prompt);
}
@@ -113,7 +107,7 @@ public final class VelocityResourcePackInfo implements ResourcePackInfo {
private UUID id;
private final String url;
private boolean shouldForce;
private @Nullable byte[] hash;
private byte @Nullable [] hash;
private @Nullable Component prompt;
private Origin origin = Origin.PLUGIN_ON_PROXY;
@@ -135,7 +129,7 @@ public final class VelocityResourcePackInfo implements ResourcePackInfo {
}
@Override
public BuilderImpl setHash(@Nullable byte[] hash) {
public BuilderImpl setHash(byte @Nullable [] hash) {
if (hash != null) {
Preconditions.checkArgument(hash.length == 20, "Hash length is not 20");
this.hash = hash.clone(); // Thanks spotbugs, very helpful.