Implement resource pack send event. (#625)

This commit is contained in:
Corey Shupe
2022-02-01 23:30:45 -05:00
committed by GitHub
parent b8f1df4470
commit 596d4758ba
6 changed files with 191 additions and 14 deletions

View File

@@ -0,0 +1,70 @@
/*
* Copyright (C) 2018 Velocity 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.velocitypowered.api.event.player;
import com.velocitypowered.api.event.ResultedEvent;
import com.velocitypowered.api.event.annotation.AwaitingEvent;
import com.velocitypowered.api.proxy.ServerConnection;
import com.velocitypowered.api.proxy.player.ResourcePackInfo;
/**
* This event is fired when the downstream server tries to send a player a ResourcePack packet.
* The proxy will wait on this event to finish before forwarding the resource pack to the user.
* If this event is denied, it will retroactively send a DENIED status to the downstream
* server in response.
* If the downstream server has it set to "forced" it will forcefully disconnect the user.
*/
@AwaitingEvent
public class ServerResourcePackSendEvent implements ResultedEvent<ResultedEvent.GenericResult> {
private GenericResult result;
private final ResourcePackInfo receivedResourcePack;
private ResourcePackInfo providedResourcePack;
private final ServerConnection serverConnection;
/**
* Constructs a new ServerResourcePackSendEvent.
*
* @param receivedResourcePack The resource pack the server sent.
* @param serverConnection The connection this occurred on.
*/
public ServerResourcePackSendEvent(
ResourcePackInfo receivedResourcePack,
ServerConnection serverConnection
) {
this.result = ResultedEvent.GenericResult.allowed();
this.receivedResourcePack = receivedResourcePack;
this.serverConnection = serverConnection;
this.providedResourcePack = receivedResourcePack;
}
public ServerConnection getServerConnection() {
return serverConnection;
}
public ResourcePackInfo getReceivedResourcePack() {
return receivedResourcePack;
}
public ResourcePackInfo getProvidedResourcePack() {
return providedResourcePack;
}
public void setProvidedResourcePack(ResourcePackInfo providedResourcePack) {
this.providedResourcePack = providedResourcePack;
}
@Override
public GenericResult getResult() {
return this.result;
}
@Override
public void setResult(GenericResult result) {
this.result = result;
}
}

View File

@@ -46,12 +46,48 @@ public interface ResourcePackInfo {
byte[] getHash();
/**
* Gets the {@link Origin} of the resource-pack.
* Gets the {@link Origin} of this resource-pack.
*
* @return the origin of the resource pack
*/
Origin getOrigin();
/**
* Gets the original {@link Origin} of the resource-pack.
* The original origin may differ if the resource pack was altered in the event
* {@link com.velocitypowered.api.event.player.ServerResourcePackSendEvent}.
*
* @return the origin of the resource pack
*/
Origin getOriginalOrigin();
/**
* Returns a copy of this {@link ResourcePackInfo} instance as a builder so that it can
* be modified.
* It is <b>not</b> guaranteed that
* {@code resourcePackInfo.asBuilder().build().equals(resourcePackInfo)} is true. That is due to
* the transient {@link ResourcePackInfo#getOrigin()} and
* {@link ResourcePackInfo#getOriginalOrigin()} fields.
*
*
* @return a content-copy of this instance as a {@link ResourcePackInfo.Builder}
*/
ResourcePackInfo.Builder asBuilder();
/**
* Returns a copy of this {@link ResourcePackInfo} instance as a builder with the new URL as the pack URL so that
* it can be modified.
* It is <b>not</b> guaranteed that
* {@code resourcePackInfo.asBuilder(resourcePackInfo.getUrl()).build().equals(resourcePackInfo)} is true.
* That is due to the transient {@link ResourcePackInfo#getOrigin()} and
* {@link ResourcePackInfo#getOriginalOrigin()} fields.
*
* @param newUrl The new URL to use in the updated builder.
*
* @return a content-copy of this instance as a {@link ResourcePackInfo.Builder}
*/
ResourcePackInfo.Builder asBuilder(String newUrl);
interface Builder {
/**