feat: Add support for Minecraft 1.20.3/1.20.4 (#126)

* docs: Minor comment tweak

* Prepare 1.20.3 support pending Velocity

* 1.20.3/1.20.4 & java 17 (#128)

* Improved PacketAdapter system + added support for 1.20.3/1.20.4

* Changed java version to 17, updated velocity dependencies, improved packet adapters & added support for 1.20.3/4.

* Fixed compile error with adventure

* deps: Bump `netty-codec-http` to 4.1.103

* ci: Upgrade dependabot config

* ci: Update CI & Docs with new requirements

* refactor: Rename `LUCK_PERMS_META` -> `LUCKPERMS_META`

* docs: Document `%luckperms_meta_(key)%`

---------

Co-authored-by: AlexDev_ <56083016+alexdev03@users.noreply.github.com>
This commit is contained in:
William 2023-12-14 23:00:04 +00:00 committed by GitHub
parent d72ad289ec
commit f16dd54a7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 170 additions and 226 deletions

View File

@ -2,7 +2,18 @@
version: 2
updates:
- package-ecosystem: "gradle" # See documentation for possible values
directory: "/" # Location of package manifests
# CI workflow action updates
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
interval: "weekly"
commit-message:
prefix: "ci"
# Gradle package updates
- package-ecosystem: "gradle"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "deps"

View File

@ -1,5 +1,5 @@
# Builds, tests the project with Gradle
name: Java CI
# Builds, tests the project with Gradle and publishes to Modrinth & Hangar
name: CI Tests & Publish
on:
push:
@ -11,32 +11,34 @@ on:
permissions:
contents: read
checks: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 16
uses: actions/setup-java@v3
- name: 'Checkout for CI 🛎️'
uses: actions/checkout@v4
- name: 'Set up JDK 17 📦'
uses: actions/setup-java@v4
with:
java-version: '16'
java-version: '17'
distribution: 'temurin'
- name: Build with Gradle
- name: 'Build with Gradle 🏗️'
uses: gradle/gradle-build-action@v2
with:
arguments: build test publish
arguments: build publish
env:
SNAPSHOTS_MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
SNAPSHOTS_MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
- name: Query Version
- name: 'Fetch Version Name 📝'
run: |
echo "::set-output name=VERSION_NAME::$(${{github.workspace}}/gradlew properties --no-daemon --console=plain -q | grep "^version:" | awk '{printf $2}')"
id: fetch-version
- name: Get Version
run: |
echo "version_name=${{steps.fetch-version.outputs.VERSION_NAME}}" >> $GITHUB_ENV
- name: Upload to Modrinth & Hangar
- name: 'Publish to Modrinth & Hangar 🧽'
uses: WiIIiam278/mc-publish@hangar
with:
modrinth-id: Q10irTG0
@ -47,7 +49,7 @@ jobs:
hangar-token: ${{ secrets.HANGAR_API_KEY }}
hangar-version-type: Alpha
hangar-game-versions: |
3.2
3.3
files: target/Velocitab-*.jar
name: Velocitab v${{ env.version_name }}
version: ${{ env.version_name }}
@ -100,9 +102,12 @@ jobs:
1.20
1.20.1
1.20.2
java: 16
- name: Upload GitHub Artifact
uses: actions/upload-artifact@v2
1.20.3
1.20.4
java: 17
- name: 'Upload GitHub Artifact 📦'
uses: actions/upload-artifact@v3
if: success() || failure()
with:
name: Velocitab Plugin
name: Velocitab
path: target/Velocitab-*.jar

View File

@ -1,4 +1,3 @@
# Carry out tests on pull requests
name: PR Tests
on:
@ -7,18 +6,20 @@ on:
permissions:
contents: read
checks: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 16
uses: actions/setup-java@v3
- name: 'Checkout for CI 🛎'
uses: actions/checkout@v4
- name: 'Set up JDK 17 📦'
uses: actions/setup-java@v4
with:
java-version: '16'
java-version: '17'
distribution: 'temurin'
- name: Test Pull Request
uses: gradle/gradle-build-action@67421db6bd0bf253fb4bd25b31ebb98943c375e1
- name: 'Build with Gradle 🏗️'
uses: gradle/gradle-build-action@v2
with:
arguments: build

View File

@ -7,32 +7,27 @@ on:
permissions:
contents: read
checks: write
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 16
uses: actions/setup-java@v3
- name: 'Checkout for CI 🛎️'
uses: actions/checkout@v4
- name: 'Set up JDK 17 📦'
uses: actions/setup-java@v4
with:
java-version: '16'
java-version: '17'
distribution: 'temurin'
- name: Build with Gradle
- name: 'Build with Gradle 🏗️'
uses: gradle/gradle-build-action@v2
with:
arguments: build test publish
arguments: build publish
env:
RELEASES_MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
RELEASES_MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
- name: Query Version
run: |
echo "::set-output name=VERSION_NAME::$(${{github.workspace}}/gradlew properties --no-daemon --console=plain -q | grep "^version:" | awk '{printf $2}')"
id: fetch-version
- name: Get Version
run: |
echo "version_name=${{steps.fetch-version.outputs.VERSION_NAME}}" >> $GITHUB_ENV
- name: Upload to Modrinth & Hangar
- name: 'Publish to Modrinth & Hangar 🚰'
uses: WiIIiam278/mc-publish@hangar
with:
modrinth-id: Q10irTG0
@ -43,7 +38,7 @@ jobs:
hangar-token: ${{ secrets.HANGAR_API_KEY }}
hangar-version-type: Release
hangar-game-versions: |
3.2
3.3
files: target/Velocitab-*.jar
name: Velocitab v${{ github.event.release.tag_name }}
version: ${{ github.event.release.tag_name }}
@ -96,9 +91,11 @@ jobs:
1.20
1.20.1
1.20.2
java: 16
- name: Upload GitHub Artifact
uses: actions/upload-artifact@v2
1.20.3
1.20.4
java: 17
- name: 'Upload GitHub Artifacts 📦'
uses: actions/upload-artifact@v3
with:
name: Velocitab Plugin
name: Velocitab
path: target/Velocitab-*.jar

View File

@ -1,4 +1,3 @@
# Update the GitHub Wiki documentation when a push is made to docs/
name: Update Docs
on:
@ -17,10 +16,10 @@ jobs:
deploy-wiki:
runs-on: ubuntu-latest
steps:
- name: 'Checkout Code'
uses: actions/checkout@v3
- name: 'Push Changes to Wiki'
uses: Andrew-Chen-Wang/github-wiki-action@v3
- name: 'Checkout for CI 🛎️'
uses: actions/checkout@v4
- name: 'Push Docs to Github Wiki 📄️'
uses: Andrew-Chen-Wang/github-wiki-action@v4
env:
WIKI_DIR: 'docs/'
GH_TOKEN: ${{ github.token }}

View File

@ -1,8 +1,8 @@
<!--suppress ALL -->
<p align="center">
<img src="images/banner.png" alt="Velocitab" />
<a href="https://github.com/WiIIiam278/Velocitab/actions/workflows/java_ci.yml">
<img src="https://img.shields.io/github/actions/workflow/status/WiIIiam278/Velocitab/java_ci.yml?branch=master&logo=github"/>
<a href="https://github.com/WiIIiam278/Velocitab/actions/workflows/ci.yml">
<img src="https://img.shields.io/github/actions/workflow/status/WiIIiam278/Velocitab/ci.yml?branch=master&logo=github"/>
</a>
<a href="https://repo.william278.net/#/releases/net/william278/velocitab/">
<img src="https://repo.william278.net/api/badge/latest/releases/net/william278/velocitab?color=00fb9a&name=Maven&prefix=v" />

View File

@ -26,17 +26,25 @@ repositories {
maven { url = 'https://repo.minebench.de/' }
maven { url = 'https://maven.elytrium.net/repo/' }
maven { url = 'https://mvn.exceptionflug.de/repository/exceptionflug-public/' }
maven { url = 'https://repo.william278.net/velocity/' }
}
dependencies {
compileOnly 'com.velocitypowered:velocity-api:3.2.0-SNAPSHOT'
compileOnly 'com.velocitypowered:velocity-proxy:3.2.0-SNAPSHOT'
compileOnly ('com.velocitypowered:velocity-api:3.3.0-SNAPSHOT') {
exclude group: 'net.kyori'
}
compileOnly 'com.velocitypowered:velocity-proxy:3.3.0-SNAPSHOT'
compileOnly 'io.netty:netty-codec-http:4.1.103.Final'
compileOnly 'org.projectlombok:lombok:1.18.30'
compileOnly 'net.luckperms:api:5.4'
compileOnly 'io.github.miniplaceholders:miniplaceholders-api:2.0.0'
compileOnly 'net.william278:PAPIProxyBridge:1.4.2'
compileOnly 'it.unimi.dsi:fastutil:8.5.12'
compileOnly 'net.kyori:adventure-nbt:4.14.0'
compileOnly 'net.kyori:adventure-api:4.14.0'
compileOnly 'net.kyori:adventure-text-minimessage:4.14.0'
compileOnly 'net.kyori:adventure-text-serializer-legacy:4.14.0'
compileOnly 'net.kyori:adventure-text-serializer-gson:4.14.0'
implementation 'org.apache.commons:commons-text:1.11.0'
@ -72,6 +80,9 @@ javadoc.options.encoding = 'UTF-8'
javadoc.options.addStringOption('Xdoclint:none', '-quiet')
java {
def javaVersion = JavaVersion.toVersion(javaVersion)
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
withSourcesJar()
withJavadocJar()
}
@ -89,7 +100,6 @@ shadowJar {
relocate 'org.bstats', 'net.william278.velocitab.libraries.bstats'
dependencies {
//noinspection GroovyAssignabilityCheck
exclude dependency(':slf4j-api')
}

View File

@ -18,6 +18,7 @@ Placeholders can be included in the header, footer and player name format of the
| `%role%` | The player's primary LuckPerms group name | `admin` |
| `%role_display_name%` | The player's primary LuckPerms group display name | `Admin` |
| `%role_weight%` | Comparable-formatted primary LuckPerms group weight. | `100` |
| `%luckperms_meta_(key)%` | Formats a meta key from the user's LuckPerms group | (varies) |
| `%server_group%` | The name of the server group the player is on | `default` |
| `%server_group_index%` | Indexed order of the server group in the list | `0` |
| `%debug_team_name%` | (Debug) Player's team name, used for [[Sorting]] | `1alphaWilliam278` |

View File

@ -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.2.0 or newer)
* A Velocity proxy server (running Velocity 3.3.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

View File

@ -1,4 +1,4 @@
javaVersion=16
javaVersion=17
org.gradle.jvmargs='-Dfile.encoding=UTF-8'
org.gradle.daemon=true

View File

@ -17,7 +17,6 @@
* limitations under the License.
*/
package net.william278.velocitab.api;
import com.velocitypowered.api.proxy.Player;

View File

@ -57,9 +57,9 @@ public enum Placeholder {
SERVER_GROUP((plugin, player) -> player.getServerGroup(plugin)),
SERVER_GROUP_INDEX((plugin, player) -> Integer.toString(player.getServerGroupPosition(plugin))),
DEBUG_TEAM_NAME((plugin, player) -> plugin.getFormatter().escape(player.getLastTeamName().orElse(""))),
LUCK_PERMS_META_((param, plugin, player) -> plugin.getLuckPermsHook().map(hook -> hook.getMeta(player.getPlayer(), param))
.orElse("")),
;
LUCKPERMS_META_((param, plugin, player) -> plugin.getLuckPermsHook()
.map(hook -> hook.getMeta(player.getPlayer(), param))
.orElse(""));
/**
* Function to replace placeholders with a real value

View File

@ -1,94 +0,0 @@
/*
* This file is part of Velocitab, licensed under the Apache License 2.0.
*
* Copyright (c) William278 <will27528@gmail.com>
* Copyright (c) contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.william278.velocitab.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.william278.velocitab.Velocitab;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* Adapter for handling the UpdateTeamsPacket for Minecraft 1.12.2
*/
@SuppressWarnings("DuplicatedCode")
public class Protocol340Adapter extends TeamsPacketAdapter {
private final LegacyComponentSerializer serializer;
public Protocol340Adapter(@NotNull Velocitab plugin) {
super(plugin, Set.of(ProtocolVersion.MINECRAFT_1_12_2));
serializer = LegacyComponentSerializer.legacySection();
}
@Override
public void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) {
ProtocolUtils.writeString(byteBuf, packet.teamName().substring(0, Math.min(packet.teamName().length(), 16)));
UpdateTeamsPacket.UpdateMode mode = packet.mode();
byteBuf.writeByte(mode.id());
if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) {
return;
}
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
final String displayName = getChatString(packet.displayName());
final String prefix = getChatString(packet.prefix());
final String suffix = getChatString(packet.suffix());
ProtocolUtils.writeString(byteBuf, shrinkString(displayName));
ProtocolUtils.writeString(byteBuf, shrinkString(prefix));
ProtocolUtils.writeString(byteBuf, shrinkString(suffix));
byteBuf.writeByte(UpdateTeamsPacket.FriendlyFlag.toBitMask(packet.friendlyFlags()));
ProtocolUtils.writeString(byteBuf, packet.nametagVisibility().id());
ProtocolUtils.writeString(byteBuf, packet.collisionRule().id());
byteBuf.writeByte(packet.color());
}
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
List<String> entities = packet.entities();
ProtocolUtils.writeVarInt(byteBuf, entities != null ? entities.size() : 0);
for (String entity : entities != null ? entities : new ArrayList<String>()) {
ProtocolUtils.writeString(byteBuf, entity);
}
}
}
/**
* Returns a shortened version of the given string, with a maximum length of 16 characters.
* This is used to ensure that the team name, display name, prefix and suffix are not too long for the client.
* @param string the string to be shortened
* @return the shortened string
*/
@NotNull
private String shrinkString(@NotNull String string) {
return string.substring(0, Math.min(string.length(), 16));
}
@NotNull
@Override
protected String getChatString(@NotNull Component component) {
return serializer.serialize(component);
}
}

View File

@ -17,7 +17,6 @@
* limitations under the License.
*/
package net.william278.velocitab.packet;
import com.velocitypowered.api.network.ProtocolVersion;
@ -33,14 +32,13 @@ import java.util.List;
import java.util.Set;
/**
* Adapter for handling the UpdateTeamsPacket for Minecraft 1.13.2 - 1.15.2
* Adapter for handling the UpdateTeamsPacket for Minecraft 1.13.2-1.15.2
*/
@SuppressWarnings("DuplicatedCode")
public class Protocol404Adapter extends TeamsPacketAdapter {
private final GsonComponentSerializer serializer;
public Protocol404Adapter(@NotNull Velocitab plugin) {
super(plugin, Set.of(ProtocolVersion.MINECRAFT_1_13_2,
ProtocolVersion.MINECRAFT_1_14,
@ -55,8 +53,13 @@ public class Protocol404Adapter extends TeamsPacketAdapter {
serializer = GsonComponentSerializer.colorDownsamplingGson();
}
public Protocol404Adapter(@NotNull Velocitab plugin, Set<ProtocolVersion> protocolVersions) {
super(plugin, protocolVersions);
serializer = null;
}
@Override
public void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) {
public void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet, @NotNull ProtocolVersion protocolVersion) {
ProtocolUtils.writeString(byteBuf, packet.teamName());
UpdateTeamsPacket.UpdateMode mode = packet.mode();
byteBuf.writeByte(mode.id());
@ -64,13 +67,13 @@ public class Protocol404Adapter extends TeamsPacketAdapter {
return;
}
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
ProtocolUtils.writeString(byteBuf, getChatString(packet.displayName()));
writeComponent(byteBuf, packet.displayName());
byteBuf.writeByte(UpdateTeamsPacket.FriendlyFlag.toBitMask(packet.friendlyFlags()));
ProtocolUtils.writeString(byteBuf, packet.nametagVisibility().id());
ProtocolUtils.writeString(byteBuf, packet.collisionRule().id());
byteBuf.writeByte(packet.color());
ProtocolUtils.writeString(byteBuf, getChatString(packet.prefix()));
ProtocolUtils.writeString(byteBuf, getChatString(packet.suffix()));
writeComponent(byteBuf, packet.prefix());
writeComponent(byteBuf, packet.suffix());
}
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
List<String> entities = packet.entities();
@ -81,10 +84,8 @@ public class Protocol404Adapter extends TeamsPacketAdapter {
}
}
@NotNull
@Override
protected String getChatString(@NotNull Component component) {
return serializer.serialize(component);
protected void writeComponent(ByteBuf buf, Component component) {
ProtocolUtils.writeString(buf, serializer.serialize(component));
}
}

View File

@ -17,7 +17,6 @@
* limitations under the License.
*/
package net.william278.velocitab.packet;
import com.velocitypowered.api.network.ProtocolVersion;
@ -41,12 +40,12 @@ public class Protocol48Adapter extends TeamsPacketAdapter {
private final LegacyComponentSerializer serializer;
public Protocol48Adapter(@NotNull Velocitab plugin) {
super(plugin, Set.of(ProtocolVersion.MINECRAFT_1_8));
super(plugin, Set.of(ProtocolVersion.MINECRAFT_1_8, ProtocolVersion.MINECRAFT_1_12_2));
serializer = LegacyComponentSerializer.legacySection();
}
@Override
public void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) {
public void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet, @NotNull ProtocolVersion protocolVersion) {
ProtocolUtils.writeString(byteBuf, shrinkString(packet.teamName()));
UpdateTeamsPacket.UpdateMode mode = packet.mode();
byteBuf.writeByte(mode.id());
@ -54,15 +53,14 @@ public class Protocol48Adapter extends TeamsPacketAdapter {
return;
}
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
final String displayName = getChatString(packet.displayName());
final String prefix = getChatString(packet.prefix());
final String suffix = getChatString(packet.suffix());
ProtocolUtils.writeString(byteBuf, shrinkString(displayName));
ProtocolUtils.writeString(byteBuf, shrinkString(prefix));
ProtocolUtils.writeString(byteBuf, shrinkString(suffix));
writeComponent(byteBuf, packet.displayName());
writeComponent(byteBuf, packet.prefix());
writeComponent(byteBuf, packet.suffix());
byteBuf.writeByte(UpdateTeamsPacket.FriendlyFlag.toBitMask(packet.friendlyFlags()));
ProtocolUtils.writeString(byteBuf, packet.nametagVisibility().id());
if (protocolVersion.compareTo(ProtocolVersion.MINECRAFT_1_12_2) >= 0) {
ProtocolUtils.writeString(byteBuf, packet.collisionRule().id());
}
byteBuf.writeByte(packet.color());
}
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
@ -85,9 +83,7 @@ public class Protocol48Adapter extends TeamsPacketAdapter {
return string.substring(0, Math.min(string.length(), 16));
}
@NotNull
@Override
protected String getChatString(@NotNull Component component) {
return serializer.serialize(component);
protected void writeComponent(ByteBuf buf, Component component) {
ProtocolUtils.writeString(buf, shrinkString(serializer.serialize(component)));
}
}

View File

@ -17,7 +17,6 @@
* limitations under the License.
*/
package net.william278.velocitab.packet;
import com.velocitypowered.api.network.ProtocolVersion;
@ -28,15 +27,12 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.william278.velocitab.Velocitab;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
/**
* Adapter for handling the UpdateTeamsPacket for Minecraft 1.16 - 1.20.2
* Adapter for handling the UpdateTeamsPacket for Minecraft 1.16-1.20.2
*/
@SuppressWarnings("DuplicatedCode")
public class Protocol735Adapter extends TeamsPacketAdapter {
public class Protocol735Adapter extends Protocol404Adapter {
private final GsonComponentSerializer serializer;
@ -62,35 +58,8 @@ public class Protocol735Adapter extends TeamsPacketAdapter {
}
@Override
public void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet) {
ProtocolUtils.writeString(byteBuf, packet.teamName());
UpdateTeamsPacket.UpdateMode mode = packet.mode();
byteBuf.writeByte(mode.id());
if (mode == UpdateTeamsPacket.UpdateMode.REMOVE_TEAM) {
return;
}
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.UPDATE_INFO) {
ProtocolUtils.writeString(byteBuf, getChatString(packet.displayName()));
byteBuf.writeByte(UpdateTeamsPacket.FriendlyFlag.toBitMask(packet.friendlyFlags()));
ProtocolUtils.writeString(byteBuf, packet.nametagVisibility().id());
ProtocolUtils.writeString(byteBuf, packet.collisionRule().id());
byteBuf.writeByte(packet.color());
ProtocolUtils.writeString(byteBuf, getChatString(packet.prefix()));
ProtocolUtils.writeString(byteBuf, getChatString(packet.suffix()));
}
if (mode == UpdateTeamsPacket.UpdateMode.CREATE_TEAM || mode == UpdateTeamsPacket.UpdateMode.ADD_PLAYERS || mode == UpdateTeamsPacket.UpdateMode.REMOVE_PLAYERS) {
List<String> entities = packet.entities();
ProtocolUtils.writeVarInt(byteBuf, entities != null ? entities.size() : 0);
for (String entity : entities != null ? entities : new ArrayList<String>()) {
ProtocolUtils.writeString(byteBuf, entity);
}
}
protected void writeComponent(ByteBuf buf, Component component) {
ProtocolUtils.writeString(buf, serializer.serialize(component));
}
@NotNull
@Override
protected String getChatString(@NotNull Component component) {
return serializer.serialize(component);
}
}
}

View File

@ -0,0 +1,46 @@
/*
* This file is part of Velocitab, licensed under the Apache License 2.0.
*
* Copyright (c) William278 <will27528@gmail.com>
* Copyright (c) contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.william278.velocitab.packet;
import com.velocitypowered.api.network.ProtocolVersion;
import com.velocitypowered.proxy.protocol.packet.chat.ComponentHolder;
import io.netty.buffer.ByteBuf;
import net.kyori.adventure.text.Component;
import net.william278.velocitab.Velocitab;
import org.jetbrains.annotations.NotNull;
import java.util.Set;
/**
* Adapter for handling the UpdateTeamsPacket for Minecraft 1.20.3-1.20.4
*/
public class Protocol765Adapter extends Protocol404Adapter {
public Protocol765Adapter(@NotNull Velocitab plugin) {
super(plugin, Set.of(
ProtocolVersion.MINECRAFT_1_20_3
));
}
protected void writeComponent(ByteBuf buf, Component component) {
new ComponentHolder(ProtocolVersion.MINECRAFT_1_20_3, component).write(buf);
}
}

View File

@ -53,10 +53,14 @@ public class ScoreboardManager {
}
private void registerVersions() {
versions.add(new Protocol735Adapter(plugin));
versions.add(new Protocol404Adapter(plugin));
versions.add(new Protocol340Adapter(plugin));
versions.add(new Protocol48Adapter(plugin));
try {
versions.add(new Protocol765Adapter(plugin));
versions.add(new Protocol735Adapter(plugin));
versions.add(new Protocol404Adapter(plugin));
versions.add(new Protocol48Adapter(plugin));
} catch (NoSuchFieldError e) {
throw new IllegalStateException("Failed to register scoreboard packet adapters. Try to update velocity to latest build", e);
}
}
@NotNull
@ -282,7 +286,8 @@ public class ScoreboardManager {
.mapping(0x58, MINECRAFT_1_19_1, true)
.mapping(0x56, MINECRAFT_1_19_3, true)
.mapping(0x5A, MINECRAFT_1_19_4, true)
.mapping(0x5C, MINECRAFT_1_20_2, true);
.mapping(0x5C, MINECRAFT_1_20_2, true)
.mapping(0x5E, MINECRAFT_1_20_3, true);
packetRegistration.register();
} catch (Throwable e) {
plugin.log(Level.ERROR, "Failed to register UpdateTeamsPacket", e);

View File

@ -17,7 +17,6 @@
* limitations under the License.
*/
package net.william278.velocitab.packet;
import com.velocitypowered.api.network.ProtocolVersion;
@ -37,9 +36,8 @@ public abstract class TeamsPacketAdapter {
private final Velocitab plugin;
private final Set<ProtocolVersion> protocolVersions;
public abstract void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet);
public abstract void encode(@NotNull ByteBuf byteBuf, @NotNull UpdateTeamsPacket packet, @NotNull ProtocolVersion protocolVersion);
@NotNull
protected abstract String getChatString(@NotNull Component component);
protected abstract void writeComponent(ByteBuf buf, Component component);
}

View File

@ -202,7 +202,7 @@ public class UpdateTeamsPacket implements MinecraftPacket {
if (optionalManager.isEmpty()) {
return;
}
optionalManager.get().getPacketAdapter(protocolVersion).encode(byteBuf, this);
optionalManager.get().getPacketAdapter(protocolVersion).encode(byteBuf, this, protocolVersion);
}
@Override

View File

@ -196,7 +196,7 @@ public final class TabPlayer implements Comparable<TabPlayer> {
}
/**
* Represents a nametag to be displayed above a player, with prefix & suffix
* Represents a nametag to be displayed above a player, with prefix and suffix
*/
@Getter
@AllArgsConstructor