Compare commits
37
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f7ed5f1fd8 | ||
|
|
db41fe5292 | ||
|
|
25f896c6d1 | ||
|
|
192b622d56 | ||
|
|
25f2ec8fd7 | ||
|
|
c4d0953be8 | ||
|
|
5cd2314965 | ||
|
|
a97869ae44 | ||
|
|
45dca9af9c | ||
|
|
97ed7066b4 | ||
|
|
285e96324d | ||
|
|
e220e992d8 | ||
|
|
aa92479285 | ||
|
|
066c948af8 | ||
|
|
1e5adc00c6 | ||
|
|
fdeb473dba | ||
|
|
048d1ae870 | ||
|
|
a17c5fa767 | ||
|
|
c21d74551d | ||
|
|
98d2c35107 | ||
|
|
a35f8d5b1c | ||
|
|
2a5977fdd2 | ||
|
|
232b20788a | ||
|
|
9962e60c90 | ||
|
|
4da9dc7f33 | ||
|
|
b5ee1c38f2 | ||
|
|
24577569b1 | ||
|
|
76bfb92926 | ||
|
|
f2173e6d5c | ||
|
|
e24151150f | ||
|
|
41be143837 | ||
|
|
74e615ec40 | ||
|
|
30b6d2f33a | ||
|
|
595f15eee0 | ||
|
|
76e0c2274b | ||
|
|
d8fa583e0f | ||
|
|
e2599e036d |
No files matched your search
@@ -1,3 +0,0 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: [retrooper]
|
||||
@@ -1,38 +0,0 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Report bugs to help us improve our software.
|
||||
title: ""
|
||||
labels: bug
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**Software brand**
|
||||
Please let us know what software you are using.
|
||||
Eg. Spigot 1.18.2, Paper 1.18.2, Tuinity 1.18.2, Pufferfish 1.18.2, etc...
|
||||
Make sure to mention the version of the software.
|
||||
|
||||
**Plugins**
|
||||
Please give us a list of your plugins. Sometimes we run into incompatibilities. Having an overview of the plugins on your server can really help identify the problem quicker.
|
||||
Eg. ViaVersion, ProtocolLib, HolographicDisplays
|
||||
You may also provide a screenshot.
|
||||
|
||||
**How To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
*Example:*
|
||||
1. Join with the 1.18.2 vanilla minecraft client.
|
||||
2. Spam
|
||||
3. ....
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
@@ -1,21 +0,0 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: FEATURE REQUEST
|
||||
labels: enhancement
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered to solve your solution without
|
||||
us adding this as a feature?**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
||||
@@ -0,0 +1,39 @@
|
||||
# Automatically build the project and run any configured tests for every push
|
||||
# and submitted pull request. This can help catch issues that only occur on
|
||||
# certain platforms or Java versions, and provides a first line of defence
|
||||
# against bad commits.
|
||||
|
||||
name: build
|
||||
on: [pull_request, push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
strategy:
|
||||
matrix:
|
||||
# Use these Java versions
|
||||
java: [
|
||||
17, # Current Java LTS & minimum supported by Minecraft
|
||||
]
|
||||
# and run on both Linux and Windows
|
||||
os: [ubuntu-20.04, windows-2022]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- name: checkout repository
|
||||
uses: actions/checkout@v2
|
||||
- name: validate gradle wrapper
|
||||
uses: gradle/wrapper-validation-action@v1
|
||||
- name: setup jdk ${{ matrix.java }}
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: ${{ matrix.java }}
|
||||
- name: make gradle wrapper executable
|
||||
if: ${{ runner.os != 'Windows' }}
|
||||
run: chmod +x ./gradlew
|
||||
- name: build
|
||||
run: ./gradlew build
|
||||
- name: capture build artifacts
|
||||
if: ${{ runner.os == 'Linux' && matrix.java == '17' }} # Only upload artifacts built from latest java on one OS
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: Artifacts
|
||||
path: build/libs/
|
||||
@@ -1,67 +0,0 @@
|
||||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
#
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master, dev ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ master, dev ]
|
||||
schedule:
|
||||
- cron: '39 0 * * 0'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'java' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||
# Learn more:
|
||||
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
@@ -1,70 +0,0 @@
|
||||
name: Gradle Package
|
||||
|
||||
on: [ push, pull_request ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Validate gradle wrapper
|
||||
uses: gradle/actions/wrapper-validation@v4
|
||||
|
||||
- name: Set up JDK 21
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: '21'
|
||||
distribution: 'temurin'
|
||||
cache: 'gradle'
|
||||
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
|
||||
settings-path: ${{ github.workspace }} # location for the settings.xml file
|
||||
|
||||
- name: Build with Gradle
|
||||
run: chmod +x gradlew && ./gradlew build
|
||||
|
||||
- name: Upload build artifacts api
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: api-build
|
||||
path: api/build/libs
|
||||
|
||||
- name: Upload build artifacts spigot
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: spigot-build
|
||||
path: spigot/build/libs
|
||||
|
||||
- name: Upload build artifacts netty-common
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: netty-common-build
|
||||
path: netty-common/build/libs
|
||||
|
||||
- name: Upload build artifacts bungeecord
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: bungeecord-build
|
||||
path: bungeecord/build/libs
|
||||
|
||||
- name: Upload build artifacts velocity
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: velocity-build
|
||||
path: velocity/build/libs
|
||||
|
||||
- name: Upload build artifacts fabric
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: fabric-build
|
||||
path: fabric/build/libs
|
||||
|
||||
- name: Upload build artifacts sponge
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: sponge-build
|
||||
path: sponge/build/libs
|
||||
+24
-119
@@ -1,128 +1,33 @@
|
||||
# User-specific stuff
|
||||
/.idea
|
||||
# gradle
|
||||
|
||||
.gradle/
|
||||
build/
|
||||
out/
|
||||
classes/
|
||||
|
||||
# eclipse
|
||||
|
||||
*.launch
|
||||
|
||||
# idea
|
||||
|
||||
.idea/
|
||||
*.iml
|
||||
*.ipr
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
# vscode
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
Thumbs.db:encryptable
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
.gradle
|
||||
build/
|
||||
bin/
|
||||
|
||||
# Ignore Gradle GUI config
|
||||
gradle-app.setting
|
||||
|
||||
# Cache of project
|
||||
.gradletasknamecache
|
||||
|
||||
**/build/
|
||||
|
||||
# Common working directory
|
||||
run/
|
||||
|
||||
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
|
||||
!gradle-wrapper.jar
|
||||
/src/main/resources/plugin.yml
|
||||
/.idea/
|
||||
.vscode/
|
||||
.project
|
||||
.settings/
|
||||
.vscode/
|
||||
bin/
|
||||
.classpath
|
||||
.project
|
||||
|
||||
# Build Source Kotlin
|
||||
/buildSrc/.kotlin/
|
||||
# macos
|
||||
|
||||
*.DS_Store
|
||||
|
||||
# fabric
|
||||
|
||||
run/
|
||||
@@ -671,4 +671,4 @@ into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
@@ -1,40 +1,9 @@
|
||||
<!--suppress HtmlDeprecatedAttribute -->
|
||||
<div align="center">
|
||||
<h2><i>PacketEvents</i></h2>
|
||||
<h3><i>A powerful networking library for Minecraft packet processing and manipulation.</i></h3>
|
||||
<a href="https://github.com/retrooper/packetevents/actions"><img src="https://img.shields.io/github/actions/workflow/status/retrooper/packetevents/gradle-publish.yml?style=for-the-badge&logo=github"></a>
|
||||
<a href="https://discord.gg/DVHxPPxHZc"><img src="https://img.shields.io/discord/721686193061888071?color=5562e9&logo=discord&logoColor=white&style=for-the-badge"></a>
|
||||
<img src="https://img.shields.io/github/license/retrooper/packetevents?style=for-the-badge&logo=github">
|
||||
<a href="https://bstats.org/plugin/bukkit/packetevents/11327"><img src="https://img.shields.io/bstats/servers/11327?style=for-the-badge"></a>
|
||||
<a href="https://github.com/retrooper/packetevents/releases"><img src="https://img.shields.io/github/downloads/retrooper/packetevents/total.svg?style=for-the-badge&logo=github"></a>
|
||||
</div>
|
||||
<h3>Resources</h3>
|
||||
# Fabric Example Mod
|
||||
|
||||
- [Read documentation](https://docs.packetevents.com/)
|
||||
- [Getting Started](https://docs.packetevents.com/getting-started)
|
||||
- [JavaDocs](https://javadocs.packetevents.com)
|
||||
- [Releases](https://github.com/retrooper/packetevents/releases/)
|
||||
- [Modrinth](https://modrinth.com/plugin/packetevents)
|
||||
- [GitHub](https://github.com/retrooper/packetevents/releases/)
|
||||
- [SpigotMC](https://www.spigotmc.org/resources/packetevents-api.80279/)
|
||||
- [Development Builds](https://ci.codemc.io/job/retrooper/job/packetevents)
|
||||
- [Statistics](https://bstats.org/plugin/bukkit/packetevents/11327)
|
||||
## Setup
|
||||
|
||||
<h3>Sponsors</h3>
|
||||
For setup instructions please see the [fabric wiki page](https://fabricmc.net/wiki/tutorial:setup) that relates to the IDE that you are using.
|
||||
|
||||
<i>Thanks to the following sponsors for supporting this project:</i>
|
||||
## License
|
||||
|
||||
<a href="https://pebblehost.com"><img src="https://pebblehost.com/src/img/logos/main-old.png" width=150><br>
|
||||
|
||||
<a href="https://www.ej-technologies.com"><img src="https://www.ej-technologies.com/images/product_banners/jprofiler_small.png"><br>
|
||||
|
||||
<h3>Credits</h3>
|
||||
|
||||
<i>Here are some projects that we are heavily inspired by, thus we have integrated</i>\
|
||||
<i>small portions of their code into our work.</i>
|
||||
|
||||
[Protocol Documentation for the Minecraft Java Edition](https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Protocol)\
|
||||
[ViaVersion](https://github.com/ViaVersion/ViaVersion)\
|
||||
[ProtocolSupport](https://github.com/ProtocolSupport/ProtocolSupport)\
|
||||
[adventure](https://github.com/KyoriPowered/adventure)\
|
||||
[MCProtocolLib](https://github.com/GeyserMC/MCProtocolLib/)
|
||||
This template is available under the CC0 license. Feel free to learn from it and incorporate it in your own projects.
|
||||
@@ -1,4 +0,0 @@
|
||||
# Table of contents
|
||||
|
||||
* [Initial page](README.md)
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
import com.github.retrooper.compression.strategy.dir.JsonBase64DataDirStrategy
|
||||
import com.github.retrooper.compression.strategy.dir.JsonRegistryCompressionDirStrategy
|
||||
import com.github.retrooper.compression.strategy.dir.JsonToNbtDirStrategy
|
||||
import com.github.retrooper.excludeAdventure
|
||||
|
||||
plugins {
|
||||
packetevents.`shadow-conventions`
|
||||
packetevents.`library-conventions`
|
||||
`mapping-compression`
|
||||
`pe-version`
|
||||
}
|
||||
|
||||
// papermc repo + disableAutoTargetJvm needed for mockbukkit
|
||||
repositories {
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
|
||||
java {
|
||||
withJavadocJar()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnlyApi(libs.bundles.adventure)
|
||||
compileOnlyApi(libs.bundles.adventure.serializers)
|
||||
implementation(libs.adventure.api)
|
||||
api(project(":patch:adventure-text-serializer-gson", "shadow")) {
|
||||
excludeAdventure()
|
||||
}
|
||||
api(libs.adventure.text.serializer.legacy) {
|
||||
excludeAdventure()
|
||||
}
|
||||
compileOnly(libs.gson)
|
||||
|
||||
testImplementation(libs.bundles.adventure)
|
||||
testImplementation(project(":patch:adventure-text-serializer-gson"))
|
||||
testImplementation(libs.adventure.text.serializer.legacy)
|
||||
testImplementation(project(":netty-common"))
|
||||
testImplementation(testlibs.mockbukkit)
|
||||
testImplementation(testlibs.slf4j)
|
||||
testImplementation(testlibs.bundles.junit)
|
||||
testImplementation(libs.netty)
|
||||
testImplementation(libs.classgraph)
|
||||
}
|
||||
|
||||
mappingCompression {
|
||||
mappingDirectory = rootDir.resolve("mappings")
|
||||
outDirectory = project.layout.buildDirectory.dir("mappings/generated/assets/mappings")
|
||||
|
||||
with<JsonToNbtDirStrategy> {
|
||||
compress("data")
|
||||
}
|
||||
with<JsonBase64DataDirStrategy> {
|
||||
compress("item_base_components")
|
||||
}
|
||||
with<JsonRegistryCompressionDirStrategy> {
|
||||
compress("registries")
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
assemble {
|
||||
setDependsOn(dependsOn.filterNot { it == "shadowNoAdventure" })
|
||||
}
|
||||
|
||||
javadoc {
|
||||
mustRunAfter(generateVersionsFile)
|
||||
}
|
||||
|
||||
sourcesJar {
|
||||
mustRunAfter(generateVersionsFile)
|
||||
}
|
||||
|
||||
withType<JavaCompile> {
|
||||
dependsOn(generateVersionsFile)
|
||||
}
|
||||
|
||||
processResources {
|
||||
dependsOn(compressMappings)
|
||||
from(project.layout.buildDirectory.dir("mappings/generated").get())
|
||||
}
|
||||
|
||||
generateVersionsFile {
|
||||
packageName = "com.github.retrooper.packetevents.util"
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
shadowJar {
|
||||
exclude {
|
||||
val path = it.path
|
||||
path.startsWith("net/kyori") && !path.startsWith("net/kyori/adventure/text/serializer") && !path.startsWith(
|
||||
"net/kyori/option"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
named<MavenPublication>("shadow") {
|
||||
artifact(tasks["javadocJar"])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
public final class PacketEvents {
|
||||
private static PacketEventsAPI<?> API;
|
||||
|
||||
//Put these variable names anywhere else, they are really only for the injectors
|
||||
@ApiStatus.Internal
|
||||
public static String IDENTIFIER, ENCODER_NAME, DECODER_NAME, CONNECTION_HANDLER_NAME, SERVER_CHANNEL_HANDLER_NAME,
|
||||
TIMEOUT_HANDLER_NAME;
|
||||
|
||||
public static PacketEventsAPI<?> getAPI() {
|
||||
return API;
|
||||
}
|
||||
|
||||
public static void setAPI(PacketEventsAPI<?> api) {
|
||||
API = api;
|
||||
}
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents;
|
||||
|
||||
import com.github.retrooper.packetevents.event.EventManager;
|
||||
import com.github.retrooper.packetevents.injector.ChannelInjector;
|
||||
import com.github.retrooper.packetevents.manager.player.PlayerManager;
|
||||
import com.github.retrooper.packetevents.manager.protocol.ProtocolManager;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerManager;
|
||||
import com.github.retrooper.packetevents.netty.NettyManager;
|
||||
import com.github.retrooper.packetevents.settings.PacketEventsSettings;
|
||||
import com.github.retrooper.packetevents.util.LogManager;
|
||||
import com.github.retrooper.packetevents.util.PEVersion;
|
||||
//Note: The PEVersions class is generated. Refer to PEVersionTask.kt
|
||||
import com.github.retrooper.packetevents.util.PEVersions;
|
||||
import com.github.retrooper.packetevents.util.updatechecker.UpdateChecker;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public abstract class PacketEventsAPI<T> {
|
||||
private final EventManager eventManager = new EventManager();
|
||||
private final PacketEventsSettings settings = new PacketEventsSettings();
|
||||
private final UpdateChecker updateChecker = new UpdateChecker();
|
||||
private final LogManager logManager = new LogManager();
|
||||
private static final Logger LOGGER = Logger.getLogger(PacketEventsAPI.class.getName());
|
||||
|
||||
public EventManager getEventManager() {
|
||||
return eventManager;
|
||||
}
|
||||
|
||||
public PacketEventsSettings getSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
public UpdateChecker getUpdateChecker() {
|
||||
return updateChecker;
|
||||
}
|
||||
|
||||
public PEVersion getVersion() {
|
||||
//Note: The PEVersions class is generated by the auto-version task. Refer to PEVersionTask.kt
|
||||
return PEVersions.CURRENT;
|
||||
}
|
||||
|
||||
public Logger getLogger() {
|
||||
return LOGGER;
|
||||
}
|
||||
|
||||
public LogManager getLogManager() {
|
||||
return logManager;
|
||||
}
|
||||
|
||||
public abstract void load();
|
||||
|
||||
public abstract boolean isLoaded();
|
||||
|
||||
public abstract void init();
|
||||
|
||||
public abstract boolean isInitialized();
|
||||
|
||||
public abstract void terminate();
|
||||
|
||||
public abstract boolean isTerminated();
|
||||
|
||||
public abstract T getPlugin();
|
||||
|
||||
public abstract ServerManager getServerManager();
|
||||
|
||||
public abstract ProtocolManager getProtocolManager();
|
||||
|
||||
public abstract PlayerManager getPlayerManager();
|
||||
|
||||
public abstract NettyManager getNettyManager();
|
||||
|
||||
public abstract ChannelInjector getInjector();
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.github.retrooper.packetevents.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.annotation.Documented;
|
||||
|
||||
/**
|
||||
* Marks an API element as obsolete and makes this information available
|
||||
* at runtime via reflection. Use in conjunction with an IDE-recognized
|
||||
* annotation like @ApiStatus.Obsolete if IDE warnings are also desired.
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.FIELD}) // Adjust targets as needed
|
||||
public @interface RuntimeObsolete {
|
||||
/**
|
||||
* Specifies in which version the API became obsolete.
|
||||
* Should generally match the value in the corresponding @ApiStatus.Obsolete annotation.
|
||||
*/
|
||||
String since() default "";
|
||||
|
||||
/**
|
||||
* Optional: Add a reason or replacement suggestion.
|
||||
*/
|
||||
String reason() default "";
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
import com.github.retrooper.packetevents.event.PacketEvent;
|
||||
import com.github.retrooper.packetevents.event.PacketListenerAbstract;
|
||||
|
||||
/**
|
||||
* The {@link PacketEvent} implements this interface.
|
||||
* Every inbuilt event should implement the {@link #call(PacketListenerCommon)} method.
|
||||
* If you are making a custom event, don't implement this.
|
||||
* The {@link PacketListenerCommon#onPacketEventExternal(PacketEvent)} method is called for every event that is not in-built.
|
||||
* including custom events.
|
||||
*
|
||||
* @author retrooper
|
||||
* @since 1.8
|
||||
*/
|
||||
public interface CallableEvent {
|
||||
default void call(PacketListenerCommon listener) {
|
||||
listener.onPacketEventExternal((PacketEvent) this);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
|
||||
|
||||
/**
|
||||
* Every event that supports cancellation should implement this interface.
|
||||
* PacketEvents' event system lets the highest priority listener be have the highest priority
|
||||
* in deciding whether the event will cancel.
|
||||
* This means an event with a lower priority than the higher priority one would not be able to decide.
|
||||
* Cancelling the event means the action assosiated with the event will be cancelled.
|
||||
* For example, cancelling the {@link PacketReceiveEvent}
|
||||
* will prevent minecraft from processing the incoming packet.
|
||||
*
|
||||
* @author retrooper
|
||||
* @see PacketReceiveEvent
|
||||
* @since 1.7
|
||||
*/
|
||||
public interface CancellableEvent {
|
||||
|
||||
/**
|
||||
* This method returns if the event will be cancelled.
|
||||
*
|
||||
* @return Will the event be cancelled.
|
||||
*/
|
||||
boolean isCancelled();
|
||||
|
||||
/**
|
||||
* Cancel or proceed with the event.
|
||||
*
|
||||
* @param val Is the event cancelled
|
||||
*/
|
||||
void setCancelled(boolean val);
|
||||
}
|
||||
@@ -1,185 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.exception.InvalidHandshakeException;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* Class for event managing. Implements both, internal and API methods.
|
||||
*
|
||||
* @apiNote It is highly recommended to register the event listeners at server start-up,
|
||||
* without frequent modifications during runtime, since this class needs to recalculate all of
|
||||
* its event listeners during any modifications. In other words, it assumes that reads (events fired)
|
||||
* greatly outnumber writes (listeners modifications). If your case requires frequent listener modifications,
|
||||
* open a pull request on GitHub and describe your case.
|
||||
*
|
||||
* @author retrooper
|
||||
* @author ShadowOfHeaven (optimization)
|
||||
*
|
||||
*/
|
||||
|
||||
public class EventManager {
|
||||
|
||||
//Using a ConcurrentHashMap is faster and more secure here, compared to Collections.synchronizedMap(new EnumMap<>(PacketListenerPriority.class))
|
||||
//This is mainly due to:
|
||||
//1. On each modification Collections.synchronizedMap synchronizes the whole Map object, while ConcurrentHashMap only it's internal, currently modified Node
|
||||
//2. ConcurrentHashMap won't fail in a multi-thread environment, while Collections.synchronizedMap is said to have a lot of potential problems,
|
||||
//being a generalized method for synchronization
|
||||
private final Map<PacketListenerPriority, Set<PacketListenerCommon>> listenersMap = new ConcurrentHashMap<>();
|
||||
//Since reads greatly outnumber writes, create an array for the best possible iteration time
|
||||
//Updated as a whole on writes, no index modifications are allowed
|
||||
private volatile PacketListenerCommon[] listeners = new PacketListenerCommon[0];
|
||||
|
||||
|
||||
/**
|
||||
* Call the PacketEvent.
|
||||
* This method processes the event on all the registered dynamic packet event listeners.
|
||||
* The {@link PacketListenerPriority#LOWEST} prioritized listeners will be processing first,
|
||||
* the {@link PacketListenerPriority#MONITOR} will be processing last and can
|
||||
* be the final decider whether the event has been cancelled or not.
|
||||
*
|
||||
* @param event {@link PacketEvent}
|
||||
*/
|
||||
public void callEvent(PacketEvent event) {
|
||||
callEvent(event, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Call the PacketEvent.
|
||||
* This method processes the event on all the registered dynamic packet event listeners.
|
||||
* The {@link PacketListenerPriority#LOWEST} prioritized listeners will be processing first,
|
||||
* the {@link PacketListenerPriority#MONITOR} will be processing last and can
|
||||
* be the final decider whether the event has been cancelled or not.
|
||||
*
|
||||
* @param event {@link PacketEvent}
|
||||
* @param postCallListenerAction The action to be ran after all the listeners have finished processing
|
||||
*/
|
||||
public void callEvent(PacketEvent event, @Nullable Runnable postCallListenerAction) {
|
||||
for (PacketListenerCommon listener : listeners) {
|
||||
try {
|
||||
event.call(listener);
|
||||
} catch (Exception t) {
|
||||
// ignore handshake exceptions
|
||||
if (t.getClass() != InvalidHandshakeException.class) {
|
||||
PacketEvents.getAPI().getLogger().log(Level.WARNING, "PacketEvents caught an unhandled exception while calling your listener.", t);
|
||||
}
|
||||
}
|
||||
if (postCallListenerAction != null) {
|
||||
postCallListenerAction.run();
|
||||
}
|
||||
}
|
||||
// For performance reasons, we don't want to re-encode the packet if it's not needed.
|
||||
if (event instanceof ProtocolPacketEvent && !((ProtocolPacketEvent) event).needsReEncode()) {
|
||||
((ProtocolPacketEvent) event).setLastUsedWrapper(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the dynamic packet event listener.
|
||||
*
|
||||
* @param listener {@link PacketListenerCommon}
|
||||
* @param priority {@link PacketListenerPriority}
|
||||
*/
|
||||
public PacketListenerCommon registerListener(PacketListener listener, PacketListenerPriority priority) {
|
||||
PacketListenerCommon packetListenerAbstract = listener.asAbstract(priority);
|
||||
return registerListener(packetListenerAbstract);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the dynamic packet event listener.
|
||||
*
|
||||
* @param listener {@link PacketListenerCommon}
|
||||
*/
|
||||
public PacketListenerCommon registerListener(PacketListenerCommon listener) {
|
||||
this.registerListenerNoRecalculation(listener);
|
||||
this.recalculateListeners();
|
||||
return listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register multiple dynamic packet event listeners with one method.
|
||||
*
|
||||
* @param listeners {@link PacketListenerCommon}
|
||||
*/
|
||||
public PacketListenerCommon[] registerListeners(PacketListenerCommon... listeners) {
|
||||
for (PacketListenerCommon listener : listeners) {
|
||||
this.registerListenerNoRecalculation(listener);
|
||||
}
|
||||
this.recalculateListeners();
|
||||
return listeners;
|
||||
}
|
||||
|
||||
public void unregisterListener(PacketListenerCommon listener) {
|
||||
if (this.unregisterListenerNoRecalculation(listener)) this.recalculateListeners();
|
||||
}
|
||||
|
||||
public void unregisterListeners(PacketListenerCommon... listeners) {
|
||||
boolean modified = false;
|
||||
for (PacketListenerCommon listener : listeners) {
|
||||
modified |= this.unregisterListenerNoRecalculation(listener);//OR - at least one of these needs to be true to return true, meaning the boolean will permanently stay true if once set so
|
||||
}
|
||||
if (modified) this.recalculateListeners();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Unregister all dynamic packet event listeners.
|
||||
*/
|
||||
public void unregisterAllListeners() {
|
||||
this.listenersMap.clear();
|
||||
synchronized (this) {//like booky10 said, the synchronization is necessary here
|
||||
this.listeners = new PacketListenerCommon[0];
|
||||
}
|
||||
}
|
||||
|
||||
//Needs to be synchronized in order to avoid race conditions (for example where the 'listeners' variable
|
||||
//is overridden by its non-up-to-date value, simply because it finished a bit later than the most recent update)
|
||||
private void recalculateListeners() {
|
||||
synchronized (this) {
|
||||
List<PacketListenerCommon> list = new ArrayList<>();
|
||||
//adds from LOWEST to MONITOR, so in the correct order
|
||||
for (PacketListenerPriority priority : PacketListenerPriority.values()) {
|
||||
Set<PacketListenerCommon> set = this.listenersMap.get(priority);
|
||||
if (set != null) list.addAll(set);
|
||||
}
|
||||
this.listeners = list.toArray(new PacketListenerCommon[0]);
|
||||
}
|
||||
}
|
||||
|
||||
//Internal registration methods, specifically separated for lesser overhead when registering an array of Listeners
|
||||
|
||||
private void registerListenerNoRecalculation(PacketListenerCommon listener) {
|
||||
Set<PacketListenerCommon> listenerSet = this.listenersMap.computeIfAbsent(listener.getPriority(), p -> new CopyOnWriteArraySet<>());
|
||||
listenerSet.add(listener);
|
||||
}
|
||||
|
||||
//Returns true if the listener was removed, so a modification occurred
|
||||
private boolean unregisterListenerNoRecalculation(PacketListenerCommon listener) {
|
||||
Set<PacketListenerCommon> listenerSet = this.listenersMap.get(listener.getPriority());
|
||||
return listenerSet != null && listenerSet.remove(listener);
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.util.TimeStampMode;
|
||||
|
||||
/**
|
||||
* An event in both of PacketEvents' event systems.
|
||||
*
|
||||
* @author retrooper
|
||||
* @since 1.2.6
|
||||
*/
|
||||
public abstract class PacketEvent implements CallableEvent {
|
||||
private final long timestamp;
|
||||
|
||||
public PacketEvent() {
|
||||
TimeStampMode timeStampMode = PacketEvents.getAPI().getSettings()
|
||||
.getTimeStampMode();
|
||||
switch (timeStampMode) {
|
||||
case MILLIS:
|
||||
timestamp = System.currentTimeMillis();
|
||||
break;
|
||||
case NANO:
|
||||
timestamp = System.nanoTime();
|
||||
break;
|
||||
//AKA NONE:
|
||||
default:
|
||||
timestamp = 0L;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Timestamp of when the PacketEvent was created.
|
||||
* Basically timestamp of the packet.
|
||||
*
|
||||
* @return Packet timestamp in milliseconds.
|
||||
*/
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
public void callPacketEventExternal(PacketListenerCommon listener) {
|
||||
listener.onPacketEventExternal(this);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface PacketHandler {
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
public interface PacketListener {
|
||||
default PacketListenerAbstract asAbstract(PacketListenerPriority priority) {
|
||||
return new PacketListenerAbstract(priority) {
|
||||
@Override
|
||||
public void onUserConnect(UserConnectEvent event) {
|
||||
PacketListener.this.onUserConnect(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserLogin(UserLoginEvent event) {
|
||||
PacketListener.this.onUserLogin(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUserDisconnect(UserDisconnectEvent event) {
|
||||
PacketListener.this.onUserDisconnect(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceive(PacketReceiveEvent event) {
|
||||
PacketListener.this.onPacketReceive(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSend(PacketSendEvent event) {
|
||||
PacketListener.this.onPacketSend(event);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketEventExternal(PacketEvent event) {
|
||||
PacketListener.this.onPacketEventExternal(event);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
default void onUserConnect(UserConnectEvent event) {
|
||||
}
|
||||
|
||||
default void onUserLogin(UserLoginEvent event) {
|
||||
}
|
||||
|
||||
default void onUserDisconnect(UserDisconnectEvent event) {
|
||||
}
|
||||
|
||||
default void onPacketReceive(PacketReceiveEvent event) {
|
||||
}
|
||||
|
||||
default void onPacketSend(PacketSendEvent event) {
|
||||
}
|
||||
|
||||
default void onPacketEventExternal(PacketEvent event) {
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
public abstract class PacketListenerAbstract extends PacketListenerCommon {
|
||||
public PacketListenerAbstract(PacketListenerPriority priority) {
|
||||
super(priority);
|
||||
}
|
||||
|
||||
public PacketListenerAbstract() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceive(PacketReceiveEvent event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSend(PacketSendEvent event) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Abstract packet listener.
|
||||
*
|
||||
* @author retrooper
|
||||
* @since 1.8
|
||||
*/
|
||||
public abstract class PacketListenerCommon {
|
||||
private final PacketListenerPriority priority;
|
||||
|
||||
public PacketListenerCommon(PacketListenerPriority priority) {
|
||||
this.priority = priority;
|
||||
}
|
||||
|
||||
public PacketListenerCommon() {
|
||||
this.priority = PacketListenerPriority.NORMAL;
|
||||
}
|
||||
|
||||
public PacketListenerPriority getPriority() {
|
||||
return priority;
|
||||
}
|
||||
|
||||
public void onUserConnect(UserConnectEvent event) {
|
||||
}
|
||||
|
||||
public void onUserLogin(UserLoginEvent event) {
|
||||
}
|
||||
|
||||
public void onUserDisconnect(UserDisconnectEvent event) {
|
||||
}
|
||||
|
||||
void onPacketReceive(PacketReceiveEvent event) {
|
||||
}
|
||||
|
||||
void onPacketSend(PacketSendEvent event) {
|
||||
}
|
||||
|
||||
public void onPacketEventExternal(PacketEvent event) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
/**
|
||||
* The priority of packet listeners affect the order they will be invoked in.
|
||||
* The lowest priority listeners are invoked first, the most high ones are invoked last.
|
||||
* The most high priority listener has the final decider on an event being cancelled.
|
||||
* This priority can be specified in the PacketListenerAbstract constructor.
|
||||
* If you don't specify a priority in the constructor, it will use the {@link #NORMAL} priority.
|
||||
*
|
||||
* @author retrooper
|
||||
* @since 1.8
|
||||
*/
|
||||
public enum PacketListenerPriority {
|
||||
/**
|
||||
* This listener will be run first and has little say in the outcome of events.
|
||||
*/
|
||||
LOWEST,
|
||||
|
||||
/**
|
||||
* Listener is of low importance.
|
||||
*/
|
||||
LOW,
|
||||
|
||||
/**
|
||||
* The normal listener priority.
|
||||
* If possible, always pick this.
|
||||
* It allows other projects to easily overturn your decisions.
|
||||
* Moreover, it is pretty bold to assume that your project should
|
||||
* always have the final say.
|
||||
*/
|
||||
NORMAL,
|
||||
|
||||
/**
|
||||
* Listener is of high importance.
|
||||
*/
|
||||
HIGH,
|
||||
|
||||
/**
|
||||
* Listener is of critical importance. Use this to decide the final state of packets.
|
||||
*/
|
||||
HIGHEST,
|
||||
|
||||
/**
|
||||
* Only use this priority if you want to perform logic based on the outcome of an event.
|
||||
* Please do not modify packets in this stage.
|
||||
*/
|
||||
MONITOR;
|
||||
|
||||
public static PacketListenerPriority getById(byte id) {
|
||||
return values()[id];
|
||||
}
|
||||
|
||||
public byte getId() {
|
||||
return (byte) ordinal();
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
import com.github.retrooper.packetevents.protocol.PacketSide;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
public class PacketReceiveEvent extends ProtocolPacketEvent {
|
||||
protected PacketReceiveEvent(Object channel, User user, Object player, Object rawByteBuf,
|
||||
boolean autoProtocolTranslation) throws PacketProcessException {
|
||||
super(PacketSide.CLIENT, channel, user, player, rawByteBuf, autoProtocolTranslation);
|
||||
}
|
||||
|
||||
protected PacketReceiveEvent(int packetID, PacketTypeCommon packetType,
|
||||
ServerVersion serverVersion,
|
||||
Object channel, User user, Object player,
|
||||
Object byteBuf) throws PacketProcessException {
|
||||
super(packetID, packetType, serverVersion,
|
||||
channel, user, player, byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(PacketListenerCommon listener) {
|
||||
listener.onPacketReceive(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketReceiveEvent clone() {
|
||||
try {
|
||||
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
|
||||
return new PacketReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
|
||||
getChannel(), getUser(), getPlayer(), clonedBuffer);
|
||||
} catch (PacketProcessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
import com.github.retrooper.packetevents.event.simple.PacketHandshakeSendEvent;
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
import com.github.retrooper.packetevents.protocol.PacketSide;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PacketSendEvent extends ProtocolPacketEvent {
|
||||
private List<Runnable> tasksAfterSend = null;
|
||||
|
||||
protected PacketSendEvent(Object channel, User user, Object player, Object rawByteBuf,
|
||||
boolean autoProtocolTranslation) throws PacketProcessException {
|
||||
super(PacketSide.SERVER, channel, user, player, rawByteBuf, autoProtocolTranslation);
|
||||
}
|
||||
|
||||
protected PacketSendEvent(int packetID, PacketTypeCommon packetType,
|
||||
ServerVersion serverVersion,
|
||||
Object channel, User user,
|
||||
Object player, Object byteBuf) throws PacketProcessException {
|
||||
super(packetID, packetType,
|
||||
serverVersion,
|
||||
channel, user, player, byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(PacketListenerCommon listener) {
|
||||
listener.onPacketSend(this);
|
||||
}
|
||||
|
||||
|
||||
public List<Runnable> getTasksAfterSend() {
|
||||
if (tasksAfterSend == null) {
|
||||
tasksAfterSend = new ArrayList<>();
|
||||
}
|
||||
return tasksAfterSend;
|
||||
}
|
||||
|
||||
public boolean hasTasksAfterSend() {
|
||||
return tasksAfterSend != null && !tasksAfterSend.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketSendEvent clone() {
|
||||
try {
|
||||
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
|
||||
return new PacketSendEvent(getPacketId(), getPacketType(), getServerVersion(),
|
||||
getChannel(), getUser(), getPlayer(), clonedBuffer);
|
||||
} catch (PacketProcessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
/**
|
||||
* Every event that has an associated player is recommended to implement this interface.
|
||||
*
|
||||
* @author retrooper
|
||||
* @since 1.6.9
|
||||
*/
|
||||
public interface PlayerEvent {
|
||||
/**
|
||||
* Associated player.
|
||||
*
|
||||
* @return Player.
|
||||
*/
|
||||
<T> T getPlayer();
|
||||
}
|
||||
@@ -1,245 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.exception.InvalidDisconnectPacketSend;
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
import com.github.retrooper.packetevents.netty.buffer.UnpooledByteBufAllocationHelper;
|
||||
import com.github.retrooper.packetevents.netty.channel.ChannelHelper;
|
||||
import com.github.retrooper.packetevents.protocol.ConnectionState;
|
||||
import com.github.retrooper.packetevents.protocol.PacketSide;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.SocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class ProtocolPacketEvent extends PacketEvent implements PlayerEvent, CancellableEvent, UserEvent {
|
||||
private final Object channel;
|
||||
private final ConnectionState connectionState;
|
||||
private final User user;
|
||||
private final Object player;
|
||||
private Object byteBuf;
|
||||
private final int packetID;
|
||||
private final PacketTypeCommon packetType;
|
||||
private ServerVersion serverVersion;
|
||||
private boolean cancel;
|
||||
private PacketWrapper<?> lastUsedWrapper;
|
||||
private List<Runnable> postTasks = null;
|
||||
private boolean cloned;
|
||||
private boolean needsReEncode = PacketEvents.getAPI().getSettings().reEncodeByDefault();
|
||||
|
||||
public ProtocolPacketEvent(PacketSide packetSide, Object channel,
|
||||
User user, Object player, Object byteBuf,
|
||||
boolean autoProtocolTranslation) throws PacketProcessException {
|
||||
this.channel = channel;
|
||||
this.user = user;
|
||||
this.player = player;
|
||||
if (autoProtocolTranslation || user.getClientVersion() == null) {
|
||||
this.serverVersion = PacketEvents.getAPI().getServerManager().getVersion();
|
||||
} else {
|
||||
//TODO Optimize
|
||||
this.serverVersion = user.getClientVersion().toServerVersion();
|
||||
}
|
||||
|
||||
this.byteBuf = byteBuf;
|
||||
int size = ByteBufHelper.readableBytes(byteBuf);
|
||||
if (size == 0) {
|
||||
throw new PacketProcessException("Trying to process a packet, but it has no content. (Size=0)");
|
||||
}
|
||||
try {
|
||||
this.packetID = ByteBufHelper.readVarInt(byteBuf);
|
||||
} catch (Exception e) {
|
||||
throw new PacketProcessException("Failed to read the Packet ID of a packet. (Size: " + size + ")");
|
||||
}
|
||||
ClientVersion version = serverVersion.toClientVersion();
|
||||
ConnectionState state = packetSide == PacketSide.CLIENT ? user.getDecoderState() : user.getEncoderState();
|
||||
this.packetType = PacketType.getById(packetSide, state,
|
||||
version, packetID);
|
||||
if (this.packetType == null) {
|
||||
// mojang messed up and keeps sending disconnect packets in the wrong protocol state
|
||||
if (PacketType.getById(packetSide, ConnectionState.PLAY, version, packetID) == PacketType.Play.Server.DISCONNECT) {
|
||||
throw new InvalidDisconnectPacketSend();
|
||||
}
|
||||
throw new PacketProcessException("Failed to map the Packet ID " + packetID + " to a PacketType constant. Bound: " + packetSide.getOpposite() + ", Connection state: " + user.getDecoderState() + ", Server version: " + serverVersion.getReleaseName());
|
||||
}
|
||||
this.connectionState = state;
|
||||
}
|
||||
|
||||
public ProtocolPacketEvent(int packetID, PacketTypeCommon packetType, ServerVersion serverVersion, Object channel,
|
||||
User user, Object player, Object byteBuf) {
|
||||
this.channel = channel;
|
||||
this.user = user;
|
||||
this.player = player;
|
||||
this.serverVersion = serverVersion;
|
||||
this.byteBuf = byteBuf;
|
||||
this.packetID = packetID;
|
||||
this.packetType = packetType;
|
||||
|
||||
this.connectionState = (packetType != null && packetType.getSide() == PacketSide.SERVER)
|
||||
? user.getEncoderState() : user.getDecoderState();
|
||||
cloned = true;
|
||||
}
|
||||
|
||||
public void markForReEncode(boolean needsReEncode) {
|
||||
this.needsReEncode = needsReEncode;
|
||||
}
|
||||
|
||||
public boolean needsReEncode() {
|
||||
return needsReEncode;
|
||||
}
|
||||
|
||||
|
||||
public boolean isClone() {
|
||||
return cloned;
|
||||
}
|
||||
|
||||
public Object getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public SocketAddress getAddress() {
|
||||
return ChannelHelper.remoteAddress(this.channel);
|
||||
}
|
||||
|
||||
/**
|
||||
* <strong>WARNING:</strong> This doesn't support local addresses or unix sockets.
|
||||
*/
|
||||
public InetSocketAddress getSocketAddress() {
|
||||
return (InetSocketAddress) this.getAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getPlayer() {
|
||||
return (T) player;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the connection state this packet has been sent/received in.
|
||||
*/
|
||||
public ConnectionState getConnectionState() {
|
||||
return connectionState;
|
||||
}
|
||||
|
||||
//TODO Possibly put clientversion inside User class and remove here
|
||||
@Deprecated
|
||||
public ClientVersion getClientVersion() {
|
||||
return user.getClientVersion();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void setClientVersion(@NotNull ClientVersion clientVersion) {
|
||||
PacketEvents.getAPI().getLogManager().debug("Setting client version with deprecated method " + clientVersion.getReleaseName());
|
||||
user.setClientVersion(clientVersion);
|
||||
}
|
||||
|
||||
public ServerVersion getServerVersion() {
|
||||
return serverVersion;
|
||||
}
|
||||
|
||||
public void setServerVersion(@NotNull ServerVersion serverVersion) {
|
||||
this.serverVersion = serverVersion;
|
||||
}
|
||||
|
||||
public Object getByteBuf() {
|
||||
return byteBuf;
|
||||
}
|
||||
|
||||
public void setByteBuf(Object byteBuf) {
|
||||
this.byteBuf = byteBuf;
|
||||
}
|
||||
|
||||
public int getPacketId() {
|
||||
return packetID;
|
||||
}
|
||||
|
||||
public PacketTypeCommon getPacketType() {
|
||||
return packetType;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getPacketName() {
|
||||
return ((Enum<?>) packetType).name();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean val) {
|
||||
this.cancel = val;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PacketWrapper<?> getLastUsedWrapper() {
|
||||
return lastUsedWrapper;
|
||||
}
|
||||
|
||||
public void setLastUsedWrapper(@Nullable PacketWrapper<?> lastUsedWrapper) {
|
||||
this.lastUsedWrapper = lastUsedWrapper;
|
||||
}
|
||||
|
||||
public List<Runnable> getPostTasks() {
|
||||
if (postTasks == null) {
|
||||
postTasks = new ArrayList<>();
|
||||
}
|
||||
return postTasks;
|
||||
}
|
||||
|
||||
public boolean hasPostTasks() {
|
||||
return postTasks != null && !postTasks.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProtocolPacketEvent clone() {
|
||||
return this instanceof PacketReceiveEvent ? ((PacketReceiveEvent) this).clone()
|
||||
: ((PacketSendEvent) this).clone();
|
||||
}
|
||||
|
||||
public void cleanUp() {
|
||||
if (isClone()) {
|
||||
ByteBufHelper.release(byteBuf);
|
||||
}
|
||||
}
|
||||
|
||||
public Object getFullBufferClone() {
|
||||
byte[] data = ByteBufHelper.copyBytes(getByteBuf());
|
||||
Object buffer = UnpooledByteBufAllocationHelper.buffer();
|
||||
ByteBufHelper.writeVarInt(buffer, getPacketId());
|
||||
ByteBufHelper.writeBytes(buffer, data);
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
-94
@@ -1,94 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
import com.github.retrooper.packetevents.event.simple.*;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class SimplePacketListenerAbstract extends PacketListenerCommon {
|
||||
public SimplePacketListenerAbstract(PacketListenerPriority priority) {
|
||||
super(priority);
|
||||
}
|
||||
|
||||
public SimplePacketListenerAbstract() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
void onPacketReceive(PacketReceiveEvent event) {
|
||||
if (event instanceof PacketHandshakeReceiveEvent) {
|
||||
onPacketHandshakeReceive((PacketHandshakeReceiveEvent) event);
|
||||
} else if (event instanceof PacketStatusReceiveEvent) {
|
||||
onPacketStatusReceive((PacketStatusReceiveEvent) event);
|
||||
} else if (event instanceof PacketLoginReceiveEvent) {
|
||||
onPacketLoginReceive((PacketLoginReceiveEvent) event);
|
||||
}
|
||||
else if (event instanceof PacketConfigReceiveEvent) {
|
||||
onPacketConfigReceive((PacketConfigReceiveEvent) event);
|
||||
}
|
||||
else if (event instanceof PacketPlayReceiveEvent) {
|
||||
onPacketPlayReceive((PacketPlayReceiveEvent) event);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void onPacketSend(PacketSendEvent event) {
|
||||
if (event instanceof PacketStatusSendEvent) {
|
||||
onPacketStatusSend((PacketStatusSendEvent) event);
|
||||
} else if (event instanceof PacketLoginSendEvent) {
|
||||
onPacketLoginSend((PacketLoginSendEvent) event);
|
||||
}
|
||||
else if (event instanceof PacketConfigSendEvent) {
|
||||
onPacketConfigSend((PacketConfigSendEvent) event);
|
||||
}
|
||||
else if (event instanceof PacketPlaySendEvent) {
|
||||
onPacketPlaySend((PacketPlaySendEvent) event);
|
||||
}
|
||||
}
|
||||
|
||||
public void onPacketHandshakeReceive(PacketHandshakeReceiveEvent event) {
|
||||
}
|
||||
|
||||
public void onPacketStatusReceive(PacketStatusReceiveEvent event) {
|
||||
}
|
||||
|
||||
public void onPacketStatusSend(PacketStatusSendEvent event) {
|
||||
}
|
||||
|
||||
public void onPacketLoginReceive(PacketLoginReceiveEvent event) {
|
||||
}
|
||||
|
||||
public void onPacketLoginSend(PacketLoginSendEvent event) {
|
||||
}
|
||||
|
||||
public void onPacketConfigReceive(PacketConfigReceiveEvent event) {
|
||||
}
|
||||
|
||||
public void onPacketConfigSend(PacketConfigSendEvent event) {
|
||||
}
|
||||
|
||||
public void onPacketPlayReceive(PacketPlayReceiveEvent event) {
|
||||
}
|
||||
|
||||
public void onPacketPlaySend(PacketPlaySendEvent event) {
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
public class UserConnectEvent extends PacketEvent implements CancellableEvent, UserEvent{
|
||||
private final User user;
|
||||
private boolean cancelled;
|
||||
|
||||
public UserConnectEvent(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(PacketListenerCommon listener) {
|
||||
listener.onUserConnect(this);
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
public class UserDisconnectEvent extends PacketEvent implements UserEvent {
|
||||
private final User user;
|
||||
|
||||
public UserDisconnectEvent(User user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(PacketListenerCommon listener) {
|
||||
listener.onUserDisconnect(this);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
/**
|
||||
* Event that involves users.
|
||||
*
|
||||
* @author retrooper
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public interface UserEvent {
|
||||
User getUser();
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
public class UserLoginEvent extends PacketEvent implements CallableEvent, UserEvent, PlayerEvent {
|
||||
private final User user;
|
||||
private final Object player;
|
||||
|
||||
public UserLoginEvent(User user, Object player) {
|
||||
this.user = user;
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getPlayer() {
|
||||
return (T) player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void call(PacketListenerCommon listener) {
|
||||
listener.onUserLogin(this);
|
||||
}
|
||||
}
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event.simple;
|
||||
|
||||
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
public class PacketConfigReceiveEvent extends PacketReceiveEvent {
|
||||
|
||||
public PacketConfigReceiveEvent(Object channel, User user,
|
||||
Object player, Object rawByteBuf,
|
||||
boolean autoProtocolTranslation) throws PacketProcessException {
|
||||
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
|
||||
}
|
||||
|
||||
protected PacketConfigReceiveEvent(int packetId, PacketTypeCommon packetType,
|
||||
ServerVersion serverVersion,
|
||||
Object channel,
|
||||
User user, Object player, Object byteBuf) throws PacketProcessException {
|
||||
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketConfigReceiveEvent clone() {
|
||||
try {
|
||||
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
|
||||
return new PacketConfigReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
|
||||
getChannel(), getUser(), getPlayer(), clonedBuffer);
|
||||
} catch (PacketProcessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PacketType.Configuration.Client getPacketType() {
|
||||
return (PacketType.Configuration.Client) super.getPacketType();
|
||||
}
|
||||
}
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event.simple;
|
||||
|
||||
import com.github.retrooper.packetevents.event.PacketSendEvent;
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
public class PacketConfigSendEvent extends PacketSendEvent {
|
||||
|
||||
public PacketConfigSendEvent(Object channel, User user,
|
||||
Object player, Object rawByteBuf,
|
||||
boolean autoProtocolTranslation) throws PacketProcessException {
|
||||
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
|
||||
}
|
||||
|
||||
protected PacketConfigSendEvent(int packetId, PacketTypeCommon packetType,
|
||||
ServerVersion serverVersion,
|
||||
Object channel,
|
||||
User user, Object player, Object byteBuf) throws PacketProcessException {
|
||||
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketConfigSendEvent clone() {
|
||||
try {
|
||||
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
|
||||
return new PacketConfigSendEvent(getPacketId(), getPacketType(), getServerVersion(),
|
||||
getChannel(), getUser(), getPlayer(), clonedBuffer);
|
||||
} catch (PacketProcessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PacketType.Configuration.Server getPacketType() {
|
||||
return (PacketType.Configuration.Server) super.getPacketType();
|
||||
}
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event.simple;
|
||||
|
||||
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
public class PacketHandshakeReceiveEvent extends PacketReceiveEvent {
|
||||
public PacketHandshakeReceiveEvent(Object channel, User user,
|
||||
Object player, Object rawByteBuf,
|
||||
boolean autoProtocolTranslation) throws PacketProcessException {
|
||||
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
|
||||
}
|
||||
|
||||
protected PacketHandshakeReceiveEvent(int packetId, PacketTypeCommon packetType,
|
||||
ServerVersion serverVersion,
|
||||
Object channel,
|
||||
User user, Object player, Object byteBuf) throws PacketProcessException {
|
||||
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketHandshakeReceiveEvent clone() {
|
||||
try {
|
||||
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
|
||||
return new PacketHandshakeReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
|
||||
getChannel(), getUser(), getPlayer(), clonedBuffer);
|
||||
} catch (PacketProcessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PacketType.Handshaking.Client getPacketType() {
|
||||
return (PacketType.Handshaking.Client) super.getPacketType();
|
||||
}
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
package com.github.retrooper.packetevents.event.simple;
|
||||
|
||||
import com.github.retrooper.packetevents.event.PacketSendEvent;
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
public class PacketHandshakeSendEvent extends PacketSendEvent {
|
||||
public PacketHandshakeSendEvent(Object channel, User user,
|
||||
Object player, Object rawByteBuf,
|
||||
boolean autoProtocolTranslation) throws PacketProcessException {
|
||||
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
|
||||
}
|
||||
|
||||
protected PacketHandshakeSendEvent(int packetId, PacketTypeCommon packetType,
|
||||
ServerVersion serverVersion,
|
||||
Object channel,
|
||||
User user, Object player, Object byteBuf) throws PacketProcessException {
|
||||
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketHandshakeSendEvent clone() {
|
||||
try {
|
||||
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
|
||||
return new PacketHandshakeSendEvent(getPacketId(), getPacketType(), getServerVersion(),
|
||||
getChannel(), getUser(), getPlayer(), clonedBuffer);
|
||||
} catch (PacketProcessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PacketType.Handshaking.Client getPacketType() {
|
||||
return (PacketType.Handshaking.Client) super.getPacketType();
|
||||
}
|
||||
}
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event.simple;
|
||||
|
||||
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
public class PacketLoginReceiveEvent extends PacketReceiveEvent {
|
||||
public PacketLoginReceiveEvent(Object channel, User user, Object player,
|
||||
Object rawByteBuf,
|
||||
boolean autoProtocolTranslation) throws PacketProcessException {
|
||||
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
|
||||
}
|
||||
|
||||
protected PacketLoginReceiveEvent(int packetId, PacketTypeCommon packetType,
|
||||
ServerVersion serverVersion,
|
||||
Object channel,
|
||||
User user, Object player, Object byteBuf) throws PacketProcessException {
|
||||
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketLoginReceiveEvent clone() {
|
||||
try {
|
||||
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
|
||||
return new PacketLoginReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
|
||||
getChannel(), getUser(), getPlayer(), clonedBuffer);
|
||||
} catch (PacketProcessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public PacketType.Login.Client getPacketType() {
|
||||
return (PacketType.Login.Client) super.getPacketType();
|
||||
}
|
||||
}
|
||||
-57
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event.simple;
|
||||
|
||||
import com.github.retrooper.packetevents.event.PacketSendEvent;
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
public class PacketLoginSendEvent extends PacketSendEvent {
|
||||
public PacketLoginSendEvent(Object channel, User user, Object player, Object rawByteBuf,
|
||||
boolean autoProtocolTranslation) throws PacketProcessException {
|
||||
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
|
||||
}
|
||||
|
||||
protected PacketLoginSendEvent(int packetId, PacketTypeCommon packetType,
|
||||
ServerVersion serverVersion,
|
||||
Object channel,
|
||||
User user, Object player, Object byteBuf) throws PacketProcessException {
|
||||
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketLoginSendEvent clone() {
|
||||
try {
|
||||
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
|
||||
return new PacketLoginSendEvent(getPacketId(), getPacketType(), getServerVersion(),
|
||||
getChannel(), getUser(), getPlayer(), clonedBuffer);
|
||||
} catch (PacketProcessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PacketType.Login.Server getPacketType() {
|
||||
return (PacketType.Login.Server) super.getPacketType();
|
||||
}
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event.simple;
|
||||
|
||||
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
public class PacketPlayReceiveEvent extends PacketReceiveEvent {
|
||||
public PacketPlayReceiveEvent(Object channel, User user,
|
||||
Object player, Object rawByteBuf,
|
||||
boolean autoProtocolTranslation) throws PacketProcessException {
|
||||
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
|
||||
}
|
||||
|
||||
protected PacketPlayReceiveEvent(int packetId, PacketTypeCommon packetType,
|
||||
ServerVersion serverVersion,
|
||||
Object channel,
|
||||
User user, Object player, Object byteBuf) throws PacketProcessException {
|
||||
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPlayReceiveEvent clone() {
|
||||
try {
|
||||
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
|
||||
return new PacketPlayReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
|
||||
getChannel(), getUser(), getPlayer(), clonedBuffer);
|
||||
} catch (PacketProcessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PacketType.Play.Client getPacketType() {
|
||||
return (PacketType.Play.Client) super.getPacketType();
|
||||
}
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event.simple;
|
||||
|
||||
import com.github.retrooper.packetevents.event.PacketSendEvent;
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
public class PacketPlaySendEvent extends PacketSendEvent {
|
||||
public PacketPlaySendEvent(Object channel, User user,
|
||||
Object player, Object rawByteBuf,
|
||||
boolean autoProtocolTranslation) throws PacketProcessException {
|
||||
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
|
||||
}
|
||||
|
||||
protected PacketPlaySendEvent(int packetId, PacketTypeCommon packetType,
|
||||
ServerVersion serverVersion,
|
||||
Object channel,
|
||||
User user, Object player, Object byteBuf) throws PacketProcessException {
|
||||
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketPlaySendEvent clone() {
|
||||
try {
|
||||
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
|
||||
return new PacketPlaySendEvent(getPacketId(), getPacketType(), getServerVersion(),
|
||||
getChannel(), getUser(), getPlayer(), clonedBuffer);
|
||||
} catch (PacketProcessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PacketType.Play.Server getPacketType() {
|
||||
return (PacketType.Play.Server) super.getPacketType();
|
||||
}
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event.simple;
|
||||
|
||||
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
public class PacketStatusReceiveEvent extends PacketReceiveEvent {
|
||||
public PacketStatusReceiveEvent(Object channel, User user,
|
||||
Object player, Object rawByteBuf,
|
||||
boolean autoProtocolTranslation) throws PacketProcessException {
|
||||
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
|
||||
}
|
||||
|
||||
protected PacketStatusReceiveEvent(int packetId, PacketTypeCommon packetType,
|
||||
ServerVersion serverVersion,
|
||||
Object channel,
|
||||
User user, Object player, Object byteBuf) throws PacketProcessException {
|
||||
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketStatusReceiveEvent clone() {
|
||||
try {
|
||||
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
|
||||
return new PacketStatusReceiveEvent(getPacketId(), getPacketType(), getServerVersion(),
|
||||
getChannel(), getUser(), getPlayer(), clonedBuffer);
|
||||
} catch (PacketProcessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public PacketType.Status.Client getPacketType() {
|
||||
return (PacketType.Status.Client) super.getPacketType();
|
||||
}
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.event.simple;
|
||||
|
||||
import com.github.retrooper.packetevents.event.PacketSendEvent;
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufHelper;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
public class PacketStatusSendEvent extends PacketSendEvent {
|
||||
public PacketStatusSendEvent(Object channel, User user, Object player, Object rawByteBuf,
|
||||
boolean autoProtocolTranslation) throws PacketProcessException {
|
||||
super(channel, user, player, rawByteBuf, autoProtocolTranslation);
|
||||
}
|
||||
|
||||
protected PacketStatusSendEvent(int packetId, PacketTypeCommon packetType,
|
||||
ServerVersion serverVersion,
|
||||
Object channel,
|
||||
User user, Object player, Object byteBuf) throws PacketProcessException {
|
||||
super(packetId, packetType, serverVersion, channel, user, player, byteBuf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PacketStatusSendEvent clone() {
|
||||
try {
|
||||
Object clonedBuffer = ByteBufHelper.retainedDuplicate(getByteBuf());
|
||||
return new PacketStatusSendEvent(getPacketId(), getPacketType(), getServerVersion(),
|
||||
getChannel(), getUser(), getPlayer(), clonedBuffer);
|
||||
} catch (PacketProcessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public PacketType.Status.Server getPacketType() {
|
||||
return (PacketType.Status.Server) super.getPacketType();
|
||||
}
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
package com.github.retrooper.packetevents.exception;
|
||||
|
||||
public class CancelPacketException extends RuntimeException {
|
||||
public static final CancelPacketException INSTANCE = new CancelPacketException();
|
||||
|
||||
@Override
|
||||
public synchronized Throwable fillInStackTrace() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
package com.github.retrooper.packetevents.exception;
|
||||
|
||||
public class InvalidDisconnectPacketSend extends RuntimeException {
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
package com.github.retrooper.packetevents.exception;
|
||||
|
||||
public class InvalidHandshakeException extends RuntimeException {
|
||||
}
|
||||
-33
@@ -1,33 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.exception;
|
||||
|
||||
public class PacketProcessException extends RuntimeException {
|
||||
public PacketProcessException(String msg, Throwable cause) {
|
||||
super(msg, cause);
|
||||
}
|
||||
|
||||
public PacketProcessException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public PacketProcessException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.injector;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.PacketSide;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
|
||||
public interface ChannelInjector {
|
||||
|
||||
default boolean isServerBound() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void inject();
|
||||
|
||||
void uninject();
|
||||
|
||||
void updateUser(Object channel, User user);
|
||||
|
||||
void setPlayer(Object channel, Object player);
|
||||
|
||||
boolean isPlayerSet(Object channel);
|
||||
|
||||
boolean isProxy();
|
||||
|
||||
default PacketSide getPacketSide() {
|
||||
return PacketSide.SERVER;
|
||||
}
|
||||
}
|
||||
-145
@@ -1,145 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.manager;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.event.PacketListenerAbstract;
|
||||
import com.github.retrooper.packetevents.event.PacketListenerPriority;
|
||||
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
|
||||
import com.github.retrooper.packetevents.event.PacketSendEvent;
|
||||
import com.github.retrooper.packetevents.manager.protocol.ProtocolManager;
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.protocol.ConnectionState;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
import com.github.retrooper.packetevents.protocol.player.UserProfile;
|
||||
import com.github.retrooper.packetevents.util.LogManager;
|
||||
import com.github.retrooper.packetevents.util.mappings.SynchronizedRegistriesHandler;
|
||||
import com.github.retrooper.packetevents.wrapper.configuration.server.WrapperConfigServerRegistryData;
|
||||
import com.github.retrooper.packetevents.wrapper.handshaking.client.WrapperHandshakingClientHandshake;
|
||||
import com.github.retrooper.packetevents.wrapper.login.server.WrapperLoginServerLoginSuccess;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerJoinGame;
|
||||
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerRespawn;
|
||||
|
||||
public class InternalPacketListener extends PacketListenerAbstract {
|
||||
|
||||
public InternalPacketListener() {
|
||||
this(PacketListenerPriority.LOWEST);
|
||||
}
|
||||
|
||||
public InternalPacketListener(PacketListenerPriority priority) {
|
||||
super(priority);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketSend(PacketSendEvent event) {
|
||||
User user = event.getUser();
|
||||
if (event.getPacketType() == PacketType.Login.Server.LOGIN_SUCCESS) {
|
||||
Object channel = event.getChannel();
|
||||
//Process outgoing login success packet
|
||||
WrapperLoginServerLoginSuccess loginSuccess = new WrapperLoginServerLoginSuccess(event);
|
||||
UserProfile profile = loginSuccess.getUserProfile();
|
||||
|
||||
//Update user profile
|
||||
user.getProfile().setUUID(profile.getUUID());
|
||||
user.getProfile().setName(profile.getName());
|
||||
//Texture properties are passed in login success on 1.19
|
||||
user.getProfile().setTextureProperties(profile.getTextureProperties());
|
||||
|
||||
//Map username with channel
|
||||
synchronized (channel) {
|
||||
PacketEvents.getAPI().getProtocolManager().setChannel(profile.getUUID(), channel);
|
||||
}
|
||||
|
||||
PacketEvents.getAPI().getLogManager().debug("Mapped player UUID with their channel.");
|
||||
|
||||
// Switch the user's connection state to new state, but the variable event.getConnectionState() remains LOGIN
|
||||
// We switch user state immediately to remain in sync with vanilla, allowing you to encode packets immediately
|
||||
boolean proxy = PacketEvents.getAPI().getInjector().isProxy();
|
||||
if (proxy ? event.getUser().getClientVersion().isNewerThanOrEquals(ClientVersion.V_1_20_2)
|
||||
: event.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_20_2)) {
|
||||
user.setEncoderState(ConnectionState.CONFIGURATION);
|
||||
} else {
|
||||
user.setConnectionState(ConnectionState.PLAY);
|
||||
}
|
||||
}
|
||||
|
||||
// The server sends dimension information in configuration phase, since 1.20.2
|
||||
else if (event.getPacketType() == PacketType.Configuration.Server.REGISTRY_DATA) {
|
||||
WrapperConfigServerRegistryData packet = new WrapperConfigServerRegistryData(event);
|
||||
|
||||
if (packet.getElements() != null) { // 1.20.2 to 1.20.5
|
||||
SynchronizedRegistriesHandler.handleRegistry(user, packet,
|
||||
packet.getRegistryKey(), packet.getElements());
|
||||
}
|
||||
if (packet.getRegistryData() != null) { // since 1.20.5
|
||||
SynchronizedRegistriesHandler.handleLegacyRegistries(user, packet, packet.getRegistryData());
|
||||
}
|
||||
}
|
||||
|
||||
// The server sends registry info in login packet for 1.16 to 1.20.1
|
||||
else if (event.getPacketType() == PacketType.Play.Server.JOIN_GAME) {
|
||||
WrapperPlayServerJoinGame joinGame = new WrapperPlayServerJoinGame(event);
|
||||
user.setEntityId(joinGame.getEntityId());
|
||||
|
||||
if (joinGame.getDimensionCodec() != null) { // 1.16 to 1.20.1
|
||||
SynchronizedRegistriesHandler.handleLegacyRegistries(user, joinGame,
|
||||
joinGame.getDimensionCodec());
|
||||
}
|
||||
|
||||
user.setDimensionType(joinGame.getDimensionType());
|
||||
}
|
||||
|
||||
// Respawn is used to switch dimensions
|
||||
else if (event.getPacketType() == PacketType.Play.Server.RESPAWN) {
|
||||
WrapperPlayServerRespawn packet = new WrapperPlayServerRespawn(event);
|
||||
user.setDimensionType(packet.getDimensionType());
|
||||
} else if (event.getPacketType() == PacketType.Play.Server.CONFIGURATION_START) {
|
||||
user.setEncoderState(ConnectionState.CONFIGURATION);
|
||||
} else if (event.getPacketType() == PacketType.Configuration.Server.CONFIGURATION_END) {
|
||||
user.setEncoderState(ConnectionState.PLAY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceive(PacketReceiveEvent event) {
|
||||
User user = event.getUser();
|
||||
if (event.getPacketType() == PacketType.Handshaking.Client.HANDSHAKE) {
|
||||
WrapperHandshakingClientHandshake packet = new WrapperHandshakingClientHandshake(event);
|
||||
ClientVersion clientVersion = packet.getClientVersion();
|
||||
ConnectionState state = packet.getNextConnectionState();
|
||||
|
||||
LogManager logger = PacketEvents.getAPI().getLogManager();
|
||||
if (logger.isDebug()) {
|
||||
logger.debug("Processed handshake for " + event.getAddress() + ": "
|
||||
+ state.name() + " / " + packet.getClientVersion().getReleaseName());
|
||||
}
|
||||
|
||||
user.setClientVersion(clientVersion);
|
||||
user.setConnectionState(state);
|
||||
} else if (event.getPacketType() == PacketType.Login.Client.LOGIN_SUCCESS_ACK) {
|
||||
user.setDecoderState(ConnectionState.CONFIGURATION);
|
||||
} else if (event.getPacketType() == PacketType.Play.Client.CONFIGURATION_ACK) {
|
||||
user.setDecoderState(ConnectionState.CONFIGURATION);
|
||||
} else if (event.getPacketType() == PacketType.Configuration.Client.CONFIGURATION_END_ACK) {
|
||||
user.setDecoderState(ConnectionState.PLAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.manager.player;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.event.ProtocolPacketEvent;
|
||||
import com.github.retrooper.packetevents.protocol.ConnectionState;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface PlayerManager {
|
||||
int getPing(@NotNull Object player);
|
||||
|
||||
@NotNull ClientVersion getClientVersion(@NotNull Object player);
|
||||
|
||||
Object getChannel(@NotNull Object player);
|
||||
|
||||
User getUser(@NotNull Object player);
|
||||
|
||||
/**
|
||||
* <strong>WARNING</strong>: Usage of this method should be avoided. Please use either
|
||||
* {@link User#getDecoderState()} or {@link User#getEncoderState()}.<br>
|
||||
* To access the specific state a packet event was sent/received in, use {@link ProtocolPacketEvent#getConnectionState()}.
|
||||
* <p>
|
||||
* Since 1.20.2, the Minecraft protocol allows the decoder/encoder connection states to de-sync.
|
||||
*
|
||||
* @throws IllegalStateException if encoder/decoder connection states do not match
|
||||
*/
|
||||
@ApiStatus.Obsolete
|
||||
default ConnectionState getConnectionState(@NotNull Object player) throws IllegalStateException {
|
||||
return getUser(player).getConnectionState();
|
||||
}
|
||||
|
||||
default void sendPacket(@NotNull Object player, @NotNull Object byteBuf) {
|
||||
PacketEvents.getAPI().getProtocolManager().sendPacket(getChannel(player), byteBuf);
|
||||
}
|
||||
default void sendPacket(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
|
||||
PacketEvents.getAPI().getProtocolManager().sendPacket(getChannel(player), wrapper);
|
||||
}
|
||||
|
||||
default void sendPacketSilently(@NotNull Object player, @NotNull Object byteBuf) {
|
||||
PacketEvents.getAPI().getProtocolManager().sendPacketSilently(getChannel(player), byteBuf);
|
||||
}
|
||||
|
||||
default void sendPacketSilently(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
|
||||
PacketEvents.getAPI().getProtocolManager().sendPacketSilently(getChannel(player), wrapper);
|
||||
}
|
||||
|
||||
default void writePacket(@NotNull Object player, @NotNull Object byteBuf) {
|
||||
PacketEvents.getAPI().getProtocolManager().writePacket(getChannel(player), byteBuf);
|
||||
}
|
||||
|
||||
default void writePacket(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
|
||||
PacketEvents.getAPI().getProtocolManager().writePacket(getChannel(player), wrapper);
|
||||
}
|
||||
|
||||
default void writePacketSilently(@NotNull Object player, @NotNull Object byteBuf) {
|
||||
PacketEvents.getAPI().getProtocolManager().writePacketSilently(getChannel(player), byteBuf);
|
||||
}
|
||||
|
||||
default void writePacketSilently(@NotNull Object player, @NotNull PacketWrapper<?> wrapper) {
|
||||
PacketEvents.getAPI().getProtocolManager().writePacketSilently(getChannel(player), wrapper);
|
||||
}
|
||||
|
||||
default void receivePacket(Object player, Object byteBuf) {
|
||||
PacketEvents.getAPI().getProtocolManager().receivePacket(getChannel(player), byteBuf);
|
||||
}
|
||||
|
||||
default void receivePacket(Object player, PacketWrapper<?> wrapper) {
|
||||
PacketEvents.getAPI().getProtocolManager().receivePacket(getChannel(player), wrapper);
|
||||
}
|
||||
|
||||
default void receivePacketSilently(Object player, Object byteBuf) {
|
||||
PacketEvents.getAPI().getProtocolManager().receivePacketSilently(getChannel(player), byteBuf);
|
||||
}
|
||||
|
||||
default void receivePacketSilently(Object player, PacketWrapper<?> wrapper) {
|
||||
PacketEvents.getAPI().getProtocolManager().receivePacketSilently(getChannel(player), wrapper);
|
||||
}
|
||||
}
|
||||
-192
@@ -1,192 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.manager.protocol;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.netty.channel.ChannelHelper;
|
||||
import com.github.retrooper.packetevents.protocol.ProtocolVersion;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
import com.github.retrooper.packetevents.util.PacketTransformationUtil;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public interface ProtocolManager {
|
||||
@ApiStatus.Internal
|
||||
Map<UUID, Object> CHANNELS = new ConcurrentHashMap<>();
|
||||
// Use SocketAddress because ProtocolLib wraps Channels with NettyChannelProxy class
|
||||
@ApiStatus.Internal
|
||||
Map<Object, User> USERS = new ConcurrentHashMap<>();
|
||||
|
||||
default Collection<User> getUsers() {
|
||||
return USERS.values();
|
||||
}
|
||||
|
||||
default Collection<Object> getChannels() {
|
||||
return CHANNELS.values();
|
||||
}
|
||||
|
||||
//Methods to implement
|
||||
ProtocolVersion getPlatformVersion();
|
||||
void sendPacket(Object channel, Object byteBuf);
|
||||
void sendPacketSilently(Object channel, Object byteBuf);
|
||||
void writePacket(Object channel, Object byteBuf);
|
||||
void writePacketSilently(Object channel, Object byteBuf);
|
||||
void receivePacket(Object channel, Object byteBuf);
|
||||
void receivePacketSilently(Object channel, Object byteBuf);
|
||||
ClientVersion getClientVersion(Object channel);
|
||||
//TODO Define method that accepts an array of channels/set/list of channels.
|
||||
|
||||
default void sendPackets(Object channel, Object... byteBuf) {
|
||||
for (Object buf : byteBuf) {
|
||||
sendPacket(channel, buf);
|
||||
}
|
||||
}
|
||||
|
||||
default void sendPacketsSilently(Object channel, Object... byteBuf) {
|
||||
for (Object buf : byteBuf) {
|
||||
sendPacketSilently(channel, buf);
|
||||
}
|
||||
}
|
||||
|
||||
default void writePackets(Object channel, Object... byteBuf) {
|
||||
for (Object buf : byteBuf) {
|
||||
writePacket(channel, buf);
|
||||
}
|
||||
}
|
||||
|
||||
default void writePacketsSilently(Object channel, Object... byteBuf) {
|
||||
for (Object buf : byteBuf) {
|
||||
writePacketSilently(channel, buf);
|
||||
}
|
||||
}
|
||||
|
||||
default void receivePackets(Object channel, Object... byteBuf) {
|
||||
for (Object buf : byteBuf) {
|
||||
receivePacket(channel, buf);
|
||||
}
|
||||
}
|
||||
|
||||
default void receivePacketsSilently(Object channel, Object... byteBuf) {
|
||||
for (Object buf : byteBuf) {
|
||||
receivePacketSilently(channel, buf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
default void setClientVersion(Object channel, ClientVersion version) {
|
||||
getUser(channel).setClientVersion(version);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
default Object[] transformWrappers(PacketWrapper<?> wrapper, Object channel, boolean outgoing) {
|
||||
//It is possible that our packet transformer util decides to transform one wrapper into multiple packets.
|
||||
//(Correcting some mistakes on your end)
|
||||
PacketWrapper<?>[] wrappers = PacketTransformationUtil.transform(wrapper);
|
||||
Object[] buffers = new Object[wrappers.length];
|
||||
for (int i = 0; i < wrappers.length; i++) {
|
||||
PacketWrapper<?> wrappper = wrappers[i];
|
||||
synchronized (wrappper.bufferLock) {
|
||||
wrappper.prepareForSend(channel, outgoing);
|
||||
buffers[i] = wrappper.buffer;
|
||||
// Fix race condition when sending packets to multiple people (due to when the buffer is freed)
|
||||
wrappper.buffer = null;
|
||||
}
|
||||
}
|
||||
return buffers;
|
||||
}
|
||||
|
||||
default void sendPacket(Object channel, PacketWrapper<?> wrapper) {
|
||||
Object[] transformed = transformWrappers(wrapper, channel, true);
|
||||
sendPackets(channel, transformed);
|
||||
}
|
||||
|
||||
default void sendPacketSilently(Object channel, PacketWrapper<?> wrapper) {
|
||||
Object[] transformed = transformWrappers(wrapper, channel, true);
|
||||
sendPacketsSilently(channel, transformed);
|
||||
}
|
||||
|
||||
default void writePacket(Object channel, PacketWrapper<?> wrapper) {
|
||||
Object[] transformed = transformWrappers(wrapper, channel, true);
|
||||
writePackets(channel, transformed);
|
||||
}
|
||||
|
||||
default void writePacketSilently(Object channel, PacketWrapper<?> wrapper) {
|
||||
Object[] transformed = transformWrappers(wrapper, channel, true);
|
||||
writePacketsSilently(channel, transformed);
|
||||
}
|
||||
|
||||
default void receivePacket(Object channel, PacketWrapper<?> wrapper) {
|
||||
Object[] transformed = transformWrappers(wrapper, channel, false);
|
||||
receivePackets(channel, transformed);
|
||||
}
|
||||
|
||||
default void receivePacketSilently(Object channel, PacketWrapper<?> wrapper) {
|
||||
Object[] transformed = transformWrappers(wrapper, channel, false);
|
||||
receivePacketsSilently(channel, transformed);
|
||||
}
|
||||
|
||||
default User getUser(Object channel) {
|
||||
Object pipeline = ChannelHelper.getPipeline(channel);
|
||||
return USERS.get(pipeline);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
default User removeUser(Object channel) {
|
||||
Object pipeline = ChannelHelper.getPipeline(channel);
|
||||
return USERS.remove(pipeline);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
default void setUser(Object channel, User user) {
|
||||
synchronized (channel) {
|
||||
Object pipeline = ChannelHelper.getPipeline(channel);
|
||||
USERS.put(pipeline, user);
|
||||
}
|
||||
PacketEvents.getAPI().getInjector().updateUser(channel, user);
|
||||
}
|
||||
|
||||
default Object getChannel(UUID uuid) {
|
||||
return CHANNELS.get(uuid);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
default void setChannel(UUID uuid, Object channel) {
|
||||
CHANNELS.put(uuid, channel);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
default void removeChannel(Object channel) {
|
||||
CHANNELS.values().remove(channel);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
default void removeChannelById(UUID uuid) {
|
||||
CHANNELS.remove(uuid);
|
||||
}
|
||||
|
||||
default boolean hasChannel(Object channel) {
|
||||
return CHANNELS.containsValue(channel);
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.manager.server;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.protocol.player.User;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface ServerManager {
|
||||
/**
|
||||
* Get the server version.
|
||||
*
|
||||
* @return Get Server Version
|
||||
*/
|
||||
ServerVersion getVersion();
|
||||
|
||||
/**
|
||||
* Get the operating system of the local machine
|
||||
*
|
||||
* @return Get Operating System
|
||||
*/
|
||||
default SystemOS getOS() {
|
||||
return SystemOS.getOS();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a platform-specific network-synchronized-registries cache key.
|
||||
* <p>
|
||||
* This tells packetevents, if a registry should be cached or read again. On
|
||||
* backend servers with global registries, this may be a constant value. On
|
||||
* proxy servers with per-server registries, this may be a value which depends
|
||||
* on the current server the {@link User} is on.
|
||||
*
|
||||
* @param user the {@link User} for which the registry gets read
|
||||
* @param version the version the packet is for
|
||||
* @return some value or null for no caching at all
|
||||
*/
|
||||
default @Nullable Object getRegistryCacheKey(User user, ClientVersion version) {
|
||||
return null; // no caching
|
||||
}
|
||||
}
|
||||
-216
@@ -1,216 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.manager.server;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Server Version.
|
||||
* This is a nice wrapper over minecraft's protocol versions.
|
||||
* You won't have to memorize the protocol version, just memorize the server version you see in the launcher.
|
||||
*
|
||||
* @author retrooper
|
||||
* @see <a href="https://wiki.vg/Protocol_version_numbers">https://wiki.vg/Protocol_version_numbers</a>
|
||||
* @since 1.6.9
|
||||
*/
|
||||
public enum ServerVersion {
|
||||
//TODO Rename to MinecraftVersion?
|
||||
V_1_7_10(5),
|
||||
V_1_8(47), V_1_8_3(47), V_1_8_8(47),
|
||||
V_1_9(107), V_1_9_1(108), V_1_9_2(109), V_1_9_4(110),
|
||||
//1.10 and 1.10.1 are redundant
|
||||
V_1_10(210), V_1_10_1(210), V_1_10_2(210),
|
||||
V_1_11(315), V_1_11_2(316),
|
||||
V_1_12(335), V_1_12_1(338), V_1_12_2(340),
|
||||
V_1_13(393), V_1_13_1(401), V_1_13_2(404),
|
||||
V_1_14(477), V_1_14_1(480), V_1_14_2(485), V_1_14_3(490), V_1_14_4(498),
|
||||
V_1_15(573), V_1_15_1(575), V_1_15_2(578),
|
||||
V_1_16(735), V_1_16_1(736), V_1_16_2(751), V_1_16_3(753), V_1_16_4(754), V_1_16_5(754),
|
||||
V_1_17(755), V_1_17_1(756),
|
||||
V_1_18(757), V_1_18_1(757), V_1_18_2(758),
|
||||
//1.19.1 and 1.19.2 have the same protocol version
|
||||
V_1_19(759), V_1_19_1(760), V_1_19_2(760), V_1_19_3(761), V_1_19_4(762),
|
||||
//1.20 and 1.20.1 have the same protocol version. 1.20.3 and 1.20.4 have the same protocol version. 1.20.5 and 1.20.6 have the same protocol version
|
||||
V_1_20(763), V_1_20_1(763), V_1_20_2(764), V_1_20_3(765), V_1_20_4(765), V_1_20_5(766), V_1_20_6(766),
|
||||
//1.21 and 1.21.1 have the same protocol version. 1.21.2 and 1.21.3 have the same protocol version
|
||||
V_1_21(767), V_1_21_1(767), V_1_21_2(768), V_1_21_3(768), V_1_21_4(769), V_1_21_5(770), V_1_21_6(771), V_1_21_7(772),
|
||||
//TODO UPDATE Add server version constant
|
||||
ERROR(-1, true);
|
||||
|
||||
private static final ServerVersion[] VALUES = values();
|
||||
private static final ServerVersion[] REVERSED_VALUES;
|
||||
|
||||
static {
|
||||
REVERSED_VALUES = values();
|
||||
int i = 0;
|
||||
int j = REVERSED_VALUES.length - 1;
|
||||
ServerVersion tmp;
|
||||
while (j > i) {
|
||||
tmp = REVERSED_VALUES[j];
|
||||
REVERSED_VALUES[j--] = REVERSED_VALUES[i];
|
||||
REVERSED_VALUES[i++] = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
private final int protocolVersion;
|
||||
private final String name;
|
||||
private ClientVersion toClientVersion;
|
||||
|
||||
ServerVersion(int protocolVersion) {
|
||||
this.protocolVersion = protocolVersion;
|
||||
this.name = name().substring(2).replace("_", ".");
|
||||
}
|
||||
|
||||
ServerVersion(int protocolVersion, boolean isNotRelease) {
|
||||
this.protocolVersion = protocolVersion;
|
||||
if (isNotRelease) {
|
||||
this.name = name();
|
||||
} else {
|
||||
this.name = name().substring(2).replace("_", ".");
|
||||
}
|
||||
}
|
||||
|
||||
public static ServerVersion[] reversedValues() {
|
||||
return REVERSED_VALUES;
|
||||
}
|
||||
|
||||
public static ServerVersion getLatest() {
|
||||
return REVERSED_VALUES[1];
|
||||
}
|
||||
|
||||
public static ServerVersion getOldest() {
|
||||
return VALUES[0];
|
||||
}
|
||||
|
||||
//TODO Optimize
|
||||
@Deprecated
|
||||
public static ServerVersion getById(int protocolVersion) {
|
||||
for (ServerVersion version : VALUES) {
|
||||
if (version.protocolVersion == protocolVersion) {
|
||||
return version;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public ClientVersion toClientVersion() {
|
||||
if (toClientVersion == null) {
|
||||
toClientVersion = ClientVersion.getById(protocolVersion);
|
||||
}
|
||||
return toClientVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the release name of this server version.
|
||||
* For example, for the V_1_18 enum constant, it would return "1.18".
|
||||
*
|
||||
* @return Release name
|
||||
*/
|
||||
public String getReleaseName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get this server version's protocol version.
|
||||
*
|
||||
* @return Protocol version.
|
||||
*/
|
||||
public int getProtocolVersion() {
|
||||
return protocolVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this server version newer than the compared server version?
|
||||
* This method simply checks if this server version's protocol version is greater than
|
||||
* the compared server version's protocol version.
|
||||
*
|
||||
* @param target Compared server version.
|
||||
* @return Is this server version newer than the compared server version.
|
||||
*/
|
||||
public boolean isNewerThan(ServerVersion target) {
|
||||
return this.ordinal() > target.ordinal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this server version older than the compared server version?
|
||||
* This method simply checks if this server version's protocol version is less than
|
||||
* the compared server version's protocol version.
|
||||
*
|
||||
* @param target Compared server version.
|
||||
* @return Is this server version older than the compared server version.
|
||||
*/
|
||||
public boolean isOlderThan(ServerVersion target) {
|
||||
return this.ordinal() < target.ordinal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this server version newer than or equal to the compared server version?
|
||||
* This method simply checks if this server version's protocol version is greater than or equal to
|
||||
* the compared server version's protocol version.
|
||||
*
|
||||
* @param target Compared server version.
|
||||
* @return Is this server version newer than or equal to the compared server version.
|
||||
*/
|
||||
public boolean isNewerThanOrEquals(ServerVersion target) {
|
||||
return this.ordinal() >= target.ordinal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this server version older than or equal to the compared server version?
|
||||
* This method simply checks if this server version's protocol version is older than or equal to
|
||||
* the compared server version's protocol version.
|
||||
*
|
||||
* @param target Compared server version.
|
||||
* @return Is this server version older than or equal to the compared server version.
|
||||
*/
|
||||
public boolean isOlderThanOrEquals(ServerVersion target) {
|
||||
return this.ordinal() <= target.ordinal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this server version newer than, older than or equal to the compared server version?
|
||||
* This method simply checks if this server version's protocol version is greater than, less than or equal to
|
||||
* the compared server version's protocol version.
|
||||
*
|
||||
* @param comparison Comparison type.
|
||||
* @param targetVersion Compared server version.
|
||||
* @return true or false, based on the comparison type.
|
||||
* @see #isNewerThan(ServerVersion)
|
||||
* @see #isNewerThanOrEquals(ServerVersion)
|
||||
* @see #isOlderThan(ServerVersion)
|
||||
* @see #isOlderThanOrEquals(ServerVersion)
|
||||
*/
|
||||
public boolean is(@NotNull VersionComparison comparison, @NotNull ServerVersion targetVersion) {
|
||||
switch (comparison) {
|
||||
case EQUALS:
|
||||
return protocolVersion == targetVersion.protocolVersion;
|
||||
case NEWER_THAN:
|
||||
return isNewerThan(targetVersion);
|
||||
case NEWER_THAN_OR_EQUALS:
|
||||
return isNewerThanOrEquals(targetVersion);
|
||||
case OLDER_THAN:
|
||||
return isOlderThan(targetVersion);
|
||||
case OLDER_THAN_OR_EQUALS:
|
||||
return isOlderThanOrEquals(targetVersion);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.manager.server;
|
||||
|
||||
/**
|
||||
* System Operating system.
|
||||
*
|
||||
* @author retrooper
|
||||
* @since 1.7
|
||||
*/
|
||||
public enum SystemOS {
|
||||
|
||||
WINDOWS, MACOS, LINUX, OTHER;
|
||||
private static SystemOS CACHE;
|
||||
|
||||
/**
|
||||
* Get the server's operating system.
|
||||
* This method will NOT cache.
|
||||
*
|
||||
* @return Operating System.
|
||||
*/
|
||||
public static SystemOS getOSNoCache() {
|
||||
final String os = System.getProperty("os.name").toLowerCase();
|
||||
for (SystemOS sysos : values()) {
|
||||
if (os.contains(sysos.name().toLowerCase())) {
|
||||
return sysos;
|
||||
}
|
||||
}
|
||||
return OTHER;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the server's operating system.
|
||||
* This method will CACHE for you.
|
||||
*
|
||||
* @return Operating System.
|
||||
*/
|
||||
public static SystemOS getOS() {
|
||||
if (CACHE == null) {
|
||||
CACHE = getOSNoCache();
|
||||
}
|
||||
return CACHE;
|
||||
}
|
||||
|
||||
}
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.manager.server;
|
||||
|
||||
/**
|
||||
* This enum contains all possible comparison types for server versions.
|
||||
*/
|
||||
public enum VersionComparison {
|
||||
/*
|
||||
The server version equals the compared server version.
|
||||
*/
|
||||
EQUALS,
|
||||
/*
|
||||
The server version is newer than the compared server version.
|
||||
*/
|
||||
NEWER_THAN,
|
||||
/*
|
||||
The server version is newer than or equal to the compared server version.
|
||||
*/
|
||||
NEWER_THAN_OR_EQUALS,
|
||||
/*
|
||||
The server version is older than the compared server version.
|
||||
*/
|
||||
OLDER_THAN,
|
||||
/*
|
||||
The server version is older than or equal to the compared server version.
|
||||
*/
|
||||
OLDER_THAN_OR_EQUALS;
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.netty;
|
||||
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufAllocationOperator;
|
||||
import com.github.retrooper.packetevents.netty.buffer.ByteBufOperator;
|
||||
import com.github.retrooper.packetevents.netty.channel.ChannelOperator;
|
||||
|
||||
public interface NettyManager {
|
||||
ChannelOperator getChannelOperator();
|
||||
|
||||
ByteBufOperator getByteBufOperator();
|
||||
|
||||
ByteBufAllocationOperator getByteBufAllocationOperator();
|
||||
}
|
||||
-36
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.netty.buffer;
|
||||
|
||||
public interface ByteBufAllocationOperator {
|
||||
Object wrappedBuffer(byte[] bytes);
|
||||
|
||||
Object copiedBuffer(byte[] bytes);
|
||||
|
||||
Object buffer();
|
||||
Object buffer(int initialCapacity);
|
||||
|
||||
Object directBuffer();
|
||||
Object directBuffer(int initialCapacity);
|
||||
|
||||
Object compositeBuffer();
|
||||
Object compositeBuffer(int maxNumComponents);
|
||||
|
||||
Object emptyBuffer();
|
||||
}
|
||||
@@ -1,286 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.netty.buffer;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public class ByteBufHelper {
|
||||
public static int capacity(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().capacity(buffer);
|
||||
}
|
||||
|
||||
public static Object capacity(Object buffer, int capacity) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().capacity(buffer, capacity);
|
||||
}
|
||||
|
||||
public static int readerIndex(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readerIndex(buffer);
|
||||
}
|
||||
|
||||
public static Object readerIndex(Object buffer, int readerIndex) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readerIndex(buffer, readerIndex);
|
||||
}
|
||||
|
||||
public static int writerIndex(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().writerIndex(buffer);
|
||||
}
|
||||
|
||||
public static Object writerIndex(Object buffer, int writerIndex) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().writerIndex(buffer, writerIndex);
|
||||
}
|
||||
|
||||
public static int readableBytes(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readableBytes(buffer);
|
||||
}
|
||||
|
||||
public static int writableBytes(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().writableBytes(buffer);
|
||||
}
|
||||
|
||||
public static Object clear(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().clear(buffer);
|
||||
}
|
||||
|
||||
public static String toString(Object buffer, int index, int length, Charset charset) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().toString(buffer, index, length, charset);
|
||||
}
|
||||
|
||||
public static byte readByte(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readByte(buffer);
|
||||
}
|
||||
|
||||
public static void writeByte(Object buffer, int value) {
|
||||
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeByte(buffer, value);
|
||||
}
|
||||
|
||||
public static boolean readBoolean(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readBoolean(buffer);
|
||||
}
|
||||
|
||||
public static void writeBoolean(Object buffer, boolean value) {
|
||||
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeBoolean(buffer, value);
|
||||
}
|
||||
|
||||
public static short readUnsignedByte(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readUnsignedByte(buffer);
|
||||
}
|
||||
|
||||
public static char readChar(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readChar(buffer);
|
||||
}
|
||||
|
||||
public static void writeChar(Object buffer, int value) {
|
||||
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeChar(buffer, value);
|
||||
}
|
||||
|
||||
public static short readShort(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readShort(buffer);
|
||||
}
|
||||
|
||||
public static int readUnsignedShort(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readUnsignedShort(buffer);
|
||||
}
|
||||
|
||||
public static void writeShort(Object buffer, int value) {
|
||||
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeShort(buffer, value);
|
||||
}
|
||||
|
||||
public static int readMedium(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readMedium(buffer);
|
||||
}
|
||||
|
||||
public static void writeMedium(Object buffer, int value) {
|
||||
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeMedium(buffer, value);
|
||||
}
|
||||
|
||||
public static int readInt(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readInt(buffer);
|
||||
}
|
||||
|
||||
public static void writeInt(Object buffer, int value) {
|
||||
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeInt(buffer, value);
|
||||
}
|
||||
|
||||
public static long readUnsignedInt(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readUnsignedInt(buffer);
|
||||
}
|
||||
|
||||
public static long readLong(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readLong(buffer);
|
||||
}
|
||||
|
||||
public static void writeLong(Object buffer, long value) {
|
||||
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeLong(buffer, value);
|
||||
}
|
||||
|
||||
public static float readFloat(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readFloat(buffer);
|
||||
}
|
||||
|
||||
public static void writeFloat(Object buffer, float value) {
|
||||
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeFloat(buffer, value);
|
||||
}
|
||||
|
||||
public static double readDouble(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readDouble(buffer);
|
||||
}
|
||||
|
||||
public static void writeDouble(Object buffer, double value) {
|
||||
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeDouble(buffer, value);
|
||||
}
|
||||
|
||||
public static Object getBytes(Object buffer, int index, byte[] destination) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().getBytes(buffer, index, destination);
|
||||
}
|
||||
|
||||
public static short getUnsignedByte(Object buffer, int index) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().getUnsignedByte(buffer, index);
|
||||
}
|
||||
|
||||
public static boolean isReadable(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().isReadable(buffer);
|
||||
}
|
||||
|
||||
public static Object copy(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().copy(buffer);
|
||||
}
|
||||
|
||||
public static Object duplicate(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().duplicate(buffer);
|
||||
}
|
||||
|
||||
public static boolean hasArray(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().hasArray(buffer);
|
||||
}
|
||||
|
||||
public static byte[] array(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().array(buffer);
|
||||
}
|
||||
|
||||
public static Object retain(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().retain(buffer);
|
||||
}
|
||||
|
||||
public static Object retainedDuplicate(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().retainedDuplicate(buffer);
|
||||
}
|
||||
|
||||
public static Object readSlice(Object buffer, int length) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readSlice(buffer, length);
|
||||
}
|
||||
|
||||
public static Object readBytes(Object buffer, byte[] destination, int destinationIndex, int length) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readBytes(buffer, destination, destinationIndex, length);
|
||||
}
|
||||
|
||||
public static Object readBytes(Object buffer, int length) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().readBytes(buffer, length);
|
||||
}
|
||||
|
||||
public static Object writeBytes(Object buffer, Object src) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeBytes(buffer, src);
|
||||
}
|
||||
|
||||
public static void readBytes(Object buffer, byte[] bytes) {
|
||||
PacketEvents.getAPI().getNettyManager().getByteBufOperator().readBytes(buffer, bytes);
|
||||
}
|
||||
|
||||
public static void writeBytes(Object buffer, byte[] bytes) {
|
||||
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeBytes(buffer, bytes);
|
||||
}
|
||||
|
||||
public static void writeBytes(Object buffer, byte[] bytes, int offset, int length) {
|
||||
PacketEvents.getAPI().getNettyManager().getByteBufOperator().writeBytes(buffer, bytes, offset, length);
|
||||
}
|
||||
|
||||
public static boolean release(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().release(buffer);
|
||||
}
|
||||
|
||||
public static int refCnt(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().refCnt(buffer);
|
||||
}
|
||||
|
||||
public static Object skipBytes(Object buffer, int length) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().skipBytes(buffer, length);
|
||||
}
|
||||
|
||||
public static Object markReaderIndex(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().markReaderIndex(buffer);
|
||||
}
|
||||
|
||||
public static Object resetReaderIndex(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().resetReaderIndex(buffer);
|
||||
}
|
||||
|
||||
public static Object markWriterIndex(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().markWriterIndex(buffer);
|
||||
}
|
||||
|
||||
public static Object resetWriterIndex(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().resetWriterIndex(buffer);
|
||||
}
|
||||
|
||||
public static Object allocateNewBuffer(Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufOperator().allocateNewBuffer(buffer);
|
||||
}
|
||||
|
||||
public static int getByteSize(int value) {
|
||||
for (int i = 1; i < 5; ++i) {
|
||||
if ((value & -1 << i * 7) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 5;
|
||||
}
|
||||
|
||||
public static int readVarInt(Object buffer) {
|
||||
int value = 0;
|
||||
int length = 0;
|
||||
byte currentByte;
|
||||
do {
|
||||
currentByte = readByte(buffer);
|
||||
value |= (currentByte & 0x7F) << (length * 7);
|
||||
length++;
|
||||
if (length > 5) {
|
||||
throw new RuntimeException("VarInt is too large. Must be smaller than 5 bytes.");
|
||||
}
|
||||
} while ((currentByte & 0x80) == 0x80);
|
||||
return value;
|
||||
}
|
||||
|
||||
public static void writeVarInt(Object buffer, int value) {
|
||||
while (true) {
|
||||
if ((value & ~0x7F) == 0) {
|
||||
writeByte(buffer, value);
|
||||
return;
|
||||
}
|
||||
writeByte(buffer, (value & 0x7F) | 0x80);
|
||||
value >>>= 7;
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] copyBytes(Object buffer) {
|
||||
byte[] bytes = new byte[readableBytes(buffer)];
|
||||
getBytes(buffer, readerIndex(buffer), bytes);
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
-242
@@ -1,242 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.netty.buffer;
|
||||
|
||||
import com.github.retrooper.packetevents.exception.PacketProcessException;
|
||||
|
||||
import java.io.*;
|
||||
//TODO give netty credit
|
||||
public class ByteBufInputStream extends InputStream implements DataInput {
|
||||
private final Object buffer;
|
||||
private final int startIndex;
|
||||
private final int endIndex;
|
||||
private final boolean releaseOnClose;
|
||||
private final StringBuilder lineBuf;
|
||||
private boolean closed;
|
||||
|
||||
public ByteBufInputStream(Object buffer) {
|
||||
this(buffer, ByteBufHelper.readableBytes(buffer));
|
||||
}
|
||||
|
||||
public ByteBufInputStream(Object buffer, int length) {
|
||||
this(buffer, length, false);
|
||||
}
|
||||
|
||||
public ByteBufInputStream(Object buffer, boolean releaseOnClose) {
|
||||
this(buffer, ByteBufHelper.readableBytes(buffer), releaseOnClose);
|
||||
}
|
||||
|
||||
public ByteBufInputStream(Object buffer, int maxLength, boolean releaseOnClose) {
|
||||
this.lineBuf = new StringBuilder();
|
||||
if (buffer == null) {
|
||||
throw new NullPointerException("buffer");
|
||||
} else if (maxLength < 0) {
|
||||
if (releaseOnClose) {
|
||||
ByteBufHelper.release(buffer);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException("maxLength: " + maxLength);
|
||||
} else if (ByteBufHelper.readableBytes(buffer) > maxLength) {
|
||||
if (releaseOnClose) {
|
||||
ByteBufHelper.release(buffer);
|
||||
}
|
||||
|
||||
throw new IndexOutOfBoundsException("Too many bytes to be read - Found " + ByteBufHelper.readableBytes(buffer) + ", maximum is " + maxLength);
|
||||
} else {
|
||||
this.releaseOnClose = releaseOnClose;
|
||||
this.buffer = buffer;
|
||||
this.startIndex = ByteBufHelper.readerIndex(buffer);
|
||||
this.endIndex = this.startIndex + ByteBufHelper.readableBytes(buffer);
|
||||
ByteBufHelper.markReaderIndex(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public int readBytes() {
|
||||
return ByteBufHelper.readerIndex(buffer) - this.startIndex;
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
try {
|
||||
super.close();
|
||||
} finally {
|
||||
if (this.releaseOnClose && !this.closed) {
|
||||
this.closed = true;
|
||||
ByteBufHelper.release(buffer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public int available() throws IOException {
|
||||
return this.endIndex - ByteBufHelper.readerIndex(buffer);
|
||||
}
|
||||
|
||||
public void mark(int readlimit) {
|
||||
ByteBufHelper.markReaderIndex(buffer);
|
||||
}
|
||||
|
||||
public boolean markSupported() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public int read() throws IOException {
|
||||
return !(ByteBufHelper.isReadable(buffer)) ? -1 : ByteBufHelper.readByte(buffer) & 255;
|
||||
}
|
||||
|
||||
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
int available = this.available();
|
||||
if (available == 0) {
|
||||
return -1;
|
||||
} else {
|
||||
len = Math.min(available, len);
|
||||
ByteBufHelper.readBytes(buffer, b, off, len);
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() throws IOException {
|
||||
ByteBufHelper.resetReaderIndex(buffer);
|
||||
}
|
||||
|
||||
public long skip(long n) throws IOException {
|
||||
return n > 2147483647L ? (long) this.skipBytes(2147483647) : (long) this.skipBytes((int) n);
|
||||
}
|
||||
|
||||
public boolean readBoolean() throws IOException {
|
||||
this.checkAvailable(1);
|
||||
return this.read() != 0;
|
||||
}
|
||||
|
||||
public byte[] readBytes(int len) {
|
||||
byte[] bytes = new byte[len];
|
||||
ByteBufHelper.readBytes(buffer, bytes);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public byte readByte() throws IOException {
|
||||
if (!(ByteBufHelper.isReadable(buffer))) {
|
||||
throw new EOFException();
|
||||
} else {
|
||||
return ByteBufHelper.readByte(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public char readChar() throws IOException {
|
||||
return (char) this.readShort();
|
||||
}
|
||||
|
||||
public double readDouble() throws IOException {
|
||||
return Double.longBitsToDouble(this.readLong());
|
||||
}
|
||||
|
||||
public float readFloat() throws IOException {
|
||||
return Float.intBitsToFloat(this.readInt());
|
||||
}
|
||||
|
||||
public void readFully(byte[] b) throws IOException {
|
||||
this.readFully(b, 0, b.length);
|
||||
}
|
||||
|
||||
public void readFully(byte[] b, int off, int len) throws IOException {
|
||||
this.checkAvailable(len);
|
||||
ByteBufHelper.readBytes(buffer, b, off, len);
|
||||
}
|
||||
|
||||
public int readInt() throws IOException {
|
||||
this.checkAvailable(4);
|
||||
return ByteBufHelper.readInt(buffer);
|
||||
}
|
||||
|
||||
public String readLine() throws IOException {
|
||||
this.lineBuf.setLength(0);
|
||||
|
||||
while (ByteBufHelper.isReadable(buffer)) {
|
||||
int c = ByteBufHelper.readUnsignedByte(buffer);
|
||||
switch (c) {
|
||||
case 13:
|
||||
if (ByteBufHelper.isReadable(buffer)
|
||||
&& (char) ByteBufHelper.getUnsignedByte(buffer, ByteBufHelper.readerIndex(buffer)) == '\n') {
|
||||
ByteBufHelper.skipBytes(buffer, 1);
|
||||
}
|
||||
case 10:
|
||||
return this.lineBuf.toString();
|
||||
default:
|
||||
this.lineBuf.append((char) c);
|
||||
}
|
||||
}
|
||||
|
||||
return this.lineBuf.length() > 0 ? this.lineBuf.toString() : null;
|
||||
}
|
||||
|
||||
public long readLong() throws IOException {
|
||||
this.checkAvailable(8);
|
||||
return ByteBufHelper.readLong(buffer);
|
||||
}
|
||||
|
||||
public long[] readLongs(int size) throws IOException {
|
||||
long[] array = new long[size];
|
||||
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = readLong();
|
||||
}
|
||||
return array;
|
||||
}
|
||||
|
||||
public short readShort() throws IOException {
|
||||
this.checkAvailable(2);
|
||||
return ByteBufHelper.readShort(buffer);
|
||||
}
|
||||
|
||||
public String readUTF() throws IOException {
|
||||
String text = DataInputStream.readUTF(this);
|
||||
return text;
|
||||
}
|
||||
|
||||
public int readUnsignedByte() throws IOException {
|
||||
return this.readByte() & 255;
|
||||
}
|
||||
|
||||
public int readUnsignedShort() throws IOException {
|
||||
return this.readShort() & '\uffff';
|
||||
}
|
||||
|
||||
public int skipBytes(int n) throws IOException {
|
||||
int nBytes = Math.min(this.available(), n);
|
||||
ByteBufHelper.skipBytes(buffer, nBytes);
|
||||
return nBytes;
|
||||
}
|
||||
|
||||
private void checkAvailable(int fieldSize) throws IOException {
|
||||
if (fieldSize < 0) {
|
||||
throw new IndexOutOfBoundsException("fieldSize cannot be a negative number");
|
||||
} else if (fieldSize > this.available()) {
|
||||
int value = this.available();
|
||||
String msg = "fieldSize is too long! Length is " + fieldSize + ", but maximum is " + value;
|
||||
if (value == 0) {
|
||||
throw new PacketProcessException(msg);
|
||||
}
|
||||
else {
|
||||
throw new EOFException(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-120
@@ -1,120 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.netty.buffer;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
public interface ByteBufOperator {
|
||||
int capacity(Object buffer);
|
||||
Object capacity(Object buffer, int capacity);
|
||||
int readerIndex(Object buffer);
|
||||
Object readerIndex(Object buffer, int readerIndex);
|
||||
|
||||
int writerIndex(Object buffer);
|
||||
Object writerIndex(Object buffer, int writerIndex);
|
||||
|
||||
int readableBytes(Object buffer);
|
||||
int writableBytes(Object buffer);
|
||||
Object clear(Object buffer);
|
||||
|
||||
byte readByte(Object buffer);
|
||||
short readShort(Object buffer);
|
||||
int readMedium(Object buffer);
|
||||
int readInt(Object buffer);
|
||||
long readUnsignedInt(Object buffer);
|
||||
long readLong(Object buffer);
|
||||
|
||||
void writeByte(Object buffer, int value);
|
||||
void writeShort(Object buffer, int value);
|
||||
void writeMedium(Object buffer, int value);
|
||||
void writeInt(Object buffer, int value);
|
||||
void writeLong(Object buffer, long value);
|
||||
|
||||
Object getBytes(Object buffer, int index, byte[] destination);
|
||||
short getUnsignedByte(Object buffer, int index);
|
||||
|
||||
boolean isReadable(Object buffer);
|
||||
Object copy(Object buffer);
|
||||
Object duplicate(Object buffer);
|
||||
boolean hasArray(Object buffer);
|
||||
byte[] array(Object buffer);
|
||||
Object retain(Object buffer);
|
||||
Object retainedDuplicate(Object buffer);
|
||||
Object readSlice(Object buffer, int length);
|
||||
Object readBytes(Object buffer, byte[] destination, int destinationIndex, int length);
|
||||
Object readBytes(Object buffer, int length);
|
||||
void readBytes(Object buffer, byte[] bytes);
|
||||
|
||||
Object writeBytes(Object buffer, Object src);
|
||||
Object writeBytes(Object buffer, byte[] bytes);
|
||||
Object writeBytes(Object buffer, byte[] bytes, int offset, int length);
|
||||
|
||||
boolean release(Object buffer);
|
||||
int refCnt(Object buffer);
|
||||
Object skipBytes(Object buffer, int length);
|
||||
String toString(Object buffer, int index, int length, Charset charset);
|
||||
Object markReaderIndex(Object buffer);
|
||||
Object resetReaderIndex(Object buffer);
|
||||
Object markWriterIndex(Object buffer);
|
||||
Object resetWriterIndex(Object buffer);
|
||||
|
||||
Object allocateNewBuffer(Object buffer);
|
||||
|
||||
default float readFloat(Object buffer) {
|
||||
return Float.intBitsToFloat(readInt(buffer));
|
||||
}
|
||||
|
||||
default void writeFloat(Object buffer, float value) {
|
||||
writeInt(buffer, Float.floatToIntBits(value));
|
||||
}
|
||||
|
||||
default double readDouble(Object buffer) {
|
||||
return Double.longBitsToDouble(readLong(buffer));
|
||||
}
|
||||
|
||||
default void writeDouble(Object buffer, double value) {
|
||||
writeLong(buffer, Double.doubleToLongBits(value));
|
||||
}
|
||||
|
||||
default char readChar(Object buffer) {
|
||||
return (char) readShort(buffer);
|
||||
}
|
||||
|
||||
default void writeChar(Object buffer, int value) {
|
||||
writeShort(buffer, value);
|
||||
}
|
||||
|
||||
//Use writeShort to write
|
||||
default int readUnsignedShort(Object buffer) {
|
||||
return readShort(buffer) & '\uffff';
|
||||
}
|
||||
|
||||
//Use writeByte to write
|
||||
default short readUnsignedByte(Object buffer) {
|
||||
return (short) (this.readByte(buffer) & 255);
|
||||
}
|
||||
|
||||
default boolean readBoolean(Object buffer) {
|
||||
return readByte(buffer) != 0;
|
||||
}
|
||||
|
||||
default void writeBoolean(Object buffer, boolean value) {
|
||||
writeByte(buffer, value ? 1 : 0);
|
||||
}
|
||||
}
|
||||
-114
@@ -1,114 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
//TODO Give netty credit
|
||||
|
||||
package com.github.retrooper.packetevents.netty.buffer;
|
||||
|
||||
import java.io.DataOutput;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class ByteBufOutputStream extends OutputStream implements DataOutput {
|
||||
private final Object buffer;
|
||||
private final int startIndex;
|
||||
private final DataOutputStream utf8out = new DataOutputStream(this);
|
||||
|
||||
public ByteBufOutputStream(Object buffer) {
|
||||
if (buffer == null) {
|
||||
throw new NullPointerException("buffer");
|
||||
} else {
|
||||
this.buffer = buffer;
|
||||
this.startIndex = ByteBufHelper.writerIndex(buffer);
|
||||
}
|
||||
}
|
||||
|
||||
public int writtenBytes() {
|
||||
return ByteBufHelper.writerIndex(buffer) - this.startIndex;
|
||||
}
|
||||
|
||||
public void write(byte[] b, int off, int len) throws IOException {
|
||||
if (len != 0) {
|
||||
ByteBufHelper.writeBytes(buffer, b, off, len);
|
||||
}
|
||||
}
|
||||
|
||||
public void write(byte[] b) throws IOException {
|
||||
ByteBufHelper.writeBytes(buffer, b);
|
||||
}
|
||||
|
||||
public void write(int b) throws IOException {
|
||||
ByteBufHelper.writeByte(buffer, b);
|
||||
}
|
||||
|
||||
public void writeBoolean(boolean v) throws IOException {
|
||||
ByteBufHelper.writeBoolean(buffer, v);
|
||||
}
|
||||
|
||||
public void writeByte(int v) throws IOException {
|
||||
ByteBufHelper.writeByte(buffer, v);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void writeBytes(String s) throws IOException {
|
||||
throw new IllegalStateException("This operation is not supported!");
|
||||
}
|
||||
|
||||
public void writeChar(int v) throws IOException {
|
||||
ByteBufHelper.writeChar(buffer, v);
|
||||
}
|
||||
|
||||
public void writeChars(String s) throws IOException {
|
||||
int len = s.length();
|
||||
|
||||
for (int i = 0; i < len; ++i) {
|
||||
ByteBufHelper.writeChar(buffer, s.charAt(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void writeDouble(double v) throws IOException {
|
||||
ByteBufHelper.writeDouble(buffer, v);
|
||||
}
|
||||
|
||||
public void writeFloat(float v) throws IOException {
|
||||
ByteBufHelper.writeFloat(buffer, v);
|
||||
}
|
||||
|
||||
public void writeInt(int v) throws IOException {
|
||||
ByteBufHelper.writeInt(buffer, v);
|
||||
}
|
||||
|
||||
public void writeLong(long v) throws IOException {
|
||||
ByteBufHelper.writeLong(buffer, v);
|
||||
}
|
||||
|
||||
public void writeShort(int v) throws IOException {
|
||||
ByteBufHelper.writeShort(buffer, v);
|
||||
}
|
||||
|
||||
public void writeUTF(String s) throws IOException {
|
||||
this.utf8out.writeUTF(s);
|
||||
}
|
||||
|
||||
public Object buffer() {
|
||||
return this.buffer;
|
||||
}
|
||||
}
|
||||
|
||||
-59
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.netty.buffer;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
|
||||
public class UnpooledByteBufAllocationHelper {
|
||||
public static Object wrappedBuffer(byte[] bytes) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().wrappedBuffer(bytes);
|
||||
}
|
||||
|
||||
public static Object copiedBuffer(byte[] bytes) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().copiedBuffer(bytes);
|
||||
}
|
||||
|
||||
public static Object buffer() {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().buffer();
|
||||
}
|
||||
|
||||
public static Object directBuffer() {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().directBuffer();
|
||||
}
|
||||
|
||||
public static Object compositeBuffer() {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().compositeBuffer();
|
||||
}
|
||||
|
||||
public static Object buffer(int initialCapacity) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().buffer(initialCapacity);
|
||||
}
|
||||
|
||||
public static Object directBuffer(int initialCapacity) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().directBuffer(initialCapacity);
|
||||
}
|
||||
|
||||
public static Object compositeBuffer(int maxNumComponents) {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().compositeBuffer(maxNumComponents);
|
||||
}
|
||||
|
||||
public static Object emptyBuffer() {
|
||||
return PacketEvents.getAPI().getNettyManager().getByteBufAllocationOperator().emptyBuffer();
|
||||
}
|
||||
}
|
||||
@@ -1,103 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.netty.channel;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ChannelHelper {
|
||||
public static SocketAddress remoteAddress(Object channel) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().remoteAddress(channel);
|
||||
}
|
||||
|
||||
public static SocketAddress localAddress(Object channel) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().localAddress(channel);
|
||||
}
|
||||
|
||||
public static boolean isOpen(Object channel) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().isOpen(channel);
|
||||
}
|
||||
|
||||
public static Object close(Object channel) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().close(channel);
|
||||
}
|
||||
|
||||
public static Object write(Object channel, Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().write(channel, buffer);
|
||||
}
|
||||
|
||||
public static Object flush(Object channel) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().flush(channel);
|
||||
}
|
||||
|
||||
public static Object writeAndFlush(Object channel, Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().writeAndFlush(channel, buffer);
|
||||
}
|
||||
|
||||
public static Object fireChannelRead(Object channel, Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().fireChannelRead(channel, buffer);
|
||||
}
|
||||
|
||||
public static Object writeInContext(Object channel, String ctx, Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().writeInContext(channel, ctx, buffer);
|
||||
}
|
||||
|
||||
public static Object flushInContext(Object channel, String ctx) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().flushInContext(channel, ctx);
|
||||
}
|
||||
|
||||
public static Object writeAndFlushInContext(Object channel, String ctx, Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().writeAndFlushInContext(channel, ctx, buffer);
|
||||
}
|
||||
|
||||
public static Object fireChannelReadInContext(Object channel, String ctx, Object buffer) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().fireChannelReadInContext(channel, ctx, buffer);
|
||||
}
|
||||
|
||||
public static List<String> pipelineHandlerNames(Object channel) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().pipelineHandlerNames(channel);
|
||||
}
|
||||
|
||||
public static String pipelineHandlerNamesAsString(Object channel) {
|
||||
return Arrays.toString(pipelineHandlerNames(channel).toArray(new String[0]));
|
||||
}
|
||||
|
||||
public static Object getPipeline(Object channel) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().getPipeline(channel);
|
||||
}
|
||||
|
||||
public static Object getPipelineHandler(Object channel, String name) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().getPipelineHandler(channel, name);
|
||||
}
|
||||
|
||||
public static Object getPipelineContext(Object channel, String handlerName) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().getPipelineContext(channel, handlerName);
|
||||
}
|
||||
|
||||
public static Object pooledByteBuf(Object channel) {
|
||||
return PacketEvents.getAPI().getNettyManager().getChannelOperator().pooledByteBuf(channel);
|
||||
}
|
||||
|
||||
public static void runInEventLoop(Object channel, Runnable runnable) {
|
||||
PacketEvents.getAPI().getNettyManager().getChannelOperator().runInEventLoop(channel, runnable);
|
||||
}
|
||||
}
|
||||
-60
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.netty.channel;
|
||||
|
||||
import java.net.SocketAddress;
|
||||
import java.util.List;
|
||||
|
||||
public interface ChannelOperator {
|
||||
SocketAddress remoteAddress(Object channel);
|
||||
|
||||
SocketAddress localAddress(Object channel);
|
||||
|
||||
boolean isOpen(Object channel);
|
||||
|
||||
Object close(Object channel);
|
||||
|
||||
Object write(Object channel, Object buffer);
|
||||
|
||||
Object flush(Object channel);
|
||||
|
||||
Object writeAndFlush(Object channel, Object buffer);
|
||||
|
||||
Object fireChannelRead(Object channel, Object buffer);
|
||||
|
||||
Object writeInContext(Object channel, String ctx, Object buffer);
|
||||
|
||||
Object flushInContext(Object channel, String ctx);
|
||||
|
||||
Object writeAndFlushInContext(Object channel, String ctx, Object buffer);
|
||||
|
||||
Object fireChannelReadInContext(Object channel, String ctx, Object buffer);
|
||||
|
||||
List<String> pipelineHandlerNames(Object channel);
|
||||
|
||||
Object getPipelineHandler(Object channel, String name);
|
||||
|
||||
Object getPipelineContext(Object channel, String name);
|
||||
|
||||
Object getPipeline(Object channel);
|
||||
|
||||
void runInEventLoop(Object channel, Runnable runnable);
|
||||
|
||||
Object pooledByteBuf(Object channel);
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol;
|
||||
|
||||
/**
|
||||
* @author retrooper
|
||||
* @since 1.8
|
||||
*/
|
||||
public enum ConnectionState {
|
||||
HANDSHAKING, STATUS, LOGIN, PLAY, CONFIGURATION;
|
||||
|
||||
public static ConnectionState getById(int id) {
|
||||
if (id >= values().length || id < 0) {
|
||||
return null;
|
||||
}
|
||||
return values()[id];
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol;
|
||||
|
||||
public enum PacketSide {
|
||||
CLIENT, SERVER;
|
||||
|
||||
public PacketSide getOpposite() {
|
||||
if (this == CLIENT) {
|
||||
return SERVER;
|
||||
}
|
||||
else {
|
||||
return CLIENT;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol;
|
||||
|
||||
//TODO
|
||||
public enum ProtocolVersion {
|
||||
UNKNOWN
|
||||
}
|
||||
-144
@@ -1,144 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.advancements;
|
||||
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class Advancement {
|
||||
|
||||
private @Nullable ResourceLocation parent;
|
||||
private @Nullable AdvancementDisplay display;
|
||||
/**
|
||||
* Removed with 1.20.2
|
||||
*/
|
||||
private List<String> criteria;
|
||||
private List<List<String>> requirements;
|
||||
/**
|
||||
* Added with 1.20
|
||||
*/
|
||||
private boolean sendsTelemetryData;
|
||||
|
||||
public Advancement(
|
||||
@Nullable ResourceLocation parent,
|
||||
@Nullable AdvancementDisplay display,
|
||||
List<List<String>> requirements,
|
||||
boolean sendsTelemetryData
|
||||
) {
|
||||
this(parent, display, Collections.emptyList(), requirements, sendsTelemetryData);
|
||||
}
|
||||
|
||||
@ApiStatus.Obsolete
|
||||
public Advancement(
|
||||
@Nullable ResourceLocation parent,
|
||||
@Nullable AdvancementDisplay display,
|
||||
List<String> criteria,
|
||||
List<List<String>> requirements,
|
||||
boolean sendsTelemetryData
|
||||
) {
|
||||
this.parent = parent;
|
||||
this.display = display;
|
||||
this.criteria = criteria;
|
||||
this.requirements = requirements;
|
||||
this.sendsTelemetryData = sendsTelemetryData;
|
||||
}
|
||||
|
||||
public static Advancement read(PacketWrapper<?> wrapper) {
|
||||
ResourceLocation parentId = wrapper.readOptional(ResourceLocation::read);
|
||||
AdvancementDisplay display = wrapper.readOptional(AdvancementDisplay::read);
|
||||
List<String> criteria = wrapper.getServerVersion().isOlderThan(ServerVersion.V_1_20_2)
|
||||
? wrapper.readList(PacketWrapper::readString) : null;
|
||||
List<List<String>> requirements = wrapper.readList(
|
||||
ew -> wrapper.readList(PacketWrapper::readString));
|
||||
boolean sendsTelemetryData = wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_20)
|
||||
&& wrapper.readBoolean();
|
||||
return new Advancement(parentId, display, criteria, requirements, sendsTelemetryData);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, Advancement advancement) {
|
||||
wrapper.writeOptional(advancement.parent, ResourceLocation::write);
|
||||
wrapper.writeOptional(advancement.display, AdvancementDisplay::write);
|
||||
if (wrapper.getServerVersion().isOlderThan(ServerVersion.V_1_20_2)) {
|
||||
wrapper.writeList(advancement.criteria, PacketWrapper::writeString);
|
||||
}
|
||||
wrapper.writeList(advancement.getRequirements(), (ew, anyList) ->
|
||||
ew.writeList(anyList, PacketWrapper::writeString));
|
||||
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_20)) {
|
||||
wrapper.writeBoolean(advancement.sendsTelemetryData);
|
||||
}
|
||||
}
|
||||
|
||||
public @Nullable ResourceLocation getParent() {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
public void setParent(@Nullable ResourceLocation parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public @Nullable AdvancementDisplay getDisplay() {
|
||||
return this.display;
|
||||
}
|
||||
|
||||
public void setDisplay(@Nullable AdvancementDisplay display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removed with 1.20.2
|
||||
*/
|
||||
public List<String> getCriteria() {
|
||||
return this.criteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removed with 1.20.2
|
||||
*/
|
||||
public void setCriteria(List<String> criteria) {
|
||||
this.criteria = criteria;
|
||||
}
|
||||
|
||||
public List<List<String>> getRequirements() {
|
||||
return this.requirements;
|
||||
}
|
||||
|
||||
public void setRequirements(List<List<String>> requirements) {
|
||||
this.requirements = requirements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Added with 1.20
|
||||
*/
|
||||
public boolean isSendsTelemetryData() {
|
||||
return this.sendsTelemetryData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Added with 1.20
|
||||
*/
|
||||
public void setSendsTelemetryData(boolean sendsTelemetryData) {
|
||||
this.sendsTelemetryData = sendsTelemetryData;
|
||||
}
|
||||
}
|
||||
-168
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.advancements;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.item.ItemStack;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class AdvancementDisplay {
|
||||
|
||||
public static final int FLAG_HAS_BACKGROUND = 0b001;
|
||||
public static final int FLAG_SHOW_TOAST = 0b010;
|
||||
public static final int FLAG_HIDDEN = 0b100;
|
||||
|
||||
private Component title;
|
||||
private Component description;
|
||||
private ItemStack icon;
|
||||
private AdvancementType type;
|
||||
private boolean showToast;
|
||||
private boolean hidden;
|
||||
private @Nullable ResourceLocation background;
|
||||
private float x;
|
||||
private float y;
|
||||
|
||||
public AdvancementDisplay(Component title, Component description, ItemStack icon, AdvancementType type, @Nullable ResourceLocation background, boolean showToast,
|
||||
boolean hidden, float x, float y) {
|
||||
this.title = title;
|
||||
this.description = description;
|
||||
this.icon = icon;
|
||||
this.type = type;
|
||||
this.showToast = showToast;
|
||||
this.hidden = hidden;
|
||||
this.background = background;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public static AdvancementDisplay read(PacketWrapper<?> wrapper) {
|
||||
Component title = wrapper.readComponent();
|
||||
Component description = wrapper.readComponent();
|
||||
ItemStack icon = wrapper.readItemStack();
|
||||
AdvancementType type = wrapper.readEnum(AdvancementType.class);
|
||||
int flags = wrapper.readInt();
|
||||
ResourceLocation background = (flags & FLAG_HAS_BACKGROUND) != 0 ? ResourceLocation.read(wrapper) : null;
|
||||
boolean showToast = (flags & FLAG_SHOW_TOAST) != 0;
|
||||
boolean hidden = (flags & FLAG_HIDDEN) != 0;
|
||||
float x = wrapper.readFloat();
|
||||
float y = wrapper.readFloat();
|
||||
return new AdvancementDisplay(title, description, icon, type, background, showToast, hidden, x, y);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, AdvancementDisplay display) {
|
||||
wrapper.writeComponent(display.title);
|
||||
wrapper.writeComponent(display.description);
|
||||
wrapper.writeItemStack(display.icon);
|
||||
wrapper.writeEnum(display.type);
|
||||
wrapper.writeInt(display.packFlags());
|
||||
if (display.background != null) {
|
||||
ResourceLocation.write(wrapper, display.background);
|
||||
}
|
||||
wrapper.writeFloat(display.x);
|
||||
wrapper.writeFloat(display.y);
|
||||
}
|
||||
|
||||
public int packFlags() {
|
||||
int flags = 0;
|
||||
if (this.background != null) {
|
||||
flags |= FLAG_HAS_BACKGROUND;
|
||||
}
|
||||
if (this.showToast) {
|
||||
flags |= FLAG_SHOW_TOAST;
|
||||
}
|
||||
if (this.hidden) {
|
||||
flags |= FLAG_HIDDEN;
|
||||
}
|
||||
return flags;
|
||||
}
|
||||
|
||||
public Component getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
public void setTitle(Component title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public Component getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void setDescription(Component description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public ItemStack getIcon() {
|
||||
return this.icon;
|
||||
}
|
||||
|
||||
public void setIcon(ItemStack icon) {
|
||||
this.icon = icon;
|
||||
}
|
||||
|
||||
public AdvancementType getType() {
|
||||
return this.type;
|
||||
}
|
||||
|
||||
public void setType(AdvancementType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public boolean isShowToast() {
|
||||
return this.showToast;
|
||||
}
|
||||
|
||||
public void setShowToast(boolean showToast) {
|
||||
this.showToast = showToast;
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return this.hidden;
|
||||
}
|
||||
|
||||
public void setHidden(boolean hidden) {
|
||||
this.hidden = hidden;
|
||||
}
|
||||
|
||||
public @Nullable ResourceLocation getBackground() {
|
||||
return this.background;
|
||||
}
|
||||
|
||||
public void setBackground(@Nullable ResourceLocation background) {
|
||||
this.background = background;
|
||||
}
|
||||
|
||||
public float getX() {
|
||||
return this.x;
|
||||
}
|
||||
|
||||
public void setX(float x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public float getY() {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public void setY(float y) {
|
||||
this.y = y;
|
||||
}
|
||||
}
|
||||
-60
@@ -1,60 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.advancements;
|
||||
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
|
||||
public final class AdvancementHolder {
|
||||
|
||||
private ResourceLocation identifier;
|
||||
private Advancement advancement;
|
||||
|
||||
public AdvancementHolder(ResourceLocation identifier, Advancement advancement) {
|
||||
this.identifier = identifier;
|
||||
this.advancement = advancement;
|
||||
}
|
||||
|
||||
public static AdvancementHolder read(PacketWrapper<?> wrapper) {
|
||||
ResourceLocation identifier = wrapper.readIdentifier();
|
||||
Advancement advancement = Advancement.read(wrapper);
|
||||
return new AdvancementHolder(identifier, advancement);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, AdvancementHolder holder) {
|
||||
wrapper.writeIdentifier(holder.identifier);
|
||||
Advancement.write(wrapper, holder.advancement);
|
||||
}
|
||||
|
||||
public ResourceLocation getIdentifier() {
|
||||
return this.identifier;
|
||||
}
|
||||
|
||||
public void setIdentifier(ResourceLocation identifier) {
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public Advancement getAdvancement() {
|
||||
return this.advancement;
|
||||
}
|
||||
|
||||
public void setAdvancement(Advancement advancement) {
|
||||
this.advancement = advancement;
|
||||
}
|
||||
}
|
||||
-75
@@ -1,75 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.advancements;
|
||||
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public final class AdvancementProgress {
|
||||
|
||||
private Map<String, CriterionProgress> criteria;
|
||||
|
||||
public AdvancementProgress(Map<String, CriterionProgress> criteria) {
|
||||
this.criteria = criteria;
|
||||
}
|
||||
|
||||
public static AdvancementProgress read(PacketWrapper<?> wrapper) {
|
||||
Map<String, CriterionProgress> criteria = wrapper.readMap(PacketWrapper::readString, CriterionProgress::read);
|
||||
return new AdvancementProgress(criteria);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, AdvancementProgress progress) {
|
||||
wrapper.writeMap(progress.getCriteria(), PacketWrapper::writeString, CriterionProgress::write);
|
||||
}
|
||||
|
||||
public Map<String, CriterionProgress> getCriteria() {
|
||||
return this.criteria;
|
||||
}
|
||||
|
||||
public void setCriteria(Map<String, CriterionProgress> criteria) {
|
||||
this.criteria = criteria;
|
||||
}
|
||||
|
||||
public static final class CriterionProgress {
|
||||
|
||||
private @Nullable Long obtainedTimestamp;
|
||||
|
||||
public CriterionProgress(@Nullable Long obtainedTimestamp) {
|
||||
this.obtainedTimestamp = obtainedTimestamp;
|
||||
}
|
||||
|
||||
public static CriterionProgress read(PacketWrapper<?> wrapper) {
|
||||
return new CriterionProgress(wrapper.readOptional(PacketWrapper::readLong));
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, CriterionProgress progress) {
|
||||
wrapper.writeOptional(progress.obtainedTimestamp, PacketWrapper::writeLong);
|
||||
}
|
||||
|
||||
public @Nullable Long getObtainedTimestamp() {
|
||||
return this.obtainedTimestamp;
|
||||
}
|
||||
|
||||
public void setObtainedTimestamp(@Nullable Long obtainedTimestamp) {
|
||||
this.obtainedTimestamp = obtainedTimestamp;
|
||||
}
|
||||
}
|
||||
}
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.advancements;
|
||||
|
||||
public enum AdvancementType {
|
||||
|
||||
TASK,
|
||||
CHALLENGE,
|
||||
GOAL,
|
||||
;
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2023 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.attribute;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.MathUtil;
|
||||
|
||||
public interface Attribute extends MappedEntity {
|
||||
|
||||
@Override
|
||||
default ResourceLocation getName() {
|
||||
return this.getName(PacketEvents.getAPI().getServerManager().getVersion().toClientVersion());
|
||||
}
|
||||
|
||||
ResourceLocation getName(ClientVersion version);
|
||||
|
||||
default double sanitizeValue(double value) {
|
||||
return this.sanitizeValue(value, PacketEvents.getAPI().getServerManager().getVersion().toClientVersion());
|
||||
}
|
||||
|
||||
default double sanitizeValue(double value, ClientVersion version) {
|
||||
if (!Double.isNaN(value)) {
|
||||
return MathUtil.clamp(value, this.getMinValue(), this.getMaxValue());
|
||||
}
|
||||
return this.getMinValue();
|
||||
}
|
||||
|
||||
double getDefaultValue();
|
||||
|
||||
double getMinValue();
|
||||
|
||||
double getMaxValue();
|
||||
}
|
||||
-39
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.attribute;
|
||||
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public interface AttributeDisplay {
|
||||
|
||||
static AttributeDisplay read(PacketWrapper<?> wrapper) {
|
||||
AttributeDisplayType<?> type = wrapper.readMappedEntity(AttributeDisplayTypes.getRegistry());
|
||||
return type.read(wrapper);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") // not unchecked
|
||||
static void write(PacketWrapper<?> wrapper, AttributeDisplay display) {
|
||||
wrapper.writeMappedEntity(display.getType());
|
||||
((AttributeDisplayType<? super AttributeDisplay>) display.getType()).write(wrapper, display);
|
||||
}
|
||||
|
||||
AttributeDisplayType<?> getType();
|
||||
}
|
||||
-31
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.attribute;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public interface AttributeDisplayType<T extends AttributeDisplay> extends MappedEntity {
|
||||
|
||||
T read(PacketWrapper<?> wrapper);
|
||||
|
||||
void write(PacketWrapper<?> wrapper, T display);
|
||||
}
|
||||
-56
@@ -1,56 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.attribute;
|
||||
|
||||
import com.github.retrooper.packetevents.util.mappings.VersionedRegistry;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public final class AttributeDisplayTypes {
|
||||
|
||||
private static final VersionedRegistry<AttributeDisplayType<?>> REGISTRY = new VersionedRegistry<>("attribute_display_type");
|
||||
|
||||
private AttributeDisplayTypes() {
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static <T extends AttributeDisplay> AttributeDisplayType<T> define(
|
||||
String name, PacketWrapper.Reader<T> reader, PacketWrapper.Writer<T> writer
|
||||
) {
|
||||
return REGISTRY.define(name, data ->
|
||||
new StaticAttributeDisplayType<>(data, reader, writer));
|
||||
}
|
||||
|
||||
public static VersionedRegistry<AttributeDisplayType<?>> getRegistry() {
|
||||
return REGISTRY;
|
||||
}
|
||||
|
||||
public static final AttributeDisplayType<DefaultAttributeDisplay> DEFAULT = define("default",
|
||||
DefaultAttributeDisplay::read, DefaultAttributeDisplay::write);
|
||||
public static final AttributeDisplayType<HiddenAttributeDisplay> HIDDEN = define("hidden",
|
||||
HiddenAttributeDisplay::read, HiddenAttributeDisplay::write);
|
||||
public static final AttributeDisplayType<OverrideAttributeDisplay> OVERRIDE = define("override",
|
||||
OverrideAttributeDisplay::read, OverrideAttributeDisplay::write);
|
||||
|
||||
static {
|
||||
REGISTRY.unloadMappings();
|
||||
}
|
||||
}
|
||||
-25
@@ -1,25 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.attribute;
|
||||
|
||||
public enum AttributeOperation {
|
||||
ADDITION,
|
||||
MULTIPLY_BASE,
|
||||
MULTIPLY_TOTAL,
|
||||
}
|
||||
-372
@@ -1,372 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2023 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.attribute;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.mappings.VersionedRegistry;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public final class Attributes {
|
||||
|
||||
private static final VersionedRegistry<Attribute> REGISTRY = new VersionedRegistry<>("attribute");
|
||||
|
||||
private Attributes() {
|
||||
}
|
||||
|
||||
private static Attribute define(
|
||||
String key, @Nullable String legacyPrefix,
|
||||
double def, double min, double max
|
||||
) {
|
||||
return REGISTRY.define(key, data ->
|
||||
new StaticAttribute(data, legacyPrefix, def, min, max));
|
||||
}
|
||||
|
||||
public static VersionedRegistry<Attribute> getRegistry() {
|
||||
return REGISTRY;
|
||||
}
|
||||
|
||||
public static Attribute getByName(String name) {
|
||||
// "remapping" to support < 1.21.2
|
||||
String normedName = ResourceLocation.normString(name);
|
||||
if (normedName.startsWith(ResourceLocation.VANILLA_NAMESPACE + ":generic.")
|
||||
|| normedName.startsWith(ResourceLocation.VANILLA_NAMESPACE + ":player.")
|
||||
|| normedName.startsWith(ResourceLocation.VANILLA_NAMESPACE + ":zombie.")) {
|
||||
normedName = normedName.substring(normedName.indexOf('.') + 1);
|
||||
}
|
||||
return REGISTRY.getByName(normedName);
|
||||
}
|
||||
|
||||
public static Attribute getById(ClientVersion version, int id) {
|
||||
return REGISTRY.getById(version, id);
|
||||
}
|
||||
|
||||
public static final Attribute ARMOR = define("armor",
|
||||
"generic", 0d, 0d, 30d);
|
||||
public static final Attribute ARMOR_TOUGHNESS = define("armor_toughness",
|
||||
"generic", 0d, 0d, 20d);
|
||||
public static final Attribute ATTACK_DAMAGE = define("attack_damage",
|
||||
"generic", 2d, 0d, 2048d);
|
||||
public static final Attribute ATTACK_KNOCKBACK = define("attack_knockback",
|
||||
"generic", 0d, 0d, 5d);
|
||||
public static final Attribute ATTACK_SPEED = define("attack_speed",
|
||||
"generic", 4d, 0d, 1024d);
|
||||
public static final Attribute FLYING_SPEED = define("flying_speed",
|
||||
"generic", 0.4d, 0d, 1024d);
|
||||
public static final Attribute FOLLOW_RANGE = define("follow_range",
|
||||
"generic", 32d, 0d, 2048d);
|
||||
public static final Attribute KNOCKBACK_RESISTANCE = define("knockback_resistance",
|
||||
"generic", 0d, 0d, 1d);
|
||||
public static final Attribute LUCK = define("luck",
|
||||
"generic", 0d, -1024d, 1024d);
|
||||
public static final Attribute MAX_HEALTH = define("max_health",
|
||||
"generic", 20d, 1d, 1024d);
|
||||
public static final Attribute MOVEMENT_SPEED = define("movement_speed",
|
||||
"generic", 0.7d, 0d, 1024d);
|
||||
public static final Attribute SPAWN_REINFORCEMENTS = define("spawn_reinforcements",
|
||||
"zombie", 0d, 0d, 1d);
|
||||
|
||||
/**
|
||||
* Added with 1.20.2
|
||||
*/
|
||||
public static final Attribute MAX_ABSORPTION = define("max_absorption",
|
||||
"generic", 0d, 0d, 2048d);
|
||||
|
||||
/**
|
||||
* Added with 1.20.5
|
||||
*/
|
||||
public static final Attribute BLOCK_BREAK_SPEED = define("block_break_speed",
|
||||
"player", 1d, 0d, 1024d);
|
||||
/**
|
||||
* Added with 1.20.5
|
||||
*/
|
||||
public static final Attribute BLOCK_INTERACTION_RANGE = define("block_interaction_range",
|
||||
"player", 4.5d, 0d, 64d);
|
||||
/**
|
||||
* Added with 1.20.5
|
||||
*/
|
||||
public static final Attribute ENTITY_INTERACTION_RANGE = define("entity_interaction_range",
|
||||
"player", 3d, 0d, 64d);
|
||||
/**
|
||||
* Added with 1.20.5
|
||||
*/
|
||||
public static final Attribute FALL_DAMAGE_MULTIPLIER = define("fall_damage_multiplier",
|
||||
"generic", 1d, 0d, 100d);
|
||||
/**
|
||||
* Added with 1.20.5
|
||||
*/
|
||||
public static final Attribute GRAVITY = define("gravity",
|
||||
"generic", 0.08d, -1d, 1d);
|
||||
/**
|
||||
* Added with 1.20.5
|
||||
*/
|
||||
public static final Attribute JUMP_STRENGTH = define("jump_strength",
|
||||
"generic", 0.42d, 0d, 32d);
|
||||
/**
|
||||
* Added with 1.20.5
|
||||
*/
|
||||
public static final Attribute SAFE_FALL_DISTANCE = define("safe_fall_distance",
|
||||
"generic", 3d, 0d, 1024d);
|
||||
/**
|
||||
* Added with 1.20.5
|
||||
*/
|
||||
public static final Attribute SCALE = define("scale",
|
||||
"generic", 1d, 1d / 16d, 16d);
|
||||
/**
|
||||
* Added with 1.20.5
|
||||
*/
|
||||
public static final Attribute STEP_HEIGHT = define("step_height",
|
||||
"generic", 0.6d, 0d, 10d);
|
||||
|
||||
/**
|
||||
* Added with 1.21
|
||||
*/
|
||||
public static final Attribute BURNING_TIME = define("burning_time",
|
||||
"generic", 0d, 1d, 1024d);
|
||||
/**
|
||||
* Added with 1.21
|
||||
*/
|
||||
public static final Attribute EXPLOSION_KNOCKBACK_RESISTANCE = define("explosion_knockback_resistance",
|
||||
"generic", 0d, 0d, 1d);
|
||||
/**
|
||||
* Added with 1.21
|
||||
*/
|
||||
public static final Attribute MINING_EFFICIENCY = define("mining_efficiency",
|
||||
"player", 0d, 0d, 1024d);
|
||||
/**
|
||||
* Added with 1.21
|
||||
*/
|
||||
public static final Attribute MOVEMENT_EFFICIENCY = define("movement_efficiency",
|
||||
"generic", 0d, 0d, 1d);
|
||||
/**
|
||||
* Added with 1.21
|
||||
*/
|
||||
public static final Attribute OXYGEN_BONUS = define("oxygen_bonus",
|
||||
"generic", 0d, 0d, 1024d);
|
||||
/**
|
||||
* Added with 1.21
|
||||
*/
|
||||
public static final Attribute SNEAKING_SPEED = define("sneaking_speed",
|
||||
"player", 0.3d, 0d, 1d);
|
||||
/**
|
||||
* Added with 1.21
|
||||
*/
|
||||
public static final Attribute SUBMERGED_MINING_SPEED = define("submerged_mining_speed",
|
||||
"player", 0.2d, 0d, 20d);
|
||||
/**
|
||||
* Added with 1.21
|
||||
*/
|
||||
public static final Attribute SWEEPING_DAMAGE_RATIO = define("sweeping_damage_ratio",
|
||||
"player", 0d, 0d, 1d);
|
||||
/**
|
||||
* Added with 1.21
|
||||
*/
|
||||
public static final Attribute WATER_MOVEMENT_EFFICIENCY = define("water_movement_efficiency",
|
||||
"generic", 0d, 0d, 1d);
|
||||
|
||||
/**
|
||||
* Added with 1.21.2
|
||||
*/
|
||||
public static final Attribute TEMPT_RANGE = define("tempt_range",
|
||||
null, 10d, 0d, 2048d);
|
||||
|
||||
/**
|
||||
* Added with 1.21.6
|
||||
*/
|
||||
public static final Attribute CAMERA_DISTANCE = define("camera_distance",
|
||||
null, 4d, 0d, 32d);
|
||||
/**
|
||||
* Added with 1.21.6
|
||||
*/
|
||||
public static final Attribute WAYPOINT_TRANSMIT_RANGE = define("waypoint_transmit_range",
|
||||
null, 0d, 0d, 60_000_000d);
|
||||
/**
|
||||
* Added with 1.21.6
|
||||
*/
|
||||
public static final Attribute WAYPOINT_RECEIVE_RANGE = define("waypoint_receive_range",
|
||||
null, 0d, 0d, 60_000_000d);
|
||||
|
||||
/**
|
||||
* This attribute has been renamed in 1.20.5 to {@link #JUMP_STRENGTH}
|
||||
*/
|
||||
@ApiStatus.Obsolete
|
||||
public static final Attribute HORSE_JUMP_STRENGTH = define("horse.jump_strength",
|
||||
null, 0.7d, 0d, 2d);
|
||||
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_ARMOR = ARMOR;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_ARMOR_TOUGHNESS = ARMOR_TOUGHNESS;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_ATTACK_DAMAGE = ATTACK_DAMAGE;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_ATTACK_KNOCKBACK = ATTACK_KNOCKBACK;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_ATTACK_SPEED = ATTACK_SPEED;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_FLYING_SPEED = FLYING_SPEED;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_FOLLOW_RANGE = FOLLOW_RANGE;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_KNOCKBACK_RESISTANCE = KNOCKBACK_RESISTANCE;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_LUCK = LUCK;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_MAX_HEALTH = MAX_HEALTH;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_MOVEMENT_SPEED = MOVEMENT_SPEED;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute ZOMBIE_SPAWN_REINFORCEMENTS = SPAWN_REINFORCEMENTS;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_MAX_ABSORPTION = MAX_ABSORPTION;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute PLAYER_BLOCK_BREAK_SPEED = BLOCK_BREAK_SPEED;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute PLAYER_BLOCK_INTERACTION_RANGE = BLOCK_INTERACTION_RANGE;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute PLAYER_ENTITY_INTERACTION_RANGE = ENTITY_INTERACTION_RANGE;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_FALL_DAMAGE_MULTIPLIER = FALL_DAMAGE_MULTIPLIER;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_GRAVITY = GRAVITY;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_JUMP_STRENGTH = JUMP_STRENGTH;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_SAFE_FALL_DISTANCE = SAFE_FALL_DISTANCE;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_SCALE = SCALE;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_STEP_HEIGHT = STEP_HEIGHT;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_BURNING_TIME = BURNING_TIME;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_EXPLOSION_KNOCKBACK_RESISTANCE = EXPLOSION_KNOCKBACK_RESISTANCE;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute PLAYER_MINING_EFFICIENCY = MINING_EFFICIENCY;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_MOVEMENT_EFFICIENCY = MOVEMENT_EFFICIENCY;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_OXYGEN_BONUS = OXYGEN_BONUS;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute PLAYER_SNEAKING_SPEED = SNEAKING_SPEED;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute PLAYER_SUBMERGED_MINING_SPEED = SUBMERGED_MINING_SPEED;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute PLAYER_SWEEPING_DAMAGE_RATIO = SWEEPING_DAMAGE_RATIO;
|
||||
/**
|
||||
* All attribute "type" prefixes were removed with 1.21.2
|
||||
*/
|
||||
@Deprecated
|
||||
public static final Attribute GENERIC_WATER_MOVEMENT_EFFICIENCY = WATER_MOVEMENT_EFFICIENCY;
|
||||
|
||||
static {
|
||||
REGISTRY.unloadMappings();
|
||||
}
|
||||
}
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.attribute;
|
||||
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public class DefaultAttributeDisplay implements AttributeDisplay {
|
||||
|
||||
public static final DefaultAttributeDisplay INSTANCE = new DefaultAttributeDisplay();
|
||||
|
||||
private DefaultAttributeDisplay() {
|
||||
}
|
||||
|
||||
public static DefaultAttributeDisplay read(PacketWrapper<?> wrapper) {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, DefaultAttributeDisplay display) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeDisplayType<?> getType() {
|
||||
return AttributeDisplayTypes.DEFAULT;
|
||||
}
|
||||
}
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.attribute;
|
||||
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public class HiddenAttributeDisplay implements AttributeDisplay {
|
||||
|
||||
public static final HiddenAttributeDisplay INSTANCE = new HiddenAttributeDisplay();
|
||||
|
||||
private HiddenAttributeDisplay() {
|
||||
}
|
||||
|
||||
public static HiddenAttributeDisplay read(PacketWrapper<?> wrapper) {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, HiddenAttributeDisplay display) {
|
||||
// NO-OP
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeDisplayType<?> getType() {
|
||||
return AttributeDisplayTypes.HIDDEN;
|
||||
}
|
||||
}
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.attribute;
|
||||
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@NullMarked
|
||||
public class OverrideAttributeDisplay implements AttributeDisplay {
|
||||
|
||||
private final Component component;
|
||||
|
||||
public OverrideAttributeDisplay(Component component) {
|
||||
this.component = component;
|
||||
}
|
||||
|
||||
public static OverrideAttributeDisplay read(PacketWrapper<?> wrapper) {
|
||||
return new OverrideAttributeDisplay(wrapper.readComponent());
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, OverrideAttributeDisplay display) {
|
||||
wrapper.writeComponent(display.component);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AttributeDisplayType<?> getType() {
|
||||
return AttributeDisplayTypes.OVERRIDE;
|
||||
}
|
||||
|
||||
public Component getComponent() {
|
||||
return this.component;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof OverrideAttributeDisplay)) return false;
|
||||
OverrideAttributeDisplay that = (OverrideAttributeDisplay) obj;
|
||||
return this.component.equals(that.component);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(this.component);
|
||||
}
|
||||
}
|
||||
-71
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.attribute;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.mapper.AbstractMappedEntity;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class StaticAttribute extends AbstractMappedEntity implements Attribute {
|
||||
|
||||
private final @Nullable ResourceLocation legacyName;
|
||||
private final double defaultValue;
|
||||
private final double minValue;
|
||||
private final double maxValue;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public StaticAttribute(
|
||||
@Nullable TypesBuilderData data, String legacyPrefix,
|
||||
double defaultValue, double minValue, double maxValue
|
||||
) {
|
||||
super(data);
|
||||
this.defaultValue = defaultValue;
|
||||
this.minValue = minValue;
|
||||
this.maxValue = maxValue;
|
||||
this.legacyName = legacyPrefix == null || data == null ? null : new ResourceLocation(
|
||||
data.getName().getNamespace(), legacyPrefix + "." + data.getName().getKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getName(ClientVersion version) {
|
||||
if (this.data == null) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
return version.isNewerThanOrEquals(ClientVersion.V_1_21_2) || this.legacyName == null
|
||||
? this.data.getName() : this.legacyName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDefaultValue() {
|
||||
return this.defaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMinValue() {
|
||||
return this.minValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxValue() {
|
||||
return this.maxValue;
|
||||
}
|
||||
}
|
||||
-52
@@ -1,52 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.attribute;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.mapper.AbstractMappedEntity;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper.Reader;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper.Writer;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public class StaticAttributeDisplayType<T extends AttributeDisplay> extends AbstractMappedEntity implements AttributeDisplayType<T> {
|
||||
|
||||
private final Reader<T> reader;
|
||||
private final Writer<T> writer;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public StaticAttributeDisplayType(@Nullable TypesBuilderData data, Reader<T> reader, Writer<T> writer) {
|
||||
super(data);
|
||||
this.reader = reader;
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T read(PacketWrapper<?> wrapper) {
|
||||
return this.reader.apply(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(PacketWrapper<?> wrapper, T display) {
|
||||
this.writer.accept(wrapper, display);
|
||||
}
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
public enum ChatCompletionAction {
|
||||
ADD,
|
||||
REMOVE,
|
||||
SET;
|
||||
|
||||
private static final ChatCompletionAction[] VALUES = values();
|
||||
|
||||
public static ChatCompletionAction fromId(int id) {
|
||||
return VALUES[id];
|
||||
}
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage_v1_19_1;
|
||||
import com.github.retrooper.packetevents.protocol.mapper.CopyableEntity;
|
||||
import com.github.retrooper.packetevents.protocol.mapper.DeepComparableEntity;
|
||||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBT;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.util.Index;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.UnknownNullability;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.github.retrooper.packetevents.util.adventure.AdventureIndexUtil.indexValueOrThrow;
|
||||
|
||||
public interface ChatType extends MappedEntity, CopyableEntity<ChatType>, DeepComparableEntity {
|
||||
|
||||
@UnknownNullability("only nullable for 1.19")
|
||||
ChatTypeDecoration getChatDecoration();
|
||||
|
||||
@ApiStatus.Obsolete(since = "1.19.1")
|
||||
@Nullable ChatTypeDecoration getOverlayDecoration();
|
||||
|
||||
@UnknownNullability("only nullable for 1.19")
|
||||
ChatTypeDecoration getNarrationDecoration();
|
||||
|
||||
@ApiStatus.Obsolete(since = "1.19.1")
|
||||
@Nullable NarrationPriority getNarrationPriority();
|
||||
|
||||
static ChatType readDirect(PacketWrapper<?> wrapper) {
|
||||
ChatTypeDecoration chatDecoration = ChatTypeDecoration.read(wrapper);
|
||||
ChatTypeDecoration narrationDecoration = ChatTypeDecoration.read(wrapper);
|
||||
return new StaticChatType(chatDecoration, narrationDecoration);
|
||||
}
|
||||
|
||||
static void writeDirect(PacketWrapper<?> wrapper, ChatType chatType) {
|
||||
ChatTypeDecoration.write(wrapper, chatType.getChatDecoration());
|
||||
ChatTypeDecoration.write(wrapper, chatType.getNarrationDecoration());
|
||||
}
|
||||
|
||||
static ChatType decode(NBT nbt, ClientVersion version, @Nullable TypesBuilderData data) {
|
||||
// everything is nullable in 1.19, even the chat format!
|
||||
NBTCompound compound = (NBTCompound) nbt;
|
||||
NBTCompound chatTag = compound.getCompoundTagOrNull("chat");
|
||||
NBTCompound narrationTag = compound.getCompoundTagOrNull("narration");
|
||||
|
||||
ChatTypeDecoration overlay = null;
|
||||
NarrationPriority narrationPriority = null;
|
||||
if (version.isOlderThan(ClientVersion.V_1_19_1)) {
|
||||
NBTCompound overlayTag = compound.getCompoundTagOrNull("overlay");
|
||||
if (overlayTag != null) {
|
||||
// why is this nullable? why is this wrapped? There is no reason to wrap this...
|
||||
overlayTag = overlayTag.getCompoundTagOrNull("description");
|
||||
if (overlayTag != null) {
|
||||
overlay = ChatTypeDecoration.decode(overlayTag, version);
|
||||
}
|
||||
}
|
||||
if (chatTag != null) {
|
||||
chatTag = chatTag.getCompoundTagOrNull("description");
|
||||
}
|
||||
if (narrationTag != null) {
|
||||
// the priority is the ONLY value which isn't nullable!
|
||||
narrationPriority = indexValueOrThrow(NarrationPriority.ID_INDEX,
|
||||
narrationTag.getStringTagValueOrThrow("priority"));
|
||||
narrationTag = narrationTag.getCompoundTagOrNull("description");
|
||||
}
|
||||
} else {
|
||||
// ensure this isn't null in everything but 1.19
|
||||
Objects.requireNonNull(chatTag, "NBT chat does not exist");
|
||||
Objects.requireNonNull(narrationTag, "NBT narration does not exist");
|
||||
}
|
||||
|
||||
ChatTypeDecoration chat = chatTag == null ? null : ChatTypeDecoration.decode(chatTag, version);
|
||||
ChatTypeDecoration narration = narrationTag == null ? null : ChatTypeDecoration.decode(narrationTag, version);
|
||||
return new StaticChatType(data, chat, overlay, narration, narrationPriority);
|
||||
}
|
||||
|
||||
static NBT encode(ChatType chatType, ClientVersion version) {
|
||||
NBTCompound compound = new NBTCompound();
|
||||
NBT chatTag = chatType.getChatDecoration() == null ? null :
|
||||
ChatTypeDecoration.encode(chatType.getChatDecoration(), version);
|
||||
NBT narrationTag = chatType.getNarrationDecoration() == null ? null :
|
||||
ChatTypeDecoration.encode(chatType.getNarrationDecoration(), version);
|
||||
|
||||
if (version.isOlderThan(ClientVersion.V_1_19_1)) {
|
||||
ChatTypeDecoration overlayDeco = chatType.getOverlayDecoration();
|
||||
if (overlayDeco != null) {
|
||||
NBTCompound overlayCompound = new NBTCompound();
|
||||
overlayCompound.setTag("description",
|
||||
ChatTypeDecoration.encode(overlayDeco, version));
|
||||
compound.setTag("overlay", overlayCompound);
|
||||
}
|
||||
if (narrationTag != null) {
|
||||
NBTCompound narrationCompound = new NBTCompound();
|
||||
narrationCompound.setTag("description", narrationTag);
|
||||
if (chatType.getNarrationPriority() != null) {
|
||||
narrationCompound.setTag("priority", new NBTString(chatType.getNarrationPriority().getId()));
|
||||
}
|
||||
narrationTag = narrationCompound;
|
||||
}
|
||||
if (chatTag != null) {
|
||||
NBTCompound chatCompound = new NBTCompound();
|
||||
chatCompound.setTag("description", chatTag);
|
||||
chatTag = chatCompound;
|
||||
}
|
||||
}
|
||||
|
||||
if (chatTag != null) {
|
||||
compound.setTag("chat", chatTag);
|
||||
}
|
||||
if (narrationTag != null) {
|
||||
compound.setTag("narration", narrationTag);
|
||||
}
|
||||
return compound;
|
||||
}
|
||||
|
||||
class Bound extends ChatMessage_v1_19_1.ChatTypeBoundNetwork {
|
||||
public Bound(ChatType type, Component name, @Nullable Component targetName) {
|
||||
super(type, name, targetName);
|
||||
}
|
||||
}
|
||||
|
||||
@ApiStatus.Obsolete(since = "1.19.1")
|
||||
enum NarrationPriority {
|
||||
|
||||
CHAT("chat"),
|
||||
SYSTEM("system");
|
||||
|
||||
public static final Index<String, NarrationPriority> ID_INDEX = Index.create(
|
||||
NarrationPriority.class, NarrationPriority::getId);
|
||||
|
||||
private final String id;
|
||||
|
||||
NarrationPriority(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
-205
@@ -1,205 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBT;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTList;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.util.adventure.AdventureSerializer;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.ComponentLike;
|
||||
import net.kyori.adventure.text.format.Style;
|
||||
import net.kyori.adventure.util.Index;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import static com.github.retrooper.packetevents.protocol.chat.ChatTypeDecoration.Parameter.CONTENT;
|
||||
import static com.github.retrooper.packetevents.protocol.chat.ChatTypeDecoration.Parameter.SENDER;
|
||||
import static com.github.retrooper.packetevents.protocol.chat.ChatTypeDecoration.Parameter.TARGET;
|
||||
import static com.github.retrooper.packetevents.util.adventure.AdventureIndexUtil.indexValueOrThrow;
|
||||
import static java.util.Arrays.asList;
|
||||
import static net.kyori.adventure.text.format.NamedTextColor.GRAY;
|
||||
import static net.kyori.adventure.text.format.Style.empty;
|
||||
import static net.kyori.adventure.text.format.Style.style;
|
||||
import static net.kyori.adventure.text.format.TextDecoration.ITALIC;
|
||||
|
||||
public class ChatTypeDecoration {
|
||||
|
||||
private final String translationKey;
|
||||
private final List<Parameter> parameters;
|
||||
private final Style style;
|
||||
|
||||
public ChatTypeDecoration(String translationKey, List<Parameter> parameters, Style style) {
|
||||
this.translationKey = translationKey;
|
||||
this.parameters = Collections.unmodifiableList(new ArrayList<>(parameters));
|
||||
this.style = style;
|
||||
}
|
||||
|
||||
public static ChatTypeDecoration read(PacketWrapper<?> wrapper) {
|
||||
String translationKey = wrapper.readString();
|
||||
List<Parameter> parameters = wrapper.readList(ew -> ew.readEnum(Parameter.values()));
|
||||
Style style = wrapper.readStyle();
|
||||
return new ChatTypeDecoration(translationKey, parameters, style);
|
||||
}
|
||||
|
||||
public static void write(PacketWrapper<?> wrapper, ChatTypeDecoration decoration) {
|
||||
wrapper.writeString(decoration.translationKey);
|
||||
wrapper.writeList(decoration.parameters, PacketWrapper::writeEnum);
|
||||
wrapper.writeStyle(decoration.style);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static ChatTypeDecoration decode(NBT nbt, ClientVersion version) {
|
||||
return decode(nbt, PacketWrapper.createDummyWrapper(version));
|
||||
}
|
||||
|
||||
public static ChatTypeDecoration decode(NBT nbt, PacketWrapper<?> wrapper) {
|
||||
NBTCompound compound = (NBTCompound) nbt;
|
||||
String translationKey = compound.getStringTagValueOrThrow("translation_key");
|
||||
NBT paramsTag = compound.getTagOrThrow("parameters");
|
||||
List<Parameter> params;
|
||||
if (paramsTag instanceof NBTList<?>) {
|
||||
params = new ArrayList<>();
|
||||
NBTList<?> paramsTagList = (NBTList<?>) paramsTag;
|
||||
for (NBT paramTag : paramsTagList.getTags()) {
|
||||
String paramId = ((NBTString) paramTag).getValue();
|
||||
params.add(indexValueOrThrow(Parameter.ID_INDEX, paramId));
|
||||
}
|
||||
} else {
|
||||
String paramId = ((NBTString) paramsTag).getValue();
|
||||
params = Collections.singletonList(indexValueOrThrow(Parameter.ID_INDEX, paramId));
|
||||
}
|
||||
NBTCompound styleTag = compound.getCompoundTagOrNull("style");
|
||||
Style style = styleTag == null ? empty() :
|
||||
wrapper.getSerializers().nbt().deserializeStyle(styleTag, wrapper);
|
||||
return new ChatTypeDecoration(translationKey, params, style);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static NBT encode(ChatTypeDecoration decoration, ClientVersion version) {
|
||||
return encode(decoration, PacketWrapper.createDummyWrapper(version));
|
||||
}
|
||||
|
||||
public static NBT encode(ChatTypeDecoration decoration, PacketWrapper<?> wrapper) {
|
||||
NBTList<NBTString> paramsTag = NBTList.createStringList();
|
||||
for (Parameter param : decoration.parameters) {
|
||||
paramsTag.addTag(new NBTString(param.getId()));
|
||||
}
|
||||
|
||||
NBTCompound compound = new NBTCompound();
|
||||
compound.setTag("translation_key", new NBTString(decoration.translationKey));
|
||||
compound.setTag("parameters", paramsTag);
|
||||
if (!decoration.style.isEmpty()) {
|
||||
compound.setTag("style", wrapper.getSerializers()
|
||||
.nbt().serializeStyle(decoration.style, wrapper));
|
||||
}
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static ChatTypeDecoration withSender(String translationKey) {
|
||||
return new ChatTypeDecoration(translationKey, asList(SENDER, CONTENT), empty());
|
||||
}
|
||||
|
||||
public static ChatTypeDecoration incomingDirectMessage(String translationKey) {
|
||||
return new ChatTypeDecoration(translationKey, asList(SENDER, CONTENT),
|
||||
style(GRAY, ITALIC));
|
||||
}
|
||||
|
||||
public static ChatTypeDecoration outgoingDirectMessage(String translationKey) {
|
||||
return new ChatTypeDecoration(translationKey, asList(TARGET, CONTENT),
|
||||
style(GRAY, ITALIC));
|
||||
}
|
||||
|
||||
public static ChatTypeDecoration teamMessage(String translationKey) {
|
||||
return new ChatTypeDecoration(translationKey, asList(TARGET, SENDER, CONTENT), empty());
|
||||
}
|
||||
|
||||
public Component decorate(Component component, ChatType.Bound chatType) {
|
||||
ComponentLike[] components = new ComponentLike[this.parameters.size()];
|
||||
for (int i = 0; i < components.length; i++) {
|
||||
Parameter parameter = this.parameters.get(i);
|
||||
components[i] = parameter.selector.apply(component, chatType);
|
||||
}
|
||||
return Component.translatable(this.translationKey, null, this.style, components);
|
||||
}
|
||||
|
||||
public String getTranslationKey() {
|
||||
return this.translationKey;
|
||||
}
|
||||
|
||||
public List<Parameter> getParameters() {
|
||||
return this.parameters;
|
||||
}
|
||||
|
||||
public Style getStyle() {
|
||||
return this.style;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof ChatTypeDecoration)) return false;
|
||||
ChatTypeDecoration that = (ChatTypeDecoration) obj;
|
||||
if (!this.translationKey.equals(that.translationKey)) return false;
|
||||
if (!this.parameters.equals(that.parameters)) return false;
|
||||
return this.style.equals(that.style);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.translationKey, this.parameters, this.style);
|
||||
}
|
||||
|
||||
public enum Parameter {
|
||||
|
||||
SENDER("sender", (component, type) -> type.getName()),
|
||||
TARGET("target", (component, type) -> type.getTargetName() != null
|
||||
? type.getTargetName() : Component.empty()),
|
||||
CONTENT("content", (component, type) -> component);
|
||||
|
||||
public static final Index<String, Parameter> ID_INDEX = Index.create(
|
||||
Parameter.class, Parameter::getId);
|
||||
|
||||
private final String id;
|
||||
private final BiFunction<Component, ChatType.Bound, Component> selector;
|
||||
|
||||
Parameter(String id, BiFunction<Component, ChatType.Bound, Component> selector) {
|
||||
this.id = id;
|
||||
this.selector = selector;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static @Nullable Parameter valueByName(String id) {
|
||||
return ID_INDEX.value(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.util.mappings.VersionedRegistry;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static com.github.retrooper.packetevents.protocol.chat.ChatTypeDecoration.incomingDirectMessage;
|
||||
import static com.github.retrooper.packetevents.protocol.chat.ChatTypeDecoration.outgoingDirectMessage;
|
||||
import static com.github.retrooper.packetevents.protocol.chat.ChatTypeDecoration.teamMessage;
|
||||
import static com.github.retrooper.packetevents.protocol.chat.ChatTypeDecoration.withSender;
|
||||
|
||||
public final class ChatTypes {
|
||||
|
||||
private static final VersionedRegistry<ChatType> REGISTRY = new VersionedRegistry<>("chat_type");
|
||||
|
||||
private ChatTypes() {
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static ChatType define(String key) {
|
||||
return define(key, withSender("chat.type.text"));
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static ChatType define(String key, ChatTypeDecoration chatDeco) {
|
||||
return define(key, chatDeco, withSender("chat.type.text.narrate"));
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static ChatType define(String key, ChatTypeDecoration chatDeco, ChatTypeDecoration narrationDeco) {
|
||||
return REGISTRY.define(key, data ->
|
||||
new StaticChatType(data, chatDeco, narrationDeco));
|
||||
}
|
||||
|
||||
public static VersionedRegistry<ChatType> getRegistry() {
|
||||
return REGISTRY;
|
||||
}
|
||||
|
||||
public static ChatType getByName(String name) {
|
||||
return REGISTRY.getByName(name);
|
||||
}
|
||||
|
||||
public static ChatType getById(ClientVersion version, int id) {
|
||||
return REGISTRY.getById(version, id);
|
||||
}
|
||||
|
||||
public static final ChatType CHAT = define("chat");
|
||||
public static final ChatType SAY_COMMAND = define("say_command",
|
||||
withSender("chat.type.announcement"));
|
||||
public static final ChatType MSG_COMMAND_INCOMING = define("msg_command_incoming",
|
||||
incomingDirectMessage("commands.message.display.incoming"));
|
||||
public static final ChatType MSG_COMMAND_OUTGOING = define("msg_command_outgoing",
|
||||
outgoingDirectMessage("commands.message.display.outgoing"));
|
||||
public static final ChatType TEAM_MSG_COMMAND_INCOMING = define("team_msg_command_incoming",
|
||||
teamMessage("chat.type.team.text"));
|
||||
public static final ChatType TEAM_MSG_COMMAND_OUTGOING = define("team_msg_command_outgoing",
|
||||
teamMessage("chat.type.team.sent"));
|
||||
public static final ChatType EMOTE_COMMAND = define("emote_command",
|
||||
withSender("chat.type.emote"),
|
||||
withSender("chat.type.emote"));
|
||||
|
||||
// added by CraftBukkit for a few versions
|
||||
public static final ChatType RAW = define("raw");
|
||||
|
||||
@Deprecated
|
||||
public static final ChatType SYSTEM = define("system");
|
||||
@Deprecated
|
||||
public static final ChatType GAME_INFO = define("game_info");
|
||||
@Deprecated
|
||||
public static final ChatType MSG_COMMAND = define("msg_command");
|
||||
@Deprecated
|
||||
public static final ChatType TEAM_MSG_COMMAND = define("team_msg_command");
|
||||
|
||||
/**
|
||||
* Returns an immutable view of the chat types.
|
||||
*
|
||||
* @return Chat Types
|
||||
*/
|
||||
public static Collection<ChatType> values() {
|
||||
return REGISTRY.getEntries();
|
||||
}
|
||||
|
||||
static {
|
||||
REGISTRY.unloadMappings();
|
||||
}
|
||||
}
|
||||
-124
@@ -1,124 +0,0 @@
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.BitSet;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class LastSeenMessages {
|
||||
public static final LastSeenMessages EMPTY = new LastSeenMessages(new ArrayList<>());
|
||||
|
||||
private final List<Entry> entries;
|
||||
|
||||
public LastSeenMessages(List<Entry> entries) {
|
||||
this.entries = entries;
|
||||
}
|
||||
|
||||
public void updateHash(DataOutput output) throws IOException {
|
||||
for (Entry entry : this.entries) {
|
||||
UUID uuid = entry.getUUID();
|
||||
byte[] lastVerifier = entry.getLastVerifier();
|
||||
output.writeByte(70);
|
||||
output.writeLong(uuid.getMostSignificantBits());
|
||||
output.writeLong(uuid.getLeastSignificantBits());
|
||||
output.write(lastVerifier);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Entry> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
public static class Packed {
|
||||
private List<MessageSignature.Packed> packedMessageSignatures;
|
||||
|
||||
public Packed(List<MessageSignature.Packed> packedMessageSignatures) {
|
||||
this.packedMessageSignatures = packedMessageSignatures;
|
||||
}
|
||||
|
||||
public List<MessageSignature.Packed> getPackedMessageSignatures() {
|
||||
return packedMessageSignatures;
|
||||
}
|
||||
|
||||
public void setPackedMessageSignatures(List<MessageSignature.Packed> packedMessageSignatures) {
|
||||
this.packedMessageSignatures = packedMessageSignatures;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Entry {
|
||||
private final UUID uuid;
|
||||
private final byte[] signature;
|
||||
|
||||
public Entry(UUID uuid, byte[] lastVerifier) {
|
||||
this.uuid = uuid;
|
||||
this.signature = lastVerifier;
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public byte[] getLastVerifier() {
|
||||
return signature;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LegacyUpdate {
|
||||
private final LastSeenMessages lastSeenMessages;
|
||||
private final @Nullable Entry lastReceived;
|
||||
|
||||
public LegacyUpdate(LastSeenMessages lastSeenMessages, @Nullable Entry lastReceived) {
|
||||
this.lastSeenMessages = lastSeenMessages;
|
||||
this.lastReceived = lastReceived;
|
||||
}
|
||||
|
||||
public LastSeenMessages getLastSeenMessages() {
|
||||
return lastSeenMessages;
|
||||
}
|
||||
|
||||
public @Nullable Entry getLastReceived() {
|
||||
return lastReceived;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Update {
|
||||
|
||||
private final int offset;
|
||||
private final BitSet acknowledged;
|
||||
private final byte checksum;
|
||||
|
||||
/**
|
||||
* Checksum has been added with 1.21.5
|
||||
*/
|
||||
@ApiStatus.Obsolete
|
||||
public Update(int offset, BitSet acknowledged) {
|
||||
this(offset, acknowledged, (byte) 0);
|
||||
}
|
||||
|
||||
public Update(int offset, BitSet acknowledged, byte checksum) {
|
||||
this.offset = offset;
|
||||
this.acknowledged = acknowledged;
|
||||
this.checksum = checksum;
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
public BitSet getAcknowledged() {
|
||||
return acknowledged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Added with 1.21.5
|
||||
*/
|
||||
public byte getChecksum() {
|
||||
return this.checksum;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class MessageSender {
|
||||
private @NotNull UUID uuid;
|
||||
private @Nullable Component displayName;
|
||||
private @Nullable Component teamName;
|
||||
|
||||
public MessageSender(@NotNull UUID uuid, @Nullable Component displayName, @Nullable Component teamName) {
|
||||
this.uuid = uuid;
|
||||
this.displayName = displayName;
|
||||
this.teamName = teamName;
|
||||
}
|
||||
|
||||
public MessageSender(@Nullable Component displayName, @Nullable Component teamName) {
|
||||
this(new UUID(0L, 0L), displayName, teamName);
|
||||
}
|
||||
|
||||
public MessageSender() {
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
public UUID getUUID() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUUID(@NotNull UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public @Nullable Component getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
public void setDisplayName(@Nullable Component displayName) {
|
||||
this.displayName = displayName;
|
||||
}
|
||||
|
||||
public @Nullable Component getTeamName() {
|
||||
return teamName;
|
||||
}
|
||||
|
||||
public void setTeamName(@Nullable Component teamName) {
|
||||
this.teamName = teamName;
|
||||
}
|
||||
}
|
||||
-70
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2023 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class MessageSignature {
|
||||
private byte[] bytes;
|
||||
|
||||
public MessageSignature(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public byte[] getBytes() {
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public void setBytes(byte[] bytes) {
|
||||
this.bytes = bytes;
|
||||
}
|
||||
|
||||
public static class Packed {
|
||||
private int id;
|
||||
private @Nullable MessageSignature fullSignature;
|
||||
|
||||
public Packed(@Nullable MessageSignature fullSignature) {
|
||||
this.id = -1;
|
||||
this.fullSignature = fullSignature;
|
||||
}
|
||||
|
||||
public Packed(int id) {
|
||||
this.id = id;
|
||||
this.fullSignature = null;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Optional<MessageSignature> getFullSignature() {
|
||||
return Optional.ofNullable(fullSignature);
|
||||
}
|
||||
|
||||
public void setFullSignature(@Nullable MessageSignature fullSignature) {
|
||||
this.fullSignature = fullSignature;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,140 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
import com.github.retrooper.packetevents.PacketEvents;
|
||||
import com.github.retrooper.packetevents.protocol.chat.Parsers.Parser;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class Node {
|
||||
|
||||
public static final byte TYPE_MASK = 0b11;
|
||||
public static final byte TYPE_ROOT = 0b00;
|
||||
public static final byte TYPE_LITERAL = 0b01;
|
||||
public static final byte TYPE_ARGUMENT = 0b10;
|
||||
|
||||
public static final byte FLAG_MASK = ~TYPE_MASK;
|
||||
public static final byte FLAG_EXECUTABLE = 0b000100;
|
||||
public static final byte FLAG_REDIRECT = 0b001000;
|
||||
public static final byte FLAG_CUSTOM_SUGGESTIONS = 0b010000;
|
||||
/**
|
||||
* Added with 1.21.6
|
||||
*/
|
||||
public static final byte FLAG_RESTRICTED = 0b100000;
|
||||
|
||||
private byte flags;
|
||||
private List<Integer> children;
|
||||
private int redirectNodeIndex;
|
||||
private Optional<String> name;
|
||||
private Optional<Parser> parser;
|
||||
private Optional<List<Object>> properties;
|
||||
private Optional<ResourceLocation> suggestionsType;
|
||||
|
||||
public Node(
|
||||
byte flags, List<Integer> children, int redirectNodeIndex, @Nullable String name,
|
||||
@Nullable Integer parserID, @Nullable List<Object> properties, @Nullable ResourceLocation suggestionsType
|
||||
) {
|
||||
this(flags, children, redirectNodeIndex, name, parserID == null ? null : Parsers.getById(
|
||||
PacketEvents.getAPI().getServerManager().getVersion().toClientVersion(), parserID),
|
||||
properties, suggestionsType);
|
||||
}
|
||||
|
||||
public Node(
|
||||
byte flags, List<Integer> children, int redirectNodeIndex, @Nullable String name, @Nullable Parser parser,
|
||||
@Nullable List<Object> properties, @Nullable ResourceLocation suggestionsType
|
||||
) {
|
||||
this.flags = flags;
|
||||
this.children = children;
|
||||
this.redirectNodeIndex = redirectNodeIndex;
|
||||
this.name = Optional.ofNullable(name);
|
||||
this.parser = Optional.ofNullable(parser);
|
||||
this.properties = Optional.ofNullable(properties);
|
||||
this.suggestionsType = Optional.ofNullable(suggestionsType);
|
||||
}
|
||||
|
||||
public byte getFlags() {
|
||||
return flags;
|
||||
}
|
||||
|
||||
public void setFlags(byte flags) {
|
||||
this.flags = flags;
|
||||
}
|
||||
|
||||
public List<Integer> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<Integer> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public int getRedirectNodeIndex() {
|
||||
return redirectNodeIndex;
|
||||
}
|
||||
|
||||
public void setRedirectNodeIndex(int redirectNodeIndex) {
|
||||
this.redirectNodeIndex = redirectNodeIndex;
|
||||
}
|
||||
|
||||
public Optional<String> getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(Optional<String> name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Optional<Parser> getParser() {
|
||||
return this.parser;
|
||||
}
|
||||
|
||||
public void setParser(Optional<Parser> parser) {
|
||||
this.parser = parser;
|
||||
}
|
||||
|
||||
public Optional<Integer> getParserID() {
|
||||
return this.parser.map(parser -> parser.getId(PacketEvents.getAPI()
|
||||
.getServerManager().getVersion().toClientVersion()));
|
||||
}
|
||||
|
||||
public void setParserID(Optional<Integer> parserID) {
|
||||
this.parser = parserID.map(id -> Parsers.getById(PacketEvents.getAPI()
|
||||
.getServerManager().getVersion().toClientVersion(), id));
|
||||
}
|
||||
|
||||
public Optional<List<Object>> getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
public void setProperties(Optional<List<Object>> properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
public Optional<ResourceLocation> getSuggestionsType() {
|
||||
return suggestionsType;
|
||||
}
|
||||
|
||||
public void setSuggestionsType(Optional<ResourceLocation> suggestionsType) {
|
||||
this.suggestionsType = suggestionsType;
|
||||
}
|
||||
}
|
||||
@@ -1,276 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.protocol.mapper.AbstractMappedEntity;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
import com.github.retrooper.packetevents.util.mappings.VersionedRegistry;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
|
||||
@NullMarked
|
||||
public final class Parsers {
|
||||
|
||||
private static final VersionedRegistry<Parser> REGISTRY = new VersionedRegistry<>("command_argument_type");
|
||||
|
||||
private Parsers() {
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static Parser define(String key) {
|
||||
return define(key, null, null);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static Parser define(String key, @Nullable Reader reader, @Nullable Writer writer) {
|
||||
return REGISTRY.define(key, data -> new Parser(data, reader, writer));
|
||||
}
|
||||
|
||||
public static Parser getByName(String name) {
|
||||
return REGISTRY.getByName(name);
|
||||
}
|
||||
|
||||
public static Parser getById(ClientVersion version, int id) {
|
||||
return REGISTRY.getById(version, id);
|
||||
}
|
||||
|
||||
public static List<Parser> getParsers() {
|
||||
return new ArrayList<>(REGISTRY.getEntries());
|
||||
}
|
||||
|
||||
public static VersionedRegistry<Parser> getRegistry() {
|
||||
return REGISTRY;
|
||||
}
|
||||
|
||||
public static final Parser BRIGADIER_BOOL = define("brigadier:bool", null, null);
|
||||
public static final Parser BRIGADIER_FLOAT = define("brigadier:float",
|
||||
packetWrapper -> {
|
||||
byte flags = packetWrapper.readByte();
|
||||
float min = (flags & 0x01) != 0 ? packetWrapper.readFloat() : -Float.MAX_VALUE;
|
||||
float max = (flags & 0x02) != 0 ? packetWrapper.readFloat() : Float.MAX_VALUE;
|
||||
return Arrays.asList(flags, min, max);
|
||||
},
|
||||
(packetWrapper, properties) -> {
|
||||
byte flags = (byte) properties.get(0);
|
||||
packetWrapper.writeByte(flags);
|
||||
if ((flags & 0x01) != 0) packetWrapper.writeFloat((float) properties.get(1));
|
||||
if ((flags & 0x02) != 0) packetWrapper.writeFloat((float) properties.get(2));
|
||||
}
|
||||
);
|
||||
public static final Parser BRIGADIER_DOUBLE = define("brigadier:double",
|
||||
packetWrapper -> {
|
||||
byte flags = packetWrapper.readByte();
|
||||
double min = (flags & 0x01) != 0 ? packetWrapper.readDouble() : -Double.MAX_VALUE;
|
||||
double max = (flags & 0x02) != 0 ? packetWrapper.readDouble() : Double.MAX_VALUE;
|
||||
return Arrays.asList(flags, min, max);
|
||||
},
|
||||
(packetWrapper, properties) -> {
|
||||
byte flags = (byte) properties.get(0);
|
||||
packetWrapper.writeByte(flags);
|
||||
if ((flags & 0x01) != 0) packetWrapper.writeDouble((double) properties.get(1));
|
||||
if ((flags & 0x02) != 0) packetWrapper.writeDouble((double) properties.get(2));
|
||||
}
|
||||
);
|
||||
public static final Parser BRIGADIER_INTEGER = define("brigadier:integer",
|
||||
packetWrapper -> {
|
||||
byte flags = packetWrapper.readByte();
|
||||
int min = (flags & 0x01) != 0 ? packetWrapper.readInt() : Integer.MIN_VALUE;
|
||||
int max = (flags & 0x02) != 0 ? packetWrapper.readInt() : Integer.MAX_VALUE;
|
||||
return Arrays.asList(flags, min, max);
|
||||
},
|
||||
(packetWrapper, properties) -> {
|
||||
byte flags = (byte) properties.get(0);
|
||||
packetWrapper.writeByte(flags);
|
||||
if ((flags & 0x01) != 0) packetWrapper.writeInt((int) properties.get(1));
|
||||
if ((flags & 0x02) != 0) packetWrapper.writeInt((int) properties.get(2));
|
||||
}
|
||||
);
|
||||
public static final Parser BRIGADIER_LONG = define("brigadier:long",
|
||||
packetWrapper -> {
|
||||
byte flags = packetWrapper.readByte();
|
||||
long min = (flags & 0x01) != 0 ? packetWrapper.readLong() : Long.MIN_VALUE;
|
||||
long max = (flags & 0x02) != 0 ? packetWrapper.readLong() : Long.MAX_VALUE;
|
||||
return Arrays.asList(flags, min, max);
|
||||
},
|
||||
(packetWrapper, properties) -> {
|
||||
byte flags = (byte) properties.get(0);
|
||||
packetWrapper.writeByte(flags);
|
||||
if ((flags & 0x01) != 0) packetWrapper.writeLong((long) properties.get(1));
|
||||
if ((flags & 0x02) != 0) packetWrapper.writeLong((long) properties.get(2));
|
||||
}
|
||||
);
|
||||
public static final Parser BRIGADIER_STRING = define("brigadier:string",
|
||||
packetWrapper -> Collections.singletonList(packetWrapper.readVarInt()),
|
||||
(packetWrapper, properties) -> packetWrapper.writeVarInt((Integer) properties.get(0))
|
||||
);
|
||||
public static final Parser ENTITY = define("entity",
|
||||
packetWrapper -> Collections.singletonList(packetWrapper.readByte()),
|
||||
(packetWrapper, properties) -> packetWrapper.writeByte(((Byte) properties.get(0)).intValue())
|
||||
);
|
||||
public static final Parser GAME_PROFILE = define("game_profile", null, null);
|
||||
public static final Parser BLOCK_POS = define("block_pos", null, null);
|
||||
public static final Parser COLUMN_POS = define("column_pos", null, null);
|
||||
public static final Parser VEC3 = define("vec3", null, null);
|
||||
public static final Parser VEC2 = define("vec2", null, null);
|
||||
public static final Parser BLOCK_STATE = define("block_state", null, null);
|
||||
public static final Parser BLOCK_PREDICATE = define("block_predicate", null, null);
|
||||
public static final Parser ITEM_STACK = define("item_stack", null, null);
|
||||
public static final Parser ITEM_PREDICATE = define("item_predicate", null, null);
|
||||
public static final Parser COLOR = define("color", null, null);
|
||||
public static final Parser COMPONENT = define("component", null, null);
|
||||
public static final Parser STYLE = define("style", null, null);
|
||||
public static final Parser MESSAGE = define("message", null, null);
|
||||
public static final Parser NBT_COMPOUND_TAG = define("nbt_compound_tag", null, null);
|
||||
@ApiStatus.Obsolete
|
||||
public static final Parser NBT = define("nbt", null, null);
|
||||
public static final Parser NBT_TAG = define("nbt_tag", null, null);
|
||||
public static final Parser NBT_PATH = define("nbt_path", null, null);
|
||||
public static final Parser OBJECTIVE = define("objective", null, null);
|
||||
public static final Parser OBJECTIVE_CRITERIA = define("objective_criteria", null, null);
|
||||
public static final Parser OPERATION = define("operation", null, null);
|
||||
public static final Parser PARTICLE = define("particle", null, null);
|
||||
public static final Parser ANGLE = define("angle", null, null);
|
||||
public static final Parser ROTATION = define("rotation", null, null);
|
||||
public static final Parser SCOREBOARD_SLOT = define("scoreboard_slot", null, null);
|
||||
public static final Parser SCORE_HOLDER = define("score_holder",
|
||||
packetWrapper -> Collections.singletonList(packetWrapper.readByte()),
|
||||
(packetWrapper, properties) -> packetWrapper.writeByte(((Byte) properties.get(0)).intValue())
|
||||
);
|
||||
public static final Parser SWIZZLE = define("swizzle", null, null);
|
||||
public static final Parser TEAM = define("team", null, null);
|
||||
public static final Parser ITEM_SLOT = define("item_slot", null, null);
|
||||
public static final Parser ITEM_SLOTS = define("item_slots", null, null);
|
||||
public static final Parser RESOURCE_LOCATION = define("resource_location", null, null);
|
||||
public static final Parser MOB_EFFECT = define("mob_effect", null, null);
|
||||
public static final Parser FUNCTION = define("function", null, null);
|
||||
public static final Parser ENTITY_ANCHOR = define("entity_anchor", null, null);
|
||||
public static final Parser INT_RANGE = define("int_range", null, null);
|
||||
public static final Parser FLOAT_RANGE = define("float_range", null, null);
|
||||
public static final Parser ITEM_ENCHANTMENT = define("item_enchantment", null, null);
|
||||
public static final Parser ENTITY_SUMMON = define("entity_summon", null, null);
|
||||
public static final Parser DIMENSION = define("dimension", null, null);
|
||||
public static final Parser GAMEMODE = define("gamemode", null, null);
|
||||
public static final Parser TIME = define("time",
|
||||
wrapper -> Collections.singletonList(wrapper.getServerVersion()
|
||||
.isNewerThanOrEquals(ServerVersion.V_1_19_4) ? wrapper.readInt() : 0),
|
||||
(wrapper, properties) -> {
|
||||
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_19_4)) {
|
||||
wrapper.writeInt((int) properties.get(0));
|
||||
}
|
||||
}
|
||||
);
|
||||
public static final Parser RESOURCE_OR_TAG = define("resource_or_tag",
|
||||
packetWrapper -> Collections.singletonList(packetWrapper.readIdentifier()),
|
||||
(packetWrapper, properties) -> packetWrapper.writeIdentifier((ResourceLocation) properties.get(0))
|
||||
);
|
||||
public static final Parser RESOURCE_OR_TAG_KEY = define("resource_or_tag_key",
|
||||
packetWrapper -> Collections.singletonList(packetWrapper.readIdentifier()),
|
||||
(packetWrapper, properties) -> packetWrapper.writeIdentifier((ResourceLocation) properties.get(0))
|
||||
);
|
||||
public static final Parser RESOURCE = define("resource",
|
||||
packetWrapper -> Collections.singletonList(packetWrapper.readIdentifier()),
|
||||
(packetWrapper, properties) -> packetWrapper.writeIdentifier((ResourceLocation) properties.get(0))
|
||||
);
|
||||
public static final Parser RESOURCE_KEY = define("resource_key",
|
||||
packetWrapper -> Collections.singletonList(packetWrapper.readIdentifier()),
|
||||
(packetWrapper, properties) -> packetWrapper.writeIdentifier((ResourceLocation) properties.get(0))
|
||||
);
|
||||
public static final Parser TEMPLATE_MIRROR = define("template_mirror", null, null);
|
||||
public static final Parser TEMPLATE_ROTATION = define("template_rotation", null, null);
|
||||
public static final Parser HEIGHTMAP = define("heightmap", null, null);
|
||||
public static final Parser LOOT_TABLE = define("loot_table", null, null);
|
||||
public static final Parser LOOT_PREDICATE = define("loot_predicate", null, null);
|
||||
public static final Parser LOOT_MODIFIER = define("loot_modifier", null, null);
|
||||
public static final Parser UUID = define("uuid", null, null);
|
||||
|
||||
/**
|
||||
* Added with 1.21.5
|
||||
*/
|
||||
public static final Parser RESOURCE_SELECTOR = define("resource_selector",
|
||||
wrapper -> Collections.singletonList(wrapper.readIdentifier()),
|
||||
(wrapper, value) -> wrapper.writeIdentifier((ResourceLocation) value.get(0))
|
||||
);
|
||||
|
||||
/**
|
||||
* Added with 1.21.6
|
||||
*/
|
||||
public static final Parser HEX_COLOR = define("hex_color", null, null);
|
||||
/**
|
||||
* Added with 1.21.6
|
||||
*/
|
||||
public static final Parser DIALOG = define("dialog", null, null);
|
||||
|
||||
static {
|
||||
REGISTRY.unloadMappings();
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Reader extends Function<PacketWrapper<?>, List<Object>> {}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface Writer extends BiConsumer<PacketWrapper<?>, List<Object>> {}
|
||||
|
||||
public static final class Parser extends AbstractMappedEntity {
|
||||
|
||||
private final Reader reader;
|
||||
private final Writer writer;
|
||||
|
||||
@Deprecated
|
||||
public Parser(String name, @Nullable Function<PacketWrapper<?>, List<Object>> read, @Nullable BiConsumer<PacketWrapper<?>, List<Object>> write) {
|
||||
this(
|
||||
new TypesBuilderData(new ResourceLocation(name), new int[0]),
|
||||
read == null ? null : read::apply,
|
||||
write == null ? null : write::accept
|
||||
);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Parser(@Nullable TypesBuilderData data, @Nullable Reader reader, @Nullable Writer writer) {
|
||||
super(data);
|
||||
this.reader = reader;
|
||||
this.writer = writer;
|
||||
}
|
||||
|
||||
public Optional<List<Object>> readProperties(PacketWrapper<?> wrapper) {
|
||||
if (this.reader != null) {
|
||||
return Optional.of(this.reader.apply(wrapper));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public void writeProperties(PacketWrapper<?> wrapper, List<Object> properties) {
|
||||
if (this.writer != null) {
|
||||
this.writer.accept(wrapper, properties);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2022 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.player.PublicProfileKey;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class RemoteChatSession {
|
||||
private final UUID sessionId;
|
||||
private final PublicProfileKey publicProfileKey;
|
||||
|
||||
public RemoteChatSession(UUID sessionId, PublicProfileKey publicProfileKey) {
|
||||
this.sessionId = sessionId;
|
||||
this.publicProfileKey = publicProfileKey;
|
||||
}
|
||||
|
||||
public UUID getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public PublicProfileKey getPublicProfileKey() {
|
||||
return publicProfileKey;
|
||||
}
|
||||
}
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
public class SignedCommandArgument {
|
||||
private String argument;
|
||||
private MessageSignature signature;
|
||||
|
||||
public SignedCommandArgument(String argument, MessageSignature signature) {
|
||||
this.argument = argument;
|
||||
this.signature = signature;
|
||||
}
|
||||
|
||||
public String getArgument() {
|
||||
return argument;
|
||||
}
|
||||
|
||||
public void setArgument(String argument) {
|
||||
this.argument = argument;
|
||||
}
|
||||
|
||||
public MessageSignature getSignature() {
|
||||
return signature;
|
||||
}
|
||||
|
||||
public void setSignature(MessageSignature signature) {
|
||||
this.signature = signature;
|
||||
}
|
||||
}
|
||||
-123
@@ -1,123 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2024 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.mapper.AbstractMappedEntity;
|
||||
import com.github.retrooper.packetevents.util.mappings.TypesBuilderData;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.UnknownNullability;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class StaticChatType extends AbstractMappedEntity implements ChatType {
|
||||
|
||||
private final @UnknownNullability("only nullable for 1.19") ChatTypeDecoration chatDecoration;
|
||||
private final @Nullable ChatTypeDecoration overlayDecoration;
|
||||
private final @UnknownNullability("only nullable for 1.19") ChatTypeDecoration narrationDecoration;
|
||||
private final @Nullable NarrationPriority narrationPriority;
|
||||
|
||||
public StaticChatType(
|
||||
ChatTypeDecoration chatDecoration,
|
||||
ChatTypeDecoration narrationDecoration
|
||||
) {
|
||||
this(null, chatDecoration, null, narrationDecoration, null);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public StaticChatType(
|
||||
@Nullable TypesBuilderData data,
|
||||
ChatTypeDecoration chatDecoration,
|
||||
ChatTypeDecoration narrationDecoration
|
||||
) {
|
||||
this(data, chatDecoration, null, narrationDecoration, null);
|
||||
}
|
||||
|
||||
public StaticChatType(
|
||||
@UnknownNullability("only nullable for 1.19") ChatTypeDecoration chatDecoration,
|
||||
@Nullable ChatTypeDecoration overlayDecoration,
|
||||
@UnknownNullability("only nullable for 1.19") ChatTypeDecoration narrationDecoration,
|
||||
@Nullable NarrationPriority narrationPriority
|
||||
) {
|
||||
this(null, chatDecoration, overlayDecoration, narrationDecoration, narrationPriority);
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public StaticChatType(
|
||||
@Nullable TypesBuilderData data,
|
||||
@UnknownNullability("only nullable for 1.19") ChatTypeDecoration chatDecoration,
|
||||
@Nullable ChatTypeDecoration overlayDecoration,
|
||||
@UnknownNullability("only nullable for 1.19") ChatTypeDecoration narrationDecoration,
|
||||
@Nullable NarrationPriority narrationPriority
|
||||
) {
|
||||
super(data);
|
||||
this.chatDecoration = chatDecoration;
|
||||
this.overlayDecoration = overlayDecoration;
|
||||
this.narrationDecoration = narrationDecoration;
|
||||
this.narrationPriority = narrationPriority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChatType copy(@Nullable TypesBuilderData newData) {
|
||||
return new StaticChatType(newData, this.chatDecoration,
|
||||
this.overlayDecoration, this.narrationDecoration, this.narrationPriority);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @UnknownNullability("only nullable for 1.19") ChatTypeDecoration getChatDecoration() {
|
||||
return this.chatDecoration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ChatTypeDecoration getOverlayDecoration() {
|
||||
return this.overlayDecoration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @UnknownNullability("only nullable for 1.19") ChatTypeDecoration getNarrationDecoration() {
|
||||
return this.narrationDecoration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable NarrationPriority getNarrationPriority() {
|
||||
return this.narrationPriority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deepEquals(Object obj) {
|
||||
if (this == obj) return true;
|
||||
if (!(obj instanceof StaticChatType)) return false;
|
||||
if (!super.equals(obj)) return false;
|
||||
StaticChatType that = (StaticChatType) obj;
|
||||
if (!Objects.equals(this.chatDecoration, that.chatDecoration)) return false;
|
||||
if (!Objects.equals(this.overlayDecoration, that.overlayDecoration)) return false;
|
||||
if (!Objects.equals(this.narrationDecoration, that.narrationDecoration)) return false;
|
||||
return this.narrationPriority == that.narrationPriority;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deepHashCode() {
|
||||
return Objects.hash(super.hashCode(), this.chatDecoration, this.overlayDecoration, this.narrationDecoration, this.narrationPriority);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "StaticChatType{chatDecoration=" + this.chatDecoration + ", overlayDecoration=" + this.overlayDecoration + ", narrationDecoration=" + this.narrationDecoration + ", narrationPriority=" + this.narrationPriority + '}';
|
||||
}
|
||||
}
|
||||
-71
@@ -1,71 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat.clickevent;
|
||||
|
||||
import com.github.retrooper.packetevents.manager.server.ServerVersion;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTInt;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public class ChangePageClickEvent implements ClickEvent {
|
||||
|
||||
private final int page;
|
||||
|
||||
@ApiStatus.Obsolete
|
||||
public ChangePageClickEvent(String page) {
|
||||
this(Integer.parseInt(page));
|
||||
}
|
||||
|
||||
public ChangePageClickEvent(int page) {
|
||||
this.page = page;
|
||||
}
|
||||
|
||||
public static ChangePageClickEvent decode(NBTCompound compound, PacketWrapper<?> wrapper) {
|
||||
int page = wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_21_5)
|
||||
? compound.getNumberTagValueOrThrow("page").intValue()
|
||||
: Integer.parseInt(compound.getStringTagValueOrThrow("value"));
|
||||
return new ChangePageClickEvent(page);
|
||||
}
|
||||
|
||||
public static void encode(NBTCompound compound, PacketWrapper<?> wrapper, ChangePageClickEvent clickEvent) {
|
||||
if (wrapper.getServerVersion().isNewerThanOrEquals(ServerVersion.V_1_21_5)) {
|
||||
compound.setTag("page", new NBTInt(clickEvent.page));
|
||||
} else {
|
||||
compound.setTag("value", new NBTString(Integer.toString(clickEvent.page)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClickEventAction<?> getAction() {
|
||||
return ClickEventActions.CHANGE_PAGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.event.ClickEvent asAdventure() {
|
||||
return net.kyori.adventure.text.event.ClickEvent.changePage(this.page);
|
||||
}
|
||||
|
||||
public int getPage() {
|
||||
return this.page;
|
||||
}
|
||||
}
|
||||
-76
@@ -1,76 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat.clickevent;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.dialog.Dialog;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTEnd;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.adventure.NbtTagHolder;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import net.kyori.adventure.text.event.ClickEvent.Payload;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public interface ClickEvent {
|
||||
|
||||
static ClickEvent decode(NBTCompound compound, PacketWrapper<?> wrapper) {
|
||||
String actionName = compound.getStringTagValueOrThrow("action");
|
||||
ClickEventAction<?> action = ClickEventActions.getRegistry().getByNameOrThrow(actionName);
|
||||
return action.decode(compound, wrapper);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked") // not unchecked
|
||||
static void encode(NBTCompound compound, PacketWrapper<?> wrapper, ClickEvent clickEvent) {
|
||||
compound.set("action", clickEvent.getAction().getName(), ResourceLocation::encode, wrapper);
|
||||
((ClickEventAction<? super ClickEvent>) clickEvent.getAction()).encode(compound, wrapper, clickEvent);
|
||||
}
|
||||
|
||||
ClickEventAction<?> getAction();
|
||||
|
||||
static ClickEvent fromAdventure(net.kyori.adventure.text.event.ClickEvent clickEvent) {
|
||||
switch (clickEvent.action()) {
|
||||
case OPEN_URL:
|
||||
return new OpenUrlClickEvent(clickEvent.value());
|
||||
case OPEN_FILE:
|
||||
return new OpenFileClickEvent(clickEvent.value());
|
||||
case RUN_COMMAND:
|
||||
return new RunCommandClickEvent(clickEvent.value());
|
||||
case SUGGEST_COMMAND:
|
||||
return new SuggestCommandClickEvent(clickEvent.value());
|
||||
case CHANGE_PAGE:
|
||||
return new ChangePageClickEvent(clickEvent.value());
|
||||
case COPY_TO_CLIPBOARD:
|
||||
return new CopyToClipboardClickEvent(clickEvent.value());
|
||||
case SHOW_DIALOG:
|
||||
return new ShowDialogClickEvent((Dialog) ((Payload.Dialog) clickEvent.payload()).dialog());
|
||||
case CUSTOM:
|
||||
Payload.Custom payload = (Payload.Custom) clickEvent.payload();
|
||||
NbtTagHolder nbtTag = (NbtTagHolder) payload.nbt();
|
||||
return new CustomClickEvent(
|
||||
new ResourceLocation(payload.key()),
|
||||
nbtTag.getTag() instanceof NBTEnd ? null : nbtTag.getTag()
|
||||
);
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unsupported clickevent: " + clickEvent);
|
||||
}
|
||||
}
|
||||
|
||||
net.kyori.adventure.text.event.ClickEvent asAdventure();
|
||||
}
|
||||
-34
@@ -1,34 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat.clickevent;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public interface ClickEventAction<T extends ClickEvent> extends MappedEntity {
|
||||
|
||||
boolean isAllowFromServer();
|
||||
|
||||
T decode(NBTCompound compound, PacketWrapper<?> wrapper);
|
||||
|
||||
void encode(NBTCompound compound, PacketWrapper<?> wrapper, T clickEvent);
|
||||
}
|
||||
-89
@@ -1,89 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat.clickevent;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.util.NbtMapDecoder;
|
||||
import com.github.retrooper.packetevents.protocol.util.NbtMapEncoder;
|
||||
import com.github.retrooper.packetevents.util.mappings.VersionedRegistry;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public final class ClickEventActions {
|
||||
|
||||
private static final VersionedRegistry<ClickEventAction<?>> REGISTRY = new VersionedRegistry<>("click_event_action");
|
||||
|
||||
private ClickEventActions() {
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static <T extends ClickEvent> ClickEventAction<T> define(
|
||||
String name, boolean allowFromServer,
|
||||
NbtMapDecoder<T> decoder, NbtMapEncoder<T> encoder
|
||||
) {
|
||||
return REGISTRY.define(name, data -> new StaticClickEventAction<>(
|
||||
data, allowFromServer, decoder, encoder));
|
||||
}
|
||||
|
||||
public static VersionedRegistry<ClickEventAction<?>> getRegistry() {
|
||||
return REGISTRY;
|
||||
}
|
||||
|
||||
public static final ClickEventAction<OpenUrlClickEvent> OPEN_URL = define("open_url", true,
|
||||
OpenUrlClickEvent::decode, OpenUrlClickEvent::encode);
|
||||
public static final ClickEventAction<OpenFileClickEvent> OPEN_FILE = define("open_file", false,
|
||||
OpenFileClickEvent::decode, OpenFileClickEvent::encode);
|
||||
public static final ClickEventAction<RunCommandClickEvent> RUN_COMMAND = define("run_command", true,
|
||||
RunCommandClickEvent::decode, RunCommandClickEvent::encode);
|
||||
/**
|
||||
* Removed in 1.9
|
||||
*/
|
||||
@ApiStatus.Obsolete
|
||||
public static final ClickEventAction<TwitchUserInfoClickEvent> TWITCH_USER_INFO = define("twitch_user_info", false,
|
||||
TwitchUserInfoClickEvent::decode, TwitchUserInfoClickEvent::encode);
|
||||
public static final ClickEventAction<SuggestCommandClickEvent> SUGGEST_COMMAND = define("suggest_command", true,
|
||||
SuggestCommandClickEvent::decode, SuggestCommandClickEvent::encode);
|
||||
|
||||
/**
|
||||
* Added with 1.8
|
||||
*/
|
||||
public static final ClickEventAction<ChangePageClickEvent> CHANGE_PAGE = define("change_page", true,
|
||||
ChangePageClickEvent::decode, ChangePageClickEvent::encode);
|
||||
|
||||
/**
|
||||
* Added with 1.15
|
||||
*/
|
||||
public static final ClickEventAction<CopyToClipboardClickEvent> COPY_TO_CLIPBOARD = define("copy_to_clipboard", true,
|
||||
CopyToClipboardClickEvent::decode, CopyToClipboardClickEvent::encode);
|
||||
|
||||
/**
|
||||
* Added with 1.21.6
|
||||
*/
|
||||
public static final ClickEventAction<ShowDialogClickEvent> SHOW_DIALOG = define("show_dialog", true,
|
||||
ShowDialogClickEvent::decode, ShowDialogClickEvent::encode);
|
||||
/**
|
||||
* Added with 1.21.6
|
||||
*/
|
||||
public static final ClickEventAction<CustomClickEvent> CUSTOM = define("custom", true,
|
||||
CustomClickEvent::decode, CustomClickEvent::encode);
|
||||
|
||||
static {
|
||||
REGISTRY.unloadMappings();
|
||||
}
|
||||
}
|
||||
-57
@@ -1,57 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat.clickevent;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTString;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public class CopyToClipboardClickEvent implements ClickEvent {
|
||||
|
||||
private final String value;
|
||||
|
||||
public CopyToClipboardClickEvent(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static CopyToClipboardClickEvent decode(NBTCompound compound, PacketWrapper<?> wrapper) {
|
||||
String value = compound.getStringTagValueOrThrow("value");
|
||||
return new CopyToClipboardClickEvent(value);
|
||||
}
|
||||
|
||||
public static void encode(NBTCompound compound, PacketWrapper<?> wrapper, CopyToClipboardClickEvent clickEvent) {
|
||||
compound.setTag("value", new NBTString(clickEvent.value));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClickEventAction<?> getAction() {
|
||||
return ClickEventActions.COPY_TO_CLIPBOARD;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.event.ClickEvent asAdventure() {
|
||||
return net.kyori.adventure.text.event.ClickEvent.copyToClipboard(this.value);
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2025 retrooper and contributors
|
||||
*
|
||||
* 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.chat.clickevent;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBT;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTCompound;
|
||||
import com.github.retrooper.packetevents.protocol.nbt.NBTEnd;
|
||||
import com.github.retrooper.packetevents.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.adventure.NbtTagHolder;
|
||||
import com.github.retrooper.packetevents.wrapper.PacketWrapper;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
@NullMarked
|
||||
public class CustomClickEvent implements ClickEvent {
|
||||
|
||||
private final ResourceLocation id;
|
||||
private final @Nullable NBT payload;
|
||||
|
||||
public CustomClickEvent(ResourceLocation id, @Nullable NBT payload) {
|
||||
this.id = id;
|
||||
this.payload = payload;
|
||||
}
|
||||
|
||||
public static CustomClickEvent decode(NBTCompound compound, PacketWrapper<?> wrapper) {
|
||||
ResourceLocation id = compound.getOrThrow("id", ResourceLocation::decode, wrapper);
|
||||
NBT payload = compound.getTagOrNull("payload");
|
||||
return new CustomClickEvent(id, payload);
|
||||
}
|
||||
|
||||
public static void encode(NBTCompound compound, PacketWrapper<?> wrapper, CustomClickEvent clickEvent) {
|
||||
compound.set("id", clickEvent.id, ResourceLocation::encode, wrapper);
|
||||
if (clickEvent.payload != null) {
|
||||
compound.setTag("payload", clickEvent.payload);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClickEventAction<?> getAction() {
|
||||
return ClickEventActions.CUSTOM;
|
||||
}
|
||||
|
||||
@Override
|
||||
public net.kyori.adventure.text.event.ClickEvent asAdventure() {
|
||||
return net.kyori.adventure.text.event.ClickEvent.custom(
|
||||
this.id.key(), new NbtTagHolder(this.payload != null ? this.payload : NBTEnd.INSTANCE));
|
||||
}
|
||||
|
||||
public ResourceLocation getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public @Nullable NBT getPayload() {
|
||||
return this.payload;
|
||||
}
|
||||
}
|
||||
Loaded 100 of 1293 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user