-
-
Notifications
You must be signed in to change notification settings - Fork 647
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add basic API for server links (#1353)
* feat: add basic server links API * refactor: more precondition checking on links * refactor: remove whitespace * refactor: adjust method order, JDs in ServerLink * refactor: remove "throws" from constructors * refactor: add @NotNull annotations * refactor: requested changes * refactor: just use `List#copyOf`
- Loading branch information
1 parent
e60e206
commit 9d25d30
Showing
4 changed files
with
140 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
api/src/main/java/com/velocitypowered/api/util/ServerLink.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Copyright (C) 2021-2024 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.util; | ||
|
||
import com.google.common.base.Preconditions; | ||
import java.net.URI; | ||
import java.util.Optional; | ||
import net.kyori.adventure.text.Component; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Represents a custom URL servers can show in player pause menus. | ||
* Links can be of a built-in type or use a custom component text label. | ||
*/ | ||
public final class ServerLink { | ||
|
||
private @Nullable Type type; | ||
private @Nullable Component label; | ||
private final URI url; | ||
|
||
private ServerLink(Component label, String url) { | ||
this.label = Preconditions.checkNotNull(label, "label"); | ||
this.url = URI.create(url); | ||
} | ||
|
||
private ServerLink(Type type, String url) { | ||
this.type = Preconditions.checkNotNull(type, "type"); | ||
this.url = URI.create(url); | ||
} | ||
|
||
/** | ||
* Construct a server link with a custom component label. | ||
* | ||
* @param label a custom component label to display | ||
* @param link the URL to open when clicked | ||
*/ | ||
public static ServerLink serverLink(Component label, String link) { | ||
return new ServerLink(label, link); | ||
} | ||
|
||
/** | ||
* Construct a server link with a built-in type. | ||
* | ||
* @param type the {@link Type built-in type} of link | ||
* @param link the URL to open when clicked | ||
*/ | ||
public static ServerLink serverLink(Type type, String link) { | ||
return new ServerLink(type, link); | ||
} | ||
|
||
/** | ||
* Get the type of the server link. | ||
* | ||
* @return the type of the server link | ||
*/ | ||
public Optional<Type> getBuiltInType() { | ||
return Optional.ofNullable(type); | ||
} | ||
|
||
/** | ||
* Get the custom component label of the server link. | ||
* | ||
* @return the custom component label of the server link | ||
*/ | ||
public Optional<Component> getCustomLabel() { | ||
return Optional.ofNullable(label); | ||
} | ||
|
||
/** | ||
* Get the link {@link URI}. | ||
* | ||
* @return the link {@link URI} | ||
*/ | ||
public URI getUrl() { | ||
return url; | ||
} | ||
|
||
/** | ||
* Built-in types of server links. | ||
* | ||
* @apiNote {@link Type#BUG_REPORT} links are shown on the connection error screen | ||
*/ | ||
public enum Type { | ||
BUG_REPORT, | ||
COMMUNITY_GUIDELINES, | ||
SUPPORT, | ||
STATUS, | ||
FEEDBACK, | ||
COMMUNITY, | ||
WEBSITE, | ||
FORUMS, | ||
NEWS, | ||
ANNOUNCEMENTS | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters