Skip to content

Commit

Permalink
WIP 1.20.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrygames committed Nov 22, 2023
1 parent 8dcc7ee commit c1f2888
Show file tree
Hide file tree
Showing 25 changed files with 406 additions and 321 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public enum ProtocolVersion {
MINECRAFT_1_19_3(761, "1.19.3"),
MINECRAFT_1_19_4(762, "1.19.4"),
MINECRAFT_1_20(763, "1.20", "1.20.1"),
MINECRAFT_1_20_2(764, "1.20.2");
MINECRAFT_1_20_2(764, "1.20.2"),
MINECRAFT_1_20_3(765, "1.20.3");

private static final int SNAPSHOT_BIT = 30;

Expand Down
21 changes: 21 additions & 0 deletions api/src/main/java/com/velocitypowered/api/proxy/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.velocitypowered.api.proxy.server.RegisteredServer;
import com.velocitypowered.api.util.GameProfile;
import com.velocitypowered.api.util.ModInfo;

import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Optional;
Expand Down Expand Up @@ -236,6 +238,7 @@ default void clearHeaderAndFooter() {
* @return the applied resource pack or null if none.
*/
@Nullable
@Deprecated
ResourcePackInfo getAppliedResourcePack();

/**
Expand All @@ -246,8 +249,26 @@ default void clearHeaderAndFooter() {
* @return the pending resource pack or null if none
*/
@Nullable
@Deprecated
ResourcePackInfo getPendingResourcePack();

/**
* Gets the {@link ResourcePackInfo} of the currently applied
* resource-packs.
*
* @return collection of the applied resource packs.
*/
Collection<ResourcePackInfo> getAppliedResourcePacks();

/**
* Gets the {@link ResourcePackInfo} of the resource packs
* the user is currently downloading or is currently
* prompted to install.
*
* @return collection of the pending resource packs
*/
Collection<ResourcePackInfo> getPendingResourcePacks();

/**
* <strong>Note that this method does not send a plugin message to the server the player
* is connected to.</strong> You should only use this method if you are trying to communicate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,20 @@
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.UUID;

/**
* Represents the information for a resource pack to apply that can be sent to the client.
*/
public interface ResourcePackInfo {

/**
* Gets the id of this resource-pack.
*
* @return the id of the resource-pack
*/
UUID getId();

/**
* Gets the link the resource-pack can be found at.
*
Expand Down Expand Up @@ -96,6 +105,13 @@ public interface ResourcePackInfo {
*/
interface Builder {

/**
* Sets the id of the resource pack.
*
* @param id the id the resource-pack
*/
Builder setId(UUID id);

/**
* Sets the resource-pack as required to play on the network.
* This feature was introduced in 1.17.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import com.velocitypowered.proxy.protocol.packet.PingIdentify;
import com.velocitypowered.proxy.protocol.packet.PluginMessage;
import com.velocitypowered.proxy.protocol.packet.RemovePlayerInfo;
import com.velocitypowered.proxy.protocol.packet.RemoveResourcePack;
import com.velocitypowered.proxy.protocol.packet.ResourcePackRequest;
import com.velocitypowered.proxy.protocol.packet.ResourcePackResponse;
import com.velocitypowered.proxy.protocol.packet.Respawn;
Expand Down Expand Up @@ -248,6 +249,10 @@ default boolean handle(ResourcePackRequest packet) {
return false;
}

default boolean handle(RemoveResourcePack packet) {
return false;
}

default boolean handle(ResourcePackResponse packet) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@
import com.velocitypowered.proxy.protocol.packet.LegacyPlayerListItem;
import com.velocitypowered.proxy.protocol.packet.PluginMessage;
import com.velocitypowered.proxy.protocol.packet.RemovePlayerInfo;
import com.velocitypowered.proxy.protocol.packet.RemoveResourcePack;
import com.velocitypowered.proxy.protocol.packet.ResourcePackRequest;
import com.velocitypowered.proxy.protocol.packet.ResourcePackResponse;
import com.velocitypowered.proxy.protocol.packet.ServerData;
import com.velocitypowered.proxy.protocol.packet.TabCompleteResponse;
import com.velocitypowered.proxy.protocol.packet.UpsertPlayerInfo;
import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder;
import com.velocitypowered.proxy.protocol.packet.config.StartUpdate;
import com.velocitypowered.proxy.protocol.util.PluginMessageUtil;
import io.netty.buffer.ByteBuf;
Expand Down Expand Up @@ -167,7 +169,8 @@ public boolean handle(BossBar packet) {
public boolean handle(ResourcePackRequest packet) {
ResourcePackInfo.Builder builder = new VelocityResourcePackInfo.BuilderImpl(
Preconditions.checkNotNull(packet.getUrl()))
.setPrompt(packet.getPrompt())
.setId(packet.getId())
.setPrompt(packet.getPrompt() == null ? null : packet.getPrompt().getComponent())
.setShouldForce(packet.isRequired())
.setOrigin(ResourcePackInfo.Origin.DOWNSTREAM_SERVER);

Expand Down Expand Up @@ -213,6 +216,11 @@ public boolean handle(ResourcePackRequest packet) {
return true;
}

@Override
public boolean handle(RemoveResourcePack packet) {
//TODO
}

@Override
public boolean handle(PluginMessage packet) {
if (bungeecordMessageResponder.process(packet)) {
Expand Down Expand Up @@ -304,7 +312,8 @@ public boolean handle(ServerData packet) {
ping -> server.getEventManager()
.fire(new ProxyPingEvent(this.serverConn.getPlayer(), ping)),
playerConnection.eventLoop()).thenAcceptAsync(pingEvent -> this.playerConnection.write(
new ServerData(pingEvent.getPing().getDescriptionComponent(),
new ServerData(new ComponentHolder(this.serverConn.ensureConnected().getProtocolVersion(),
pingEvent.getPing().getDescriptionComponent()),
pingEvent.getPing().getFavicon().orElse(null), packet.isSecureChatEnforced())),
playerConnection.eventLoop());
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import com.velocitypowered.proxy.protocol.packet.ResourcePackRequest;
import com.velocitypowered.proxy.protocol.packet.chat.ChatQueue;
import com.velocitypowered.proxy.protocol.packet.chat.ChatType;
import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder;
import com.velocitypowered.proxy.protocol.packet.chat.builder.ChatBuilderFactory;
import com.velocitypowered.proxy.protocol.packet.chat.legacy.LegacyChat;
import com.velocitypowered.proxy.protocol.packet.config.StartUpdate;
Expand All @@ -84,6 +85,7 @@
import io.netty.buffer.Unpooled;
import java.net.InetSocketAddress;
import java.util.ArrayDeque;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -1015,22 +1017,36 @@ private void tickResourcePackQueue() {
request.setHash("");
}
request.setRequired(queued.getShouldForce());
request.setPrompt(queued.getPrompt());
request.setPrompt(queued.getPrompt() == null ? null : new ComponentHolder(getProtocolVersion(), queued.getPrompt()));

connection.write(request);
}
}

@Override
@Deprecated
public @Nullable ResourcePackInfo getAppliedResourcePack() {
//TODO which resource pack should be returned here?
return appliedResourcePack;
}

@Override
@Deprecated
public @Nullable ResourcePackInfo getPendingResourcePack() {
//TODO which resource pack should be returned here?
return pendingResourcePack;
}

@Override
public Collection<ResourcePackInfo> getAppliedResourcePacks() {
//TODO
}

@Override
public Collection<ResourcePackInfo> getPendingResourcePacks() {
//TODO
}

/**
* Clears the applied resource pack field.
*/
Expand Down Expand Up @@ -1089,6 +1105,7 @@ public boolean onResourcePackResponse(PlayerResourcePackStatusEvent.Status statu
* Gives an indication about the previous resource pack responses.
*/
public @Nullable Boolean getPreviousResourceResponse() {
//TODO can probably be removed
return previousResourceResponse;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,24 @@
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;

import java.util.UUID;

/**
* Implements {@link ResourcePackInfo}.
*/
public final class VelocityResourcePackInfo implements ResourcePackInfo {

private final UUID id;
private final String url;
private final @Nullable byte[] hash;
private final boolean shouldForce;
private final @Nullable Component prompt; // 1.17+ only
private final Origin origin;
private Origin originalOrigin;

private VelocityResourcePackInfo(String url, @Nullable byte[] hash, boolean shouldForce,
private VelocityResourcePackInfo(UUID id, String url, @Nullable byte[] hash, boolean shouldForce,
@Nullable Component prompt, Origin origin) {
this.id = id;
this.url = url;
this.hash = hash;
this.shouldForce = shouldForce;
Expand All @@ -44,6 +48,11 @@ private VelocityResourcePackInfo(String url, @Nullable byte[] hash, boolean shou
this.originalOrigin = origin;
}

@Override
public UUID getId() {
return id;
}

@Override
public String getUrl() {
return url;
Expand Down Expand Up @@ -81,6 +90,7 @@ public Origin getOriginalOrigin() {
@Override
public Builder asBuilder() {
return new BuilderImpl(url)
.setId(id)
.setShouldForce(shouldForce)
.setHash(hash)
.setPrompt(prompt);
Expand All @@ -89,6 +99,7 @@ public Builder asBuilder() {
@Override
public Builder asBuilder(String newUrl) {
return new BuilderImpl(newUrl)
.setId(id)
.setShouldForce(shouldForce)
.setHash(hash)
.setPrompt(prompt);
Expand All @@ -99,6 +110,7 @@ public Builder asBuilder(String newUrl) {
*/
public static final class BuilderImpl implements ResourcePackInfo.Builder {

private UUID id;
private final String url;
private boolean shouldForce;
private @Nullable byte[] hash;
Expand All @@ -109,6 +121,12 @@ public BuilderImpl(String url) {
this.url = Preconditions.checkNotNull(url, "url");
}

@Override
public BuilderImpl setId(UUID id) {
this.id = id;
return this;
}

@Override
public BuilderImpl setShouldForce(boolean shouldForce) {
this.shouldForce = shouldForce;
Expand All @@ -134,7 +152,7 @@ public BuilderImpl setPrompt(@Nullable Component prompt) {

@Override
public ResourcePackInfo build() {
return new VelocityResourcePackInfo(url, hash, shouldForce, prompt, origin);
return new VelocityResourcePackInfo(id, url, hash, shouldForce, prompt, origin);
}

public BuilderImpl setOrigin(Origin origin) {
Expand Down
Loading

0 comments on commit c1f2888

Please sign in to comment.