Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6efeb16822 | ||
|
|
9b09b1f5f8 | ||
|
|
851295d48c | ||
|
|
1f453dc0d9 | ||
|
|
916c08ce7e | ||
|
|
0ac29fb2c2 | ||
|
|
45d08e9066 | ||
|
|
bc0bef2e07 | ||
|
|
6d82839e6d | ||
|
|
c039f4e24c | ||
|
|
4add75cda7 | ||
|
|
28f661f270 | ||
|
|
42f38c3209 | ||
|
|
151ecdcd72 | ||
|
|
a0f8ab7bbb | ||
|
|
1af2103f6c | ||
|
|
8769742917 | ||
|
|
20f4907a23 | ||
|
|
6fb27e5c17 | ||
|
|
07b173bb74 | ||
|
|
dbf4271c9d | ||
|
|
a2d287ff9f | ||
|
|
58ca2024e1 | ||
|
|
2881fb18e0 | ||
|
|
ffdddeeb0a | ||
|
|
e356a35aa7 | ||
|
|
0474810b8d | ||
|
|
ea818b272e | ||
|
|
9342b19aad | ||
|
|
2968047571 | ||
|
|
dccac81286 | ||
|
|
bc67e8d952 | ||
|
|
f9ab1bd811 | ||
|
|
8776e8bdc0 | ||
|
|
ba882f8f98 | ||
|
|
a022620712 | ||
|
|
f618cdec99 | ||
|
|
ec2093cf5d | ||
|
|
eb9bc2fdce | ||
|
|
f35b4f1fac | ||
|
|
abe880dae6 | ||
|
|
0f030c86a7 | ||
|
|
2c6e18e4fe | ||
|
|
78c7f03923 | ||
|
|
68a32ed2f0 | ||
|
|
7cf008bb62 | ||
|
|
a60342359b | ||
|
|
0e269fa493 | ||
|
|
815e0820da | ||
|
|
faedf26b5b | ||
|
|
c7c38e70c0 | ||
|
|
21d293dd7f | ||
|
|
6481cec270 | ||
|
|
54c04a62e0 | ||
|
|
7edde72416 | ||
|
|
84a054aac1 | ||
|
|
8ebc8c34f3 | ||
|
|
50e55529d9 | ||
|
|
553dd2cb45 | ||
|
|
a30d62a995 | ||
|
|
08f6b3ce36 | ||
|
|
7d1b0d83ce | ||
|
|
e7d0b01eee | ||
|
|
fdfc528a9a | ||
|
|
dccb6f234b | ||
|
|
6e7f936e83 | ||
|
|
ec26bafd53 | ||
|
|
d7d7940d0b | ||
|
|
667278f9e6 | ||
|
|
fa7096c5c1 | ||
|
|
958064b44c | ||
|
|
26dad99265 | ||
|
|
d8007dc73c | ||
|
|
5850a9852d | ||
|
|
095fe16447 | ||
|
|
cbf8b8f401 | ||
|
|
d600b0cbe1 | ||
|
|
0d70cdbe15 | ||
|
|
b1b0874c0f | ||
|
|
67ba0e9566 | ||
|
|
bebdc34b4b | ||
|
|
3e0eb90662 | ||
|
|
d8f98945e2 | ||
|
|
0c3d709456 | ||
|
|
868c5ba203 | ||
|
|
0953ff77e4 | ||
|
|
c211b10eaa | ||
|
|
def3bf9d4a | ||
|
|
cb1b33b3e7 | ||
|
|
a8acae2d5f | ||
|
|
fdb7f47749 | ||
|
|
cabb95a3a4 | ||
|
|
0b93af88a3 | ||
|
|
11cb113619 | ||
|
|
429e4f0bff | ||
|
|
3b0d1d961a | ||
|
|
b4720c723a | ||
|
|
215cbc6310 | ||
|
|
f07ba9b527 | ||
|
|
5a20030ff3 | ||
|
|
1b350c0c53 | ||
|
|
87db6fc75a | ||
|
|
840770a350 | ||
|
|
3997ea70f7 | ||
|
|
854696abff | ||
|
|
d92b9fdeaa | ||
|
|
270d28f259 | ||
|
|
ed1852ba40 | ||
|
|
f91e6a83f9 | ||
|
|
8a0e187621 | ||
|
|
0e8b5e8e98 | ||
|
|
e30dd63b3c | ||
|
|
489b28e520 | ||
|
|
d23e743550 | ||
|
|
16f89f2638 | ||
|
|
fe5646a68c | ||
|
|
53aca791dd | ||
|
|
1f0a4c26db | ||
|
|
4c34ced240 | ||
|
|
18c4f90cb0 | ||
|
|
9c90445c9c | ||
|
|
494e6ffc05 | ||
|
|
a196dbc16b | ||
|
|
8934bbdfc3 | ||
|
|
8316c59010 | ||
|
|
5ea1c1ec95 | ||
|
|
cc7c571a3c | ||
|
|
06b4678b2d | ||
|
|
a109118a97 | ||
|
|
a135a1414c | ||
|
|
f50751ed48 | ||
|
|
4b7998b4ea | ||
|
|
6db1a2a614 | ||
|
|
625373827c | ||
|
|
a9288ebd3a | ||
|
|
01bbb2c1c2 | ||
|
|
8dbc8e8eba | ||
|
|
0c9f3aa080 | ||
|
|
00625be890 | ||
|
|
e112f81ec8 | ||
|
|
23f776a6ee | ||
|
|
0050872950 | ||
|
|
7e53f55509 | ||
|
|
1bf7962dc3 | ||
|
|
50176dc317 | ||
|
|
9ed074d0d5 | ||
|
|
8bad8a10be | ||
|
|
34509e86c0 | ||
|
|
ef75bd567d | ||
|
|
7ed3e50e93 | ||
|
|
a45eceaf1d | ||
|
|
573cdfb3ac | ||
|
|
28787340d1 | ||
|
|
c358245c0b | ||
|
|
cb073405b7 | ||
|
|
f618f6a7d6 | ||
|
|
c5e066e050 | ||
|
|
d954e1745d | ||
|
|
9c92ccea77 | ||
|
|
2b9e0cec5c | ||
|
|
c1cd8bc03e | ||
|
|
39efc5262e | ||
|
|
6e5e115c3b | ||
|
|
fbcbd33c66 | ||
|
|
7bea3142bc | ||
|
|
fb472c3454 | ||
|
|
ac10bb3fd0 | ||
|
|
1bc3d407d1 | ||
|
|
62c0ef360f | ||
|
|
8c6d104faa | ||
|
|
f6b8c4a8c8 | ||
|
|
6586fc1436 | ||
|
|
6dfd4747ee | ||
|
|
6377721ebd | ||
|
|
2ec6185c46 | ||
|
|
b22907748a | ||
|
|
1aee8a7a6c | ||
|
|
7edb43844c | ||
|
|
f28aac5eb3 | ||
|
|
4971eeab6a | ||
|
|
0bb940e42d | ||
|
|
e32933ada9 | ||
|
|
a817746edc | ||
|
|
408392e796 | ||
|
|
20a4ae3e4b | ||
|
|
08b2d78165 | ||
|
|
17eb7b676a | ||
|
|
9a1598b9ed | ||
|
|
9e7cd151bc | ||
|
|
2a14f9a0cd | ||
|
|
bf825d5ef6 | ||
|
|
28ba4afc27 | ||
|
|
7f347231bb | ||
|
|
f1b5f9223a | ||
|
|
e4a1530aa8 | ||
|
|
09b67fad63 | ||
|
|
1b3c5b4032 | ||
|
|
b7d8a3c8d5 | ||
|
|
9a515df0f3 | ||
|
|
c6103f2f51 | ||
|
|
5c0eda76e8 | ||
|
|
544a28b06b | ||
|
|
5c145d0184 | ||
|
|
ed55bccfe4 | ||
|
|
5acc2fefbc | ||
|
|
7f748b5c68 | ||
|
|
0ec03f8b09 | ||
|
|
a70034e0b5 | ||
|
|
98a0fdca94 | ||
|
|
82961cc153 | ||
|
|
6c0d891c9f | ||
|
|
6fa387e6ab | ||
|
|
07bdb57694 | ||
|
|
75dd79347a | ||
|
|
9257890d3c | ||
|
|
891f55192d | ||
|
|
7adadc0d21 | ||
|
|
638378cddf | ||
|
|
56d772df34 | ||
|
|
7bb5cf3ae9 | ||
|
|
b67e3c30fd | ||
|
|
a2e214ae18 | ||
|
|
54d8e29a7e | ||
|
|
a2daa9c989 | ||
|
|
74cc42fecf | ||
|
|
dd59ddbd4f | ||
|
|
bcfc77aa7d | ||
|
|
1a46346789 | ||
|
|
394be165fd | ||
|
|
20d86374b5 | ||
|
|
8864b161f9 | ||
|
|
7b0160d6c3 | ||
|
|
7e5173982d | ||
|
|
ee75f19790 | ||
|
|
e54f6d1999 | ||
|
|
c46bb5bcf5 | ||
|
|
d08f15c095 | ||
|
|
8aa7898755 | ||
|
|
9682b68251 | ||
|
|
364cfad9d8 | ||
|
|
641171a14f | ||
|
|
23f045feee | ||
|
|
f1bde8ba2a | ||
|
|
9ccc3aed30 | ||
|
|
ad56caeb88 | ||
|
|
573201c0b1 | ||
|
|
e298a7efac | ||
|
|
2e59a51734 | ||
|
|
d4894ca4b5 | ||
|
|
7f7c6241de | ||
|
|
51606eb5ef | ||
|
|
c9883c2638 | ||
|
|
74fb55d96b | ||
|
|
4e844a0095 | ||
|
|
da7f8ea3b6 | ||
|
|
81c4e530e9 | ||
|
|
b1524642aa | ||
|
|
a828c43f99 | ||
|
|
fccfadf1b7 | ||
|
|
18b41c82c4 | ||
|
|
27ee6f519e |
No files matched your search
@@ -71,7 +71,7 @@ body:
|
||||
attributes:
|
||||
label: Additional Server Info
|
||||
description: |
|
||||
Do you use a proxy (eg. BungeeCord)? What software do you use and what plugins?
|
||||
Do you use a proxy (e.g. BungeeCord)? What software do you use and what plugins?
|
||||
placeholder: |
|
||||
Example: "I also use BungeeCord with the following plugins: x, y, z"
|
||||
validations:
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
# This workflow will build a Java project with Gradle
|
||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle
|
||||
|
||||
name: Java CI with Gradle
|
||||
|
||||
on: [push, pull_request]
|
||||
@@ -13,16 +10,15 @@ jobs:
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: gradle/wrapper-validation-action@v1
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Validate Gradle Wrapper
|
||||
uses: gradle/wrapper-validation-action@v1
|
||||
- name: Set up JDK 11
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 11
|
||||
check-latest: true
|
||||
- name: Build with Gradle
|
||||
run: ./gradlew build
|
||||
- uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: artifact
|
||||
path: build/libs
|
||||
@@ -0,0 +1,27 @@
|
||||
name: Publish to Hangar and Modrinth
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- dev
|
||||
|
||||
jobs:
|
||||
publish:
|
||||
if: github.repository_owner == 'ViaVersion'
|
||||
runs-on: ubuntu-22.04
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Validate Gradle Wrapper
|
||||
uses: gradle/wrapper-validation-action@v1
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: 17
|
||||
check-latest: true
|
||||
- name: Publish
|
||||
env:
|
||||
HANGAR_TOKEN: ${{ secrets.HANGAR_TOKEN }}
|
||||
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
|
||||
run: ./gradlew build modrinth publishAllPublicationsToHangar --stacktrace
|
||||
@@ -1,49 +1,41 @@
|
||||
# ViaVersion - Spigot, Sponge, BungeeCord, Velocity
|
||||
# ViaVersion
|
||||
|
||||
[](https://viaversion.com)
|
||||
[](https://github.com/ViaVersion/ViaVersion/actions)
|
||||
[](https://viaversion.com/discord)
|
||||
|
||||
**Allows the connection of higher client versions to lower server versions**
|
||||
**Allows the connection of higher client versions to lower server versions -
|
||||
it works on any platform you can think of.**
|
||||
|
||||
The base ViaVersion jar runs on Paper, Velocity, Bungee, and Sponge. We also have projects integrating ViaVersion to run
|
||||
on Fabric, Forge, or as a standalone proxy to join from basically any client version on any server version from the
|
||||
past decade. **See [HERE](https://github.com/ViaVersion) for an overview of the different Via\* projects.**
|
||||
|
||||
Supported Versions:
|
||||
|
||||

|
||||
|
||||
On Paper you may also use ProtocolSupport, but ensure you have the right build for your server version.
|
||||

|
||||
|
||||
**User Docs:** https://docs.viaversion.com/display/VIAVERSION/
|
||||
|
||||
|
||||
Sources
|
||||
Releases/Dev Builds
|
||||
--------
|
||||
**[OpenNBT](https://github.com/ViaVersion/OpenNBT)**
|
||||
You can find official releases in the following places:
|
||||
|
||||
**[Via Mappings Generator](https://github.com/ViaVersion/Mappings)**
|
||||
- **Hangar (for our plugins)**: https://hangar.papermc.io/ViaVersion/ViaVersion
|
||||
- **Modrinth (for our mods)**: https://modrinth.com/mod/viaversion
|
||||
- **GitHub**: https://github.com/ViaVersion/ViaVersion/releases
|
||||
|
||||
**[Mojang mappings](https://minecraft.fandom.com/wiki/Obfuscation_map)** (Thank you, Mojang, very cool)
|
||||
Dev builds for **all** of our projects are on our Jenkins server:
|
||||
|
||||
**[wiki.vg](https://wiki.vg)** (Used for historic information regarding packet structure, we also contribute back)
|
||||
|
||||
**[Burger](https://github.com/Pokechu22/Burger)** (See [PAaaS](https://github.com/Matsv/Paaas))
|
||||
|
||||
|
||||
|
||||
Releases / Dev Builds
|
||||
--------
|
||||
You can find official releases here:
|
||||
|
||||
https://www.spigotmc.org/resources/viaversion.19254/history
|
||||
- **Jenkins**: https://ci.viaversion.com
|
||||
|
||||
ViaVersion as a Dependency
|
||||
----------
|
||||
|
||||
You can find official dev builds here:
|
||||
|
||||
**Jenkins:** https://ci.viaversion.com
|
||||
|
||||
**JavaDocs:** https://jd.viaversion.com
|
||||
|
||||
**Maven Repository:**
|
||||
**Maven:**
|
||||
|
||||
```xml
|
||||
<repository>
|
||||
<id>viaversion-repo</id>
|
||||
@@ -51,7 +43,6 @@ You can find official dev builds here:
|
||||
</repository>
|
||||
```
|
||||
|
||||
**API-artifact:**
|
||||
```xml
|
||||
<dependency>
|
||||
<groupId>com.viaversion</groupId>
|
||||
@@ -61,7 +52,17 @@ You can find official dev builds here:
|
||||
</dependency>
|
||||
```
|
||||
|
||||
Replace the version depending on your needs.
|
||||
**Gradle:**
|
||||
|
||||
```kotlin
|
||||
repositories {
|
||||
maven("https://repo.viaversion.com")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("com.viaversion:viaversion-api:VERSION") // Replace the version
|
||||
}
|
||||
```
|
||||
|
||||
If you need access to the existing protocol or platform implementations, use the parent artifact `viaversion`.
|
||||
Please note the [differences in licensing](#license).
|
||||
@@ -69,8 +70,8 @@ Please note the [differences in licensing](#license).
|
||||
|
||||
Building
|
||||
--------
|
||||
After cloning this repository, build the project with Gradle by running `./gradlew build` and take the created jar out of
|
||||
the `build/libs` directory.
|
||||
After cloning this repository, build the project with Gradle by running `./gradlew build` and take the created jar out
|
||||
of the `build/libs` directory.
|
||||
|
||||
|
||||
Mapping Files
|
||||
@@ -78,12 +79,21 @@ Mapping Files
|
||||
Mapping files are generated and managed in our [Mappings repository](https://github.com/ViaVersion/Mappings).
|
||||
|
||||
|
||||
Resources
|
||||
--------
|
||||
|
||||
- **[Via Mappings Generator](https://github.com/ViaVersion/Mappings)**
|
||||
- **[Mojang mappings](https://minecraft.wiki/w/Obfuscation_map)** (Thank you, Mojang, very cool)
|
||||
- **[wiki.vg](https://wiki.vg)** (Used for historic information regarding packet structure, we also contribute back)
|
||||
- **[Burger](https://github.com/Pokechu22/Burger)** (See [PAaaS](https://github.com/Matsv/Paaas))
|
||||
|
||||
License
|
||||
--------
|
||||
The entirety of the [API directory](api) (including the legacy API directory) is licensed under the MIT License; see [licenses/MIT.md](licenses/MIT.md) for
|
||||
The entirety of the [API directory](api) (including the legacy API directory) is licensed under the MIT License;
|
||||
see [licenses/MIT.md](licenses/MIT.md) for
|
||||
details.
|
||||
|
||||
Everything else, unless explicitly stated otherwise, is licensed under the GNU General Public License, including the end
|
||||
product as a whole; see [licenses/GPL.md](licenses/GPL.md) for details.
|
||||
Everything else, unless explicitly stated otherwise, is licensed under the GNU General Public License v3, including the
|
||||
end-product as a whole; see [licenses/GPL.md](licenses/GPL.md) for details.
|
||||
|
||||
Special thanks to all our [Contributors](https://github.com/ViaVersion/ViaVersion/graphs/contributors).
|
||||
@@ -83,8 +83,12 @@ public class ProtocolVersion {
|
||||
public static final ProtocolVersion v1_18 = register(757, "1.18/1.18.1", new VersionRange("1.18", 0, 1));
|
||||
public static final ProtocolVersion v1_18_2 = register(758, "1.18.2");
|
||||
public static final ProtocolVersion v1_19 = register(759, "1.19");
|
||||
public static final ProtocolVersion v1_19_1 = register(760, "1.19.1");
|
||||
public static final ProtocolVersion v1_19_1 = register(760, "1.19.1/2", new VersionRange("1.19", 1, 2));
|
||||
public static final ProtocolVersion v1_19_3 = register(761, "1.19.3");
|
||||
public static final ProtocolVersion v1_19_4 = register(762, "1.19.4");
|
||||
public static final ProtocolVersion v1_20 = register(763, "1.20/1.20.1", new VersionRange("1.20", 0, 1));
|
||||
public static final ProtocolVersion v1_20_2 = register(764, "1.20.2");
|
||||
public static final ProtocolVersion v1_20_3 = register(765, "1.20.3");
|
||||
public static final ProtocolVersion unknown = register(-1, "UNKNOWN");
|
||||
|
||||
public static ProtocolVersion register(int version, String name) {
|
||||
|
||||
+13
-5
@@ -1,11 +1,17 @@
|
||||
plugins {
|
||||
id("net.kyori.blossom")
|
||||
id("via.shadow-conventions")
|
||||
id("org.jetbrains.gradle.plugin.idea-ext")
|
||||
}
|
||||
|
||||
blossom {
|
||||
replaceToken("\$VERSION", project.version)
|
||||
replaceToken("\$IMPL_VERSION", "git-ViaVersion-${project.version}:${rootProject.latestCommitHash()}")
|
||||
sourceSets {
|
||||
main {
|
||||
blossom {
|
||||
javaSources {
|
||||
property("version", project.version.toString())
|
||||
property("impl_version", "git-ViaVersion-${project.version}:${rootProject.latestCommitHash()}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -15,7 +21,7 @@ dependencies {
|
||||
api(libs.fastutil)
|
||||
api(libs.flare)
|
||||
api(libs.flareFastutil)
|
||||
api(libs.openNBT)
|
||||
api(libs.vianbt)
|
||||
api(libs.gson)
|
||||
|
||||
compileOnlyApi(libs.snakeYaml)
|
||||
@@ -27,3 +33,5 @@ dependencies {
|
||||
java {
|
||||
withJavadocJar()
|
||||
}
|
||||
|
||||
publishShadowJar()
|
||||
+10
-1
@@ -31,5 +31,14 @@ public final class VersionInfo {
|
||||
*
|
||||
* @see ViaPlatform#getPluginVersion()
|
||||
*/
|
||||
public static final String VERSION = "$VERSION";
|
||||
public static final String VERSION = "{{ version }}";
|
||||
private static final String IMPLEMENTATION_VERSION = "{{ impl_version }}";
|
||||
|
||||
public static String getVersion() {
|
||||
return VERSION;
|
||||
}
|
||||
|
||||
public static String getImplementationVersion() {
|
||||
return IMPLEMENTATION_VERSION;
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public interface ViaAPI<T> {
|
||||
* @return API version incremented with meaningful API changes
|
||||
*/
|
||||
default int apiVersion() {
|
||||
return 19;
|
||||
return 22;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,7 +117,7 @@ public interface ViaAPI<T> {
|
||||
* Sends a raw packet to the player.
|
||||
*
|
||||
* @param player the platform's player object, e.g. for Bukkit this is Player
|
||||
* @param packet the packet; you need a VarInt Id, then the packet contents
|
||||
* @param packet the packet; you need a VarInt id, then the packet contents
|
||||
* @throws IllegalArgumentException if the player is not injected by Via
|
||||
*/
|
||||
void sendRawPacket(T player, ByteBuf packet);
|
||||
@@ -126,7 +126,7 @@ public interface ViaAPI<T> {
|
||||
* Sends a raw packet to the player.
|
||||
*
|
||||
* @param uuid the uuid from the player to send packet
|
||||
* @param packet the packet; you need a VarInt Id, then the packet contents
|
||||
* @param packet the packet; you need a VarInt id, then the packet contents
|
||||
* @throws IllegalArgumentException if the player is not injected by Via
|
||||
*/
|
||||
void sendRawPacket(UUID uuid, ByteBuf packet);
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
package com.viaversion.viaversion.api;
|
||||
|
||||
import com.viaversion.viaversion.api.command.ViaVersionCommand;
|
||||
import com.viaversion.viaversion.api.configuration.ConfigurationProvider;
|
||||
import com.viaversion.viaversion.api.connection.ConnectionManager;
|
||||
import com.viaversion.viaversion.api.debug.DebugHandler;
|
||||
import com.viaversion.viaversion.api.platform.ViaInjector;
|
||||
@@ -91,6 +92,13 @@ public interface ViaManager {
|
||||
*/
|
||||
Scheduler getScheduler();
|
||||
|
||||
/**
|
||||
* Returns the configuration provider.
|
||||
*
|
||||
* @return the configuration provider
|
||||
*/
|
||||
ConfigurationProvider getConfigurationProvider();
|
||||
|
||||
/**
|
||||
* If debug is enabled, packets and other otherwise suppressed warnings will be logged.
|
||||
*
|
||||
@@ -131,4 +139,12 @@ public interface ViaManager {
|
||||
* @param runnable runnable to be executed
|
||||
*/
|
||||
void addEnableListener(Runnable runnable);
|
||||
|
||||
/**
|
||||
* Returns whether the manager has been initialized (and protocols have been loaded).
|
||||
*
|
||||
* @return whether the manager has been initialized
|
||||
*/
|
||||
boolean isInitialized();
|
||||
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public interface ViaCommandSender {
|
||||
/**
|
||||
* Check if the sender has a permission.
|
||||
*
|
||||
* @param permission Permission string eg. viaversion.admin
|
||||
* @param permission Permission string e.g. viaversion.admin
|
||||
* @return True if the sender has the permission
|
||||
*/
|
||||
boolean hasPermission(String permission);
|
||||
|
||||
@@ -58,7 +58,7 @@ public abstract class ViaSubCommand {
|
||||
* @return The permission required to use the commands
|
||||
*/
|
||||
public String permission() {
|
||||
return "viaversion.admin";
|
||||
return "viaversion.admin." + name();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -32,7 +32,7 @@ public interface ViaVersionCommand {
|
||||
* @param command Your own SubCommand instance to handle it.
|
||||
* @throws Exception throws an exception when the subcommand already exists or if it's not valid, example: spacee
|
||||
*/
|
||||
void registerSubCommand(ViaSubCommand command) throws Exception;
|
||||
void registerSubCommand(ViaSubCommand command);
|
||||
|
||||
/**
|
||||
* Check if a subcommand is registered.
|
||||
|
||||
+25
-14
@@ -20,23 +20,34 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type.types.minecraft;
|
||||
package com.viaversion.viaversion.api.configuration;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class BaseChunkType extends Type<Chunk> {
|
||||
public interface Config {
|
||||
|
||||
protected BaseChunkType() {
|
||||
super(Chunk.class);
|
||||
}
|
||||
/**
|
||||
* Reloads the config
|
||||
*/
|
||||
void reload();
|
||||
|
||||
protected BaseChunkType(String typeName) {
|
||||
super(typeName, Chunk.class);
|
||||
}
|
||||
/**
|
||||
* Saves the config
|
||||
*/
|
||||
void save();
|
||||
|
||||
@Override
|
||||
public Class<? extends Type> getBaseClass() {
|
||||
return BaseChunkType.class;
|
||||
}
|
||||
/**
|
||||
* Sets the specified path to the given value.
|
||||
*
|
||||
* @param path Path of the object to set.
|
||||
* @param value New value to set the path to
|
||||
*/
|
||||
void set(String path, Object value);
|
||||
|
||||
/**
|
||||
* Get all the configuration values
|
||||
*
|
||||
* @return Map with key-values
|
||||
*/
|
||||
Map<String, Object> getValues();
|
||||
}
|
||||
+12
-18
@@ -22,32 +22,26 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.configuration;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
|
||||
public interface ConfigurationProvider {
|
||||
|
||||
/**
|
||||
* Sets the specified path to the given value.
|
||||
* Registers a config to be saved or reloaded when {@link #reloadConfigs()} is called.
|
||||
*
|
||||
* @param path Path of the object to set.
|
||||
* @param value New value to set the path to
|
||||
* @param config the config to register
|
||||
*/
|
||||
void set(String path, Object value);
|
||||
void register(Config config);
|
||||
|
||||
/**
|
||||
* Saves the config
|
||||
*/
|
||||
void saveConfig();
|
||||
|
||||
/**
|
||||
* Reloads the config
|
||||
*/
|
||||
void reloadConfig();
|
||||
|
||||
/**
|
||||
* Get all the configuration values
|
||||
* Returns all registered configs.
|
||||
*
|
||||
* @return Map with key-values
|
||||
* @return unmodifiable collection of all registered configs
|
||||
*/
|
||||
Map<String, Object> getValues();
|
||||
Collection<Config> configs();
|
||||
|
||||
/**
|
||||
* Reloads the configuration files.
|
||||
*/
|
||||
void reloadConfigs();
|
||||
}
|
||||
+17
-7
@@ -30,7 +30,7 @@ import com.viaversion.viaversion.api.protocol.version.BlockedProtocolVersions;
|
||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public interface ViaVersionConfig {
|
||||
public interface ViaVersionConfig extends Config {
|
||||
|
||||
/**
|
||||
* Get if the plugin should check for updates
|
||||
@@ -87,7 +87,7 @@ public interface ViaVersionConfig {
|
||||
* <p>
|
||||
* This option requires {@link #isShowShieldWhenSwordInHand()} to be disabled
|
||||
*
|
||||
* @return {@code true} if non delayed shield blocking is enabled.
|
||||
* @return {@code true} if non-delayed shield blocking is enabled.
|
||||
*/
|
||||
boolean isNoDelayShieldBlocking();
|
||||
|
||||
@@ -126,7 +126,7 @@ public interface ViaVersionConfig {
|
||||
* Get if the boss bars for 1.9 & 1.10 clients are being stopped from flickering
|
||||
* This will keep all boss bars on 100% (not recommended)
|
||||
*
|
||||
* @return true if boss bar anti flickering is enabled
|
||||
* @return true if boss bar anti-flickering is enabled
|
||||
*/
|
||||
boolean isBossbarAntiflicker();
|
||||
|
||||
@@ -256,6 +256,8 @@ public interface ViaVersionConfig {
|
||||
*/
|
||||
boolean is1_13TeamColourFix();
|
||||
|
||||
boolean shouldRegisterUserConnectionOnJoin();
|
||||
|
||||
/**
|
||||
* Should we fix shift quick move action for 1.12 clients
|
||||
*
|
||||
@@ -382,7 +384,7 @@ public interface ViaVersionConfig {
|
||||
boolean isTruncate1_14Books();
|
||||
|
||||
/**
|
||||
* Handles left handed info by using unused bit 7 on Client Settings packet
|
||||
* Handles left-handed info by using unused bit 7 on Client Settings packet
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
@@ -441,16 +443,24 @@ public interface ViaVersionConfig {
|
||||
|
||||
/***
|
||||
* Get the world names that should be returned for each Vanilla dimension.
|
||||
* Note that this can be overriden per-user by using {@link UserConnection#put(StorableObject)} with
|
||||
* Note that this can be overridden per-user by using {@link UserConnection#put(StorableObject)} with
|
||||
* a custom instance of {@link WorldIdentifiers} for the user's {@link UserConnection}.
|
||||
*
|
||||
* @return the global map from vanilla dimensions to world name
|
||||
*/
|
||||
WorldIdentifiers get1_16WorldNamesMap();
|
||||
|
||||
/**
|
||||
* Caches light until chunks are unloaded to allow subsequent chunk update packets as opposed to instantly uncaching when the first chunk data is sent.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean cache1_17Light();
|
||||
|
||||
@Nullable String chatTypeFormat(String translationKey);
|
||||
|
||||
/**
|
||||
* Force-update 1.19.4+ player's inventory when they try to swap armor in a pre-occupied slot.
|
||||
*
|
||||
* @return true if enabled
|
||||
*/
|
||||
boolean isArmorToggleFix();
|
||||
}
|
||||
@@ -65,7 +65,7 @@ public interface ConnectionManager {
|
||||
|
||||
/**
|
||||
* Returns the UUID from the frontend connection to this proxy server
|
||||
* Returns null when there isn't a server or this connection isn't frontend or it doesn't have an id
|
||||
* Returns null when there isn't a server or this connection isn't frontend, or it doesn't have an id
|
||||
* When ViaVersion is reloaded, this method may not return some players.
|
||||
* May not return ProtocolSupport players.
|
||||
* <p>
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
package com.viaversion.viaversion.api.connection;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.ProtocolPipeline;
|
||||
import com.viaversion.viaversion.api.protocol.packet.Direction;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import java.util.UUID;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -33,10 +34,63 @@ public interface ProtocolInfo {
|
||||
* Returns the protocol state the user is currently in.
|
||||
*
|
||||
* @return protocol state
|
||||
* @deprecated server and client can be in different states, use {@link #getClientState()} or {@link #getServerState()}
|
||||
*/
|
||||
State getState();
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default State getState() {
|
||||
return this.getServerState();
|
||||
}
|
||||
|
||||
void setState(State state);
|
||||
/**
|
||||
* Returns the protocol state the client is currently in.
|
||||
*
|
||||
* @return the client protocol state
|
||||
*/
|
||||
State getClientState();
|
||||
|
||||
/**
|
||||
* Returns the protocol state the server is currently in.
|
||||
*
|
||||
* @return the server protocol state
|
||||
*/
|
||||
State getServerState();
|
||||
|
||||
/**
|
||||
* Returns the protocol state for the given direction.
|
||||
*
|
||||
* @param direction protocol direction
|
||||
* @return state for the given direction
|
||||
*/
|
||||
default State getState(final Direction direction) {
|
||||
// Return the state the packet is coming from
|
||||
return direction == Direction.CLIENTBOUND ? this.getServerState() : this.getClientState();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets both client and server state.
|
||||
*
|
||||
* @param state the new protocol state
|
||||
* @see #setClientState(State)
|
||||
* @see #setServerState(State)
|
||||
*/
|
||||
default void setState(final State state) {
|
||||
this.setClientState(state);
|
||||
this.setServerState(state);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the client protocol state.
|
||||
*
|
||||
* @param clientState the new client protocol state
|
||||
*/
|
||||
void setClientState(State clientState);
|
||||
|
||||
/**
|
||||
* Sets the server protocol state.
|
||||
*
|
||||
* @param serverState the new server protocol state
|
||||
*/
|
||||
void setServerState(State serverState);
|
||||
|
||||
/**
|
||||
* Returns the user's protocol version, or -1 if not set.
|
||||
|
||||
@@ -38,4 +38,7 @@ public interface StorableObject {
|
||||
default boolean clearOnServerSwitch() {
|
||||
return true;
|
||||
}
|
||||
|
||||
default void onRemove() {
|
||||
}
|
||||
}
|
||||
@@ -101,6 +101,8 @@ public interface MappingData {
|
||||
|
||||
@Nullable Mappings getStatisticsMappings();
|
||||
|
||||
@Nullable Mappings getMenuMappings();
|
||||
|
||||
@Nullable Mappings getEnchantmentMappings();
|
||||
|
||||
@Nullable FullMappings getEntityMappings();
|
||||
|
||||
@@ -52,6 +52,7 @@ public class MappingDataBase implements MappingData {
|
||||
protected Mappings statisticsMappings;
|
||||
protected Mappings enchantmentMappings;
|
||||
protected Mappings paintingMappings;
|
||||
protected Mappings menuMappings;
|
||||
protected Map<RegistryType, List<TagData>> tags;
|
||||
|
||||
public MappingDataBase(final String unmappedVersion, final String mappedVersion) {
|
||||
@@ -71,6 +72,7 @@ public class MappingDataBase implements MappingData {
|
||||
blockEntityMappings = loadMappings(data, "blockentities");
|
||||
soundMappings = loadMappings(data, "sounds");
|
||||
statisticsMappings = loadMappings(data, "statistics");
|
||||
menuMappings = loadMappings(data, "menus");
|
||||
enchantmentMappings = loadMappings(data, "enchantments");
|
||||
paintingMappings = loadMappings(data, "paintings");
|
||||
itemMappings = loadBiMappings(data, "items");
|
||||
@@ -202,6 +204,11 @@ public class MappingDataBase implements MappingData {
|
||||
return statisticsMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Mappings getMenuMappings() {
|
||||
return menuMappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Mappings getEnchantmentMappings() {
|
||||
return enchantmentMappings;
|
||||
@@ -236,7 +243,9 @@ public class MappingDataBase implements MappingData {
|
||||
*/
|
||||
protected int checkValidity(final int id, final int mappedId, final String type) {
|
||||
if (mappedId == -1) {
|
||||
getLogger().warning(String.format("Missing %s %s for %s %s %d", mappedVersion, type, unmappedVersion, type, id));
|
||||
if (!Via.getConfig().isSuppressConversionWarnings()) {
|
||||
getLogger().warning(String.format("Missing %s %s for %s %s %d", mappedVersion, type, unmappedVersion, type, id));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return mappedId;
|
||||
|
||||
@@ -87,7 +87,7 @@ public interface EntityTracker {
|
||||
*
|
||||
* @param id entity id
|
||||
* @return stored entity data if an entity with the id is tracked, else null
|
||||
* @throws IllegalArgumentException if entitiy data storage has not been enabled via the implementation
|
||||
* @throws IllegalArgumentException if entity data storage has not been enabled via the implementation
|
||||
*/
|
||||
@Nullable StoredEntityData entityData(int id);
|
||||
|
||||
@@ -96,7 +96,7 @@ public interface EntityTracker {
|
||||
*
|
||||
* @param id entity id
|
||||
* @return stored entity data if it has previously been initialized by {@link #entityData(int)}
|
||||
* @throws IllegalArgumentException if entitiy data storage has not been enabled via the implementation
|
||||
* @throws IllegalArgumentException if entity data storage has not been enabled via the implementation
|
||||
*/
|
||||
@Nullable StoredEntityData entityDataIfPresent(int id);
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ public interface BossBar {
|
||||
BossColor getColor();
|
||||
|
||||
/**
|
||||
* Yay colors!
|
||||
* Yay, colors!
|
||||
*
|
||||
* @param color Whatever color you want!
|
||||
* @return The BossBar object
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Stored up until 1.14 to be used in chunk sending.
|
||||
*/
|
||||
public class ClientWorld implements StorableObject {
|
||||
private Environment environment;
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public ClientWorld(final UserConnection connection) {
|
||||
}
|
||||
|
||||
public ClientWorld() {
|
||||
}
|
||||
|
||||
public ClientWorld(final Environment environment) {
|
||||
this.environment = environment;
|
||||
}
|
||||
|
||||
public @Nullable Environment getEnvironment() {
|
||||
return environment;
|
||||
}
|
||||
|
||||
public void setEnvironment(final int environmentId) {
|
||||
this.environment = Environment.getEnvironmentById(environmentId);
|
||||
}
|
||||
}
|
||||
+44
-25
@@ -20,17 +20,19 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type.types;
|
||||
package com.viaversion.viaversion.api.minecraft;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Particle {
|
||||
private List<ParticleData> arguments = new ArrayList<>(4);
|
||||
public final class Particle {
|
||||
private final List<ParticleData<?>> arguments = new ArrayList<>(4);
|
||||
private int id;
|
||||
|
||||
public Particle(int id) {
|
||||
public Particle(final int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@@ -38,50 +40,67 @@ public class Particle {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
public void setId(final int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public List<ParticleData> getArguments() {
|
||||
public <T> ParticleData<T> getArgument(final int index) {
|
||||
//noinspection unchecked
|
||||
return (ParticleData<T>) arguments.get(index);
|
||||
}
|
||||
|
||||
public <T> ParticleData<T> removeArgument(final int index) {
|
||||
//noinspection unchecked
|
||||
return (ParticleData<T>) arguments.remove(index);
|
||||
}
|
||||
|
||||
public List<ParticleData<?>> getArguments() {
|
||||
return arguments;
|
||||
}
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public void setArguments(List<ParticleData> arguments) {
|
||||
this.arguments = arguments;
|
||||
public <T> void add(final Type<T> type, final T value) {
|
||||
arguments.add(new ParticleData<>(type, value));
|
||||
}
|
||||
|
||||
public <T> void add(Type<T> type, T value) {
|
||||
arguments.add(new ParticleData(type, value));
|
||||
public <T> void add(final int index, final Type<T> type, final T value) {
|
||||
arguments.add(index, new ParticleData<>(type, value));
|
||||
}
|
||||
|
||||
public static class ParticleData {
|
||||
private Type type;
|
||||
private Object value;
|
||||
public static final class ParticleData<T> {
|
||||
private final Type<T> type;
|
||||
private T value;
|
||||
|
||||
public ParticleData(Type type, Object value) {
|
||||
public ParticleData(final Type<T> type, final T value) {
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public Type getType() {
|
||||
public Type<T> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(Type type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Object getValue() {
|
||||
public T getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public <T> T get() {
|
||||
return (T) value;
|
||||
public void setValue(final T value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
public void write(final ByteBuf buf) throws Exception {
|
||||
type.write(buf, value);
|
||||
}
|
||||
|
||||
public void write(final PacketWrapper wrapper) {
|
||||
wrapper.write(type, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ParticleData{" +
|
||||
"type=" + type +
|
||||
", value=" + value +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,4 +50,14 @@ public final class Quaternion {
|
||||
public float w() {
|
||||
return w;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Quaternion{" +
|
||||
"x=" + x +
|
||||
", y=" + y +
|
||||
", z=" + z +
|
||||
", w=" + w +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,10 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public interface BlockEntity {
|
||||
|
||||
static byte pack(int sectionX, int sectionZ) {
|
||||
return (byte) (((sectionX) & 15) << 4 | (sectionZ & 15));
|
||||
}
|
||||
|
||||
default byte sectionX() {
|
||||
return (byte) ((packedXZ() >> 4) & 15);
|
||||
}
|
||||
|
||||
+5
@@ -47,6 +47,11 @@ public class ChunkSectionLightImpl implements ChunkSectionLight {
|
||||
|
||||
@Override
|
||||
public void setSkyLight(byte[] data) {
|
||||
if (data == null) {
|
||||
this.skyLight = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (data.length != LIGHT_LENGTH) throw new IllegalArgumentException("Data length != " + LIGHT_LENGTH);
|
||||
if (this.skyLight == null) {
|
||||
this.skyLight = new NibbleArray(data);
|
||||
|
||||
+86
-10
@@ -29,21 +29,24 @@ import it.unimi.dsi.fastutil.ints.IntList;
|
||||
|
||||
public final class DataPaletteImpl implements DataPalette {
|
||||
|
||||
private static final int DEFAULT_INITIAL_SIZE = 16;
|
||||
|
||||
private final IntList palette;
|
||||
private final Int2IntMap inversePalette;
|
||||
private final int[] values;
|
||||
private final int sizeBits;
|
||||
private ChunkData values;
|
||||
|
||||
public DataPaletteImpl(final int valuesLength) {
|
||||
this(valuesLength, 8);
|
||||
this(valuesLength, DEFAULT_INITIAL_SIZE);
|
||||
}
|
||||
|
||||
public DataPaletteImpl(final int valuesLength, final int expectedPaletteLength) {
|
||||
this.values = new int[valuesLength];
|
||||
public DataPaletteImpl(final int valuesLength, final int initialSize) {
|
||||
values = new EmptyChunkData(valuesLength);
|
||||
sizeBits = Integer.numberOfTrailingZeros(valuesLength) / 3;
|
||||
// Pre-size the palette array/map
|
||||
palette = new IntArrayList(expectedPaletteLength);
|
||||
inversePalette = new Int2IntOpenHashMap(expectedPaletteLength);
|
||||
palette = new IntArrayList(initialSize);
|
||||
// To get an initial table size of initialSize, need to scale it down by load factor.
|
||||
inversePalette = new Int2IntOpenHashMap((int) (initialSize * Int2IntOpenHashMap.DEFAULT_LOAD_FACTOR));
|
||||
inversePalette.defaultReturnValue(-1);
|
||||
}
|
||||
|
||||
@@ -54,7 +57,7 @@ public final class DataPaletteImpl implements DataPalette {
|
||||
|
||||
@Override
|
||||
public int idAt(final int sectionCoordinate) {
|
||||
final int index = values[sectionCoordinate];
|
||||
final int index = values.get(sectionCoordinate);
|
||||
return palette.getInt(index);
|
||||
}
|
||||
|
||||
@@ -67,17 +70,17 @@ public final class DataPaletteImpl implements DataPalette {
|
||||
inversePalette.put(id, index);
|
||||
}
|
||||
|
||||
values[sectionCoordinate] = index;
|
||||
values.set(sectionCoordinate, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int paletteIndexAt(final int packedCoordinate) {
|
||||
return values[packedCoordinate];
|
||||
return values.get(packedCoordinate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPaletteIndexAt(final int sectionCoordinate, final int index) {
|
||||
values[sectionCoordinate] = index;
|
||||
values.set(sectionCoordinate, index);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,4 +134,77 @@ public final class DataPaletteImpl implements DataPalette {
|
||||
palette.clear();
|
||||
inversePalette.clear();
|
||||
}
|
||||
|
||||
interface ChunkData {
|
||||
int get(int idx);
|
||||
void set(int idx, int val);
|
||||
}
|
||||
|
||||
private class EmptyChunkData implements ChunkData {
|
||||
|
||||
private final int size;
|
||||
|
||||
public EmptyChunkData(int size) {
|
||||
this.size = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int get(int idx) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int idx, int val) {
|
||||
if (val != 0) {
|
||||
values = new ByteChunkData(size);
|
||||
values.set(idx, val);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class ByteChunkData implements ChunkData {
|
||||
private final byte[] data;
|
||||
|
||||
public ByteChunkData(int size) {
|
||||
this.data = new byte[size];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int get(int idx) {
|
||||
return data[idx] & 0xFF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int idx, int val) {
|
||||
// Overflowed size of byte (over 256 different materials), go up to short
|
||||
if (val > 0xFF) {
|
||||
values = new ShortChunkData(data);
|
||||
values.set(idx, val);
|
||||
return;
|
||||
}
|
||||
data[idx] = (byte) val;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ShortChunkData implements ChunkData {
|
||||
private final short[] data;
|
||||
|
||||
public ShortChunkData(byte[] data) {
|
||||
this.data = new short[data.length];
|
||||
for (int i = 0; i < data.length; i++) {
|
||||
this.data[i] = (short) (data[i] & 0xFF);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int get(int idx) {
|
||||
return data[idx];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(int idx, int val) {
|
||||
data[idx] = (short) val;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -28,7 +28,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
// 1.10 Entity / Object ids
|
||||
public class Entity1_10Types {
|
||||
public class EntityTypes1_10 {
|
||||
|
||||
public static EntityType getTypeFromId(int typeID, boolean isObject) {
|
||||
Optional<EntityType> type;
|
||||
+1
-1
@@ -28,7 +28,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
// 1.11 Entity / Object ids
|
||||
public class Entity1_11Types {
|
||||
public class EntityTypes1_11 {
|
||||
|
||||
public static EntityType getTypeFromId(int typeID, boolean isObject) {
|
||||
Optional<EntityType> type;
|
||||
+1
-1
@@ -29,7 +29,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
// 1.12 Entity / Object taken from https://github.com/Matsv/ViaBackwards/blob/master/core/src/main/java/nl/matsv/viabackwards/api/entities/types/EntityType1_12.java
|
||||
public class Entity1_12Types {
|
||||
public class EntityTypes1_12 {
|
||||
|
||||
public static EntityType getTypeFromId(int typeID, boolean isObject) {
|
||||
Optional<EntityType> type;
|
||||
+1
-1
@@ -27,7 +27,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Entity1_13Types {
|
||||
public class EntityTypes1_13 {
|
||||
|
||||
public static EntityType getTypeFromId(int typeID, boolean isObject) {
|
||||
Optional<EntityType> type;
|
||||
+3
-3
@@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.minecraft.entities;
|
||||
|
||||
import com.viaversion.viaversion.util.EntityTypeUtil;
|
||||
|
||||
public enum Entity1_14Types implements EntityType {
|
||||
public enum EntityTypes1_14 implements EntityType {
|
||||
|
||||
ENTITY(-1),
|
||||
|
||||
@@ -204,12 +204,12 @@ public enum Entity1_14Types implements EntityType {
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
|
||||
Entity1_14Types(int id) {
|
||||
EntityTypes1_14(int id) {
|
||||
this.id = id;
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
Entity1_14Types(int id, EntityType parent) {
|
||||
EntityTypes1_14(int id, EntityType parent) {
|
||||
this.id = id;
|
||||
this.parent = parent;
|
||||
}
|
||||
+3
-3
@@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.minecraft.entities;
|
||||
|
||||
import com.viaversion.viaversion.util.EntityTypeUtil;
|
||||
|
||||
public enum Entity1_15Types implements EntityType {
|
||||
public enum EntityTypes1_15 implements EntityType {
|
||||
|
||||
ENTITY(-1),
|
||||
|
||||
@@ -206,12 +206,12 @@ public enum Entity1_15Types implements EntityType {
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
|
||||
Entity1_15Types(int id) {
|
||||
EntityTypes1_15(int id) {
|
||||
this.id = id;
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
Entity1_15Types(int id, EntityType parent) {
|
||||
EntityTypes1_15(int id, EntityType parent) {
|
||||
this.id = id;
|
||||
this.parent = parent;
|
||||
}
|
||||
+3
-3
@@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.minecraft.entities;
|
||||
|
||||
import com.viaversion.viaversion.util.EntityTypeUtil;
|
||||
|
||||
public enum Entity1_16Types implements EntityType {
|
||||
public enum EntityTypes1_16 implements EntityType {
|
||||
|
||||
ENTITY(-1),
|
||||
|
||||
@@ -211,12 +211,12 @@ public enum Entity1_16Types implements EntityType {
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
|
||||
Entity1_16Types(int id) {
|
||||
EntityTypes1_16(int id) {
|
||||
this.id = id;
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
Entity1_16Types(int id, EntityType parent) {
|
||||
EntityTypes1_16(int id, EntityType parent) {
|
||||
this.id = id;
|
||||
this.parent = parent;
|
||||
}
|
||||
+3
-3
@@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.minecraft.entities;
|
||||
|
||||
import com.viaversion.viaversion.util.EntityTypeUtil;
|
||||
|
||||
public enum Entity1_16_2Types implements EntityType {
|
||||
public enum EntityTypes1_16_2 implements EntityType {
|
||||
|
||||
ENTITY(-1),
|
||||
|
||||
@@ -215,12 +215,12 @@ public enum Entity1_16_2Types implements EntityType {
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
|
||||
Entity1_16_2Types(int id) {
|
||||
EntityTypes1_16_2(int id) {
|
||||
this.id = id;
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
Entity1_16_2Types(int id, EntityType parent) {
|
||||
EntityTypes1_16_2(int id, EntityType parent) {
|
||||
this.id = id;
|
||||
this.parent = parent;
|
||||
}
|
||||
+3
-3
@@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.minecraft.entities;
|
||||
|
||||
import com.viaversion.viaversion.util.EntityTypeUtil;
|
||||
|
||||
public enum Entity1_17Types implements EntityType {
|
||||
public enum EntityTypes1_17 implements EntityType {
|
||||
|
||||
ENTITY(-1),
|
||||
|
||||
@@ -220,12 +220,12 @@ public enum Entity1_17Types implements EntityType {
|
||||
private final int id;
|
||||
private final EntityType parent;
|
||||
|
||||
Entity1_17Types(int id) {
|
||||
EntityTypes1_17(int id) {
|
||||
this.id = id;
|
||||
this.parent = null;
|
||||
}
|
||||
|
||||
Entity1_17Types(int id, EntityType parent) {
|
||||
EntityTypes1_17(int id, EntityType parent) {
|
||||
this.id = id;
|
||||
this.parent = parent;
|
||||
}
|
||||
+3
-3
@@ -28,7 +28,7 @@ import com.viaversion.viaversion.util.EntityTypeUtil;
|
||||
import java.util.Locale;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public enum Entity1_19Types implements EntityType {
|
||||
public enum EntityTypes1_19 implements EntityType {
|
||||
|
||||
ENTITY(null, null),
|
||||
|
||||
@@ -229,12 +229,12 @@ public enum Entity1_19Types implements EntityType {
|
||||
private final String identifier;
|
||||
private int id = -1;
|
||||
|
||||
Entity1_19Types(final EntityType parent) {
|
||||
EntityTypes1_19(final EntityType parent) {
|
||||
this.parent = parent;
|
||||
this.identifier = "minecraft:" + name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
Entity1_19Types(final EntityType parent, @Nullable final String identifier) {
|
||||
EntityTypes1_19(final EntityType parent, @Nullable final String identifier) {
|
||||
this.parent = parent;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
+3
-3
@@ -28,7 +28,7 @@ import com.viaversion.viaversion.util.EntityTypeUtil;
|
||||
import java.util.Locale;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public enum Entity1_19_3Types implements EntityType {
|
||||
public enum EntityTypes1_19_3 implements EntityType {
|
||||
|
||||
ENTITY(null, null),
|
||||
|
||||
@@ -230,12 +230,12 @@ public enum Entity1_19_3Types implements EntityType {
|
||||
private final String identifier;
|
||||
private int id = -1;
|
||||
|
||||
Entity1_19_3Types(final EntityType parent) {
|
||||
EntityTypes1_19_3(final EntityType parent) {
|
||||
this.parent = parent;
|
||||
this.identifier = "minecraft:" + name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
Entity1_19_3Types(final EntityType parent, @Nullable final String identifier) {
|
||||
EntityTypes1_19_3(final EntityType parent, @Nullable final String identifier) {
|
||||
this.parent = parent;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
+3
-3
@@ -28,7 +28,7 @@ import com.viaversion.viaversion.util.EntityTypeUtil;
|
||||
import java.util.Locale;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public enum Entity1_19_4Types implements EntityType {
|
||||
public enum EntityTypes1_19_4 implements EntityType {
|
||||
|
||||
ENTITY(null, null),
|
||||
|
||||
@@ -237,12 +237,12 @@ public enum Entity1_19_4Types implements EntityType {
|
||||
private final String identifier;
|
||||
private int id = -1;
|
||||
|
||||
Entity1_19_4Types(final EntityType parent) {
|
||||
EntityTypes1_19_4(final EntityType parent) {
|
||||
this.parent = parent;
|
||||
this.identifier = "minecraft:" + name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
Entity1_19_4Types(final EntityType parent, @Nullable final String identifier) {
|
||||
EntityTypes1_19_4(final EntityType parent, @Nullable final String identifier) {
|
||||
this.parent = parent;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
+283
@@ -0,0 +1,283 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.entities;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.util.EntityTypeUtil;
|
||||
import java.util.Locale;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public enum EntityTypes1_20_3 implements EntityType {
|
||||
|
||||
ENTITY(null, null),
|
||||
|
||||
AREA_EFFECT_CLOUD(ENTITY),
|
||||
END_CRYSTAL(ENTITY),
|
||||
EVOKER_FANGS(ENTITY),
|
||||
EXPERIENCE_ORB(ENTITY),
|
||||
EYE_OF_ENDER(ENTITY),
|
||||
FALLING_BLOCK(ENTITY),
|
||||
FIREWORK_ROCKET(ENTITY),
|
||||
ITEM(ENTITY),
|
||||
LLAMA_SPIT(ENTITY),
|
||||
TNT(ENTITY),
|
||||
SHULKER_BULLET(ENTITY),
|
||||
FISHING_BOBBER(ENTITY),
|
||||
|
||||
LIVINGENTITY(ENTITY, null),
|
||||
ARMOR_STAND(LIVINGENTITY),
|
||||
MARKER(ENTITY),
|
||||
PLAYER(LIVINGENTITY),
|
||||
|
||||
DISPLAY(ENTITY, null),
|
||||
BLOCK_DISPLAY(DISPLAY),
|
||||
ITEM_DISPLAY(DISPLAY),
|
||||
TEXT_DISPLAY(DISPLAY),
|
||||
INTERACTION(ENTITY),
|
||||
|
||||
ABSTRACT_INSENTIENT(LIVINGENTITY, null),
|
||||
ENDER_DRAGON(ABSTRACT_INSENTIENT),
|
||||
|
||||
BEE(ABSTRACT_INSENTIENT),
|
||||
|
||||
ABSTRACT_CREATURE(ABSTRACT_INSENTIENT, null),
|
||||
|
||||
ABSTRACT_AGEABLE(ABSTRACT_CREATURE, null),
|
||||
VILLAGER(ABSTRACT_AGEABLE),
|
||||
WANDERING_TRADER(ABSTRACT_AGEABLE),
|
||||
|
||||
// Animals
|
||||
ABSTRACT_ANIMAL(ABSTRACT_AGEABLE, null),
|
||||
AXOLOTL(ABSTRACT_ANIMAL),
|
||||
DOLPHIN(ABSTRACT_INSENTIENT),
|
||||
CHICKEN(ABSTRACT_ANIMAL),
|
||||
COW(ABSTRACT_ANIMAL),
|
||||
MOOSHROOM(COW),
|
||||
PANDA(ABSTRACT_INSENTIENT),
|
||||
PIG(ABSTRACT_ANIMAL),
|
||||
POLAR_BEAR(ABSTRACT_ANIMAL),
|
||||
RABBIT(ABSTRACT_ANIMAL),
|
||||
SHEEP(ABSTRACT_ANIMAL),
|
||||
TURTLE(ABSTRACT_ANIMAL),
|
||||
FOX(ABSTRACT_ANIMAL),
|
||||
FROG(ABSTRACT_ANIMAL),
|
||||
GOAT(ABSTRACT_ANIMAL),
|
||||
SNIFFER(ABSTRACT_ANIMAL),
|
||||
|
||||
ABSTRACT_TAMEABLE_ANIMAL(ABSTRACT_ANIMAL, null),
|
||||
CAT(ABSTRACT_TAMEABLE_ANIMAL),
|
||||
OCELOT(ABSTRACT_TAMEABLE_ANIMAL),
|
||||
WOLF(ABSTRACT_TAMEABLE_ANIMAL),
|
||||
|
||||
ABSTRACT_PARROT(ABSTRACT_TAMEABLE_ANIMAL, null),
|
||||
PARROT(ABSTRACT_PARROT),
|
||||
|
||||
// Horses
|
||||
ABSTRACT_HORSE(ABSTRACT_ANIMAL, null),
|
||||
CHESTED_HORSE(ABSTRACT_HORSE, null),
|
||||
DONKEY(CHESTED_HORSE),
|
||||
MULE(CHESTED_HORSE),
|
||||
LLAMA(CHESTED_HORSE),
|
||||
TRADER_LLAMA(CHESTED_HORSE),
|
||||
HORSE(ABSTRACT_HORSE),
|
||||
SKELETON_HORSE(ABSTRACT_HORSE),
|
||||
ZOMBIE_HORSE(ABSTRACT_HORSE),
|
||||
CAMEL(ABSTRACT_HORSE),
|
||||
|
||||
// Golem
|
||||
ABSTRACT_GOLEM(ABSTRACT_CREATURE, null),
|
||||
SNOW_GOLEM(ABSTRACT_GOLEM),
|
||||
IRON_GOLEM(ABSTRACT_GOLEM),
|
||||
SHULKER(ABSTRACT_GOLEM),
|
||||
|
||||
// Fish
|
||||
ABSTRACT_FISHES(ABSTRACT_CREATURE, null),
|
||||
COD(ABSTRACT_FISHES),
|
||||
PUFFERFISH(ABSTRACT_FISHES),
|
||||
SALMON(ABSTRACT_FISHES),
|
||||
TROPICAL_FISH(ABSTRACT_FISHES),
|
||||
|
||||
// Monsters
|
||||
ABSTRACT_MONSTER(ABSTRACT_CREATURE, null),
|
||||
BLAZE(ABSTRACT_MONSTER),
|
||||
CREEPER(ABSTRACT_MONSTER),
|
||||
ENDERMITE(ABSTRACT_MONSTER),
|
||||
ENDERMAN(ABSTRACT_MONSTER),
|
||||
GIANT(ABSTRACT_MONSTER),
|
||||
SILVERFISH(ABSTRACT_MONSTER),
|
||||
VEX(ABSTRACT_MONSTER),
|
||||
WITCH(ABSTRACT_MONSTER),
|
||||
WITHER(ABSTRACT_MONSTER),
|
||||
RAVAGER(ABSTRACT_MONSTER),
|
||||
BREEZE(ABSTRACT_MONSTER),
|
||||
|
||||
ABSTRACT_PIGLIN(ABSTRACT_MONSTER, null),
|
||||
|
||||
PIGLIN(ABSTRACT_PIGLIN),
|
||||
PIGLIN_BRUTE(ABSTRACT_PIGLIN),
|
||||
|
||||
HOGLIN(ABSTRACT_ANIMAL),
|
||||
STRIDER(ABSTRACT_ANIMAL),
|
||||
TADPOLE(ABSTRACT_FISHES),
|
||||
ZOGLIN(ABSTRACT_MONSTER),
|
||||
WARDEN(ABSTRACT_MONSTER),
|
||||
|
||||
// Illagers
|
||||
ABSTRACT_ILLAGER_BASE(ABSTRACT_MONSTER, null),
|
||||
ABSTRACT_EVO_ILLU_ILLAGER(ABSTRACT_ILLAGER_BASE, null),
|
||||
EVOKER(ABSTRACT_EVO_ILLU_ILLAGER),
|
||||
ILLUSIONER(ABSTRACT_EVO_ILLU_ILLAGER),
|
||||
VINDICATOR(ABSTRACT_ILLAGER_BASE),
|
||||
PILLAGER(ABSTRACT_ILLAGER_BASE),
|
||||
|
||||
// Skeletons
|
||||
ABSTRACT_SKELETON(ABSTRACT_MONSTER, null),
|
||||
SKELETON(ABSTRACT_SKELETON),
|
||||
STRAY(ABSTRACT_SKELETON),
|
||||
WITHER_SKELETON(ABSTRACT_SKELETON),
|
||||
|
||||
// Guardians
|
||||
GUARDIAN(ABSTRACT_MONSTER),
|
||||
ELDER_GUARDIAN(GUARDIAN),
|
||||
|
||||
// Spiders
|
||||
SPIDER(ABSTRACT_MONSTER),
|
||||
CAVE_SPIDER(SPIDER),
|
||||
|
||||
// Zombies
|
||||
ZOMBIE(ABSTRACT_MONSTER),
|
||||
DROWNED(ZOMBIE),
|
||||
HUSK(ZOMBIE),
|
||||
ZOMBIFIED_PIGLIN(ZOMBIE),
|
||||
ZOMBIE_VILLAGER(ZOMBIE),
|
||||
|
||||
// Flying entities
|
||||
ABSTRACT_FLYING(ABSTRACT_INSENTIENT, null),
|
||||
GHAST(ABSTRACT_FLYING),
|
||||
PHANTOM(ABSTRACT_FLYING),
|
||||
|
||||
ABSTRACT_AMBIENT(ABSTRACT_INSENTIENT, null),
|
||||
BAT(ABSTRACT_AMBIENT),
|
||||
ALLAY(ABSTRACT_CREATURE),
|
||||
|
||||
ABSTRACT_WATERMOB(ABSTRACT_INSENTIENT, null),
|
||||
SQUID(ABSTRACT_WATERMOB),
|
||||
GLOW_SQUID(SQUID),
|
||||
|
||||
// Slimes
|
||||
SLIME(ABSTRACT_INSENTIENT),
|
||||
MAGMA_CUBE(SLIME),
|
||||
|
||||
// Hangable objects
|
||||
ABSTRACT_HANGING(ENTITY, null),
|
||||
LEASH_KNOT(ABSTRACT_HANGING),
|
||||
ITEM_FRAME(ABSTRACT_HANGING),
|
||||
GLOW_ITEM_FRAME(ITEM_FRAME),
|
||||
PAINTING(ABSTRACT_HANGING),
|
||||
|
||||
ABSTRACT_LIGHTNING(ENTITY, null),
|
||||
LIGHTNING_BOLT(ABSTRACT_LIGHTNING),
|
||||
|
||||
// Arrows
|
||||
ABSTRACT_ARROW(ENTITY, null),
|
||||
ARROW(ABSTRACT_ARROW),
|
||||
SPECTRAL_ARROW(ABSTRACT_ARROW),
|
||||
TRIDENT(ABSTRACT_ARROW),
|
||||
|
||||
// Fireballs
|
||||
ABSTRACT_FIREBALL(ENTITY, null),
|
||||
DRAGON_FIREBALL(ABSTRACT_FIREBALL),
|
||||
FIREBALL(ABSTRACT_FIREBALL),
|
||||
SMALL_FIREBALL(ABSTRACT_FIREBALL),
|
||||
WITHER_SKULL(ABSTRACT_FIREBALL),
|
||||
|
||||
// Projectiles
|
||||
PROJECTILE_ABSTRACT(ENTITY, null),
|
||||
SNOWBALL(PROJECTILE_ABSTRACT),
|
||||
ENDER_PEARL(PROJECTILE_ABSTRACT),
|
||||
EGG(PROJECTILE_ABSTRACT),
|
||||
POTION(PROJECTILE_ABSTRACT),
|
||||
EXPERIENCE_BOTTLE(PROJECTILE_ABSTRACT),
|
||||
WIND_CHARGE(PROJECTILE_ABSTRACT),
|
||||
|
||||
// Vehicles
|
||||
MINECART_ABSTRACT(ENTITY, null),
|
||||
CHESTED_MINECART_ABSTRACT(MINECART_ABSTRACT, null),
|
||||
CHEST_MINECART(CHESTED_MINECART_ABSTRACT),
|
||||
HOPPER_MINECART(CHESTED_MINECART_ABSTRACT),
|
||||
MINECART(MINECART_ABSTRACT),
|
||||
FURNACE_MINECART(MINECART_ABSTRACT),
|
||||
COMMAND_BLOCK_MINECART(MINECART_ABSTRACT),
|
||||
TNT_MINECART(MINECART_ABSTRACT),
|
||||
SPAWNER_MINECART(MINECART_ABSTRACT),
|
||||
BOAT(ENTITY),
|
||||
CHEST_BOAT(BOAT);
|
||||
|
||||
private static final EntityType[] TYPES = EntityTypeUtil.createSizedArray(values());
|
||||
private final EntityType parent;
|
||||
private final String identifier;
|
||||
private int id = -1;
|
||||
|
||||
EntityTypes1_20_3(final EntityType parent) {
|
||||
this.parent = parent;
|
||||
this.identifier = "minecraft:" + name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
EntityTypes1_20_3(final EntityType parent, @Nullable final String identifier) {
|
||||
this.parent = parent;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
if (id == -1) {
|
||||
throw new IllegalStateException("Ids have not been initialized yet (type " + name() + ")");
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String identifier() {
|
||||
Preconditions.checkArgument(identifier != null, "Called identifier method on abstract type");
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable EntityType getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbstractType() {
|
||||
return identifier == null;
|
||||
}
|
||||
|
||||
public static EntityType getTypeFromId(final int typeId) {
|
||||
return EntityTypeUtil.getTypeFromId(TYPES, typeId, ENTITY);
|
||||
}
|
||||
|
||||
public static void initialize(final Protocol<?, ?, ?, ?> protocol) {
|
||||
EntityTypeUtil.initialize(values(), TYPES, protocol, (type, id) -> type.id = id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.metadata;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public final class ChunkPosition {
|
||||
private final int chunkX;
|
||||
private final int chunkZ;
|
||||
|
||||
public ChunkPosition(final int chunkX, final int chunkZ) {
|
||||
this.chunkX = chunkX;
|
||||
this.chunkZ = chunkZ;
|
||||
}
|
||||
|
||||
public ChunkPosition(final long chunkKey) {
|
||||
this.chunkX = (int) chunkKey;
|
||||
this.chunkZ = (int) (chunkKey >> 32);
|
||||
}
|
||||
|
||||
public int chunkX() {
|
||||
return chunkX;
|
||||
}
|
||||
|
||||
public int chunkZ() {
|
||||
return chunkZ;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a long key for this chunk position.
|
||||
*
|
||||
* @return the chunk key
|
||||
*/
|
||||
public long chunkKey() {
|
||||
return chunkKey(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a long key for the given chunk coordinates.
|
||||
*
|
||||
* @param chunkX the chunk X coordinate
|
||||
* @param chunkZ the chunk Z coordinate
|
||||
* @return the chunk key
|
||||
*/
|
||||
public static long chunkKey(final int chunkX, final int chunkZ) {
|
||||
return (long) chunkX & 0xffffffffL | ((long) chunkZ & 0xffffffffL) << 32;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
final ChunkPosition that = (ChunkPosition) o;
|
||||
return chunkX == that.chunkX && chunkZ == that.chunkZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(chunkX, chunkZ);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ChunkPosition{" +
|
||||
"chunkX=" + chunkX +
|
||||
", chunkZ=" + chunkZ +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,14 @@ public interface MetaType {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MetaType{" +
|
||||
"typeId=" + typeId +
|
||||
", type=" + type +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
+4
-4
@@ -31,15 +31,15 @@ public enum MetaType1_12 implements MetaType {
|
||||
Float(2, Type.FLOAT),
|
||||
String(3, Type.STRING),
|
||||
Chat(4, Type.COMPONENT),
|
||||
Slot(5, Type.ITEM),
|
||||
Slot(5, Type.ITEM1_8),
|
||||
Boolean(6, Type.BOOLEAN),
|
||||
Vector3F(7, Type.ROTATION),
|
||||
Position(8, Type.POSITION),
|
||||
OptPosition(9, Type.OPTIONAL_POSITION),
|
||||
Position(8, Type.POSITION1_8),
|
||||
OptPosition(9, Type.OPTIONAL_POSITION1_8),
|
||||
Direction(10, Type.VAR_INT),
|
||||
OptUUID(11, Type.OPTIONAL_UUID),
|
||||
BlockID(12, Type.VAR_INT),
|
||||
NBTTag(13, Type.NBT);
|
||||
NBTTag(13, Type.NAMED_COMPOUND_TAG);
|
||||
|
||||
private final int typeID;
|
||||
private final Type type;
|
||||
|
||||
-69
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.metadata.types;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_13;
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public enum MetaType1_13 implements MetaType {
|
||||
Byte(0, Type.BYTE),
|
||||
VarInt(1, Type.VAR_INT),
|
||||
Float(2, Type.FLOAT),
|
||||
String(3, Type.STRING),
|
||||
Chat(4, Type.COMPONENT),
|
||||
OptChat(5, Type.OPTIONAL_COMPONENT),
|
||||
Slot(6, Type.FLAT_ITEM),
|
||||
Boolean(7, Type.BOOLEAN),
|
||||
Vector3F(8, Type.ROTATION),
|
||||
Position(9, Type.POSITION),
|
||||
OptPosition(10, Type.OPTIONAL_POSITION),
|
||||
Direction(11, Type.VAR_INT),
|
||||
OptUUID(12, Type.OPTIONAL_UUID),
|
||||
BlockID(13, Type.VAR_INT),
|
||||
NBTTag(14, Type.NBT),
|
||||
PARTICLE(15, Types1_13.PARTICLE);
|
||||
|
||||
private final int typeID;
|
||||
private final Type type;
|
||||
|
||||
MetaType1_13(int typeID, Type type) {
|
||||
this.typeID = typeID;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static MetaType1_13 byId(int id) {
|
||||
return values()[id];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int typeId() {
|
||||
return typeID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
-69
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.metadata.types;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_13_2;
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public enum MetaType1_13_2 implements MetaType {
|
||||
Byte(0, Type.BYTE),
|
||||
VarInt(1, Type.VAR_INT),
|
||||
Float(2, Type.FLOAT),
|
||||
String(3, Type.STRING),
|
||||
Chat(4, Type.COMPONENT),
|
||||
OptChat(5, Type.OPTIONAL_COMPONENT),
|
||||
Slot(6, Type.FLAT_VAR_INT_ITEM),
|
||||
Boolean(7, Type.BOOLEAN),
|
||||
Vector3F(8, Type.ROTATION),
|
||||
Position(9, Type.POSITION),
|
||||
OptPosition(10, Type.OPTIONAL_POSITION),
|
||||
Direction(11, Type.VAR_INT),
|
||||
OptUUID(12, Type.OPTIONAL_UUID),
|
||||
BlockID(13, Type.VAR_INT),
|
||||
NBTTag(14, Type.NBT),
|
||||
PARTICLE(15, Types1_13_2.PARTICLE);
|
||||
|
||||
private final int typeID;
|
||||
private final Type type;
|
||||
|
||||
MetaType1_13_2(int typeID, Type type) {
|
||||
this.typeID = typeID;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static MetaType1_13_2 byId(int id) {
|
||||
return values()[id];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int typeId() {
|
||||
return typeID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.metadata.types;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_14;
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public enum MetaType1_14 implements MetaType {
|
||||
Byte(0, Type.BYTE),
|
||||
VarInt(1, Type.VAR_INT),
|
||||
Float(2, Type.FLOAT),
|
||||
String(3, Type.STRING),
|
||||
Chat(4, Type.COMPONENT),
|
||||
OptChat(5, Type.OPTIONAL_COMPONENT),
|
||||
Slot(6, Type.FLAT_VAR_INT_ITEM),
|
||||
Boolean(7, Type.BOOLEAN),
|
||||
Vector3F(8, Type.ROTATION),
|
||||
Position(9, Type.POSITION1_14),
|
||||
OptPosition(10, Type.OPTIONAL_POSITION_1_14),
|
||||
Direction(11, Type.VAR_INT),
|
||||
OptUUID(12, Type.OPTIONAL_UUID),
|
||||
BlockID(13, Type.VAR_INT),
|
||||
NBTTag(14, Type.NBT),
|
||||
PARTICLE(15, Types1_14.PARTICLE),
|
||||
VillagerData(16, Type.VILLAGER_DATA),
|
||||
OptVarInt(17, Type.OPTIONAL_VAR_INT),
|
||||
Pose(18, Type.VAR_INT);
|
||||
|
||||
private final int typeID;
|
||||
private final Type type;
|
||||
|
||||
MetaType1_14(int typeID, Type type) {
|
||||
this.typeID = typeID;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static MetaType1_14 byId(int id) {
|
||||
return values()[id];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int typeId() {
|
||||
return typeID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
-73
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.metadata.types;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_16;
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public enum MetaType1_16 implements MetaType {
|
||||
BYTE(0, Type.BYTE),
|
||||
VAR_INT(1, Type.VAR_INT),
|
||||
FLOAT(2, Type.FLOAT),
|
||||
STRING(3, Type.STRING),
|
||||
COMPONENT(4, Type.COMPONENT),
|
||||
OPT_COMPONENT(5, Type.OPTIONAL_COMPONENT),
|
||||
ITEM(6, Type.FLAT_VAR_INT_ITEM),
|
||||
BOOLEAN(7, Type.BOOLEAN),
|
||||
ROTATION(8, Type.ROTATION),
|
||||
POSITION(9, Type.POSITION1_14),
|
||||
OPT_POSITION(10, Type.OPTIONAL_POSITION_1_14),
|
||||
DIRECTION(11, Type.VAR_INT),
|
||||
OPT_UUID(12, Type.OPTIONAL_UUID),
|
||||
BLOCK_STATE(13, Type.VAR_INT),
|
||||
NBT(14, Type.NBT),
|
||||
PARTICLE(15, Types1_16.PARTICLE),
|
||||
VILLAGER_DATA(16, Type.VILLAGER_DATA),
|
||||
OPT_VAR_INT(17, Type.OPTIONAL_VAR_INT),
|
||||
POSE(18, Type.VAR_INT);
|
||||
|
||||
private static final MetaType1_16[] VALUES = values();
|
||||
private final int typeId;
|
||||
private final Type type;
|
||||
|
||||
MetaType1_16(int typeId, Type type) {
|
||||
this.typeId = typeId;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static MetaType1_16 byId(int id) {
|
||||
return VALUES[id];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int typeId() {
|
||||
return typeId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
-73
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.metadata.types;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_17;
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public enum MetaType1_17 implements MetaType {
|
||||
BYTE(0, Type.BYTE),
|
||||
VAR_INT(1, Type.VAR_INT),
|
||||
FLOAT(2, Type.FLOAT),
|
||||
STRING(3, Type.STRING),
|
||||
COMPONENT(4, Type.COMPONENT),
|
||||
OPT_COMPONENT(5, Type.OPTIONAL_COMPONENT),
|
||||
ITEM(6, Type.FLAT_VAR_INT_ITEM),
|
||||
BOOLEAN(7, Type.BOOLEAN),
|
||||
ROTATION(8, Type.ROTATION),
|
||||
POSITION(9, Type.POSITION1_14),
|
||||
OPT_POSITION(10, Type.OPTIONAL_POSITION_1_14),
|
||||
DIRECTION(11, Type.VAR_INT),
|
||||
OPT_UUID(12, Type.OPTIONAL_UUID),
|
||||
BLOCK_STATE(13, Type.VAR_INT),
|
||||
NBT(14, Type.NBT),
|
||||
PARTICLE(15, Types1_17.PARTICLE),
|
||||
VILLAGER_DATA(16, Type.VILLAGER_DATA),
|
||||
OPT_VAR_INT(17, Type.OPTIONAL_VAR_INT),
|
||||
POSE(18, Type.VAR_INT);
|
||||
|
||||
private static final MetaType1_17[] VALUES = values();
|
||||
private final int typeId;
|
||||
private final Type type;
|
||||
|
||||
MetaType1_17(int typeId, Type type) {
|
||||
this.typeId = typeId;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static MetaType1_17 byId(int id) {
|
||||
return VALUES[id];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int typeId() {
|
||||
return typeId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
-73
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.metadata.types;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_18;
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public enum MetaType1_18 implements MetaType {
|
||||
BYTE(0, Type.BYTE),
|
||||
VAR_INT(1, Type.VAR_INT),
|
||||
FLOAT(2, Type.FLOAT),
|
||||
STRING(3, Type.STRING),
|
||||
COMPONENT(4, Type.COMPONENT),
|
||||
OPT_COMPONENT(5, Type.OPTIONAL_COMPONENT),
|
||||
ITEM(6, Type.FLAT_VAR_INT_ITEM),
|
||||
BOOLEAN(7, Type.BOOLEAN),
|
||||
ROTATION(8, Type.ROTATION),
|
||||
POSITION(9, Type.POSITION1_14),
|
||||
OPT_POSITION(10, Type.OPTIONAL_POSITION_1_14),
|
||||
DIRECTION(11, Type.VAR_INT),
|
||||
OPT_UUID(12, Type.OPTIONAL_UUID),
|
||||
BLOCK_STATE(13, Type.VAR_INT),
|
||||
NBT(14, Type.NBT),
|
||||
PARTICLE(15, Types1_18.PARTICLE),
|
||||
VILLAGER_DATA(16, Type.VILLAGER_DATA),
|
||||
OPT_VAR_INT(17, Type.OPTIONAL_VAR_INT),
|
||||
POSE(18, Type.VAR_INT);
|
||||
|
||||
private static final MetaType1_18[] VALUES = values();
|
||||
private final int typeId;
|
||||
private final Type type;
|
||||
|
||||
MetaType1_18(int typeId, Type type) {
|
||||
this.typeId = typeId;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static MetaType1_18 byId(int id) {
|
||||
return VALUES[id];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int typeId() {
|
||||
return typeId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type type() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
+3
-2
@@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.VoidType;
|
||||
|
||||
public enum MetaType1_8 implements MetaType {
|
||||
Byte(0, Type.BYTE),
|
||||
@@ -31,11 +32,11 @@ public enum MetaType1_8 implements MetaType {
|
||||
Int(2, Type.INT),
|
||||
Float(3, Type.FLOAT),
|
||||
String(4, Type.STRING),
|
||||
Slot(5, Type.ITEM),
|
||||
Slot(5, Type.ITEM1_8),
|
||||
Position(6, Type.VECTOR),
|
||||
Rotation(7, Type.ROTATION),
|
||||
@Deprecated
|
||||
NonExistent(-1, Type.NOTHING);
|
||||
NonExistent(-1, new VoidType());
|
||||
|
||||
private final int typeID;
|
||||
private final Type type;
|
||||
|
||||
+3
-3
@@ -31,11 +31,11 @@ public enum MetaType1_9 implements MetaType {
|
||||
Float(2, Type.FLOAT),
|
||||
String(3, Type.STRING),
|
||||
Chat(4, Type.COMPONENT),
|
||||
Slot(5, Type.ITEM),
|
||||
Slot(5, Type.ITEM1_8),
|
||||
Boolean(6, Type.BOOLEAN),
|
||||
Vector3F(7, Type.ROTATION),
|
||||
Position(8, Type.POSITION),
|
||||
OptPosition(9, Type.OPTIONAL_POSITION),
|
||||
Position(8, Type.POSITION1_8),
|
||||
OptPosition(9, Type.OPTIONAL_POSITION1_8),
|
||||
Direction(10, Type.VAR_INT),
|
||||
OptUUID(11, Type.OPTIONAL_UUID),
|
||||
BlockID(12, Type.VAR_INT);
|
||||
|
||||
+5
-5
@@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.ParticleType;
|
||||
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
|
||||
|
||||
public final class MetaTypes1_13 extends AbstractMetaTypes {
|
||||
|
||||
@@ -34,15 +34,15 @@ public final class MetaTypes1_13 extends AbstractMetaTypes {
|
||||
public final MetaType stringType = add(3, Type.STRING);
|
||||
public final MetaType componentType = add(4, Type.COMPONENT);
|
||||
public final MetaType optionalComponentType = add(5, Type.OPTIONAL_COMPONENT);
|
||||
public final MetaType itemType = add(6, Type.FLAT_ITEM);
|
||||
public final MetaType itemType = add(6, Type.ITEM1_13);
|
||||
public final MetaType booleanType = add(7, Type.BOOLEAN);
|
||||
public final MetaType rotationType = add(8, Type.ROTATION);
|
||||
public final MetaType positionType = add(9, Type.POSITION);
|
||||
public final MetaType optionalPositionType = add(10, Type.OPTIONAL_POSITION);
|
||||
public final MetaType positionType = add(9, Type.POSITION1_8);
|
||||
public final MetaType optionalPositionType = add(10, Type.OPTIONAL_POSITION1_8);
|
||||
public final MetaType directionType = add(11, Type.VAR_INT);
|
||||
public final MetaType optionalUUIDType = add(12, Type.OPTIONAL_UUID);
|
||||
public final MetaType blockStateType = add(13, Type.VAR_INT);
|
||||
public final MetaType nbtType = add(14, Type.NBT);
|
||||
public final MetaType nbtType = add(14, Type.NAMED_COMPOUND_TAG);
|
||||
public final MetaType particleType;
|
||||
|
||||
public MetaTypes1_13(final ParticleType particleType) {
|
||||
|
||||
+5
-5
@@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.ParticleType;
|
||||
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
|
||||
|
||||
public final class MetaTypes1_13_2 extends AbstractMetaTypes {
|
||||
|
||||
@@ -34,15 +34,15 @@ public final class MetaTypes1_13_2 extends AbstractMetaTypes {
|
||||
public final MetaType stringType = add(3, Type.STRING);
|
||||
public final MetaType componentType = add(4, Type.COMPONENT);
|
||||
public final MetaType optionalComponentType = add(5, Type.OPTIONAL_COMPONENT);
|
||||
public final MetaType itemType = add(6, Type.FLAT_VAR_INT_ITEM);
|
||||
public final MetaType itemType = add(6, Type.ITEM1_13_2);
|
||||
public final MetaType booleanType = add(7, Type.BOOLEAN);
|
||||
public final MetaType rotationType = add(8, Type.ROTATION);
|
||||
public final MetaType positionType = add(9, Type.POSITION);
|
||||
public final MetaType optionalPositionType = add(10, Type.OPTIONAL_POSITION);
|
||||
public final MetaType positionType = add(9, Type.POSITION1_8);
|
||||
public final MetaType optionalPositionType = add(10, Type.OPTIONAL_POSITION1_8);
|
||||
public final MetaType directionType = add(11, Type.VAR_INT);
|
||||
public final MetaType optionalUUIDType = add(12, Type.OPTIONAL_UUID);
|
||||
public final MetaType blockStateType = add(13, Type.VAR_INT);
|
||||
public final MetaType nbtType = add(14, Type.NBT);
|
||||
public final MetaType nbtType = add(14, Type.NAMED_COMPOUND_TAG);
|
||||
public final MetaType particleType;
|
||||
|
||||
public MetaTypes1_13_2(final ParticleType particleType) {
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.ParticleType;
|
||||
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
|
||||
|
||||
public final class MetaTypes1_14 extends AbstractMetaTypes {
|
||||
|
||||
@@ -34,7 +34,7 @@ public final class MetaTypes1_14 extends AbstractMetaTypes {
|
||||
public final MetaType stringType = add(3, Type.STRING);
|
||||
public final MetaType componentType = add(4, Type.COMPONENT);
|
||||
public final MetaType optionalComponentType = add(5, Type.OPTIONAL_COMPONENT);
|
||||
public final MetaType itemType = add(6, Type.FLAT_VAR_INT_ITEM);
|
||||
public final MetaType itemType = add(6, Type.ITEM1_13_2);
|
||||
public final MetaType booleanType = add(7, Type.BOOLEAN);
|
||||
public final MetaType rotationType = add(8, Type.ROTATION);
|
||||
public final MetaType positionType = add(9, Type.POSITION1_14);
|
||||
@@ -42,7 +42,7 @@ public final class MetaTypes1_14 extends AbstractMetaTypes {
|
||||
public final MetaType directionType = add(11, Type.VAR_INT);
|
||||
public final MetaType optionalUUIDType = add(12, Type.OPTIONAL_UUID);
|
||||
public final MetaType blockStateType = add(13, Type.VAR_INT);
|
||||
public final MetaType nbtType = add(14, Type.NBT);
|
||||
public final MetaType nbtType = add(14, Type.NAMED_COMPOUND_TAG);
|
||||
public final MetaType particleType;
|
||||
public final MetaType villagerDatatType = add(16, Type.VILLAGER_DATA);
|
||||
public final MetaType optionalVarIntType = add(17, Type.OPTIONAL_VAR_INT);
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.ParticleType;
|
||||
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
|
||||
|
||||
public final class MetaTypes1_19 extends AbstractMetaTypes {
|
||||
|
||||
@@ -34,7 +34,7 @@ public final class MetaTypes1_19 extends AbstractMetaTypes {
|
||||
public final MetaType stringType = add(3, Type.STRING);
|
||||
public final MetaType componentType = add(4, Type.COMPONENT);
|
||||
public final MetaType optionalComponentType = add(5, Type.OPTIONAL_COMPONENT);
|
||||
public final MetaType itemType = add(6, Type.FLAT_VAR_INT_ITEM);
|
||||
public final MetaType itemType = add(6, Type.ITEM1_13_2);
|
||||
public final MetaType booleanType = add(7, Type.BOOLEAN);
|
||||
public final MetaType rotationType = add(8, Type.ROTATION);
|
||||
public final MetaType positionType = add(9, Type.POSITION1_14);
|
||||
@@ -42,7 +42,7 @@ public final class MetaTypes1_19 extends AbstractMetaTypes {
|
||||
public final MetaType directionType = add(11, Type.VAR_INT);
|
||||
public final MetaType optionalUUIDType = add(12, Type.OPTIONAL_UUID);
|
||||
public final MetaType blockStateType = add(13, Type.VAR_INT);
|
||||
public final MetaType nbtType = add(14, Type.NBT);
|
||||
public final MetaType nbtType = add(14, Type.NAMED_COMPOUND_TAG);
|
||||
public final MetaType particleType;
|
||||
public final MetaType villagerDatatType = add(16, Type.VILLAGER_DATA);
|
||||
public final MetaType optionalVarIntType = add(17, Type.OPTIONAL_VAR_INT);
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.ParticleType;
|
||||
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
|
||||
|
||||
public final class MetaTypes1_19_3 extends AbstractMetaTypes {
|
||||
|
||||
@@ -35,7 +35,7 @@ public final class MetaTypes1_19_3 extends AbstractMetaTypes {
|
||||
public final MetaType stringType = add(4, Type.STRING);
|
||||
public final MetaType componentType = add(5, Type.COMPONENT);
|
||||
public final MetaType optionalComponentType = add(6, Type.OPTIONAL_COMPONENT);
|
||||
public final MetaType itemType = add(7, Type.FLAT_VAR_INT_ITEM);
|
||||
public final MetaType itemType = add(7, Type.ITEM1_13_2);
|
||||
public final MetaType booleanType = add(8, Type.BOOLEAN);
|
||||
public final MetaType rotationType = add(9, Type.ROTATION);
|
||||
public final MetaType positionType = add(10, Type.POSITION1_14);
|
||||
@@ -43,7 +43,7 @@ public final class MetaTypes1_19_3 extends AbstractMetaTypes {
|
||||
public final MetaType directionType = add(12, Type.VAR_INT);
|
||||
public final MetaType optionalUUIDType = add(13, Type.OPTIONAL_UUID);
|
||||
public final MetaType blockStateType = add(14, Type.VAR_INT);
|
||||
public final MetaType nbtType = add(15, Type.NBT);
|
||||
public final MetaType nbtType = add(15, Type.NAMED_COMPOUND_TAG);
|
||||
public final MetaType particleType;
|
||||
public final MetaType villagerDatatType = add(17, Type.VILLAGER_DATA);
|
||||
public final MetaType optionalVarIntType = add(18, Type.OPTIONAL_VAR_INT);
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@ package com.viaversion.viaversion.api.minecraft.metadata.types;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.ParticleType;
|
||||
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
|
||||
|
||||
public final class MetaTypes1_19_4 extends AbstractMetaTypes {
|
||||
|
||||
@@ -35,7 +35,7 @@ public final class MetaTypes1_19_4 extends AbstractMetaTypes {
|
||||
public final MetaType stringType = add(4, Type.STRING);
|
||||
public final MetaType componentType = add(5, Type.COMPONENT);
|
||||
public final MetaType optionalComponentType = add(6, Type.OPTIONAL_COMPONENT);
|
||||
public final MetaType itemType = add(7, Type.FLAT_VAR_INT_ITEM);
|
||||
public final MetaType itemType = add(7, Type.ITEM1_13_2);
|
||||
public final MetaType booleanType = add(8, Type.BOOLEAN);
|
||||
public final MetaType rotationType = add(9, Type.ROTATION);
|
||||
public final MetaType positionType = add(10, Type.POSITION1_14);
|
||||
@@ -44,7 +44,7 @@ public final class MetaTypes1_19_4 extends AbstractMetaTypes {
|
||||
public final MetaType optionalUUIDType = add(13, Type.OPTIONAL_UUID);
|
||||
public final MetaType blockStateType = add(14, Type.VAR_INT);
|
||||
public final MetaType optionalBlockStateType = add(15, Type.VAR_INT);
|
||||
public final MetaType nbtType = add(16, Type.NBT);
|
||||
public final MetaType nbtType = add(16, Type.NAMED_COMPOUND_TAG);
|
||||
public final MetaType particleType;
|
||||
public final MetaType villagerDatatType = add(18, Type.VILLAGER_DATA);
|
||||
public final MetaType optionalVarIntType = add(19, Type.OPTIONAL_VAR_INT);
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.metadata.types;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
|
||||
|
||||
public final class MetaTypes1_20_2 extends AbstractMetaTypes {
|
||||
|
||||
public final MetaType byteType = add(0, Type.BYTE);
|
||||
public final MetaType varIntType = add(1, Type.VAR_INT);
|
||||
public final MetaType longType = add(2, Type.VAR_LONG);
|
||||
public final MetaType floatType = add(3, Type.FLOAT);
|
||||
public final MetaType stringType = add(4, Type.STRING);
|
||||
public final MetaType componentType = add(5, Type.COMPONENT);
|
||||
public final MetaType optionalComponentType = add(6, Type.OPTIONAL_COMPONENT);
|
||||
public final MetaType itemType = add(7, Type.ITEM1_20_2);
|
||||
public final MetaType booleanType = add(8, Type.BOOLEAN);
|
||||
public final MetaType rotationType = add(9, Type.ROTATION);
|
||||
public final MetaType positionType = add(10, Type.POSITION1_14);
|
||||
public final MetaType optionalPositionType = add(11, Type.OPTIONAL_POSITION_1_14);
|
||||
public final MetaType directionType = add(12, Type.VAR_INT);
|
||||
public final MetaType optionalUUIDType = add(13, Type.OPTIONAL_UUID);
|
||||
public final MetaType blockStateType = add(14, Type.VAR_INT);
|
||||
public final MetaType optionalBlockStateType = add(15, Type.VAR_INT);
|
||||
public final MetaType nbtType = add(16, Type.COMPOUND_TAG);
|
||||
public final MetaType particleType;
|
||||
public final MetaType villagerDatatType = add(18, Type.VILLAGER_DATA);
|
||||
public final MetaType optionalVarIntType = add(19, Type.OPTIONAL_VAR_INT);
|
||||
public final MetaType poseType = add(20, Type.VAR_INT);
|
||||
public final MetaType catVariantType = add(21, Type.VAR_INT);
|
||||
public final MetaType frogVariantType = add(22, Type.VAR_INT);
|
||||
public final MetaType optionalGlobalPosition = add(23, Type.OPTIONAL_GLOBAL_POSITION);
|
||||
public final MetaType paintingVariantType = add(24, Type.VAR_INT);
|
||||
public final MetaType snifferState = add(25, Type.VAR_INT);
|
||||
public final MetaType vectorType = add(26, Type.VECTOR3F);
|
||||
public final MetaType quaternionType = add(27, Type.QUATERNION);
|
||||
|
||||
public MetaTypes1_20_2(final ParticleType particleType) {
|
||||
super(28);
|
||||
this.particleType = add(17, particleType);
|
||||
}
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.metadata.types;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.misc.ParticleType;
|
||||
|
||||
public final class MetaTypes1_20_3 extends AbstractMetaTypes {
|
||||
|
||||
public final MetaType byteType = add(0, Type.BYTE);
|
||||
public final MetaType varIntType = add(1, Type.VAR_INT);
|
||||
public final MetaType longType = add(2, Type.VAR_LONG);
|
||||
public final MetaType floatType = add(3, Type.FLOAT);
|
||||
public final MetaType stringType = add(4, Type.STRING);
|
||||
public final MetaType componentType = add(5, Type.TAG);
|
||||
public final MetaType optionalComponentType = add(6, Type.OPTIONAL_TAG);
|
||||
public final MetaType itemType = add(7, Type.ITEM1_20_2);
|
||||
public final MetaType booleanType = add(8, Type.BOOLEAN);
|
||||
public final MetaType rotationType = add(9, Type.ROTATION);
|
||||
public final MetaType positionType = add(10, Type.POSITION1_14);
|
||||
public final MetaType optionalPositionType = add(11, Type.OPTIONAL_POSITION_1_14);
|
||||
public final MetaType directionType = add(12, Type.VAR_INT);
|
||||
public final MetaType optionalUUIDType = add(13, Type.OPTIONAL_UUID);
|
||||
public final MetaType blockStateType = add(14, Type.VAR_INT);
|
||||
public final MetaType optionalBlockStateType = add(15, Type.VAR_INT);
|
||||
public final MetaType nbtType = add(16, Type.COMPOUND_TAG);
|
||||
public final MetaType particleType;
|
||||
public final MetaType villagerDatatType = add(18, Type.VILLAGER_DATA);
|
||||
public final MetaType optionalVarIntType = add(19, Type.OPTIONAL_VAR_INT);
|
||||
public final MetaType poseType = add(20, Type.VAR_INT);
|
||||
public final MetaType catVariantType = add(21, Type.VAR_INT);
|
||||
public final MetaType frogVariantType = add(22, Type.VAR_INT);
|
||||
public final MetaType optionalGlobalPosition = add(23, Type.OPTIONAL_GLOBAL_POSITION);
|
||||
public final MetaType paintingVariantType = add(24, Type.VAR_INT);
|
||||
public final MetaType snifferState = add(25, Type.VAR_INT);
|
||||
public final MetaType vectorType = add(26, Type.VECTOR3F);
|
||||
public final MetaType quaternionType = add(27, Type.QUATERNION);
|
||||
|
||||
public MetaTypes1_20_3(final ParticleType particleType) {
|
||||
super(28);
|
||||
this.particleType = add(17, particleType);
|
||||
}
|
||||
}
|
||||
@@ -1,216 +0,0 @@
|
||||
/*
|
||||
* This file is part of adventure, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2017-2020 KyoriPowered
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.nbt;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
import java.util.zip.GZIPOutputStream;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
// Specific Via changes:
|
||||
// - Use OpenNBT tags
|
||||
// - Added readString/writeString methods from TagStringIO
|
||||
// - Has not been updated for the sake of keeping the class simple
|
||||
|
||||
/**
|
||||
* Serialization operations for binary tags.
|
||||
*/
|
||||
public final class BinaryTagIO {
|
||||
private BinaryTagIO() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a compound tag from {@code path}.
|
||||
*
|
||||
* @param path the path
|
||||
* @return the compound tag
|
||||
* @throws IOException if an exception was encountered while reading a compound tag
|
||||
*/
|
||||
public static @NonNull CompoundTag readPath(final @NonNull Path path) throws IOException {
|
||||
return readInputStream(Files.newInputStream(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a compound tag from an input stream.
|
||||
*
|
||||
* @param input the input stream
|
||||
* @return the compound tag
|
||||
* @throws IOException if an exception was encountered while reading a compound tag
|
||||
*/
|
||||
public static @NonNull CompoundTag readInputStream(final @NonNull InputStream input) throws IOException {
|
||||
try (final DataInputStream dis = new DataInputStream(input)) {
|
||||
return readDataInput(dis);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a compound tag from {@code path} using GZIP decompression.
|
||||
*
|
||||
* @param path the path
|
||||
* @return the compound tag
|
||||
* @throws IOException if an exception was encountered while reading a compound tag
|
||||
*/
|
||||
public static @NonNull CompoundTag readCompressedPath(final @NonNull Path path) throws IOException {
|
||||
return readCompressedInputStream(Files.newInputStream(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a compound tag from an input stream using GZIP decompression.
|
||||
*
|
||||
* @param input the input stream
|
||||
* @return the compound tag
|
||||
* @throws IOException if an exception was encountered while reading a compound tag
|
||||
*/
|
||||
public static @NonNull CompoundTag readCompressedInputStream(final @NonNull InputStream input) throws IOException {
|
||||
try (final DataInputStream dis = new DataInputStream(new BufferedInputStream(new GZIPInputStream(input)))) {
|
||||
return readDataInput(dis);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a compound tag from {@code input}.
|
||||
*
|
||||
* @param input the input
|
||||
* @return the compound tag
|
||||
* @throws IOException if an exception was encountered while reading a compound tag
|
||||
*/
|
||||
public static @NonNull CompoundTag readDataInput(final @NonNull DataInput input) throws IOException {
|
||||
byte type = input.readByte();
|
||||
if (type != CompoundTag.ID) {
|
||||
throw new IOException(String.format("Expected root tag to be a CompoundTag, was %s", type));
|
||||
}
|
||||
input.skipBytes(input.readUnsignedShort()); // read empty name
|
||||
|
||||
final CompoundTag compoundTag = new CompoundTag();
|
||||
compoundTag.read(input);
|
||||
return compoundTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a compound tag to {@code path}.
|
||||
*
|
||||
* @param tag the compound tag
|
||||
* @param path the path
|
||||
* @throws IOException if an exception was encountered while writing the compound tag
|
||||
*/
|
||||
public static void writePath(final @NonNull CompoundTag tag, final @NonNull Path path) throws IOException {
|
||||
writeOutputStream(tag, Files.newOutputStream(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a compound tag to an output stream.
|
||||
*
|
||||
* @param tag the compound tag
|
||||
* @param output the output stream
|
||||
* @throws IOException if an exception was encountered while writing the compound tag
|
||||
*/
|
||||
public static void writeOutputStream(final @NonNull CompoundTag tag, final @NonNull OutputStream output) throws IOException {
|
||||
try (final DataOutputStream dos = new DataOutputStream(output)) {
|
||||
writeDataOutput(tag, dos);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a compound tag to {@code path} using GZIP compression.
|
||||
*
|
||||
* @param tag the compound tag
|
||||
* @param path the path
|
||||
* @throws IOException if an exception was encountered while writing the compound tag
|
||||
*/
|
||||
public static void writeCompressedPath(final @NonNull CompoundTag tag, final @NonNull Path path) throws IOException {
|
||||
writeCompressedOutputStream(tag, Files.newOutputStream(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a compound tag to an output stream using GZIP compression.
|
||||
*
|
||||
* @param tag the compound tag
|
||||
* @param output the output stream
|
||||
* @throws IOException if an exception was encountered while writing the compound tag
|
||||
*/
|
||||
public static void writeCompressedOutputStream(final @NonNull CompoundTag tag, final @NonNull OutputStream output) throws IOException {
|
||||
try (final DataOutputStream dos = new DataOutputStream(new GZIPOutputStream(output))) {
|
||||
writeDataOutput(tag, dos);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a compound tag to {@code output}.
|
||||
*
|
||||
* @param tag the compound tag
|
||||
* @param output the output
|
||||
* @throws IOException if an exception was encountered while writing the compound tag
|
||||
*/
|
||||
public static void writeDataOutput(final @NonNull CompoundTag tag, final @NonNull DataOutput output) throws IOException {
|
||||
output.writeByte(CompoundTag.ID);
|
||||
output.writeUTF(""); // write empty name
|
||||
tag.write(output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a compound tag from a {@link String}.
|
||||
*
|
||||
* @param input the string
|
||||
* @return the compound tag
|
||||
* @throws IOException if an exception was encountered while reading a compound tag
|
||||
*/
|
||||
public static @NonNull CompoundTag readString(final @NonNull String input) throws IOException {
|
||||
try {
|
||||
final CharBuffer buffer = new CharBuffer(input);
|
||||
final TagStringReader parser = new TagStringReader(buffer);
|
||||
final CompoundTag tag = parser.compound();
|
||||
if (buffer.skipWhitespace().hasMore()) {
|
||||
throw new IOException("Document had trailing content after first CompoundTag");
|
||||
}
|
||||
return tag;
|
||||
} catch (final StringTagParseException ex) {
|
||||
throw new IOException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes a compound tag to a {@link String}.
|
||||
*
|
||||
* @param tag the compound tag
|
||||
* @return the string
|
||||
* @throws IOException if an exception was encountered while writing the compound tag
|
||||
*/
|
||||
public static @NonNull String writeString(final @NonNull CompoundTag tag) throws IOException {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
try (final TagStringWriter emit = new TagStringWriter(sb)) {
|
||||
emit.writeTag(tag);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,144 +0,0 @@
|
||||
/*
|
||||
* This file is part of adventure, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2017-2021 KyoriPowered
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.nbt;
|
||||
|
||||
/**
|
||||
* A character buffer designed to be inspected by a parser.
|
||||
*/
|
||||
final class CharBuffer {
|
||||
private final CharSequence sequence;
|
||||
private int index;
|
||||
|
||||
CharBuffer(final CharSequence sequence) {
|
||||
this.sequence = sequence;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the character at the current position.
|
||||
*
|
||||
* @return The current character
|
||||
*/
|
||||
public char peek() {
|
||||
return this.sequence.charAt(this.index);
|
||||
}
|
||||
|
||||
public char peek(final int offset) {
|
||||
return this.sequence.charAt(this.index + offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current character and advance.
|
||||
*
|
||||
* @return current character
|
||||
*/
|
||||
public char take() {
|
||||
return this.sequence.charAt(this.index++);
|
||||
}
|
||||
|
||||
public boolean advance() {
|
||||
this.index++;
|
||||
return this.hasMore();
|
||||
}
|
||||
|
||||
public boolean hasMore() {
|
||||
return this.index < this.sequence.length();
|
||||
}
|
||||
|
||||
public boolean hasMore(final int offset) {
|
||||
return this.index + offset < this.sequence.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for the provided token, and advance the reader index past the {@code until} character.
|
||||
*
|
||||
* @param until Case-insensitive token
|
||||
* @return the string starting at the current position (inclusive) and going until the location of {@code until}, exclusive
|
||||
*/
|
||||
public CharSequence takeUntil(char until) throws StringTagParseException {
|
||||
until = Character.toLowerCase(until);
|
||||
int endIdx = -1;
|
||||
for (int idx = this.index; idx < this.sequence.length(); ++idx) {
|
||||
if (this.sequence.charAt(idx) == Tokens.ESCAPE_MARKER) {
|
||||
idx++;
|
||||
} else if (Character.toLowerCase(this.sequence.charAt(idx)) == until) {
|
||||
endIdx = idx;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (endIdx == -1) {
|
||||
throw this.makeError("No occurrence of " + until + " was found");
|
||||
}
|
||||
|
||||
final CharSequence result = this.sequence.subSequence(this.index, endIdx);
|
||||
this.index = endIdx + 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert that the next non-whitespace character is the provided parameter.
|
||||
*
|
||||
* <p>If the assertion is successful, the token will be consumed.</p>
|
||||
*
|
||||
* @param expectedChar expected character
|
||||
* @return this
|
||||
* @throws StringTagParseException if EOF or non-matching value is found
|
||||
*/
|
||||
public CharBuffer expect(final char expectedChar) throws StringTagParseException {
|
||||
this.skipWhitespace();
|
||||
if (!this.hasMore()) {
|
||||
throw this.makeError("Expected character '" + expectedChar + "' but got EOF");
|
||||
}
|
||||
if (this.peek() != expectedChar) {
|
||||
throw this.makeError("Expected character '" + expectedChar + "' but got '" + this.peek() + "'");
|
||||
}
|
||||
this.take();
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the next non-whitespace character is {@code token}, advance past it.
|
||||
*
|
||||
* <p>This method always consumes whitespace.</p>
|
||||
*
|
||||
* @param token next non-whitespace character to query
|
||||
* @return if the next non-whitespace character is {@code token}
|
||||
*/
|
||||
public boolean takeIf(final char token) {
|
||||
this.skipWhitespace();
|
||||
if (this.hasMore() && this.peek() == token) {
|
||||
this.advance();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public CharBuffer skipWhitespace() {
|
||||
while (this.hasMore() && Character.isWhitespace(this.peek())) this.advance();
|
||||
return this;
|
||||
}
|
||||
|
||||
public StringTagParseException makeError(final String message) {
|
||||
return new StringTagParseException(message, this.sequence, this.index);
|
||||
}
|
||||
}
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* This file is part of adventure, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2017-2020 KyoriPowered
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.nbt;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* An exception thrown when parsing a string tag.
|
||||
*/
|
||||
class StringTagParseException extends IOException {
|
||||
private static final long serialVersionUID = -3001637554903912905L;
|
||||
private final CharSequence buffer;
|
||||
private final int position;
|
||||
|
||||
public StringTagParseException(final String message, final CharSequence buffer, final int position) {
|
||||
super(message);
|
||||
this.buffer = buffer;
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return super.getMessage() + "(at position " + this.position + ")";
|
||||
}
|
||||
}
|
||||
@@ -1,358 +0,0 @@
|
||||
/*
|
||||
* This file is part of adventure, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2017-2021 KyoriPowered
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.nbt;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.DoubleTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.FloatTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.LongTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ShortTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
import it.unimi.dsi.fastutil.ints.IntList;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.LongStream;
|
||||
|
||||
// Specific Via changes:
|
||||
// - Use OpenNBT tags
|
||||
// - Small byteArray() optimization
|
||||
// - acceptLegacy = true by default
|
||||
final class TagStringReader {
|
||||
private static final int MAX_DEPTH = 512;
|
||||
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
|
||||
private static final int[] EMPTY_INT_ARRAY = new int[0];
|
||||
private static final long[] EMPTY_LONG_ARRAY = new long[0];
|
||||
|
||||
private final CharBuffer buffer;
|
||||
private boolean acceptLegacy = true; // Via - always true
|
||||
private int depth;
|
||||
|
||||
TagStringReader(final CharBuffer buffer) {
|
||||
this.buffer = buffer;
|
||||
}
|
||||
|
||||
public CompoundTag compound() throws StringTagParseException {
|
||||
this.buffer.expect(Tokens.COMPOUND_BEGIN);
|
||||
final CompoundTag compoundTag = new CompoundTag();
|
||||
if (this.buffer.takeIf(Tokens.COMPOUND_END)) {
|
||||
return compoundTag;
|
||||
}
|
||||
|
||||
while (this.buffer.hasMore()) {
|
||||
compoundTag.put(this.key(), this.tag());
|
||||
if (this.separatorOrCompleteWith(Tokens.COMPOUND_END)) {
|
||||
return compoundTag;
|
||||
}
|
||||
}
|
||||
throw this.buffer.makeError("Unterminated compound tag!");
|
||||
}
|
||||
|
||||
public ListTag list() throws StringTagParseException {
|
||||
final ListTag listTag = new ListTag();
|
||||
this.buffer.expect(Tokens.ARRAY_BEGIN);
|
||||
final boolean prefixedIndex = this.acceptLegacy && this.buffer.peek() == '0' && this.buffer.peek(1) == ':';
|
||||
if (!prefixedIndex && this.buffer.takeIf(Tokens.ARRAY_END)) {
|
||||
return listTag;
|
||||
}
|
||||
while (this.buffer.hasMore()) {
|
||||
if (prefixedIndex) {
|
||||
this.buffer.takeUntil(':');
|
||||
}
|
||||
|
||||
final Tag next = this.tag();
|
||||
listTag.add(next);
|
||||
if (this.separatorOrCompleteWith(Tokens.ARRAY_END)) {
|
||||
return listTag;
|
||||
}
|
||||
}
|
||||
throw this.buffer.makeError("Reached end of file without end of list tag!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Similar to a list tag in syntax, but returning a single array tag rather than a list of tags.
|
||||
*
|
||||
* @return array-typed tag
|
||||
*/
|
||||
public Tag array(char elementType) throws StringTagParseException {
|
||||
this.buffer.expect(Tokens.ARRAY_BEGIN)
|
||||
.expect(elementType)
|
||||
.expect(Tokens.ARRAY_SIGNATURE_SEPARATOR);
|
||||
|
||||
elementType = Character.toLowerCase(elementType);
|
||||
if (elementType == Tokens.TYPE_BYTE) {
|
||||
return new ByteArrayTag(this.byteArray());
|
||||
} else if (elementType == Tokens.TYPE_INT) {
|
||||
return new IntArrayTag(this.intArray());
|
||||
} else if (elementType == Tokens.TYPE_LONG) {
|
||||
return new LongArrayTag(this.longArray());
|
||||
} else {
|
||||
throw this.buffer.makeError("Type " + elementType + " is not a valid element type in an array!");
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] byteArray() throws StringTagParseException {
|
||||
if (this.buffer.takeIf(Tokens.ARRAY_END)) {
|
||||
return EMPTY_BYTE_ARRAY;
|
||||
}
|
||||
|
||||
final IntList bytes = new IntArrayList(); // Via - no boxing
|
||||
while (this.buffer.hasMore()) {
|
||||
final CharSequence value = this.buffer.skipWhitespace().takeUntil(Tokens.TYPE_BYTE);
|
||||
try {
|
||||
bytes.add(Byte.parseByte(value.toString())); // Via
|
||||
} catch (final NumberFormatException ex) {
|
||||
throw this.buffer.makeError("All elements of a byte array must be bytes!");
|
||||
}
|
||||
|
||||
if (this.separatorOrCompleteWith(Tokens.ARRAY_END)) {
|
||||
final byte[] result = new byte[bytes.size()];
|
||||
for (int i = 0; i < bytes.size(); ++i) {
|
||||
result[i] = (byte) bytes.getInt(i); // Via
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
throw this.buffer.makeError("Reached end of document without array close");
|
||||
}
|
||||
|
||||
private int[] intArray() throws StringTagParseException {
|
||||
if (this.buffer.takeIf(Tokens.ARRAY_END)) {
|
||||
return EMPTY_INT_ARRAY;
|
||||
}
|
||||
|
||||
final IntStream.Builder builder = IntStream.builder();
|
||||
while (this.buffer.hasMore()) {
|
||||
final Tag value = this.tag();
|
||||
if (!(value instanceof IntTag)) {
|
||||
throw this.buffer.makeError("All elements of an int array must be ints!");
|
||||
}
|
||||
builder.add(((NumberTag) value).asInt());
|
||||
if (this.separatorOrCompleteWith(Tokens.ARRAY_END)) {
|
||||
return builder.build().toArray();
|
||||
}
|
||||
}
|
||||
throw this.buffer.makeError("Reached end of document without array close");
|
||||
}
|
||||
|
||||
private long[] longArray() throws StringTagParseException {
|
||||
if (this.buffer.takeIf(Tokens.ARRAY_END)) {
|
||||
return EMPTY_LONG_ARRAY;
|
||||
}
|
||||
|
||||
final LongStream.Builder longs = LongStream.builder();
|
||||
while (this.buffer.hasMore()) {
|
||||
final CharSequence value = this.buffer.skipWhitespace().takeUntil(Tokens.TYPE_LONG);
|
||||
try {
|
||||
longs.add(Long.parseLong(value.toString()));
|
||||
} catch (final NumberFormatException ex) {
|
||||
throw this.buffer.makeError("All elements of a long array must be longs!");
|
||||
}
|
||||
|
||||
if (this.separatorOrCompleteWith(Tokens.ARRAY_END)) {
|
||||
return longs.build().toArray();
|
||||
}
|
||||
}
|
||||
throw this.buffer.makeError("Reached end of document without array close");
|
||||
}
|
||||
|
||||
public String key() throws StringTagParseException {
|
||||
this.buffer.skipWhitespace();
|
||||
final char starChar = this.buffer.peek();
|
||||
try {
|
||||
if (starChar == Tokens.SINGLE_QUOTE || starChar == Tokens.DOUBLE_QUOTE) {
|
||||
return unescape(this.buffer.takeUntil(this.buffer.take()).toString());
|
||||
}
|
||||
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
while (this.buffer.hasMore()) {
|
||||
final char peek = this.buffer.peek();
|
||||
if (!Tokens.id(peek)) {
|
||||
if (this.acceptLegacy) {
|
||||
// In legacy format, a key is any non-colon character, with escapes allowed
|
||||
if (peek == Tokens.ESCAPE_MARKER) {
|
||||
this.buffer.take(); // skip
|
||||
continue;
|
||||
} else if (peek != Tokens.COMPOUND_KEY_TERMINATOR) {
|
||||
builder.append(this.buffer.take());
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
builder.append(this.buffer.take());
|
||||
}
|
||||
return builder.toString();
|
||||
} finally {
|
||||
this.buffer.expect(Tokens.COMPOUND_KEY_TERMINATOR);
|
||||
}
|
||||
}
|
||||
|
||||
public Tag tag() throws StringTagParseException {
|
||||
if (this.depth++ > MAX_DEPTH) {
|
||||
throw this.buffer.makeError("Exceeded maximum allowed depth of " + MAX_DEPTH + " when reading tag");
|
||||
}
|
||||
try {
|
||||
final char startToken = this.buffer.skipWhitespace().peek();
|
||||
switch (startToken) {
|
||||
case Tokens.COMPOUND_BEGIN:
|
||||
return this.compound();
|
||||
case Tokens.ARRAY_BEGIN:
|
||||
// Maybe add in a legacy-only mode to read those?
|
||||
if (this.buffer.hasMore(2) && this.buffer.peek(2) == ';') { // we know we're an array tag
|
||||
return this.array(this.buffer.peek(1));
|
||||
} else {
|
||||
return this.list();
|
||||
}
|
||||
case Tokens.SINGLE_QUOTE:
|
||||
case Tokens.DOUBLE_QUOTE:
|
||||
// definitely a string tag
|
||||
this.buffer.advance();
|
||||
return new StringTag(unescape(this.buffer.takeUntil(startToken).toString()));
|
||||
default: // scalar
|
||||
return this.scalar();
|
||||
}
|
||||
} finally {
|
||||
this.depth--;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A tag that is definitely some sort of scalar.
|
||||
*
|
||||
* <p>Does not detect quoted strings, so those should have been parsed already.</p>
|
||||
*
|
||||
* @return a parsed tag
|
||||
*/
|
||||
private Tag scalar() {
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
int noLongerNumericAt = -1;
|
||||
while (this.buffer.hasMore()) {
|
||||
char current = this.buffer.peek();
|
||||
if (current == '\\') { // escape -- we are significantly more lenient than original format at the moment
|
||||
this.buffer.advance();
|
||||
current = this.buffer.take();
|
||||
} else if (Tokens.id(current)) {
|
||||
this.buffer.advance();
|
||||
} else { // end of value
|
||||
break;
|
||||
}
|
||||
builder.append(current);
|
||||
if (noLongerNumericAt == -1 && !Tokens.numeric(current)) {
|
||||
noLongerNumericAt = builder.length();
|
||||
}
|
||||
}
|
||||
|
||||
final int length = builder.length();
|
||||
final String built = builder.toString();
|
||||
if (noLongerNumericAt == length) {
|
||||
final char last = built.charAt(length - 1);
|
||||
try {
|
||||
switch (Character.toLowerCase(last)) { // try to read and return as a number
|
||||
case Tokens.TYPE_BYTE:
|
||||
return new ByteTag(Byte.parseByte(built.substring(0, length - 1)));
|
||||
case Tokens.TYPE_SHORT:
|
||||
return new ShortTag(Short.parseShort(built.substring(0, length - 1)));
|
||||
case Tokens.TYPE_INT:
|
||||
return new IntTag(Integer.parseInt(built.substring(0, length - 1)));
|
||||
case Tokens.TYPE_LONG:
|
||||
return new LongTag(Long.parseLong(built.substring(0, length - 1)));
|
||||
case Tokens.TYPE_FLOAT:
|
||||
final float floatValue = Float.parseFloat(built.substring(0, length - 1));
|
||||
if (Float.isFinite(floatValue)) { // don't accept NaN and Infinity
|
||||
return new FloatTag(floatValue);
|
||||
}
|
||||
break;
|
||||
case Tokens.TYPE_DOUBLE:
|
||||
final double doubleValue = Double.parseDouble(built.substring(0, length - 1));
|
||||
if (Double.isFinite(doubleValue)) { // don't accept NaN and Infinity
|
||||
return new DoubleTag(doubleValue);
|
||||
}
|
||||
break;
|
||||
}
|
||||
} catch (final NumberFormatException ignored) {
|
||||
}
|
||||
} else if (noLongerNumericAt == -1) { // if we run out of content without an explicit value separator, then we're either an integer or string tag -- all others have a character at the end
|
||||
try {
|
||||
return new IntTag(Integer.parseInt(built));
|
||||
} catch (final NumberFormatException ex) {
|
||||
if (built.indexOf('.') != -1) {
|
||||
try {
|
||||
return new DoubleTag(Double.parseDouble(built));
|
||||
} catch (final NumberFormatException ex2) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (built.equalsIgnoreCase(Tokens.LITERAL_TRUE)) {
|
||||
return new ByteTag((byte) 1);
|
||||
} else if (built.equalsIgnoreCase(Tokens.LITERAL_FALSE)) {
|
||||
return new ByteTag((byte) 0);
|
||||
}
|
||||
return new StringTag(built);
|
||||
|
||||
}
|
||||
|
||||
private boolean separatorOrCompleteWith(final char endCharacter) throws StringTagParseException {
|
||||
if (this.buffer.takeIf(endCharacter)) {
|
||||
return true;
|
||||
}
|
||||
this.buffer.expect(Tokens.VALUE_SEPARATOR);
|
||||
return this.buffer.takeIf(endCharacter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove simple escape sequences from a string.
|
||||
*
|
||||
* @param withEscapes input string with escapes
|
||||
* @return string with escapes processed
|
||||
*/
|
||||
private static String unescape(final String withEscapes) {
|
||||
int escapeIdx = withEscapes.indexOf(Tokens.ESCAPE_MARKER);
|
||||
if (escapeIdx == -1) { // nothing to unescape
|
||||
return withEscapes;
|
||||
}
|
||||
int lastEscape = 0;
|
||||
final StringBuilder output = new StringBuilder(withEscapes.length());
|
||||
do {
|
||||
output.append(withEscapes, lastEscape, escapeIdx);
|
||||
lastEscape = escapeIdx + 1;
|
||||
} while ((escapeIdx = withEscapes.indexOf(Tokens.ESCAPE_MARKER, lastEscape + 1)) != -1); // add one extra character to make sure we don't include escaped backslashes
|
||||
output.append(withEscapes.substring(lastEscape));
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
public void legacy(final boolean acceptLegacy) {
|
||||
this.acceptLegacy = acceptLegacy;
|
||||
}
|
||||
}
|
||||
@@ -1,261 +0,0 @@
|
||||
/*
|
||||
* This file is part of adventure, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2017-2020 KyoriPowered
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.nbt;
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteArrayTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ByteTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.DoubleTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.FloatTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.IntArrayTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.IntTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ListTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.LongTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.NumberTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.ShortTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.Map;
|
||||
|
||||
// Specific Via changes:
|
||||
// - Use OpenNBT tags
|
||||
// - Has not been updated to support pretty printing and legacy writing since that is not needed
|
||||
|
||||
/**
|
||||
* An emitter for the SNBT format.
|
||||
*
|
||||
* <p>Details on the format are described in the package documentation.</p>
|
||||
*/
|
||||
final class TagStringWriter implements AutoCloseable {
|
||||
private final Appendable out;
|
||||
private int level;
|
||||
/**
|
||||
* Whether a {@link Tokens#VALUE_SEPARATOR} needs to be printed before the beginning of the next object.
|
||||
*/
|
||||
private boolean needsSeparator;
|
||||
|
||||
public TagStringWriter(final Appendable out) {
|
||||
this.out = out;
|
||||
}
|
||||
|
||||
// NBT-specific
|
||||
|
||||
public TagStringWriter writeTag(final Tag tag) throws IOException {
|
||||
if (tag instanceof CompoundTag) {
|
||||
return this.writeCompound((CompoundTag) tag);
|
||||
} else if (tag instanceof ListTag) {
|
||||
return this.writeList((ListTag) tag);
|
||||
} else if (tag instanceof ByteArrayTag) {
|
||||
return this.writeByteArray((ByteArrayTag) tag);
|
||||
} else if (tag instanceof IntArrayTag) {
|
||||
return this.writeIntArray((IntArrayTag) tag);
|
||||
} else if (tag instanceof LongArrayTag) {
|
||||
return this.writeLongArray((LongArrayTag) tag);
|
||||
} else if (tag instanceof StringTag) {
|
||||
return this.value(((StringTag) tag).getValue(), Tokens.EOF);
|
||||
} else if (tag instanceof ByteTag) {
|
||||
return this.value(Byte.toString(((NumberTag) tag).asByte()), Tokens.TYPE_BYTE);
|
||||
} else if (tag instanceof ShortTag) {
|
||||
return this.value(Short.toString(((NumberTag) tag).asShort()), Tokens.TYPE_SHORT);
|
||||
} else if (tag instanceof IntTag) {
|
||||
return this.value(Integer.toString(((NumberTag) tag).asInt()), Tokens.TYPE_INT);
|
||||
} else if (tag instanceof LongTag) {
|
||||
return this.value(Long.toString(((NumberTag) tag).asLong()), Character.toUpperCase(Tokens.TYPE_LONG)); // special case
|
||||
} else if (tag instanceof FloatTag) {
|
||||
return this.value(Float.toString(((NumberTag) tag).asFloat()), Tokens.TYPE_FLOAT);
|
||||
} else if (tag instanceof DoubleTag) {
|
||||
return this.value(Double.toString(((NumberTag) tag).asDouble()), Tokens.TYPE_DOUBLE);
|
||||
} else {
|
||||
throw new IOException("Unknown tag type: " + tag.getClass().getSimpleName());
|
||||
// unknown!
|
||||
}
|
||||
}
|
||||
|
||||
private TagStringWriter writeCompound(final CompoundTag tag) throws IOException {
|
||||
this.beginCompound();
|
||||
for (final Map.Entry<String, Tag> entry : tag.entrySet()) {
|
||||
this.key(entry.getKey());
|
||||
this.writeTag(entry.getValue());
|
||||
}
|
||||
this.endCompound();
|
||||
return this;
|
||||
}
|
||||
|
||||
private TagStringWriter writeList(final ListTag tag) throws IOException {
|
||||
this.beginList();
|
||||
for (final Tag el : tag) {
|
||||
this.printAndResetSeparator();
|
||||
this.writeTag(el);
|
||||
}
|
||||
this.endList();
|
||||
return this;
|
||||
}
|
||||
|
||||
private TagStringWriter writeByteArray(final ByteArrayTag tag) throws IOException {
|
||||
this.beginArray(Tokens.TYPE_BYTE);
|
||||
|
||||
final byte[] value = tag.getValue();
|
||||
for (int i = 0, length = value.length; i < length; i++) {
|
||||
this.printAndResetSeparator();
|
||||
this.value(Byte.toString(value[i]), Tokens.TYPE_BYTE);
|
||||
}
|
||||
this.endArray();
|
||||
return this;
|
||||
}
|
||||
|
||||
private TagStringWriter writeIntArray(final IntArrayTag tag) throws IOException {
|
||||
this.beginArray(Tokens.TYPE_INT);
|
||||
|
||||
final int[] value = tag.getValue();
|
||||
for (int i = 0, length = value.length; i < length; i++) {
|
||||
this.printAndResetSeparator();
|
||||
this.value(Integer.toString(value[i]), Tokens.TYPE_INT);
|
||||
}
|
||||
this.endArray();
|
||||
return this;
|
||||
}
|
||||
|
||||
private TagStringWriter writeLongArray(final LongArrayTag tag) throws IOException {
|
||||
this.beginArray(Tokens.TYPE_LONG);
|
||||
|
||||
final long[] value = tag.getValue();
|
||||
for (int i = 0, length = value.length; i < length; i++) {
|
||||
this.printAndResetSeparator();
|
||||
this.value(Long.toString(value[i]), Tokens.TYPE_LONG);
|
||||
}
|
||||
this.endArray();
|
||||
return this;
|
||||
}
|
||||
|
||||
// Value types
|
||||
|
||||
public TagStringWriter beginCompound() throws IOException {
|
||||
this.printAndResetSeparator();
|
||||
this.level++;
|
||||
this.out.append(Tokens.COMPOUND_BEGIN);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TagStringWriter endCompound() throws IOException {
|
||||
this.out.append(Tokens.COMPOUND_END);
|
||||
this.level--;
|
||||
this.needsSeparator = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TagStringWriter key(final String key) throws IOException {
|
||||
this.printAndResetSeparator();
|
||||
this.writeMaybeQuoted(key, false);
|
||||
this.out.append(Tokens.COMPOUND_KEY_TERMINATOR);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TagStringWriter value(final String value, final char valueType) throws IOException {
|
||||
if (valueType == Tokens.EOF) { // string doesn't have its type
|
||||
this.writeMaybeQuoted(value, true);
|
||||
} else {
|
||||
this.out.append(value);
|
||||
if (valueType != Tokens.TYPE_INT) {
|
||||
this.out.append(valueType);
|
||||
}
|
||||
}
|
||||
this.needsSeparator = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TagStringWriter beginList() throws IOException {
|
||||
this.printAndResetSeparator();
|
||||
this.level++;
|
||||
this.out.append(Tokens.ARRAY_BEGIN);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TagStringWriter endList() throws IOException {
|
||||
this.out.append(Tokens.ARRAY_END);
|
||||
this.level--;
|
||||
this.needsSeparator = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
private TagStringWriter beginArray(final char type) throws IOException {
|
||||
this.beginList()
|
||||
.out.append(type)
|
||||
.append(Tokens.ARRAY_SIGNATURE_SEPARATOR);
|
||||
return this;
|
||||
}
|
||||
|
||||
private TagStringWriter endArray() throws IOException {
|
||||
return this.endList();
|
||||
}
|
||||
|
||||
private void writeMaybeQuoted(final String content, boolean requireQuotes) throws IOException {
|
||||
if (!requireQuotes) {
|
||||
for (int i = 0; i < content.length(); ++i) {
|
||||
if (!Tokens.id(content.charAt(i))) {
|
||||
requireQuotes = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (requireQuotes) {
|
||||
this.out.append(Tokens.DOUBLE_QUOTE);
|
||||
this.out.append(escape(content, Tokens.DOUBLE_QUOTE));
|
||||
this.out.append(Tokens.DOUBLE_QUOTE);
|
||||
} else {
|
||||
this.out.append(content);
|
||||
}
|
||||
}
|
||||
|
||||
private static String escape(final String content, final char quoteChar) {
|
||||
final StringBuilder output = new StringBuilder(content.length());
|
||||
for (int i = 0; i < content.length(); ++i) {
|
||||
final char c = content.charAt(i);
|
||||
if (c == quoteChar || c == '\\') {
|
||||
output.append(Tokens.ESCAPE_MARKER);
|
||||
}
|
||||
output.append(c);
|
||||
}
|
||||
return output.toString();
|
||||
}
|
||||
|
||||
private void printAndResetSeparator() throws IOException {
|
||||
if (this.needsSeparator) {
|
||||
this.out.append(Tokens.VALUE_SEPARATOR);
|
||||
this.needsSeparator = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (this.level != 0) {
|
||||
throw new IllegalStateException("Document finished with unbalanced start and end objects");
|
||||
}
|
||||
if (this.out instanceof Writer) {
|
||||
((Writer) this.out).flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* This file is part of adventure, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) 2017-2021 KyoriPowered
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.nbt;
|
||||
|
||||
final class Tokens {
|
||||
// Compounds
|
||||
static final char COMPOUND_BEGIN = '{';
|
||||
static final char COMPOUND_END = '}';
|
||||
static final char COMPOUND_KEY_TERMINATOR = ':';
|
||||
|
||||
// Arrays
|
||||
static final char ARRAY_BEGIN = '[';
|
||||
static final char ARRAY_END = ']';
|
||||
static final char ARRAY_SIGNATURE_SEPARATOR = ';';
|
||||
|
||||
static final char VALUE_SEPARATOR = ',';
|
||||
|
||||
static final char SINGLE_QUOTE = '\'';
|
||||
static final char DOUBLE_QUOTE = '"';
|
||||
static final char ESCAPE_MARKER = '\\';
|
||||
|
||||
static final char TYPE_BYTE = 'b';
|
||||
static final char TYPE_SHORT = 's';
|
||||
static final char TYPE_INT = 'i'; // array only
|
||||
static final char TYPE_LONG = 'l';
|
||||
static final char TYPE_FLOAT = 'f';
|
||||
static final char TYPE_DOUBLE = 'd';
|
||||
|
||||
static final String LITERAL_TRUE = "true";
|
||||
static final String LITERAL_FALSE = "false";
|
||||
|
||||
static final String NEWLINE = System.getProperty("line.separator", "\n");
|
||||
static final char EOF = '\0';
|
||||
|
||||
private Tokens() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return if a character is a valid component in an identifier.
|
||||
*
|
||||
* <p>An identifier character must match the expression {@code [a-zA-Z0-9_+.-]}</p>
|
||||
*
|
||||
* @param c the character
|
||||
* @return identifier
|
||||
*/
|
||||
static boolean id(final char c) {
|
||||
return (c >= 'a' && c <= 'z')
|
||||
|| (c >= 'A' && c <= 'Z')
|
||||
|| (c >= '0' && c <= '9')
|
||||
|| c == '-' || c == '_'
|
||||
|| c == '.' || c == '+';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether a character could be at some position in a number.
|
||||
*
|
||||
* <p>A string passing this check does not necessarily mean it is syntactically valid.</p>
|
||||
*
|
||||
* @param c character to check
|
||||
* @return if possibly part of a number
|
||||
*/
|
||||
static boolean numeric(final char c) {
|
||||
return (c >= '0' && c <= '9') // digit
|
||||
|| c == '+' || c == '-' // positive or negative
|
||||
|| c == 'e' || c == 'E' // exponent
|
||||
|| c == '.'; // decimal
|
||||
}
|
||||
}
|
||||
+12
-10
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2023 ViaVersion and contributors
|
||||
* Copyright (C) 2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -20,16 +20,18 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type.types.version;
|
||||
package com.viaversion.viaversion.api.minecraft.signature;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.ModernMetaType;
|
||||
import com.viaversion.viaversion.api.platform.providers.Provider;
|
||||
import com.viaversion.viaversion.util.Pair;
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public class Metadata1_16Type extends ModernMetaType {
|
||||
import java.util.List;
|
||||
|
||||
@Override
|
||||
protected MetaType getType(final int index) {
|
||||
return Types1_16.META_TYPES.byId(index);
|
||||
}
|
||||
public abstract class SignableCommandArgumentsProvider implements Provider {
|
||||
|
||||
/**
|
||||
* @param command The command to get the signable arguments for.
|
||||
* @return The signable arguments for the command.
|
||||
*/
|
||||
public abstract List<Pair<String, String>> getSignableArguments(final String command);
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2023-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.signature.model;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
public class DecoratableMessage {
|
||||
|
||||
private final String plain;
|
||||
private final JsonElement decorated;
|
||||
|
||||
public DecoratableMessage(final String plain) {
|
||||
this(plain, createLiteralText(plain));
|
||||
}
|
||||
|
||||
public DecoratableMessage(final String plain, final JsonElement decorated) {
|
||||
this.plain = plain;
|
||||
this.decorated = decorated;
|
||||
}
|
||||
|
||||
public String plain() {
|
||||
return this.plain;
|
||||
}
|
||||
|
||||
public JsonElement decorated() {
|
||||
return this.decorated;
|
||||
}
|
||||
|
||||
public boolean isDecorated() {
|
||||
return !this.decorated.equals(createLiteralText(plain));
|
||||
}
|
||||
|
||||
private static JsonElement createLiteralText(final String text) {
|
||||
final JsonObject object = new JsonObject();
|
||||
object.addProperty("text", text);
|
||||
return object;
|
||||
}
|
||||
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2023-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.signature.model;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MessageMetadata {
|
||||
|
||||
private final UUID sender;
|
||||
private final Instant timestamp;
|
||||
private final long salt;
|
||||
|
||||
public MessageMetadata(final UUID sender, final Instant timestamp, final long salt) {
|
||||
this.sender = sender;
|
||||
this.timestamp = timestamp;
|
||||
this.salt = salt;
|
||||
}
|
||||
|
||||
public MessageMetadata(final UUID sender, final long timestamp, final long salt) {
|
||||
this(sender, Instant.ofEpochMilli(timestamp), salt);
|
||||
}
|
||||
|
||||
public UUID sender() {
|
||||
return this.sender;
|
||||
}
|
||||
|
||||
public Instant timestamp() {
|
||||
return this.timestamp;
|
||||
}
|
||||
|
||||
public long salt() {
|
||||
return this.salt;
|
||||
}
|
||||
|
||||
}
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2023-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.signature.model.chain.v1_19_1;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.util.DataConsumer;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.time.Instant;
|
||||
|
||||
public class MessageBody {
|
||||
|
||||
private static final byte HASH_SEPARATOR_BYTE = 70;
|
||||
|
||||
private final DecoratableMessage content;
|
||||
private final Instant timestamp;
|
||||
private final long salt;
|
||||
private final PlayerMessageSignature[] lastSeenMessages;
|
||||
|
||||
public MessageBody(final DecoratableMessage content, final Instant timestamp, final long salt, final PlayerMessageSignature[] lastSeenMessages) {
|
||||
this.content = content;
|
||||
this.timestamp = timestamp;
|
||||
this.salt = salt;
|
||||
this.lastSeenMessages = lastSeenMessages;
|
||||
}
|
||||
|
||||
public void update(final DataConsumer dataConsumer) {
|
||||
try {
|
||||
final MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
final DataOutputStream dataOutputStream = new DataOutputStream(outputStream);
|
||||
dataOutputStream.writeLong(this.salt);
|
||||
dataOutputStream.writeLong(this.timestamp.getEpochSecond());
|
||||
|
||||
dataOutputStream.write(this.content.plain().getBytes(StandardCharsets.UTF_8));
|
||||
dataOutputStream.write(HASH_SEPARATOR_BYTE);
|
||||
if (this.content.isDecorated()) {
|
||||
dataOutputStream.write(GsonUtil.toSortedString(this.content.decorated(), null).getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
for (PlayerMessageSignature lastSeenMessage : this.lastSeenMessages) {
|
||||
dataOutputStream.writeByte(HASH_SEPARATOR_BYTE);
|
||||
dataOutputStream.writeLong(lastSeenMessage.uuid().getMostSignificantBits());
|
||||
dataOutputStream.writeLong(lastSeenMessage.uuid().getLeastSignificantBits());
|
||||
dataOutputStream.write(lastSeenMessage.signatureBytes());
|
||||
}
|
||||
|
||||
digest.update(outputStream.toByteArray());
|
||||
dataConsumer.accept(digest.digest());
|
||||
} catch (NoSuchAlgorithmException | IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2023-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.signature.model.chain.v1_19_1;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.signature.util.DataConsumer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class MessageHeader {
|
||||
|
||||
private final byte[] precedingSignature;
|
||||
private final UUID sender;
|
||||
|
||||
public MessageHeader(final byte[] precedingSignature, final UUID sender) {
|
||||
this.precedingSignature = precedingSignature;
|
||||
this.sender = sender;
|
||||
}
|
||||
|
||||
public void update(final DataConsumer dataConsumer) {
|
||||
if (this.precedingSignature != null) {
|
||||
dataConsumer.accept(this.precedingSignature);
|
||||
}
|
||||
|
||||
dataConsumer.accept(this.sender);
|
||||
}
|
||||
|
||||
}
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2023-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.signature.model.chain.v1_19_3;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.google.common.primitives.Longs;
|
||||
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.util.DataConsumer;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
|
||||
public class MessageBody {
|
||||
|
||||
private final String content;
|
||||
private final Instant timestamp;
|
||||
private final long salt;
|
||||
private final PlayerMessageSignature[] lastSeenMessages;
|
||||
|
||||
public MessageBody(final String content, final Instant timestamp, final long salt, final PlayerMessageSignature[] lastSeenMessages) {
|
||||
this.content = content;
|
||||
this.timestamp = timestamp;
|
||||
this.salt = salt;
|
||||
this.lastSeenMessages = lastSeenMessages;
|
||||
}
|
||||
|
||||
public void update(final DataConsumer dataConsumer) {
|
||||
dataConsumer.accept(Longs.toByteArray(this.salt));
|
||||
dataConsumer.accept(Longs.toByteArray(this.timestamp.getEpochSecond()));
|
||||
final byte[] contentData = this.content.getBytes(StandardCharsets.UTF_8);
|
||||
dataConsumer.accept(Ints.toByteArray(contentData.length));
|
||||
dataConsumer.accept(contentData);
|
||||
|
||||
dataConsumer.accept(Ints.toByteArray(this.lastSeenMessages.length));
|
||||
for (PlayerMessageSignature messageSignatureData : this.lastSeenMessages) {
|
||||
dataConsumer.accept(messageSignatureData.signatureBytes());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2023-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.signature.model.chain.v1_19_3;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.util.DataConsumer;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class MessageLink {
|
||||
|
||||
private final int index;
|
||||
private final UUID sender;
|
||||
private final UUID sessionId;
|
||||
|
||||
public MessageLink(final UUID sender, final UUID sessionId) {
|
||||
this(0, sender, sessionId);
|
||||
}
|
||||
|
||||
public MessageLink(final int index, final UUID sender, final UUID sessionId) {
|
||||
this.index = index;
|
||||
this.sender = sender;
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
||||
public void update(final DataConsumer dataConsumer) {
|
||||
dataConsumer.accept(this.sender);
|
||||
dataConsumer.accept(this.sessionId);
|
||||
dataConsumer.accept(Ints.toByteArray(this.index));
|
||||
}
|
||||
|
||||
public MessageLink next() {
|
||||
return this.index == Integer.MAX_VALUE ? null : new MessageLink(this.index + 1, this.sender, this.sessionId);
|
||||
}
|
||||
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2023-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.signature.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.util.DataConsumer;
|
||||
|
||||
import java.security.PrivateKey;
|
||||
import java.security.Signature;
|
||||
import java.security.SignatureException;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class ChatSession implements StorableObject {
|
||||
|
||||
private final UUID uuid;
|
||||
private final PrivateKey privateKey;
|
||||
private final ProfileKey profileKey;
|
||||
private final Signature signer;
|
||||
|
||||
public ChatSession(final UUID uuid, final PrivateKey privateKey, final ProfileKey profileKey) {
|
||||
Objects.requireNonNull(uuid, "uuid");
|
||||
Objects.requireNonNull(privateKey, "privateKey");
|
||||
Objects.requireNonNull(profileKey, "profileKey");
|
||||
this.uuid = uuid;
|
||||
this.privateKey = privateKey;
|
||||
this.profileKey = profileKey;
|
||||
|
||||
try {
|
||||
this.signer = Signature.getInstance("SHA256withRSA");
|
||||
this.signer.initSign(this.privateKey);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Failed to initialize signature", e);
|
||||
}
|
||||
}
|
||||
|
||||
public UUID getUuid() {
|
||||
return this.uuid;
|
||||
}
|
||||
|
||||
public ProfileKey getProfileKey() {
|
||||
return this.profileKey;
|
||||
}
|
||||
|
||||
public byte[] sign(final Consumer<DataConsumer> dataConsumer) throws SignatureException {
|
||||
dataConsumer.accept(bytes -> {
|
||||
try {
|
||||
this.signer.update(bytes);
|
||||
} catch (SignatureException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
});
|
||||
return this.signer.sign();
|
||||
}
|
||||
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2023-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.signature.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
|
||||
import com.viaversion.viaversion.util.GsonUtil;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.SignatureException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatSession1_19_0 extends ChatSession {
|
||||
|
||||
public ChatSession1_19_0(UUID uuid, PrivateKey privateKey, ProfileKey profileKey) {
|
||||
super(uuid, privateKey, profileKey);
|
||||
}
|
||||
|
||||
public byte[] signChatMessage(final MessageMetadata metadata, final DecoratableMessage content) throws SignatureException {
|
||||
return this.sign(signer -> {
|
||||
final byte[] data = new byte[32];
|
||||
final ByteBuffer buffer = ByteBuffer.wrap(data).order(ByteOrder.BIG_ENDIAN);
|
||||
buffer.putLong(metadata.salt());
|
||||
buffer.putLong(metadata.sender().getMostSignificantBits()).putLong(metadata.sender().getLeastSignificantBits());
|
||||
buffer.putLong(metadata.timestamp().getEpochSecond());
|
||||
signer.accept(data);
|
||||
signer.accept(GsonUtil.toSortedString(content.decorated(), null).getBytes(StandardCharsets.UTF_8));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2023-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.signature.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
|
||||
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.model.DecoratableMessage;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.model.chain.v1_19_1.MessageBody;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.model.chain.v1_19_1.MessageHeader;
|
||||
|
||||
import java.security.PrivateKey;
|
||||
import java.security.SignatureException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatSession1_19_1 extends ChatSession {
|
||||
|
||||
private byte[] precedingSignature;
|
||||
|
||||
public ChatSession1_19_1(UUID uuid, PrivateKey privateKey, ProfileKey profileKey) {
|
||||
super(uuid, privateKey, profileKey);
|
||||
}
|
||||
|
||||
public byte[] signChatMessage(final MessageMetadata metadata, final DecoratableMessage content, final PlayerMessageSignature[] lastSeenMessages) throws SignatureException {
|
||||
final byte[] signature = this.sign(signer -> {
|
||||
final MessageHeader messageHeader = new MessageHeader(this.precedingSignature, metadata.sender());
|
||||
final MessageBody messageBody = new MessageBody(content, metadata.timestamp(), metadata.salt(), lastSeenMessages);
|
||||
messageHeader.update(signer);
|
||||
messageBody.update(signer);
|
||||
});
|
||||
this.precedingSignature = signature;
|
||||
return signature;
|
||||
}
|
||||
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2023-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.minecraft.signature.storage;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.viaversion.viaversion.api.minecraft.PlayerMessageSignature;
|
||||
import com.viaversion.viaversion.api.minecraft.ProfileKey;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.model.MessageMetadata;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.model.chain.v1_19_3.MessageBody;
|
||||
import com.viaversion.viaversion.api.minecraft.signature.model.chain.v1_19_3.MessageLink;
|
||||
|
||||
import java.security.PrivateKey;
|
||||
import java.security.SignatureException;
|
||||
import java.util.UUID;
|
||||
|
||||
public class ChatSession1_19_3 extends ChatSession {
|
||||
|
||||
private final UUID sessionId = UUID.randomUUID();
|
||||
private MessageLink link;
|
||||
|
||||
public ChatSession1_19_3(UUID uuid, PrivateKey privateKey, ProfileKey profileKey) {
|
||||
super(uuid, privateKey, profileKey);
|
||||
|
||||
this.link = new MessageLink(uuid, this.sessionId);
|
||||
}
|
||||
|
||||
public byte[] signChatMessage(final MessageMetadata metadata, final String content, final PlayerMessageSignature[] lastSeenMessages) throws SignatureException {
|
||||
return this.sign(signer -> {
|
||||
final MessageLink messageLink = this.nextLink();
|
||||
final MessageBody messageBody = new MessageBody(content, metadata.timestamp(), metadata.salt(), lastSeenMessages);
|
||||
signer.accept(Ints.toByteArray(1));
|
||||
messageLink.update(signer);
|
||||
messageBody.update(signer);
|
||||
});
|
||||
}
|
||||
|
||||
private MessageLink nextLink() {
|
||||
final MessageLink messageLink = this.link;
|
||||
if (messageLink != null) {
|
||||
this.link = messageLink.next();
|
||||
}
|
||||
|
||||
return messageLink;
|
||||
}
|
||||
|
||||
public UUID getSessionId() {
|
||||
return this.sessionId;
|
||||
}
|
||||
|
||||
}
|
||||
+13
-13
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion
|
||||
* Copyright (C) 2016-2023 ViaVersion and contributors
|
||||
* Copyright (C) 2023-2023 ViaVersion and contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -20,20 +20,20 @@
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type.types.minecraft;
|
||||
package com.viaversion.viaversion.api.minecraft.signature.util;
|
||||
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public class Particle1_17Type extends AbstractParticleType {
|
||||
@FunctionalInterface
|
||||
public interface DataConsumer extends Consumer<byte[]> {
|
||||
|
||||
public Particle1_17Type() {
|
||||
readers.put(4, blockHandler());
|
||||
readers.put(25, blockHandler());
|
||||
readers.put(15, dustHandler());
|
||||
readers.put(16, dustTransitionHandler());
|
||||
readers.put(36, itemHandler(Type.FLAT_VAR_INT_ITEM));
|
||||
readers.put(37, vibrationHandler(Type.POSITION1_14));
|
||||
default void accept(final UUID uuid) {
|
||||
final byte[] serializedUuid = new byte[16];
|
||||
ByteBuffer.wrap(serializedUuid).order(ByteOrder.BIG_ENDIAN).putLong(uuid.getMostSignificantBits()).putLong(uuid.getLeastSignificantBits());
|
||||
this.accept(serializedUuid);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,8 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.platform;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public interface UnsupportedSoftware {
|
||||
|
||||
/**
|
||||
@@ -38,10 +40,19 @@ public interface UnsupportedSoftware {
|
||||
*/
|
||||
String getReason();
|
||||
|
||||
/**
|
||||
* Returns the name of unsupported software if present.
|
||||
*
|
||||
* @return name of unsupported software if it is matched, else null
|
||||
*/
|
||||
@Nullable String match();
|
||||
|
||||
/**
|
||||
* Returns whether the unsupported software is present.
|
||||
*
|
||||
* @return true if the unsupported software is found
|
||||
*/
|
||||
boolean findMatch();
|
||||
default boolean findMatch() {
|
||||
return match() != null;
|
||||
}
|
||||
}
|
||||
@@ -31,14 +31,14 @@ public interface ViaInjector {
|
||||
/**
|
||||
* Inject into the current Platform
|
||||
*
|
||||
* @throws Exception If there is an error with injecting
|
||||
* @throws Exception if there is an error with injecting
|
||||
*/
|
||||
void inject() throws Exception;
|
||||
|
||||
/**
|
||||
* Uninject into the current Platform
|
||||
*
|
||||
* @throws Exception If there is an error with uninjecting
|
||||
* @throws Exception if there is an error with uninjecting
|
||||
*/
|
||||
void uninject() throws Exception;
|
||||
|
||||
@@ -57,7 +57,7 @@ public interface ViaInjector {
|
||||
* For proxies, this returns the lowest supported protocol version.
|
||||
*
|
||||
* @return server protocol version
|
||||
* @throws Exception if there is an error with getting this info, eg. not binded
|
||||
* @throws Exception if there is an error with getting this info, e.g. not binded
|
||||
* @see ViaPlatform#isProxy()
|
||||
*/
|
||||
int getServerProtocolVersion() throws Exception;
|
||||
@@ -66,7 +66,7 @@ public interface ViaInjector {
|
||||
* Returns the supported server protocol versions.
|
||||
*
|
||||
* @return server protocol versions
|
||||
* @throws Exception if there is an error with getting this info, eg. not binded
|
||||
* @throws Exception if there is an error with getting this info, e.g. not binded
|
||||
* @see ViaPlatform#isProxy()
|
||||
*/
|
||||
default IntSortedSet getServerProtocolVersions() throws Exception {
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
package com.viaversion.viaversion.api.platform;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.ViaAPI;
|
||||
import com.viaversion.viaversion.api.command.ViaCommandSender;
|
||||
import com.viaversion.viaversion.api.configuration.ConfigurationProvider;
|
||||
@@ -104,23 +105,22 @@ public interface ViaPlatform<T> {
|
||||
PlatformTask runSync(Runnable runnable);
|
||||
|
||||
/**
|
||||
* Run a task Sync after a interval
|
||||
* This must be only used after plugin enable.
|
||||
* Runs a synchronous task after a delay in ticks.
|
||||
*
|
||||
* @param runnable The task to run
|
||||
* @param ticks The interval to run it after
|
||||
* @return The Task ID
|
||||
* @param runnable task to run
|
||||
* @param delay delay in ticks to run it after
|
||||
* @return created task
|
||||
*/
|
||||
PlatformTask runSync(Runnable runnable, long ticks);
|
||||
PlatformTask runSync(Runnable runnable, long delay);
|
||||
|
||||
/**
|
||||
* Run a task at a repeating interval.
|
||||
* Runs a synchronous task at a repeating interval.
|
||||
*
|
||||
* @param runnable The task to run
|
||||
* @param ticks The interval to run it at
|
||||
* @return The Task ID
|
||||
* @param runnable task to run
|
||||
* @param period period in ticks to run at
|
||||
* @return created task
|
||||
*/
|
||||
PlatformTask runRepeatingSync(Runnable runnable, long ticks);
|
||||
PlatformTask runRepeatingSync(Runnable runnable, long period);
|
||||
|
||||
/**
|
||||
* Get the online players
|
||||
@@ -181,13 +181,10 @@ public interface ViaPlatform<T> {
|
||||
*/
|
||||
ViaVersionConfig getConf();
|
||||
|
||||
/**
|
||||
* Get the backend configuration provider for this platform.
|
||||
* (On some platforms this returns the same as getConf())
|
||||
*
|
||||
* @return The configuration provider
|
||||
*/
|
||||
ConfigurationProvider getConfigurationProvider();
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
default ConfigurationProvider getConfigurationProvider() {
|
||||
return Via.getManager().getConfigurationProvider();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ViaVersions's data folder.
|
||||
@@ -209,12 +206,13 @@ public interface ViaPlatform<T> {
|
||||
JsonObject getDump();
|
||||
|
||||
/**
|
||||
* Get if older clients are allowed to be used using ViaVersion.
|
||||
* (Only 1.9 on 1.9.2 server is supported by ViaVersion alone)
|
||||
* Get if older clients are allowed using ViaVersion.
|
||||
*
|
||||
* @return True if allowed
|
||||
*/
|
||||
boolean isOldClientsAllowed();
|
||||
default boolean isOldClientsAllowed() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an immutable collection of classes to be checked as unsupported software with their software name.
|
||||
|
||||
@@ -25,7 +25,7 @@ package com.viaversion.viaversion.api.platform;
|
||||
public interface ViaPlatformLoader {
|
||||
|
||||
/**
|
||||
* Initialise the loading for a platform, eg. registering listeners / providers / events etc.
|
||||
* Initialise the loading for a platform, e.g. registering listeners / providers / events etc.
|
||||
*/
|
||||
void load();
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
||||
|
||||
/**
|
||||
* Creates a protocol with automated id mapping if the respective packet type classes are not null.
|
||||
* They are also required to track the CONFIGURATION state.
|
||||
*/
|
||||
protected AbstractProtocol(@Nullable Class<CU> unmappedClientboundPacketType, @Nullable Class<CM> mappedClientboundPacketType,
|
||||
@Nullable Class<SM> mappedServerboundPacketType, @Nullable Class<SU> unmappedServerboundPacketType) {
|
||||
@@ -95,6 +96,7 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
||||
initialized = true;
|
||||
|
||||
registerPackets();
|
||||
registerConfigurationChangeHandlers();
|
||||
|
||||
// Register the rest of the ids with no handlers if necessary
|
||||
if (unmappedClientboundPacketType != null && mappedClientboundPacketType != null
|
||||
@@ -117,6 +119,33 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
||||
}
|
||||
}
|
||||
|
||||
protected void registerConfigurationChangeHandlers() {
|
||||
// Register handlers for protocol state switching
|
||||
// Assuming ids will change too often, it is cleaner to register them here instead of the base protocols,
|
||||
// even if there will be multiple of these handlers
|
||||
final SU configurationAcknowledgedPacket = configurationAcknowledgedPacket();
|
||||
if (configurationAcknowledgedPacket != null) {
|
||||
registerServerbound(configurationAcknowledgedPacket, setClientStateHandler(State.CONFIGURATION));
|
||||
}
|
||||
|
||||
final CU startConfigurationPacket = startConfigurationPacket();
|
||||
if (startConfigurationPacket != null) {
|
||||
registerClientbound(startConfigurationPacket, setServerStateHandler(State.CONFIGURATION));
|
||||
}
|
||||
|
||||
final ServerboundPacketType finishConfigurationPacket = serverboundFinishConfigurationPacket();
|
||||
if (finishConfigurationPacket != null) {
|
||||
final int id = finishConfigurationPacket.getId();
|
||||
registerServerbound(State.CONFIGURATION, id, id, setClientStateHandler(State.PLAY));
|
||||
}
|
||||
|
||||
final ClientboundPacketType clientboundFinishConfigurationPacket = clientboundFinishConfigurationPacket();
|
||||
if (clientboundFinishConfigurationPacket != null) {
|
||||
final int id = clientboundFinishConfigurationPacket.getId();
|
||||
registerClientbound(State.CONFIGURATION, id, id, setServerStateHandler(State.PLAY));
|
||||
}
|
||||
}
|
||||
|
||||
private <U extends PacketType, M extends PacketType> void registerPacketIdChanges(
|
||||
Map<State, PacketTypeMap<U>> unmappedPacketTypes,
|
||||
Map<State, PacketTypeMap<M>> mappedPacketTypes,
|
||||
@@ -208,6 +237,28 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
protected @Nullable SU configurationAcknowledgedPacket() {
|
||||
final Map<State, PacketTypeMap<SU>> packetTypes = packetTypesProvider.unmappedServerboundPacketTypes();
|
||||
final PacketTypeMap<SU> packetTypeMap = packetTypes.get(State.PLAY);
|
||||
return packetTypeMap != null ? packetTypeMap.typeByName("CONFIGURATION_ACKNOWLEDGED") : null;
|
||||
}
|
||||
|
||||
protected @Nullable CU startConfigurationPacket() {
|
||||
final Map<State, PacketTypeMap<CU>> packetTypes = packetTypesProvider.unmappedClientboundPacketTypes();
|
||||
final PacketTypeMap<CU> packetTypeMap = packetTypes.get(State.PLAY);
|
||||
return packetTypeMap != null ? packetTypeMap.typeByName("START_CONFIGURATION") : null;
|
||||
}
|
||||
|
||||
protected @Nullable ServerboundPacketType serverboundFinishConfigurationPacket() {
|
||||
// To be overridden
|
||||
return null;
|
||||
}
|
||||
|
||||
protected @Nullable ClientboundPacketType clientboundFinishConfigurationPacket() {
|
||||
// To be overridden
|
||||
return null;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------------
|
||||
|
||||
@Override
|
||||
@@ -361,7 +412,7 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
||||
}
|
||||
}
|
||||
|
||||
private void throwRemapError(Direction direction, State state, int unmappedPacketId, int mappedPacketId, InformativeException e) throws InformativeException {
|
||||
protected void throwRemapError(Direction direction, State state, int unmappedPacketId, int mappedPacketId, InformativeException e) throws InformativeException {
|
||||
// Don't print errors during handshake/login/status
|
||||
if (state != State.PLAY && direction == Direction.SERVERBOUND && !Via.getManager().debugHandler().enabled()) {
|
||||
e.setShouldBePrinted(false);
|
||||
@@ -373,7 +424,7 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
||||
Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName() + " IN REMAP OF " + packetType + " (" + toNiceHex(unmappedPacketId) + ")");
|
||||
} else {
|
||||
Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName()
|
||||
+ " IN REMAP OF " + toNiceHex(unmappedPacketId) + "->" + toNiceHex(mappedPacketId));
|
||||
+ " IN REMAP OF " + state + " " + toNiceHex(unmappedPacketId) + "->" + toNiceHex(mappedPacketId));
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
@@ -404,6 +455,14 @@ public abstract class AbstractProtocol<CU extends ClientboundPacketType, CM exte
|
||||
}
|
||||
}
|
||||
|
||||
protected PacketHandler setClientStateHandler(final State state) {
|
||||
return wrapper -> wrapper.user().getProtocolInfo().setClientState(state);
|
||||
}
|
||||
|
||||
protected PacketHandler setServerStateHandler(final State state) {
|
||||
return wrapper -> wrapper.user().getProtocolInfo().setServerState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketTypesProvider<CU, CM, SM, SU> getPacketTypesProvider() {
|
||||
return packetTypesProvider;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
package com.viaversion.viaversion.api.protocol;
|
||||
|
||||
import com.google.common.annotations.Beta;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.data.MappingData;
|
||||
import com.viaversion.viaversion.api.platform.providers.ViaProviders;
|
||||
@@ -58,6 +59,16 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
|
||||
registerServerbound(state, unmappedPacketId, mappedPacketId, handler, false);
|
||||
}
|
||||
|
||||
default void registerClientbound(State state, ClientboundPacketType packetType, PacketHandler handler) {
|
||||
Preconditions.checkArgument(packetType.state() == state);
|
||||
registerClientbound(state, packetType.getId(), packetType.getId(), handler, false);
|
||||
}
|
||||
|
||||
default void registerServerbound(State state, ServerboundPacketType packetType, PacketHandler handler) {
|
||||
Preconditions.checkArgument(packetType.state() == state);
|
||||
registerServerbound(state, packetType.getId(), packetType.getId(), handler, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a serverbound packet, with id transformation and remapper.
|
||||
*
|
||||
|
||||
@@ -69,10 +69,17 @@ public interface ProtocolPipeline extends SimpleProtocol {
|
||||
/**
|
||||
* Returns the list of protocols this pipeline contains.
|
||||
*
|
||||
* @return list of protocols in this pipe
|
||||
* @return immutable list of protocols in this pipe
|
||||
*/
|
||||
List<Protocol> pipes();
|
||||
|
||||
/**
|
||||
* Returns the list of protocols this pipeline contains in reversed order.
|
||||
*
|
||||
* @return immutable list of protocols in reversed direction
|
||||
*/
|
||||
List<Protocol> reversedPipes();
|
||||
|
||||
/**
|
||||
* Returns whether this pipe has protocols that are not base protocols, as given by {@link Protocol#isBaseProtocol()}.
|
||||
*
|
||||
|
||||
@@ -27,7 +27,7 @@ import com.viaversion.viaversion.api.protocol.packet.Direction;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||
|
||||
/**
|
||||
* Dummy protocol class when there is no need of any of the
|
||||
* Dummy protocol class when there is no need of the
|
||||
* existing packet type enums or automated channel mappings.
|
||||
*
|
||||
* @see Protocol
|
||||
|
||||
+1
-2
@@ -23,8 +23,7 @@
|
||||
package com.viaversion.viaversion.api.protocol.packet;
|
||||
|
||||
/**
|
||||
* Interface to be implemented by server outgoing packet type enums,
|
||||
* representing PLAY state packets, ordered by their packet id.
|
||||
* Interface to be implemented by server outgoing packet types.
|
||||
*/
|
||||
public interface ClientboundPacketType extends PacketType {
|
||||
|
||||
|
||||
@@ -81,11 +81,9 @@ public class PacketTracker {
|
||||
if (connection.isClientSide()) return false; // Don't apply PPS limiting for client-side
|
||||
ViaVersionConfig conf = Via.getConfig();
|
||||
// Max PPS Checker
|
||||
if (conf.getMaxPPS() > 0) {
|
||||
if (packetsPerSecond >= conf.getMaxPPS()) {
|
||||
connection.disconnect(conf.getMaxPPSKickMessage().replace("%pps", Long.toString(packetsPerSecond)));
|
||||
return true; // don't send current packet
|
||||
}
|
||||
if (conf.getMaxPPS() > 0 && packetsPerSecond >= conf.getMaxPPS()) {
|
||||
connection.disconnect(conf.getMaxPPSKickMessage().replace("%pps", Long.toString(packetsPerSecond)));
|
||||
return true; // don't send current packet
|
||||
}
|
||||
|
||||
// Tracking PPS Checker
|
||||
|
||||
+1
-2
@@ -23,8 +23,7 @@
|
||||
package com.viaversion.viaversion.api.protocol.packet;
|
||||
|
||||
/**
|
||||
* Interface to be implemented by server incoming packet type enums,
|
||||
* representing PLAY state packets, ordered by their packet id.
|
||||
* Interface to be implemented by server incoming packet types.
|
||||
*/
|
||||
public interface ServerboundPacketType extends PacketType {
|
||||
|
||||
|
||||
@@ -27,5 +27,6 @@ public enum State {
|
||||
HANDSHAKE,
|
||||
STATUS,
|
||||
LOGIN,
|
||||
CONFIGURATION,
|
||||
PLAY
|
||||
}
|
||||
+3
-1
@@ -25,9 +25,11 @@ package com.viaversion.viaversion.api.protocol.packet.provider;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketType;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
final class PacketTypeArrayMap<P> implements PacketTypeMap<P> {
|
||||
final class PacketTypeArrayMap<P extends PacketType> implements PacketTypeMap<P> {
|
||||
private final Map<String, P> packetsByName;
|
||||
private final P[] packets;
|
||||
|
||||
|
||||
+3
-3
@@ -29,7 +29,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public interface PacketTypeMap<P> {
|
||||
public interface PacketTypeMap<P extends PacketType> {
|
||||
|
||||
/**
|
||||
* Returns the packet type by the given name.
|
||||
@@ -67,11 +67,11 @@ public interface PacketTypeMap<P> {
|
||||
return of(byName, types);
|
||||
}
|
||||
|
||||
static <T> PacketTypeMap<T> of(final Map<String, T> packetsByName, final Int2ObjectMap<T> packetsById) {
|
||||
static <T extends PacketType> PacketTypeMap<T> of(final Map<String, T> packetsByName, final Int2ObjectMap<T> packetsById) {
|
||||
return new PacketTypeMapMap<>(packetsByName, packetsById);
|
||||
}
|
||||
|
||||
static <T> PacketTypeMap<T> of(final Map<String, T> packetsByName, final T[] packets) {
|
||||
static <T extends PacketType> PacketTypeMap<T> of(final Map<String, T> packetsByName, final T[] packets) {
|
||||
return new PacketTypeArrayMap<>(packetsByName, packets);
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -22,12 +22,13 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.protocol.packet.provider;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.packet.PacketType;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
final class PacketTypeMapMap<P> implements PacketTypeMap<P> {
|
||||
final class PacketTypeMapMap<P extends PacketType> implements PacketTypeMap<P> {
|
||||
private final Map<String, P> packetsByName;
|
||||
private final Int2ObjectMap<P> packetsById;
|
||||
|
||||
|
||||
+10
-9
@@ -83,6 +83,9 @@ public class ProtocolVersion {
|
||||
public static final ProtocolVersion v1_19_1 = register(760, "1.19.1/2", new VersionRange("1.19", 1, 2));
|
||||
public static final ProtocolVersion v1_19_3 = register(761, "1.19.3");
|
||||
public static final ProtocolVersion v1_19_4 = register(762, "1.19.4");
|
||||
public static final ProtocolVersion v1_20 = register(763, "1.20/1.20.1", new VersionRange("1.20", 0, 1));
|
||||
public static final ProtocolVersion v1_20_2 = register(764, "1.20.2");
|
||||
public static final ProtocolVersion v1_20_3 = register(765, "1.20.3");
|
||||
public static final ProtocolVersion unknown = register(-1, "UNKNOWN");
|
||||
|
||||
public static ProtocolVersion register(int version, String name) {
|
||||
@@ -104,7 +107,7 @@ public class ProtocolVersion {
|
||||
* @param snapshotVersion snapshot protocol version, or -1 if not a snapshot
|
||||
* @param name version name
|
||||
* @param versionRange range of versions that are supported by this protocol version, null if not a range
|
||||
* @return registered {@link ProtocolVersion}
|
||||
* @return registered ProtocolVersion
|
||||
*/
|
||||
public static ProtocolVersion register(int version, int snapshotVersion, String name, @Nullable VersionRange versionRange) {
|
||||
ProtocolVersion protocol = new ProtocolVersion(version, snapshotVersion, name, versionRange);
|
||||
@@ -127,11 +130,11 @@ public class ProtocolVersion {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link ProtocolVersion} instance, even if this protocol version
|
||||
* Returns a ProtocolVersion instance, even if this protocol version
|
||||
* has not been registered. See {@link #isRegistered(int)} berorehand or {@link #isKnown()}.
|
||||
*
|
||||
* @param version protocol version
|
||||
* @return registered or unknown {@link ProtocolVersion}
|
||||
* @return registered or unknown ProtocolVersion
|
||||
*/
|
||||
public static @NonNull ProtocolVersion getProtocol(int version) {
|
||||
ProtocolVersion protocolVersion = VERSIONS.get(version);
|
||||
@@ -182,10 +185,8 @@ public class ProtocolVersion {
|
||||
if (majorVersion.equals(protocol) || (protocol.startsWith(name.substring(0, name.length() - 1)))) {
|
||||
return version;
|
||||
}
|
||||
} else if (version.isRange()) {
|
||||
if (version.getIncludedVersions().contains(protocol)) {
|
||||
return version;
|
||||
}
|
||||
} else if (version.isRange() && version.getIncludedVersions().contains(protocol)) {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -245,7 +246,7 @@ public class ProtocolVersion {
|
||||
* Returns the snapshot protocol version without the snapshot indicator bit if this is a snapshot protocol version.
|
||||
*
|
||||
* @return snapshot protocol version without the snapshot indicator bit
|
||||
* @throws IllegalArgumentException if the version if not a snapshot version
|
||||
* @throws IllegalArgumentException if the version is not a snapshot version
|
||||
* @see #isSnapshot()
|
||||
*/
|
||||
public int getSnapshotVersion() {
|
||||
@@ -257,7 +258,7 @@ public class ProtocolVersion {
|
||||
* Returns the snapshot protocol version with the snapshot indicator bit if this is a snapshot protocol version.
|
||||
*
|
||||
* @return snapshot protocol version with the snapshot indicator bit
|
||||
* @throws IllegalArgumentException if the version if not a snapshot version
|
||||
* @throws IllegalArgumentException if the version is not a snapshot version
|
||||
* @see #isSnapshot()
|
||||
*/
|
||||
public int getFullSnapshotVersion() {
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ public interface ServerProtocolVersion {
|
||||
|
||||
/**
|
||||
* Returns true if the actual protocol version has not yet been identified.
|
||||
* In that case, all methods above will returns -1.
|
||||
* In that case, all methods above will return -1.
|
||||
*
|
||||
* @return true if set, false if unknown (yet)
|
||||
*/
|
||||
|
||||
@@ -25,6 +25,7 @@ package com.viaversion.viaversion.api.protocol.version;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.platform.providers.Provider;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface VersionProvider extends Provider {
|
||||
|
||||
/**
|
||||
|
||||
@@ -51,7 +51,7 @@ public interface EntityRewriter<T extends Protocol> extends Rewriter<T> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mapped entitiy (or the same if it has not changed).
|
||||
* Returns the mapped entity (or the same if it has not changed).
|
||||
*
|
||||
* @param id unmapped entity id
|
||||
* @return mapped entity id
|
||||
|
||||
@@ -27,7 +27,7 @@ import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
public abstract class RewriterBase<T extends Protocol> implements Rewriter<T> {
|
||||
protected final T protocol;
|
||||
|
||||
protected RewriterBase(T protocol) {
|
||||
protected RewriterBase(final T protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.type;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
@Deprecated
|
||||
public abstract class PartialType<T, X> extends Type<T> {
|
||||
private final X param;
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.api.type;
|
||||
|
||||
|
||||
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
|
||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
|
||||
import com.viaversion.viaversion.api.minecraft.EulerAngle;
|
||||
@@ -35,8 +35,11 @@ import com.viaversion.viaversion.api.minecraft.Quaternion;
|
||||
import com.viaversion.viaversion.api.minecraft.Vector;
|
||||
import com.viaversion.viaversion.api.minecraft.Vector3f;
|
||||
import com.viaversion.viaversion.api.minecraft.VillagerData;
|
||||
import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity;
|
||||
import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.minecraft.metadata.ChunkPosition;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
import com.viaversion.viaversion.api.type.types.BitSetType;
|
||||
import com.viaversion.viaversion.api.type.types.BooleanType;
|
||||
import com.viaversion.viaversion.api.type.types.ByteArrayType;
|
||||
import com.viaversion.viaversion.api.type.types.ByteType;
|
||||
@@ -50,34 +53,38 @@ import com.viaversion.viaversion.api.type.types.RemainingBytesType;
|
||||
import com.viaversion.viaversion.api.type.types.ShortByteArrayType;
|
||||
import com.viaversion.viaversion.api.type.types.ShortType;
|
||||
import com.viaversion.viaversion.api.type.types.StringType;
|
||||
import com.viaversion.viaversion.api.type.types.UUIDIntArrayType;
|
||||
import com.viaversion.viaversion.api.type.types.UUIDType;
|
||||
import com.viaversion.viaversion.api.type.types.UnsignedByteType;
|
||||
import com.viaversion.viaversion.api.type.types.UnsignedShortType;
|
||||
import com.viaversion.viaversion.api.type.types.VarIntArrayType;
|
||||
import com.viaversion.viaversion.api.type.types.VarIntType;
|
||||
import com.viaversion.viaversion.api.type.types.VarLongType;
|
||||
import com.viaversion.viaversion.api.type.types.VoidType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.BlockChangeRecordType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.EulerAngleType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.FlatItemArrayType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.FlatItemType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.FlatVarIntItemArrayType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.FlatVarIntItemType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.GlobalPositionType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.ItemArrayType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.ItemType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.NBTType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.OptionalVarIntType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.PlayerMessageSignatureType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.Position1_14Type;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.PositionType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.ProfileKeyType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.QuaternionType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.VarLongBlockChangeRecordType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.Vector3fType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.VectorType;
|
||||
import com.viaversion.viaversion.api.type.types.minecraft.VillagerDataType;
|
||||
import com.viaversion.viaversion.api.type.types.block.BlockChangeRecordType;
|
||||
import com.viaversion.viaversion.api.type.types.block.BlockEntityType1_18;
|
||||
import com.viaversion.viaversion.api.type.types.block.BlockEntityType1_20_2;
|
||||
import com.viaversion.viaversion.api.type.types.math.ChunkPositionType;
|
||||
import com.viaversion.viaversion.api.type.types.misc.CompoundTagType;
|
||||
import com.viaversion.viaversion.api.type.types.math.EulerAngleType;
|
||||
import com.viaversion.viaversion.api.type.types.item.ItemShortArrayType1_13;
|
||||
import com.viaversion.viaversion.api.type.types.item.ItemType1_13;
|
||||
import com.viaversion.viaversion.api.type.types.item.ItemShortArrayType1_13_2;
|
||||
import com.viaversion.viaversion.api.type.types.item.ItemType1_13_2;
|
||||
import com.viaversion.viaversion.api.type.types.math.GlobalPositionType;
|
||||
import com.viaversion.viaversion.api.type.types.item.ItemType1_20_2;
|
||||
import com.viaversion.viaversion.api.type.types.item.ItemShortArrayType1_8;
|
||||
import com.viaversion.viaversion.api.type.types.item.ItemType1_8;
|
||||
import com.viaversion.viaversion.api.type.types.misc.NamedCompoundTagType;
|
||||
import com.viaversion.viaversion.api.type.types.OptionalVarIntType;
|
||||
import com.viaversion.viaversion.api.type.types.misc.PlayerMessageSignatureType;
|
||||
import com.viaversion.viaversion.api.type.types.math.PositionType1_14;
|
||||
import com.viaversion.viaversion.api.type.types.math.PositionType1_8;
|
||||
import com.viaversion.viaversion.api.type.types.misc.ProfileKeyType;
|
||||
import com.viaversion.viaversion.api.type.types.math.QuaternionType;
|
||||
import com.viaversion.viaversion.api.type.types.misc.TagType;
|
||||
import com.viaversion.viaversion.api.type.types.block.VarLongBlockChangeRecordType;
|
||||
import com.viaversion.viaversion.api.type.types.math.Vector3fType;
|
||||
import com.viaversion.viaversion.api.type.types.math.VectorType;
|
||||
import com.viaversion.viaversion.api.type.types.misc.VillagerDataType;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@@ -118,67 +125,47 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
||||
public static final Type<UUID> UUID = new UUIDType();
|
||||
public static final Type<UUID> OPTIONAL_UUID = new UUIDType.OptionalUUIDType();
|
||||
public static final Type<UUID[]> UUID_ARRAY = new ArrayType<>(Type.UUID);
|
||||
@Deprecated/*(forRemoval = true)*/
|
||||
public static final Type<UUID> UUID_INT_ARRAY = new UUIDIntArrayType();
|
||||
|
||||
public static final VarIntType VAR_INT = new VarIntType();
|
||||
public static final OptionalVarIntType OPTIONAL_VAR_INT = new OptionalVarIntType();
|
||||
public static final Type<int[]> VAR_INT_ARRAY_PRIMITIVE = new VarIntArrayType();
|
||||
public static final VarLongType VAR_LONG = new VarLongType();
|
||||
|
||||
/* Boxed number array types */
|
||||
@Deprecated
|
||||
public static final Type<Byte[]> BYTE_ARRAY = new ArrayType<>(Type.BYTE);
|
||||
@Deprecated
|
||||
public static final Type<Short[]> UNSIGNED_BYTE_ARRAY = new ArrayType<>(Type.UNSIGNED_BYTE);
|
||||
@Deprecated
|
||||
public static final Type<Boolean[]> BOOLEAN_ARRAY = new ArrayType<>(Type.BOOLEAN);
|
||||
@Deprecated
|
||||
public static final Type<Integer[]> INT_ARRAY = new ArrayType<>(Type.INT);
|
||||
@Deprecated
|
||||
public static final Type<Short[]> SHORT_ARRAY = new ArrayType<>(Type.SHORT);
|
||||
@Deprecated
|
||||
public static final Type<Integer[]> UNSIGNED_SHORT_ARRAY = new ArrayType<>(Type.UNSIGNED_SHORT);
|
||||
@Deprecated
|
||||
public static final Type<Double[]> DOUBLE_ARRAY = new ArrayType<>(Type.DOUBLE);
|
||||
@Deprecated
|
||||
public static final Type<Long[]> LONG_ARRAY = new ArrayType<>(Type.LONG);
|
||||
@Deprecated
|
||||
public static final Type<Float[]> FLOAT_ARRAY = new ArrayType<>(Type.FLOAT);
|
||||
@Deprecated
|
||||
public static final Type<Integer[]> VAR_INT_ARRAY = new ArrayType<>(Type.VAR_INT);
|
||||
@Deprecated
|
||||
public static final Type<Long[]> VAR_LONG_ARRAY = new ArrayType<>(Type.VAR_LONG);
|
||||
|
||||
/* Special Types */
|
||||
public static final VoidType NOTHING = new VoidType(); // This is purely used for remapping.
|
||||
|
||||
/* MC Types */
|
||||
public static final Type<Position> POSITION = new PositionType();
|
||||
public static final Type<Position> OPTIONAL_POSITION = new PositionType.OptionalPositionType();
|
||||
public static final Type<Position> POSITION1_14 = new Position1_14Type();
|
||||
public static final Type<Position> OPTIONAL_POSITION_1_14 = new Position1_14Type.OptionalPosition1_14Type();
|
||||
public static final Type<Position> POSITION1_8 = new PositionType1_8();
|
||||
public static final Type<Position> OPTIONAL_POSITION1_8 = new PositionType1_8.OptionalPositionType();
|
||||
public static final Type<Position> POSITION1_14 = new PositionType1_14();
|
||||
public static final Type<Position> OPTIONAL_POSITION_1_14 = new PositionType1_14.OptionalPosition1_14Type();
|
||||
public static final Type<EulerAngle> ROTATION = new EulerAngleType();
|
||||
public static final Type<Vector> VECTOR = new VectorType();
|
||||
public static final Type<Vector3f> VECTOR3F = new Vector3fType();
|
||||
public static final Type<Quaternion> QUATERNION = new QuaternionType();
|
||||
public static final Type<CompoundTag> NBT = new NBTType();
|
||||
public static final Type<CompoundTag[]> NBT_ARRAY = new ArrayType<>(Type.NBT);
|
||||
|
||||
public static final Type<CompoundTag> NAMED_COMPOUND_TAG = new NamedCompoundTagType();
|
||||
public static final Type<CompoundTag[]> NAMED_COMPOUND_TAG_ARRAY = new ArrayType<>(Type.NAMED_COMPOUND_TAG);
|
||||
public static final Type<CompoundTag> COMPOUND_TAG = new CompoundTagType();
|
||||
public static final Type<CompoundTag> OPTIONAL_COMPOUND_TAG = new CompoundTagType.OptionalCompoundTagType();
|
||||
public static final Type<Tag> TAG = new TagType();
|
||||
public static final Type<Tag> OPTIONAL_TAG = new TagType.OptionalTagType();
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public static final Type<CompoundTag> NBT = NAMED_COMPOUND_TAG;
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public static final Type<CompoundTag[]> NBT_ARRAY = NAMED_COMPOUND_TAG_ARRAY;
|
||||
|
||||
public static final Type<GlobalPosition> GLOBAL_POSITION = new GlobalPositionType();
|
||||
public static final Type<GlobalPosition> OPTIONAL_GLOBAL_POSITION = new GlobalPositionType.OptionalGlobalPositionType();
|
||||
public static final Type<ChunkPosition> CHUNK_POSITION = new ChunkPositionType();
|
||||
|
||||
public static final Type<BlockEntity> BLOCK_ENTITY1_18 = new BlockEntityType1_18();
|
||||
public static final Type<BlockEntity> BLOCK_ENTITY1_20_2 = new BlockEntityType1_20_2();
|
||||
|
||||
public static final Type<BlockChangeRecord> BLOCK_CHANGE_RECORD = new BlockChangeRecordType();
|
||||
public static final Type<BlockChangeRecord[]> BLOCK_CHANGE_RECORD_ARRAY = new ArrayType<>(Type.BLOCK_CHANGE_RECORD);
|
||||
|
||||
public static final Type<BlockChangeRecord> VAR_LONG_BLOCK_CHANGE_RECORD = new VarLongBlockChangeRecordType();
|
||||
public static final Type<BlockChangeRecord[]> VAR_LONG_BLOCK_CHANGE_RECORD_ARRAY = new ArrayType<>(Type.VAR_LONG_BLOCK_CHANGE_RECORD);
|
||||
|
||||
public static final Type<VillagerData> VILLAGER_DATA = new VillagerDataType();
|
||||
|
||||
public static final Type<Item> ITEM = new ItemType();
|
||||
public static final Type<Item[]> ITEM_ARRAY = new ItemArrayType();
|
||||
|
||||
public static final Type<ProfileKey> PROFILE_KEY = new ProfileKeyType();
|
||||
public static final Type<ProfileKey> OPTIONAL_PROFILE_KEY = new ProfileKeyType.OptionalProfileKeyType();
|
||||
|
||||
@@ -186,20 +173,43 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
||||
public static final Type<PlayerMessageSignature> OPTIONAL_PLAYER_MESSAGE_SIGNATURE = new PlayerMessageSignatureType.OptionalPlayerMessageSignatureType();
|
||||
public static final Type<PlayerMessageSignature[]> PLAYER_MESSAGE_SIGNATURE_ARRAY = new ArrayType<>(PLAYER_MESSAGE_SIGNATURE);
|
||||
|
||||
/* 1.13 Flat Item (no data) */
|
||||
public static final Type<Item> FLAT_ITEM = new FlatItemType();
|
||||
public static final Type<Item> FLAT_VAR_INT_ITEM = new FlatVarIntItemType();
|
||||
public static final Type<Item[]> FLAT_ITEM_ARRAY = new FlatItemArrayType();
|
||||
public static final Type<Item[]> FLAT_VAR_INT_ITEM_ARRAY = new FlatVarIntItemArrayType();
|
||||
public static final Type<Item[]> FLAT_ITEM_ARRAY_VAR_INT = new ArrayType<>(FLAT_ITEM);
|
||||
public static final Type<Item[]> FLAT_VAR_INT_ITEM_ARRAY_VAR_INT = new ArrayType<>(FLAT_VAR_INT_ITEM);
|
||||
public static final BitSetType PROFILE_ACTIONS_ENUM = new BitSetType(6);
|
||||
public static final ByteArrayType SIGNATURE_BYTES = new ByteArrayType(256);
|
||||
public static final ByteArrayType.OptionalByteArrayType OPTIONAL_SIGNATURE_BYTES = new ByteArrayType.OptionalByteArrayType(256);
|
||||
|
||||
public static final Type<Item> ITEM1_8 = new ItemType1_8();
|
||||
public static final Type<Item> ITEM1_13 = new ItemType1_13();
|
||||
public static final Type<Item> ITEM1_13_2 = new ItemType1_13_2();
|
||||
public static final Type<Item> ITEM1_20_2 = new ItemType1_20_2();
|
||||
public static final Type<Item[]> ITEM1_8_SHORT_ARRAY = new ItemShortArrayType1_8();
|
||||
public static final Type<Item[]> ITEM1_13_SHORT_ARRAY = new ItemShortArrayType1_13();
|
||||
public static final Type<Item[]> ITEM1_13_2_SHORT_ARRAY = new ItemShortArrayType1_13_2();
|
||||
public static final Type<Item[]> ITEM1_13_ARRAY = new ArrayType<>(ITEM1_13);
|
||||
public static final Type<Item[]> ITEM1_13_2_ARRAY = new ArrayType<>(ITEM1_13_2);
|
||||
public static final Type<Item[]> ITEM1_20_2_ARRAY = new ArrayType<>(ITEM1_20_2);
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public static final Type<Item> ITEM = ITEM1_8;
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public static final Type<Item> FLAT_ITEM = ITEM1_13;
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public static final Type<Item> FLAT_VAR_INT_ITEM = ITEM1_13_2;
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public static final Type<Item[]> ITEM_ARRAY = ITEM1_8_SHORT_ARRAY;
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public static final Type<Item[]> FLAT_ITEM_ARRAY = ITEM1_13_SHORT_ARRAY;
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public static final Type<Item[]> FLAT_VAR_INT_ITEM_ARRAY = ITEM1_13_2_SHORT_ARRAY;
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public static final Type<Item[]> FLAT_ITEM_ARRAY_VAR_INT = ITEM1_13_ARRAY;
|
||||
@Deprecated/*(forRemoval=true)*/
|
||||
public static final Type<Item[]> FLAT_VAR_INT_ITEM_ARRAY_VAR_INT = ITEM1_13_2_ARRAY;
|
||||
|
||||
/* Actual Class */
|
||||
private final Class<? super T> outputClass;
|
||||
private final String typeName;
|
||||
|
||||
protected Type(Class<? super T> outputClass) {
|
||||
this(outputClass.getSimpleName(), outputClass);
|
||||
this(null, outputClass);
|
||||
}
|
||||
|
||||
protected Type(String typeName, Class<? super T> outputClass) {
|
||||
@@ -222,7 +232,7 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
||||
* @return type name
|
||||
*/
|
||||
public String getTypeName() {
|
||||
return typeName;
|
||||
return typeName != null ? typeName : this.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,6 +247,6 @@ public abstract class Type<T> implements ByteBufReader<T>, ByteBufWriter<T> {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Type|" + typeName;
|
||||
return getTypeName();
|
||||
}
|
||||
}
|
||||
Loaded 100 of 470 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user