#3864: Add ServerLinks API

This commit is contained in:
Outfluencer
2025-07-23 19:13:03 +10:00
committed by md_5
parent 8e99a4c5bf
commit e62fc6c291
4 changed files with 111 additions and 20 deletions

View File

@@ -0,0 +1,77 @@
package net.md_5.bungee.api;
import lombok.AccessLevel;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import net.md_5.bungee.api.chat.BaseComponent;
/**
* Represents a server link which may be sent to the client.
*/
@Data
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public final class ServerLink
{
/**
* The links type.
*
* Note: This value is nullable, if null, label is non-null.
*/
private final LinkType type;
/**
* The label for the link.
*
* Note: This value is nullable, if null, type is non-null.
*/
private final BaseComponent label;
/**
* The URL that is displayed.
*/
@NonNull
private final String url;
/**
* Creates a link with a specified type and URL.
*
* @param type the type of the link
* @param url the URL to be displayed
*/
public ServerLink(@NonNull LinkType type, @NonNull String url)
{
this.type = type;
this.label = null;
this.url = url;
}
/**
* Creates a link with a label and URL.
*
* @param label the label to be displayed
* @param url the URL to be displayed
*/
public ServerLink(@NonNull BaseComponent label, @NonNull String url)
{
this.type = null;
this.label = label;
this.url = url;
}
public enum LinkType
{
REPORT_BUG,
COMMUNITY_GUIDELINES,
SUPPORT,
STATUS,
FEEDBACK,
COMMUNITY,
WEBSITE,
FORUMS,
NEWS,
ANNOUNCEMENTS;
}
}

View File

@@ -1,5 +1,6 @@
package net.md_5.bungee.api.connection;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
@@ -8,6 +9,7 @@ import net.md_5.bungee.api.Callback;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ServerConnectRequest;
import net.md_5.bungee.api.ServerLink;
import net.md_5.bungee.api.SkinConfiguration;
import net.md_5.bungee.api.Title;
import net.md_5.bungee.api.chat.BaseComponent;
@@ -411,4 +413,16 @@ public interface ProxiedPlayer extends Connection, CommandSender
*/
@ApiStatus.Experimental
void showDialog(Dialog dialog);
/**
* Sends server links to the player.
*
* Note: The links already sent to the player will be overwritten. Also, the
* backend server is able to override links sent by the proxy.
*
* @param serverLinks the server links to send
* @throws IllegalStateException if the player's version is not at least
* 1.21
*/
void sendServerLinks(List<ServerLink> serverLinks);
}