Skip to content

Commit

Permalink
feat: Add support for Minecraft 1.21.2/3 (#228)
Browse files Browse the repository at this point in the history
* First step for 1.21.2

* fix

* feat: start preparing 1.21.2 support

bumps gradle and various build deps

* build: now requires Velocity 3.4.0

* build: use Velocity 3.4.0 from maven

* refactor: cleanup, fix wrong protocol ver in 765

* refactor: minor code cleanup & reformat

* refactor: further code cleanup

* refactor: more minor refactoring work

* docs: document prerequisites for using the plugin message API

* Fixed team packet mapping problem
Fixed problems with SortingOrder packet
Changed scoreboard logic to skip team packets for 1.21.2+ players if nametag is empty

* docs: further grammar fixes to plugin message API docs

* refactor: adjust PPB version checking logic

* build: simplify PPB test logic

* refactor: remove unused code

* refactor: adjust formatting

* refactor: make nametag empty by default

* refactor: suppress warning

* fix: `ConfigurationException` deserializing minimum PPB version string

* refactor: remove unused import

* Bug fixes

* Removed tablist order from all TabPlayer instances when a player leaves

* Fixed problem with data structure

* Removed synchronized

* fix: subscriber order not taking effect

* refactor: minor code style tweaks

---------

Co-authored-by: AlexDev_ <[email protected]>
  • Loading branch information
WiIIiam278 and alexdev03 authored Oct 28, 2024
1 parent 73de08e commit 6f140e4
Show file tree
Hide file tree
Showing 35 changed files with 425 additions and 168 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
hangar-token: ${{ secrets.HANGAR_API_KEY }}
hangar-version-type: Alpha
hangar-game-versions: |
3.3
3.4
files: target/Velocitab-*.jar
name: Velocitab v${{ env.version_name }}
version: ${{ env.version_name }}
Expand Down Expand Up @@ -124,4 +124,5 @@ jobs:
1.20.6
1.21
1.21.1
1.21.2
java: 17
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
hangar-token: ${{ secrets.HANGAR_API_KEY }}
hangar-version-type: Release
hangar-game-versions: |
3.3
3.4
files: target/Velocitab-*.jar
name: Velocitab v${{ github.event.release.tag_name }}
version: ${{ github.event.release.tag_name }}
Expand Down Expand Up @@ -113,4 +113,5 @@ jobs:
1.20.6
1.21
1.21.1
1.21.2
java: 17
17 changes: 9 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import org.apache.tools.ant.filters.ReplaceTokens

plugins {
id 'xyz.jpenilla.run-velocity' version '2.3.1'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'com.gradleup.shadow' version '8.3.3'
id 'org.cadixdev.licenser' version '0.6.1'
id 'org.ajoberstar.grgit' version '5.2.2'
id 'org.ajoberstar.grgit' version '5.3.0'
id 'maven-publish'
id 'java'
}

group 'net.william278'
version "$ext.plugin_version${versionMetadata()}"
version "$ext.plugin_version"
description "$ext.plugin_description"
defaultTasks 'licenseFormat', 'build'

Expand All @@ -20,23 +20,24 @@ ext {

set 'velocity_api_version', velocity_api_version.toString()
set 'velocity_minimum_build', velocity_minimum_build.toString()
set 'papi_proxy_bridge_minimum_version', papi_proxy_bridge_minimum_version.toString()
}

repositories {
mavenCentral()
maven { url = 'https://repo.william278.net/velocity/' }
maven { url = 'https://repo.papermc.io/repository/maven-public/' }
maven { url = 'https://jitpack.io' }
maven { url = 'https://repo.william278.net/releases/' }
maven { url = 'https://repo.william278.net/snapshots/' }
maven { url = 'https://repo.papermc.io/repository/maven-public/' }
maven { url = 'https://repo.minebench.de/' }
maven { url = 'https://jitpack.io' }
}

dependencies {
compileOnly "com.velocitypowered:velocity-api:${velocity_api_version}-SNAPSHOT"
compileOnly "com.velocitypowered:velocity-proxy:${velocity_api_version}-SNAPSHOT"

compileOnly 'io.netty:netty-codec-http:4.1.112.Final'
compileOnly 'io.netty:netty-codec-http:4.1.114.Final'
compileOnly 'org.projectlombok:lombok:1.18.34'
compileOnly 'net.luckperms:api:5.4'
compileOnly 'io.github.miniplaceholders:miniplaceholders-api:2.2.3'
Expand Down Expand Up @@ -71,7 +72,6 @@ license {
}

logger.lifecycle("Building Velocitab ${version} by William278")

version rootProject.version
archivesBaseName = "${rootProject.name}"

Expand Down Expand Up @@ -160,11 +160,12 @@ publishing {
}

tasks {
var papi = papi_proxy_bridge_minimum_version
runVelocity {
velocityVersion("${velocity_api_version}-SNAPSHOT")

downloadPlugins {
modrinth ("papiproxybridge", "1.6.1")
modrinth ("papiproxybridge", papi)
modrinth ("miniplaceholders", "2.2.4")
}
}
Expand Down
23 changes: 15 additions & 8 deletions docs/Plugin-Message-API.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
Velocitab provides a plugin message API.
Velocitab provides a plugin message API, to let you do things with Velocitab from your backend servers.

> **Note:** This feature requires sending Update Teams packets. `send_scoreboard_packets` must be enabled in the [`config.yml` file](config-file) for this to work. [More details...](sorting#compatibility-issues)
>
## Prerequisites
To use the Velocitab plugin message API, you must first turn it on and ensure the following:

* That `enable_plugin_message_api` and `send_scoreboard_packets` is set to `true` in your Velocitab [[config file]]
* That `bungee-plugin-message-channel` is set to `true` in your **Velocity proxy config** TOML (see [Velocity config reference](https://docs.papermc.io/velocity/configuration)).

## API Requests from Backend Plugins

### 1 Changing player's username in the TAB List
To change a player's username in the tablist, you can send a plugin message with the channel `velocitab:update_custom_name` and as data `customName`.
Remember to replace `customName` with the desired name.
### 1 Changing player's username in the TAB list
To change a player's username in the TAB list, you can send a plugin message on the channel `velocitab:update_custom_name` with a `customName` string, where `customName` is the new desired display name.
<details>
<summary>Example &mdash; Changing player's username in the TAB List</summary>

Expand All @@ -13,10 +20,10 @@ player.sendPluginMessage(plugin, "velocitab:update_custom_name", "Steve".getByte
```
</details>

### 2 Update team color
To change a player's team color in the TAB List, you can send a plugin message with the channel `velocitab:update_team_color` and as data `teamColor`.
You can only use legacy color codes, for example `a` for green, `b` for aqua, etc.
This option overrides the glow effect if set
### 2 Update color of player's nametag
To change player's [nametag](nametags) color, you can send a plugin message on the channel `velocitab:update_team_color` with `teamColor` string, where `teamColor` is the new desired name tag color.

You can only use legacy color codes, for example `a` for green, `b` for aqua, etc. Please note this option overrides the color of the glow potion effect if set. [Check here](https://wiki.vg/index.php?title=Text_formatting&oldid=18983#Colors) for a list of supported colors (The value under the "Code" header on the table is what you need).

<details>
<summary>Example &mdash; Changing player's team color</summary>
Expand Down
2 changes: 1 addition & 1 deletion docs/Setup.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
This page will walk you through installing Velocitab on a Velocity proxy server.

## Requirements
* A Velocity proxy server (running Velocity 3.3.0 or newer)
* A Velocity proxy server (running Velocity 3.4.0 or newer)
* Backend Minecraft servers. The following Minecraft server versions are fully supported:
- Minecraft 1.8&mdash;1.8.9
- Minecraft 1.12.2&mdash;latest
Expand Down
7 changes: 4 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ javaVersion=17
org.gradle.jvmargs='-Dfile.encoding=UTF-8'
org.gradle.daemon=true

plugin_version=1.7.1
plugin_version=1.7.2
plugin_archive=velocitab
plugin_description=A beautiful and versatile TAB list plugin for Velocity proxies

velocity_api_version=3.3.0
velocity_minimum_build=400
velocity_api_version=3.4.0
velocity_minimum_build=444
papi_proxy_bridge_minimum_version=1.7
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
20 changes: 10 additions & 10 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand All @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2

goto fail

Expand Down
7 changes: 3 additions & 4 deletions src/main/java/net/william278/velocitab/Velocitab.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@

import java.nio.file.Path;
import java.util.List;
import java.util.Optional;

@Plugin(id = "velocitab")
@Getter
Expand Down Expand Up @@ -144,9 +143,9 @@ public Velocitab getPlugin() {
return this;
}

@NotNull
public Optional<ScoreboardManager> getScoreboardManager() {
return Optional.ofNullable(scoreboardManager);
@Override
public ScoreboardManager getScoreboardManager() {
return scoreboardManager;
}

private void prepareAPI() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package net.william278.velocitab.config;

import com.velocitypowered.api.plugin.PluginContainer;
import com.velocitypowered.api.plugin.PluginDescription;
import de.exlll.configlib.NameFormatters;
import de.exlll.configlib.YamlConfigurationProperties;
import de.exlll.configlib.YamlConfigurations;
Expand Down Expand Up @@ -129,16 +131,24 @@ default Metadata getMetadata() {
}
}

@SuppressWarnings("OptionalIsPresent")
default void checkCompatibility() {
if (getSkipCompatibilityCheck().orElse(false)) {
getPlugin().getLogger().warn("Skipping compatibility check");
getPlugin().getLogger().warn("Skipping compatibility checks");
return;
}

// Validate Velocity platform version
final Metadata metadata = getMetadata();
final Version proxyVersion = getVelocityVersion();
metadata.validateApiVersion(proxyVersion);
metadata.validateBuild(proxyVersion);

// Validate PAPIProxyBridge hook version
final Optional<Version> papiProxyBridgeVersion = getPapiProxyBridgeVersion();
if (papiProxyBridgeVersion.isPresent()) {
metadata.validatePapiProxyBridgeVersion(papiProxyBridgeVersion.get());
}
}

@NotNull
Expand All @@ -151,6 +161,12 @@ default Optional<Boolean> getSkipCompatibilityCheck() {
.findFirst();
}

default Optional<Version> getPapiProxyBridgeVersion() {
return getPlugin().getServer().getPluginManager()
.getPlugin("papiproxybridge").map(PluginContainer::getDescription)
.flatMap(PluginDescription::getVersion).map(Version::fromString);
}

@NotNull
Version getVelocityVersion();

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/william278/velocitab/config/Formatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import net.william278.velocitab.Velocitab;
import net.william278.velocitab.player.TabPlayer;
import net.william278.velocitab.util.QuadFunction;
import net.william278.velocitab.util.SerializerUtil;
import net.william278.velocitab.util.SerializationUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -57,11 +57,11 @@ public enum Formatter {
MiniMessage.miniMessage()::serialize
),
LEGACY(
(text, player, viewer, plugin) -> SerializerUtil.LEGACY_SERIALIZER.deserialize(text),
(text, player, viewer, plugin) -> SerializationUtil.LEGACY_SERIALIZER.deserialize(text),
Function.identity(),
"Legacy Text",
SerializerUtil.LEGACY_SERIALIZER::deserialize,
SerializerUtil.LEGACY_SERIALIZER::serialize
SerializationUtil.LEGACY_SERIALIZER::deserialize,
SerializationUtil.LEGACY_SERIALIZER::serialize
);


Expand Down
9 changes: 9 additions & 0 deletions src/main/java/net/william278/velocitab/config/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class Metadata {

private String velocityApiVersion;
private int velocityMinimumBuild;
private String papiProxyBridgeMinimumVersion;

public void validateApiVersion(@NotNull Version version) {
if (version.compareTo(Version.fromString(velocityApiVersion)) < 0) {
Expand All @@ -56,6 +57,14 @@ public void validateBuild(@NotNull Version version) {
}
}

public void validatePapiProxyBridgeVersion(@NotNull Version version) {
if (version.compareTo(Version.fromString(papiProxyBridgeMinimumVersion)) < 0) {
final String serverVersion = version.toStringWithoutMetadata();
throw new IllegalStateException("Your PAPIProxyBridge version (" + serverVersion + ") is not supported! " +
"Disabling Velocitab. Please update to at least PAPIProxyBridge v" + papiProxyBridgeMinimumVersion + ".");
}
}

private int getBuildNumber(@NotNull String proxyVersion) {
final Matcher matcher = Pattern.compile(".*-b(\\d+).*").matcher(proxyVersion);
if (matcher.find(1)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CompletableFuture<ServerLink> getServerLink(@NotNull Velocitab plugin, @NotNull
(type) -> CompletableFuture.completedFuture(ServerLink.serverLink(type, url()))
).orElseGet(
() -> Placeholder.replace(label(), plugin, player)
.thenApply(replaced -> plugin.getFormatter().format(replaced, player, plugin))
.thenApply(replaced -> plugin.getFormatter().format(replaced, player, plugin))
.thenApply(formatted -> ServerLink.serverLink(formatted, url()))
);
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/net/william278/velocitab/config/TabGroups.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class TabGroups implements ConfigValidator {
List.of("<rainbow:!2>Running Velocitab by William278 & AlexDev_</rainbow>"),
List.of("<gray>There are currently %players_online%/%max_players_online% players online</gray>"),
"<gray>[%server%] %prefix%%username%</gray>",
new Nametag("<white>%prefix%</white>", "<white>%suffix%</white>"),
new Nametag("", ""),
Set.of("lobby", "survival", "creative", "minigames", "skyblock", "prison", "hub"),
List.of("%role_weight%", "%username_lower%"),
false,
Expand All @@ -63,11 +63,12 @@ public class TabGroups implements ConfigValidator {
public List<Group> groups = List.of(DEFAULT_GROUP);

@NotNull
@SuppressWarnings("unused")
public Group getGroupFromName(@NotNull String name) {
return groups.stream()
.filter(group -> group.name().equals(name))
.findFirst()
.orElseThrow(() -> new IllegalStateException("No group with name " + name + " found"));
.orElseThrow(() -> new IllegalStateException("No group with name %s found".formatted(name)));
}

public Optional<Group> getGroup(@NotNull String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ public class MiniConditionManager {

public final static Map<String, String> REPLACE_2 = Map.of(
"*LESS3*", "<",
"*GREATER3*",">",
"*GREATER3*", ">",
"*LESS2*", "<",
"*GREATER2*", ">"
);
);

private final static Map<String, String> REPLACE_3 = Map.of(
"?dp?", ":"
Expand Down
Loading

0 comments on commit 6f140e4

Please sign in to comment.