mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2026-11-04 08:52:09 -05:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
39808bc64f |
No files matched your search
@@ -1,2 +1 @@
|
||||
* text=auto eol=lf
|
||||
.github/workflows/*.lock.yml linguist-generated=true merge=ours
|
||||
+36
-73
@@ -1,75 +1,38 @@
|
||||
# Contributing to ProtocolLib
|
||||
Contributing to ProtocolLib
|
||||
===========================
|
||||
This page will detail specific things that must be done if you intend to contribute to this project.
|
||||
|
||||
ProtocolLib supports a wide range of Minecraft versions through reflection and compatibility wrappers. Changes to packet
|
||||
registration, reflection, or public wrappers can affect plugins on versions other than the one currently used for
|
||||
development, so keep changes focused and preserve existing behavior unless a break is unavoidable.
|
||||
## Updating ProtocolLib to a New Protocol Version
|
||||
#### Before we get started:
|
||||
1. **When do we need to update the protocol version?**
|
||||
_A Minecraft protocol version is a number for each specification of the Minecraft protocol.
|
||||
This means it is incremented when there is a change to the [Protocol Specification](http://wiki.vg/Protocol),
|
||||
but not necessarily for each Minecraft version update. If the latest Minecraft version contains a protocol change,
|
||||
that means ProtocolLib needs to be updated._
|
||||
2. **When do we need to update other parts of ProtocolLib?**
|
||||
_When the package version guard changes. The package version guard is the version string inserted
|
||||
into the package identifier for CraftBukkit and net.minecraft.server (e.g. v1_9_R2). It is incremented
|
||||
by Spigot if there is a major breaking change in the internal server code. This is to encourage plugins
|
||||
that interact directly with CraftBukkit/nms code to update more specifically. However, since most of
|
||||
ProtocolLib uses reflection, and the structure of packet classes is generally static, one will have
|
||||
to go through the code and change imports from nms/CraftBukkit._
|
||||
|
||||
## Building ProtocolLib
|
||||
|
||||
Use the Gradle wrapper from the repository root. The root project builds the platform-neutral library published to
|
||||
Maven. The `paper` module compiles and tests it against Paper's development bundle and produces the primary plugin,
|
||||
`build/libs/ProtocolLib.jar`. The `spigot` compatibility module produces `build/libs/ProtocolLib-Spigot.jar`.
|
||||
|
||||
```shell
|
||||
./gradlew test
|
||||
./gradlew build shadowJar
|
||||
```
|
||||
|
||||
`shadowJar` builds both plugin distributions with the required Byte Buddy classes included. Neither platform provider
|
||||
nor plugin descriptor is included in the Maven core artifact.
|
||||
|
||||
ProtocolLib uses the Java 25 toolchain to compile against the current server, but production classes target Java 17 for
|
||||
compatibility with older supported servers.
|
||||
|
||||
## Updating ProtocolLib for a Minecraft Release
|
||||
|
||||
Start by reviewing the [Java Edition protocol](https://minecraft.wiki/w/Java_Edition_protocol) and the corresponding
|
||||
server classes. The server packet classes and codecs are authoritative when documentation and implementation differ.
|
||||
|
||||
### 1. Update version metadata
|
||||
|
||||
- Update `mcVersion` in `gradle.properties`.
|
||||
- Add the release to `MinecraftVersion` and update `MinecraftVersion.LATEST`.
|
||||
- Update `ProtocolLibrary.MAXIMUM_MINECRAFT_VERSION` and `ProtocolLibrary.MINECRAFT_LAST_RELEASE_DATE`.
|
||||
- Update `MinecraftProtocolVersion` if the release changed the protocol number.
|
||||
|
||||
### 2. Reconcile packet types
|
||||
|
||||
`PacketType` must contain a matching definition for every packet in the current server protocol registries. Compare the
|
||||
serverbound and clientbound packet classes and codecs against every protocol phase, including configuration.
|
||||
|
||||
- Add new, renamed, or split packets and update their current IDs and aliases.
|
||||
- Do not remove an existing public `PacketType` constant. Move removed types to the deprecated section and document their
|
||||
replacement when one exists.
|
||||
- Represent split packets as separate packet types instead of redirecting incompatible packet shapes.
|
||||
- Run the packet registry tests after changing packet definitions. A missing definition can prevent later packets in the
|
||||
same protocol registry from being registered.
|
||||
|
||||
### 3. Update reflection and wrappers
|
||||
|
||||
- Inspect changed fields, constructors, records, nested classes, and stream codecs instead of relying only on class names.
|
||||
- Prefer structural or type-based reflection where names are unstable.
|
||||
- Treat the current server API shape as primary and use older supported shapes only as narrow compatibility fallbacks.
|
||||
- Put version checks at the narrowest compatibility boundary and leave the older path unchanged.
|
||||
- If an NMS concept was removed, report it as unsupported or absent rather than treating a different class as equivalent.
|
||||
- Preserve packet fields that are unrelated to the value being changed.
|
||||
- Keep converters symmetric and preserve wrapper cloning and equality semantics.
|
||||
- A custom `StructureModifier` must maintain the complete modifier contract, including safe reads and writes, field count,
|
||||
metadata, introspection, defaults, and `withTarget()`.
|
||||
|
||||
### 4. Add regression coverage
|
||||
|
||||
- Initialize the test environment with `BukkitInitialization` when tests access CraftBukkit or NMS classes.
|
||||
- Exercise the actual packet structure supplied by the current Paper dependency.
|
||||
- Cover both sides of a version guard when feasible.
|
||||
- Re-enable previously disabled tests when the underlying incompatibility is fixed.
|
||||
- Run targeted tests while developing, followed by `./gradlew test`.
|
||||
- Before declaring a Minecraft release supported, build the shaded plugin and test it on the corresponding server.
|
||||
|
||||
## Pull Request Expectations
|
||||
|
||||
- Keep the change limited to the reported problem or release update.
|
||||
- Include regression tests for packet, reflection, converter, or wrapper behavior changes.
|
||||
- Preserve public API signatures and binary compatibility where possible.
|
||||
- Clearly document any unavoidable compatibility change.
|
||||
- Do not hide reflection failures with broad exception handling or silent fallbacks.
|
||||
#### Ready? Let's get started!
|
||||
1. Read the [Protocol Changes](http://wiki.vg/Protocol_History). Always make sure the list is both
|
||||
complete and correct. If you're unsure, don't hesitate to ask in #mcdevs (the people who maintain wiki.vg) on [libera.chat](http://libera.chat)
|
||||
or #spigot on [irc.spi.gt](http://irc.spi.gt) ([webchat](https://irc.spi.gt/iris/?channels=spigot)).
|
||||
2. Search for usages of the now-defunct NMS package guard and change them.
|
||||
3. The class `com.comphenix.protocol.PacketType` contains a list of all the packets. If any packets were added or removed
|
||||
(or had their ID changed), make sure to update this list. If a packet was removed
|
||||
in favor of usage of another packet, instead of removing it, move it to the bottom of the list
|
||||
in its section, add a deprecation warning to it, and redirect it to the packet that replaced it.
|
||||
4. `mvn` in the root directory to build the project.
|
||||
5. If tests fail in the maven build, go through the tests to make sure you removed references to any removed packets
|
||||
and changed the NMS version guards.
|
||||
6. Increment the package version in `com.comphenix.protocol.utility.Constants`.
|
||||
7. `com.comphenix.protocol.ProtocolLibrary` contains several constants that must be updated, including the Minecraft version
|
||||
and the release date.
|
||||
8. `com.comphenix.protocol.utility.MinecraftProtocolVersion` contains a map of all the protocol version integers.
|
||||
If the protocol version has been incremented, add a new line to the map.
|
||||
9. `mvn` in root directory again. If it builds successfully, test on the appropriate version of a Spigot server. If
|
||||
the build fails, debug!
|
||||
@@ -17,7 +17,7 @@ jobs:
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '25'
|
||||
java-version: '21'
|
||||
cache: 'gradle'
|
||||
|
||||
- name: Run gradle build lifecycle
|
||||
@@ -27,6 +27,4 @@ jobs:
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ProtocolLib
|
||||
path: |
|
||||
build/libs/ProtocolLib.jar
|
||||
build/libs/ProtocolLib-Spigot.jar
|
||||
path: build/libs/ProtocolLib.jar
|
||||
@@ -16,7 +16,7 @@ jobs:
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '25'
|
||||
java-version: '21'
|
||||
cache: 'gradle'
|
||||
|
||||
- name: Run gradle build lifecycle
|
||||
@@ -27,9 +27,7 @@ jobs:
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ProtocolLib
|
||||
path: |
|
||||
build/libs/ProtocolLib.jar
|
||||
build/libs/ProtocolLib-Spigot.jar
|
||||
path: build/libs/ProtocolLib.jar
|
||||
|
||||
- name: Create or update GitHub pre-release
|
||||
env:
|
||||
@@ -43,4 +41,3 @@ jobs:
|
||||
NEW_NOTES="$RELEASE_NOTES"$'\n'"* [$SHORT_HASH] $COMMIT_MSG"
|
||||
gh release edit dev-build --notes "$NEW_NOTES" --repo ${{ github.repository }}
|
||||
gh release upload dev-build build/libs/ProtocolLib.jar#ProtocolLib.jar --clobber --repo ${{ github.repository }}
|
||||
gh release upload dev-build build/libs/ProtocolLib-Spigot.jar#ProtocolLib-Spigot.jar --clobber --repo ${{ github.repository }}
|
||||
@@ -1,124 +0,0 @@
|
||||
# ProtocolLib Agent Guide
|
||||
|
||||
This file applies to the entire repository. Read `.github/CONTRIBUTING.md` before changing Minecraft support, packet
|
||||
definitions, reflection, or public wrappers.
|
||||
|
||||
## Repository Basics
|
||||
|
||||
- The main project uses the Gradle wrapper. Do not use `TinyProtocol/pom.xml` to build ProtocolLib.
|
||||
- The Java toolchain and current Spigot dependency are defined in `build.gradle.kts`.
|
||||
- Keep the Java 25 build toolchain separate from the Java 17 production bytecode target.
|
||||
- Production code is under `src/main/java`; JUnit tests and NMS test initialization are under `src/test/java`.
|
||||
- Keep changes focused. Do not combine protocol fixes with unrelated cleanup or formatting.
|
||||
- Preserve public API and binary compatibility unless the task explicitly requires a breaking change.
|
||||
|
||||
## Build and Test Commands
|
||||
|
||||
```shell
|
||||
./gradlew test
|
||||
./gradlew build shadowJar
|
||||
```
|
||||
|
||||
Run the smallest relevant test while developing:
|
||||
|
||||
```shell
|
||||
./gradlew test --tests fully.qualified.TestClass
|
||||
./gradlew test --tests fully.qualified.TestClass.testMethod
|
||||
```
|
||||
|
||||
After changing production Java code, run the targeted tests and then the complete test suite. Use `build shadowJar` when
|
||||
the task affects packaging, dependencies, release support, or the final plugin artifact.
|
||||
|
||||
Do not introduce another build system, test runner, formatter, or lint tool unless the repository adopts it separately.
|
||||
|
||||
## Important Code Areas
|
||||
|
||||
- `PacketType.java`: public packet constants, current IDs, aliases, and deprecated packet definitions.
|
||||
- `injector/packet/internal/ProtocolRegistry_1_20_5.java`: current packet discovery and codec registration.
|
||||
- `utility/MinecraftVersion.java`: named Minecraft versions and the latest supported release.
|
||||
- `utility/MinecraftProtocolVersion.java`: Minecraft release to protocol-number mappings.
|
||||
- `ProtocolLibrary.java`: supported version bounds and latest release date.
|
||||
- `utility/MinecraftReflection.java`: centralized NMS and CraftBukkit class discovery.
|
||||
- `reflect/StructureModifier.java`: indexed packet field access and conversion contract.
|
||||
- `wrappers/`: stable public representations of unstable NMS structures.
|
||||
- `events/PacketContainer.java` and `events/AbstractStructure.java`: packet construction and typed field access.
|
||||
- `src/test/java/com/comphenix/protocol/BukkitInitialization.java`: test bootstrap for CraftBukkit and NMS access.
|
||||
|
||||
## Minecraft Release Updates
|
||||
|
||||
Follow the complete checklist in `.github/CONTRIBUTING.md`. In particular:
|
||||
|
||||
- Update all version metadata together; do not bump only the Gradle dependency.
|
||||
- Reconcile every serverbound and clientbound packet in every protocol phase with `PacketType`.
|
||||
- Add packet types for newly split packets instead of forcing incompatible shapes through an older packet constant.
|
||||
- Preserve removed public `PacketType` constants in the deprecated section.
|
||||
- Update `MinecraftProtocolVersion` only when the protocol number actually changed.
|
||||
|
||||
Every packet exposed by the current NMS protocol registries must have a matching `PacketType`. An undefined or incorrectly
|
||||
renamed packet can abort registration of later packets in the same registry.
|
||||
|
||||
## Version Compatibility
|
||||
|
||||
- Put version checks at the narrowest affected boundary.
|
||||
- Treat the current supported server API shape as the primary path. Use older supported shapes only as narrow fallbacks.
|
||||
- Keep the pre-change code path intact whenever possible.
|
||||
- Use named `MinecraftVersion` constants with `atOrAbove()` instead of scattered version strings.
|
||||
- A public method should keep the same signature and broad contract across versions.
|
||||
- If Minecraft removed a concept, return an unsupported or absent result consistent with existing APIs. Do not claim an
|
||||
unrelated packet or class is the removed type.
|
||||
- When Minecraft splits one packet into several packets, expose and use the new packet types explicitly.
|
||||
- Preserve unrelated packet fields when adapting or rewriting one logical value.
|
||||
|
||||
The current test dependency exercises the latest supported server. Review older guarded paths carefully because they may
|
||||
not execute in the local test run.
|
||||
|
||||
## Packet and Reflection Rules
|
||||
|
||||
- Treat the current server packet classes, record components, constructors, and codecs as authoritative.
|
||||
- Prefer existing `MinecraftReflection`, `FuzzyReflection`, and accessor helpers over new direct reflection.
|
||||
- Prefer structural and type-based matching where obfuscated names are unstable.
|
||||
- Search for an existing class resolver, converter, or accessor before adding another one.
|
||||
- Cache stable reflective lookups following nearby patterns; do not repeatedly scan classes on packet hot paths.
|
||||
- Do not hide reflection failures with broad catches, silent defaults, or unrelated fallback types.
|
||||
- Account for static fields, inherited fields, records, nested implementations, and duplicate field types when writing
|
||||
fuzzy contracts.
|
||||
|
||||
## `StructureModifier` Contract
|
||||
|
||||
Typed accessors returned from packet APIs must behave like normal `StructureModifier` instances.
|
||||
|
||||
- `size()`, `getFields()`, `getField()`, target metadata, and field metadata must agree.
|
||||
- `readSafely()` returns `null` for an absent index.
|
||||
- `writeSafely()` ignores an absent index without throwing.
|
||||
- `withTarget()` must preserve the modifier's behavior for the new target.
|
||||
- `writeDefaults()` must remain safe.
|
||||
- Converters must be applied symmetrically on reads and writes.
|
||||
|
||||
If a packet no longer contains a real backing field, prefer an empty modifier when compatible. If a virtual field is
|
||||
required for API compatibility, initialize all modifier metadata and test its inherited methods.
|
||||
|
||||
## Wrapper and Converter Rules
|
||||
|
||||
- Wrapper factories, converters, getters, setters, and `deepClone()` must describe the same logical value.
|
||||
- Preserve converter symmetry: converting specific to generic and back must not unexpectedly lose represented state.
|
||||
- If a wrapper handle changes from a nested value to an entire packet, define logical `equals()` and `hashCode()` so
|
||||
unrelated packet metadata does not affect equality.
|
||||
- Clones that represent the same logical value should compare equal.
|
||||
- Do not fabricate legacy states that the modern wire format cannot distinguish; document or surface the limitation.
|
||||
- Record or immutable packet updates must retain entity IDs, flags, and other components not owned by the wrapper.
|
||||
|
||||
## Tests
|
||||
|
||||
- Call `BukkitInitialization.initializeAll()` before tests that resolve CraftBukkit or NMS classes.
|
||||
- Prefer regression tests using the actual Spigot packet classes supplied by the test dependency.
|
||||
- Test reads, writes, safe access, cloning, equality, and preservation of unrelated fields when changing wrappers.
|
||||
- Test modifier metadata and inherited methods when introducing a custom `StructureModifier`.
|
||||
- Re-enable disabled tests when fixing the incompatibility that caused them to be disabled.
|
||||
- Do not weaken assertions or encode known incorrect behavior merely to make a new Minecraft version pass.
|
||||
|
||||
## Documentation and Review
|
||||
|
||||
- Update Javadocs when version support, nullability, or unsupported behavior changes.
|
||||
- Update `.github/CONTRIBUTING.md` when the repository-wide build or release workflow changes.
|
||||
- Keep this file operational and durable; do not add task-specific notes, temporary workarounds, or current PR details.
|
||||
- Before finishing, inspect the complete diff for accidental API changes and unrelated edits.
|
||||
@@ -14,19 +14,16 @@ lead to more subtle bugs.
|
||||
|
||||
* [Spigot Page](https://spigotmc.org/resources/protocollib.1997/)
|
||||
* [Releases](https://github.com/dmulloy2/ProtocolLib/releases)
|
||||
* [Dev Builds](https://ci.dmulloy2.net/job/ProtocolLib/)
|
||||
* [JavaDoc](https://ci.dmulloy2.net/job/ProtocolLib/javadoc/index.html)
|
||||
* [Dev Build](https://github.com/dmulloy2/ProtocolLib/releases/tag/dev-build)
|
||||
* [JavaDoc](https://dmulloy2.net/ProtocolLib/javadoc/)
|
||||
* [Protocol Wiki](https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Protocol)
|
||||
|
||||
`ProtocolLib.jar` is the primary Paper plugin. Spigot servers must use the compatibility artifact,
|
||||
`ProtocolLib-Spigot.jar`. The Maven artifact is the platform-neutral library shared by both distributions.
|
||||
|
||||
### Compilation
|
||||
|
||||
ProtocolLib is built with [Gradle](https://gradle.org/). If you have it installed, just run
|
||||
`./gradlew build` in the root project folder. Other gradle targets you may be interested in
|
||||
include `clean`, `test`, and `shadowJar`. `shadowJar` will create a jar with all dependencies
|
||||
(ByteBuddy) included for both Paper and Spigot.
|
||||
(ByteBuddy) included.
|
||||
|
||||
### A new API
|
||||
|
||||
@@ -69,48 +66,6 @@ dependencies {
|
||||
}
|
||||
```
|
||||
|
||||
#### Snapshot builds
|
||||
|
||||
Snapshot builds are available for testing changes before the next release. To use `5.5.0-SNAPSHOT`,
|
||||
add the [public repository](https://repo.dmulloy2.net/repository/public/) and update your dependency version.
|
||||
|
||||
For Maven:
|
||||
|
||||
```xml
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>dmulloy2-public</id>
|
||||
<url>https://repo.dmulloy2.net/repository/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.dmulloy2</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>5.5.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
```
|
||||
|
||||
For Gradle:
|
||||
|
||||
```gradle
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url = uri('https://repo.dmulloy2.net/repository/public/')
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly 'net.dmulloy2:ProtocolLib:5.5.0-SNAPSHOT'
|
||||
}
|
||||
```
|
||||
|
||||
#### Accessing the API
|
||||
|
||||
Then get a reference to ProtocolManager in onLoad() or onEnable() and you're good to go.
|
||||
|
||||
````java
|
||||
@@ -137,26 +92,25 @@ protocolManager.addPacketListener(new PacketAdapter(
|
||||
});
|
||||
````
|
||||
|
||||
It's also possible to read and modify the content of packets, including the ones sent by a client. For
|
||||
instance, you can censor the text players write on signs by listening for `UPDATE_SIGN` packets:
|
||||
It's also possible to read and modify the content of these packets. For instance, you can create a global
|
||||
censor by listening for Packet3Chat events:
|
||||
|
||||
````java
|
||||
// Censor signs
|
||||
// Censor
|
||||
protocolManager.addPacketListener(new PacketAdapter(
|
||||
this,
|
||||
ListenerPriority.NORMAL,
|
||||
PacketType.Play.Client.UPDATE_SIGN
|
||||
PacketType.Play.Client.CHAT
|
||||
) {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
PacketContainer packet = event.getPacket();
|
||||
String[] lines = packet.getStringArrays().read(0);
|
||||
String message = packet.getStrings().read(0);
|
||||
|
||||
for (int i = 0; i < lines.length; i++) {
|
||||
lines[i] = lines[i].replace("shit", "****").replace("damn", "****");
|
||||
if (message.contains("shit") || message.contains("damn")) {
|
||||
event.setCancelled(true);
|
||||
event.getPlayer().sendMessage("Bad manners!");
|
||||
}
|
||||
|
||||
packet.getStringArrays().write(0, lines);
|
||||
}
|
||||
});
|
||||
````
|
||||
|
||||
@@ -64,7 +64,7 @@ public abstract class TinyProtocol {
|
||||
|
||||
// Packets we have to intercept
|
||||
private static final Class<?> PACKET_LOGIN_IN_START = Reflection.getClass("{nms}.PacketLoginInStart", "net.minecraft.network.protocol.login.PacketLoginInStart");
|
||||
private static final FieldAccessor<String> getPlayerName = new PlayerNameAccessor();
|
||||
private static final FieldAccessor<GameProfile> getGameProfile = Reflection.getField(PACKET_LOGIN_IN_START, GameProfile.class, 0);
|
||||
|
||||
// Speedup channel lookup
|
||||
private Map<String, Channel> channelLookup = new MapMaker().weakValues().makeMap();
|
||||
@@ -492,59 +492,6 @@ public abstract class TinyProtocol {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the player name from the login start packet.
|
||||
* This fixes the issue from 1.19 where the GameProfile field has been removed from this login packet.
|
||||
*
|
||||
* @author gamerover98
|
||||
*/
|
||||
private static class PlayerNameAccessor implements FieldAccessor<String> {
|
||||
|
||||
private FieldAccessor<String> getPlayerName;
|
||||
private FieldAccessor<GameProfile> getGameProfile;
|
||||
|
||||
PlayerNameAccessor() {
|
||||
try {
|
||||
this.getGameProfile = Reflection.getField(PACKET_LOGIN_IN_START, GameProfile.class, 0);
|
||||
} catch (IllegalArgumentException illegalArgumentException) {
|
||||
// nothing to do.
|
||||
}
|
||||
|
||||
try {
|
||||
//HOT-FIX for 1.19+
|
||||
this.getPlayerName = Reflection.getField(PACKET_LOGIN_IN_START, String.class, 0);
|
||||
} catch (IllegalArgumentException illegalArgumentException) {
|
||||
// nothing to do.
|
||||
}
|
||||
|
||||
if (getGameProfile == null && getPlayerName == null) {
|
||||
throw new UnsupportedOperationException("The current server version is not supported by TinyProtocol");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get(Object target) {
|
||||
if (getPlayerName != null) {
|
||||
String playerName = getPlayerName.get(target);
|
||||
return playerName.substring(0, Math.min(16, playerName.length()));
|
||||
}
|
||||
|
||||
return getGameProfile.get(target).getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(Object target, Object value) {
|
||||
throw new UnsupportedOperationException("Not supported");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasField(Object target) {
|
||||
return getPlayerName != null
|
||||
? getPlayerName.hasField(target)
|
||||
: getGameProfile.hasField(target);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Channel handler that is inserted into the player's channel pipeline, allowing us to intercept sent and received packets.
|
||||
*
|
||||
@@ -586,7 +533,8 @@ public abstract class TinyProtocol {
|
||||
|
||||
private void handleLoginStart(Channel channel, Object packet) {
|
||||
if (PACKET_LOGIN_IN_START.isInstance(packet)) {
|
||||
channelLookup.put(getPlayerName.get(packet), channel);
|
||||
GameProfile profile = getGameProfile.get(packet);
|
||||
channelLookup.put(profile.getName(), channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+75
-35
@@ -1,20 +1,38 @@
|
||||
//import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
//import io.github.patrick.gradle.remapper.RemapTask
|
||||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar.Companion.shadowJar
|
||||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
||||
|
||||
plugins {
|
||||
`java-library`
|
||||
`maven-publish`
|
||||
signing
|
||||
id("io.github.patrick.remapper") version "1.4.3"
|
||||
id("com.vanniktech.maven.publish") version "0.36.0"
|
||||
`signing`
|
||||
id("com.gradleup.shadow") version "9.0.2"
|
||||
// id("io.github.patrick.remapper") version "1.4.2"
|
||||
id("com.vanniktech.maven.publish") version "0.34.0"
|
||||
id("io.papermc.paperweight.userdev") version "2.0.0-beta.18"
|
||||
}
|
||||
|
||||
group = "net.dmulloy2"
|
||||
description = "Provides access to the Minecraft protocol"
|
||||
|
||||
val mcVersion: String by project
|
||||
val mcVersion = "1.21.8"
|
||||
val isSnapshot = version.toString().endsWith("-SNAPSHOT")
|
||||
val isJitPack = System.getenv("JITPACK")?.equals("true", ignoreCase = true) ?: false
|
||||
val commitHash = System.getenv("COMMIT_SHA") ?: ""
|
||||
val isCI = commitHash.isNotEmpty()
|
||||
|
||||
paperweight {
|
||||
reobfArtifactConfiguration = io.papermc.paperweight.userdev.ReobfArtifactConfiguration.REOBF_PRODUCTION
|
||||
}
|
||||
|
||||
tasks.assemble {
|
||||
dependsOn(tasks.reobfJar)
|
||||
}
|
||||
|
||||
/*tasks.shadowJar {
|
||||
dependsOn(tasks.assemble)
|
||||
}*/
|
||||
|
||||
repositories {
|
||||
if (!isCI) {
|
||||
mavenLocal()
|
||||
@@ -41,35 +59,66 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("net.bytebuddy:byte-buddy:1.18.2")
|
||||
compileOnly("org.spigotmc:spigot-api:${mcVersion}-R0.1-SNAPSHOT")
|
||||
compileOnly("org.spigotmc:spigot:${mcVersion}-R0.1-SNAPSHOT")
|
||||
compileOnly("io.netty:netty-all:4.2.8.Final")
|
||||
compileOnly("net.kyori:adventure-text-serializer-gson:4.25.0")
|
||||
implementation("net.bytebuddy:byte-buddy:1.17.5")
|
||||
// compileOnly("org.spigotmc:spigot-api:${mcVersion}-R0.1-SNAPSHOT")
|
||||
// compileOnly("org.spigotmc:spigot:${mcVersion}-R0.1-SNAPSHOT:remapped-mojang")
|
||||
compileOnly("io.netty:netty-all:4.0.23.Final")
|
||||
compileOnly("net.kyori:adventure-text-serializer-gson:4.24.0")
|
||||
compileOnly("net.kyori:adventure-text-serializer-ansi:4.24.0")
|
||||
compileOnly("com.googlecode.json-simple:json-simple:1.1.1")
|
||||
compileOnly("commons-lang:commons-lang:2.6")
|
||||
|
||||
paperweight.paperDevBundle("1.21.8-R0.1-SNAPSHOT")
|
||||
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-engine:5.10.0")
|
||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.0")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.10.0")
|
||||
testImplementation("org.mockito:mockito-core:5.6.0")
|
||||
testImplementation("io.netty:netty-common:4.1.97.Final")
|
||||
testImplementation("io.netty:netty-transport:4.1.97.Final")
|
||||
// testImplementation("org.spigotmc:spigot:${mcVersion}-R0.1-SNAPSHOT:remapped-mojang")
|
||||
testImplementation("net.kyori:adventure-text-serializer-gson:4.24.0")
|
||||
testImplementation("net.kyori:adventure-text-serializer-plain:4.24.0")
|
||||
testImplementation("net.kyori:adventure-text-serializer-ansi:4.24.0")
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(25))
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
test {
|
||||
java.setSrcDirs(emptyList<String>())
|
||||
resources.setSrcDirs(emptyList<String>())
|
||||
}
|
||||
sourceCompatibility = JavaVersion.VERSION_21
|
||||
targetCompatibility = JavaVersion.VERSION_21
|
||||
}
|
||||
|
||||
tasks {
|
||||
test {
|
||||
dependsOn(":paper:test")
|
||||
processResources {
|
||||
val fullVersion = if (isSnapshot && isCI) "${version}-${commitHash.take(7)}" else version
|
||||
|
||||
eachFile {
|
||||
expand("version" to fullVersion)
|
||||
}
|
||||
}
|
||||
|
||||
check {
|
||||
dependsOn(":paper:check", ":spigot:check")
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
exceptionFormat = TestExceptionFormat.FULL
|
||||
}
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
dependencies {
|
||||
include(dependency("net.bytebuddy:byte-buddy:.*"))
|
||||
}
|
||||
relocate("net.bytebuddy", "com.comphenix.net.bytebuddy")
|
||||
|
||||
/*manifest {
|
||||
attributes(
|
||||
"paperweight-mappings-namespace" to "mojang"
|
||||
)
|
||||
}*/
|
||||
|
||||
// archiveFileName = "ProtocolLib.jar"
|
||||
}
|
||||
|
||||
reobfJar {
|
||||
outputJar = layout.buildDirectory.file("libs/ProtocolLib.jar")
|
||||
}
|
||||
|
||||
javadoc {
|
||||
@@ -78,21 +127,12 @@ tasks {
|
||||
|
||||
compileJava {
|
||||
options.encoding = "UTF-8"
|
||||
options.release.set(17)
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register("shadowJar") {
|
||||
group = "build"
|
||||
description = "Builds the Paper and Spigot plugin distributions."
|
||||
dependsOn(":paper:shadowJar", ":spigot:shadowJar")
|
||||
}
|
||||
|
||||
mavenPublishing {
|
||||
publishToMavenCentral()
|
||||
if (!isSnapshot && !isJitPack) {
|
||||
signAllPublications()
|
||||
}
|
||||
signAllPublications()
|
||||
|
||||
coordinates("$group", project.name, "$version")
|
||||
|
||||
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
version=5.5.0-SNAPSHOT
|
||||
mcVersion=26.3
|
||||
version=5.4.1-SNAPSHOT
|
||||
mavenCentralUsername=
|
||||
mavenCentralPassword=
|
||||
signing.keyId=
|
||||
|
||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015 the original authors.
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -15,8 +15,6 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
@@ -57,7 +55,7 @@
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/2d6327017519d23b96af35865dc997fcb544fb40/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
@@ -86,7 +84,7 @@ done
|
||||
# shellcheck disable=SC2034
|
||||
APP_BASE_NAME=${0##*/}
|
||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
@@ -114,6 +112,7 @@ case "$( uname )" in #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
@@ -171,6 +170,7 @@ fi
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
@@ -203,14 +203,15 @@ fi
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
|
||||
Vendored
+12
-13
@@ -13,8 +13,6 @@
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
@rem SPDX-License-Identifier: Apache-2.0
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@@ -45,11 +43,11 @@ set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
@@ -59,21 +57,22 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo. 1>&2
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||
echo. 1>&2
|
||||
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||
echo location of your Java installation. 1>&2
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
import org.gradle.api.attributes.java.TargetJvmVersion
|
||||
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
|
||||
|
||||
plugins {
|
||||
`java-library`
|
||||
id("com.gradleup.shadow") version "9.4.0"
|
||||
id("io.papermc.paperweight.userdev") version "2.0.0-beta.21"
|
||||
}
|
||||
|
||||
group = "net.dmulloy2"
|
||||
version = rootProject.version
|
||||
|
||||
val mcVersion: String by project
|
||||
val isSnapshot = version.toString().endsWith("-SNAPSHOT")
|
||||
val commitHash = System.getenv("COMMIT_SHA") ?: ""
|
||||
val isCI = commitHash.isNotEmpty()
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
maven("https://repo.codemc.io/repository/nms/")
|
||||
maven("https://hub.spigotmc.org/nexus/content/groups/public/")
|
||||
maven("https://libraries.minecraft.net/") {
|
||||
metadataSources {
|
||||
mavenPom()
|
||||
artifact()
|
||||
ignoreGradleMetadataRedirection()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":"))
|
||||
paperweight.paperDevBundle("$mcVersion.build.+")
|
||||
|
||||
compileOnly("io.netty:netty-all:4.2.8.Final")
|
||||
compileOnly("net.kyori:adventure-text-serializer-gson:4.25.0")
|
||||
compileOnly("commons-lang:commons-lang:2.6")
|
||||
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-engine:6.0.1")
|
||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:6.0.1")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher:6.0.1")
|
||||
testImplementation("org.mockito:mockito-core:5.21.0")
|
||||
testImplementation("io.netty:netty-common:4.2.8.Final")
|
||||
testImplementation("io.netty:netty-transport:4.2.8.Final")
|
||||
testImplementation("net.kyori:adventure-text-serializer-gson:4.25.0")
|
||||
testImplementation("net.kyori:adventure-text-serializer-plain:4.25.0")
|
||||
testImplementation("commons-lang:commons-lang:2.6")
|
||||
}
|
||||
|
||||
paperweight.reobfArtifactConfiguration =
|
||||
io.papermc.paperweight.userdev.ReobfArtifactConfiguration.MOJANG_PRODUCTION
|
||||
|
||||
configurations.matching { it.name == "compileClasspath" || it.name == "runtimeClasspath" || it.name == "testCompileClasspath" || it.name == "testRuntimeClasspath" }.configureEach {
|
||||
attributes {
|
||||
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 25)
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(25))
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
test {
|
||||
java.srcDir(rootProject.file("src/test/java"))
|
||||
resources.srcDir(rootProject.file("src/test/resources"))
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
processResources {
|
||||
val fullVersion = if (isSnapshot && isCI) "${version}-${commitHash.take(7)}" else version
|
||||
|
||||
eachFile {
|
||||
expand("version" to fullVersion)
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
testLogging {
|
||||
exceptionFormat = TestExceptionFormat.FULL
|
||||
}
|
||||
}
|
||||
|
||||
compileJava {
|
||||
options.release.set(17)
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate("net.bytebuddy", "com.comphenix.net.bytebuddy")
|
||||
|
||||
manifest {
|
||||
attributes("paperweight-mappings-namespace" to "mojang")
|
||||
}
|
||||
|
||||
destinationDirectory.set(rootProject.layout.buildDirectory.dir("libs"))
|
||||
archiveFileName.set("ProtocolLib.jar")
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
package com.comphenix.protocol.paper;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLib;
|
||||
import com.comphenix.protocol.internal.PlatformProvider;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.papermc.paper.command.brigadier.BasicCommand;
|
||||
import io.papermc.paper.command.brigadier.CommandSourceStack;
|
||||
import io.papermc.paper.network.ChannelInitializeListenerHolder;
|
||||
import net.kyori.adventure.key.Key;
|
||||
|
||||
public final class PaperPlatformProvider implements PlatformProvider {
|
||||
|
||||
public static final Key CHANNEL_INITIALIZER_KEY = Key.key("protocollib", "channel-initializer");
|
||||
|
||||
@Override
|
||||
public boolean hasEarlyChannelInitialization() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Runnable registerChannelInitializer(Consumer<Channel> channelInitializer) {
|
||||
ChannelInitializeListenerHolder.addListener(CHANNEL_INITIALIZER_KEY, channelInitializer::accept);
|
||||
return () -> ChannelInitializeListenerHolder.removeListener(CHANNEL_INITIALIZER_KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCommand(ProtocolLib plugin, String name, CommandExecutor executor) {
|
||||
CommandMetadata metadata = getMetadata(name);
|
||||
Command command = new RegisteredCommand(name, metadata);
|
||||
|
||||
plugin.registerCommand(
|
||||
name,
|
||||
metadata.description(),
|
||||
metadata.aliases(),
|
||||
new RegisteredBasicCommand(name, metadata, command, executor));
|
||||
}
|
||||
|
||||
private static CommandMetadata getMetadata(String name) {
|
||||
return switch (name) {
|
||||
case "protocol" -> new CommandMetadata(
|
||||
"Performs administrative tasks regarding ProtocolLib.",
|
||||
"/<command> config|check|update|timings|listeners|version|dump",
|
||||
"protocol.admin",
|
||||
List.of());
|
||||
case "packet" -> new CommandMetadata(
|
||||
"Add or remove a simple packet listener.",
|
||||
"/<command> add|remove|names client|server [ID start]-[ID stop] [detailed]",
|
||||
"protocol.admin",
|
||||
List.of());
|
||||
case "filter" -> new CommandMetadata(
|
||||
"Add or remove programmable filters to the packet listeners.",
|
||||
"/<command> add|remove name [ID start]-[ID stop]",
|
||||
"protocol.admin",
|
||||
List.of("packet_filter"));
|
||||
case "packetlog" -> new CommandMetadata(
|
||||
"Logs hex representations of packets to a file or console",
|
||||
"/<command> <protocol> <sender> <packet> [location]",
|
||||
"protocol.admin",
|
||||
List.of());
|
||||
default -> throw new IllegalArgumentException("Unknown ProtocolLib command " + name);
|
||||
};
|
||||
}
|
||||
|
||||
private record CommandMetadata(String description, String usage, String permission, List<String> aliases) {
|
||||
}
|
||||
|
||||
private record RegisteredBasicCommand(
|
||||
String name,
|
||||
CommandMetadata metadata,
|
||||
Command command,
|
||||
CommandExecutor executor) implements BasicCommand {
|
||||
|
||||
@Override
|
||||
public void execute(CommandSourceStack source, String[] arguments) {
|
||||
if (!this.executor.onCommand(source.getSender(), this.command, this.name, arguments)) {
|
||||
source.getSender().sendMessage(this.metadata.usage().replace("<command>", this.name));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String permission() {
|
||||
return this.metadata.permission();
|
||||
}
|
||||
}
|
||||
|
||||
private static final class RegisteredCommand extends Command {
|
||||
|
||||
private RegisteredCommand(String name, CommandMetadata metadata) {
|
||||
super(name, metadata.description(), metadata.usage(), metadata.aliases());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
}
|
||||
-1
@@ -1 +0,0 @@
|
||||
com.comphenix.protocol.paper.PaperPlatformProvider
|
||||
@@ -1,22 +0,0 @@
|
||||
name: ProtocolLib
|
||||
version: ${version}
|
||||
description: Provides read/write access to the Minecraft protocol.
|
||||
authors: [dmulloy2]
|
||||
|
||||
main: com.comphenix.protocol.ProtocolLib
|
||||
load: STARTUP
|
||||
api-version: "26.3"
|
||||
folia-supported: true
|
||||
|
||||
permissions:
|
||||
protocol.*:
|
||||
description: Gives access to everything.
|
||||
children:
|
||||
protocol.admin: true
|
||||
protocol.info: true
|
||||
protocol.admin:
|
||||
description: Able to initiate the update process and configure debug mode.
|
||||
default: op
|
||||
protocol.info:
|
||||
description: Can read update notifications and error reports.
|
||||
default: op
|
||||
@@ -3,5 +3,3 @@
|
||||
*/
|
||||
|
||||
rootProject.name = 'ProtocolLib'
|
||||
|
||||
include 'paper', 'spigot'
|
||||
@@ -1,79 +0,0 @@
|
||||
import org.gradle.api.attributes.java.TargetJvmVersion
|
||||
|
||||
plugins {
|
||||
`java-library`
|
||||
id("com.gradleup.shadow") version "9.4.0"
|
||||
}
|
||||
|
||||
group = "net.dmulloy2"
|
||||
version = rootProject.version
|
||||
|
||||
val mcVersion: String by project
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
maven("https://repo.codemc.io/repository/nms/")
|
||||
maven("https://hub.spigotmc.org/nexus/content/groups/public/")
|
||||
maven("https://libraries.minecraft.net/") {
|
||||
metadataSources {
|
||||
mavenPom()
|
||||
artifact()
|
||||
ignoreGradleMetadataRedirection()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":"))
|
||||
compileOnly("org.spigotmc:spigot-api:${mcVersion}-R0.1-SNAPSHOT")
|
||||
compileOnly("org.spigotmc:spigot:${mcVersion}-R0.1-SNAPSHOT")
|
||||
compileOnly("io.netty:netty-all:4.2.8.Final")
|
||||
compileOnly("net.kyori:adventure-text-serializer-gson:4.25.0")
|
||||
compileOnly("com.googlecode.json-simple:json-simple:1.1.1")
|
||||
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-engine:6.0.1")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher:6.0.1")
|
||||
testImplementation("org.mockito:mockito-core:5.21.0")
|
||||
testImplementation("io.netty:netty-transport:4.2.8.Final")
|
||||
testImplementation("org.spigotmc:spigot:${mcVersion}-R0.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
configurations.matching { it.name == "compileClasspath" || it.name == "runtimeClasspath" || it.name == "testCompileClasspath" || it.name == "testRuntimeClasspath" }.configureEach {
|
||||
attributes {
|
||||
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 25)
|
||||
}
|
||||
}
|
||||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion.set(JavaLanguageVersion.of(25))
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
processResources {
|
||||
eachFile {
|
||||
expand("version" to project.version)
|
||||
}
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
compileJava {
|
||||
options.release.set(17)
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
relocate("net.bytebuddy", "com.comphenix.net.bytebuddy")
|
||||
|
||||
manifest {
|
||||
attributes("paperweight-mappings-namespace" to "mojang")
|
||||
}
|
||||
|
||||
destinationDirectory.set(rootProject.layout.buildDirectory.dir("libs"))
|
||||
archiveFileName.set("ProtocolLib-Spigot.jar")
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package com.comphenix.protocol.spigot;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLib;
|
||||
import com.comphenix.protocol.internal.PlatformProvider;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
|
||||
public final class SpigotPlatformProvider implements PlatformProvider {
|
||||
|
||||
@Override
|
||||
public boolean hasEarlyChannelInitialization() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Runnable registerChannelInitializer(Consumer<Channel> channelInitializer) {
|
||||
throw new UnsupportedOperationException("Early channel initialization is unavailable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCommand(ProtocolLib plugin, String name, CommandExecutor executor) {
|
||||
PluginCommand command = plugin.getCommand(name);
|
||||
if (command == null) {
|
||||
throw new IllegalStateException("plugin.yml might be corrupt.");
|
||||
}
|
||||
|
||||
command.setExecutor(executor);
|
||||
}
|
||||
}
|
||||
-1
@@ -1 +0,0 @@
|
||||
com.comphenix.protocol.spigot.SpigotPlatformProvider
|
||||
@@ -1,26 +0,0 @@
|
||||
package com.comphenix.protocol;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.comphenix.protocol.spigot.SpigotPlatformProvider;
|
||||
|
||||
class PlatformCommandRegistrarTest {
|
||||
|
||||
@Test
|
||||
void registersLegacyExecutorFromPluginDescriptor() {
|
||||
ProtocolLib plugin = mock(ProtocolLib.class);
|
||||
CommandExecutor executor = mock(CommandExecutor.class);
|
||||
PluginCommand command = mock(PluginCommand.class);
|
||||
when(plugin.getCommand("protocol")).thenReturn(command);
|
||||
|
||||
new SpigotPlatformProvider().registerCommand(plugin, "protocol", executor);
|
||||
|
||||
verify(command).setExecutor(executor);
|
||||
}
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
package com.comphenix.protocol.injector.netty.manager;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.comphenix.protocol.internal.PlatformProvider;
|
||||
class PlatformChannelInitializerTest {
|
||||
|
||||
@Test
|
||||
void reportsPaperInitializerUnavailable() {
|
||||
PlatformProvider provider = PlatformProvider.get();
|
||||
assertInstanceOf(com.comphenix.protocol.spigot.SpigotPlatformProvider.class, provider);
|
||||
assertFalse(provider.hasEarlyChannelInitialization());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.comphenix.protocol;
|
||||
|
||||
import com.comphenix.protocol.injector.PacketFilterManager;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
|
||||
class BukkitListener implements Listener {
|
||||
private final PacketFilterManager manager;
|
||||
|
||||
BukkitListener(PacketFilterManager manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
// @EventHandler(priority = EventPriority.LOWEST)
|
||||
// public void handleLogin(PlayerLoginEvent event) {
|
||||
// networkManagerInjector.getInjector(event.getPlayer()).inject();
|
||||
// }
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void handleJoin(PlayerJoinEvent event) {
|
||||
manager.injectPlayer(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void handleQuit(PlayerQuitEvent event) {
|
||||
manager.removePlayer(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void handlePluginUnload(PluginDisableEvent event) {
|
||||
manager.removePacketListeners(event.getPlugin());
|
||||
}
|
||||
}
|
||||
@@ -21,21 +21,19 @@ import java.util.ArrayDeque;
|
||||
import java.util.Arrays;
|
||||
import java.util.Deque;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.comphenix.protocol.error.ErrorReporter;
|
||||
import com.comphenix.protocol.error.Report;
|
||||
import com.comphenix.protocol.error.ReportType;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
/**
|
||||
* Base class for all our commands.
|
||||
*
|
||||
* @author Kristian
|
||||
*/
|
||||
abstract class CommandBase implements CommandExecutor {
|
||||
abstract class CommandBase {
|
||||
public static final ReportType REPORT_COMMAND_ERROR = new ReportType("Cannot execute command %s.");
|
||||
public static final ReportType REPORT_UNEXPECTED_COMMAND = new ReportType("Incorrect command assigned to %s.");
|
||||
|
||||
@@ -58,15 +56,8 @@ abstract class CommandBase implements CommandExecutor {
|
||||
this.minimumArgumentCount = minimumArgumentCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
public boolean onCommand(CommandSender sender, String[] args) {
|
||||
try {
|
||||
// Make sure we're dealing with the correct command
|
||||
if (!command.getName().equalsIgnoreCase(name)) {
|
||||
reporter.reportWarning(this, Report.newBuilder(REPORT_UNEXPECTED_COMMAND).messageParam(this));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (permission != null && !sender.hasPermission(permission)) {
|
||||
sender.sendMessage(ChatColor.RED + "You haven't got permission to run this command.");
|
||||
return true;
|
||||
@@ -81,7 +72,7 @@ abstract class CommandBase implements CommandExecutor {
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
reporter.reportDetailed(this,
|
||||
Report.newBuilder(REPORT_COMMAND_ERROR).error(ex).messageParam(name).callerParam(sender, label, args)
|
||||
Report.newBuilder(REPORT_COMMAND_ERROR).error(ex).messageParam(name).callerParam(sender, name, args)
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -120,9 +120,25 @@ class CommandProtocol extends CommandBase {
|
||||
return;
|
||||
}
|
||||
|
||||
// Top-level class instead of anonymous inner class so that PaperPluginClassLoader
|
||||
// can resolve the .class entry when BukkitScheduler dispatches it on the main thread.
|
||||
Runnable notify = new UpdateNotifyRunnable(sender, command, updater, config, plugin, this);
|
||||
// Perform on an async thread
|
||||
Runnable notify = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (command) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "[ProtocolLib] " + updater.getResult());
|
||||
String remoteVersion = updater.getRemoteVersion();
|
||||
if (remoteVersion != null) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Remote version: " + remoteVersion);
|
||||
sender.sendMessage(ChatColor.YELLOW + "Current version: " + plugin.getDescription().getVersion());
|
||||
}
|
||||
} else if (updater.shouldNotify() || config.isDebug()) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "[ProtocolLib] " + updater.getResult());
|
||||
}
|
||||
|
||||
updater.removeListener(this);
|
||||
updateFinished();
|
||||
}
|
||||
};
|
||||
updater.start(type);
|
||||
updater.addListener(notify);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.comphenix.protocol;
|
||||
|
||||
import com.comphenix.protocol.injector.PacketFilterManager;
|
||||
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
|
||||
class LegacyLoginListener implements Listener {
|
||||
private final PacketFilterManager manager;
|
||||
|
||||
LegacyLoginListener(PacketFilterManager manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void handleLogin(PlayerLoginEvent event) {
|
||||
manager.injectPlayer(event.getPlayer());
|
||||
}
|
||||
}
|
||||
@@ -16,22 +16,6 @@
|
||||
*/
|
||||
package com.comphenix.protocol;
|
||||
|
||||
import com.comphenix.protocol.PacketType.Protocol;
|
||||
import com.comphenix.protocol.PacketType.Sender;
|
||||
import com.comphenix.protocol.events.ListeningWhitelist;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import com.comphenix.protocol.injector.netty.WirePacket;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -48,11 +32,28 @@ import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.comphenix.protocol.PacketType.Protocol;
|
||||
import com.comphenix.protocol.PacketType.Sender;
|
||||
import com.comphenix.protocol.error.ErrorReporter;
|
||||
import com.comphenix.protocol.events.ListeningWhitelist;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import com.comphenix.protocol.injector.PacketFilterManager;
|
||||
import com.comphenix.protocol.injector.netty.WirePacket;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Logs packets to a given stream
|
||||
* @author dmulloy2
|
||||
*/
|
||||
public class PacketLogging implements CommandExecutor, PacketListener {
|
||||
public class PacketLogging extends CommandBase implements PacketListener {
|
||||
public static final String NAME = "packetlog";
|
||||
|
||||
private static MethodAccessor HEX_DUMP;
|
||||
@@ -69,93 +70,94 @@ public class PacketLogging implements CommandExecutor, PacketListener {
|
||||
private final ProtocolManager manager;
|
||||
private final Plugin plugin;
|
||||
|
||||
PacketLogging(Plugin plugin, ProtocolManager manager) {
|
||||
PacketLogging(ErrorReporter reporter, Plugin plugin, PacketFilterManager manager) {
|
||||
super(reporter, CommandBase.PERMISSION_ADMIN, NAME, 2);
|
||||
this.plugin = plugin;
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
public boolean handleCommand(CommandSender sender, String[] args) {
|
||||
PacketType type = null;
|
||||
|
||||
try {
|
||||
if (args.length > 2) {
|
||||
Protocol protocol;
|
||||
if (args.length <= 2) {
|
||||
sender.sendMessage(ChatColor.RED + "Invalid syntax: /packetlog <protocol> <sender> <packet> [location]");
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
protocol = Protocol.valueOf(args[0].toUpperCase());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
sender.sendMessage(ChatColor.RED + "Unknown protocol " + args[0]);
|
||||
return true;
|
||||
}
|
||||
Protocol protocol;
|
||||
|
||||
Sender pSender;
|
||||
try {
|
||||
protocol = Protocol.valueOf(args[0].toUpperCase());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
sender.sendMessage(ChatColor.RED + "Unknown protocol " + args[0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
pSender = Sender.valueOf(args[1].toUpperCase());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
sender.sendMessage(ChatColor.RED + "Unknown sender: " + args[1]);
|
||||
return true;
|
||||
}
|
||||
Sender pSender;
|
||||
|
||||
try {
|
||||
try { // Try IDs first
|
||||
int id = Integer.parseInt(args[2]);
|
||||
type = PacketType.findCurrent(protocol, pSender, id);
|
||||
} catch (NumberFormatException ex) { // Check packet names
|
||||
String name = args[2];
|
||||
for (PacketType packet : PacketType.values()) {
|
||||
if (packet.getProtocol() == protocol && packet.getSender() == pSender) {
|
||||
if (packet.name().equalsIgnoreCase(name)) {
|
||||
try {
|
||||
pSender = Sender.valueOf(args[1].toUpperCase());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
sender.sendMessage(ChatColor.RED + "Unknown sender: " + args[1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
try { // Try IDs first
|
||||
int id = Integer.parseInt(args[2]);
|
||||
type = PacketType.findCurrent(protocol, pSender, id);
|
||||
} catch (NumberFormatException ex) { // Check packet names
|
||||
String name = args[2];
|
||||
for (PacketType packet : PacketType.values()) {
|
||||
if (packet.getProtocol() == protocol && packet.getSender() == pSender) {
|
||||
if (packet.name().equalsIgnoreCase(name)) {
|
||||
type = packet;
|
||||
break;
|
||||
}
|
||||
for (String className : packet.getClassNames()) {
|
||||
if (className.equalsIgnoreCase(name)) {
|
||||
type = packet;
|
||||
break;
|
||||
}
|
||||
for (String className : packet.getClassNames()) {
|
||||
if (className.equalsIgnoreCase(name)) {
|
||||
type = packet;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IllegalArgumentException ex) { // RIP
|
||||
type = null;
|
||||
}
|
||||
} catch (IllegalArgumentException ex) { // RIP
|
||||
type = null;
|
||||
}
|
||||
|
||||
if (type == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Unknown packet: " + args[2]);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args.length > 3) {
|
||||
if (args[3].equalsIgnoreCase("console")) {
|
||||
this.location = LogLocation.CONSOLE;
|
||||
} else {
|
||||
this.location = LogLocation.FILE;
|
||||
}
|
||||
}
|
||||
|
||||
if (pSender == Sender.CLIENT) {
|
||||
if (receivingTypes.contains(type)) {
|
||||
receivingTypes.remove(type);
|
||||
} else {
|
||||
receivingTypes.add(type);
|
||||
}
|
||||
} else {
|
||||
if (sendingTypes.contains(type)) {
|
||||
sendingTypes.remove(type);
|
||||
} else {
|
||||
sendingTypes.add(type);
|
||||
}
|
||||
}
|
||||
|
||||
startLogging();
|
||||
sender.sendMessage(ChatColor.GREEN + "Now logging " + type.getPacketClass().getSimpleName());
|
||||
if (type == null) {
|
||||
sender.sendMessage(ChatColor.RED + "Unknown packet: " + args[2]);
|
||||
return true;
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.RED + "Invalid syntax: /packetlog <protocol> <sender> <packet> [location]");
|
||||
if (args.length > 3) {
|
||||
if (args[3].equalsIgnoreCase("console")) {
|
||||
this.location = LogLocation.CONSOLE;
|
||||
} else {
|
||||
this.location = LogLocation.FILE;
|
||||
}
|
||||
}
|
||||
|
||||
if (pSender == Sender.CLIENT) {
|
||||
if (receivingTypes.contains(type)) {
|
||||
receivingTypes.remove(type);
|
||||
} else {
|
||||
receivingTypes.add(type);
|
||||
}
|
||||
} else {
|
||||
if (sendingTypes.contains(type)) {
|
||||
sendingTypes.remove(type);
|
||||
} else {
|
||||
sendingTypes.add(type);
|
||||
}
|
||||
}
|
||||
|
||||
startLogging();
|
||||
sender.sendMessage(ChatColor.GREEN + "Now logging " + type.getPacketClass().getSimpleName());
|
||||
return true;
|
||||
} catch (Throwable ex) {
|
||||
sender.sendMessage(ChatColor.RED + "Failed to parse command: " + ex);
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import org.apache.commons.lang.WordUtils;
|
||||
import com.comphenix.protocol.utility.WordUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import com.comphenix.protocol.PacketTypeLookup.ClassLookup;
|
||||
@@ -133,124 +133,114 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
public static final PacketType CUSTOM_CHAT_COMPLETIONS = new PacketType(PROTOCOL, SENDER, 0x17, "CustomChatCompletions");
|
||||
public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x18, "CustomPayload", "SPacketCustomPayload");
|
||||
public static final PacketType DAMAGE_EVENT = new PacketType(PROTOCOL, SENDER, 0x19, "DamageEvent", "ClientboundDamageEventPacket");
|
||||
public static final PacketType DEBUG_BLOCK_VALUE = new PacketType(PROTOCOL, SENDER, 0x1A, "DebugBlockValue");
|
||||
public static final PacketType DEBUG_CHUNK_VALUE = new PacketType(PROTOCOL, SENDER, 0x1B, "DebugChunkValue");
|
||||
public static final PacketType DEBUG_ENTITY_VALUE = new PacketType(PROTOCOL, SENDER, 0x1C, "DebugEntityValue");
|
||||
public static final PacketType DEBUG_EVENT = new PacketType(PROTOCOL, SENDER, 0x1D, "DebugEvent");
|
||||
public static final PacketType DEBUG_SAMPLE = new PacketType(PROTOCOL, SENDER, 0x1E, "DebugSample");
|
||||
public static final PacketType DELETE_CHAT_MESSAGE = new PacketType(PROTOCOL, SENDER, 0x1F, "DeleteChat");
|
||||
public static final PacketType KICK_DISCONNECT = new PacketType(PROTOCOL, SENDER, 0x20, "Disconnect", "KickDisconnect", "SPacketDisconnect");
|
||||
public static final PacketType DISGUISED_CHAT = new PacketType(PROTOCOL, SENDER, 0x21, "DisguisedChat");
|
||||
public static final PacketType ENTITY_STATUS = new PacketType(PROTOCOL, SENDER, 0x22, "EntityEvent", "EntityStatus", "SPacketEntityStatus");
|
||||
public static final PacketType ENTITY_POSITION_SYNC = new PacketType(PROTOCOL, SENDER, 0x23, "EntityPositionSync");
|
||||
public static final PacketType EXPLOSION = new PacketType(PROTOCOL, SENDER, 0x24, "Explode", "Explosion", "SPacketExplosion");
|
||||
public static final PacketType ADD_TRANSIENT_BLOCK = new PacketType(PROTOCOL, SENDER, 0x25, MinecraftVersion.v26_3, "AddTransientBlock");
|
||||
public static final PacketType UNLOAD_CHUNK = new PacketType(PROTOCOL, SENDER, 0x26, MinecraftVersion.v26_3, "ForgetLevelChunk", "UnloadChunk", "SPacketUnloadChunk");
|
||||
public static final PacketType GAME_STATE_CHANGE = new PacketType(PROTOCOL, SENDER, 0x27, MinecraftVersion.v26_3, "GameEvent", "GameStateChange", "SPacketChangeGameState");
|
||||
public static final PacketType GAME_RULE_VALUES = new PacketType(PROTOCOL, SENDER, 0x28, MinecraftVersion.v26_3, "GameRuleValues");
|
||||
public static final PacketType GAME_TEST_HIGHLIGHT_POS = new PacketType(PROTOCOL, SENDER, 0x29, MinecraftVersion.v26_3, "GameTestHighlightPos");
|
||||
public static final PacketType OPEN_WINDOW_HORSE = new PacketType(PROTOCOL, SENDER, 0x2A, MinecraftVersion.v26_3, "MountScreenOpen", "HorseScreenOpen", "OpenWindowHorse");
|
||||
public static final PacketType HURT_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x2B, MinecraftVersion.v26_3, "HurtAnimation", "ClientboundHurtAnimationPacket");
|
||||
public static final PacketType INITIALIZE_BORDER = new PacketType(PROTOCOL, SENDER, 0x2C, MinecraftVersion.v26_3, "InitializeBorder");
|
||||
public static final PacketType KEEP_ALIVE = new PacketType(PROTOCOL, SENDER, 0x2D, MinecraftVersion.v26_3, "KeepAlive", "SPacketKeepAlive");
|
||||
public static final PacketType MAP_CHUNK = new PacketType(PROTOCOL, SENDER, 0x2E, MinecraftVersion.v26_3, "LevelChunkWithLight", "MapChunk", "SPacketChunkData");
|
||||
public static final PacketType WORLD_EVENT = new PacketType(PROTOCOL, SENDER, 0x2F, MinecraftVersion.v26_3, "LevelEvent", "WorldEvent", "SPacketEffect");
|
||||
public static final PacketType WORLD_PARTICLES = new PacketType(PROTOCOL, SENDER, 0x30, MinecraftVersion.v26_3, "LevelParticles", "WorldParticles", "SPacketParticles");
|
||||
public static final PacketType LIGHT_UPDATE = new PacketType(PROTOCOL, SENDER, 0x31, MinecraftVersion.v26_3, "LightUpdate");
|
||||
public static final PacketType LOGIN = new PacketType(PROTOCOL, SENDER, 0x32, MinecraftVersion.v26_3, "Login", "SPacketJoinGame");
|
||||
public static final PacketType LOW_DISK_SPACE_WARNING = new PacketType(PROTOCOL, SENDER, 0x33, MinecraftVersion.v26_3, "LowDiskSpaceWarning");
|
||||
public static final PacketType MAP = new PacketType(PROTOCOL, SENDER, 0x34, MinecraftVersion.v26_3, "MapItemData", "Map", "SPacketMaps");
|
||||
public static final PacketType OPEN_WINDOW_MERCHANT = new PacketType(PROTOCOL, SENDER, 0x35, MinecraftVersion.v26_3, "MerchantOffers", "OpenWindowMerchant");
|
||||
public static final PacketType REL_ENTITY_MOVE = new PacketType(PROTOCOL, SENDER, 0x36, MinecraftVersion.v26_3, "net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Pos", "Entity$RelEntityMove", "Entity$PacketPlayOutRelEntityMove");
|
||||
public static final PacketType REL_ENTITY_MOVE_LOOK = new PacketType(PROTOCOL, SENDER, 0x37, MinecraftVersion.v26_3, "net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$PosRot", "Entity$RelEntityMoveLook", "Entity$PacketPlayOutRelEntityMoveLook");
|
||||
public static final PacketType MOVE_MINECART = new PacketType(PROTOCOL, SENDER, 0x38, MinecraftVersion.v26_3, "MoveMinecart");
|
||||
public static final PacketType ENTITY_LOOK = new PacketType(PROTOCOL, SENDER, 0x39, MinecraftVersion.v26_3, "net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Rot", "Entity$EntityLook", "Entity$PacketPlayOutEntityLook");
|
||||
public static final PacketType VEHICLE_MOVE = new PacketType(PROTOCOL, SENDER, 0x3A, MinecraftVersion.v26_3, "MoveVehicle", "VehicleMove", "SPacketMoveVehicle");
|
||||
public static final PacketType OPEN_BOOK = new PacketType(PROTOCOL, SENDER, 0x3B, MinecraftVersion.v26_3, "OpenBook");
|
||||
public static final PacketType OPEN_WINDOW = new PacketType(PROTOCOL, SENDER, 0x3C, MinecraftVersion.v26_3, "OpenScreen", "OpenWindow", "SPacketOpenWindow");
|
||||
public static final PacketType OPEN_SIGN_EDITOR = new PacketType(PROTOCOL, SENDER, 0x3D, MinecraftVersion.v26_3, "OpenSignEditor", "SPacketSignEditorOpen");
|
||||
public static final PacketType PING = new PacketType(PROTOCOL, SENDER, 0x3E, MinecraftVersion.v26_3, "Ping");
|
||||
public static final PacketType PONG_RESPONSE = new PacketType(PROTOCOL, SENDER, 0x3F, MinecraftVersion.v26_3, "PongResponse");
|
||||
public static final PacketType AUTO_RECIPE = new PacketType(PROTOCOL, SENDER, 0x40, MinecraftVersion.v26_3, "PlaceGhostRecipe", "AutoRecipe", "SPacketPlaceGhostRecipe");
|
||||
public static final PacketType ABILITIES = new PacketType(PROTOCOL, SENDER, 0x41, MinecraftVersion.v26_3, "PlayerAbilities", "Abilities", "SPacketPlayerAbilities");
|
||||
public static final PacketType CHAT = new PacketType(PROTOCOL, SENDER, 0x42, MinecraftVersion.v26_3, "PlayerChat", "Chat", "SPacketChat");
|
||||
public static final PacketType PLAYER_COMBAT_END = new PacketType(PROTOCOL, SENDER, 0x43, MinecraftVersion.v26_3, "PlayerCombatEnd");
|
||||
public static final PacketType PLAYER_COMBAT_ENTER = new PacketType(PROTOCOL, SENDER, 0x44, MinecraftVersion.v26_3, "PlayerCombatEnter");
|
||||
public static final PacketType PLAYER_COMBAT_KILL = new PacketType(PROTOCOL, SENDER, 0x45, MinecraftVersion.v26_3, "PlayerCombatKill");
|
||||
public static final PacketType PLAYER_INFO_REMOVE = new PacketType(PROTOCOL, SENDER, 0x46, MinecraftVersion.v26_3, "PlayerInfoRemove");
|
||||
public static final PacketType PLAYER_INFO = new PacketType(PROTOCOL, SENDER, 0x47, MinecraftVersion.v26_3, "PlayerInfoUpdate", "PlayerInfo");
|
||||
public static final PacketType LOOK_AT = new PacketType(PROTOCOL, SENDER, 0x48, MinecraftVersion.v26_3, "PlayerLookAt", "LookAt", "SPacketPlayerPosLook");
|
||||
public static final PacketType POSITION = new PacketType(PROTOCOL, SENDER, 0x49, MinecraftVersion.v26_3, "PlayerPosition", "Position");
|
||||
public static final PacketType PLAYER_ROTATION = new PacketType(PROTOCOL, SENDER, 0x4A, MinecraftVersion.v26_3, "PlayerRotation");
|
||||
public static final PacketType RECIPE_BOOK_ADD = new PacketType(PROTOCOL, SENDER, 0x4B, MinecraftVersion.v26_3, "RecipeBookAdd");
|
||||
public static final PacketType RECIPE_BOOK_REMOVE = new PacketType(PROTOCOL, SENDER, 0x4C, MinecraftVersion.v26_3, "RecipeBookRemove");
|
||||
public static final PacketType RECIPE_BOOK_SETTINGS = new PacketType(PROTOCOL, SENDER, 0x4D, MinecraftVersion.v26_3, "RecipeBookSettings");
|
||||
public static final PacketType ENTITY_DESTROY = new PacketType(PROTOCOL, SENDER, 0x4E, MinecraftVersion.v26_3, "RemoveEntities", "EntityDestroy", "SPacketDestroyEntities");
|
||||
public static final PacketType REMOVE_ENTITY_EFFECT = new PacketType(PROTOCOL, SENDER, 0x4F, MinecraftVersion.v26_3, "RemoveMobEffect", "RemoveEntityEffect", "SPacketRemoveEntityEffect");
|
||||
public static final PacketType RESET_SCORE = new PacketType(PROTOCOL, SENDER, 0x50, MinecraftVersion.v26_3, "ResetScore", "ResetScorePacket");
|
||||
public static final PacketType REMOVE_RESOURCE_PACK = new PacketType(PROTOCOL, SENDER, 0x51, MinecraftVersion.v26_3, "ResourcePackPop", "ResourcePackPopPacket");
|
||||
public static final PacketType ADD_RESOURCE_PACK = new PacketType(PROTOCOL, SENDER, 0x52, MinecraftVersion.v26_3, "ResourcePackPush", "ResourcePackPushPacket");
|
||||
public static final PacketType POST_EFFECTS = new PacketType(PROTOCOL, SENDER, 0x53, MinecraftVersion.v26_3, "PostEffects");
|
||||
public static final PacketType RESPAWN = new PacketType(PROTOCOL, SENDER, 0x54, MinecraftVersion.v26_3, "Respawn", "SPacketRespawn");
|
||||
public static final PacketType ENTITY_HEAD_ROTATION = new PacketType(PROTOCOL, SENDER, 0x55, MinecraftVersion.v26_3, "RotateHead", "EntityHeadRotation", "SPacketEntityHeadLook");
|
||||
public static final PacketType MULTI_BLOCK_CHANGE = new PacketType(PROTOCOL, SENDER, 0x56, MinecraftVersion.v26_3, "SectionBlocksUpdate", "MultiBlockChange", "SPacketMultiBlockChange");
|
||||
public static final PacketType SELECT_ADVANCEMENT_TAB = new PacketType(PROTOCOL, SENDER, 0x57, MinecraftVersion.v26_3, "SelectAdvancementsTab", "SelectAdvancementTab", "SPacketSelectAdvancementsTab");
|
||||
public static final PacketType SERVER_DATA = new PacketType(PROTOCOL, SENDER, 0x58, MinecraftVersion.v26_3, "ServerData");
|
||||
public static final PacketType SET_ACTION_BAR_TEXT = new PacketType(PROTOCOL, SENDER, 0x59, MinecraftVersion.v26_3, "SetActionBarText");
|
||||
public static final PacketType SET_BORDER_CENTER = new PacketType(PROTOCOL, SENDER, 0x5A, MinecraftVersion.v26_3, "SetBorderCenter");
|
||||
public static final PacketType SET_BORDER_LERP_SIZE = new PacketType(PROTOCOL, SENDER, 0x5B, MinecraftVersion.v26_3, "SetBorderLerpSize");
|
||||
public static final PacketType SET_BORDER_SIZE = new PacketType(PROTOCOL, SENDER, 0x5C, MinecraftVersion.v26_3, "SetBorderSize");
|
||||
public static final PacketType SET_BORDER_WARNING_DELAY = new PacketType(PROTOCOL, SENDER, 0x5D, MinecraftVersion.v26_3, "SetBorderWarningDelay");
|
||||
public static final PacketType SET_BORDER_WARNING_DISTANCE = new PacketType(PROTOCOL, SENDER, 0x5E, MinecraftVersion.v26_3, "SetBorderWarningDistance");
|
||||
public static final PacketType CAMERA = new PacketType(PROTOCOL, SENDER, 0x5F, MinecraftVersion.v26_3, "SetCamera", "Camera", "SPacketCamera");
|
||||
public static final PacketType VIEW_CENTRE = new PacketType(PROTOCOL, SENDER, 0x60, MinecraftVersion.v26_3, "SetChunkCacheCenter", "ViewCentre");
|
||||
public static final PacketType VIEW_DISTANCE = new PacketType(PROTOCOL, SENDER, 0x61, MinecraftVersion.v26_3, "SetChunkCacheRadius", "ViewDistance");
|
||||
public static final PacketType SET_CURSOR_ITEM = new PacketType(PROTOCOL, SENDER, 0x62, MinecraftVersion.v26_3, "SetCursorItem");
|
||||
public static final PacketType SPAWN_POSITION = new PacketType(PROTOCOL, SENDER, 0x63, MinecraftVersion.v26_3, "SetDefaultSpawnPosition", "SpawnPosition", "SPacketSpawnPosition");
|
||||
public static final PacketType SCOREBOARD_DISPLAY_OBJECTIVE = new PacketType(PROTOCOL, SENDER, 0x64, MinecraftVersion.v26_3, "SetDisplayObjective", "ScoreboardDisplayObjective", "SPacketDisplayObjective");
|
||||
public static final PacketType ENTITY_METADATA = new PacketType(PROTOCOL, SENDER, 0x65, MinecraftVersion.v26_3, "SetEntityData", "EntityMetadata", "SPacketEntityMetadata");
|
||||
public static final PacketType ATTACH_ENTITY = new PacketType(PROTOCOL, SENDER, 0x66, MinecraftVersion.v26_3, "SetEntityLink", "AttachEntity", "SPacketEntityAttach");
|
||||
public static final PacketType ENTITY_VELOCITY = new PacketType(PROTOCOL, SENDER, 0x67, MinecraftVersion.v26_3, "SetEntityMotion", "EntityVelocity", "SPacketEntityVelocity");
|
||||
public static final PacketType ENTITY_EQUIPMENT = new PacketType(PROTOCOL, SENDER, 0x68, MinecraftVersion.v26_3, "SetEquipment", "EntityEquipment", "SPacketEntityEquipment");
|
||||
public static final PacketType EXPERIENCE = new PacketType(PROTOCOL, SENDER, 0x69, MinecraftVersion.v26_3, "SetExperience", "Experience", "SPacketSetExperience");
|
||||
public static final PacketType UPDATE_HEALTH = new PacketType(PROTOCOL, SENDER, 0x6A, MinecraftVersion.v26_3, "SetHealth", "UpdateHealth", "SPacketUpdateHealth");
|
||||
public static final PacketType HELD_ITEM_SLOT = new PacketType(PROTOCOL, SENDER, 0x6B, MinecraftVersion.v26_3, "SetHeldSlot", "SetCarriedItem", "HeldItemSlot", "SPacketHeldItemChange");
|
||||
public static final PacketType SCOREBOARD_OBJECTIVE = new PacketType(PROTOCOL, SENDER, 0x6C, MinecraftVersion.v26_3, "SetObjective", "ScoreboardObjective", "SPacketScoreboardObjective");
|
||||
public static final PacketType MOUNT = new PacketType(PROTOCOL, SENDER, 0x6D, MinecraftVersion.v26_3, "SetPassengers", "Mount", "SPacketSetPassengers");
|
||||
public static final PacketType SET_PLAYER_INVENTORY = new PacketType(PROTOCOL, SENDER, 0x6E, MinecraftVersion.v26_3, "SetPlayerInventory");
|
||||
public static final PacketType SCOREBOARD_TEAM = new PacketType(PROTOCOL, SENDER, 0x6F, MinecraftVersion.v26_3, "SetPlayerTeam", "ScoreboardTeam", "SPacketTeams");
|
||||
public static final PacketType SCOREBOARD_SCORE = new PacketType(PROTOCOL, SENDER, 0x70, MinecraftVersion.v26_3, "SetScore", "ScoreboardScore", "SPacketUpdateScore");
|
||||
public static final PacketType UPDATE_SIMULATION_DISTANCE = new PacketType(PROTOCOL, SENDER, 0x71, MinecraftVersion.v26_3, "SetSimulationDistance");
|
||||
public static final PacketType SET_SUBTITLE_TEXT = new PacketType(PROTOCOL, SENDER, 0x72, MinecraftVersion.v26_3, "SetSubtitleText");
|
||||
public static final PacketType UPDATE_TIME = new PacketType(PROTOCOL, SENDER, 0x73, MinecraftVersion.v26_3, "SetTime", "UpdateTime", "SPacketTimeUpdate");
|
||||
public static final PacketType SET_TITLE_TEXT = new PacketType(PROTOCOL, SENDER, 0x74, MinecraftVersion.v26_3, "SetTitleText");
|
||||
public static final PacketType SET_TITLES_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x75, MinecraftVersion.v26_3, "SetTitlesAnimation");
|
||||
public static final PacketType ENTITY_SOUND = new PacketType(PROTOCOL, SENDER, 0x76, MinecraftVersion.v26_3, "SoundEntity", "EntitySound", "SPacketSoundEffect");
|
||||
public static final PacketType NAMED_SOUND_EFFECT = new PacketType(PROTOCOL, SENDER, 0x77, MinecraftVersion.v26_3, "Sound", "NamedSoundEffect");
|
||||
public static final PacketType START_CONFIGURATION = new PacketType(PROTOCOL, SENDER, 0x78, MinecraftVersion.v26_3, "StartConfiguration");
|
||||
public static final PacketType STOP_SOUND = new PacketType(PROTOCOL, SENDER, 0x79, MinecraftVersion.v26_3, "StopSound");
|
||||
public static final PacketType STORE_COOKIE = new PacketType(PROTOCOL, SENDER, 0x7A, MinecraftVersion.v26_3, "StoreCookie");
|
||||
public static final PacketType SWING_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x7B, MinecraftVersion.v26_3, "SwingAnimation");
|
||||
public static final PacketType SYSTEM_CHAT = new PacketType(PROTOCOL, SENDER, 0x7C, MinecraftVersion.v26_3, "SystemChat");
|
||||
public static final PacketType PLAYER_LIST_HEADER_FOOTER = new PacketType(PROTOCOL, SENDER, 0x7D, MinecraftVersion.v26_3, "TabList", "PlayerListHeaderFooter", "SPacketPlayerListHeaderFooter");
|
||||
public static final PacketType NBT_QUERY = new PacketType(PROTOCOL, SENDER, 0x7E, MinecraftVersion.v26_3, "TagQuery", "NBTQuery");
|
||||
public static final PacketType COLLECT = new PacketType(PROTOCOL, SENDER, 0x7F, MinecraftVersion.v26_3, "TakeItemEntity", "Collect", "SPacketCollectItem");
|
||||
public static final PacketType ENTITY_TELEPORT = new PacketType(PROTOCOL, SENDER, 0x80, MinecraftVersion.v26_3, "TeleportEntity", "EntityTeleport", "SPacketEntityTeleport");
|
||||
public static final PacketType TEST_INSTANCE_BLOCK_STATUS = new PacketType(PROTOCOL, SENDER, 0x81, MinecraftVersion.v26_3, "ClientboundTestInstanceBlockStatus");
|
||||
public static final PacketType TICKING_STATE = new PacketType(PROTOCOL, SENDER, 0x82, MinecraftVersion.v26_3, "TickingState", "TickingStatePacket");
|
||||
public static final PacketType TICKING_STEP_STATE = new PacketType(PROTOCOL, SENDER, 0x83, MinecraftVersion.v26_3, "TickingStep", "TickingStepPacket");
|
||||
public static final PacketType TRANSFER = new PacketType(PROTOCOL, SENDER, 0x84, MinecraftVersion.v26_3, "Transfer");
|
||||
public static final PacketType ADVANCEMENTS = new PacketType(PROTOCOL, SENDER, 0x85, MinecraftVersion.v26_3, "UpdateAdvancements", "Advancements", "SPacketAdvancementInfo");
|
||||
public static final PacketType UPDATE_ATTRIBUTES = new PacketType(PROTOCOL, SENDER, 0x86, MinecraftVersion.v26_3, "UpdateAttributes", "SPacketEntityProperties");
|
||||
public static final PacketType ENTITY_EFFECT = new PacketType(PROTOCOL, SENDER, 0x87, MinecraftVersion.v26_3, "UpdateMobEffect", "EntityEffect", "SPacketEntityEffect");
|
||||
public static final PacketType RECIPE_UPDATE = new PacketType(PROTOCOL, SENDER, 0x88, MinecraftVersion.v26_3, "UpdateRecipes", "RecipeUpdate");
|
||||
public static final PacketType TAGS = new PacketType(PROTOCOL, SENDER, 0x89, MinecraftVersion.v26_3, "UpdateTags", "Tags");
|
||||
public static final PacketType PROJECTILE_POWER = new PacketType(PROTOCOL, SENDER, 0x8A, MinecraftVersion.v26_3, "ProjectilePower");
|
||||
public static final PacketType REPORT_DETAILS = new PacketType(PROTOCOL, SENDER, 0x8B, MinecraftVersion.v26_3, "CustomReportDetails");
|
||||
public static final PacketType SERVER_LINKS = new PacketType(PROTOCOL, SENDER, 0x8C, MinecraftVersion.v26_3, "ServerLinks");
|
||||
public static final PacketType TRACKED_WAYPOINT = new PacketType(PROTOCOL, SENDER, 0x8D, MinecraftVersion.v26_3, "TrackedWaypoint");
|
||||
public static final PacketType CLEAR_DIALOG = new PacketType(PROTOCOL, SENDER, 0x8E, MinecraftVersion.v26_3, "ClearDialog");
|
||||
public static final PacketType SHOW_DIALOG = new PacketType(PROTOCOL, SENDER, 0x8F, MinecraftVersion.v26_3, "ShowDialog");
|
||||
public static final PacketType DEBUG_SAMPLE = new PacketType(PROTOCOL, SENDER, 0x1A, "DebugSample");
|
||||
public static final PacketType DELETE_CHAT_MESSAGE = new PacketType(PROTOCOL, SENDER, 0x1B, "DeleteChat");
|
||||
public static final PacketType KICK_DISCONNECT = new PacketType(PROTOCOL, SENDER, 0x1C, "Disconnect", "KickDisconnect", "SPacketDisconnect");
|
||||
public static final PacketType DISGUISED_CHAT = new PacketType(PROTOCOL, SENDER, 0x1D, "DisguisedChat");
|
||||
public static final PacketType ENTITY_STATUS = new PacketType(PROTOCOL, SENDER, 0x1E, "EntityEvent", "EntityStatus", "SPacketEntityStatus");
|
||||
public static final PacketType ENTITY_POSITION_SYNC = new PacketType(PROTOCOL, SENDER, 0x1F, "EntityPositionSync");
|
||||
public static final PacketType EXPLOSION = new PacketType(PROTOCOL, SENDER, 0x20, "Explode", "Explosion", "SPacketExplosion");
|
||||
public static final PacketType UNLOAD_CHUNK = new PacketType(PROTOCOL, SENDER, 0x21, "ForgetLevelChunk", "UnloadChunk", "SPacketUnloadChunk");
|
||||
public static final PacketType GAME_STATE_CHANGE = new PacketType(PROTOCOL, SENDER, 0x22, "GameEvent", "GameStateChange", "SPacketChangeGameState");
|
||||
public static final PacketType OPEN_WINDOW_HORSE = new PacketType(PROTOCOL, SENDER, 0x23, "HorseScreenOpen", "OpenWindowHorse");
|
||||
public static final PacketType HURT_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x24, "HurtAnimation", "ClientboundHurtAnimationPacket");
|
||||
public static final PacketType INITIALIZE_BORDER = new PacketType(PROTOCOL, SENDER, 0x25, "InitializeBorder");
|
||||
public static final PacketType KEEP_ALIVE = new PacketType(PROTOCOL, SENDER, 0x26, "KeepAlive", "SPacketKeepAlive");
|
||||
public static final PacketType MAP_CHUNK = new PacketType(PROTOCOL, SENDER, 0x27, "LevelChunkWithLight", "MapChunk", "SPacketChunkData");
|
||||
public static final PacketType WORLD_EVENT = new PacketType(PROTOCOL, SENDER, 0x28, "LevelEvent", "WorldEvent", "SPacketEffect");
|
||||
public static final PacketType WORLD_PARTICLES = new PacketType(PROTOCOL, SENDER, 0x29, "LevelParticles", "WorldParticles", "SPacketParticles");
|
||||
public static final PacketType LIGHT_UPDATE = new PacketType(PROTOCOL, SENDER, 0x2A, "LightUpdate");
|
||||
public static final PacketType LOGIN = new PacketType(PROTOCOL, SENDER, 0x2B, "Login", "SPacketJoinGame");
|
||||
public static final PacketType MAP = new PacketType(PROTOCOL, SENDER, 0x2C, "MapItemData", "Map", "SPacketMaps");
|
||||
public static final PacketType OPEN_WINDOW_MERCHANT = new PacketType(PROTOCOL, SENDER, 0x2D, "MerchantOffers", "OpenWindowMerchant");
|
||||
public static final PacketType REL_ENTITY_MOVE = new PacketType(PROTOCOL, SENDER, 0x2E, "net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Pos", "Entity$RelEntityMove", "Entity$PacketPlayOutRelEntityMove");
|
||||
public static final PacketType REL_ENTITY_MOVE_LOOK = new PacketType(PROTOCOL, SENDER, 0x2F, "net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$PosRot", "Entity$RelEntityMoveLook", "Entity$PacketPlayOutRelEntityMoveLook");
|
||||
public static final PacketType MOVE_MINECART = new PacketType(PROTOCOL, SENDER, 0x30, "MoveMinecart");
|
||||
public static final PacketType ENTITY_LOOK = new PacketType(PROTOCOL, SENDER, 0x31, "net.minecraft.network.protocol.game.ClientboundMoveEntityPacket$Rot", "Entity$EntityLook", "Entity$PacketPlayOutEntityLook");
|
||||
public static final PacketType VEHICLE_MOVE = new PacketType(PROTOCOL, SENDER, 0x32, "MoveVehicle", "VehicleMove", "SPacketMoveVehicle");
|
||||
public static final PacketType OPEN_BOOK = new PacketType(PROTOCOL, SENDER, 0x33, "OpenBook");
|
||||
public static final PacketType OPEN_WINDOW = new PacketType(PROTOCOL, SENDER, 0x34, "OpenScreen", "OpenWindow", "SPacketOpenWindow");
|
||||
public static final PacketType OPEN_SIGN_EDITOR = new PacketType(PROTOCOL, SENDER, 0x35, "OpenSignEditor", "SPacketSignEditorOpen");
|
||||
public static final PacketType PING = new PacketType(PROTOCOL, SENDER, 0x36, "Ping");
|
||||
public static final PacketType PONG_RESPONSE = new PacketType(PROTOCOL, SENDER, 0x37, "PongResponse");
|
||||
public static final PacketType AUTO_RECIPE = new PacketType(PROTOCOL, SENDER, 0x38, "PlaceGhostRecipe", "AutoRecipe", "SPacketPlaceGhostRecipe");
|
||||
public static final PacketType ABILITIES = new PacketType(PROTOCOL, SENDER, 0x39, "PlayerAbilities", "Abilities", "SPacketPlayerAbilities");
|
||||
public static final PacketType CHAT = new PacketType(PROTOCOL, SENDER, 0x3A, "PlayerChat", "Chat", "SPacketChat");
|
||||
public static final PacketType PLAYER_COMBAT_END = new PacketType(PROTOCOL, SENDER, 0x3B, "PlayerCombatEnd");
|
||||
public static final PacketType PLAYER_COMBAT_ENTER = new PacketType(PROTOCOL, SENDER, 0x3C, "PlayerCombatEnter");
|
||||
public static final PacketType PLAYER_COMBAT_KILL = new PacketType(PROTOCOL, SENDER, 0x3D, "PlayerCombatKill");
|
||||
public static final PacketType PLAYER_INFO_REMOVE = new PacketType(PROTOCOL, SENDER, 0x3E, "PlayerInfoRemove");
|
||||
public static final PacketType PLAYER_INFO = new PacketType(PROTOCOL, SENDER, 0x3F, "PlayerInfoUpdate", "PlayerInfo");
|
||||
public static final PacketType LOOK_AT = new PacketType(PROTOCOL, SENDER, 0x40, "PlayerLookAt", "LookAt", "SPacketPlayerPosLook");
|
||||
public static final PacketType POSITION = new PacketType(PROTOCOL, SENDER, 0x41, "PlayerPosition", "Position");
|
||||
public static final PacketType PLAYER_ROTATION = new PacketType(PROTOCOL, SENDER, 0x42, "PlayerRotation");
|
||||
public static final PacketType RECIPE_BOOK_ADD = new PacketType(PROTOCOL, SENDER, 0x43, "RecipeBookAdd");
|
||||
public static final PacketType RECIPE_BOOK_REMOVE = new PacketType(PROTOCOL, SENDER, 0x44, "RecipeBookRemove");
|
||||
public static final PacketType RECIPE_BOOK_SETTINGS = new PacketType(PROTOCOL, SENDER, 0x45, "RecipeBookSettings");
|
||||
public static final PacketType ENTITY_DESTROY = new PacketType(PROTOCOL, SENDER, 0x46, "RemoveEntities", "EntityDestroy", "SPacketDestroyEntities");
|
||||
public static final PacketType REMOVE_ENTITY_EFFECT = new PacketType(PROTOCOL, SENDER, 0x47, "RemoveMobEffect", "RemoveEntityEffect", "SPacketRemoveEntityEffect");
|
||||
public static final PacketType RESET_SCORE = new PacketType(PROTOCOL, SENDER, 0x48, "ResetScore", "ResetScorePacket");
|
||||
public static final PacketType REMOVE_RESOURCE_PACK = new PacketType(PROTOCOL, SENDER, 0x49, "ResourcePackPop", "ResourcePackPopPacket");
|
||||
public static final PacketType ADD_RESOURCE_PACK = new PacketType(PROTOCOL, SENDER, 0x4A, "ResourcePackPush", "ResourcePackPushPacket");
|
||||
public static final PacketType RESPAWN = new PacketType(PROTOCOL, SENDER, 0x4B, "Respawn", "SPacketRespawn");
|
||||
public static final PacketType ENTITY_HEAD_ROTATION = new PacketType(PROTOCOL, SENDER, 0x4C, "RotateHead", "EntityHeadRotation", "SPacketEntityHeadLook");
|
||||
public static final PacketType MULTI_BLOCK_CHANGE = new PacketType(PROTOCOL, SENDER, 0x4D, "SectionBlocksUpdate", "MultiBlockChange", "SPacketMultiBlockChange");
|
||||
public static final PacketType SELECT_ADVANCEMENT_TAB = new PacketType(PROTOCOL, SENDER, 0x4E, "SelectAdvancementsTab", "SelectAdvancementTab", "SPacketSelectAdvancementsTab");
|
||||
public static final PacketType SERVER_DATA = new PacketType(PROTOCOL, SENDER, 0x4F, "ServerData");
|
||||
public static final PacketType SET_ACTION_BAR_TEXT = new PacketType(PROTOCOL, SENDER, 0x50, "SetActionBarText");
|
||||
public static final PacketType SET_BORDER_CENTER = new PacketType(PROTOCOL, SENDER, 0x51, "SetBorderCenter");
|
||||
public static final PacketType SET_BORDER_LERP_SIZE = new PacketType(PROTOCOL, SENDER, 0x52, "SetBorderLerpSize");
|
||||
public static final PacketType SET_BORDER_SIZE = new PacketType(PROTOCOL, SENDER, 0x53, "SetBorderSize");
|
||||
public static final PacketType SET_BORDER_WARNING_DELAY = new PacketType(PROTOCOL, SENDER, 0x54, "SetBorderWarningDelay");
|
||||
public static final PacketType SET_BORDER_WARNING_DISTANCE = new PacketType(PROTOCOL, SENDER, 0x55, "SetBorderWarningDistance");
|
||||
public static final PacketType CAMERA = new PacketType(PROTOCOL, SENDER, 0x56, "SetCamera", "Camera", "SPacketCamera");
|
||||
public static final PacketType VIEW_CENTRE = new PacketType(PROTOCOL, SENDER, 0x57, "SetChunkCacheCenter", "ViewCentre");
|
||||
public static final PacketType VIEW_DISTANCE = new PacketType(PROTOCOL, SENDER, 0x58, "SetChunkCacheRadius", "ViewDistance");
|
||||
public static final PacketType SET_CURSOR_ITEM = new PacketType(PROTOCOL, SENDER, 0x59, "SetCursorItem");
|
||||
public static final PacketType SPAWN_POSITION = new PacketType(PROTOCOL, SENDER, 0x5A, "SetDefaultSpawnPosition", "SpawnPosition", "SPacketSpawnPosition");
|
||||
public static final PacketType SCOREBOARD_DISPLAY_OBJECTIVE = new PacketType(PROTOCOL, SENDER, 0x5B, "SetDisplayObjective", "ScoreboardDisplayObjective", "SPacketDisplayObjective");
|
||||
public static final PacketType ENTITY_METADATA = new PacketType(PROTOCOL, SENDER, 0x5C, "SetEntityData", "EntityMetadata", "SPacketEntityMetadata");
|
||||
public static final PacketType ATTACH_ENTITY = new PacketType(PROTOCOL, SENDER, 0x5D, "SetEntityLink", "AttachEntity", "SPacketEntityAttach");
|
||||
public static final PacketType ENTITY_VELOCITY = new PacketType(PROTOCOL, SENDER, 0x5E, "SetEntityMotion", "EntityVelocity", "SPacketEntityVelocity");
|
||||
public static final PacketType ENTITY_EQUIPMENT = new PacketType(PROTOCOL, SENDER, 0x5F, "SetEquipment", "EntityEquipment", "SPacketEntityEquipment");
|
||||
public static final PacketType EXPERIENCE = new PacketType(PROTOCOL, SENDER, 0x60, "SetExperience", "Experience", "SPacketSetExperience");
|
||||
public static final PacketType UPDATE_HEALTH = new PacketType(PROTOCOL, SENDER, 0x61, "SetHealth", "UpdateHealth", "SPacketUpdateHealth");
|
||||
public static final PacketType HELD_ITEM_SLOT = new PacketType(PROTOCOL, SENDER, 0x62, "SetHeldSlot", "SetCarriedItem", "HeldItemSlot", "SPacketHeldItemChange");
|
||||
public static final PacketType SCOREBOARD_OBJECTIVE = new PacketType(PROTOCOL, SENDER, 0x63, "SetObjective", "ScoreboardObjective", "SPacketScoreboardObjective");
|
||||
public static final PacketType MOUNT = new PacketType(PROTOCOL, SENDER, 0x64, "SetPassengers", "Mount", "SPacketSetPassengers");
|
||||
public static final PacketType SET_PLAYER_INVENTORY = new PacketType(PROTOCOL, SENDER, 0x65, "SetPlayerInventory");
|
||||
public static final PacketType SCOREBOARD_TEAM = new PacketType(PROTOCOL, SENDER, 0x66, "SetPlayerTeam", "ScoreboardTeam", "SPacketTeams");
|
||||
public static final PacketType SCOREBOARD_SCORE = new PacketType(PROTOCOL, SENDER, 0x67, "SetScore", "ScoreboardScore", "SPacketUpdateScore");
|
||||
public static final PacketType UPDATE_SIMULATION_DISTANCE = new PacketType(PROTOCOL, SENDER, 0x68, "SetSimulationDistance");
|
||||
public static final PacketType SET_SUBTITLE_TEXT = new PacketType(PROTOCOL, SENDER, 0x69, "SetSubtitleText");
|
||||
public static final PacketType UPDATE_TIME = new PacketType(PROTOCOL, SENDER, 0x6A, "SetTime", "UpdateTime", "SPacketTimeUpdate");
|
||||
public static final PacketType SET_TITLE_TEXT = new PacketType(PROTOCOL, SENDER, 0x6B, "SetTitleText");
|
||||
public static final PacketType SET_TITLES_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x6C, "SetTitlesAnimation");
|
||||
public static final PacketType ENTITY_SOUND = new PacketType(PROTOCOL, SENDER, 0x6D, "SoundEntity", "EntitySound", "SPacketSoundEffect");
|
||||
public static final PacketType NAMED_SOUND_EFFECT = new PacketType(PROTOCOL, SENDER, 0x6E, "Sound", "NamedSoundEffect");
|
||||
public static final PacketType START_CONFIGURATION = new PacketType(PROTOCOL, SENDER, 0x6F, "StartConfiguration");
|
||||
public static final PacketType STOP_SOUND = new PacketType(PROTOCOL, SENDER, 0x70, "StopSound");
|
||||
public static final PacketType STORE_COOKIE = new PacketType(PROTOCOL, SENDER, 0x71, "StoreCookie");
|
||||
public static final PacketType SYSTEM_CHAT = new PacketType(PROTOCOL, SENDER, 0x72, "SystemChat");
|
||||
public static final PacketType PLAYER_LIST_HEADER_FOOTER = new PacketType(PROTOCOL, SENDER, 0x73, "TabList", "PlayerListHeaderFooter", "SPacketPlayerListHeaderFooter");
|
||||
public static final PacketType NBT_QUERY = new PacketType(PROTOCOL, SENDER, 0x74, "TagQuery", "NBTQuery");
|
||||
public static final PacketType COLLECT = new PacketType(PROTOCOL, SENDER, 0x75, "TakeItemEntity", "Collect", "SPacketCollectItem");
|
||||
public static final PacketType ENTITY_TELEPORT = new PacketType(PROTOCOL, SENDER, 0x76, "TeleportEntity", "EntityTeleport", "SPacketEntityTeleport");
|
||||
public static final PacketType TEST_INSTANCE_BLOCK_STATUS = new PacketType(PROTOCOL, SENDER, 0x77, "ClientboundTestInstanceBlockStatus");
|
||||
public static final PacketType TICKING_STATE = new PacketType(PROTOCOL, SENDER, 0x78, "TickingState", "TickingStatePacket");
|
||||
public static final PacketType TICKING_STEP_STATE = new PacketType(PROTOCOL, SENDER, 0x79, "TickingStep", "TickingStepPacket");
|
||||
public static final PacketType TRANSFER = new PacketType(PROTOCOL, SENDER, 0x7A, "Transfer");
|
||||
public static final PacketType ADVANCEMENTS = new PacketType(PROTOCOL, SENDER, 0x7B, "UpdateAdvancements", "Advancements", "SPacketAdvancementInfo");
|
||||
public static final PacketType UPDATE_ATTRIBUTES = new PacketType(PROTOCOL, SENDER, 0x7C, "UpdateAttributes", "SPacketEntityProperties");
|
||||
public static final PacketType ENTITY_EFFECT = new PacketType(PROTOCOL, SENDER, 0x7D, "UpdateMobEffect", "EntityEffect", "SPacketEntityEffect");
|
||||
public static final PacketType RECIPE_UPDATE = new PacketType(PROTOCOL, SENDER, 0x7E, "UpdateRecipes", "RecipeUpdate");
|
||||
public static final PacketType TAGS = new PacketType(PROTOCOL, SENDER, 0x7F, "UpdateTags", "Tags");
|
||||
public static final PacketType PROJECTILE_POWER = new PacketType(PROTOCOL, SENDER, 0x80, "ProjectilePower");
|
||||
public static final PacketType REPORT_DETAILS = new PacketType(PROTOCOL, SENDER, 0x81, "CustomReportDetails");
|
||||
public static final PacketType SERVER_LINKS = new PacketType(PROTOCOL, SENDER, 0x82, "ServerLinks");
|
||||
public static final PacketType TRACKED_WAYPOINT = new PacketType(PROTOCOL, SENDER, 0x83, "TrackedWaypoint");
|
||||
public static final PacketType CLEAR_DIALOG = new PacketType(PROTOCOL, SENDER, 0x84, "ClearDialog");
|
||||
public static final PacketType SHOW_DIALOG = new PacketType(PROTOCOL, SENDER, 0x85, "ShowDialog");
|
||||
|
||||
/**
|
||||
* @deprecated Removed in 1.9
|
||||
@@ -426,6 +416,7 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
*/
|
||||
@Deprecated
|
||||
public static final PacketType SPAWN_ENTITY_EXPERIENCE_ORB = new PacketType(PROTOCOL, SENDER, 232, "AddExperienceOrb", "SpawnEntityExperienceOrb", "SPacketSpawnExperienceOrb");
|
||||
|
||||
|
||||
private static final Server INSTANCE = new Server();
|
||||
|
||||
@@ -448,74 +439,71 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
private static final Sender SENDER = Sender.CLIENT;
|
||||
|
||||
public static final PacketType TELEPORT_ACCEPT = new PacketType(PROTOCOL, SENDER, 0x00, "AcceptTeleportation", "TeleportAccept", "CPacketConfirmTeleport");
|
||||
public static final PacketType ATTACK = new PacketType(PROTOCOL, SENDER, 0x01, "Attack");
|
||||
public static final PacketType TILE_NBT_QUERY = new PacketType(PROTOCOL, SENDER, 0x02, "BlockEntityTagQuery", "TileNBTQuery");
|
||||
public static final PacketType SELECT_BUNDLE_ITEM = new PacketType(PROTOCOL, SENDER, 0x03, "SelectBundleItem");
|
||||
public static final PacketType DIFFICULTY_CHANGE = new PacketType(PROTOCOL, SENDER, 0x04, "ChangeDifficulty", "DifficultyChange");
|
||||
public static final PacketType CHANGE_GAME_MODE = new PacketType(PROTOCOL, SENDER, 0x05, "ChangeGameMode");
|
||||
public static final PacketType CHAT_ACK = new PacketType(PROTOCOL, SENDER, 0x06, "ChatAck");
|
||||
public static final PacketType CHAT_COMMAND = new PacketType(PROTOCOL, SENDER, 0x07, "ChatCommand");
|
||||
public static final PacketType CHAT_COMMAND_SIGNED = new PacketType(PROTOCOL, SENDER, 0x08, "ChatCommandSigned");
|
||||
public static final PacketType CHAT = new PacketType(PROTOCOL, SENDER, 0x09, "Chat", "CPacketChatMessage");
|
||||
public static final PacketType CHAT_SESSION_UPDATE = new PacketType(PROTOCOL, SENDER, 0x0A, "ChatSessionUpdate");
|
||||
public static final PacketType CHUNK_BATCH_RECEIVED = new PacketType(PROTOCOL, SENDER, 0x0B, "ChunkBatchReceived");
|
||||
public static final PacketType CLIENT_COMMAND = new PacketType(PROTOCOL, SENDER, 0x0C, "ClientCommand", "CPacketClientStatus");
|
||||
public static final PacketType CLIENT_TICK_END = new PacketType(PROTOCOL, SENDER, 0x0D, "ClientTickEnd");
|
||||
public static final PacketType SETTINGS = new PacketType(PROTOCOL, SENDER, 0x0E, "ClientInformation", "Settings", "CPacketClientSettings");
|
||||
public static final PacketType TAB_COMPLETE = new PacketType(PROTOCOL, SENDER, 0x0F, "CommandSuggestion", "TabComplete", "CPacketTabComplete");
|
||||
public static final PacketType CONFIGURATION_ACK = new PacketType(PROTOCOL, SENDER, 0x10, "ConfigurationAcknowledged");
|
||||
public static final PacketType ENCHANT_ITEM = new PacketType(PROTOCOL, SENDER, 0x11, "ContainerButtonClick", "EnchantItem", "CPacketEnchantItem");
|
||||
public static final PacketType WINDOW_CLICK = new PacketType(PROTOCOL, SENDER, 0x12, "ContainerClick", "WindowClick", "CPacketClickWindow");
|
||||
public static final PacketType CLOSE_WINDOW = new PacketType(PROTOCOL, SENDER, 0x13, "ContainerClose", "CloseWindow", "CPacketCloseWindow");
|
||||
public static final PacketType CONTAINER_SLOT_STATE_CHANGED = new PacketType(PROTOCOL, SENDER, 0x14, "ContainerSlotStateChanged", "ContainerSlotStateChangedPacket");
|
||||
public static final PacketType COOKIE_RESPONSE = new PacketType(PROTOCOL, SENDER, 0x15, "CookieResponse");
|
||||
public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x16, "CustomPayload", "CPacketCustomPayload");
|
||||
public static final PacketType DEBUG_SUBSCRIPTION_REQUEST = new PacketType(PROTOCOL, SENDER, 0x17, "DebugSubscriptionRequest");
|
||||
public static final PacketType B_EDIT = new PacketType(PROTOCOL, SENDER, 0x18, "EditBook", "BEdit");
|
||||
public static final PacketType ENTITY_NBT_QUERY = new PacketType(PROTOCOL, SENDER, 0x19, "EntityTagQuery", "EntityNBTQuery");
|
||||
public static final PacketType USE_ENTITY = new PacketType(PROTOCOL, SENDER, 0x1A, "Interact", "UseEntity", "CPacketUseEntity");
|
||||
public static final PacketType JIGSAW_GENERATE = new PacketType(PROTOCOL, SENDER, 0x1B, "JigsawGenerate");
|
||||
public static final PacketType KEEP_ALIVE = new PacketType(PROTOCOL, SENDER, 0x1C, "KeepAlive", "CPacketKeepAlive");
|
||||
public static final PacketType DIFFICULTY_LOCK = new PacketType(PROTOCOL, SENDER, 0x1D, "LockDifficulty", "DifficultyLock");
|
||||
public static final PacketType POSITION = new PacketType(PROTOCOL, SENDER, 0x1E, "net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos", "Flying$Position", "Flying$PacketPlayInPosition", "CPacketPlayer$Position");
|
||||
public static final PacketType POSITION_LOOK = new PacketType(PROTOCOL, SENDER, 0x1F, "net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot", "Flying$PositionLook", "Flying$PacketPlayInPositionLook", "CPacketPlayer$PositionRotation");
|
||||
public static final PacketType LOOK = new PacketType(PROTOCOL, SENDER, 0x20, "net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Rot", "Flying$Look", "Flying$PacketPlayInLook", "CPacketPlayer$Rotation");
|
||||
public static final PacketType GROUND = new PacketType(PROTOCOL, SENDER, 0x21, "net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$StatusOnly", "Flying$d");
|
||||
public static final PacketType VEHICLE_MOVE = new PacketType(PROTOCOL, SENDER, 0x22, "MoveVehicle", "VehicleMove", "CPacketVehicleMove");
|
||||
public static final PacketType BOAT_MOVE = new PacketType(PROTOCOL, SENDER, 0x23, "PaddleBoat", "BoatMove", "CPacketSteerBoat");
|
||||
public static final PacketType PICK_ITEM_FROM_BLOCK = new PacketType(PROTOCOL, SENDER, 0x24, "PickItemFromBlock");
|
||||
public static final PacketType PICK_ITEM = new PacketType(PROTOCOL, SENDER, 0x25, "PickItemFromEntity", "PickItem");
|
||||
public static final PacketType PING_REQUEST = new PacketType(PROTOCOL, SENDER, 0x26, "PingRequest");
|
||||
public static final PacketType AUTO_RECIPE = new PacketType(PROTOCOL, SENDER, 0x27, "PlaceRecipe", "AutoRecipe", "CPacketPlaceRecipe");
|
||||
public static final PacketType ABILITIES = new PacketType(PROTOCOL, SENDER, 0x28, "PlayerAbilities", "Abilities", "CPacketPlayerAbilities");
|
||||
public static final PacketType BLOCK_DIG = new PacketType(PROTOCOL, SENDER, 0x29, "PlayerAction", "BlockDig", "CPacketPlayerDigging");
|
||||
public static final PacketType ENTITY_ACTION = new PacketType(PROTOCOL, SENDER, 0x2A, "PlayerCommand", "EntityAction", "CPacketEntityAction");
|
||||
public static final PacketType STEER_VEHICLE = new PacketType(PROTOCOL, SENDER, 0x2B, "PlayerInput", "SteerVehicle", "CPacketInput");
|
||||
public static final PacketType PLAYER_LOADED = new PacketType(PROTOCOL, SENDER, 0x2C, "PlayerLoaded");
|
||||
public static final PacketType PONG = new PacketType(PROTOCOL, SENDER, 0x2D, "Pong");
|
||||
public static final PacketType PUNCH = new PacketType(PROTOCOL, SENDER, 0x2E, MinecraftVersion.v26_3, "Punch");
|
||||
public static final PacketType RECIPE_SETTINGS = new PacketType(PROTOCOL, SENDER, 0x2F, MinecraftVersion.v26_3, "RecipeBookChangeSettings", "RecipeSettings");
|
||||
public static final PacketType RECIPE_DISPLAYED = new PacketType(PROTOCOL, SENDER, 0x30, MinecraftVersion.v26_3, "RecipeBookSeenRecipe", "RecipeDisplayed", "CPacketRecipeInfo");
|
||||
public static final PacketType ITEM_NAME = new PacketType(PROTOCOL, SENDER, 0x31, MinecraftVersion.v26_3, "RenameItem", "ItemName");
|
||||
public static final PacketType RESOURCE_PACK_STATUS = new PacketType(PROTOCOL, SENDER, 0x32, MinecraftVersion.v26_3, "ResourcePack", "ResourcePackStatus", "CPacketResourcePackStatus");
|
||||
public static final PacketType ADVANCEMENTS = new PacketType(PROTOCOL, SENDER, 0x33, MinecraftVersion.v26_3, "SeenAdvancements", "Advancements", "CPacketSeenAdvancements");
|
||||
public static final PacketType TR_SEL = new PacketType(PROTOCOL, SENDER, 0x34, MinecraftVersion.v26_3, "SelectTrade", "TrSel");
|
||||
public static final PacketType BEACON = new PacketType(PROTOCOL, SENDER, 0x35, MinecraftVersion.v26_3, "SetBeacon", "Beacon");
|
||||
public static final PacketType HELD_ITEM_SLOT = new PacketType(PROTOCOL, SENDER, 0x36, MinecraftVersion.v26_3, "SetCarriedItem", "HeldItemSlot", "CPacketHeldItemChange");
|
||||
public static final PacketType SET_COMMAND_BLOCK = new PacketType(PROTOCOL, SENDER, 0x37, MinecraftVersion.v26_3, "SetCommandBlock");
|
||||
public static final PacketType SET_COMMAND_MINECART = new PacketType(PROTOCOL, SENDER, 0x38, MinecraftVersion.v26_3, "SetCommandMinecart");
|
||||
public static final PacketType SET_CREATIVE_SLOT = new PacketType(PROTOCOL, SENDER, 0x39, MinecraftVersion.v26_3, "SetCreativeModeSlot", "SetCreativeSlot", "CPacketCreativeInventoryAction");
|
||||
public static final PacketType SET_GAME_RULE = new PacketType(PROTOCOL, SENDER, 0x3A, MinecraftVersion.v26_3, "SetGameRule");
|
||||
public static final PacketType SET_JIGSAW = new PacketType(PROTOCOL, SENDER, 0x3B, MinecraftVersion.v26_3, "SetJigsawBlock", "SetJigsaw");
|
||||
public static final PacketType STRUCT = new PacketType(PROTOCOL, SENDER, 0x3C, MinecraftVersion.v26_3, "SetStructureBlock", "Struct");
|
||||
public static final PacketType SET_TEST_BLOCK = new PacketType(PROTOCOL, SENDER, 0x3D, MinecraftVersion.v26_3, "SetTestBlock");
|
||||
public static final PacketType UPDATE_SIGN = new PacketType(PROTOCOL, SENDER, 0x3E, MinecraftVersion.v26_3, "SignUpdate", "UpdateSign", "CPacketUpdateSign");
|
||||
public static final PacketType SPECTATE_ENTITY = new PacketType(PROTOCOL, SENDER, 0x3F, MinecraftVersion.v26_3, "SpectatorAction", "SpectateEntity");
|
||||
public static final PacketType SPECTATE = new PacketType(PROTOCOL, SENDER, 0x40, "TeleportToEntity", "Spectate", "CPacketSpectate");
|
||||
public static final PacketType TEST_INSTANCE_BLOCK_ACTION = new PacketType(PROTOCOL, SENDER, 0x41, "TestInstanceBlockAction");
|
||||
public static final PacketType USE_ITEM_ON = new PacketType(PROTOCOL, SENDER, 0x42, "UseItemOn", "BlockPlace", "CPacketPlayerTryUseItemOnBlock");
|
||||
public static final PacketType USE_ITEM = new PacketType(PROTOCOL, SENDER, 0x43, "UseItem", "CPacketPlayerTryUseItem");
|
||||
public static final PacketType CUSTOM_CLICK_ACTION = new PacketType(PROTOCOL, SENDER, 0x44, "CustomClickAction");
|
||||
public static final PacketType TILE_NBT_QUERY = new PacketType(PROTOCOL, SENDER, 0x01, "BlockEntityTagQuery", "TileNBTQuery");
|
||||
public static final PacketType SELECT_BUNDLE_ITEM = new PacketType(PROTOCOL, SENDER, 0x02, "SelectBundleItem");
|
||||
public static final PacketType DIFFICULTY_CHANGE = new PacketType(PROTOCOL, SENDER, 0x03, "ChangeDifficulty", "DifficultyChange");
|
||||
public static final PacketType CHANGE_GAME_MODE = new PacketType(PROTOCOL, SENDER, 0x04, "ChangeGameMode");
|
||||
public static final PacketType CHAT_ACK = new PacketType(PROTOCOL, SENDER, 0x05, "ChatAck");
|
||||
public static final PacketType CHAT_COMMAND = new PacketType(PROTOCOL, SENDER, 0x06, "ChatCommand");
|
||||
public static final PacketType CHAT_COMMAND_SIGNED = new PacketType(PROTOCOL, SENDER, 0x07, "ChatCommandSigned");
|
||||
public static final PacketType CHAT = new PacketType(PROTOCOL, SENDER, 0x08, "Chat", "CPacketChatMessage");
|
||||
public static final PacketType CHAT_SESSION_UPDATE = new PacketType(PROTOCOL, SENDER, 0x09, "ChatSessionUpdate");
|
||||
public static final PacketType CHUNK_BATCH_RECEIVED = new PacketType(PROTOCOL, SENDER, 0x0A, "ChunkBatchReceived");
|
||||
public static final PacketType CLIENT_COMMAND = new PacketType(PROTOCOL, SENDER, 0x0B, "ClientCommand", "CPacketClientStatus");
|
||||
public static final PacketType CLIENT_TICK_END = new PacketType(PROTOCOL, SENDER, 0x0C, "ClientTickEnd");
|
||||
public static final PacketType SETTINGS = new PacketType(PROTOCOL, SENDER, 0x0D, "ClientInformation", "Settings", "CPacketClientSettings");
|
||||
public static final PacketType TAB_COMPLETE = new PacketType(PROTOCOL, SENDER, 0x0E, "CommandSuggestion", "TabComplete", "CPacketTabComplete");
|
||||
public static final PacketType CONFIGURATION_ACK = new PacketType(PROTOCOL, SENDER, 0x0F, "ConfigurationAcknowledged");
|
||||
public static final PacketType ENCHANT_ITEM = new PacketType(PROTOCOL, SENDER, 0x10, "ContainerButtonClick", "EnchantItem", "CPacketEnchantItem");
|
||||
public static final PacketType WINDOW_CLICK = new PacketType(PROTOCOL, SENDER, 0x11, "ContainerClick", "WindowClick", "CPacketClickWindow");
|
||||
public static final PacketType CLOSE_WINDOW = new PacketType(PROTOCOL, SENDER, 0x12, "ContainerClose", "CloseWindow", "CPacketCloseWindow");
|
||||
public static final PacketType CONTAINER_SLOT_STATE_CHANGED = new PacketType(PROTOCOL, SENDER, 0x13, "ContainerSlotStateChanged", "ContainerSlotStateChangedPacket");
|
||||
public static final PacketType COOKIE_RESPONSE = new PacketType(PROTOCOL, SENDER, 0x14, "CookieResponse");
|
||||
public static final PacketType CUSTOM_PAYLOAD = new PacketType(PROTOCOL, SENDER, 0x15, "CustomPayload", "CPacketCustomPayload");
|
||||
public static final PacketType DEBUG_SAMPLE_SUBSCRIPTION = new PacketType(PROTOCOL, SENDER, 0x16, "DebugSampleSubscription");
|
||||
public static final PacketType B_EDIT = new PacketType(PROTOCOL, SENDER, 0x17, "EditBook", "BEdit");
|
||||
public static final PacketType ENTITY_NBT_QUERY = new PacketType(PROTOCOL, SENDER, 0x18, "EntityTagQuery", "EntityNBTQuery");
|
||||
public static final PacketType USE_ENTITY = new PacketType(PROTOCOL, SENDER, 0x19, "Interact", "UseEntity", "CPacketUseEntity");
|
||||
public static final PacketType JIGSAW_GENERATE = new PacketType(PROTOCOL, SENDER, 0x1A, "JigsawGenerate");
|
||||
public static final PacketType KEEP_ALIVE = new PacketType(PROTOCOL, SENDER, 0x1B, "KeepAlive", "CPacketKeepAlive");
|
||||
public static final PacketType DIFFICULTY_LOCK = new PacketType(PROTOCOL, SENDER, 0x1C, "LockDifficulty", "DifficultyLock");
|
||||
public static final PacketType POSITION = new PacketType(PROTOCOL, SENDER, 0x1D, "net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos", "Flying$Position", "Flying$PacketPlayInPosition", "CPacketPlayer$Position");
|
||||
public static final PacketType POSITION_LOOK = new PacketType(PROTOCOL, SENDER, 0x1E, "net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot", "Flying$PositionLook", "Flying$PacketPlayInPositionLook", "CPacketPlayer$PositionRotation");
|
||||
public static final PacketType LOOK = new PacketType(PROTOCOL, SENDER, 0x1F, "net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Rot", "Flying$Look", "Flying$PacketPlayInLook", "CPacketPlayer$Rotation");
|
||||
public static final PacketType GROUND = new PacketType(PROTOCOL, SENDER, 0x20, "net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$StatusOnly", "Flying$d");
|
||||
public static final PacketType VEHICLE_MOVE = new PacketType(PROTOCOL, SENDER, 0x21, "MoveVehicle", "VehicleMove", "CPacketVehicleMove");
|
||||
public static final PacketType BOAT_MOVE = new PacketType(PROTOCOL, SENDER, 0x22, "PaddleBoat", "BoatMove", "CPacketSteerBoat");
|
||||
public static final PacketType PICK_ITEM_FROM_BLOCK = new PacketType(PROTOCOL, SENDER, 0x23, "PickItemFromBlock");
|
||||
public static final PacketType PICK_ITEM = new PacketType(PROTOCOL, SENDER, 0x24, "PickItemFromEntity", "PickItem");
|
||||
public static final PacketType PING_REQUEST = new PacketType(PROTOCOL, SENDER, 0x25, "PingRequest");
|
||||
public static final PacketType AUTO_RECIPE = new PacketType(PROTOCOL, SENDER, 0x26, "PlaceRecipe", "AutoRecipe", "CPacketPlaceRecipe");
|
||||
public static final PacketType ABILITIES = new PacketType(PROTOCOL, SENDER, 0x27, "PlayerAbilities", "Abilities", "CPacketPlayerAbilities");
|
||||
public static final PacketType BLOCK_DIG = new PacketType(PROTOCOL, SENDER, 0x28, "PlayerAction", "BlockDig", "CPacketPlayerDigging");
|
||||
public static final PacketType ENTITY_ACTION = new PacketType(PROTOCOL, SENDER, 0x29, "PlayerCommand", "EntityAction", "CPacketEntityAction");
|
||||
public static final PacketType STEER_VEHICLE = new PacketType(PROTOCOL, SENDER, 0x2A, "PlayerInput", "SteerVehicle", "CPacketInput");
|
||||
public static final PacketType PLAYER_LOADED = new PacketType(PROTOCOL, SENDER, 0x2B, "PlayerLoaded");
|
||||
public static final PacketType PONG = new PacketType(PROTOCOL, SENDER, 0x2C, "Pong");
|
||||
public static final PacketType RECIPE_SETTINGS = new PacketType(PROTOCOL, SENDER, 0x2D, "RecipeBookChangeSettings", "RecipeSettings");
|
||||
public static final PacketType RECIPE_DISPLAYED = new PacketType(PROTOCOL, SENDER, 0x2E, "RecipeBookSeenRecipe", "RecipeDisplayed", "CPacketRecipeInfo");
|
||||
public static final PacketType ITEM_NAME = new PacketType(PROTOCOL, SENDER, 0x2F, "RenameItem", "ItemName");
|
||||
public static final PacketType RESOURCE_PACK_STATUS = new PacketType(PROTOCOL, SENDER, 0x30, "ResourcePack", "ResourcePackStatus", "CPacketResourcePackStatus");
|
||||
public static final PacketType ADVANCEMENTS = new PacketType(PROTOCOL, SENDER, 0x31, "SeenAdvancements", "Advancements", "CPacketSeenAdvancements");
|
||||
public static final PacketType TR_SEL = new PacketType(PROTOCOL, SENDER, 0x32, "SelectTrade", "TrSel");
|
||||
public static final PacketType BEACON = new PacketType(PROTOCOL, SENDER, 0x33, "SetBeacon", "Beacon");
|
||||
public static final PacketType HELD_ITEM_SLOT = new PacketType(PROTOCOL, SENDER, 0x34, "SetCarriedItem", "HeldItemSlot", "CPacketHeldItemChange");
|
||||
public static final PacketType SET_COMMAND_BLOCK = new PacketType(PROTOCOL, SENDER, 0x35, "SetCommandBlock");
|
||||
public static final PacketType SET_COMMAND_MINECART = new PacketType(PROTOCOL, SENDER, 0x36, "SetCommandMinecart");
|
||||
public static final PacketType SET_CREATIVE_SLOT = new PacketType(PROTOCOL, SENDER, 0x37, "SetCreativeModeSlot", "SetCreativeSlot", "CPacketCreativeInventoryAction");
|
||||
public static final PacketType SET_JIGSAW = new PacketType(PROTOCOL, SENDER, 0x38, "SetJigsawBlock", "SetJigsaw");
|
||||
public static final PacketType STRUCT = new PacketType(PROTOCOL, SENDER, 0x39, "SetStructureBlock", "Struct");
|
||||
public static final PacketType SET_TEST_BLOCK = new PacketType(PROTOCOL, SENDER, 0x3A, "SetTestBlock");
|
||||
public static final PacketType UPDATE_SIGN = new PacketType(PROTOCOL, SENDER, 0x3B, "SignUpdate", "UpdateSign", "CPacketUpdateSign");
|
||||
public static final PacketType ARM_ANIMATION = new PacketType(PROTOCOL, SENDER, 0x3C, "Swing", "ArmAnimation", "CPacketAnimation");
|
||||
public static final PacketType SPECTATE = new PacketType(PROTOCOL, SENDER, 0x3D, "TeleportToEntity", "Spectate", "CPacketSpectate");
|
||||
public static final PacketType TEST_INSTANCE_BLOCK_ACTION = new PacketType(PROTOCOL, SENDER, 0x3E, "TestInstanceBlockAction");
|
||||
public static final PacketType USE_ITEM_ON = new PacketType(PROTOCOL, SENDER, 0x3F, "UseItemOn", "BlockPlace", "CPacketPlayerTryUseItemOnBlock");
|
||||
public static final PacketType USE_ITEM = new PacketType(PROTOCOL, SENDER, 0x40, "UseItem", "CPacketPlayerTryUseItem");
|
||||
public static final PacketType CUSTOM_CLICK_ACTION = new PacketType(PROTOCOL, SENDER, 0x41, "CustomClickAction");
|
||||
|
||||
/**
|
||||
* @deprecated Removed in 1.17
|
||||
@@ -535,18 +523,6 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
@Deprecated
|
||||
public static final PacketType CHAT_PREVIEW = new PacketType(PROTOCOL, SENDER, 253, "ChatPreview");
|
||||
|
||||
/**
|
||||
* deprecated Removed in 1.21.9
|
||||
*/
|
||||
@Deprecated
|
||||
public static final PacketType DEBUG_SAMPLE_SUBSCRIPTION = new PacketType(PROTOCOL, SENDER, 0x16, "DebugSampleSubscription");
|
||||
|
||||
/**
|
||||
* @deprecated Removed in 26.3
|
||||
*/
|
||||
@Deprecated
|
||||
public static final PacketType ARM_ANIMATION = new PacketType(PROTOCOL, SENDER, 252, "Swing", "ArmAnimation", "CPacketAnimation");
|
||||
|
||||
/**
|
||||
* @deprecated Renamed to USE_ITEM_ON
|
||||
*/
|
||||
@@ -728,17 +704,15 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
public static final PacketType REGISTRY_DATA = new PacketType(PROTOCOL, SENDER, 0x07, "RegistryData");
|
||||
public static final PacketType REMOVE_RESOURCE_PACK = new PacketType(PROTOCOL, SENDER, 0x08, "ResourcePackPop");
|
||||
public static final PacketType ADD_RESOURCE_PACK = new PacketType(PROTOCOL, SENDER, 0x09, "ResourcePackPush");
|
||||
public static final PacketType POST_EFFECTS = new PacketType(PROTOCOL, SENDER, 0x0A, "PostEffects");
|
||||
public static final PacketType STORE_COOKIE = new PacketType(PROTOCOL, SENDER, 0x0B, "StoreCookie");
|
||||
public static final PacketType TRANSFER = new PacketType(PROTOCOL, SENDER, 0x0C, "Transfer");
|
||||
public static final PacketType UPDATE_ENABLED_FEATURES = new PacketType(PROTOCOL, SENDER, 0x0D, "UpdateEnabledFeatures");
|
||||
public static final PacketType UPDATE_TAGS = new PacketType(PROTOCOL, SENDER, 0x0E, "UpdateTags");
|
||||
public static final PacketType SELECT_KNOWN_PACKS = new PacketType(PROTOCOL, SENDER, 0x0F, "ClientboundSelectKnownPacks");
|
||||
public static final PacketType REPORT_DETAILS = new PacketType(PROTOCOL, SENDER, 0x10, "CustomReportDetails");
|
||||
public static final PacketType SERVER_LINKS = new PacketType(PROTOCOL, SENDER, 0x11, "ServerLinks");
|
||||
public static final PacketType CLEAR_DIALOG = new PacketType(PROTOCOL, SENDER, 0x12, "ClearDialog");
|
||||
public static final PacketType SHOW_DIALOG = new PacketType(PROTOCOL, SENDER, 0x13, "ShowDialog");
|
||||
public static final PacketType CODE_OF_CONDUCT = new PacketType(PROTOCOL, SENDER, 0x14, "CodeOfConduct");
|
||||
public static final PacketType STORE_COOKIE = new PacketType(PROTOCOL, SENDER, 0x0A, "StoreCookie");
|
||||
public static final PacketType TRANSFER = new PacketType(PROTOCOL, SENDER, 0x0B, "Transfer");
|
||||
public static final PacketType UPDATE_ENABLED_FEATURES = new PacketType(PROTOCOL, SENDER, 0x0C, "UpdateEnabledFeatures");
|
||||
public static final PacketType UPDATE_TAGS = new PacketType(PROTOCOL, SENDER, 0x0D, "UpdateTags");
|
||||
public static final PacketType SELECT_KNOWN_PACKS = new PacketType(PROTOCOL, SENDER, 0x0E, "ClientboundSelectKnownPacks");
|
||||
public static final PacketType REPORT_DETAILS = new PacketType(PROTOCOL, SENDER, 0x0F, "CustomReportDetails");
|
||||
public static final PacketType SERVER_LINKS = new PacketType(PROTOCOL, SENDER, 0x10, "ServerLinks");
|
||||
public static final PacketType CLEAR_DIALOG = new PacketType(PROTOCOL, SENDER, 0x11, "ClearDialog");
|
||||
public static final PacketType SHOW_DIALOG = new PacketType(PROTOCOL, SENDER, 0x12, "ShowDialog");
|
||||
|
||||
/**
|
||||
* @deprecated Removed in 1.20.4: replaced with new packets for removing and sending resource packs
|
||||
@@ -771,7 +745,6 @@ public class PacketType implements Serializable, Cloneable, Comparable<PacketTyp
|
||||
public static final PacketType RESOURCE_PACK_ACK = new PacketType(PROTOCOL, SENDER, 0x06, "ResourcePack");
|
||||
public static final PacketType SELECT_KNOWN_PACKS = new PacketType(PROTOCOL, SENDER, 0x07, "ServerboundSelectKnownPacks");
|
||||
public static final PacketType CUSTOM_CLICK_ACTION = new PacketType(PROTOCOL, SENDER, 0x08, "CustomClickAction");
|
||||
public static final PacketType ACCEPT_CODE_OF_CONDUCT = new PacketType(PROTOCOL, SENDER, 0x09, "AcceptCodeOfConduct");
|
||||
|
||||
private static final Client INSTANCE = new Client();
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.comphenix.protocol;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.comphenix.protocol.injector.PacketFilterManager;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.papermc.paper.connection.PlayerConnection;
|
||||
import io.papermc.paper.connection.ReadablePlayerCookieConnectionImpl;
|
||||
import io.papermc.paper.event.connection.PlayerConnectionValidateLoginEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
class PaperLoginListener implements Listener {
|
||||
private final PacketFilterManager manager;
|
||||
|
||||
PaperLoginListener(PacketFilterManager manager) {
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
private static FieldAccessor networkManagerField;
|
||||
private static FieldAccessor channelField;
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void onPlayerConnectionValidateLogin(PlayerConnectionValidateLoginEvent event) {
|
||||
try {
|
||||
PlayerConnection connection = event.getConnection();
|
||||
ProtocolLogger.log("onPlayerConnectionValidateLogin: " + connection.getAddress());
|
||||
|
||||
if (networkManagerField == null) {
|
||||
FuzzyReflection fuzzy = FuzzyReflection.fromClass(ReadablePlayerCookieConnectionImpl.class, true);
|
||||
Field field = fuzzy.getFieldByType("networkManager", MinecraftReflection.getNetworkManagerClass());
|
||||
networkManagerField = Accessors.getFieldAccessor(field);
|
||||
}
|
||||
|
||||
Object networkManager = networkManagerField.get(connection);
|
||||
|
||||
if (channelField == null) {
|
||||
FuzzyReflection fuzzy = FuzzyReflection.fromObject(networkManager, true);
|
||||
Field field = fuzzy.getFieldByType("channel", Channel.class);
|
||||
channelField = Accessors.getFieldAccessor(field);
|
||||
}
|
||||
|
||||
Channel channel = (Channel) channelField.get(networkManager);
|
||||
manager.injectChannel(channel);
|
||||
ProtocolLogger.log("Successfully injected channel " + channel);
|
||||
} catch (Throwable ex) {
|
||||
ProtocolLogger.log(Level.SEVERE, "Failed to inject channel", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,26 +15,6 @@
|
||||
*/
|
||||
package com.comphenix.protocol;
|
||||
|
||||
import com.comphenix.protocol.async.AsyncFilterManager;
|
||||
import com.comphenix.protocol.error.BasicErrorReporter;
|
||||
import com.comphenix.protocol.error.DelegatedErrorReporter;
|
||||
import com.comphenix.protocol.error.DetailedErrorReporter;
|
||||
import com.comphenix.protocol.error.ErrorReporter;
|
||||
import com.comphenix.protocol.error.Report;
|
||||
import com.comphenix.protocol.error.ReportType;
|
||||
import com.comphenix.protocol.injector.InternalManager;
|
||||
import com.comphenix.protocol.injector.PacketFilterManager;
|
||||
import com.comphenix.protocol.metrics.Statistics;
|
||||
import com.comphenix.protocol.scheduler.DefaultScheduler;
|
||||
import com.comphenix.protocol.scheduler.FoliaScheduler;
|
||||
import com.comphenix.protocol.scheduler.ProtocolScheduler;
|
||||
import com.comphenix.protocol.scheduler.Task;
|
||||
import com.comphenix.protocol.updater.Updater;
|
||||
import com.comphenix.protocol.updater.Updater.UpdateType;
|
||||
import com.comphenix.protocol.utility.*;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -47,19 +27,38 @@ import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.comphenix.protocol.async.AsyncFilterManager;
|
||||
import com.comphenix.protocol.error.BasicErrorReporter;
|
||||
import com.comphenix.protocol.error.DelegatedErrorReporter;
|
||||
import com.comphenix.protocol.error.DetailedErrorReporter;
|
||||
import com.comphenix.protocol.error.ErrorReporter;
|
||||
import com.comphenix.protocol.error.Report;
|
||||
import com.comphenix.protocol.error.ReportType;
|
||||
import com.comphenix.protocol.injector.PacketFilterManager;
|
||||
import com.comphenix.protocol.metrics.Statistics;
|
||||
import com.comphenix.protocol.scheduler.DefaultScheduler;
|
||||
import com.comphenix.protocol.scheduler.FoliaScheduler;
|
||||
import com.comphenix.protocol.scheduler.ProtocolScheduler;
|
||||
import com.comphenix.protocol.scheduler.Task;
|
||||
import com.comphenix.protocol.updater.Updater;
|
||||
import com.comphenix.protocol.updater.Updater.UpdateType;
|
||||
import com.comphenix.protocol.utility.ByteBuddyFactory;
|
||||
import com.comphenix.protocol.utility.ChatExtensions;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.comphenix.protocol.utility.Util;
|
||||
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.comphenix.protocol.internal.PlatformProvider;
|
||||
|
||||
/**
|
||||
* The main entry point for ProtocolLib.
|
||||
*
|
||||
* @author Kristian
|
||||
*/
|
||||
public class ProtocolLib extends JavaPlugin {
|
||||
public abstract class ProtocolLib extends JavaPlugin {
|
||||
// Every possible error or warning report type
|
||||
public static final ReportType REPORT_CANNOT_DELETE_CONFIG = new ReportType(
|
||||
"Cannot delete old ProtocolLib configuration.");
|
||||
@@ -92,8 +91,8 @@ public class ProtocolLib extends JavaPlugin {
|
||||
// these fields are only existing once, we can make them static
|
||||
private static Logger logger;
|
||||
private static ProtocolConfig config;
|
||||
private static InternalManager protocolManager;
|
||||
private static ErrorReporter reporter = new BasicErrorReporter();
|
||||
protected static PacketFilterManager protocolManager;
|
||||
protected static ErrorReporter reporter = new BasicErrorReporter();
|
||||
|
||||
private Statistics statistics;
|
||||
|
||||
@@ -211,7 +210,7 @@ public class ProtocolLib extends JavaPlugin {
|
||||
this.commandPacket = new CommandPacket(reporter, this, logger, this.commandFilter, protocolManager);
|
||||
break;
|
||||
case LOGGING:
|
||||
this.packetLogging = new PacketLogging(this, protocolManager);
|
||||
this.packetLogging = new PacketLogging(reporter, this, protocolManager);
|
||||
break;
|
||||
}
|
||||
} catch (OutOfMemoryError e) {
|
||||
@@ -337,7 +336,11 @@ public class ProtocolLib extends JavaPlugin {
|
||||
this.registerCommand(PacketLogging.NAME, this.packetLogging);
|
||||
|
||||
// Player login and logout events
|
||||
protocolManager.registerEvents(manager, this);
|
||||
protocolManager.inject();
|
||||
|
||||
manager.registerEvents(new BukkitListener(protocolManager), this);
|
||||
|
||||
registerLoginListener();
|
||||
|
||||
// Worker that ensures that async packets are eventually sent
|
||||
// It also performs the update check.
|
||||
@@ -365,6 +368,8 @@ public class ProtocolLib extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
abstract void registerLoginListener();
|
||||
|
||||
// Used to check Minecraft version
|
||||
private MinecraftVersion verifyMinecraftVersion() {
|
||||
MinecraftVersion minimum = new MinecraftVersion(ProtocolLibrary.MINIMUM_MINECRAFT_VERSION);
|
||||
@@ -438,19 +443,7 @@ public class ProtocolLib extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private void registerCommand(String name, CommandExecutor executor) {
|
||||
try {
|
||||
// Ignore these - they must have printed an error already
|
||||
if (executor == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PlatformProvider.get().registerCommand(this, name, executor);
|
||||
} catch (RuntimeException e) {
|
||||
reporter.reportWarning(this,
|
||||
Report.newBuilder(REPORT_CANNOT_REGISTER_COMMAND).messageParam(name, e.getMessage()).error(e));
|
||||
}
|
||||
}
|
||||
abstract void registerCommand(String name, CommandBase command);
|
||||
|
||||
/**
|
||||
* Disable the current plugin.
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.comphenix.protocol;
|
||||
|
||||
public final class ProtocolLibPaper extends ProtocolLib {
|
||||
|
||||
@Override
|
||||
void registerLoginListener() {
|
||||
try {
|
||||
Class.forName("io.papermc.paper.event.connection.PlayerConnectionValidateLoginEvent");
|
||||
getServer().getPluginManager().registerEvents(new com.comphenix.protocol.PaperLoginListener(protocolManager), this);
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
getServer().getPluginManager().registerEvents(new LegacyLoginListener(protocolManager), this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCommand(String name, CommandBase command) {
|
||||
registerCommand(name, (stack, args) -> command.onCommand(stack.getSender(), args));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.comphenix.protocol;
|
||||
|
||||
import com.comphenix.protocol.error.Report;
|
||||
|
||||
import org.bukkit.command.PluginCommand;
|
||||
|
||||
public final class ProtocolLibSpigot extends ProtocolLib {
|
||||
@Override
|
||||
void registerLoginListener() {
|
||||
getServer().getPluginManager().registerEvents(new LegacyLoginListener(protocolManager), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
void registerCommand(String name, CommandBase command) {
|
||||
try {
|
||||
PluginCommand pluginCmd = this.getCommand(name);
|
||||
|
||||
// Try to load the command
|
||||
if (pluginCmd != null) {
|
||||
pluginCmd.setExecutor((sender, _c, _l, args) ->
|
||||
command.onCommand(sender, args));
|
||||
} else {
|
||||
throw new RuntimeException("plugin.yml might be corrupt.");
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
reporter.reportWarning(this,
|
||||
Report.newBuilder(REPORT_CANNOT_REGISTER_COMMAND).messageParam(name, e.getMessage()).error(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import com.comphenix.protocol.error.BasicErrorReporter;
|
||||
import com.comphenix.protocol.error.ErrorReporter;
|
||||
import com.comphenix.protocol.scheduler.ProtocolScheduler;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import com.comphenix.protocol.utility.Validate;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
@@ -35,12 +35,12 @@ public class ProtocolLibrary {
|
||||
/**
|
||||
* The maximum version ProtocolLib has been tested with.
|
||||
*/
|
||||
public static final String MAXIMUM_MINECRAFT_VERSION = "26.3";
|
||||
public static final String MAXIMUM_MINECRAFT_VERSION = "1.21.8";
|
||||
|
||||
/**
|
||||
* The date (with ISO 8601 or YYYY-MM-DD) when the most recent version (26.3) was released.
|
||||
* The date (with ISO 8601 or YYYY-MM-DD) when the most recent version (1.21.8) was released.
|
||||
*/
|
||||
public static final String MINECRAFT_LAST_RELEASE_DATE = "2026-09-15";
|
||||
public static final String MINECRAFT_LAST_RELEASE_DATE = "2025-07-17";
|
||||
|
||||
private static Plugin plugin;
|
||||
private static ProtocolConfig config;
|
||||
@@ -48,8 +48,8 @@ public class ProtocolLibrary {
|
||||
private static ProtocolScheduler scheduler;
|
||||
private static ErrorReporter reporter = new BasicErrorReporter();
|
||||
|
||||
private static boolean updatesDisabled;
|
||||
private static boolean initialized;
|
||||
private static boolean updatesDisabled = false;
|
||||
private static boolean initialized = false;
|
||||
|
||||
protected static void init(Plugin plugin, ProtocolConfig config, ProtocolManager manager,
|
||||
ProtocolScheduler scheduler, ErrorReporter reporter) {
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
/**
|
||||
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
||||
* Copyright (C) 2012 Kristian S. Stangeland
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program;
|
||||
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
package com.comphenix.protocol;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.comphenix.protocol.updater.Updater;
|
||||
|
||||
/**
|
||||
* Callback invoked on the main thread after an asynchronous update check completes.
|
||||
* <p>
|
||||
* Extracted as a top-level class (instead of an anonymous inner class) so that
|
||||
* {@code PaperPluginClassLoader} can always resolve its {@code .class} entry when
|
||||
* {@link org.bukkit.scheduler.BukkitScheduler#runTask} dispatches it back onto the
|
||||
* main server thread — the same pattern used by {@code SpigotUpdateRunnable}.
|
||||
*/
|
||||
final class UpdateNotifyRunnable implements Runnable {
|
||||
|
||||
private final CommandSender sender;
|
||||
private final boolean command;
|
||||
private final Updater updater;
|
||||
private final ProtocolConfig config;
|
||||
private final Plugin plugin;
|
||||
private final CommandProtocol owner;
|
||||
|
||||
UpdateNotifyRunnable(CommandSender sender, boolean command,
|
||||
Updater updater, ProtocolConfig config,
|
||||
Plugin plugin, CommandProtocol owner) {
|
||||
this.sender = sender;
|
||||
this.command = command;
|
||||
this.updater = updater;
|
||||
this.config = config;
|
||||
this.plugin = plugin;
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (command) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "[ProtocolLib] " + updater.getResult());
|
||||
String remoteVersion = updater.getRemoteVersion();
|
||||
if (remoteVersion != null) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Remote version: " + remoteVersion);
|
||||
sender.sendMessage(ChatColor.YELLOW + "Current version: " + plugin.getDescription().getVersion());
|
||||
}
|
||||
} else if (updater.shouldNotify() || config.isDebug()) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "[ProtocolLib] " + updater.getResult());
|
||||
}
|
||||
|
||||
updater.removeListener(this);
|
||||
owner.updateFinished();
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,6 @@ import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import com.comphenix.protocol.injector.collection.InboundPacketListenerSet;
|
||||
import com.comphenix.protocol.injector.collection.OutboundPacketListenerSet;
|
||||
import com.comphenix.protocol.injector.netty.Injector;
|
||||
import com.comphenix.protocol.scheduler.ProtocolScheduler;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -275,7 +274,7 @@ public class AsyncFilterManager implements AsynchronousManager {
|
||||
* @return TRUE if we are, FALSE otherwise.
|
||||
*/
|
||||
private boolean onMainThread() {
|
||||
return Thread.currentThread() == mainThread;
|
||||
return Thread.currentThread().getId() == mainThread.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -309,10 +308,12 @@ public class AsyncFilterManager implements AsynchronousManager {
|
||||
|
||||
asyncMarker.setQueuedSendingIndex(asyncMarker.getNewSendingIndex());
|
||||
|
||||
PacketSendingQueue sendingQueue = getSendingQueue(syncPacket);
|
||||
if (sendingQueue != null) {
|
||||
// The player is only be null when they're logged out,
|
||||
// so this should be a pretty safe check
|
||||
Player player = syncPacket.getPlayer();
|
||||
if (player != null) {
|
||||
// Start the process
|
||||
sendingQueue.enqueue(newEvent);
|
||||
getSendingQueue(syncPacket).enqueue(newEvent);
|
||||
|
||||
// We know this is occurring on the main thread, so pass TRUE
|
||||
getProcessingQueue(syncPacket).enqueue(newEvent, true);
|
||||
@@ -321,12 +322,12 @@ public class AsyncFilterManager implements AsynchronousManager {
|
||||
|
||||
@Override
|
||||
public Set<PacketType> getReceivingTypes() {
|
||||
return clientProcessingQueue.keySet();
|
||||
return serverProcessingQueue.keySet();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<PacketType> getSendingTypes() {
|
||||
return serverProcessingQueue.keySet();
|
||||
return clientProcessingQueue.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -346,8 +347,8 @@ public class AsyncFilterManager implements AsynchronousManager {
|
||||
* Construct a asynchronous marker with all the default values.
|
||||
* @return Asynchronous marker.
|
||||
*/
|
||||
public AsyncMarker createAsyncMarker(Injector injector) {
|
||||
return createAsyncMarker(injector, AsyncMarker.DEFAULT_TIMEOUT_DELTA);
|
||||
public AsyncMarker createAsyncMarker() {
|
||||
return createAsyncMarker(AsyncMarker.DEFAULT_TIMEOUT_DELTA);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -355,13 +356,13 @@ public class AsyncFilterManager implements AsynchronousManager {
|
||||
* @param timeoutDelta - how long (in ms) until the packet expire.
|
||||
* @return An async marker.
|
||||
*/
|
||||
public AsyncMarker createAsyncMarker(Injector injector, long timeoutDelta) {
|
||||
return createAsyncMarker(injector, timeoutDelta, currentSendingIndex.incrementAndGet());
|
||||
public AsyncMarker createAsyncMarker(long timeoutDelta) {
|
||||
return createAsyncMarker(timeoutDelta, currentSendingIndex.incrementAndGet());
|
||||
}
|
||||
|
||||
// Helper method
|
||||
private AsyncMarker createAsyncMarker(Injector injector, long timeoutDelta, long sendingIndex) {
|
||||
return new AsyncMarker(injector, sendingIndex, System.currentTimeMillis(), timeoutDelta);
|
||||
private AsyncMarker createAsyncMarker(long timeoutDelta, long sendingIndex) {
|
||||
return new AsyncMarker(manager, sendingIndex, System.currentTimeMillis(), timeoutDelta);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -538,7 +538,7 @@ public class AsyncListenerHandler {
|
||||
*/
|
||||
private void listenerLoop(int workerID) {
|
||||
// Danger, danger!
|
||||
if (Thread.currentThread() == mainThread)
|
||||
if (Thread.currentThread().getId() == mainThread.getId())
|
||||
throw new IllegalStateException("Do not call this method from the main thread.");
|
||||
if (cancelled)
|
||||
throw new IllegalStateException("Listener has been cancelled. Create a new listener instead.");
|
||||
|
||||
@@ -23,18 +23,14 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import com.comphenix.protocol.PacketStream;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolLogger;
|
||||
import com.comphenix.protocol.events.NetworkMarker;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.injector.netty.Injector;
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
@@ -68,7 +64,7 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
||||
/**
|
||||
* The packet stream responsible for transmitting the packet when it's done processing.
|
||||
*/
|
||||
private final Injector injector;
|
||||
private transient PacketStream packetStream;
|
||||
|
||||
/**
|
||||
* Current list of async packet listeners.
|
||||
@@ -90,7 +86,7 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
||||
private volatile boolean processed;
|
||||
|
||||
// Whether or not the packet has been sent
|
||||
private final AtomicBoolean transmitted = new AtomicBoolean(false);
|
||||
private volatile boolean transmitted;
|
||||
|
||||
// Whether or not the asynchronous processing itself should be cancelled
|
||||
private volatile boolean asyncCancelled;
|
||||
@@ -113,8 +109,11 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
||||
* Create a container for asyncronous packets.
|
||||
* @param initialTime - the current time in milliseconds since 01.01.1970 00:00.
|
||||
*/
|
||||
AsyncMarker(Injector injector, long sendingIndex, long initialTime, long timeoutDelta) {
|
||||
this.injector = Objects.requireNonNull(injector, "injector is nul");
|
||||
AsyncMarker(PacketStream packetStream, long sendingIndex, long initialTime, long timeoutDelta) {
|
||||
if (packetStream == null)
|
||||
throw new IllegalArgumentException("packetStream cannot be NULL");
|
||||
|
||||
this.packetStream = packetStream;
|
||||
|
||||
// Timeout
|
||||
this.initialTime = initialTime;
|
||||
@@ -181,18 +180,16 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
||||
* Retrieve the packet stream responsible for transmitting this packet.
|
||||
* @return The packet stream.
|
||||
*/
|
||||
@Deprecated
|
||||
public PacketStream getPacketStream() {
|
||||
return ProtocolLibrary.getProtocolManager();
|
||||
return packetStream;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the output packet stream responsible for transmitting this packet.
|
||||
* @param packetStream - new output packet stream.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setPacketStream(PacketStream packetStream) {
|
||||
// NOOP
|
||||
this.packetStream = packetStream;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -288,7 +285,7 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
||||
* @return TRUE if it has been sent before, FALSE otherwise.
|
||||
*/
|
||||
public boolean isTransmitted() {
|
||||
return transmitted.get();
|
||||
return transmitted;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -386,18 +383,13 @@ public class AsyncMarker implements Serializable, Comparable<AsyncMarker> {
|
||||
* @throws IOException If the packet couldn't be sent.
|
||||
*/
|
||||
void sendPacket(PacketEvent event) throws IOException {
|
||||
if (!this.transmitted.compareAndSet(false, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object handle = event.getPacket().getHandle();
|
||||
|
||||
if (event.isServerPacket()) {
|
||||
NetworkMarker marker = NetworkMarker.getNetworkMarker(event);
|
||||
this.injector.sendClientboundPacket(handle, marker, false);
|
||||
packetStream.sendServerPacket(event.getPlayer(), event.getPacket(), NetworkMarker.getNetworkMarker(event), false);
|
||||
} else {
|
||||
this.injector.readServerboundPacket(handle);
|
||||
packetStream.receiveClientPacket(event.getPlayer(), event.getPacket(), NetworkMarker.getNetworkMarker(event),
|
||||
false);
|
||||
}
|
||||
transmitted = true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -134,18 +134,14 @@ class PlayerSendingHandler {
|
||||
* @return The server or client sending queue the packet belongs to.
|
||||
*/
|
||||
public PacketSendingQueue getSendingQueue(PacketEvent packet, boolean createNew) {
|
||||
Player player = packet.getPlayer();
|
||||
if (player == null)
|
||||
return null;
|
||||
|
||||
QueueContainer queues = playerSendingQueues.get(player);
|
||||
QueueContainer queues = playerSendingQueues.get(packet.getPlayer());
|
||||
|
||||
// Safe concurrent initialization
|
||||
if (queues == null && createNew) {
|
||||
final QueueContainer newContainer = new QueueContainer();
|
||||
|
||||
// Attempt to map the queue
|
||||
queues = playerSendingQueues.putIfAbsent(player, newContainer);
|
||||
queues = playerSendingQueues.putIfAbsent(packet.getPlayer(), newContainer);
|
||||
|
||||
if (queues == null) {
|
||||
queues = newContainer;
|
||||
|
||||
@@ -58,8 +58,6 @@ public class IntegerMap<T> {
|
||||
* @return The old associated value, or NULL.
|
||||
*/
|
||||
public T remove(int key) {
|
||||
if (key < 0 || key >= array.length) return null;
|
||||
|
||||
T old = array[key];
|
||||
array[key] = null;
|
||||
|
||||
|
||||
@@ -190,8 +190,7 @@ public class ConcurrentPlayerMap<TValue> extends AbstractMap<Player, TValue> imp
|
||||
Preconditions.checkNotNull(player, "player cannot be null");
|
||||
|
||||
Object key = keyMethod.apply(player);
|
||||
Preconditions.checkState(key != null, "Unable to derive a key for the player.");
|
||||
|
||||
|
||||
keyLookup.put(key, player);
|
||||
return key;
|
||||
}
|
||||
|
||||
@@ -30,20 +30,17 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringStyle;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.comphenix.protocol.ProtocolConfig;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolLogger;
|
||||
import com.comphenix.protocol.collections.ExpireHashMap;
|
||||
import com.comphenix.protocol.error.Report.ReportBuilder;
|
||||
import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.reflect.PrettyPrinter;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.primitives.Primitives;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Internal class used to handle exceptions.
|
||||
@@ -472,7 +469,7 @@ public class DetailedErrorReporter implements ErrorReporter {
|
||||
} if (isSimpleType(value) || value instanceof Class<?>) {
|
||||
return value.toString();
|
||||
} else {
|
||||
try {
|
||||
/*try {
|
||||
if (!apacheCommonsMissing)
|
||||
return ToStringBuilder.reflectionToString(value, ToStringStyle.MULTI_LINE_STYLE, false, null);
|
||||
} catch (LinkageError ex) {
|
||||
@@ -483,7 +480,7 @@ public class DetailedErrorReporter implements ErrorReporter {
|
||||
} catch (Throwable ex) {
|
||||
// Don't use the error logger to log errors in error logging (that could lead to infinite loops)
|
||||
ProtocolLogger.log(Level.WARNING, "Cannot convert to a String with Apache: " + ex.getMessage());
|
||||
}
|
||||
}*/
|
||||
|
||||
// Use our custom object printer instead
|
||||
try {
|
||||
|
||||
@@ -10,22 +10,8 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.reflect.EquivalentConverter;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
@@ -55,8 +41,6 @@ import com.comphenix.protocol.wrappers.WrappedLevelChunkData;
|
||||
import com.comphenix.protocol.wrappers.WrappedMessageSignature;
|
||||
import com.comphenix.protocol.wrappers.WrappedNumberFormat;
|
||||
import com.comphenix.protocol.wrappers.WrappedParticle;
|
||||
import com.comphenix.protocol.wrappers.WrappedPositionMoveRotation;
|
||||
import com.comphenix.protocol.wrappers.WrappedPositionPath;
|
||||
import com.comphenix.protocol.wrappers.WrappedProfilePublicKey;
|
||||
import com.comphenix.protocol.wrappers.WrappedProfilePublicKey.WrappedProfileKeyData;
|
||||
import com.comphenix.protocol.wrappers.WrappedRegistrable;
|
||||
@@ -66,12 +50,24 @@ import com.comphenix.protocol.wrappers.WrappedSaltedSignature;
|
||||
import com.comphenix.protocol.wrappers.WrappedServerPing;
|
||||
import com.comphenix.protocol.wrappers.WrappedStatistic;
|
||||
import com.comphenix.protocol.wrappers.WrappedTeamParameters;
|
||||
import com.comphenix.protocol.wrappers.WrappedVecDelta;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtBase;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtFactory;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.comphenix.protocol.utility.Validate;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldType;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.MerchantRecipe;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class AbstractStructure {
|
||||
protected transient Object handle;
|
||||
@@ -600,7 +596,9 @@ public abstract class AbstractStructure {
|
||||
*/
|
||||
public StructureModifier<List<PlayerInfoData>> getPlayerInfoDataLists() {
|
||||
// Convert to and from the ProtocolLib wrapper
|
||||
return getLists(PlayerInfoData.getConverter());
|
||||
return structureModifier.withType(
|
||||
Collection.class,
|
||||
BukkitConverters.getListConverter(PlayerInfoData.getConverter()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1166,35 +1164,9 @@ public abstract class AbstractStructure {
|
||||
}
|
||||
|
||||
/**
|
||||
* Since 26.3 the signature fields are optional, an absent signature is read and written as {@code null}.
|
||||
*
|
||||
* @return read/writer structure direct access to unsalted signature data for example in chat message (since 1.19.3)
|
||||
*/
|
||||
public StructureModifier<WrappedMessageSignature> getMessageSignatures() {
|
||||
if (MinecraftVersion.v26_3.atOrAbove()) {
|
||||
EquivalentConverter<WrappedMessageSignature> converter = BukkitConverters.getWrappedMessageSignatureConverter();
|
||||
return structureModifier.withParamType(
|
||||
Optional.class,
|
||||
new EquivalentConverter<WrappedMessageSignature>() {
|
||||
@Override
|
||||
public Object getGeneric(WrappedMessageSignature specific) {
|
||||
return Optional.ofNullable(converter.getGeneric(specific));
|
||||
}
|
||||
|
||||
@Override
|
||||
public WrappedMessageSignature getSpecific(Object generic) {
|
||||
return generic == null ? null : ((Optional<?>) generic).map(converter::getSpecific).orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<WrappedMessageSignature> getSpecificType() {
|
||||
return WrappedMessageSignature.class;
|
||||
}
|
||||
},
|
||||
MinecraftReflection.getMessageSignatureClass()
|
||||
);
|
||||
}
|
||||
|
||||
return structureModifier.withType(
|
||||
MinecraftReflection.getMessageSignatureClass(),
|
||||
BukkitConverters.getWrappedMessageSignatureConverter()
|
||||
@@ -1324,48 +1296,6 @@ public abstract class AbstractStructure {
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a read/write structure for {@link WrappedPositionMoveRotation} (available since Minecraft 1.21.2).
|
||||
* <p>
|
||||
* This is used in packets such as {@code ENTITY_TELEPORT} and {@code ENTITY_POSITION_SYNC} (before 26.3).
|
||||
*
|
||||
* @return A modifier for PositionMoveRotation fields.
|
||||
*/
|
||||
public StructureModifier<WrappedPositionMoveRotation> getPositionMoveRotation() {
|
||||
return structureModifier.withType(
|
||||
MinecraftReflection.getPositionMoveRotationClass(),
|
||||
WrappedPositionMoveRotation.getConverter()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a read/write structure for {@link WrappedVecDelta} (available since Minecraft 26.3).
|
||||
* <p>
|
||||
* This is used in {@code REL_ENTITY_MOVE} and {@code REL_ENTITY_MOVE_LOOK}.
|
||||
*
|
||||
* @return A modifier for VecDelta fields.
|
||||
*/
|
||||
public StructureModifier<WrappedVecDelta> getVecDeltas() {
|
||||
return structureModifier.withType(
|
||||
MinecraftReflection.getVecDeltaClass().orElse(void.class),
|
||||
WrappedVecDelta.getConverter()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a read/write structure for {@link WrappedPositionPath} (available since Minecraft 26.3).
|
||||
* <p>
|
||||
* This is used in {@code ENTITY_POSITION_SYNC}.
|
||||
*
|
||||
* @return A modifier for PositionPath fields.
|
||||
*/
|
||||
public StructureModifier<WrappedPositionPath> getPositionPaths() {
|
||||
return structureModifier.withType(
|
||||
MinecraftReflection.getPositionPathClass().orElse(void.class),
|
||||
WrappedPositionPath.getConverter()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an equivalent converter for ItemStack arrays.
|
||||
* @author Kristian
|
||||
|
||||
@@ -232,13 +232,13 @@ public abstract class PacketAdapter implements PacketListener {
|
||||
@Override
|
||||
public void onPacketReceiving(PacketEvent event) {
|
||||
// Lets prevent some bugs
|
||||
throw new IllegalStateException("Override onPacketReceiving to get notifications of received packets!");
|
||||
throw new IllegalStateException("Override onPacketReceiving to get notifcations of received packets!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
// Lets prevent some bugs
|
||||
throw new IllegalStateException("Override onPacketSending to get notifications of sent packets!");
|
||||
throw new IllegalStateException("Override onPacketSending to get notifcations of sent packets!");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -391,8 +391,6 @@ public class PacketEvent extends EventObject implements Cancellable {
|
||||
* <li>getPlayer</li>
|
||||
* <li>getAddress</li>
|
||||
* <li>getServer</li>
|
||||
* <li>getName, after the login start packet</li>
|
||||
* <li>getUniqueId, when supplied by the login protocol</li>
|
||||
* <li>chat</li>
|
||||
* <li>sendMessage</li>
|
||||
* <li>kickPlayer</li>
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import com.comphenix.protocol.utility.Validate;
|
||||
|
||||
/**
|
||||
* Stores and retrieves metadata for applicable packet objects.
|
||||
|
||||
@@ -22,10 +22,8 @@ import java.io.ObjectInputStream;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
@@ -38,6 +36,7 @@ import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||
import com.comphenix.protocol.utility.ByteBuddyFactory;
|
||||
import com.comphenix.protocol.utility.Util;
|
||||
|
||||
import io.papermc.paper.persistence.PersistentDataContainerView;
|
||||
import net.bytebuddy.description.ByteCodeElement;
|
||||
import net.bytebuddy.description.modifier.Visibility;
|
||||
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
|
||||
@@ -62,7 +61,6 @@ import org.bukkit.World;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.profile.PlayerProfile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
@@ -70,7 +68,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
*
|
||||
* @author Kristian
|
||||
*/
|
||||
class SerializedOfflinePlayer implements Serializable {
|
||||
class SerializedOfflinePlayer implements OfflinePlayer, Serializable {
|
||||
|
||||
/**
|
||||
* Generated by Eclipse.
|
||||
@@ -124,18 +122,22 @@ class SerializedOfflinePlayer implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOp() {
|
||||
return operator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOp(boolean operator) {
|
||||
this.operator = operator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> serialize() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getBedSpawnLocation() {
|
||||
return bedSpawnLocation;
|
||||
}
|
||||
@@ -150,14 +152,33 @@ class SerializedOfflinePlayer implements Serializable {
|
||||
return lastSeen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getRespawnLocation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param b
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public @org.jspecify.annotations.Nullable Location getRespawnLocation(boolean b) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLocation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PersistentDataContainerView getPersistentDataContainer() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO do we need to implement this?
|
||||
|
||||
public void incrementStatistic(Statistic statistic) throws IllegalArgumentException {
|
||||
@@ -217,34 +238,45 @@ class SerializedOfflinePlayer implements Serializable {
|
||||
public void setStatistic(Statistic statistic, EntityType entityType, int i) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Location getLastDeathLocation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getFirstPlayed() {
|
||||
return firstPlayed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLastPlayed() {
|
||||
return lastPlayed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getUniqueId() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public @NotNull PlayerProfile getPlayerProfile() {
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public com.destroystokyo.paper.profile.PlayerProfile getPlayerProfile() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPlayedBefore() {
|
||||
return playedBefore;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBanned() {
|
||||
return banned;
|
||||
}
|
||||
@@ -271,14 +303,25 @@ class SerializedOfflinePlayer implements Serializable {
|
||||
this.banned = banned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnline() {
|
||||
return online;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isWhitelisted() {
|
||||
return whitelisted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWhitelisted(boolean whitelisted) {
|
||||
this.whitelisted = whitelisted;
|
||||
}
|
||||
@@ -315,6 +358,7 @@ class SerializedOfflinePlayer implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player getPlayer() {
|
||||
try {
|
||||
// Try to get the real player underneath
|
||||
@@ -333,7 +377,7 @@ class SerializedOfflinePlayer implements Serializable {
|
||||
*/
|
||||
public Player getProxyPlayer() {
|
||||
try {
|
||||
return (Player) proxyPlayerConstructor.newInstance(this.createOfflinePlayerProxy());
|
||||
return (Player) proxyPlayerConstructor.newInstance(this);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException("Cannot access reflection.", e);
|
||||
} catch (InstantiationException e) {
|
||||
@@ -343,38 +387,6 @@ class SerializedOfflinePlayer implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
private OfflinePlayer createOfflinePlayerProxy() {
|
||||
return (OfflinePlayer) Proxy.newProxyInstance(
|
||||
OfflinePlayer.class.getClassLoader(),
|
||||
new Class<?>[]{OfflinePlayer.class},
|
||||
(proxy, method, arguments) -> {
|
||||
if (method.getDeclaringClass() == Object.class) {
|
||||
return switch (method.getName()) {
|
||||
case "equals" -> proxy == arguments[0];
|
||||
case "hashCode" -> System.identityHashCode(proxy);
|
||||
case "toString" -> "SerializedOfflinePlayer[" + this.name + "]";
|
||||
default -> throw new UnsupportedOperationException("Unsupported Object method " + method);
|
||||
};
|
||||
}
|
||||
|
||||
try {
|
||||
Method target = SerializedOfflinePlayer.class.getMethod(
|
||||
method.getName(),
|
||||
method.getParameterTypes());
|
||||
return target.invoke(this, arguments);
|
||||
} catch (NoSuchMethodException exception) {
|
||||
if (method.isDefault()) {
|
||||
return InvocationHandler.invokeDefault(proxy, method, arguments);
|
||||
}
|
||||
throw new UnsupportedOperationException(
|
||||
"The method " + method.getName() + " is not supported for offline players.",
|
||||
exception);
|
||||
} catch (InvocationTargetException exception) {
|
||||
throw exception.getCause();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static Constructor<? extends Player> setupProxyPlayerConstructor() {
|
||||
final Method[] offlinePlayerMethods = OfflinePlayer.class.getMethods();
|
||||
final String[] methodNames = new String[offlinePlayerMethods.length];
|
||||
|
||||
@@ -39,7 +39,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import com.comphenix.protocol.utility.Validate;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.comphenix.protocol.injector;
|
||||
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
/**
|
||||
* Yields access to the internal hook configuration.
|
||||
@@ -11,14 +9,6 @@ import org.bukkit.plugin.PluginManager;
|
||||
*/
|
||||
public interface InternalManager extends ProtocolManager {
|
||||
|
||||
/**
|
||||
* Register this protocol manager on Bukkit.
|
||||
*
|
||||
* @param manager - Bukkit plugin manager that provides player join/leave events.
|
||||
* @param plugin - the parent plugin.
|
||||
*/
|
||||
void registerEvents(PluginManager manager, final Plugin plugin);
|
||||
|
||||
/**
|
||||
* Called when ProtocolLib is closing.
|
||||
*/
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package com.comphenix.protocol.injector;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLib;
|
||||
import com.comphenix.protocol.async.AsyncFilterManager;
|
||||
import com.comphenix.protocol.error.ErrorReporter;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
@@ -112,7 +114,7 @@ public class PacketFilterBuilder {
|
||||
*
|
||||
* @return A new packet filter manager.
|
||||
*/
|
||||
public InternalManager build() {
|
||||
public PacketFilterManager build() {
|
||||
if (this.reporter == null) {
|
||||
throw new IllegalArgumentException("reporter cannot be NULL.");
|
||||
}
|
||||
|
||||
@@ -8,21 +8,6 @@ import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.server.PluginDisableEvent;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import com.comphenix.protocol.AsynchronousManager;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
@@ -43,12 +28,19 @@ import com.comphenix.protocol.injector.PluginVerifier.VerificationResult;
|
||||
import com.comphenix.protocol.injector.collection.InboundPacketListenerSet;
|
||||
import com.comphenix.protocol.injector.collection.OutboundPacketListenerSet;
|
||||
import com.comphenix.protocol.injector.collection.PacketListenerSet;
|
||||
import com.comphenix.protocol.injector.netty.Injector;
|
||||
import com.comphenix.protocol.injector.netty.WirePacket;
|
||||
import com.comphenix.protocol.injector.netty.manager.NetworkManagerInjector;
|
||||
import com.comphenix.protocol.injector.packet.PacketRegistry;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import io.netty.channel.Channel;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class PacketFilterManager implements ListenerManager, InternalManager {
|
||||
|
||||
@@ -152,20 +144,29 @@ public class PacketFilterManager implements ListenerManager, InternalManager {
|
||||
|
||||
@Override
|
||||
public void sendServerPacket(Player receiver, PacketContainer packet, NetworkMarker marker, boolean filters) {
|
||||
if (this.closed) {
|
||||
return;
|
||||
}
|
||||
|
||||
// A monitor listener should never modify a packet/event so we can simply invoke monitor listeners
|
||||
// independently of our injector pipeline
|
||||
if (!filters) {
|
||||
this.runMonitorListeners(packet, () -> {
|
||||
if (!this.closed) {
|
||||
// if we skip the packet events later when actually writing into the pipeline we at least notify all
|
||||
// monitor listeners before doing so - they will not be able to change the event tho
|
||||
if (!filters) {
|
||||
// ensure we are on the main thread if any listener requires that
|
||||
if (this.hasMainThreadListener(packet.getType()) && !this.server.isPrimaryThread()) {
|
||||
NetworkMarker copy = marker; // okay fine
|
||||
ProtocolLibrary.getScheduler().scheduleSyncDelayedTask(
|
||||
() -> this.sendServerPacket(receiver, packet, copy, false), 1L);
|
||||
return;
|
||||
}
|
||||
|
||||
// construct the event and post to all monitor listeners
|
||||
PacketEvent event = PacketEvent.fromServer(this, packet, marker, receiver, false);
|
||||
this.outboundListeners.invoke(event, ListenerPriority.MONITOR);
|
||||
});
|
||||
}
|
||||
|
||||
this.networkManagerInjector.getInjector(receiver).sendClientboundPacket(packet.getHandle(), marker, filters);
|
||||
// update the marker of the event without accidentally constructing it
|
||||
marker = NetworkMarker.getNetworkMarker(event);
|
||||
}
|
||||
|
||||
// process outbound
|
||||
this.networkManagerInjector.getInjector(receiver).sendClientboundPacket(packet.getHandle(), marker, filters);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -192,40 +193,34 @@ public class PacketFilterManager implements ListenerManager, InternalManager {
|
||||
|
||||
@Override
|
||||
public void receiveClientPacket(Player sender, PacketContainer packet, NetworkMarker marker, boolean filters) {
|
||||
if (this.closed) {
|
||||
return;
|
||||
}
|
||||
|
||||
// make sure we are on the main thread if any listener of the packet needs it
|
||||
if (filters && this.requiresMainThread(packet)) {
|
||||
ProtocolLibrary.getScheduler().runTask(
|
||||
() -> this.receiveClientPacket(sender, packet, marker, filters));
|
||||
return;
|
||||
}
|
||||
|
||||
Object nmsPacket = packet.getHandle();
|
||||
|
||||
if (filters) {
|
||||
PacketEvent event = PacketEvent.fromClient(this, packet, marker, sender, false);
|
||||
this.invokeInboundPacketListeners(event);
|
||||
|
||||
if (event.isCancelled()) {
|
||||
if (!this.closed) {
|
||||
// make sure we are on the main thread if any listener of the packet needs it
|
||||
if (this.hasMainThreadListener(packet.getType()) && !this.server.isPrimaryThread()) {
|
||||
ProtocolLibrary.getScheduler().runTask(
|
||||
() -> this.receiveClientPacket(sender, packet, marker, filters));
|
||||
return;
|
||||
}
|
||||
|
||||
// Prevent possible de-sync if the packet was replaced by a listener.
|
||||
nmsPacket = event.getPacket().getHandle();
|
||||
} else {
|
||||
// A monitor listener should never modify a packet/event so we can simply invoke monitor listeners
|
||||
// independently of our injector pipeline
|
||||
this.runMonitorListeners(packet, () -> {
|
||||
Object nmsPacket = packet.getHandle();
|
||||
// check to which listeners we need to post the packet
|
||||
if (filters) {
|
||||
// post to all listeners
|
||||
PacketEvent event = PacketEvent.fromClient(this.networkManagerInjector, packet, null, sender);
|
||||
this.invokeInboundPacketListeners(event);
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// prevent possible de-sync
|
||||
nmsPacket = event.getPacket().getHandle();
|
||||
} else {
|
||||
PacketEvent event = PacketEvent.fromClient(this, packet, marker, sender, false);
|
||||
this.inboundListeners.invoke(event, ListenerPriority.MONITOR);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// post to the player inject, reset our cancel state change
|
||||
this.networkManagerInjector.getInjector(sender).readServerboundPacket(nmsPacket);
|
||||
// post to the player inject, reset our cancel state change
|
||||
this.networkManagerInjector.getInjector(sender).readServerboundPacket(nmsPacket);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -325,24 +320,30 @@ public class PacketFilterManager implements ListenerManager, InternalManager {
|
||||
|
||||
@Override
|
||||
public void removePacketListener(PacketListener listener) {
|
||||
if (!this.closed && this.registeredListeners.remove(listener)) {
|
||||
ListeningWhitelist outbound = listener.getSendingWhitelist();
|
||||
ListeningWhitelist inbound = listener.getReceivingWhitelist();
|
||||
if (this.closed || !this.registeredListeners.remove(listener)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// remove outbound listeners (if any)
|
||||
if (outbound != null && outbound.isEnabled()) {
|
||||
this.outboundListeners.removeListener(listener);
|
||||
}
|
||||
ListeningWhitelist outbound = listener.getSendingWhitelist();
|
||||
ListeningWhitelist inbound = listener.getReceivingWhitelist();
|
||||
|
||||
// remove inbound listeners (if any)
|
||||
if (inbound != null && inbound.isEnabled()) {
|
||||
this.inboundListeners.removeListener(listener);
|
||||
}
|
||||
// remove outbound listeners (if any)
|
||||
if (outbound != null && outbound.isEnabled()) {
|
||||
this.outboundListeners.removeListener(listener);
|
||||
}
|
||||
|
||||
// remove inbound listeners (if any)
|
||||
if (inbound != null && inbound.isEnabled()) {
|
||||
this.inboundListeners.removeListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePacketListeners(Plugin plugin) {
|
||||
if (this.closed || this.plugin.equals(plugin)) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (PacketListener listener : this.getPacketListeners()) {
|
||||
if (Objects.equals(listener.getPlugin(), plugin)) {
|
||||
this.removePacketListener(listener);
|
||||
@@ -419,46 +420,26 @@ public class PacketFilterManager implements ListenerManager, InternalManager {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerEvents(PluginManager manager, Plugin plugin) {
|
||||
if (!this.closed && !this.injected) {
|
||||
// prevent duplicate event registrations / injections
|
||||
this.injected = true;
|
||||
this.networkManagerInjector.inject();
|
||||
public void removePlayer(Player player) {
|
||||
asyncFilterManager.removePlayer(player);
|
||||
}
|
||||
|
||||
// Paper disables reconfiguration when any PlayerLoginEvent listener is registered.
|
||||
if (!this.networkManagerInjector.isUsingPaperChannelInitializer()) {
|
||||
manager.registerEvents(new Listener() {
|
||||
public void injectPlayer(Player player) {
|
||||
networkManagerInjector.getInjector(player).inject();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void handleLogin(PlayerLoginEvent event) {
|
||||
networkManagerInjector.getInjector(event.getPlayer()).inject();
|
||||
}
|
||||
}, plugin);
|
||||
}
|
||||
public void injectChannel(Channel channel) {
|
||||
networkManagerInjector.getInjector(channel).inject();
|
||||
}
|
||||
|
||||
// all listeners we need, this is a bit messy, but it makes the job correctly
|
||||
manager.registerEvents(new Listener() {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void handleJoin(PlayerJoinEvent event) {
|
||||
networkManagerInjector.getInjector(event.getPlayer()).inject();
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void handleQuit(PlayerQuitEvent event) {
|
||||
PacketFilterManager.this.asyncFilterManager.removePlayer(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void handlePluginUnload(PluginDisableEvent event) {
|
||||
// don't do this for our plugin!
|
||||
if (event.getPlugin() != PacketFilterManager.this.plugin) {
|
||||
PacketFilterManager.this.removePacketListeners(event.getPlugin());
|
||||
}
|
||||
}
|
||||
}, plugin);
|
||||
public void inject() {
|
||||
if (this.closed || this.injected) {
|
||||
return;
|
||||
}
|
||||
|
||||
// prevent duplicate event registrations / injections
|
||||
this.injected = true;
|
||||
this.networkManagerInjector.inject();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -520,25 +501,12 @@ public class PacketFilterManager implements ListenerManager, InternalManager {
|
||||
this.postPacketToListeners(this.outboundListeners, event, true);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean requiresMainThread(PacketContainer packet) {
|
||||
return this.hasMainThreadListener(packet.getType()) && !this.server.isPrimaryThread();
|
||||
}
|
||||
|
||||
private void runMonitorListeners(PacketContainer packet, Runnable notifyMonitor) {
|
||||
if (this.requiresMainThread(packet)) {
|
||||
ProtocolLibrary.getScheduler().runTask(notifyMonitor);
|
||||
} else {
|
||||
notifyMonitor.run();
|
||||
}
|
||||
}
|
||||
|
||||
private void postPacketToListeners(PacketListenerSet listeners, PacketEvent event, boolean outbound) {
|
||||
try {
|
||||
// append async marker if any async listener for the packet was registered
|
||||
if (this.asyncFilterManager.hasAsynchronousListeners(event)) {
|
||||
Injector injector = this.networkManagerInjector.getInjector(event.getPlayer());
|
||||
event.setAsyncMarker(this.asyncFilterManager.createAsyncMarker(injector));
|
||||
event.setAsyncMarker(this.asyncFilterManager.createAsyncMarker());
|
||||
}
|
||||
|
||||
// post to sync listeners
|
||||
|
||||
@@ -35,7 +35,6 @@ import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.ConstructorAccessor;
|
||||
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
||||
import com.comphenix.protocol.reflect.cloning.ImmutableDetector;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyFieldContract;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract;
|
||||
import com.comphenix.protocol.reflect.instances.DefaultInstances;
|
||||
@@ -83,26 +82,15 @@ public class StructureCache {
|
||||
return newInstance(packetClass);
|
||||
}
|
||||
|
||||
// determineBestCreator can re-enter this cache (legacy 1.8 packet registry), which
|
||||
// ConcurrentHashMap.computeIfAbsent rejects on Java 9+, so use get/put instead.
|
||||
private static Optional<Supplier<Object>> creatorFor(Class<?> clazz) {
|
||||
Optional<Supplier<Object>> creator = CACHED_INSTANCE_CREATORS.get(clazz);
|
||||
if (creator == null) {
|
||||
creator = Optional.ofNullable(determineBestCreator(clazz));
|
||||
Optional<Supplier<Object>> existing = CACHED_INSTANCE_CREATORS.putIfAbsent(clazz, creator);
|
||||
if (existing != null) {
|
||||
creator = existing;
|
||||
}
|
||||
}
|
||||
return creator;
|
||||
}
|
||||
|
||||
public static boolean canCreateInstance(Class<?> clazz) {
|
||||
return creatorFor(clazz).isPresent();
|
||||
Optional<Supplier<Object>> creator = CACHED_INSTANCE_CREATORS.computeIfAbsent(clazz, x ->
|
||||
Optional.ofNullable(determineBestCreator(clazz)));
|
||||
return creator.isPresent();
|
||||
}
|
||||
|
||||
public static Object newInstance(Class<?> clazz) {
|
||||
Optional<Supplier<Object>> creator = creatorFor(clazz);
|
||||
Optional<Supplier<Object>> creator = CACHED_INSTANCE_CREATORS.computeIfAbsent(clazz, x ->
|
||||
Optional.ofNullable(determineBestCreator(clazz)));
|
||||
if (!creator.isPresent()) {
|
||||
throw new IllegalArgumentException("Cannot create instance of " + clazz);
|
||||
}
|
||||
@@ -110,21 +98,15 @@ public class StructureCache {
|
||||
}
|
||||
|
||||
static Supplier<Object> determineBestCreator(Class<?> clazz) {
|
||||
boolean packetClass = MinecraftReflection.isPacketClass(clazz);
|
||||
boolean immutableClass = ImmutableDetector.isImmutable(clazz);
|
||||
|
||||
// Certain packets are singletons which can't really be created. Immutable classes may also expose multiple
|
||||
// constant instances as an enum replacement, which should be reused instead of invoking their constructors.
|
||||
if (packetClass || immutableClass) {
|
||||
// certain packets are singletons which can't really be created
|
||||
if (MinecraftReflection.isPacketClass(clazz)) {
|
||||
FuzzyReflection fuzzy = FuzzyReflection.fromClass(clazz, false);
|
||||
List<Field> singletons = fuzzy.getFieldList(FuzzyFieldContract.newBuilder()
|
||||
.typeExact(clazz)
|
||||
.requireModifier(Modifier.STATIC)
|
||||
.requireModifier(Modifier.PUBLIC)
|
||||
.build());
|
||||
|
||||
// Preserve the existing packet singleton behavior.
|
||||
if (packetClass && singletons.size() == 1) {
|
||||
if (singletons.size() == 1) {
|
||||
FieldAccessor accessor = Accessors.getFieldAccessor(singletons.get(0));
|
||||
try {
|
||||
accessor.get(null);
|
||||
@@ -132,23 +114,6 @@ public class StructureCache {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
if (immutableClass) {
|
||||
for (Field singleton : singletons) {
|
||||
if (!Modifier.isFinal(singleton.getModifiers())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
FieldAccessor accessor = Accessors.getFieldAccessor(singleton);
|
||||
try {
|
||||
Object instance = accessor.get(null);
|
||||
if (instance != null) {
|
||||
return () -> instance;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -159,10 +124,7 @@ public class StructureCache {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
// stream codecs only exist on 1.20.5+; on legacy versions asking the registry re-enters its own
|
||||
// initialization (createOldRegister builds StructureModifiers, which land back here)
|
||||
WrappedStreamCodec streamCodec = MinecraftVersion.v1_20_5.atOrAbove()
|
||||
? PacketRegistry.getStreamCodec(clazz) : null;
|
||||
WrappedStreamCodec streamCodec = PacketRegistry.getStreamCodec(clazz);
|
||||
|
||||
// use the new stream codec for versions above 1.20.5 if possible
|
||||
if (streamCodec != null && tryInitTrickDataSerializer()) {
|
||||
@@ -325,8 +287,8 @@ public class StructureCache {
|
||||
|
||||
if (registryByteBuf.isPresent()) {
|
||||
ConstructorAccessor accessor = Accessors.getConstructorAccessor(FuzzyReflection.fromClass(serializerBase, true).getConstructor(FuzzyMethodContract.newBuilder()
|
||||
.parameterExactType(ByteBuf.class)
|
||||
.parameterExactType(MinecraftReflection.getRegistryAccessClass())
|
||||
.parameterDerivedOf(ByteBuf.class)
|
||||
.parameterDerivedOf(MinecraftReflection.getRegistryAccessClass())
|
||||
.build()));
|
||||
TRICKED_DATA_SERIALIZER_BASE = (buf) -> accessor.invoke(buf, MinecraftRegistryAccess.get());
|
||||
} else {
|
||||
|
||||
+25
-34
@@ -13,7 +13,6 @@ import com.comphenix.protocol.events.ListeningWhitelist;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.events.PacketListener;
|
||||
import com.comphenix.protocol.wrappers.Converters;
|
||||
|
||||
public class OutboundPacketListenerSet extends PacketListenerSet {
|
||||
|
||||
@@ -32,46 +31,38 @@ public class OutboundPacketListenerSet extends PacketListenerSet {
|
||||
|
||||
if (event.getPacketType() == PacketType.Play.Server.BUNDLE && !event.isCancelled()) {
|
||||
// unpack the bundle and invoke for each packet in the bundle
|
||||
List<PacketContainer> packets = Converters.toList(event.getPacket().getPacketBundles().read(0));
|
||||
// lazily allocated when the first packet is removed or replaced
|
||||
List<PacketContainer> outPackets = null;
|
||||
for (int index = 0; index < packets.size(); index++) {
|
||||
PacketContainer subPacket = packets.get(index);
|
||||
PacketContainer packet = null;
|
||||
|
||||
if (subPacket != null) {
|
||||
PacketEvent subPacketEvent = PacketEvent.fromServer(this, subPacket, event.getNetworkMarker(),
|
||||
event.getPlayer(), event.isFiltered(), event);
|
||||
super.invoke(subPacketEvent, priorityFilter);
|
||||
|
||||
if (!subPacketEvent.isCancelled()) {
|
||||
PacketContainer result = subPacketEvent.getPacket();
|
||||
if (result != null && result.getHandle() != null) {
|
||||
packet = result;
|
||||
}
|
||||
}
|
||||
Iterable<PacketContainer> packets = event.getPacket().getPacketBundles().read(0);
|
||||
List<PacketContainer> outPackets = new ArrayList<>();
|
||||
for (PacketContainer subPacket : packets) {
|
||||
// ignore null packets as the will throw an error in the packet encoder
|
||||
if (subPacket == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean changed = packet == null || packet.getHandle() != subPacket.getHandle();
|
||||
if (outPackets == null && changed) {
|
||||
outPackets = new ArrayList<>(packets.size());
|
||||
outPackets.addAll(packets.subList(0, index));
|
||||
PacketEvent subPacketEvent = PacketEvent.fromServer(this, subPacket, event.getNetworkMarker(),
|
||||
event.getPlayer());
|
||||
super.invoke(subPacketEvent, priorityFilter);
|
||||
|
||||
|
||||
// if the packet has been cancelled, the packet will not be add to the bundle
|
||||
if (subPacketEvent.isCancelled()) {
|
||||
continue;
|
||||
}
|
||||
if (outPackets != null && packet != null) {
|
||||
|
||||
PacketContainer packet = subPacketEvent.getPacket();
|
||||
if (packet == null || packet.getHandle() == null) {
|
||||
// super.invoke() should prevent us from getting new null packet so we just ignore it here
|
||||
continue;
|
||||
} else {
|
||||
outPackets.add(packet);
|
||||
}
|
||||
}
|
||||
|
||||
if (!event.isReadOnly() && outPackets != null) {
|
||||
if (!outPackets.isEmpty()) {
|
||||
// the original bundle may be shared between multiple recipients
|
||||
PacketContainer bundle = event.getPacket().shallowClone();
|
||||
bundle.getPacketBundles().write(0, outPackets);
|
||||
event.setPacket(bundle);
|
||||
} else {
|
||||
// cancel entire packet if each individual packet has been cancelled
|
||||
event.setCancelled(true);
|
||||
}
|
||||
if (packets.iterator().hasNext()) {
|
||||
event.getPacket().getPacketBundles().write(0, outPackets);
|
||||
} else {
|
||||
// cancel entire packet if each individual packet has been cancelled
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package com.comphenix.protocol.injector.netty;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Protocol;
|
||||
import com.comphenix.protocol.events.NetworkMarker;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
/**
|
||||
* Represents an injected client connection.
|
||||
*
|
||||
@@ -68,24 +67,6 @@ public interface Injector {
|
||||
*/
|
||||
Player getPlayer();
|
||||
|
||||
/**
|
||||
* Retrieve the player name captured during login.
|
||||
*
|
||||
* @return The player name, or NULL if it is not known yet.
|
||||
*/
|
||||
default String getPlayerName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the player UUID captured during login.
|
||||
*
|
||||
* @return The player UUID, or NULL if it is not available.
|
||||
*/
|
||||
default UUID getPlayerUniqueId() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the current player instance.
|
||||
*
|
||||
@@ -93,6 +74,8 @@ public interface Injector {
|
||||
*/
|
||||
void setPlayer(Player player);
|
||||
|
||||
boolean hasValidPlayer();
|
||||
|
||||
boolean isConnected();
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,13 +19,10 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||
import com.comphenix.protocol.utility.MinecraftMethods;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.comphenix.protocol.utility.StreamSerializer;
|
||||
import com.comphenix.protocol.wrappers.CustomPacketPayloadWrapper;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
@@ -84,11 +81,6 @@ public class WirePacket {
|
||||
public static byte[] bytesFromPacket(PacketContainer packet) {
|
||||
checkNotNull(packet, "packet cannot be null!");
|
||||
|
||||
// packets are written by their stream codec since 1.20.5
|
||||
if (MinecraftVersion.v1_20_5.atOrAbove()) {
|
||||
return bytesFromStreamCodec(packet);
|
||||
}
|
||||
|
||||
ByteBuf buffer = PacketContainer.createPacketBuffer();
|
||||
ByteBuf store = PacketContainer.createPacketBuffer();
|
||||
|
||||
@@ -115,44 +107,6 @@ public class WirePacket {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
private static byte[] bytesFromStreamCodec(PacketContainer packet) {
|
||||
// Spigot keeps the data of unknown custom payloads in a buffer and the codec reads from it,
|
||||
// so the reader index is restored to keep the packet writable after this call
|
||||
ByteBuf payloadData = getCustomPayloadData(packet);
|
||||
int readerIndex = payloadData != null ? payloadData.readerIndex() : 0;
|
||||
|
||||
try {
|
||||
ByteBuf buffer = (ByteBuf) packet.serializeToBuffer();
|
||||
return StreamSerializer.getDefault().getBytesAndRelease(buffer);
|
||||
} finally {
|
||||
if (payloadData != null) {
|
||||
payloadData.readerIndex(readerIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static ByteBuf getCustomPayloadData(PacketContainer packet) {
|
||||
PacketType type = packet.getType();
|
||||
if (type != PacketType.Play.Server.CUSTOM_PAYLOAD
|
||||
&& type != PacketType.Play.Client.CUSTOM_PAYLOAD
|
||||
&& type != PacketType.Configuration.Server.CUSTOM_PAYLOAD
|
||||
&& type != PacketType.Configuration.Client.CUSTOM_PAYLOAD) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Object payload = packet.getModifier()
|
||||
.withType(CustomPacketPayloadWrapper.getCustomPacketPayloadClass())
|
||||
.readSafely(0);
|
||||
if (payload == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
StructureModifier<ByteBuf> buffers = new StructureModifier<>(payload.getClass())
|
||||
.withTarget(payload)
|
||||
.withType(ByteBuf.class);
|
||||
return buffers.readSafely(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a WirePacket from an existing Minecraft packet
|
||||
*
|
||||
@@ -164,10 +118,6 @@ public class WirePacket {
|
||||
checkNotNull(packet, "packet cannot be null!");
|
||||
checkArgument(MinecraftReflection.isPacketClass(packet), "packet must be a Minecraft packet");
|
||||
|
||||
if (MinecraftVersion.v1_20_5.atOrAbove()) {
|
||||
return fromPacket(PacketContainer.fromPacket(packet));
|
||||
}
|
||||
|
||||
ByteBuf buffer = PacketContainer.createPacketBuffer();
|
||||
|
||||
MethodAccessor write = MinecraftMethods.getPacketWriteByteBufMethod();
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package com.comphenix.protocol.injector.netty.channel;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Protocol;
|
||||
import com.comphenix.protocol.events.NetworkMarker;
|
||||
import com.comphenix.protocol.injector.netty.Injector;
|
||||
import com.comphenix.protocol.injector.netty.WirePacket;
|
||||
import com.comphenix.protocol.injector.temporary.TemporaryPlayer;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
final class EmptyInjector implements Injector {
|
||||
|
||||
@@ -68,21 +68,16 @@ final class EmptyInjector implements Injector {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerName() {
|
||||
return this.player != null ? this.player.getName() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getPlayerUniqueId() {
|
||||
return this.player != null ? this.player.getUniqueId() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasValidPlayer() {
|
||||
return player != null && !(player instanceof TemporaryPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return false;
|
||||
|
||||
@@ -16,12 +16,9 @@ package com.comphenix.protocol.injector.netty.channel;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLogger;
|
||||
import com.comphenix.protocol.error.ErrorReporter;
|
||||
import com.comphenix.protocol.injector.ListenerManager;
|
||||
import com.comphenix.protocol.injector.netty.Injector;
|
||||
@@ -29,10 +26,12 @@ import com.comphenix.protocol.injector.temporary.TemporaryPlayerFactory;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftFields;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.google.common.collect.MapMaker;
|
||||
|
||||
import com.google.common.collect.MapMaker;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
/**
|
||||
* Represents an injector factory.
|
||||
@@ -85,12 +84,8 @@ public class InjectionFactory {
|
||||
|
||||
// try to get the injector using the player reference first
|
||||
Injector injector = this.playerLookup.get(player);
|
||||
if (injector == null) {
|
||||
injector = this.getTemporaryInjector(player);
|
||||
}
|
||||
|
||||
// check if we found an injector
|
||||
if (injector != null && !injector.isClosed()) {
|
||||
ProtocolLogger.log(player.getName() + " has a cached injector. Player valid: " + injector.hasValidPlayer());
|
||||
return injector;
|
||||
}
|
||||
|
||||
@@ -110,7 +105,10 @@ public class InjectionFactory {
|
||||
this.playerLookup.remove(injector.getPlayer());
|
||||
this.cacheInjector(player, injector);
|
||||
// re-set the player of the injection
|
||||
ProtocolLogger.log("Reusing existing injector and setting player to " + player.getName());
|
||||
injector.setPlayer(player);
|
||||
} else {
|
||||
ProtocolLogger.log(player.getName() + "'s channel already has an injector. Player valid: " + injector.hasValidPlayer());
|
||||
}
|
||||
} else {
|
||||
// construct a new injector as it seems like we have none yet
|
||||
|
||||
+13
-89
@@ -4,18 +4,13 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.PacketType.Protocol;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
@@ -33,7 +28,6 @@ import com.comphenix.protocol.injector.netty.WirePacket;
|
||||
import com.comphenix.protocol.injector.packet.PacketRegistry;
|
||||
import com.comphenix.protocol.injector.temporary.TemporaryPlayer;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyFieldContract;
|
||||
@@ -47,6 +41,8 @@ import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.EventLoop;
|
||||
import io.netty.util.AttributeKey;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class NettyChannelInjector implements Injector {
|
||||
|
||||
@@ -103,7 +99,6 @@ public class NettyChannelInjector implements Injector {
|
||||
|
||||
// information about the player belonging to this injector
|
||||
private String playerName;
|
||||
private UUID playerUniqueId;
|
||||
private Player player;
|
||||
|
||||
// lazy initialized fields, if we don't need them we don't bother about them
|
||||
@@ -119,10 +114,6 @@ public class NettyChannelInjector implements Injector {
|
||||
) {
|
||||
// bukkit stuff
|
||||
this.player = player;
|
||||
if (player != null && !(player instanceof TemporaryPlayer)) {
|
||||
this.playerName = player.getName();
|
||||
this.playerUniqueId = player.getUniqueId();
|
||||
}
|
||||
|
||||
// protocol lib stuff
|
||||
this.errorReporter = errorReporter;
|
||||
@@ -251,7 +242,7 @@ public class NettyChannelInjector implements Injector {
|
||||
this.uninject();
|
||||
|
||||
// remove any outgoing references
|
||||
this.channel.attr(INJECTOR).set(null);
|
||||
this.channel.attr(INJECTOR).remove();
|
||||
|
||||
// cleanup
|
||||
this.savedMarkers.clear();
|
||||
@@ -358,9 +349,8 @@ public class NettyChannelInjector implements Injector {
|
||||
|
||||
// check if the name of the player is already known to the injector
|
||||
if (this.playerName != null) {
|
||||
Player bukkitPlayer = Bukkit.getPlayerExact(this.playerName);
|
||||
if (bukkitPlayer != null) {
|
||||
this.player = bukkitPlayer;
|
||||
this.player = Bukkit.getPlayerExact(this.playerName);
|
||||
if (this.player != null) {
|
||||
this.injectionFactory.cacheInjector(this.player, this);
|
||||
}
|
||||
}
|
||||
@@ -369,28 +359,22 @@ public class NettyChannelInjector implements Injector {
|
||||
return this.player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPlayerName() {
|
||||
return this.playerName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID getPlayerUniqueId() {
|
||||
return this.playerUniqueId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPlayer(Player player) {
|
||||
this.injectionFactory.invalidate(this.player, this.playerName);
|
||||
|
||||
this.player = player;
|
||||
this.playerName = player.getName();
|
||||
this.playerUniqueId = player.getUniqueId();
|
||||
|
||||
this.injectionFactory.cacheInjector(player, this);
|
||||
this.injectionFactory.cacheInjector(player.getName(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasValidPlayer() {
|
||||
return this.player != null && !(player instanceof TemporaryPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isConnected() {
|
||||
return this.channel.isActive();
|
||||
@@ -440,19 +424,14 @@ public class NettyChannelInjector implements Injector {
|
||||
// process login packets for the player name
|
||||
if (packet.getType() == PacketType.Login.Client.START) {
|
||||
String username;
|
||||
UUID uniqueId;
|
||||
if (MinecraftVersion.WILD_UPDATE.atOrAbove()) {
|
||||
// 1.19 replaced the gameprofile with username and uuid field
|
||||
username = packet.getStrings().readSafely(0);
|
||||
uniqueId = readLoginUniqueId(packet);
|
||||
} else {
|
||||
WrappedGameProfile profile = packet.getGameProfiles().readSafely(0);
|
||||
username = profile != null ? profile.getName() : null;
|
||||
uniqueId = profile != null ? profile.getUUID() : null;
|
||||
}
|
||||
|
||||
this.playerUniqueId = uniqueId;
|
||||
|
||||
if (username != null) {
|
||||
this.playerName = username;
|
||||
this.injectionFactory.cacheInjector(username, this);
|
||||
@@ -467,22 +446,6 @@ public class NettyChannelInjector implements Injector {
|
||||
}
|
||||
}
|
||||
|
||||
private static UUID readLoginUniqueId(PacketContainer packet) {
|
||||
UUID uniqueId = packet.getUUIDs().readSafely(0);
|
||||
if (uniqueId != null) {
|
||||
return uniqueId;
|
||||
}
|
||||
|
||||
StructureModifier<Optional> optionals = packet.getModifier().withType(Optional.class);
|
||||
for (int i = 0; i < optionals.size(); i++) {
|
||||
Optional<?> optional = optionals.readSafely(i);
|
||||
if (optional != null && optional.orElse(null) instanceof UUID optionalUniqueId) {
|
||||
return optionalUniqueId;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void processInboundInternal(ChannelHandlerContext ctx, PacketContainer packetContainer) {
|
||||
if (this.listenerManager.hasMainThreadListener(packetContainer.getType()) && !Bukkit.isPrimaryThread()) {
|
||||
// not on the main thread but we are required to be reschedule the packet on the
|
||||
@@ -556,16 +519,15 @@ public class NettyChannelInjector implements Injector {
|
||||
return action;
|
||||
}
|
||||
|
||||
PacketContainer packetContainer = new PacketContainer(packetType, packet);
|
||||
|
||||
// ensure that we are on the main thread if we need to
|
||||
if (!Bukkit.isPrimaryThread() && hasMainThreadListener(this.listenerManager, protocol, packetContainer)) {
|
||||
if (this.listenerManager.hasMainThreadListener(packetType) && !Bukkit.isPrimaryThread()) {
|
||||
// not on the main thread but we are required to be - re-schedule the packet on the main thread
|
||||
ProtocolLibrary.getScheduler().runTask(() -> this.sendClientboundPacket(packet, marker, true));
|
||||
ProtocolLibrary.getScheduler().runTask(() -> this.sendClientboundPacket(packet, null, true));
|
||||
return null;
|
||||
}
|
||||
|
||||
// create event and invoke listeners
|
||||
PacketContainer packetContainer = new PacketContainer(packetType, packet);
|
||||
PacketEvent event = PacketEvent.fromServer(this, packetContainer, marker, this.player);
|
||||
this.listenerManager.invokeOutboundPacketListeners(event);
|
||||
|
||||
@@ -595,44 +557,6 @@ public class NettyChannelInjector implements Injector {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a listener that must be called on the main thread is going to be invoked for the given outbound packet.
|
||||
* The packets inside a bundle are posted to their listeners together with the bundle, so their listeners count for
|
||||
* the bundle as well.
|
||||
*
|
||||
* @param listenerManager the listener manager holding the registered listeners.
|
||||
* @param protocol the current outbound protocol of the connection.
|
||||
* @param packet the outbound packet.
|
||||
* @return true if the packet must be processed on the main thread, false otherwise.
|
||||
*/
|
||||
static boolean hasMainThreadListener(ListenerManager listenerManager, Protocol protocol, PacketContainer packet) {
|
||||
if (listenerManager.hasMainThreadListener(packet.getType())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (packet.getType() != PacketType.Play.Server.BUNDLE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Iterable<?> subPackets = packet.getModifier().<Iterable<?>>withType(Iterable.class).readSafely(0);
|
||||
if (subPackets == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Object subPacket : subPackets) {
|
||||
if (subPacket == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PacketType subPacketType = PacketRegistry.getPacketType(protocol, subPacket.getClass());
|
||||
if (subPacketType != null && listenerManager.hasMainThreadListener(subPacketType)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T> T proxyAction(T action, PacketEvent event, NetworkMarker marker) {
|
||||
// hack - we only know that the given action is either a runnable or callable, but we need to work out which thing
|
||||
|
||||
@@ -5,7 +5,6 @@ import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelConfig;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelId;
|
||||
import io.netty.channel.ChannelMetadata;
|
||||
import io.netty.channel.ChannelPipeline;
|
||||
import io.netty.channel.ChannelProgressivePromise;
|
||||
@@ -34,11 +33,6 @@ final class NettyChannelProxy implements Channel {
|
||||
this.injector = injector;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelId id() {
|
||||
return this.delegate.id();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EventLoop eventLoop() {
|
||||
return this.eventLoop;
|
||||
@@ -244,11 +238,6 @@ final class NettyChannelProxy implements Channel {
|
||||
return this.delegate.attr(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> boolean hasAttr(AttributeKey<T> attributeKey) {
|
||||
return this.delegate.hasAttr(attributeKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull Channel o) {
|
||||
return this.delegate.compareTo(o);
|
||||
|
||||
+1
-18
@@ -10,13 +10,11 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import io.netty.channel.AbstractEventLoop;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelPromise;
|
||||
import io.netty.channel.EventLoop;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.util.concurrent.AbstractEventExecutor;
|
||||
import io.netty.util.concurrent.EventExecutor;
|
||||
import io.netty.util.concurrent.Future;
|
||||
import io.netty.util.concurrent.ProgressivePromise;
|
||||
@@ -27,7 +25,7 @@ import io.netty.util.concurrent.ScheduledFuture;
|
||||
* An abstract event loop implementation which delegates all calls to a given event loop, but proxies all calls which
|
||||
* schedule something on the event loop to methods which decide what should happen to the scheduled task.
|
||||
*/
|
||||
final class NettyEventLoopProxy extends AbstractEventLoop {
|
||||
final class NettyEventLoopProxy implements EventLoop {
|
||||
|
||||
private static final Callable<?> EMPTY_CALLABLE = () -> null;
|
||||
private static final Runnable EMPTY_RUNNABLE = () -> {
|
||||
@@ -238,15 +236,6 @@ final class NettyEventLoopProxy extends AbstractEventLoop {
|
||||
}
|
||||
}
|
||||
|
||||
// ShreddedPaper uses this method
|
||||
@Override
|
||||
public void lazyExecute(Runnable command) {
|
||||
Runnable proxied = this.proxyRunnable(command);
|
||||
if (proxied != null) {
|
||||
((AbstractEventExecutor)this.delegate).lazyExecute(proxied);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forEach(Consumer<? super EventExecutor> action) {
|
||||
this.delegate.forEach(action);
|
||||
@@ -262,12 +251,6 @@ final class NettyEventLoopProxy extends AbstractEventLoop {
|
||||
return this.delegate.register(channel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelFuture register(ChannelPromise channelPromise) {
|
||||
return this.delegate.register(channelPromise);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public ChannelFuture register(Channel channel, ChannelPromise promise) {
|
||||
return this.delegate.register(channel, promise);
|
||||
|
||||
+7
-45
@@ -7,15 +7,11 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLogger;
|
||||
import com.comphenix.protocol.error.ErrorReporter;
|
||||
import com.comphenix.protocol.injector.ListenerManager;
|
||||
import com.comphenix.protocol.injector.netty.Injector;
|
||||
import com.comphenix.protocol.injector.netty.channel.InjectionFactory;
|
||||
import com.comphenix.protocol.internal.PlatformProvider;
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
||||
@@ -26,7 +22,8 @@ import com.comphenix.protocol.wrappers.Pair;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
public class NetworkManagerInjector {
|
||||
|
||||
@@ -39,9 +36,7 @@ public class NetworkManagerInjector {
|
||||
private final InjectionFactory injectionFactory;
|
||||
|
||||
// netty handler
|
||||
private final InjectionChannelInboundHandler injectionHandler;
|
||||
private final InjectionChannelInitializer pipelineInjectorHandler;
|
||||
private Runnable paperChannelInitializerCleanup;
|
||||
|
||||
// status of this injector
|
||||
private boolean closed = false;
|
||||
@@ -52,20 +47,18 @@ public class NetworkManagerInjector {
|
||||
this.injectionFactory = new InjectionFactory(plugin, reporter, listenerManager);
|
||||
|
||||
// hooking netty handlers
|
||||
this.injectionHandler = new InjectionChannelInboundHandler(
|
||||
InjectionChannelInboundHandler injectionHandler = new InjectionChannelInboundHandler(
|
||||
this.errorReporter,
|
||||
this.injectionFactory);
|
||||
this.pipelineInjectorHandler = new InjectionChannelInitializer(
|
||||
INBOUND_INJECT_HANDLER_NAME,
|
||||
this.injectionHandler);
|
||||
this.pipelineInjectorHandler = new InjectionChannelInitializer(INBOUND_INJECT_HANDLER_NAME, injectionHandler);
|
||||
}
|
||||
|
||||
public Injector getInjector(Player player) {
|
||||
return this.injectionFactory.fromPlayer(player);
|
||||
}
|
||||
|
||||
public boolean isUsingPaperChannelInitializer() {
|
||||
return this.paperChannelInitializerCleanup != null;
|
||||
public Injector getInjector(Channel channel) {
|
||||
return injectionFactory.fromChannel(channel);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -74,13 +67,6 @@ public class NetworkManagerInjector {
|
||||
return;
|
||||
}
|
||||
|
||||
PlatformProvider platformProvider = PlatformProvider.get();
|
||||
if (platformProvider.hasEarlyChannelInitialization()) {
|
||||
this.paperChannelInitializerCleanup = platformProvider.registerChannelInitializer(this::injectChannel);
|
||||
this.injected = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// get all "server connections" defined in the minecraft server class
|
||||
FuzzyReflection server = FuzzyReflection.fromClass(MinecraftReflection.getMinecraftServerClass());
|
||||
List<Method> serverConnectionGetter = server.getMethodList(FuzzyMethodContract.newBuilder()
|
||||
@@ -143,23 +129,6 @@ public class NetworkManagerInjector {
|
||||
this.injected = true;
|
||||
}
|
||||
|
||||
private void injectChannel(Channel channel) {
|
||||
addInjectionHandler(channel, MinecraftReflection.getNetworkManagerClass(), this.injectionHandler);
|
||||
}
|
||||
|
||||
static void addInjectionHandler(Channel channel, Class<?> networkManagerClass, ChannelHandler injectionHandler) {
|
||||
for (String handlerName : channel.pipeline().names()) {
|
||||
ChannelHandler handler = channel.pipeline().get(handlerName);
|
||||
if (networkManagerClass.isInstance(handler)) {
|
||||
channel.pipeline().addBefore(handlerName, INBOUND_INJECT_HANDLER_NAME, injectionHandler);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Preserve the existing behavior for forks with an unexpected pipeline layout.
|
||||
channel.pipeline().addLast(INBOUND_INJECT_HANDLER_NAME, injectionHandler);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (this.closed || !this.injected) {
|
||||
return;
|
||||
@@ -188,13 +157,6 @@ public class NetworkManagerInjector {
|
||||
|
||||
// clear up
|
||||
this.overriddenLists.clear();
|
||||
try {
|
||||
if (this.paperChannelInitializerCleanup != null) {
|
||||
this.paperChannelInitializerCleanup.run();
|
||||
}
|
||||
} finally {
|
||||
this.paperChannelInitializerCleanup = null;
|
||||
this.injectionFactory.close();
|
||||
}
|
||||
this.injectionFactory.close();
|
||||
}
|
||||
}
|
||||
@@ -412,8 +412,8 @@ public class PacketRegistry {
|
||||
private static Class<?> searchForPacket(List<String> classNames) {
|
||||
for (String name : classNames) {
|
||||
try {
|
||||
Class<?> clazz = resolvePacketClassName(name);
|
||||
if (clazz != null && MinecraftReflection.getPacketClass().isAssignableFrom(clazz)
|
||||
Class<?> clazz = MinecraftReflection.getMinecraftClass(name);
|
||||
if (MinecraftReflection.getPacketClass().isAssignableFrom(clazz)
|
||||
&& !Modifier.isAbstract(clazz.getModifiers())) {
|
||||
return clazz;
|
||||
}
|
||||
@@ -424,22 +424,6 @@ public class PacketRegistry {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a single packet class name. Fully-qualified names (those already containing their
|
||||
* package, e.g. {@code net.minecraft.network.protocol.game.XPacket}) are loaded directly, since
|
||||
* {@link MinecraftReflection#getMinecraftClass(String)} would otherwise prepend the Minecraft
|
||||
* package and fail to find them. Relative names continue to be resolved against the Minecraft
|
||||
* package.
|
||||
*/
|
||||
private static Class<?> resolvePacketClassName(String name) {
|
||||
Optional<Class<?>> direct = MinecraftReflection.getOptionalClass(name);
|
||||
if (direct.isPresent()) {
|
||||
return direct.get();
|
||||
}
|
||||
|
||||
return MinecraftReflection.getMinecraftClass(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the correct packet class from a given type.
|
||||
*
|
||||
|
||||
+2
-14
@@ -19,7 +19,6 @@ package com.comphenix.protocol.injector.temporary;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -133,16 +132,7 @@ public class TemporaryPlayerFactory {
|
||||
if (methodName.equals("isOnline")) {
|
||||
return injector.isConnected();
|
||||
} else if (methodName.equals("getName")) {
|
||||
String playerName = injector.getPlayerName();
|
||||
if (playerName != null) {
|
||||
return playerName;
|
||||
}
|
||||
return "UNKNOWN[" + injector.getAddress() + "]";
|
||||
} else if (methodName.equals("getUniqueId")) {
|
||||
UUID playerUniqueId = injector.getPlayerUniqueId();
|
||||
if (playerUniqueId != null) {
|
||||
return playerUniqueId;
|
||||
}
|
||||
}
|
||||
|
||||
// Ignore all other methods
|
||||
@@ -194,16 +184,14 @@ public class TemporaryPlayerFactory {
|
||||
* <li>getPlayer()</li>
|
||||
* <li>getAddress()</li>
|
||||
* <li>getServer()</li>
|
||||
* <li>getName()</li>
|
||||
* <li>getUniqueId(), when supplied by the login protocol</li>
|
||||
* <li>chat(String)</li>
|
||||
* <li>sendMessage(String)</li>
|
||||
* <li>sendMessage(String[])</li>
|
||||
* <li>kickPlayer(String)</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* Before the login start packet is received, the player has no profile information
|
||||
* and can only be identified by its address.
|
||||
* Note that a temporary player has not yet been assigned a name, and thus cannot be
|
||||
* uniquely identified. Use the address instead.
|
||||
*
|
||||
* @return A temporary player instance.
|
||||
*/
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
package com.comphenix.protocol.internal;
|
||||
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLib;
|
||||
|
||||
import io.netty.channel.Channel;
|
||||
|
||||
public interface PlatformProvider {
|
||||
|
||||
static PlatformProvider get() {
|
||||
return Holder.INSTANCE;
|
||||
}
|
||||
|
||||
boolean hasEarlyChannelInitialization();
|
||||
|
||||
Runnable registerChannelInitializer(Consumer<Channel> channelInitializer);
|
||||
|
||||
void registerCommand(ProtocolLib plugin, String name, CommandExecutor executor);
|
||||
|
||||
final class Holder {
|
||||
|
||||
private static final PlatformProvider INSTANCE = ServiceLoader.load(
|
||||
PlatformProvider.class,
|
||||
PlatformProvider.class.getClassLoader())
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalStateException("No ProtocolLib platform provider is available"));
|
||||
|
||||
private Holder() {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,8 +90,6 @@ public class StructureModifier<T> {
|
||||
protected Map<FieldAccessor, Integer> defaultFields;
|
||||
// Cache of previous types
|
||||
protected Map<Class<?>, StructureModifier<?>> subtypeCache;
|
||||
// Cache of previous parameterized types
|
||||
private Map<List<Type>, StructureModifier<?>> paramTypeCache = new HashMap<>();
|
||||
|
||||
// Whether or subclasses should handle conversion
|
||||
protected boolean customConvertHandling;
|
||||
@@ -203,7 +201,6 @@ public class StructureModifier<T> {
|
||||
other.defaultFields,
|
||||
other.converter,
|
||||
other.subtypeCache);
|
||||
this.paramTypeCache = other.paramTypeCache;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -534,18 +531,8 @@ public class StructureModifier<T> {
|
||||
return (StructureModifier<R>) NO_OP_MODIFIER;
|
||||
}
|
||||
|
||||
// parameterized lookups must not share a cache entry with the raw field type
|
||||
List<Type> paramTypeKey = null;
|
||||
if (paramTypes.length > 0) {
|
||||
paramTypeKey = new ArrayList<>(paramTypes.length + 1);
|
||||
paramTypeKey.add(fieldType);
|
||||
paramTypeKey.addAll(Arrays.asList(paramTypes));
|
||||
}
|
||||
|
||||
// Do we need to update the cache?
|
||||
StructureModifier<R> result = (StructureModifier<R>) (paramTypeKey == null
|
||||
? this.subtypeCache.get(fieldType)
|
||||
: this.paramTypeCache.get(paramTypeKey));
|
||||
StructureModifier<R> result = (StructureModifier<R>) this.subtypeCache.get(fieldType);
|
||||
if (result == null) {
|
||||
List<FieldAccessor> fields = new ArrayList<>();
|
||||
Map<FieldAccessor, Integer> defaults = new HashMap<>();
|
||||
@@ -584,11 +571,7 @@ public class StructureModifier<T> {
|
||||
|
||||
// Cache structure modifiers
|
||||
result = this.withFieldType(fieldType, fields, defaults);
|
||||
if (paramTypeKey == null) {
|
||||
this.subtypeCache.put(fieldType, result);
|
||||
} else {
|
||||
this.paramTypeCache.put(paramTypeKey, result);
|
||||
}
|
||||
this.subtypeCache.put(fieldType, result);
|
||||
}
|
||||
|
||||
// Add the target too
|
||||
|
||||
@@ -63,7 +63,6 @@ public class ImmutableDetector implements Cloner {
|
||||
add(MinecraftReflection::getBlockClass);
|
||||
add(MinecraftReflection::getItemClass);
|
||||
add(MinecraftReflection::getSoundEffectClass);
|
||||
add(MinecraftReflection::getWorldTypeClass);
|
||||
|
||||
if (MinecraftVersion.AQUATIC_UPDATE.atOrAbove()) {
|
||||
add(MinecraftReflection::getFluidTypeClass);
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/**
|
||||
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
||||
* Copyright (C) 2015 dmulloy2
|
||||
* <p>
|
||||
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
||||
* GNU General Public License as published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
* <p>
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details.
|
||||
* <p>
|
||||
* You should have received a copy of the GNU General Public License along with this program;
|
||||
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
* 02111-1307 USA
|
||||
*/
|
||||
package com.comphenix.protocol.updater;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.error.Report;
|
||||
|
||||
/**
|
||||
* Update check worker (top-level class so the runtime always loads a single {@code .class} entry).
|
||||
*/
|
||||
final class SpigotUpdateRunnable implements Runnable {
|
||||
|
||||
private final SpigotUpdater updater;
|
||||
|
||||
SpigotUpdateRunnable(SpigotUpdater updater) {
|
||||
this.updater = updater;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String version = this.updater.getSpigotVersion();
|
||||
this.updater.setRemoteVersion(version);
|
||||
|
||||
if (this.updater.versionCheck(version)) {
|
||||
this.updater.result = Updater.UpdateResult.SPIGOT_UPDATE_AVAILABLE;
|
||||
} else {
|
||||
this.updater.result = Updater.UpdateResult.NO_UPDATE;
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
if (ProtocolLibrary.getConfig().isDebug()) {
|
||||
ProtocolLibrary.getErrorReporter().reportDetailed(
|
||||
this.updater,
|
||||
Report.newBuilder(Updater.REPORT_CANNOT_UPDATE_PLUGIN).error(ex).callerParam(this));
|
||||
}
|
||||
|
||||
ProtocolLibrary.disableUpdates();
|
||||
} finally {
|
||||
for (Runnable listener : this.updater.listeners) {
|
||||
ProtocolLibrary.getScheduler().runTask(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@
|
||||
*/
|
||||
package com.comphenix.protocol.updater;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.error.Report;
|
||||
import com.comphenix.protocol.utility.Closer;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
@@ -42,7 +44,7 @@ public final class SpigotUpdater extends Updater {
|
||||
waitForThread();
|
||||
|
||||
this.type = type;
|
||||
this.thread = new Thread(new SpigotUpdateRunnable(this));
|
||||
this.thread = new Thread(new SpigotUpdateRunnable());
|
||||
this.thread.start();
|
||||
}
|
||||
|
||||
@@ -52,8 +54,36 @@ public final class SpigotUpdater extends Updater {
|
||||
return String.format(result.toString(), remoteVersion, plugin.getDescription().getVersion(), RESOURCE_URL);
|
||||
}
|
||||
|
||||
void setRemoteVersion(String remoteVersion) {
|
||||
this.remoteVersion = remoteVersion;
|
||||
private class SpigotUpdateRunnable implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String version = getSpigotVersion();
|
||||
remoteVersion = version;
|
||||
|
||||
if (versionCheck(version)) {
|
||||
result = UpdateResult.SPIGOT_UPDATE_AVAILABLE;
|
||||
} else {
|
||||
result = UpdateResult.NO_UPDATE;
|
||||
}
|
||||
} catch (Throwable ex) {
|
||||
if (ProtocolLibrary.getConfig().isDebug()) {
|
||||
ProtocolLibrary.getErrorReporter().reportDetailed(
|
||||
SpigotUpdater.this, Report.newBuilder(REPORT_CANNOT_UPDATE_PLUGIN).error(ex).callerParam(this));
|
||||
} else {
|
||||
// People don't care
|
||||
// plugin.getLogger().log(Level.WARNING, "Failed to check for updates: " + ex);
|
||||
}
|
||||
|
||||
ProtocolLibrary.disableUpdates();
|
||||
} finally {
|
||||
// Invoke the listeners on the main thread
|
||||
for (Runnable listener : listeners) {
|
||||
ProtocolLibrary.getScheduler().runTask(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final String RESOURCE_URL = "https://www.spigotmc.org/resources/protocollib.1997/";
|
||||
|
||||
@@ -88,23 +88,20 @@ final class CachedPackage {
|
||||
* @throws RuntimeException If we are unable to find the given class.
|
||||
*/
|
||||
public Optional<Class<?>> getPackageClass(String className, String... aliases) {
|
||||
Optional<Class<?>> cached = cache.get(className);
|
||||
if (cached != null) {
|
||||
return cached;
|
||||
}
|
||||
return cache.computeIfAbsent(className, x -> {
|
||||
Optional<Class<?>> clazz = resolveClass(className);
|
||||
if (clazz.isPresent()) {
|
||||
return clazz;
|
||||
}
|
||||
|
||||
Optional<Class<?>> clazz = resolveClass(className);
|
||||
if (!clazz.isPresent()) {
|
||||
for (String alias : aliases) {
|
||||
Optional<Class<?>> aliasClazz = resolveClass(alias);
|
||||
if (aliasClazz.isPresent()) {
|
||||
clazz = aliasClazz;
|
||||
break;
|
||||
clazz = resolveClass(alias);
|
||||
if (clazz.isPresent()) {
|
||||
return clazz;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cache.put(className, clazz);
|
||||
return clazz;
|
||||
return Optional.empty();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -57,25 +57,21 @@ public final class MinecraftMethods {
|
||||
}
|
||||
|
||||
public static Function<ByteBuf, Object> getFriendlyBufBufConstructor() {
|
||||
if (friendlyBufBufConstructor == null) {
|
||||
Optional<Class<?>> registryByteBuf = MinecraftReflection.getRegistryFriendlyByteBufClass();
|
||||
|
||||
if (registryByteBuf.isPresent()) {
|
||||
ConstructorAccessor accessor = Accessors.getConstructorAccessor(
|
||||
FuzzyReflection.fromClass(registryByteBuf.get()).getConstructor(
|
||||
FuzzyMethodContract.newBuilder()
|
||||
.parameterExactType(ByteBuf.class, 0)
|
||||
.parameterExactType(MinecraftReflection.getRegistryAccessClass(), 1)
|
||||
.build()));
|
||||
friendlyBufBufConstructor = byteBuf -> accessor.invoke(byteBuf, MinecraftRegistryAccess.get());
|
||||
} else {
|
||||
ConstructorAccessor accessor = Accessors.getConstructorAccessor(
|
||||
MinecraftReflection.getPacketDataSerializerClass(),
|
||||
ByteBuf.class);
|
||||
friendlyBufBufConstructor = byteBuf -> accessor.invoke(byteBuf);
|
||||
}
|
||||
}
|
||||
return friendlyBufBufConstructor;
|
||||
if (friendlyBufBufConstructor == null) {
|
||||
Optional<Class<?>> registryByteBuf = MinecraftReflection.getRegistryFriendlyByteBufClass();
|
||||
|
||||
if (registryByteBuf.isPresent()) {
|
||||
ConstructorAccessor accessor = Accessors.getConstructorAccessor(FuzzyReflection.fromClass(registryByteBuf.get()).getConstructor(FuzzyMethodContract.newBuilder()
|
||||
.parameterDerivedOf(ByteBuf.class)
|
||||
.parameterDerivedOf(MinecraftReflection.getRegistryAccessClass())
|
||||
.build()));
|
||||
friendlyBufBufConstructor = (byteBuf) -> accessor.invoke(byteBuf, MinecraftRegistryAccess.get());
|
||||
} else {
|
||||
ConstructorAccessor accessor = Accessors.getConstructorAccessor(MinecraftReflection.getPacketDataSerializerClass(), ByteBuf.class);
|
||||
friendlyBufBufConstructor = (byteBuf) -> accessor.invoke(byteBuf);
|
||||
}
|
||||
}
|
||||
return friendlyBufBufConstructor;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -96,12 +96,6 @@ public final class MinecraftProtocolVersion {
|
||||
map.put(new MinecraftVersion(1, 21, 2), 768);
|
||||
map.put(new MinecraftVersion(1, 21, 6), 771);
|
||||
map.put(new MinecraftVersion(1, 21, 8), 772);
|
||||
map.put(new MinecraftVersion(1, 21, 9), 773);
|
||||
map.put(new MinecraftVersion(1, 21, 11), 774);
|
||||
|
||||
map.put(new MinecraftVersion(26, 1, 0), 775);
|
||||
map.put(new MinecraftVersion(26, 2, 0), 776);
|
||||
map.put(new MinecraftVersion(26, 3, 0), 777);
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
@@ -553,10 +553,6 @@ public final class MinecraftReflection {
|
||||
return getClass("com.mojang.authlib.GameProfile");
|
||||
}
|
||||
|
||||
public static Class<?> getGameProfilePropertyMapClass() {
|
||||
return getClass("com.mojang.authlib.properties.PropertyMap");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the entity (NMS) class.
|
||||
*
|
||||
@@ -921,19 +917,15 @@ public final class MinecraftReflection {
|
||||
}
|
||||
|
||||
public static Class<?> getMinecraftKeyClass() {
|
||||
return getMinecraftClass("resources.MinecraftKey", "resources.Identifier", "resources.ResourceLocation", "MinecraftKey");
|
||||
return getMinecraftClass("resources.MinecraftKey", "resources.ResourceLocation", "MinecraftKey");
|
||||
}
|
||||
|
||||
public static Class<?> getMobEffectListClass() {
|
||||
return getMinecraftClass("world.effect.MobEffectList", "MobEffectList", "world.effect.MobEffect", "world.effect.MobEffects");
|
||||
}
|
||||
|
||||
public static Class<?> getDamageTypeClass() {
|
||||
return getMinecraftClass("world.damagesource.DamageType");
|
||||
return getMinecraftClass("world.effect.MobEffectList", "MobEffectList", "world.effect.MobEffect");
|
||||
}
|
||||
|
||||
public static Class<?> getSoundEffectClass() {
|
||||
return getNullableNMS("sounds.SoundEffect", "sounds.SoundEvent", "SoundEffect", "sounds.SoundEvents");
|
||||
return getNullableNMS("sounds.SoundEffect", "sounds.SoundEvent", "SoundEffect");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1122,15 +1114,6 @@ public final class MinecraftReflection {
|
||||
return getOptionalNMS("network.chat.numbers.StyledFormat");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the NMS TeamColor class, added in 26.2.
|
||||
*
|
||||
* @return The TeamColor class.
|
||||
*/
|
||||
public static Optional<Class<?>> getTeamColorClass() {
|
||||
return getOptionalNMS("world.scores.TeamColor");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the Gson class used by Minecraft.
|
||||
*
|
||||
@@ -1430,13 +1413,8 @@ public final class MinecraftReflection {
|
||||
try {
|
||||
Method asMirrorMethod = getCraftItemStackClass().getMethod("asCraftMirror", getItemStackClass());
|
||||
asCraftMirror = Accessors.getMethodAccessor(asMirrorMethod);
|
||||
} catch (ReflectiveOperationException ex1) {
|
||||
try {
|
||||
Method asMirrorMethod = getCraftItemStackClass().getMethod("asBukkitMirror", getItemStackClass());
|
||||
asCraftMirror = Accessors.getMethodAccessor(asMirrorMethod);
|
||||
} catch (ReflectiveOperationException ex2) {
|
||||
throw new RuntimeException("Failed to obtain CraftItemStack.asCraftMirror", ex2);
|
||||
}
|
||||
} catch (ReflectiveOperationException ex) {
|
||||
throw new RuntimeException("Failed to obtain CraftItemStack.asCraftMirror", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1498,18 +1476,6 @@ public final class MinecraftReflection {
|
||||
.orElseThrow(() -> new RuntimeException("Cannot find class " + className));
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to load a class by its fully-qualified canonical name, without prepending the
|
||||
* Minecraft package. Unlike {@link #getMinecraftClass(String)}, this can resolve names that
|
||||
* already include their package (e.g. {@code net.minecraft.network.protocol.game.XPacket}).
|
||||
*
|
||||
* @param className - the fully-qualified class name.
|
||||
* @return Optional that may contain the class.
|
||||
*/
|
||||
public static Optional<Class<?>> getOptionalClass(String className) {
|
||||
return getClassSource().loadClass(className);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the class object of a specific CraftBukkit class.
|
||||
*
|
||||
@@ -1714,7 +1680,7 @@ public final class MinecraftReflection {
|
||||
}
|
||||
|
||||
public static Class<?> getEntityTypes() {
|
||||
return getMinecraftClass("world.entity.EntityType", "world.entity.EntityTypes", "EntityTypes");
|
||||
return getMinecraftClass("world.entity.EntityTypes", "world.entity.EntityType", "EntityTypes");
|
||||
}
|
||||
|
||||
public static Class<?> getParticleParam() {
|
||||
@@ -1934,30 +1900,15 @@ public final class MinecraftReflection {
|
||||
return isMojangMapped;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the PositionMoveRotation class (introduced in 1.21.2).
|
||||
*
|
||||
* @return The PositionMoveRotation class.
|
||||
*/
|
||||
public static Class<?> getPositionMoveRotationClass() {
|
||||
return getMinecraftClass("world.entity.PositionMoveRotation");
|
||||
public static Optional<Class<?>> getDataComponentMapClass() {
|
||||
return getOptionalNMS("core.component.DataComponentMap");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the VecDelta class (since 26.3).
|
||||
*
|
||||
* @return The VecDelta class.
|
||||
*/
|
||||
public static Optional<Class<?>> getVecDeltaClass() {
|
||||
return getOptionalNMS("network.protocol.game.VecDelta");
|
||||
public static Optional<Class<?>> getDataComponentHolderClass() {
|
||||
return getOptionalNMS("core.component.DataComponentHolder");
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the PositionPath class (since 26.3).
|
||||
*
|
||||
* @return The PositionPath class.
|
||||
*/
|
||||
public static Optional<Class<?>> getPositionPathClass() {
|
||||
return getOptionalNMS("world.entity.PositionPath");
|
||||
public static Optional<Class<?>> getTypedDataComponentClass() {
|
||||
return getOptionalNMS("core.component.TypedDataComponent");
|
||||
}
|
||||
}
|
||||
@@ -36,36 +36,6 @@ import org.bukkit.Server;
|
||||
* @author Kristian
|
||||
*/
|
||||
public final class MinecraftVersion implements Comparable<MinecraftVersion>, Serializable {
|
||||
/**
|
||||
* Version 26.3 - wilderness bound
|
||||
*/
|
||||
public static final MinecraftVersion v26_3 = new MinecraftVersion("26.3");
|
||||
|
||||
/**
|
||||
* Version 26.2 - chaos cubed
|
||||
*/
|
||||
public static final MinecraftVersion v26_2 = new MinecraftVersion("26.2");
|
||||
|
||||
/**
|
||||
* Version 26.1 - tiny takeover
|
||||
*/
|
||||
public static final MinecraftVersion v26_1 = new MinecraftVersion("26.1");
|
||||
|
||||
/**
|
||||
* Version 1.21.11 - mounts of mayhem
|
||||
*/
|
||||
public static final MinecraftVersion v1_21_11 = new MinecraftVersion("1.21.11");
|
||||
|
||||
/**
|
||||
* Version 1.21.10 - hotfix for 1.21.9
|
||||
*/
|
||||
public static final MinecraftVersion v1_21_10 = new MinecraftVersion("1.21.10");
|
||||
|
||||
/**
|
||||
* Version 1.21.9 - the copper age drop
|
||||
*/
|
||||
public static final MinecraftVersion v1_21_9 = new MinecraftVersion("1.21.9");
|
||||
|
||||
/**
|
||||
* Version 1.21.6 - chase the skies
|
||||
*/
|
||||
@@ -199,7 +169,7 @@ public final class MinecraftVersion implements Comparable<MinecraftVersion>, Ser
|
||||
/**
|
||||
* The latest release version of minecraft.
|
||||
*/
|
||||
public static final MinecraftVersion LATEST = v26_3;
|
||||
public static final MinecraftVersion LATEST = v1_21_6;
|
||||
|
||||
// used when serializing
|
||||
private static final long serialVersionUID = -8695133558996459770L;
|
||||
|
||||
@@ -326,9 +326,15 @@ public class StreamSerializer {
|
||||
|
||||
public byte[] getBytesAndRelease(ByteBuf buf) {
|
||||
try {
|
||||
byte[] bytes = new byte[buf.readableBytes()];
|
||||
buf.getBytes(buf.readerIndex(), bytes);
|
||||
return bytes;
|
||||
if (buf.hasArray()) {
|
||||
// heap buffer, we can access the array directly
|
||||
return buf.array();
|
||||
} else {
|
||||
// direct buffer, we need to copy the bytes into an array
|
||||
byte[] bytes = new byte[buf.readableBytes()];
|
||||
buf.readBytes(bytes);
|
||||
return bytes;
|
||||
}
|
||||
} finally {
|
||||
ReferenceCountUtil.safeRelease(buf);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.comphenix.protocol.utility;
|
||||
|
||||
public final class Validate {
|
||||
private Validate() {}
|
||||
|
||||
public static void notNull(Object obj, String err) {
|
||||
if (obj == null) {
|
||||
throw new IllegalArgumentException(err);
|
||||
}
|
||||
}
|
||||
|
||||
public static void isTrue(boolean bool, String err) {
|
||||
if (!bool) {
|
||||
throw new IllegalArgumentException(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.comphenix.protocol.utility;
|
||||
|
||||
public final class WordUtils {
|
||||
private WordUtils() {}
|
||||
|
||||
public static String capitalize(String str) {
|
||||
if (str == null || str.isEmpty()) {
|
||||
return str;
|
||||
}
|
||||
return str.substring(0, 1).toUpperCase() + str.substring(1).toLowerCase();
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,12 @@ package com.comphenix.protocol.utility;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.ByteBufAllocator;
|
||||
import io.netty.util.ByteProcessor;
|
||||
|
||||
import io.netty.buffer.ByteBufProcessor;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.nio.channels.GatheringByteChannel;
|
||||
import java.nio.channels.ScatteringByteChannel;
|
||||
import java.nio.charset.Charset;
|
||||
@@ -56,16 +54,6 @@ public class ZeroBuffer extends ByteBuf {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isReadOnly() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf asReadOnly() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readerIndex() {
|
||||
return 0;
|
||||
@@ -191,71 +179,36 @@ public class ZeroBuffer extends ByteBuf {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short getShortLE(int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUnsignedShort(int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUnsignedShortLE(int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMedium(int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMediumLE(int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUnsignedMedium(int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUnsignedMediumLE(int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInt(int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntLE(int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUnsignedInt(int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getUnsignedIntLE(int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLong(int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getLongLE(int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char getChar(int i) {
|
||||
return 0;
|
||||
@@ -311,16 +264,6 @@ public class ZeroBuffer extends ByteBuf {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBytes(int i, FileChannel fileChannel, long l, int i1) throws IOException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getCharSequence(int i, int i1, Charset charset) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf setBoolean(int i, boolean b) {
|
||||
return null;
|
||||
@@ -336,41 +279,21 @@ public class ZeroBuffer extends ByteBuf {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf setShortLE(int i, int i1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf setMedium(int i, int i1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf setMediumLE(int i, int i1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf setInt(int i, int i1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf setIntLE(int i, int i1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf setLong(int i, long l) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf setLongLE(int i, long l) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf setChar(int i, int i1) {
|
||||
return null;
|
||||
@@ -426,21 +349,11 @@ public class ZeroBuffer extends ByteBuf {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int setBytes(int i, FileChannel fileChannel, long l, int i1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf setZero(int i, int i1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int setCharSequence(int i, CharSequence charSequence, Charset charset) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readBoolean() {
|
||||
return false;
|
||||
@@ -461,71 +374,36 @@ public class ZeroBuffer extends ByteBuf {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public short readShortLE() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readUnsignedShort() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readUnsignedShortLE() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readMedium() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readMediumLE() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readUnsignedMedium() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readUnsignedMediumLE() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readInt() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readIntLE() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readUnsignedInt() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readUnsignedIntLE() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readLong() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long readLongLE() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char readChar() {
|
||||
return 0;
|
||||
@@ -551,11 +429,6 @@ public class ZeroBuffer extends ByteBuf {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf readRetainedSlice(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf readBytes(ByteBuf byteBuf) {
|
||||
return null;
|
||||
@@ -596,16 +469,6 @@ public class ZeroBuffer extends ByteBuf {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence readCharSequence(int i, Charset charset) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readBytes(FileChannel fileChannel, long l, int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf skipBytes(int i) {
|
||||
return null;
|
||||
@@ -626,41 +489,21 @@ public class ZeroBuffer extends ByteBuf {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf writeShortLE(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf writeMedium(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf writeMediumLE(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf writeInt(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf writeIntLE(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf writeLong(long l) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf writeLongLE(long l) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf writeChar(int i) {
|
||||
return null;
|
||||
@@ -716,21 +559,11 @@ public class ZeroBuffer extends ByteBuf {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int writeBytes(FileChannel fileChannel, long l, int i) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf writeZero(int i) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int writeCharSequence(CharSequence charSequence, Charset charset) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int indexOf(int i, int i1, byte b) {
|
||||
return 0;
|
||||
@@ -752,22 +585,22 @@ public class ZeroBuffer extends ByteBuf {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int forEachByte(ByteProcessor byteProcessor) {
|
||||
public int forEachByte(ByteBufProcessor byteBufProcessor) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int forEachByte(int i, int i1, ByteProcessor byteProcessor) {
|
||||
public int forEachByte(int i, int i1, ByteBufProcessor byteBufProcessor) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int forEachByteDesc(ByteProcessor byteProcessor) {
|
||||
public int forEachByteDesc(ByteBufProcessor byteBufProcessor) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int forEachByteDesc(int i, int i1, ByteProcessor byteProcessor) {
|
||||
public int forEachByteDesc(int i, int i1, ByteBufProcessor byteBufProcessor) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -786,31 +619,16 @@ public class ZeroBuffer extends ByteBuf {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf retainedSlice() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf slice(int i, int i1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf retainedSlice(int i, int i1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf duplicate() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf retainedDuplicate() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int nioBufferCount() {
|
||||
return 0;
|
||||
@@ -920,14 +738,4 @@ public class ZeroBuffer extends ByteBuf {
|
||||
public ByteBuf retain() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf touch() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ByteBuf touch(Object o) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -70,7 +70,6 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.WorldType;
|
||||
@@ -874,13 +873,6 @@ public class BukkitConverters {
|
||||
return ignoreNull(new EquivalentConverter<EntityType>() {
|
||||
@Override
|
||||
public Object getGeneric(EntityType specific) {
|
||||
if (MinecraftVersion.v26_2.atOrAbove()) {
|
||||
// EntityType.byString was removed in 26.2, resolve through the registry instead
|
||||
WrappedRegistry registry = WrappedRegistry.getRegistry(MinecraftReflection.getEntityTypes());
|
||||
NamespacedKey key = specific.getKey();
|
||||
return registry.get(new MinecraftKey(key.getNamespace(), key.getKey()));
|
||||
}
|
||||
|
||||
if (entityTypeFromName == null) {
|
||||
Class<?> entityTypesClass = MinecraftReflection.getEntityTypes();
|
||||
entityTypeFromName = Accessors.getMethodAccessor(
|
||||
@@ -1436,142 +1428,6 @@ public class BukkitConverters {
|
||||
});
|
||||
}
|
||||
|
||||
// Lazily-resolved CraftDamageType reflection. volatile + DCL keeps the publish safe
|
||||
// and avoids re-running fuzzy lookups in concurrent injection paths.
|
||||
private static volatile MethodAccessor damageTypeToNms = null;
|
||||
private static volatile MethodAccessor damageTypeFromNms = null;
|
||||
private static volatile MethodAccessor damageTypeHolderValue = null;
|
||||
private static boolean damageTypeToNmsReturnsHolder;
|
||||
private static boolean damageTypeFromNmsAcceptsHolder;
|
||||
private static final Map<Object, Object> damageTypeHolders = new ConcurrentHashMap<>();
|
||||
|
||||
private static FuzzyReflection craftDamageTypeFuzzy() {
|
||||
return FuzzyReflection.fromClass(getCraftBukkitClass("damage.CraftDamageType"), false);
|
||||
}
|
||||
|
||||
private static MethodAccessor resolveDamageTypeToNms() {
|
||||
MethodAccessor accessor = damageTypeToNms;
|
||||
if (accessor != null) return accessor;
|
||||
synchronized (BukkitConverters.class) {
|
||||
accessor = damageTypeToNms;
|
||||
if (accessor != null) return accessor;
|
||||
try {
|
||||
accessor = Accessors.getMethodAccessor(craftDamageTypeFuzzy().getMethod(FuzzyMethodContract.newBuilder()
|
||||
.parameterExactArray(org.bukkit.damage.DamageType.class)
|
||||
.returnTypeExact(MinecraftReflection.getDamageTypeClass())
|
||||
.requireModifier(Modifier.STATIC)
|
||||
.build()));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
accessor = Accessors.getMethodAccessor(craftDamageTypeFuzzy().getMethod(FuzzyMethodContract.newBuilder()
|
||||
.parameterExactArray(org.bukkit.damage.DamageType.class)
|
||||
.returnTypeExact(MinecraftReflection.getHolderClass())
|
||||
.requireModifier(Modifier.STATIC)
|
||||
.build()));
|
||||
damageTypeToNmsReturnsHolder = true;
|
||||
}
|
||||
damageTypeToNms = accessor;
|
||||
return accessor;
|
||||
}
|
||||
}
|
||||
|
||||
private static MethodAccessor resolveDamageTypeFromNms() {
|
||||
MethodAccessor accessor = damageTypeFromNms;
|
||||
if (accessor != null) return accessor;
|
||||
synchronized (BukkitConverters.class) {
|
||||
accessor = damageTypeFromNms;
|
||||
if (accessor != null) return accessor;
|
||||
try {
|
||||
accessor = Accessors.getMethodAccessor(craftDamageTypeFuzzy().getMethod(FuzzyMethodContract.newBuilder()
|
||||
.parameterExactArray(MinecraftReflection.getDamageTypeClass())
|
||||
.returnTypeExact(org.bukkit.damage.DamageType.class)
|
||||
.requireModifier(Modifier.STATIC)
|
||||
.build()));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
accessor = Accessors.getMethodAccessor(craftDamageTypeFuzzy().getMethod(FuzzyMethodContract.newBuilder()
|
||||
.parameterExactArray(MinecraftReflection.getHolderClass())
|
||||
.returnTypeExact(org.bukkit.damage.DamageType.class)
|
||||
.requireModifier(Modifier.STATIC)
|
||||
.build()));
|
||||
damageTypeFromNmsAcceptsHolder = true;
|
||||
}
|
||||
damageTypeFromNms = accessor;
|
||||
return accessor;
|
||||
}
|
||||
}
|
||||
|
||||
private static Object getHolderValue(Object holder) {
|
||||
MethodAccessor accessor = damageTypeHolderValue;
|
||||
if (accessor == null) {
|
||||
synchronized (BukkitConverters.class) {
|
||||
accessor = damageTypeHolderValue;
|
||||
if (accessor == null) {
|
||||
accessor = Accessors.getMethodAccessor(
|
||||
FuzzyReflection.fromClass(MinecraftReflection.getHolderClass(), false)
|
||||
.getMethod(FuzzyMethodContract.newBuilder()
|
||||
.parameterCount(0)
|
||||
.banModifier(Modifier.STATIC)
|
||||
.returnTypeExact(Object.class)
|
||||
.build()));
|
||||
damageTypeHolderValue = accessor;
|
||||
}
|
||||
}
|
||||
}
|
||||
return accessor.invoke(holder);
|
||||
}
|
||||
|
||||
private static Object getDamageTypeHolder(Object generic) {
|
||||
Object holder = damageTypeHolders.get(generic);
|
||||
if (holder != null) {
|
||||
return holder;
|
||||
}
|
||||
|
||||
MethodAccessor accessor = resolveDamageTypeToNms();
|
||||
if (!damageTypeToNmsReturnsHolder) {
|
||||
throw new IllegalStateException("CraftDamageType accepts holders but does not produce them");
|
||||
}
|
||||
|
||||
for (org.bukkit.damage.DamageType damageType : org.bukkit.Registry.DAMAGE_TYPE) {
|
||||
Object candidate = accessor.invoke(null, damageType);
|
||||
Object candidateValue = getHolderValue(candidate);
|
||||
damageTypeHolders.putIfAbsent(candidateValue, candidate);
|
||||
if (Objects.equal(candidateValue, generic)) {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("Unable to resolve a holder for damage type " + generic);
|
||||
}
|
||||
|
||||
public static EquivalentConverter<org.bukkit.damage.DamageType> getDamageTypeConverter() {
|
||||
return ignoreNull(new EquivalentConverter<org.bukkit.damage.DamageType>() {
|
||||
|
||||
@Override
|
||||
public Class<org.bukkit.damage.DamageType> getSpecificType() {
|
||||
return org.bukkit.damage.DamageType.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getGeneric(org.bukkit.damage.DamageType specific) {
|
||||
Object generic = resolveDamageTypeToNms().invoke(null, specific);
|
||||
if (damageTypeToNmsReturnsHolder) {
|
||||
Object value = getHolderValue(generic);
|
||||
damageTypeHolders.putIfAbsent(value, generic);
|
||||
return value;
|
||||
}
|
||||
return generic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public org.bukkit.damage.DamageType getSpecific(Object generic) {
|
||||
MethodAccessor accessor = resolveDamageTypeFromNms();
|
||||
if (damageTypeFromNmsAcceptsHolder) {
|
||||
generic = getDamageTypeHolder(generic);
|
||||
}
|
||||
return (org.bukkit.damage.DamageType) accessor.invoke(null, generic);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static Class<?> dimensionManager;
|
||||
private static FauxEnumConverter<Dimension> dimensionConverter;
|
||||
private static FauxEnumConverter<DimensionImpl> dimensionImplConverter;
|
||||
|
||||
@@ -18,8 +18,6 @@ import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import net.bytebuddy.ByteBuddy;
|
||||
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
|
||||
@@ -35,8 +33,8 @@ import net.bytebuddy.matcher.ElementMatchers;
|
||||
* by default. Constructing a new wrapper instance will give out a handle to a completely new implemented type, that
|
||||
* allows to set a key and some kind of data of any choice.
|
||||
* <p>
|
||||
* Constructing this class from a generic handle requires either retained raw byte data, such as {@code DiscardedPayload},
|
||||
* or a writable serialization method on the concrete payload type.
|
||||
* Note that constructing this class from a generic handle is only possible for the spigot-specific UnknownPayload type.
|
||||
* All other payloads should be accessed via a structure modifier directly.
|
||||
*
|
||||
* @author Pasqual Koschmieder
|
||||
*/
|
||||
@@ -48,16 +46,7 @@ public final class CustomPacketPayloadWrapper {
|
||||
private static final ConstructorAccessor PAYLOAD_WRAPPER_CONSTRUCTOR;
|
||||
|
||||
private static final MethodAccessor GET_ID_PAYLOAD_METHOD;
|
||||
private static final MethodAccessor GET_ID_HOLDER_PAYLOAD_METHOD;
|
||||
private static final MethodAccessor GET_ID_PAYLOAD_HOLDER_METHOD;
|
||||
private static final MethodAccessor SERIALIZE_PAYLOAD_METHOD;
|
||||
private static final Class<?> PAYLOAD_SERIALIZER_CLASS;
|
||||
private static final ConcurrentHashMap<Class<?>, Optional<MethodAccessor>> SERIALIZE_PAYLOAD_METHODS =
|
||||
new ConcurrentHashMap<>();
|
||||
|
||||
/** True when running on the nested-ID API where DiscardedPayload is used instead of the ByteBuddy proxy. */
|
||||
private static final boolean USE_DISCARDED_PAYLOAD;
|
||||
private static final boolean DISCARDED_PAYLOAD_USES_BYTE_ARRAY;
|
||||
|
||||
private static final EquivalentConverter<CustomPacketPayloadWrapper> CONVERTER;
|
||||
|
||||
@@ -66,73 +55,22 @@ public final class CustomPacketPayloadWrapper {
|
||||
MINECRAFT_KEY_CLASS = MinecraftReflection.getMinecraftKeyClass();
|
||||
CUSTOM_PACKET_PAYLOAD_CLASS = MinecraftReflection.getMinecraftClass("network.protocol.common.custom.CustomPacketPayload");
|
||||
|
||||
Method getPayloadId = null;
|
||||
Method getPayloadIdHolder = null;
|
||||
Method getPayloadIdFromHolder = null;
|
||||
boolean useDiscardedPayload = false;
|
||||
try {
|
||||
getPayloadId = FuzzyReflection.fromClass(CUSTOM_PACKET_PAYLOAD_CLASS).getMethod(FuzzyMethodContract.newBuilder()
|
||||
.banModifier(Modifier.STATIC)
|
||||
.returnTypeExact(MINECRAFT_KEY_CLASS)
|
||||
.parameterCount(0)
|
||||
.build());
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
// Paper 26: the payload exposes its identifier through one intermediate record.
|
||||
Method[] accessors = findChainedIdAccessors(CUSTOM_PACKET_PAYLOAD_CLASS, MINECRAFT_KEY_CLASS);
|
||||
getPayloadIdHolder = accessors[0];
|
||||
getPayloadIdFromHolder = accessors[1];
|
||||
useDiscardedPayload = true;
|
||||
}
|
||||
GET_ID_PAYLOAD_METHOD = getPayloadId != null ? Accessors.getMethodAccessor(getPayloadId) : null;
|
||||
GET_ID_HOLDER_PAYLOAD_METHOD = getPayloadIdHolder != null
|
||||
? Accessors.getMethodAccessor(getPayloadIdHolder) : null;
|
||||
GET_ID_PAYLOAD_HOLDER_METHOD = getPayloadIdFromHolder != null
|
||||
? Accessors.getMethodAccessor(getPayloadIdFromHolder) : null;
|
||||
USE_DISCARDED_PAYLOAD = useDiscardedPayload;
|
||||
Method getPayloadId = FuzzyReflection.fromClass(CUSTOM_PACKET_PAYLOAD_CLASS).getMethod(FuzzyMethodContract.newBuilder()
|
||||
.banModifier(Modifier.STATIC)
|
||||
.returnTypeExact(MINECRAFT_KEY_CLASS)
|
||||
.parameterCount(0)
|
||||
.build());
|
||||
GET_ID_PAYLOAD_METHOD = Accessors.getMethodAccessor(getPayloadId);
|
||||
|
||||
Method serializePayloadData = null;
|
||||
try {
|
||||
serializePayloadData = FuzzyReflection.fromClass(CUSTOM_PACKET_PAYLOAD_CLASS).getMethod(FuzzyMethodContract.newBuilder()
|
||||
.banModifier(Modifier.STATIC)
|
||||
.returnTypeVoid()
|
||||
.parameterCount(1)
|
||||
.parameterDerivedOf(ByteBuf.class, 0)
|
||||
.build());
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
// Paper 26 declares the write method on each concrete payload instead.
|
||||
}
|
||||
SERIALIZE_PAYLOAD_METHOD = serializePayloadData != null
|
||||
? Accessors.getMethodAccessor(serializePayloadData) : null;
|
||||
if (serializePayloadData == null) {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
try {
|
||||
PAYLOAD_SERIALIZER_CLASS = MinecraftReflection.getPacketDataSerializer(buffer).getClass();
|
||||
} finally {
|
||||
if (buffer.refCnt() > 0) {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
PAYLOAD_SERIALIZER_CLASS = null;
|
||||
}
|
||||
Method serializePayloadData = FuzzyReflection.fromClass(CUSTOM_PACKET_PAYLOAD_CLASS).getMethod(FuzzyMethodContract.newBuilder()
|
||||
.banModifier(Modifier.STATIC)
|
||||
.returnTypeVoid()
|
||||
.parameterCount(1)
|
||||
.parameterDerivedOf(ByteBuf.class, 0)
|
||||
.build());
|
||||
SERIALIZE_PAYLOAD_METHOD = Accessors.getMethodAccessor(serializePayloadData);
|
||||
|
||||
Constructor<?> payloadWrapperConstructor;
|
||||
boolean discardedPayloadUsesByteArray = false;
|
||||
if (useDiscardedPayload) {
|
||||
Class<?> discardedPayloadClass = MinecraftReflection.getMinecraftClass(
|
||||
"network.protocol.common.custom.DiscardedPayload");
|
||||
try {
|
||||
payloadWrapperConstructor = discardedPayloadClass.getConstructor(
|
||||
MINECRAFT_KEY_CLASS, byte[].class);
|
||||
discardedPayloadUsesByteArray = true;
|
||||
} catch (NoSuchMethodException exception) {
|
||||
payloadWrapperConstructor = discardedPayloadClass.getConstructor(
|
||||
MINECRAFT_KEY_CLASS, ByteBuf.class);
|
||||
}
|
||||
} else {
|
||||
payloadWrapperConstructor = makePayloadWrapper();
|
||||
}
|
||||
DISCARDED_PAYLOAD_USES_BYTE_ARRAY = discardedPayloadUsesByteArray;
|
||||
Constructor<?> payloadWrapperConstructor = makePayloadWrapper();
|
||||
PAYLOAD_WRAPPER_CONSTRUCTOR = Accessors.getConstructorAccessor(payloadWrapperConstructor);
|
||||
|
||||
CONVERTER = new EquivalentConverter<CustomPacketPayloadWrapper>() {
|
||||
@@ -156,41 +94,6 @@ public final class CustomPacketPayloadWrapper {
|
||||
}
|
||||
}
|
||||
|
||||
private static Method[] findChainedIdAccessors(Class<?> payloadClass, Class<?> keyClass) {
|
||||
Method payloadAccessor = null;
|
||||
Method keyAccessor = null;
|
||||
FuzzyMethodContract keyAccessorContract = FuzzyMethodContract.newBuilder()
|
||||
.banModifier(Modifier.STATIC)
|
||||
.returnTypeExact(keyClass)
|
||||
.parameterCount(0)
|
||||
.build();
|
||||
|
||||
for (Method candidate : payloadClass.getMethods()) {
|
||||
if (Modifier.isStatic(candidate.getModifiers()) || candidate.getParameterCount() != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Method candidateKeyAccessor;
|
||||
try {
|
||||
candidateKeyAccessor = FuzzyReflection.fromClass(candidate.getReturnType(), true)
|
||||
.getMethod(keyAccessorContract);
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (payloadAccessor != null) {
|
||||
throw new IllegalArgumentException("Multiple CustomPacketPayload identifier accessors found");
|
||||
}
|
||||
payloadAccessor = candidate;
|
||||
keyAccessor = candidateKeyAccessor;
|
||||
}
|
||||
|
||||
if (payloadAccessor == null) {
|
||||
throw new IllegalArgumentException("Unable to find a CustomPacketPayload identifier accessor");
|
||||
}
|
||||
return new Method[]{payloadAccessor, keyAccessor};
|
||||
}
|
||||
|
||||
private static Constructor<?> makePayloadWrapper() throws Exception {
|
||||
return new ByteBuddy()
|
||||
.subclass(Object.class)
|
||||
@@ -213,64 +116,6 @@ public final class CustomPacketPayloadWrapper {
|
||||
.getConstructor(MinecraftReflection.getMinecraftKeyClass(), byte[].class);
|
||||
}
|
||||
|
||||
private static Optional<MethodAccessor> findSerializePayloadMethod(Class<?> payloadClass) {
|
||||
Method serializeMethod = null;
|
||||
for (Method candidate : FuzzyReflection.fromClass(payloadClass, true).getMethods()) {
|
||||
if (Modifier.isStatic(candidate.getModifiers())
|
||||
|| candidate.getReturnType() != void.class
|
||||
|| candidate.getParameterCount() != 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Class<?> parameterClass = candidate.getParameterTypes()[0];
|
||||
if (parameterClass == Object.class || !parameterClass.isAssignableFrom(PAYLOAD_SERIALIZER_CLASS)) {
|
||||
continue;
|
||||
}
|
||||
if (serializeMethod != null) {
|
||||
throw new IllegalArgumentException("Multiple CustomPacketPayload serialization methods found on "
|
||||
+ payloadClass.getName());
|
||||
}
|
||||
serializeMethod = candidate;
|
||||
}
|
||||
|
||||
if (serializeMethod == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
serializeMethod.setAccessible(true);
|
||||
return Optional.of(Accessors.getMethodAccessor(serializeMethod));
|
||||
}
|
||||
|
||||
private static MethodAccessor getSerializePayloadMethod(Object payload) {
|
||||
if (SERIALIZE_PAYLOAD_METHOD != null) {
|
||||
return SERIALIZE_PAYLOAD_METHOD;
|
||||
}
|
||||
return SERIALIZE_PAYLOAD_METHODS
|
||||
.computeIfAbsent(payload.getClass(), CustomPacketPayloadWrapper::findSerializePayloadMethod)
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private static byte[] serializePayload(Object payload) {
|
||||
MethodAccessor serializeMethod = getSerializePayloadMethod(payload);
|
||||
if (serializeMethod == null) {
|
||||
throw new UnsupportedOperationException(
|
||||
"Cannot extract raw custom payload bytes from " + payload.getClass().getName()
|
||||
+ ": payload has no byte array, ByteBuf, or serialization method");
|
||||
}
|
||||
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
try {
|
||||
Object serializer = MinecraftReflection.getPacketDataSerializer(buffer);
|
||||
serializeMethod.invoke(payload, serializer);
|
||||
byte[] result = new byte[buffer.readableBytes()];
|
||||
buffer.getBytes(buffer.readerIndex(), result);
|
||||
return result;
|
||||
} finally {
|
||||
if (buffer.refCnt() > 0) {
|
||||
buffer.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ====== api methods ======
|
||||
|
||||
/**
|
||||
@@ -326,39 +171,29 @@ public final class CustomPacketPayloadWrapper {
|
||||
* @return a wrapper holding the minecraft key and payload of the given custom payload instance.
|
||||
*/
|
||||
public static CustomPacketPayloadWrapper fromUnknownPayload(Object payload) {
|
||||
MinecraftKey id = getPayloadId(payload);
|
||||
Object messageId = GET_ID_PAYLOAD_METHOD.invoke(payload);
|
||||
MinecraftKey id = MinecraftKey.getConverter().getSpecific(messageId);
|
||||
|
||||
// we read and retain the underlying buffer in case the class uses a buffer to store the data
|
||||
// this way, when passing the packet to further handling, the buffer is not released and can be re-used
|
||||
StructureModifier<Object> modifier = new StructureModifier<>(payload.getClass()).withTarget(payload);
|
||||
byte[] messagePayload = (byte[]) modifier.withType(byte[].class).readSafely(0);
|
||||
if (messagePayload != null) {
|
||||
messagePayload = messagePayload.clone();
|
||||
} else {
|
||||
messagePayload = modifier.withType(ByteBuf.class).optionRead(0)
|
||||
.map(buffer -> {
|
||||
ByteBuf buf = (ByteBuf) buffer;
|
||||
byte[] data = StreamSerializer.getDefault().getBytesAndRelease(buf.markReaderIndex().retain());
|
||||
buf.resetReaderIndex();
|
||||
return data;
|
||||
})
|
||||
.orElseGet(() -> serializePayload(payload));
|
||||
}
|
||||
byte[] messagePayload = modifier.withType(ByteBuf.class).optionRead(0)
|
||||
.map(buffer -> {
|
||||
ByteBuf buf = (ByteBuf) buffer;
|
||||
byte[] data = StreamSerializer.getDefault().getBytesAndRelease(buf.markReaderIndex().retain());
|
||||
buf.resetReaderIndex();
|
||||
return data;
|
||||
})
|
||||
.orElseGet(() -> {
|
||||
ByteBuf buffer = Unpooled.buffer();
|
||||
Object serializer = MinecraftReflection.getPacketDataSerializer(buffer);
|
||||
SERIALIZE_PAYLOAD_METHOD.invoke(payload, serializer);
|
||||
return StreamSerializer.getDefault().getBytesAndRelease(buffer);
|
||||
});
|
||||
|
||||
return new CustomPacketPayloadWrapper(messagePayload, id);
|
||||
}
|
||||
|
||||
private static MinecraftKey getPayloadId(Object payload) {
|
||||
Object messageId;
|
||||
if (GET_ID_PAYLOAD_METHOD != null) {
|
||||
messageId = GET_ID_PAYLOAD_METHOD.invoke(payload);
|
||||
} else {
|
||||
Object idHolder = GET_ID_HOLDER_PAYLOAD_METHOD.invoke(payload);
|
||||
messageId = GET_ID_PAYLOAD_HOLDER_METHOD.invoke(idHolder);
|
||||
}
|
||||
return MinecraftKey.getConverter().getSpecific(messageId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the generic id of the wrapped message id.
|
||||
*
|
||||
@@ -395,13 +230,6 @@ public final class CustomPacketPayloadWrapper {
|
||||
* @return a new payload wrapper instance using the provided message id and payload.
|
||||
*/
|
||||
public Object newHandle() {
|
||||
if (USE_DISCARDED_PAYLOAD) {
|
||||
if (DISCARDED_PAYLOAD_USES_BYTE_ARRAY) {
|
||||
return PAYLOAD_WRAPPER_CONSTRUCTOR.invoke(this.getGenericId(), this.payload);
|
||||
}
|
||||
ByteBuf buf = Unpooled.copiedBuffer(this.payload);
|
||||
return PAYLOAD_WRAPPER_CONSTRUCTOR.invoke(this.getGenericId(), buf);
|
||||
}
|
||||
return PAYLOAD_WRAPPER_CONSTRUCTOR.invoke(this.getGenericId(), this.payload);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import com.comphenix.protocol.utility.Validate;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.GameMode;
|
||||
|
||||
@@ -36,12 +36,6 @@ public abstract class EnumWrappers {
|
||||
public enum ClientCommand {
|
||||
PERFORM_RESPAWN,
|
||||
REQUEST_STATS,
|
||||
REQUEST_GAMERULE_VALUES,
|
||||
|
||||
/**
|
||||
* @deprecated Removed in 26.1
|
||||
*/
|
||||
@Deprecated
|
||||
OPEN_INVENTORY_ACHIEVEMENT
|
||||
}
|
||||
|
||||
@@ -186,9 +180,7 @@ public abstract class EnumWrappers {
|
||||
DROP_ALL_ITEMS,
|
||||
DROP_ITEM,
|
||||
RELEASE_USE_ITEM,
|
||||
SWAP_HELD_ITEMS("SWAP_ITEM_WITH_OFFHAND"),
|
||||
STAB,
|
||||
CHANGE_DESTROY_DIRECTION;
|
||||
SWAP_HELD_ITEMS("SWAP_ITEM_WITH_OFFHAND");
|
||||
|
||||
final String[] aliases;
|
||||
PlayerDigType(String... aliases) {
|
||||
@@ -804,10 +796,7 @@ public abstract class EnumWrappers {
|
||||
PLAYER_DIG_TYPE_CLASS = getEnum(PacketType.Play.Client.BLOCK_DIG.getPacketClass(), 1);
|
||||
PLAYER_ACTION_CLASS = getEnum(PacketType.Play.Client.ENTITY_ACTION.getPacketClass(), 0);
|
||||
SCOREBOARD_ACTION_CLASS = getEnum(PacketType.Play.Server.SCOREBOARD_SCORE.getPacketClass(), 0);
|
||||
// the particle enum was removed in 1.13, later packets may contain unrelated enums
|
||||
if (!MinecraftVersion.AQUATIC_UPDATE.atOrAbove()) {
|
||||
PARTICLE_CLASS = getEnum(PacketType.Play.Server.WORLD_PARTICLES.getPacketClass(), 0);
|
||||
}
|
||||
PARTICLE_CLASS = getEnum(PacketType.Play.Server.WORLD_PARTICLES.getPacketClass(), 0);
|
||||
|
||||
PLAYER_INFO_ACTION_CLASS = getEnum(PacketType.Play.Server.PLAYER_INFO.getPacketClass(), 0);
|
||||
if (PLAYER_INFO_ACTION_CLASS == null) {
|
||||
@@ -816,7 +805,7 @@ public abstract class EnumWrappers {
|
||||
}
|
||||
|
||||
try {
|
||||
SOUND_CATEGORY_CLASS = MinecraftReflection.getMinecraftClass("sounds.SoundCategory", "sounds.SoundSource");
|
||||
SOUND_CATEGORY_CLASS = MinecraftReflection.getMinecraftClass("sounds.SoundCategory");
|
||||
} catch (Exception ex) {
|
||||
SOUND_CATEGORY_CLASS = getEnum(PacketType.Play.Server.NAMED_SOUND_EFFECT.getPacketClass(), 0);
|
||||
}
|
||||
@@ -832,17 +821,13 @@ public abstract class EnumWrappers {
|
||||
if (MinecraftVersion.CAVES_CLIFFS_1.atOrAbove()) {
|
||||
HAND_CLASS = MinecraftReflection.getMinecraftClass("world.EnumHand", "world.InteractionHand");
|
||||
|
||||
if (MinecraftVersion.v26_1.atOrAbove()) {
|
||||
// TODO
|
||||
} else {
|
||||
FuzzyReflection fuzzy = FuzzyReflection.fromClass(MinecraftReflection.getEnumEntityUseActionClass(), true);
|
||||
Method getType = fuzzy.getMethod(FuzzyMethodContract.newBuilder()
|
||||
.parameterCount(0)
|
||||
.returnTypeMatches(FuzzyMatchers.except(Void.class))
|
||||
.build());
|
||||
FuzzyReflection fuzzy = FuzzyReflection.fromClass(MinecraftReflection.getEnumEntityUseActionClass(), true);
|
||||
Method getType = fuzzy.getMethod(FuzzyMethodContract.newBuilder()
|
||||
.parameterCount(0)
|
||||
.returnTypeMatches(FuzzyMatchers.except(Void.class))
|
||||
.build());
|
||||
|
||||
ENTITY_USE_ACTION_CLASS = getType.getReturnType();
|
||||
}
|
||||
ENTITY_USE_ACTION_CLASS = getType.getReturnType();
|
||||
} else {
|
||||
HAND_CLASS = getEnum(PacketType.Play.Client.USE_ENTITY.getPacketClass(), 1);
|
||||
ENTITY_USE_ACTION_CLASS = getEnum(PacketType.Play.Client.USE_ENTITY.getPacketClass(), 0);
|
||||
|
||||
@@ -37,7 +37,7 @@ import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
|
||||
import com.comphenix.protocol.wrappers.collection.ConvertedMap;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import com.comphenix.protocol.utility.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
|
||||
@@ -105,22 +105,17 @@ public class LegacyDataWatcher extends AbstractWrapper implements IDataWatcher {
|
||||
*/
|
||||
@Deprecated
|
||||
public LegacyDataWatcher(List<WrappedWatchableObject> objects) {
|
||||
this(newHandle(fakeEntity()));
|
||||
|
||||
for (WrappedWatchableObject object : objects) {
|
||||
WrappedDataWatcherObject watcherObject = MinecraftReflection.watcherObjectExists()
|
||||
? object.getWatcherObject()
|
||||
: WrappedDataWatcherObject.fromIndex(object.getIndex());
|
||||
setObject(watcherObject, object, false);
|
||||
}
|
||||
this(newHandle(fakeEntity(), objects));
|
||||
}
|
||||
|
||||
private static Object newHandle(Object entity) {
|
||||
private static Object newHandle(Object entity, List<WrappedWatchableObject> objects) {
|
||||
if (constructor == null) {
|
||||
constructor = Accessors.getConstructorAccessor(HANDLE_TYPE, MinecraftReflection.getEntityClass());
|
||||
constructor = Accessors.getConstructorAccessor(HANDLE_TYPE, MinecraftReflection.getEntityClass(),
|
||||
MinecraftReflection.getArrayClass(MinecraftReflection.getDataWatcherItemClass()));
|
||||
}
|
||||
|
||||
return constructor.invoke(entity);
|
||||
Object[] genericItems = new Object[0];// (Object[]) ITEMS_CONVERTER.getGeneric(objects);
|
||||
return constructor.invoke(entity, genericItems);
|
||||
}
|
||||
|
||||
private static Object fakeEntity() {
|
||||
|
||||
@@ -53,7 +53,14 @@ public class MinecraftKey {
|
||||
* @param key The key
|
||||
*/
|
||||
public MinecraftKey(String key) {
|
||||
this("minecraft", key);
|
||||
if (key.contains(":")) {
|
||||
String[] split = key.split(":", 2);
|
||||
this.prefix = split[0];
|
||||
this.key = split[1];
|
||||
} else {
|
||||
this.prefix = "minecraft";
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
|
||||
/**
|
||||
* Mutable version of PropertyMap
|
||||
* Credit to PaperMC: https://github.com/PaperMC/Paper/blob/main/paper-server/src/main/java/io/papermc/paper/profile/MutablePropertyMap.java
|
||||
*/
|
||||
public class MutablePropertyMap extends PropertyMap {
|
||||
private final Multimap<String, Property> properties = HashMultimap.create();
|
||||
|
||||
public MutablePropertyMap() {
|
||||
super(ImmutableMultimap.of());
|
||||
}
|
||||
|
||||
public MutablePropertyMap(final Multimap<String, Property> properties) {
|
||||
this();
|
||||
this.putAll(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Multimap<String, Property> delegate() {
|
||||
return this.properties;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
|
||||
public class ResourceKey {
|
||||
private static final AutoWrapper<ResourceKey> AUTO_WRAPPER = AutoWrapper.wrap(ResourceKey.class, MinecraftReflection.getResourceKey())
|
||||
.field(0, MinecraftKey.getConverter())
|
||||
.field(1, MinecraftKey.getConverter());
|
||||
|
||||
MinecraftKey registryName;
|
||||
MinecraftKey location;
|
||||
|
||||
ResourceKey() {
|
||||
|
||||
}
|
||||
|
||||
public ResourceKey(MinecraftKey registryName, MinecraftKey location) {
|
||||
this.registryName = registryName;
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public MinecraftKey getRegistryName() {
|
||||
return registryName;
|
||||
}
|
||||
|
||||
public MinecraftKey getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setRegistryName(MinecraftKey registryName) {
|
||||
this.registryName = registryName;
|
||||
}
|
||||
|
||||
public void setLocation(MinecraftKey location) {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public static ResourceKey fromGeneric(Object generic) {
|
||||
return AUTO_WRAPPER.wrap(generic);
|
||||
}
|
||||
|
||||
public Object toGeneric() {
|
||||
return AUTO_WRAPPER.unwrap(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import java.lang.reflect.RecordComponent;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.ConstructorAccessor;
|
||||
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||
import com.comphenix.protocol.reflect.cloning.AggregateCloner;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
|
||||
/**
|
||||
* Represents a single data component in Minecraft, which is a key-value pair
|
||||
* used to store metadata about game objects such as items, mobs, and block entities.
|
||||
* <p>
|
||||
* This class provides methods to create, access, and manipulate data components,
|
||||
* as well as to convert them to and from their underlying NMS handles.
|
||||
*
|
||||
* @see WrappedDataComponentHolder
|
||||
*/
|
||||
public final class WrappedDataComponent {
|
||||
private static final Optional<Class<?>> HANDLE_TYPE = MinecraftReflection.getTypedDataComponentClass();
|
||||
|
||||
private static MethodAccessor TYPE_ACCESSOR;
|
||||
private static MethodAccessor VALUE_ACCESSOR;
|
||||
private static ConstructorAccessor CTOR_ACCESSOR;
|
||||
|
||||
private final Object keyHandle;
|
||||
private final String key;
|
||||
|
||||
private Object value;
|
||||
|
||||
static {
|
||||
initialize();
|
||||
}
|
||||
|
||||
private static void initialize() {
|
||||
if (HANDLE_TYPE.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Class<?> clazz = HANDLE_TYPE.get();
|
||||
RecordComponent typeComponent = clazz.getRecordComponents()[0];
|
||||
TYPE_ACCESSOR = Accessors.getMethodAccessor(typeComponent.getAccessor());
|
||||
|
||||
RecordComponent valueComponent = clazz.getRecordComponents()[1];
|
||||
VALUE_ACCESSOR = Accessors.getMethodAccessor(valueComponent.getAccessor());
|
||||
|
||||
CTOR_ACCESSOR = Accessors.getConstructorAccessor(clazz, typeComponent.getType(), valueComponent.getType());
|
||||
}
|
||||
|
||||
WrappedDataComponent(Object keyHandle, String key, Object value) {
|
||||
this.keyHandle = keyHandle;
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the key of this data component, e.g. "minecraft:custom_data".
|
||||
*/
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the in-memory value of this data component.
|
||||
* <br>
|
||||
* <b>NOTE:</b> this does <b>NOT</b> update the underlying handle
|
||||
* @param value new NMS value
|
||||
*/
|
||||
public void setValue(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the current in-memory value of this data component
|
||||
* @param <T> desired return type
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getValue() {
|
||||
return (T) value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new WrappedDataComponent from an existing NMS handle.
|
||||
* @param handle NMS handle
|
||||
* @return new WrappedDataComponent instance
|
||||
*/
|
||||
public static WrappedDataComponent fromHandle(Object handle) {
|
||||
if (TYPE_ACCESSOR == null || VALUE_ACCESSOR == null) {
|
||||
throw new IllegalStateException("Unable to access TypedDataComponent");
|
||||
}
|
||||
|
||||
Object typeHandle = TYPE_ACCESSOR.invoke(handle);
|
||||
Object value = VALUE_ACCESSOR.invoke(handle);
|
||||
|
||||
WrappedRegistry componentTypeRegistry = WrappedRegistry.getDataComponentTypeRegistry();
|
||||
String key = componentTypeRegistry.getKey(typeHandle).getFullKey();
|
||||
|
||||
return new WrappedDataComponent(typeHandle, key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new NMS handle for this data component using the current value.
|
||||
* @return new NMS handle
|
||||
*/
|
||||
public Object getHandle() {
|
||||
if (CTOR_ACCESSOR == null) {
|
||||
throw new IllegalStateException("Unable to access TypedDataComponent constructor");
|
||||
}
|
||||
|
||||
return CTOR_ACCESSOR.invoke(keyHandle, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new WrappedDataComponent with the specified key and no value.
|
||||
* @param key the key of the data component, e.g. "minecraft:custom_data".
|
||||
* @return new WrappedDataComponent instance
|
||||
*/
|
||||
public static WrappedDataComponent create(String key) {
|
||||
return create(key, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new WrappedDataComponent with the specified key and value.
|
||||
* @param key the key of the data component, e.g. "minecraft:custom_data".
|
||||
* @param value the NMS value of the data component, e.g. an ItemStack or Integer.
|
||||
* @return new WrappedDataComponent instance
|
||||
*/
|
||||
public static WrappedDataComponent create(String key, Object value) {
|
||||
WrappedRegistry componentTypeRegistry = WrappedRegistry.getDataComponentTypeRegistry();
|
||||
Object keyHandle = componentTypeRegistry.get(key);
|
||||
|
||||
if (keyHandle == null) {
|
||||
throw new IllegalArgumentException("Invalid key: " + key);
|
||||
}
|
||||
|
||||
return new WrappedDataComponent(keyHandle, key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a shallow clone of this WrappedDataComponent, which means it copies the key and value references,
|
||||
* but does not clone the value itself. This should cover most cases where the value is immutable
|
||||
* (e.g. strings, numbers, enums).
|
||||
* @return a new WrappedDataComponent instance with the same key and value references
|
||||
*/
|
||||
public WrappedDataComponent shallowClone() {
|
||||
return new WrappedDataComponent(keyHandle, key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a deep clone of this WrappedDataComponent, which means it clones the value as well.
|
||||
* This is useful when the value is mutable (e.g. books, NBT data) and you want to ensure that
|
||||
* changes to the cloned component do not affect the original component.
|
||||
* @return a new WrappedDataComponent instance with a cloned value
|
||||
*/
|
||||
public WrappedDataComponent deepClone() {
|
||||
Object clonedValue = AggregateCloner.DEFAULT.clone(value);
|
||||
return new WrappedDataComponent(keyHandle, key, clonedValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WrappedDataComponent[" + key + "=>" + value + "]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof WrappedDataComponent other)) return false;
|
||||
|
||||
return key.equals(other.key) && value.equals(other.value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = key.hashCode();
|
||||
result = 31 * result + (value != null ? value.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
/**
|
||||
* Provides access to a DataComponentHolder, which is an object that can hold
|
||||
* various (meta)data components
|
||||
*/
|
||||
public final class WrappedDataComponentHolder extends AbstractWrapper {
|
||||
private static MethodAccessor GET_COMPONENTS;
|
||||
private static MethodAccessor GET_COMPONENT;
|
||||
|
||||
private static Optional<Class<?>> DATA_COMPONENT_MAP_CLASS = MinecraftReflection.getDataComponentMapClass();
|
||||
private static Optional<Class<?>> DATA_COMPONENT_HOLDER_CLASS = MinecraftReflection.getDataComponentHolderClass();
|
||||
|
||||
static {
|
||||
initialize();
|
||||
}
|
||||
|
||||
private static void initialize() {
|
||||
if (DATA_COMPONENT_MAP_CLASS.isEmpty() || DATA_COMPONENT_HOLDER_CLASS.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Class<?> mapClass = DATA_COMPONENT_MAP_CLASS.get();
|
||||
Class<?> holderClass = DATA_COMPONENT_HOLDER_CLASS.get();
|
||||
FuzzyReflection fuzzy = FuzzyReflection.fromClass(holderClass, true);
|
||||
GET_COMPONENTS = Accessors.getMethodAccessor(fuzzy.getMethod(FuzzyMethodContract.newBuilder()
|
||||
.parameterCount(0)
|
||||
.returnTypeExact(mapClass)
|
||||
.build()));
|
||||
GET_COMPONENT = Accessors.getMethodAccessor(fuzzy.getMethod(FuzzyMethodContract.newBuilder()
|
||||
.parameterCount(1)
|
||||
//.requireModifier(Modifier.PUBLIC)
|
||||
.banModifier(Modifier.STATIC)
|
||||
.parameterExactType(MinecraftReflection.getMinecraftClass("core.component.DataComponentType"))
|
||||
.build()));
|
||||
}
|
||||
|
||||
public WrappedDataComponentHolder(Object handle) {
|
||||
super(DATA_COMPONENT_HOLDER_CLASS.orElseThrow(() -> new IllegalStateException("DataComponentHolder class is not available in this version")));
|
||||
setHandle(handle);
|
||||
}
|
||||
|
||||
public Map<String, WrappedDataComponent> getAllComponents() {
|
||||
Iterable<?> components = (Iterable<?>) GET_COMPONENTS.invoke(handle);
|
||||
Map<String, WrappedDataComponent> wrapped = new HashMap<>();
|
||||
for (Object componentHandle : components) {
|
||||
WrappedDataComponent component = WrappedDataComponent.fromHandle(componentHandle);
|
||||
wrapped.put(component.getKey(), component);
|
||||
}
|
||||
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
public WrappedDataComponent getComponent(String key) {
|
||||
Object keyHandle = WrappedRegistry.getDataComponentTypeRegistry().get(key);
|
||||
Object valueHandle = GET_COMPONENT.invoke(handle, keyHandle);
|
||||
return new WrappedDataComponent(keyHandle, key, valueHandle);
|
||||
}
|
||||
|
||||
public static WrappedDataComponentHolder fromItemStack(ItemStack itemStack) {
|
||||
Object nmsStack = MinecraftReflection.getMinecraftItemStack(itemStack);
|
||||
return new WrappedDataComponentHolder(nmsStack);
|
||||
}
|
||||
}
|
||||
@@ -36,12 +36,12 @@ import com.comphenix.protocol.reflect.accessors.ConstructorAccessor;
|
||||
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.comphenix.protocol.utility.Validate;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.EntityPose;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
|
||||
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -35,23 +35,18 @@ public class WrappedGameProfile extends AbstractWrapper {
|
||||
GAME_PROFILE, String.class, String.class);
|
||||
private static final ConstructorAccessor CREATE_UUID_STRING = Accessors.getConstructorAccessorOrNull(
|
||||
GAME_PROFILE, UUID.class, String.class);
|
||||
private static final ConstructorAccessor CREATE_UUID_STRING_PROPERTIES = Accessors.getConstructorAccessorOrNull(
|
||||
GAME_PROFILE, UUID.class, String.class, MinecraftReflection.getGameProfilePropertyMapClass());
|
||||
|
||||
private static final FieldAccessor GET_UUID_STRING = Accessors.getFieldAccessorOrNull(
|
||||
GAME_PROFILE, "id", String.class);
|
||||
|
||||
private static final MethodAccessor GET_ID = findMethodAccessor(GAME_PROFILE, "id", "getId");
|
||||
private static final MethodAccessor GET_NAME = findMethodAccessor(GAME_PROFILE, "name", "getName");
|
||||
private static final MethodAccessor GET_PROPERTIES = findMethodAccessor(
|
||||
GAME_PROFILE, "properties", "getProperties");
|
||||
private static final MethodAccessor IS_COMPLETE = findMethodAccessor(
|
||||
GAME_PROFILE, "complete", "isComplete");
|
||||
|
||||
static MethodAccessor findMethodAccessor(Class<?> type, String methodName, String fallbackName) {
|
||||
MethodAccessor accessor = Accessors.getMethodAccessorOrNull(type, methodName);
|
||||
return accessor != null ? accessor : Accessors.getMethodAccessorOrNull(type, fallbackName);
|
||||
}
|
||||
private static final MethodAccessor GET_ID = Accessors.getMethodAccessorOrNull(
|
||||
GAME_PROFILE, "getId");
|
||||
private static final MethodAccessor GET_NAME = Accessors.getMethodAccessorOrNull(
|
||||
GAME_PROFILE, "getName");
|
||||
private static final MethodAccessor GET_PROPERTIES = Accessors.getMethodAccessorOrNull(
|
||||
GAME_PROFILE, "getProperties");
|
||||
private static final MethodAccessor IS_COMPLETE = Accessors.getMethodAccessorOrNull(
|
||||
GAME_PROFILE, "isComplete");
|
||||
|
||||
// Fetching game profile
|
||||
private static FieldAccessor PLAYER_PROFILE;
|
||||
@@ -122,51 +117,6 @@ public class WrappedGameProfile extends AbstractWrapper {
|
||||
this(parseUUID(id), name);
|
||||
}
|
||||
|
||||
private static Object createHandle(UUID uuid, String name, Multimap<String, WrappedSignedProperty> properties) {
|
||||
if (CREATE_STRING_STRING != null) {
|
||||
return CREATE_STRING_STRING.invoke(uuid != null ? uuid.toString() : null, name);
|
||||
}
|
||||
|
||||
if (CREATE_UUID_STRING == null) {
|
||||
throw new IllegalArgumentException("Unsupported GameProfile constructor.");
|
||||
}
|
||||
|
||||
if (!MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
|
||||
return CREATE_UUID_STRING.invoke(uuid, name);
|
||||
}
|
||||
|
||||
// 1.20.2+ requires all fields to have a value: null uuid -> UUID(0,0), null name -> empty name
|
||||
// it's not allowed to pass null for both, so we need to pre-check that
|
||||
if (uuid == null && (name == null || name.isEmpty())) {
|
||||
throw new IllegalArgumentException("Name and ID cannot both be blank");
|
||||
}
|
||||
|
||||
// 1.21.9+ made PropertyMap's underlying map immutable, so we need to override it with a mutable map
|
||||
if (MinecraftVersion.v1_21_9.atOrAbove()) {
|
||||
return CREATE_UUID_STRING_PROPERTIES.invoke(uuid == null ? MinecraftGenerator.SYS_UUID : uuid, name == null ? "" : name,
|
||||
convertPropertyMap(properties));
|
||||
}
|
||||
|
||||
return CREATE_UUID_STRING.invoke(uuid == null ? MinecraftGenerator.SYS_UUID : uuid, name == null ? "" : name);
|
||||
}
|
||||
|
||||
private static Object convertPropertyMap(Multimap<String, WrappedSignedProperty> properties) {
|
||||
com.comphenix.protocol.wrappers.MutablePropertyMap map =
|
||||
new com.comphenix.protocol.wrappers.MutablePropertyMap();
|
||||
|
||||
if (properties == null || properties.isEmpty()) {
|
||||
return map;
|
||||
}
|
||||
|
||||
for (String key : properties.keySet()) {
|
||||
for (WrappedSignedProperty property : properties.get(key)) {
|
||||
map.put(key, (com.mojang.authlib.properties.Property) property.getHandle());
|
||||
}
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new game profile with the given properties.
|
||||
* <p>
|
||||
@@ -177,12 +127,24 @@ public class WrappedGameProfile extends AbstractWrapper {
|
||||
*/
|
||||
public WrappedGameProfile(UUID uuid, String name) {
|
||||
super(GAME_PROFILE);
|
||||
setHandle(createHandle(uuid, name, null));
|
||||
}
|
||||
|
||||
public WrappedGameProfile(UUID uuid, String name, Multimap<String, WrappedSignedProperty> properties) {
|
||||
super(GAME_PROFILE);
|
||||
setHandle(createHandle(uuid, name, properties));
|
||||
if (CREATE_STRING_STRING != null) {
|
||||
setHandle(CREATE_STRING_STRING.invoke(uuid != null ? uuid.toString() : null, name));
|
||||
} else if (CREATE_UUID_STRING != null) {
|
||||
if (MinecraftVersion.CONFIG_PHASE_PROTOCOL_UPDATE.atOrAbove()) {
|
||||
// 1.20.2+ requires all fields to have a value: null uuid -> UUID(0,0), null name -> empty name
|
||||
// it's not allowed to pass null for both, so we need to pre-check that
|
||||
if (uuid == null && (name == null || name.isEmpty())) {
|
||||
throw new IllegalArgumentException("Name and ID cannot both be blank");
|
||||
}
|
||||
|
||||
setHandle(CREATE_UUID_STRING.invoke(uuid == null ? MinecraftGenerator.SYS_UUID : uuid, name == null ? "" : name));
|
||||
} else {
|
||||
setHandle(CREATE_UUID_STRING.invoke(uuid, name));
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported GameProfile constructor.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -195,12 +157,7 @@ public class WrappedGameProfile extends AbstractWrapper {
|
||||
if (handle == null)
|
||||
return null;
|
||||
|
||||
WrappedGameProfile delegate = new WrappedGameProfile(handle);
|
||||
if (MinecraftVersion.v1_21_9.atOrAbove()) {
|
||||
return new WrappedGameProfile(delegate.getUUID(), delegate.getName(), delegate.getProperties());
|
||||
} else {
|
||||
return delegate;
|
||||
}
|
||||
return new WrappedGameProfile(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -312,15 +269,7 @@ public class WrappedGameProfile extends AbstractWrapper {
|
||||
|
||||
if (result == null) {
|
||||
Multimap properties = (Multimap) GET_PROPERTIES.invoke(handle);
|
||||
|
||||
Multimap inner;
|
||||
if (MinecraftVersion.v1_21_9.atOrAbove()) {
|
||||
inner = properties;
|
||||
} else {
|
||||
inner = GuavaWrappers.getBukkitMultimap(properties);
|
||||
}
|
||||
|
||||
result = new ConvertedMultimap<String, Object, WrappedSignedProperty>(inner) {
|
||||
result = new ConvertedMultimap<String, Object, WrappedSignedProperty>(GuavaWrappers.getBukkitMultimap(properties)) {
|
||||
@Override
|
||||
protected Object toInner(WrappedSignedProperty outer) {
|
||||
return outer.handle;
|
||||
|
||||
@@ -3,11 +3,8 @@ package com.comphenix.protocol.wrappers;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import com.comphenix.protocol.reflect.EquivalentConverter;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -52,19 +49,11 @@ public final class WrappedLevelChunkData {
|
||||
static {
|
||||
FuzzyReflection reflection = FuzzyReflection.fromClass(HANDLE_TYPE, true);
|
||||
|
||||
if (MinecraftVersion.v26_3.atOrAbove()) {
|
||||
LEVEL_CHUNK_PACKET_DATA_CONSTRUCTOR = Accessors.getConstructorAccessor(reflection.getConstructor(FuzzyMethodContract.newBuilder()
|
||||
.parameterExactType(Map.class)
|
||||
.parameterExactType(byte[].class)
|
||||
.parameterExactType(List.class)
|
||||
.build()));
|
||||
} else {
|
||||
LEVEL_CHUNK_PACKET_DATA_CONSTRUCTOR = Accessors.getConstructorAccessor(reflection.getConstructor(FuzzyMethodContract.newBuilder()
|
||||
.parameterDerivedOf(MinecraftReflection.getPacketDataSerializerClass())
|
||||
.parameterExactType(int.class)
|
||||
.parameterExactType(int.class)
|
||||
.build()));
|
||||
}
|
||||
LEVEL_CHUNK_PACKET_DATA_CONSTRUCTOR = Accessors.getConstructorAccessor(reflection.getConstructor(FuzzyMethodContract.newBuilder()
|
||||
.parameterDerivedOf(MinecraftReflection.getPacketDataSerializerClass())
|
||||
.parameterExactType(int.class)
|
||||
.parameterExactType(int.class)
|
||||
.build()));
|
||||
BLOCK_ENTITIES_DATA_ACCESSOR = Accessors.getFieldAccessor(reflection.getField(FuzzyFieldContract.newBuilder()
|
||||
.typeExact(List.class)
|
||||
.build()));
|
||||
@@ -191,12 +180,7 @@ public final class WrappedLevelChunkData {
|
||||
*/
|
||||
@Deprecated
|
||||
public static ChunkData fromValues(NbtCompound heightmapsTag, byte[] buffer, List<BlockEntityInfo> blockEntityInfo) {
|
||||
ChunkData data;
|
||||
if (MinecraftVersion.v26_3.atOrAbove()) {
|
||||
data = new ChunkData(LEVEL_CHUNK_PACKET_DATA_CONSTRUCTOR.invoke(Collections.emptyMap(), new byte[0], Collections.emptyList()));
|
||||
} else {
|
||||
data = new ChunkData(LEVEL_CHUNK_PACKET_DATA_CONSTRUCTOR.invoke(StructureCache.newNullDataSerializer(), 0, 0));
|
||||
}
|
||||
ChunkData data = new ChunkData(LEVEL_CHUNK_PACKET_DATA_CONSTRUCTOR.invoke(StructureCache.newNullDataSerializer(), 0, 0));
|
||||
|
||||
data.setHeightmapsTag(heightmapsTag);
|
||||
data.setBuffer(buffer);
|
||||
@@ -214,12 +198,7 @@ public final class WrappedLevelChunkData {
|
||||
* @return a newly created wrapper
|
||||
*/
|
||||
public static ChunkData fromValues(Map<EnumWrappers.HeightmapType, long[]> heightmaps, byte[] buffer, List<BlockEntityInfo> blockEntityInfo) {
|
||||
ChunkData data;
|
||||
if (MinecraftVersion.v26_3.atOrAbove()) {
|
||||
data = new ChunkData(LEVEL_CHUNK_PACKET_DATA_CONSTRUCTOR.invoke(Collections.emptyMap(), new byte[0], Collections.emptyList()));
|
||||
} else {
|
||||
data = new ChunkData(LEVEL_CHUNK_PACKET_DATA_CONSTRUCTOR.invoke(StructureCache.newNullDataSerializer(), 0, 0));
|
||||
}
|
||||
ChunkData data = new ChunkData(LEVEL_CHUNK_PACKET_DATA_CONSTRUCTOR.invoke(StructureCache.newNullDataSerializer(), 0, 0));
|
||||
|
||||
data.setHeightmaps(heightmaps);
|
||||
data.setBuffer(buffer);
|
||||
@@ -454,29 +433,18 @@ public final class WrappedLevelChunkData {
|
||||
|
||||
static {
|
||||
FuzzyReflection reflection = FuzzyReflection.fromClass(HANDLE_TYPE, true);
|
||||
List<Field> posFields = reflection.getFieldList(FuzzyFieldContract.newBuilder().typeExact(int.class).build());
|
||||
|
||||
if (MinecraftVersion.v26_3.atOrAbove()) {
|
||||
BLOCK_ENTITY_INFO_CONSTRUCTOR = Accessors.getConstructorAccessor(HANDLE_TYPE, byte.class, short.class,
|
||||
MinecraftReflection.getBlockEntityTypeClass(), Optional.class);
|
||||
PACKED_XZ_ACCESSOR = new IntegerFieldAccessor(Accessors.getFieldAccessor(HANDLE_TYPE, byte.class, true), Number::byteValue);
|
||||
Y_ACCESSOR = new IntegerFieldAccessor(Accessors.getFieldAccessor(HANDLE_TYPE, short.class, true), Number::shortValue);
|
||||
TAG_ACCESSOR = Accessors.getFieldAccessor(reflection.getField(FuzzyFieldContract.newBuilder()
|
||||
.typeExact(Optional.class)
|
||||
.build()));
|
||||
} else {
|
||||
List<Field> posFields = reflection.getFieldList(FuzzyFieldContract.newBuilder().typeExact(int.class).build());
|
||||
|
||||
BLOCK_ENTITY_INFO_CONSTRUCTOR = Accessors.getConstructorAccessor(HANDLE_TYPE, int.class, int.class,
|
||||
MinecraftReflection.getBlockEntityTypeClass(), MinecraftReflection.getNBTCompoundClass());
|
||||
PACKED_XZ_ACCESSOR = Accessors.getFieldAccessor(posFields.get(0));
|
||||
Y_ACCESSOR = Accessors.getFieldAccessor(posFields.get(1));
|
||||
TAG_ACCESSOR = Accessors.getFieldAccessor(reflection.getField(FuzzyFieldContract.newBuilder()
|
||||
.typeExact(MinecraftReflection.getNBTCompoundClass())
|
||||
.build()));
|
||||
}
|
||||
BLOCK_ENTITY_INFO_CONSTRUCTOR = Accessors.getConstructorAccessor(HANDLE_TYPE, int.class, int.class,
|
||||
MinecraftReflection.getBlockEntityTypeClass(), MinecraftReflection.getNBTCompoundClass());
|
||||
PACKED_XZ_ACCESSOR = Accessors.getFieldAccessor(posFields.get(0));
|
||||
Y_ACCESSOR = Accessors.getFieldAccessor(posFields.get(1));
|
||||
TYPE_ACCESSOR = Accessors.getFieldAccessor(reflection.getField(FuzzyFieldContract.newBuilder()
|
||||
.typeExact(MinecraftReflection.getBlockEntityTypeClass())
|
||||
.build()));
|
||||
TAG_ACCESSOR = Accessors.getFieldAccessor(reflection.getField(FuzzyFieldContract.newBuilder()
|
||||
.typeExact(MinecraftReflection.getNBTCompoundClass())
|
||||
.build()));
|
||||
}
|
||||
|
||||
public BlockEntityInfo(Object handle) {
|
||||
@@ -565,9 +533,6 @@ public final class WrappedLevelChunkData {
|
||||
@Nullable
|
||||
public NbtCompound getAdditionalData() {
|
||||
Object tagHandle = TAG_ACCESSOR.get(handle);
|
||||
if (MinecraftVersion.v26_3.atOrAbove()) {
|
||||
tagHandle = ((Optional<Object>) tagHandle).orElse(null);
|
||||
}
|
||||
|
||||
return tagHandle == null ? null : NbtFactory.fromNMSCompound(tagHandle);
|
||||
}
|
||||
@@ -578,11 +543,7 @@ public final class WrappedLevelChunkData {
|
||||
* @param additionalData the additional data for this block entity, can be {@code null}
|
||||
*/
|
||||
public void setAdditionalData(@Nullable NbtCompound additionalData) {
|
||||
if (MinecraftVersion.v26_3.atOrAbove()) {
|
||||
TAG_ACCESSOR.set(handle, Optional.ofNullable(additionalData).map(data -> NbtFactory.fromBase(data).getHandle()));
|
||||
} else {
|
||||
TAG_ACCESSOR.set(handle, additionalData == null ? null : NbtFactory.fromBase(additionalData).getHandle());
|
||||
}
|
||||
TAG_ACCESSOR.set(handle, additionalData == null ? null : NbtFactory.fromBase(additionalData).getHandle());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -607,46 +568,12 @@ public final class WrappedLevelChunkData {
|
||||
* @param additionalData An NBT-Tag containing additional information. Can be {@code null}.
|
||||
*/
|
||||
public static BlockEntityInfo fromValues(int sectionX, int sectionZ, int y, MinecraftKey typeKey, @Nullable NbtCompound additionalData) {
|
||||
if (MinecraftVersion.v26_3.atOrAbove()) {
|
||||
return new BlockEntityInfo(BLOCK_ENTITY_INFO_CONSTRUCTOR.invoke(
|
||||
(byte) (sectionX << 4 | sectionZ),
|
||||
(short) y,
|
||||
REGISTRY.get(typeKey),
|
||||
Optional.ofNullable(additionalData).map(data -> NbtFactory.fromBase(data).getHandle())
|
||||
));
|
||||
} else {
|
||||
return new BlockEntityInfo(BLOCK_ENTITY_INFO_CONSTRUCTOR.invoke(
|
||||
return new BlockEntityInfo(BLOCK_ENTITY_INFO_CONSTRUCTOR.invoke(
|
||||
sectionX << 4 | sectionZ,
|
||||
y,
|
||||
REGISTRY.get(typeKey),
|
||||
additionalData == null ? null : NbtFactory.fromBase(additionalData).getHandle()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final static class IntegerFieldAccessor implements FieldAccessor {
|
||||
private final FieldAccessor inner;
|
||||
private final Function<Number, Object> toType;
|
||||
|
||||
public IntegerFieldAccessor(FieldAccessor inner, Function<Number, Object> toType) {
|
||||
this.inner = inner;
|
||||
this.toType = toType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object get(Object instance) {
|
||||
return ((Number) this.inner.get(instance)).intValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(Object instance, Object value) {
|
||||
this.inner.set(instance, this.toType.apply((Integer) value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Field getField() {
|
||||
return this.inner.getField();
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,15 +27,6 @@ public class WrappedParticle<T> {
|
||||
private static MethodAccessor toNMS;
|
||||
private static MethodAccessor toCraftData;
|
||||
|
||||
private static final class ItemStackTemplateAccessor {
|
||||
private static final Class<?> TYPE = MinecraftReflection.getMinecraftClass("world.item.ItemStackTemplate");
|
||||
private static final MethodAccessor CREATE_ITEM_STACK = Accessors.getMethodAccessor(
|
||||
FuzzyReflection.fromClass(TYPE).getMethod(FuzzyMethodContract.newBuilder()
|
||||
.returnTypeExact(MinecraftReflection.getItemStackClass())
|
||||
.parameterCount(0)
|
||||
.build()));
|
||||
}
|
||||
|
||||
private static void ensureMethods() {
|
||||
if (toBukkit != null && toNMS != null) {
|
||||
return;
|
||||
@@ -185,15 +176,6 @@ public class WrappedParticle<T> {
|
||||
}
|
||||
|
||||
private static Object getItem(Object handle) {
|
||||
if (MinecraftVersion.v26_1.atOrAbove()) {
|
||||
Object template = new StructureModifier<>(handle.getClass())
|
||||
.withTarget(handle)
|
||||
.withType(ItemStackTemplateAccessor.TYPE)
|
||||
.read(0);
|
||||
Object itemStack = ItemStackTemplateAccessor.CREATE_ITEM_STACK.invoke(template);
|
||||
return BukkitConverters.getItemStackConverter().getSpecific(itemStack);
|
||||
}
|
||||
|
||||
return new StructureModifier<>(handle.getClass())
|
||||
.withTarget(handle)
|
||||
.withType(MinecraftReflection.getItemStackClass(), BukkitConverters.getItemStackConverter())
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import com.comphenix.protocol.reflect.EquivalentConverter;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.ConstructorAccessor;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
* Wrapper around the NMS {@code PositionMoveRotation} record, introduced in Minecraft 1.21.2.
|
||||
* <p>
|
||||
* This type is used in packets such as {@code ENTITY_TELEPORT} and {@code ENTITY_POSITION_SYNC}
|
||||
* to represent combined position, movement delta and rotation.
|
||||
* <p>
|
||||
* Example usage:
|
||||
* <pre>{@code
|
||||
* WrappedPositionMoveRotation posRot = WrappedPositionMoveRotation.create(
|
||||
* new Vector(x, y, z), // position
|
||||
* new Vector(0, 0, 0), // deltaMovement
|
||||
* yaw, // yRot
|
||||
* pitch // xRot
|
||||
* );
|
||||
* packet.getPositionMoveRotation().write(0, posRot);
|
||||
* }</pre>
|
||||
*/
|
||||
public class WrappedPositionMoveRotation extends AbstractWrapper {
|
||||
|
||||
private static Class<?> NMS_CLASS;
|
||||
private static ConstructorAccessor CONSTRUCTOR;
|
||||
private static StructureModifier<Object> BASE_MODIFIER;
|
||||
|
||||
private final StructureModifier<Object> modifier;
|
||||
|
||||
private WrappedPositionMoveRotation(Object handle) {
|
||||
super(getNmsClass());
|
||||
setHandle(handle);
|
||||
this.modifier = getBaseModifier().withTarget(handle);
|
||||
}
|
||||
|
||||
private static Class<?> getNmsClass() {
|
||||
if (NMS_CLASS == null) {
|
||||
NMS_CLASS = MinecraftReflection.getPositionMoveRotationClass();
|
||||
}
|
||||
return NMS_CLASS;
|
||||
}
|
||||
|
||||
private static StructureModifier<Object> getBaseModifier() {
|
||||
if (BASE_MODIFIER == null) {
|
||||
BASE_MODIFIER = new StructureModifier<>(getNmsClass());
|
||||
}
|
||||
return BASE_MODIFIER;
|
||||
}
|
||||
|
||||
private static ConstructorAccessor getConstructor() {
|
||||
if (CONSTRUCTOR == null) {
|
||||
CONSTRUCTOR = Accessors.getConstructorAccessor(
|
||||
getNmsClass(),
|
||||
MinecraftReflection.getVec3DClass(),
|
||||
MinecraftReflection.getVec3DClass(),
|
||||
float.class,
|
||||
float.class
|
||||
);
|
||||
}
|
||||
return CONSTRUCTOR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code WrappedPositionMoveRotation} from the given NMS handle.
|
||||
*
|
||||
* @param handle - the NMS {@code PositionMoveRotation} instance.
|
||||
* @return the wrapper.
|
||||
*/
|
||||
public static WrappedPositionMoveRotation fromHandle(Object handle) {
|
||||
return new WrappedPositionMoveRotation(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@code WrappedPositionMoveRotation} with the given values.
|
||||
*
|
||||
* @param position - the absolute position.
|
||||
* @param deltaMovement - the movement delta (velocity).
|
||||
* @param yRot - the yaw rotation.
|
||||
* @param xRot - the pitch rotation.
|
||||
* @return a new wrapper instance.
|
||||
*/
|
||||
public static WrappedPositionMoveRotation create(Vector position, Vector deltaMovement, float yRot, float xRot) {
|
||||
EquivalentConverter<Vector> conv = BukkitConverters.getVectorConverter();
|
||||
Object handle = getConstructor().invoke(
|
||||
conv.getGeneric(position),
|
||||
conv.getGeneric(deltaMovement),
|
||||
yRot,
|
||||
xRot
|
||||
);
|
||||
return new WrappedPositionMoveRotation(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the absolute position component.
|
||||
*
|
||||
* @return the position as a Bukkit {@link Vector}.
|
||||
*/
|
||||
public Vector getPosition() {
|
||||
return modifier.withType(MinecraftReflection.getVec3DClass(), BukkitConverters.getVectorConverter()).read(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the absolute position component.
|
||||
*
|
||||
* @param position - the new position.
|
||||
*/
|
||||
public void setPosition(Vector position) {
|
||||
modifier.withType(MinecraftReflection.getVec3DClass(), BukkitConverters.getVectorConverter()).write(0, position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the movement delta (velocity) component.
|
||||
*
|
||||
* @return the delta movement as a Bukkit {@link Vector}.
|
||||
*/
|
||||
public Vector getDeltaMovement() {
|
||||
return modifier.withType(MinecraftReflection.getVec3DClass(), BukkitConverters.getVectorConverter()).read(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the movement delta (velocity) component.
|
||||
*
|
||||
* @param deltaMovement - the new delta movement.
|
||||
*/
|
||||
public void setDeltaMovement(Vector deltaMovement) {
|
||||
modifier.withType(MinecraftReflection.getVec3DClass(), BukkitConverters.getVectorConverter()).write(1, deltaMovement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the yaw rotation (y-axis rotation).
|
||||
*
|
||||
* @return the yaw as a float.
|
||||
*/
|
||||
public float getYRot() {
|
||||
StructureModifier<Float> floats = modifier.withType(float.class);
|
||||
return floats.read(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the yaw rotation (y-axis rotation).
|
||||
*
|
||||
* @param yRot - the new yaw value.
|
||||
*/
|
||||
public void setYRot(float yRot) {
|
||||
modifier.withType(float.class).write(0, yRot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the pitch rotation (x-axis rotation).
|
||||
*
|
||||
* @return the pitch as a float.
|
||||
*/
|
||||
public float getXRot() {
|
||||
StructureModifier<Float> floats = modifier.withType(float.class);
|
||||
return floats.read(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pitch rotation (x-axis rotation).
|
||||
*
|
||||
* @param xRot - the new pitch value.
|
||||
*/
|
||||
public void setXRot(float xRot) {
|
||||
modifier.withType(float.class).write(1, xRot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an {@link EquivalentConverter} that converts between {@code WrappedPositionMoveRotation}
|
||||
* and the underlying NMS handle.
|
||||
*
|
||||
* @return the converter.
|
||||
*/
|
||||
public static EquivalentConverter<WrappedPositionMoveRotation> getConverter() {
|
||||
return Converters.handle(AbstractWrapper::getHandle,
|
||||
WrappedPositionMoveRotation::fromHandle, WrappedPositionMoveRotation.class);
|
||||
}
|
||||
}
|
||||
@@ -1,207 +0,0 @@
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.comphenix.protocol.reflect.EquivalentConverter;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.ConstructorAccessor;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
/**
|
||||
* Wrapper around the NMS {@code PositionPath} type, introduced in Minecraft 26.3.
|
||||
* <p>
|
||||
* Used by {@code ENTITY_POSITION_SYNC} to store the entity position. A path is either linear (a single position) or
|
||||
* stepped (several positions reached at given ticks).
|
||||
* <pre>{@code
|
||||
* packet.getPositionPaths().write(0, WrappedPositionPath.linear(new Vector(x, y, z)));
|
||||
* }</pre>
|
||||
*/
|
||||
public final class WrappedPositionPath extends AbstractWrapper {
|
||||
|
||||
private static Class<?> STEPPED_CLASS;
|
||||
|
||||
private static ConstructorAccessor LINEAR_CONSTRUCTOR;
|
||||
private static ConstructorAccessor STEPPED_CONSTRUCTOR;
|
||||
private static ConstructorAccessor STEP_CONSTRUCTOR;
|
||||
|
||||
private static StructureModifier<Object> LINEAR_MODIFIER;
|
||||
private static StructureModifier<Object> STEPPED_MODIFIER;
|
||||
private static StructureModifier<Object> STEP_MODIFIER;
|
||||
|
||||
private static volatile boolean initialized;
|
||||
|
||||
private WrappedPositionPath(Object handle) {
|
||||
super(getPositionPathClass());
|
||||
setHandle(handle);
|
||||
}
|
||||
|
||||
private static Class<?> getPositionPathClass() {
|
||||
return MinecraftReflection.getPositionPathClass()
|
||||
.orElseThrow(() -> new UnsupportedOperationException("PositionPath requires Minecraft 26.3 or newer"));
|
||||
}
|
||||
|
||||
private static void initialize() {
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
Class<?> pathClass = getPositionPathClass();
|
||||
Class<?> vec3Class = MinecraftReflection.getVec3DClass();
|
||||
Class<?> linearClass = null;
|
||||
Class<?> stepClass = null;
|
||||
|
||||
for (Class<?> nested : pathClass.getDeclaredClasses()) {
|
||||
if (!pathClass.isAssignableFrom(nested)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Field steps = getListField(nested);
|
||||
if (steps != null) {
|
||||
STEPPED_CLASS = nested;
|
||||
stepClass = (Class<?>) ((ParameterizedType) steps.getGenericType()).getActualTypeArguments()[0];
|
||||
} else {
|
||||
linearClass = nested;
|
||||
}
|
||||
}
|
||||
|
||||
Preconditions.checkState(linearClass != null && STEPPED_CLASS != null, "Unable to find PositionPath implementations");
|
||||
|
||||
LINEAR_CONSTRUCTOR = Accessors.getConstructorAccessor(linearClass, vec3Class);
|
||||
STEPPED_CONSTRUCTOR = Accessors.getConstructorAccessor(STEPPED_CLASS, List.class);
|
||||
STEP_CONSTRUCTOR = Accessors.getConstructorAccessor(stepClass, vec3Class, int.class);
|
||||
|
||||
LINEAR_MODIFIER = new StructureModifier<>(linearClass);
|
||||
STEPPED_MODIFIER = new StructureModifier<>(STEPPED_CLASS);
|
||||
STEP_MODIFIER = new StructureModifier<>(stepClass);
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
private static Field getListField(Class<?> clazz) {
|
||||
for (Field field : clazz.getDeclaredFields()) {
|
||||
if (List.class.equals(field.getType())) {
|
||||
return field;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static WrappedPositionPath fromHandle(Object handle) {
|
||||
return new WrappedPositionPath(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a linear path.
|
||||
*
|
||||
* @param position - the absolute position.
|
||||
* @return the path.
|
||||
*/
|
||||
public static WrappedPositionPath linear(Vector position) {
|
||||
Preconditions.checkNotNull(position, "position cannot be NULL");
|
||||
initialize();
|
||||
return new WrappedPositionPath(LINEAR_CONSTRUCTOR.invoke(BukkitConverters.getVectorConverter().getGeneric(position)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a stepped path ending at the position of the last step.
|
||||
*
|
||||
* @param steps - the steps in order, must not be empty.
|
||||
* @return the path.
|
||||
*/
|
||||
public static WrappedPositionPath stepped(List<Step> steps) {
|
||||
Preconditions.checkArgument(steps != null && !steps.isEmpty(), "steps cannot be empty");
|
||||
initialize();
|
||||
|
||||
EquivalentConverter<Vector> vectorConverter = BukkitConverters.getVectorConverter();
|
||||
List<Object> handles = new ArrayList<>(steps.size());
|
||||
for (Step step : steps) {
|
||||
handles.add(STEP_CONSTRUCTOR.invoke(vectorConverter.getGeneric(step.getPosition()), step.getTickOffset()));
|
||||
}
|
||||
|
||||
return new WrappedPositionPath(STEPPED_CONSTRUCTOR.invoke(Collections.unmodifiableList(handles)));
|
||||
}
|
||||
|
||||
public boolean isStepped() {
|
||||
initialize();
|
||||
return STEPPED_CLASS.isInstance(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the final position of the path.
|
||||
*/
|
||||
public Vector getEndPosition() {
|
||||
StructureModifier<Object> modifier = isStepped() ? STEPPED_MODIFIER : LINEAR_MODIFIER;
|
||||
return modifier.withTarget(handle)
|
||||
.withType(MinecraftReflection.getVec3DClass(), BukkitConverters.getVectorConverter())
|
||||
.read(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the steps of a stepped path.
|
||||
* @throws IllegalStateException if the path is linear.
|
||||
*/
|
||||
public List<Step> getSteps() {
|
||||
Preconditions.checkState(isStepped(), "Linear paths have no steps");
|
||||
|
||||
List<?> handles = STEPPED_MODIFIER.withTarget(handle).<List<?>>withType(List.class).read(0);
|
||||
List<Step> steps = new ArrayList<>(handles.size());
|
||||
for (Object stepHandle : handles) {
|
||||
StructureModifier<Object> step = STEP_MODIFIER.withTarget(stepHandle);
|
||||
Vector position = step.withType(MinecraftReflection.getVec3DClass(), BukkitConverters.getVectorConverter()).read(0);
|
||||
steps.add(new Step(position, step.<Integer>withType(int.class).read(0)));
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(steps);
|
||||
}
|
||||
|
||||
public static EquivalentConverter<WrappedPositionPath> getConverter() {
|
||||
return Converters.ignoreNull(Converters.handle(AbstractWrapper::getHandle,
|
||||
WrappedPositionPath::fromHandle, WrappedPositionPath.class));
|
||||
}
|
||||
|
||||
public static final class Step {
|
||||
|
||||
private final Vector position;
|
||||
private final int tickOffset;
|
||||
|
||||
public Step(Vector position, int tickOffset) {
|
||||
this.position = Preconditions.checkNotNull(position, "position cannot be NULL").clone();
|
||||
this.tickOffset = tickOffset;
|
||||
}
|
||||
|
||||
public Vector getPosition() {
|
||||
return position.clone();
|
||||
}
|
||||
|
||||
public int getTickOffset() {
|
||||
return tickOffset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Step)) return false;
|
||||
|
||||
Step that = (Step) obj;
|
||||
return tickOffset == that.tickOffset && position.equals(that.position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(position, tickOffset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Step[position=" + position + ", tickOffset=" + tickOffset + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,5 @@
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyMatchers;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
@@ -19,21 +10,79 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import com.comphenix.protocol.reflect.FuzzyReflection;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyMatchers;
|
||||
import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
|
||||
public class WrappedRegistry {
|
||||
// map of NMS class to registry instance
|
||||
private static final Map<Class<?>, WrappedRegistry> REGISTRY;
|
||||
private static final Map<Class<?>, WrappedRegistry> BY_CLASS;
|
||||
private static final Map<String, WrappedRegistry> BY_KEY;
|
||||
|
||||
private static final MethodAccessor GET;
|
||||
private static final MethodAccessor GET_ID;
|
||||
private static final MethodAccessor GET_KEY;
|
||||
private static final MethodAccessor GET_BY_KEY;
|
||||
private static final MethodAccessor GET_ITEM_ID;
|
||||
private static final MethodAccessor GET_ITEM_KEY;
|
||||
private static final MethodAccessor GET_REGISTRY_KEY;
|
||||
|
||||
private static final MethodAccessor GET_HOLDER;
|
||||
|
||||
static {
|
||||
Map<Class<?>, WrappedRegistry> regMap = new HashMap<>();
|
||||
Class<?> iRegistry = MinecraftReflection.getIRegistry();
|
||||
FuzzyReflection fuzzy = FuzzyReflection.fromClass(iRegistry, false);
|
||||
|
||||
GET_BY_KEY = Accessors.getMethodAccessor(fuzzy.getMethod(FuzzyMethodContract
|
||||
.newBuilder()
|
||||
.parameterCount(1)
|
||||
.returnTypeMatches(FuzzyMatchers.and(FuzzyMatchers.assignable(Object.class), FuzzyMatchers.except(Optional.class)))
|
||||
.requireModifier(Modifier.ABSTRACT)
|
||||
.parameterExactType(MinecraftReflection.getMinecraftKeyClass())
|
||||
.build()));
|
||||
GET_ITEM_ID = Accessors.getMethodAccessor(fuzzy.getMethod(FuzzyMethodContract
|
||||
.newBuilder()
|
||||
.parameterCount(1)
|
||||
.returnTypeExact(int.class)
|
||||
.requireModifier(Modifier.ABSTRACT)
|
||||
.parameterDerivedOf(Object.class)
|
||||
.build()));
|
||||
GET_ITEM_KEY = Accessors.getMethodAccessor(fuzzy.getMethod(FuzzyMethodContract
|
||||
.newBuilder()
|
||||
.parameterCount(1)
|
||||
.returnTypeExact(MinecraftReflection.getMinecraftKeyClass())
|
||||
.build()));
|
||||
GET_REGISTRY_KEY = Accessors.getMethodAccessor(fuzzy.getMethod(FuzzyMethodContract
|
||||
.newBuilder()
|
||||
.parameterCount(0)
|
||||
.returnTypeExact(MinecraftReflection.getResourceKey())
|
||||
.build()));
|
||||
|
||||
MethodAccessor getHolder = null;
|
||||
|
||||
if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) {
|
||||
try {
|
||||
getHolder = Accessors.getMethodAccessor(fuzzy.getMethod(FuzzyMethodContract
|
||||
.newBuilder()
|
||||
.parameterCount(1)
|
||||
.banModifier(Modifier.STATIC)
|
||||
.returnTypeExact(MinecraftReflection.getHolderClass())
|
||||
.requireModifier(Modifier.PUBLIC)
|
||||
.build()));
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
GET_HOLDER = getHolder;
|
||||
|
||||
Map<Class<?>, WrappedRegistry> byClass = new HashMap<>();
|
||||
Map<String, WrappedRegistry> byKey = new HashMap<>();
|
||||
|
||||
// get the possible registry fields
|
||||
Class<?> iRegistry = MinecraftReflection.getIRegistry();
|
||||
|
||||
Class<?> builtInRegistries = MinecraftReflection.getBuiltInRegistries();
|
||||
Set<Field> registries = FuzzyReflection.combineArrays(
|
||||
iRegistry == null ? null : iRegistry.getFields(),
|
||||
@@ -43,95 +92,75 @@ public class WrappedRegistry {
|
||||
for (Field field : registries) {
|
||||
try {
|
||||
// make sure it's actually a registry
|
||||
if (iRegistry.isAssignableFrom(field.getType())) {
|
||||
Type genType = field.getGenericType();
|
||||
if (genType instanceof ParameterizedType) {
|
||||
ParameterizedType par = (ParameterizedType) genType;
|
||||
Type paramType = par.getActualTypeArguments()[0];
|
||||
if (paramType instanceof Class) {
|
||||
// for example Registry<Item>
|
||||
regMap.put((Class<?>) paramType, new WrappedRegistry(field.get(null)));
|
||||
} else if (paramType instanceof ParameterizedType) {
|
||||
// for example Registry<EntityType<?>>
|
||||
par = (ParameterizedType) paramType;
|
||||
paramType = par.getActualTypeArguments()[0];
|
||||
if (paramType instanceof WildcardType) {
|
||||
// some registry types are even more nested, but we don't want them
|
||||
// for example Registry<Codec<ChunkGenerator>>, Registry<Codec<WorldChunkManager>>
|
||||
WildcardType wildcard = (WildcardType) paramType;
|
||||
if (wildcard.getUpperBounds().length != 1 || wildcard.getLowerBounds().length > 0) {
|
||||
continue;
|
||||
}
|
||||
if (!iRegistry.isAssignableFrom(field.getType())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// we only want types with an undefined upper bound (aka. ?)
|
||||
if (wildcard.getUpperBounds()[0] != Object.class) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
Type genType = field.getGenericType();
|
||||
if (!(genType instanceof ParameterizedType par)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
paramType = par.getRawType();
|
||||
if (paramType instanceof Class<?>) {
|
||||
// there might be duplicate registries, like the codec registries
|
||||
// we don't want them to be registered here
|
||||
regMap.put((Class<?>) paramType, new WrappedRegistry(field.get(null)));
|
||||
}
|
||||
Class<?> registryClass = null;
|
||||
|
||||
Type paramType = par.getActualTypeArguments()[0];
|
||||
if (paramType instanceof Class<?> paramClass) {
|
||||
// for example Registry<Item>
|
||||
registryClass = paramClass;
|
||||
} else if (paramType instanceof ParameterizedType) {
|
||||
// for example Registry<EntityType<?>>
|
||||
par = (ParameterizedType) paramType;
|
||||
paramType = par.getActualTypeArguments()[0];
|
||||
if (paramType instanceof WildcardType wildcard) {
|
||||
// some registry types are even more nested, but we don't want them
|
||||
// for example Registry<Codec<ChunkGenerator>>, Registry<Codec<WorldChunkManager>>
|
||||
if (wildcard.getUpperBounds().length != 1 || wildcard.getLowerBounds().length > 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// we only want types with an undefined upper bound (aka. ?)
|
||||
if (wildcard.getUpperBounds()[0] != Object.class) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
paramType = par.getRawType();
|
||||
if (paramType instanceof Class<?> paramClass) {
|
||||
// there might be duplicate registries, like the codec registries
|
||||
// we don't want them to be registered here
|
||||
registryClass = paramClass;
|
||||
}
|
||||
}
|
||||
|
||||
Object handle = field.get(null);
|
||||
ResourceKey key = ResourceKey.fromGeneric(GET_REGISTRY_KEY.invoke(handle));
|
||||
WrappedRegistry wrapped = new WrappedRegistry(handle, key);
|
||||
|
||||
if (registryClass != null) {
|
||||
byClass.put(registryClass, wrapped);
|
||||
}
|
||||
|
||||
String registryName = key.getLocation().getFullKey();
|
||||
byKey.put(registryName, wrapped);
|
||||
} catch (ReflectiveOperationException ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
REGISTRY = ImmutableMap.copyOf(regMap);
|
||||
|
||||
FuzzyReflection fuzzy = FuzzyReflection.fromClass(iRegistry, false);
|
||||
GET = Accessors.getMethodAccessor(fuzzy.getMethod(FuzzyMethodContract
|
||||
.newBuilder()
|
||||
.parameterCount(1)
|
||||
.returnTypeMatches(FuzzyMatchers.and(FuzzyMatchers.assignable(Object.class), FuzzyMatchers.except(Optional.class)))
|
||||
.requireModifier(Modifier.ABSTRACT)
|
||||
.parameterExactType(MinecraftReflection.getMinecraftKeyClass())
|
||||
.build()));
|
||||
GET_ID = Accessors.getMethodAccessor(fuzzy.getMethod(FuzzyMethodContract
|
||||
.newBuilder()
|
||||
.parameterCount(1)
|
||||
.returnTypeExact(int.class)
|
||||
.requireModifier(Modifier.ABSTRACT)
|
||||
.parameterDerivedOf(Object.class)
|
||||
.build()));
|
||||
GET_KEY = Accessors.getMethodAccessor(fuzzy.getMethod(FuzzyMethodContract
|
||||
.newBuilder()
|
||||
.parameterCount(1)
|
||||
.returnTypeExact(MinecraftReflection.getMinecraftKeyClass())
|
||||
.build()));
|
||||
|
||||
MethodAccessor getHolder = null;
|
||||
|
||||
if (MinecraftVersion.FEATURE_PREVIEW_UPDATE.atOrAbove()) {
|
||||
try {
|
||||
getHolder = Accessors.getMethodAccessor(fuzzy.getMethod(FuzzyMethodContract
|
||||
.newBuilder()
|
||||
.parameterCount(1)
|
||||
.banModifier(Modifier.STATIC)
|
||||
.returnTypeExact(MinecraftReflection.getHolderClass())
|
||||
.requireModifier(Modifier.PUBLIC)
|
||||
.build()));
|
||||
} catch (IllegalArgumentException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
GET_HOLDER = getHolder;
|
||||
BY_CLASS = ImmutableMap.copyOf(byClass);
|
||||
BY_KEY = ImmutableMap.copyOf(byKey);
|
||||
}
|
||||
|
||||
private final Object handle;
|
||||
private final ResourceKey key;
|
||||
|
||||
private WrappedRegistry(Object handle) {
|
||||
private WrappedRegistry(Object handle, ResourceKey key) {
|
||||
this.handle = handle;
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public Object get(MinecraftKey key) {
|
||||
return GET.invoke(handle, MinecraftKey.getConverter().getGeneric(key));
|
||||
return GET_BY_KEY.invoke(handle, MinecraftKey.getConverter().getGeneric(key));
|
||||
}
|
||||
|
||||
public Object get(String key) {
|
||||
@@ -139,7 +168,11 @@ public class WrappedRegistry {
|
||||
}
|
||||
|
||||
public MinecraftKey getKey(Object generic) {
|
||||
return MinecraftKey.getConverter().getSpecific(GET_KEY.invoke(handle, generic));
|
||||
return MinecraftKey.getConverter().getSpecific(GET_ITEM_KEY.invoke(handle, generic));
|
||||
}
|
||||
|
||||
public ResourceKey getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public int getId(MinecraftKey key) {
|
||||
@@ -151,7 +184,7 @@ public class WrappedRegistry {
|
||||
}
|
||||
|
||||
public int getId(Object entry) {
|
||||
return (int) GET_ID.invoke(this.handle, entry);
|
||||
return (int) GET_ITEM_ID.invoke(this.handle, entry);
|
||||
}
|
||||
|
||||
public Object getHolder(Object generic) {
|
||||
@@ -170,7 +203,15 @@ public class WrappedRegistry {
|
||||
return getRegistry(MinecraftReflection.getSoundEffectClass());
|
||||
}
|
||||
|
||||
public static WrappedRegistry getDataComponentTypeRegistry() {
|
||||
return getByKey("minecraft:data_component_type");
|
||||
}
|
||||
|
||||
public static WrappedRegistry getRegistry(Class<?> type) {
|
||||
return REGISTRY.get(type);
|
||||
return BY_CLASS.get(type);
|
||||
}
|
||||
|
||||
public static WrappedRegistry getByKey(String key) {
|
||||
return BY_KEY.get(key);
|
||||
}
|
||||
}
|
||||
@@ -16,26 +16,15 @@ import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
public class WrappedStatistic extends AbstractWrapper {
|
||||
private static final Class<?> STATISTIC = MinecraftReflection.getStatisticClass();
|
||||
private static final Class<?> STATISTIC_LIST = MinecraftReflection.getStatisticListClass();
|
||||
private static final FieldAccessor GET_NAME_FIELD;
|
||||
private static final MethodAccessor GET_NAME_METHOD;
|
||||
|
||||
|
||||
static {
|
||||
FieldAccessor[] nameFields = Accessors.getFieldAccessorArray(STATISTIC, String.class, true);
|
||||
if (nameFields.length > 0) {
|
||||
GET_NAME_FIELD = nameFields[0];
|
||||
GET_NAME_METHOD = null;
|
||||
} else {
|
||||
GET_NAME_FIELD = null;
|
||||
GET_NAME_METHOD = Accessors.getMethodAccessor(
|
||||
FuzzyReflection.fromClass(STATISTIC.getSuperclass(), true)
|
||||
.getMethodByReturnTypeAndParameters("getName", String.class));
|
||||
}
|
||||
|
||||
try {
|
||||
FIND_STATISTICS = Accessors.getMethodAccessor(
|
||||
FuzzyReflection.fromClass(STATISTIC_LIST).getMethodByReturnTypeAndParameters(
|
||||
"findStatistic", STATISTIC, new Class<?>[]{String.class}));
|
||||
MAP_ACCESSOR = Accessors.getFieldAccessor(STATISTIC_LIST, Map.class, true);
|
||||
GET_NAME = Accessors.getFieldAccessor(STATISTIC, String.class, true);
|
||||
} catch (Exception ex) {
|
||||
// TODO - find an alternative
|
||||
}
|
||||
@@ -43,6 +32,7 @@ public class WrappedStatistic extends AbstractWrapper {
|
||||
|
||||
private static MethodAccessor FIND_STATISTICS;
|
||||
private static FieldAccessor MAP_ACCESSOR;
|
||||
private static FieldAccessor GET_NAME;
|
||||
|
||||
private final String name;
|
||||
|
||||
@@ -50,9 +40,7 @@ public class WrappedStatistic extends AbstractWrapper {
|
||||
super(STATISTIC);
|
||||
setHandle(handle);
|
||||
|
||||
this.name = GET_NAME_FIELD != null
|
||||
? (String) GET_NAME_FIELD.get(handle)
|
||||
: (String) GET_NAME_METHOD.invoke(handle);
|
||||
this.name = (String) GET_NAME.get(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,8 +3,6 @@ package com.comphenix.protocol.wrappers;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import com.comphenix.protocol.injector.StructureCache;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
@@ -92,26 +90,12 @@ public class WrappedTeamParameters extends AbstractWrapper {
|
||||
|
||||
@NotNull
|
||||
public EnumWrappers.ChatFormatting getColor() {
|
||||
if (MinecraftVersion.v26_2.atOrAbove()) {
|
||||
Optional<?> optional = modifier.<Optional<?>>withType(Optional.class).read(0);
|
||||
Object teamColor = optional != null ? optional.orElse(null) : null;
|
||||
if (teamColor == null) {
|
||||
return EnumWrappers.ChatFormatting.RESET;
|
||||
}
|
||||
|
||||
return EnumWrappers.ChatFormatting.valueOf(((Enum<?>) teamColor).name());
|
||||
}
|
||||
|
||||
return modifier
|
||||
.withType(EnumWrappers.getChatFormattingClass(), EnumWrappers.getChatFormattingConverter())
|
||||
.read(0);
|
||||
}
|
||||
|
||||
public int getOptions() {
|
||||
if (MinecraftVersion.v26_2.atOrAbove()) {
|
||||
return (byte) modifier.withType(byte.class).read(0);
|
||||
}
|
||||
|
||||
return (int) modifier.withType(int.class).read(0);
|
||||
}
|
||||
|
||||
@@ -226,27 +210,9 @@ public class WrappedTeamParameters extends AbstractWrapper {
|
||||
wrapped.modifier.withType(String.class).writeSafely(1, collisionRule.toString());
|
||||
}
|
||||
|
||||
if (MinecraftVersion.v26_2.atOrAbove()) {
|
||||
wrapped.modifier.withType(Optional.class).write(0, Optional.ofNullable(toNmsTeamColor(color)));
|
||||
wrapped.modifier.withType(byte.class).write(0, (byte) options);
|
||||
} else {
|
||||
wrapped.modifier.withType(EnumWrappers.getChatFormattingClass()).write(0, EnumWrappers.getChatFormattingConverter().getGeneric(color));
|
||||
wrapped.modifier.withType(int.class).write(0, options);
|
||||
}
|
||||
wrapped.modifier.withType(EnumWrappers.getChatFormattingClass()).write(0, EnumWrappers.getChatFormattingConverter().getGeneric(color));
|
||||
wrapped.modifier.withType(int.class).write(0, options);
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
private static Object toNmsTeamColor(EnumWrappers.ChatFormatting color) {
|
||||
Class<?> teamColorClass = MinecraftReflection.getTeamColorClass()
|
||||
.orElseThrow(() -> new IllegalStateException("TeamColor class doesn't exist on this server version"));
|
||||
|
||||
try {
|
||||
return Enum.valueOf((Class) teamColorClass, color.name());
|
||||
} catch (IllegalArgumentException ex) {
|
||||
// formatting-only values (e.g. RESET) don't map to a team color
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,237 +0,0 @@
|
||||
package com.comphenix.protocol.wrappers;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import com.comphenix.protocol.reflect.EquivalentConverter;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.ConstructorAccessor;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
/**
|
||||
* Wrapper around the NMS {@code VecDelta} type, introduced in Minecraft 26.3.
|
||||
* <p>
|
||||
* Used by {@code REL_ENTITY_MOVE} and {@code REL_ENTITY_MOVE_LOOK} to store the position change. A delta is either
|
||||
* linear (a single offset) or stepped (several offsets reached at given ticks). Offsets use the same encoding as the
|
||||
* short fields of older versions.
|
||||
* <pre>{@code
|
||||
* packet.getVecDeltas().write(0, WrappedVecDelta.linear(deltaX, deltaY, deltaZ));
|
||||
* }</pre>
|
||||
*/
|
||||
public final class WrappedVecDelta extends AbstractWrapper {
|
||||
|
||||
private static Class<?> STEPPED_CLASS;
|
||||
|
||||
private static ConstructorAccessor LINEAR_CONSTRUCTOR;
|
||||
private static ConstructorAccessor STEPPED_CONSTRUCTOR;
|
||||
private static ConstructorAccessor STEP_CONSTRUCTOR;
|
||||
|
||||
private static StructureModifier<Object> LINEAR_MODIFIER;
|
||||
private static StructureModifier<Object> STEPPED_MODIFIER;
|
||||
private static StructureModifier<Object> STEP_MODIFIER;
|
||||
|
||||
private static volatile boolean initialized;
|
||||
|
||||
private WrappedVecDelta(Object handle) {
|
||||
super(getVecDeltaClass());
|
||||
setHandle(handle);
|
||||
}
|
||||
|
||||
private static Class<?> getVecDeltaClass() {
|
||||
return MinecraftReflection.getVecDeltaClass()
|
||||
.orElseThrow(() -> new UnsupportedOperationException("VecDelta requires Minecraft 26.3 or newer"));
|
||||
}
|
||||
|
||||
private static void initialize() {
|
||||
if (initialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
Class<?> vecDeltaClass = getVecDeltaClass();
|
||||
Class<?> linearClass = null;
|
||||
Class<?> stepClass = null;
|
||||
|
||||
for (Class<?> nested : vecDeltaClass.getDeclaredClasses()) {
|
||||
if (!vecDeltaClass.isAssignableFrom(nested)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Field steps = getListField(nested);
|
||||
if (steps != null) {
|
||||
STEPPED_CLASS = nested;
|
||||
stepClass = (Class<?>) ((ParameterizedType) steps.getGenericType()).getActualTypeArguments()[0];
|
||||
} else {
|
||||
linearClass = nested;
|
||||
}
|
||||
}
|
||||
|
||||
Preconditions.checkState(linearClass != null && STEPPED_CLASS != null, "Unable to find VecDelta implementations");
|
||||
|
||||
LINEAR_CONSTRUCTOR = Accessors.getConstructorAccessor(linearClass, short.class, short.class, short.class);
|
||||
STEPPED_CONSTRUCTOR = Accessors.getConstructorAccessor(STEPPED_CLASS, List.class);
|
||||
STEP_CONSTRUCTOR = Accessors.getConstructorAccessor(stepClass, short.class, short.class, short.class, int.class);
|
||||
|
||||
LINEAR_MODIFIER = new StructureModifier<>(linearClass);
|
||||
STEPPED_MODIFIER = new StructureModifier<>(STEPPED_CLASS);
|
||||
STEP_MODIFIER = new StructureModifier<>(stepClass);
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
private static Field getListField(Class<?> clazz) {
|
||||
for (Field field : clazz.getDeclaredFields()) {
|
||||
if (List.class.equals(field.getType())) {
|
||||
return field;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static WrappedVecDelta fromHandle(Object handle) {
|
||||
return new WrappedVecDelta(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a linear delta.
|
||||
*
|
||||
* @param deltaX - the encoded x offset.
|
||||
* @param deltaY - the encoded y offset.
|
||||
* @param deltaZ - the encoded z offset.
|
||||
* @return the delta.
|
||||
*/
|
||||
public static WrappedVecDelta linear(short deltaX, short deltaY, short deltaZ) {
|
||||
initialize();
|
||||
return new WrappedVecDelta(LINEAR_CONSTRUCTOR.invoke(deltaX, deltaY, deltaZ));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a stepped delta.
|
||||
*
|
||||
* @param steps - the steps in order, must not be empty.
|
||||
* @return the delta.
|
||||
*/
|
||||
public static WrappedVecDelta stepped(List<Step> steps) {
|
||||
Preconditions.checkArgument(steps != null && !steps.isEmpty(), "steps cannot be empty");
|
||||
initialize();
|
||||
|
||||
List<Object> handles = new ArrayList<>(steps.size());
|
||||
for (Step step : steps) {
|
||||
handles.add(STEP_CONSTRUCTOR.invoke(step.getDeltaX(), step.getDeltaY(), step.getDeltaZ(), step.getTicks()));
|
||||
}
|
||||
|
||||
return new WrappedVecDelta(STEPPED_CONSTRUCTOR.invoke(Collections.unmodifiableList(handles)));
|
||||
}
|
||||
|
||||
public boolean isStepped() {
|
||||
initialize();
|
||||
return STEPPED_CLASS.isInstance(handle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the encoded x offset of a linear delta.
|
||||
* @throws IllegalStateException if the delta is stepped.
|
||||
*/
|
||||
public short getDeltaX() {
|
||||
return readLinear(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the encoded y offset of a linear delta.
|
||||
* @throws IllegalStateException if the delta is stepped.
|
||||
*/
|
||||
public short getDeltaY() {
|
||||
return readLinear(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the encoded z offset of a linear delta.
|
||||
* @throws IllegalStateException if the delta is stepped.
|
||||
*/
|
||||
public short getDeltaZ() {
|
||||
return readLinear(2);
|
||||
}
|
||||
|
||||
private short readLinear(int index) {
|
||||
Preconditions.checkState(!isStepped(), "Stepped deltas have no single offset");
|
||||
return LINEAR_MODIFIER.withTarget(handle).<Short>withType(short.class).read(index);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the steps of a stepped delta.
|
||||
* @throws IllegalStateException if the delta is linear.
|
||||
*/
|
||||
public List<Step> getSteps() {
|
||||
Preconditions.checkState(isStepped(), "Linear deltas have no steps");
|
||||
|
||||
List<?> handles = STEPPED_MODIFIER.withTarget(handle).<List<?>>withType(List.class).read(0);
|
||||
List<Step> steps = new ArrayList<>(handles.size());
|
||||
for (Object stepHandle : handles) {
|
||||
StructureModifier<Object> step = STEP_MODIFIER.withTarget(stepHandle);
|
||||
StructureModifier<Short> shorts = step.withType(short.class);
|
||||
steps.add(new Step(shorts.read(0), shorts.read(1), shorts.read(2), step.<Integer>withType(int.class).read(0)));
|
||||
}
|
||||
|
||||
return Collections.unmodifiableList(steps);
|
||||
}
|
||||
|
||||
public static EquivalentConverter<WrappedVecDelta> getConverter() {
|
||||
return Converters.ignoreNull(Converters.handle(AbstractWrapper::getHandle,
|
||||
WrappedVecDelta::fromHandle, WrappedVecDelta.class));
|
||||
}
|
||||
|
||||
public static final class Step {
|
||||
|
||||
private final short deltaX;
|
||||
private final short deltaY;
|
||||
private final short deltaZ;
|
||||
private final int ticks;
|
||||
|
||||
public Step(short deltaX, short deltaY, short deltaZ, int ticks) {
|
||||
this.deltaX = deltaX;
|
||||
this.deltaY = deltaY;
|
||||
this.deltaZ = deltaZ;
|
||||
this.ticks = ticks;
|
||||
}
|
||||
|
||||
public short getDeltaX() {
|
||||
return deltaX;
|
||||
}
|
||||
|
||||
public short getDeltaY() {
|
||||
return deltaY;
|
||||
}
|
||||
|
||||
public short getDeltaZ() {
|
||||
return deltaZ;
|
||||
}
|
||||
|
||||
public int getTicks() {
|
||||
return ticks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof Step)) return false;
|
||||
|
||||
Step that = (Step) obj;
|
||||
return deltaX == that.deltaX && deltaY == that.deltaY && deltaZ == that.deltaZ && ticks == that.ticks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(deltaX, deltaY, deltaZ, ticks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Step[deltaX=" + deltaX + ", deltaY=" + deltaY + ", deltaZ=" + deltaZ + ", ticks=" + ticks + "]";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,8 @@ import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Base64;
|
||||
|
||||
import org.yaml.snakeyaml.external.biz.base64Coder.Base64Coder;
|
||||
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtBase;
|
||||
import com.comphenix.protocol.wrappers.nbt.NbtCompound;
|
||||
@@ -22,7 +23,7 @@ public class NbtTextSerializer {
|
||||
* A default instance of this serializer.
|
||||
*/
|
||||
public static final NbtTextSerializer DEFAULT = new NbtTextSerializer();
|
||||
|
||||
|
||||
private NbtBinarySerializer binarySerializer;
|
||||
|
||||
public NbtTextSerializer() {
|
||||
@@ -58,7 +59,7 @@ public class NbtTextSerializer {
|
||||
binarySerializer.serialize(value, dataOutput);
|
||||
|
||||
// Serialize that array
|
||||
return Base64.getEncoder().encodeToString(outputStream.toByteArray());
|
||||
return Base64Coder.encodeLines(outputStream.toByteArray());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,7 +70,7 @@ public class NbtTextSerializer {
|
||||
* @throws IOException If we are unable to parse the input.
|
||||
*/
|
||||
public <TType> NbtWrapper<TType> deserialize(String input) throws IOException {
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64.getDecoder().decode(input));
|
||||
ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(input));
|
||||
|
||||
return binarySerializer.deserialize(new DataInputStream(inputStream));
|
||||
}
|
||||
|
||||
@@ -7,8 +7,6 @@ import com.comphenix.protocol.reflect.accessors.Accessors;
|
||||
import com.comphenix.protocol.reflect.accessors.ConstructorAccessor;
|
||||
import com.comphenix.protocol.reflect.accessors.FieldAccessor;
|
||||
import com.comphenix.protocol.reflect.accessors.MethodAccessor;
|
||||
import com.comphenix.protocol.reflect.instances.DefaultInstances;
|
||||
import com.comphenix.protocol.reflect.instances.MinecraftGenerator;
|
||||
import com.comphenix.protocol.utility.MinecraftProtocolVersion;
|
||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||
import com.comphenix.protocol.utility.MinecraftVersion;
|
||||
@@ -25,7 +23,6 @@ public final class ServerPingRecord implements ServerPingImpl {
|
||||
private static Class<?> SERVER_PING;
|
||||
private static Class<?> PLAYER_SAMPLE_CLASS;
|
||||
private static Class<?> SERVER_DATA_CLASS;
|
||||
private static Class<?> NAME_AND_ID_CLASS;
|
||||
|
||||
private static Class<?> GSON_CLASS;
|
||||
private static MethodAccessor GSON_TO_JSON;
|
||||
@@ -59,37 +56,13 @@ public final class ServerPingRecord implements ServerPingImpl {
|
||||
PLAYER_SAMPLE_CLASS = MinecraftReflection.getServerPingPlayerSampleClass();
|
||||
SERVER_DATA_CLASS = MinecraftReflection.getServerPingServerDataClass();
|
||||
|
||||
PING_CTOR = Accessors.getConstructorAccessor(SERVER_PING, MinecraftReflection.getIChatBaseComponentClass(), Optional.class, Optional.class, Optional.class, boolean.class);
|
||||
PING_CTOR = Accessors.getConstructorAccessor(SERVER_PING.getConstructors()[0]);
|
||||
|
||||
DATA_WRAPPER = AutoWrapper.wrap(ServerData.class, SERVER_DATA_CLASS);
|
||||
SAMPLE_WRAPPER = AutoWrapper.wrap(PlayerSample.class, PLAYER_SAMPLE_CLASS);
|
||||
FAVICON_WRAPPER = AutoWrapper.wrap(Favicon.class, MinecraftReflection.getMinecraftClass("network.protocol.status.ServerPing$a", "network.protocol.status.ServerStatus$Favicon"));
|
||||
|
||||
if (MinecraftVersion.v1_21_10.atOrAbove()) {
|
||||
NAME_AND_ID_CLASS = MinecraftReflection.getMinecraftClass("server.players.NameAndId");
|
||||
NAME_AND_ID_WRAPPER = AutoWrapper.wrap(NameAndId.class, NAME_AND_ID_CLASS);
|
||||
|
||||
PROFILE_LIST_CONVERTER = BukkitConverters.getListConverter(new EquivalentConverter<>() {
|
||||
@Override
|
||||
public Object getGeneric(WrappedGameProfile specific) {
|
||||
NameAndId wrapper = new NameAndId(specific.getUUID(), specific.getName());
|
||||
return NAME_AND_ID_WRAPPER.getGeneric(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WrappedGameProfile getSpecific(Object generic) {
|
||||
NameAndId wrapper = NAME_AND_ID_WRAPPER.getSpecific(generic);
|
||||
return new WrappedGameProfile(wrapper.id, wrapper.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<WrappedGameProfile> getSpecificType() {
|
||||
return WrappedGameProfile.class;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
PROFILE_LIST_CONVERTER = BukkitConverters.getListConverter(BukkitConverters.getWrappedGameProfileConverter());
|
||||
}
|
||||
PROFILE_LIST_CONVERTER = BukkitConverters.getListConverter(BukkitConverters.getWrappedGameProfileConverter());
|
||||
|
||||
DEFAULT_DESCRIPTION = WrappedChatComponent.fromLegacyText("A Minecraft Server");
|
||||
|
||||
@@ -151,24 +124,11 @@ public final class ServerPingRecord implements ServerPingImpl {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class NameAndId {
|
||||
public UUID id;
|
||||
public String name;
|
||||
|
||||
public NameAndId(UUID id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public NameAndId() {
|
||||
this(MinecraftGenerator.SYS_UUID, "");
|
||||
}
|
||||
}
|
||||
|
||||
private static AutoWrapper<PlayerSample> SAMPLE_WRAPPER;
|
||||
|
||||
private static AutoWrapper<ServerData> DATA_WRAPPER;
|
||||
|
||||
private static AutoWrapper<Favicon> FAVICON_WRAPPER;
|
||||
private static AutoWrapper<NameAndId> NAME_AND_ID_WRAPPER;
|
||||
|
||||
private WrappedChatComponent description;
|
||||
private PlayerSample playerSample;
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
name: ProtocolLib
|
||||
version: ${version}
|
||||
main: com.comphenix.protocol.ProtocolLibPaper
|
||||
api-version: '1.21.8'
|
||||
website: https://github.com/dmulloy2/ProtocolLib
|
||||
load: STARTUP
|
||||
@@ -1,9 +1,9 @@
|
||||
name: ProtocolLib
|
||||
version: ${version}
|
||||
description: Provides read/write access to the Minecraft protocol.
|
||||
authors: [dmulloy2]
|
||||
authors: [dmulloy2, comphenix]
|
||||
|
||||
main: com.comphenix.protocol.ProtocolLib
|
||||
main: com.comphenix.protocol.ProtocolLibSpigot
|
||||
load: STARTUP
|
||||
database: false
|
||||
api-version: "1.13"
|
||||
@@ -44,4 +44,4 @@ permissions:
|
||||
default: op
|
||||
protocol.info:
|
||||
description: Can read update notifications and error reports.
|
||||
default: op
|
||||
default: op
|
||||
Loaded 100 of 138 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user