Compare commits

...
78 Commits
Author SHA1 Message Date
retrooper 787df36fe0 1.6.6 STABLE RELEASE 2020-09-09 19:48:26 +02:00
retrooper a59ea40e12 1.6.6 update, protocollib listening packets supported,
event priority system added(also compatible with ProtocolLib)
2020-09-09 19:47:06 +02:00
retrooper fdb3a23acc protocollib event priority system working, btw this commit contains debugs 2020-09-09 19:18:07 +02:00
retrooper 60d24ac3c1 A few bugs fixed with event priority system, about to test with protocollib 2020-09-09 18:49:50 +02:00
retrooper 7634540bd7 Merge remote-tracking branch 'origin/master' into master
# Conflicts:
#	src/main/java/io/github/retrooper/packetevents/example/MainExample.java
2020-09-09 17:59:18 +02:00
retrooper 0a475e4242 1.6.6 PRE, working on event priority system, eventsynchronization is deprecated 2020-09-09 17:57:50 +02:00
retrooper ff3b66b22e 1.6.5 release for SPIGOTMC rebuild(removed debugs), and a deprecation: PacketEvents#hasStarted is deprecated, use PacketEvents#isInitialized 2020-09-09 15:57:17 +02:00
Retrooper 8be5f5bfa6 1.6.5 stable release
* debugs removed
2020-09-03 16:41:36 +08:00
retrooper 8d887335e2 Merge pull request #35 from undersquire/patch-8
Update PacketType.java
2020-09-03 07:42:48 +02:00
undersquire 553f429a53 Update PacketType.java
Fixes issues with switch statements?
2020-09-02 19:02:42 -07:00
retrooper a4a8b36665 bug fix, BUT CONTAINS DEBUGS.
Performance issues should be fixed now.
2020-09-02 18:44:29 +02:00
retrooper 49d46b79df performance issues fixed for packetevents, all packets called on a new single threaded executor 2020-09-02 18:19:18 +02:00
retrooper 08a2b92bcf ClientVersion always ClientVersion.ACCESS_FAILURE FIXED!
PacketEvents supports client version checking on 1.7.10.

ClientVersion checking now works ONLY if you are on 1.7.10 spigot/paperspigot, OR have ViaVersion present, or have ProtocolSupport present or have ProtocolLib present.
2020-09-02 18:13:13 +02:00
retrooper f32dafc3ee PacketEvents FULLY documented, for the javadoc. 2020-09-02 17:16:40 +02:00
retrooper 84e391ffc8 1.6.5 pre with debugs 2020-09-02 16:26:55 +02:00
retrooper 26a369af89 test.txt removed 2020-09-02 15:06:03 +02:00
retrooper 56c752b487 test.txt 2020-09-02 15:05:41 +02:00
retrooper 890fcadac2 .idea readded 2020-09-02 15:05:07 +02:00
retrooper 27f09f6627 empty .idea? 2020-09-02 15:04:25 +02:00
Retrooper e5b89271ee getting server version failure fix 2020-09-02 03:42:40 +08:00
Retrooper 48ef0e7852 clientcommand enum not found fix 2020-09-02 03:00:00 +08:00
retrooper 192851b03f Merge pull request #34 from LIWKK/patch-2
Remove debug
2020-09-01 17:46:15 +02:00
Johannes dd30876e70 Remove debug 2020-09-01 18:44:04 +03:00
retrooper ce2603549b 1.6.3 release,
* LICENSE and copyright holder added in each file.
If you are making a closed source product, all you need to do is make sure you aren't obfuscating my files.
* BukkitMoveEvent deprecated, you may copy the event and recreate it on your end in your project, BukkitMoveEvent will most likely be removed in the next minor update.
* CancellableEvent interface added, implemented in all built in events as they are all cancellable.
* Asynchronous injecting and uninjecting is no longer done on the Netty threads, it is now done using java's Executor Service's threadpool
* GitHub Wiki API usage Guide has been rewritten, should finished done today or in a few days
2020-09-01 16:53:31 +02:00
retrooper c645124e55 Merge branch 'master' of https://github.com/retrooper/packetevents into master 2020-09-01 16:16:11 +02:00
retrooper 3c3a00b7bb Merge pull request #33 from NikV2/master
New features
2020-08-30 17:01:12 +02:00
Nik d34e152b98 commit 2020-08-30 17:52:37 +03:00
Retrooper d5454b918a 1.6.2 release
* Issues with WrappedPacketInEntityAction on 1.7.10
2020-08-30 16:15:28 +08:00
Retrooper 427a0fff4a * NPE fix for WrappedPacketInEntityAction in 1.8+ 2020-08-30 15:38:17 +08:00
retrooper 7fc446321d Merge pull request #32 from SamJakob/patch-3
Only update JavaDoc on published release
2020-08-29 21:55:13 +02:00
retrooper 3f85f4998b 1.6.1 release STABLE 2020-08-28 18:13:23 +02:00
retrooper 4799fb67c4 1.6.1 release 2020-08-28 16:37:26 +02:00
SamJakob 5ed9038f7b Only update JavaDoc on published release 2020-08-28 12:22:33 +01:00
retrooper 8c1cd4b824 Merge pull request #31 from NikV2/master
Hotfix - Mistake patching
2020-08-28 07:37:06 +02:00
Nik 50a09de212 Sorry i just can't watch it be like that:") IT HURTS 2020-08-28 03:54:53 +03:00
Nik e66710f5ed commit 2020-08-28 03:52:50 +03:00
retrooper 33131f4fcd Merge pull request #30 from NikV2/master
Uninjections async are now configurable in the settings(can cause reload bugs), I’d rather have setIdentifier() deprecated for one patch version(1.6.1) then in 1.16.2 we remove it completely, basically if then user doesn’t set identifier to anything, we will generate a random one, low priority for injecting and uninjecting players in PacketEvents class.
2020-08-28 01:57:42 +02:00
Nik 9834787279 commit 2020-08-28 02:46:11 +03:00
retrooper 227b569138 Merge pull request #29 from SamJakob/patch-3
Remove committer from javadoc workflow
2020-08-28 01:37:32 +02:00
SamJakob ad1a8a3dba Remove committer from workflow 2020-08-28 00:32:56 +01:00
Nik 262c470031 commit 2020-08-28 02:22:10 +03:00
retrooper 4c9b9be23f Merge pull request #27 from SamJakob/patch-2
Use GitHub Actions to deploy JavaDocs to GH Pages
2020-08-28 01:14:31 +02:00
SamJakob d1c04d39d2 Use GitHub Actions to deploy JavaDocs to GH Pages 2020-08-28 00:13:58 +01:00
retrooper afbe7b44b6 Merge pull request #26 from SamJakob/master
Add JavaDoc to build (and cleanup)
2020-08-28 00:38:39 +02:00
SamJakob f76f1687fb Add JavaDoc to build and fix JavaDoc HTML entities, add .gitignore (cleanup) 2020-08-27 23:32:37 +01:00
retrooper 8eb4015cab 1.6 release commit 2020-08-27 19:10:53 +02:00
retrooper 3ec44f72da 1.6 stable RELEASE 2020-08-27 19:02:37 +02:00
retrooper 3797c45d98 1.6 pre 6
Stable version, please use this and wait for 1.6 official release, more features coming ;)

* Useless enums deleted: Gamemode.java, Hand.java
* Enums that belong to wrappers have been refactored to be a "subclass" of that wrapper: EntityAnimationType.java, EntityUseAction.java, PlayerAction.java, PlayerDigType.java
* Null pointer fixed in WrappedPacketInCustomPayload for 1.7.10
* Null pointer fixed in WrappedPacketInBlockPlace for 1.7.10
* Bug fixed in WrappedPacketInClientCommand for 1.7.10
* Bug fix in WrappedPacketInWindowClick.getWindowClickType() sometimes throwing a ArrayIndexOutOfBoundsException
* WrappedPacketInEntityAction.PlayerAction missing enum constants for 1.7.10/1.8.x fixed, this enum should now be cross version safe, the RIDING_JUMP doesn't exist on newer versions, so accessing this enum should return START_RIDING_JUMP instead.
This system for the enum should make 1.7/1.8 compatible with newer versions.
2020-08-26 14:38:39 +02:00
retrooper 94b7523774 wrapped packet version initialized 2020-08-25 22:05:20 +02:00
retrooper 6f0de9f01c serverversion is public now 2020-08-25 22:04:06 +02:00
retrooper 16cc63447f not tryna mess stuff up 2020-08-25 21:15:02 +02:00
retrooper bb6661b4eb 1.6 pre v5
added RIDING_JUMP enum constant, for now a simple fix, for some reason 1.8 tries accessing this
2020-08-25 21:05:29 +02:00
retrooper 63a5005257 1.6 pre release v4
RIDING_JUMP enum constant added to support 1.8.x
2020-08-25 20:55:33 +02:00
retrooper 8b4fdd4773 1.6 pre 3
* WrappedPacketInAbilities bug fixed for 1.16.x ONLY
2020-08-25 18:49:36 +02:00
retrooper 333bea795f 1.6 pre 2(still 2)
* pom.xml version of packetevents updated to 1.6
2020-08-25 18:19:53 +02:00
retrooper 3ee972a4ff 1.6 pre 2, WrappedPacketInFlying & WrappedPacketInWindowClick.java bugs fixed 2020-08-25 18:01:37 +02:00
retrooper 94a1f67975 1.6 pre, with debugs, might not work!
* All wrappers optimized, much faster with lots of caching
* All wrappers have a function for loading, now wrappers load stuff when you call PacketEvents#load()
* WrappedPacketOutKeepAlive is now sendable to players
* WrappedPacketOutPosition wrapper created
* WrappedPacketInWindowClick wrapper created
2020-08-25 17:30:19 +02:00
retrooper e00b55842d * WrappedPacketOutPosition created (UNFINISHED, onGround BOOLEAN not done and flags missing) 2020-08-25 13:33:53 +02:00
retrooper ba1a4afa79 1.5.9 packetevents release 2020-08-24 15:47:15 +02:00
retrooper d2925592fc 1.5.9 bug fixes, about to release 2020-08-24 15:35:24 +02:00
retrooper d97c1a03ee 1.5.9 pre release 2020-08-24 14:33:24 +02:00
retrooper a1d48d3b20 Release 1.5.8.2
* Code cleanup
* PacketReceiveEvent#getNMSPacketClass() deprecated
* PacketReceiveEvent#getPacketName() deprecated
* PacketSendEvent#getNMSPacketClass() deprecated
* PacketSendEvent#getPacketName() deprecated
* PlayerUninjectEvent#PlayerUninjectEvent(Player player, boolean sync) deprecated, use PlayerUninjectEvent#PlayerUninjectEvent(Player player)
* WrappedPacketInBlockDig null pointers fixed for 1.7.10, just Direction field will be Direction.NULL, I will fix later
* Clientbound wrappers cleaned up
2020-08-19 16:46:21 +02:00
retrooper 4ce0463465 Release 1.5.8.2
* WrappedPacketInBlockDig fixed for 1.7.10.
Only the Direction field is set to Direction.NULL.
I cannot get it to work, this is a quick solution for now.
2020-08-19 16:07:57 +02:00
retrooper 6725caad36 Release 1.5.8.1, pom fix attempt, Jitpack release failed so this should fix it 2020-08-17 19:56:06 +02:00
retrooper 17e9d667a8 1.5.8 Release
* v_1_16_1 and v_1_16_2 added in ClientVersion & ServerVersion
* Settings class renamed to PacketEventsSettings
* WrappedPacketInSettings wrapper created, for the client settings packet
* WrappedPacketInEntityAction code duplication fix
2020-08-17 19:34:56 +02:00
Retrooper 92d85822f3 1.5.7 STABLE with some fixes, memory leaks fixed 2020-08-14 01:54:35 +08:00
Retrooper bdeb421ca3 1.5.7 release 2020-08-14 01:46:38 +08:00
Retrooper b5a5aa4748 Merge branch 'master' of https://github.com/retrooper/packetevents into master 2020-08-14 01:44:56 +08:00
terrarier2111 096d8ab807 Fixed a stupid mistake i made 2020-08-13 16:38:00 +02:00
Retrooper da7d2c7929 Merge branch 'master' of https://github.com/retrooper/packetevents into master 2020-08-13 21:24:16 +08:00
terrarier2111 ead6156bfa Merge pull request #24 from terrarier2111/master
Fixed massive memoryleak
2020-08-12 18:09:10 +02:00
terrarier2111 4220b2d7b3 Fixed massive memoryleak 2020-08-12 18:05:01 +02:00
terrarier2111 e7c598d29e Fixing massive memoryleak 2020-08-12 18:03:27 +02:00
terrarier2111 1677383049 Update FieldWithTypeAndIndex.java 2020-08-12 18:02:00 +02:00
terrarier2111 23ec389798 Fixing massive memoryleak 2020-08-12 18:01:31 +02:00
terrarier2111 0ceaf9a3b2 Fixing massive memoryleak 2020-08-12 17:59:47 +02:00
Retrooper 5fbb775ab4 1.5.6 release ready and this build will be put on spigotmc 2020-08-11 21:03:37 +08:00
Retrooper 8914842e71 1.5.6 release 2020-08-11 20:57:27 +08:00
105 changed files with 4887 additions and 1375 deletions

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
name: Generate and deploy JavaDocs
on:
release:
types: [published]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn install
- name: List target/apidocs
run: ls target/apidocs
- name: GitHub Pages
uses: crazy-max/ghaction-github-pages@v2.1.2
env:
GH_PAT: ${{ secrets.GH_PAT }}
with:
target_branch: javadocs
keep_history: true
build_dir: target/apidocs
commit_message: Update JavaDocs
+113
View File
@@ -0,0 +1,113 @@
#
# JetBrains
#
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf
# Generated files
.idea/**/contentModel.xml
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/artifacts
# .idea/compiler.xml
# .idea/jarRepositories.xml
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr
# CMake
cmake-build-*/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser
#
# Java
#
# Compiled class file
*.class
# Log file
*.log
# BlueJ files
*.ctxt
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# 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*
#
# Maven
#
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar
-44
View File
@@ -1,44 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="minecraft" name="Minecraft">
<configuration>
<autoDetectTypes>
<platformType>SPIGOT</platformType>
</autoDetectTypes>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
<output url="file://$MODULE_DIR$/target/classes" />
<output-test url="file://$MODULE_DIR$/target/test-classes" />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.github.spigot:1.7.10:1.7.10" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.github.spigot:1.8.8:1.8.8" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.comphenix.protocol:ProtocolLib:4.5.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: cglib:cglib-nodep:3.2.5" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.comphenix.executors:BukkitExecutors:1.1-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: us.myles:viaversion:3.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: us.myles:viaversion-common:3.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.yaml:snakeyaml:1.18" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: us.myles:viaversion-bukkit:3.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: us.myles:viaversion-bukkit-legacy:3.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: us.myles:viaversion-bungee:3.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: us.myles:viaversion-fabric:3.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: us.myles:viaversion-sponge:3.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: us.myles:viaversion-sponge-legacy:3.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: us.myles:viaversion-velocity:3.0.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: net.md-5:bungeecord-chat:1.15-SNAPSHOT" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.guava:guava:21.0" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.github.ProtocolSupport:ProtocolSupport:4fdd683" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: org.apache.commons:commons-lang3:3.8.1" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: it.unimi.dsi:fastutil:8.2.2" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: com.google.code.gson:gson:2.8.5" level="project" />
</component>
</module>
+34 -25
View File
@@ -6,15 +6,7 @@
<groupId>io.github.retrooper</groupId>
<artifactId>packetevents</artifactId>
<version>1.5.5</version>
<packaging>jar</packaging>
<name>packetevents</name>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<version>1.6.6</version>
<!-- You can build the project with this: "mvn clean compile assembly:single" -->
<build>
@@ -35,8 +27,28 @@
<target>8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<packaging>jar</packaging>
<name>packetevents</name>
<properties>
<java.version>1.8</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>spigot-repo</id>
@@ -62,28 +74,27 @@
<dependencies>
<dependency>
<groupId>org.github.spigot</groupId>
<artifactId>1.8.8</artifactId>
<version>1.8.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.github.spigot</groupId>
<artifactId>1.8.8</artifactId>
<version>1.8.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.github.spigot</groupId>
<artifactId>1.7.10</artifactId>
<version>1.7.10</version>
<scope>provided</scope>
</dependency>
<groupId>org.github.spigot</groupId>
<artifactId>1.7.10</artifactId>
<version>1.7.10</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
<version>4.5.0</version>
<scope>provided</scope>
</dependency>
<!-- ViaVersion API-->
</dependency>
<dependency>
<groupId>us.myles</groupId>
<artifactId>viaversion</artifactId>
@@ -91,7 +102,6 @@
<scope>provided</scope>
</dependency>
<!-- ProtocolSupport API-->
<dependency>
<groupId>com.github.ProtocolSupport</groupId>
<artifactId>ProtocolSupport</artifactId>
@@ -112,6 +122,5 @@
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
@@ -1,74 +1,149 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents;
import io.github.retrooper.packetevents.api.PacketEventsAPI;
import io.github.retrooper.packetevents.enums.ClientVersion;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.event.PacketEvent;
import io.github.retrooper.packetevents.event.PacketListener;
import io.github.retrooper.packetevents.event.impl.BukkitMoveEvent;
import io.github.retrooper.packetevents.packet.PacketType;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.settings.Settings;
import io.github.retrooper.packetevents.utils.onlineplayers.OnlinePlayerUtilities;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.settings.PacketEventsSettings;
import io.github.retrooper.packetevents.utils.NMSUtils;
import io.github.retrooper.packetevents.utils.nms_entityfinder.EntityFinderUtils;
import io.github.retrooper.packetevents.utils.versionlookup.VersionLookupUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.Plugin;
public final class PacketEvents implements PacketListener, Listener {
private static Plugin plugin;
import java.util.ArrayList;
public final class PacketEvents implements Listener {
private static final PacketEventsAPI packetEventsAPI = new PacketEventsAPI();
private static final PacketEvents instance = new PacketEvents();
private static boolean hasLoaded, hasStarted;
private static final Settings settings = new Settings();
private static final PacketEventsSettings settings = new PacketEventsSettings();
private static final ArrayList<Plugin> plugins = new ArrayList<Plugin>(1);
private static boolean hasLoaded, isStarted;
/**
* Call this before start()
* This loads the PacketEvents API.
*
* ServerVersion:
* In this method we detect and cache the server version.
*
* NMSUtils:
* We setup some NMS utilities.
*
* Packet ID System:
* All the packet classes we will be needing are cached in a Map with an integer ID.
*
* Version Lookup Utils:
* We setup the client protocol version system.
* We check if ViaVersion, ProtocolSupport or ProtocolLib is present.
*
* Wrappers:
* All PacketEvents' wrappers are setup and do all loading they need to do.
*
*/
public static void load() {
ServerVersion version = ServerVersion.getVersion();
WrappedPacket.version = version;
PacketEvent.version = version;
NMSUtils.version = version;
EntityFinderUtils.version = version;
NMSUtils.load();
PacketTypeClasses.Client.load();
PacketTypeClasses.Server.load();
EntityFinderUtils.load();
ClientVersion.prepareLookUp();
WrappedPacket.loadAllWrappers();
hasLoaded = true;
}
/**
* Loads PacketEvents if you haven't already, Sets everything up, injects all players
* Initiates PacketEvents
*
* Loading:
* Loads PacketEvents if you haven't already.
*
* Registering:
* Registers this class as a Bukkit listener to inject/eject players.
*
* @param pl JavaPlugin instance
*/
public static void start(final Plugin pl) {
public static void init(final Plugin pl) {
if (!hasLoaded) {
load();
}
if (!hasStarted) {
plugin = pl;
//Register Bukkit and PacketListener
getAPI().getEventManager().registerListener(instance);
if (!isStarted) {
plugins.add(pl);
//Register Bukkit listener
Bukkit.getPluginManager().registerEvents(instance, plugins.get(0));
Bukkit.getPluginManager().registerEvents(instance, plugin);
for (final Player p : OnlinePlayerUtilities.getOnlinePlayers()) {
for (final Player p : Bukkit.getOnlinePlayers()) {
getAPI().getPlayerUtils().injectPlayer(p);
}
hasStarted = true;
isStarted = true;
}
}
/**
* Stop all tasks and unregisters all PacketEvents' listeners
* Loads PacketEvents if you haven't already, Sets everything up, injects all players
* @param pl Plugin instance
* @deprecated Use {@link #init(Plugin)}
*/
@Deprecated
public static void start(final Plugin pl) {
init(pl);
}
/**
*
*/
public static void stop() {
if (hasStarted) {
for (final Player p : OnlinePlayerUtilities.getOnlinePlayers()) {
getAPI().getPlayerUtils().uninjectPlayerNow(p);
if (isStarted) {
for (final Player p : Bukkit.getOnlinePlayers()) {
getAPI().getPlayerUtils().ejectPlayer(p);
}
getAPI().getEventManager().unregisterAllListeners();
PacketType.Client.packetIds.clear();
PacketType.Server.packetIds.clear();
isStarted = false;
}
}
@@ -76,43 +151,57 @@ public final class PacketEvents implements PacketListener, Listener {
return hasLoaded;
}
@Deprecated
public static boolean hasStarted() {
return hasStarted;
return isStarted;
}
public static boolean isInitialized() {
return isStarted;
}
public static PacketEventsAPI getAPI() {
return packetEventsAPI;
}
@Deprecated
public static Plugin getPlugin() {
return plugin;
return plugins.get(0);
}
public static ArrayList<Plugin> getPlugins() {
return plugins;
}
public static String getHandlerName(final String name) {
return "pe-" + getSettings().getIdentifier() + "-" + name;
return "pe-" + settings.getIdentifier() + "-" + name;
}
public static Settings getSettings() {
public static PacketEventsSettings getSettings() {
return settings;
}
@EventHandler
public void onJoin(final PlayerJoinEvent e) {
getAPI().getPlayerUtils().injectPlayer(e.getPlayer());
getAPI().getPlayerUtils().setClientVersion(e.getPlayer(), ClientVersion.fromProtocolVersion(VersionLookupUtils.getProtocolVersion(e.getPlayer())));
if(!VersionLookupUtils.hasLoaded()) {
VersionLookupUtils.load();
}
ClientVersion version = ClientVersion.fromProtocolVersion(VersionLookupUtils.getProtocolVersion(e.getPlayer()));
PacketEvents.getAPI().getPlayerUtils().clientVersionsMap.put(e.getPlayer().getUniqueId(), version);
PacketEvents.getAPI().getPlayerUtils().injectPlayer(e.getPlayer());
}
@EventHandler
public void onQuit(final PlayerQuitEvent e) {
getAPI().getPlayerUtils().clearClientVersion(e.getPlayer());
getAPI().getPlayerUtils().uninjectPlayerNow(e.getPlayer());
PacketEvents.getAPI().getPlayerUtils().ejectPlayer(e.getPlayer());
PacketEvents.getAPI().getPlayerUtils().clientVersionsMap.remove(e.getPlayer().getUniqueId());
}
@EventHandler
public void onMove(final PlayerMoveEvent e) {
BukkitMoveEvent moveEvent = new BukkitMoveEvent(e);
getAPI().getEventManager().callEvent(moveEvent);
PacketEvents.getAPI().getEventManager().callEvent(moveEvent);
e.setCancelled(moveEvent.isCancelled());
}
}
}
@@ -0,0 +1,37 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.annotations;
import java.lang.annotation.Documented;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* This annotation indicates that something might be unstable.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
public @interface Beta {
}
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.annotations;
@@ -6,7 +30,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Is for sure not null.
* Guaranteed to not be null.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.annotations;
@@ -6,7 +30,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/**
* Could be null.
* Possible that it is null.
*/
@Documented
@Retention(RetentionPolicy.RUNTIME)
@@ -1,6 +1,32 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.annotations;
import io.github.retrooper.packetevents.annotations.data.EventSynchronization;
import io.github.retrooper.packetevents.enums.EventSynchronization;
import io.github.retrooper.packetevents.enums.PacketEventPriority;
import org.bukkit.event.EventHandler;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
@@ -9,10 +35,10 @@ import java.lang.annotation.Target;
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
/**
* Just like Bukkit's @EventHandler, but for PacketEvents' custom event system.
* Make sure your class implements the PacketListener interface, and is registered when annotating your method with this annotation!
*/
public @interface PacketHandler {
@Deprecated
EventSynchronization synchronization() default EventSynchronization.NORMAL;
byte priority() default PacketEventPriority.NORMAL;
}
@@ -1,5 +0,0 @@
package io.github.retrooper.packetevents.annotations.data;
public enum EventSynchronization {
FORCE_SYNC, FORCE_ASYNC, NORMAL
}
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.api;
import io.github.retrooper.packetevents.event.manager.EventManager;
@@ -17,6 +41,7 @@ public final class PacketEventsAPI {
*
* @return {@link System#nanoTime()} / 1000000(1 million)
*/
@Deprecated
public long currentPreciseMillis() {
return System.nanoTime() / 1000000;
}
@@ -29,57 +54,34 @@ public final class PacketEventsAPI {
*
* @return {@link System#currentTimeMillis()}
*/
@Deprecated
public long currentMillis() {
return System.currentTimeMillis();
}
/**
* Get all utilities to do with the player
*
* @return Player Utilities
*/
public PlayerUtils getPlayerUtils() {
return playerUtils;
}
/**
* Use {@link #getPlayerUtils()}
*
* @return
*/
@Deprecated
public PlayerUtils getPlayerUtilities() {
return playerUtils;
}
/**
* Get all utilities to do with the server
*
* @return Server Utilities
*/
public ServerUtils getServerUtils() {
return serverUtils;
}
/**
* Please use {@link #getServerUtils()}
*
* @return
*/
@Deprecated
public ServerUtils getServerUtilities() {
return serverUtils;
}
/**
* Get the event manager
* Used to call events, register and unregister listeners
*
* @return PacketEvents' event manager
*/
public EventManager getEventManager() {
return eventManager;
}
}
}
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.enums;
import io.github.retrooper.packetevents.PacketEvents;
@@ -8,9 +32,9 @@ import java.util.Map;
public enum ClientVersion {
LESS_THAN_V_1_7_10, v_1_7_10, v_1_8, v_1_9, v_1_9_1, v_1_9_2, v_1_9_3, v_1_10, v_1_11, v_1_11_1, v_1_12, v_1_12_1, v_1_12_2,
v_1_13, v_1_13_1, v_1_13_2, v_1_14, v_1_14_1, v_1_14_2, v_1_14_3, v_1_14_4, v_1_15_PRE_1, v_1_15_PRE_2, v_1_15_PRE_3, v_1_15_PRE_4, v_1_15_PRE_5, v_1_15_PRE_6, v_1_15_PRE_7,
v_1_15, v_1_15_1, v_1_15_2, v_1_16, v_1_16_PRE_1, v_1_16_PRE_2, v_1_16_PRE_3, v_1_16_PRE_4, v_1_16_PRE_5, v_1_16_PRE_6, v_1_16_PRE_7, v_1_16_PRE_8, v_1_16_RC_1, v_1_16_1, HIGHER_THAN_V_1_16_1, INVALID, ACCESS_FAILURE;
v_1_15, v_1_15_1, v_1_15_2, v_1_16, v_1_16_PRE_1, v_1_16_PRE_2, v_1_16_PRE_3, v_1_16_PRE_4, v_1_16_PRE_5, v_1_16_PRE_6, v_1_16_PRE_7, v_1_16_PRE_8, v_1_16_RC_1, v_1_16_1, v_1_16_2, HIGHER_THAN_V_1_16_2, INVALID, ACCESS_FAILURE;
private static final Map<Integer, ClientVersion> VERSION_LOOKUP = new HashMap<>();
private static final Map<Integer, ClientVersion> VERSION_LOOKUP = new HashMap<Integer, ClientVersion>();
public static void prepareLookUp() {
VERSION_LOOKUP.put(-1, ACCESS_FAILURE);
@@ -59,6 +83,7 @@ public enum ClientVersion {
VERSION_LOOKUP.put(734, v_1_16_RC_1);
VERSION_LOOKUP.put(735, v_1_16);
VERSION_LOOKUP.put(736, v_1_16_1);
VERSION_LOOKUP.put(737, v_1_16_2);
}
public static ClientVersion fromProtocolVersion(int protocolVersion) {
@@ -69,14 +94,14 @@ public enum ClientVersion {
if (lookedUp != null) {
return lookedUp;
}
return protocolVersion > 736 ? HIGHER_THAN_V_1_16_1 : INVALID;
return protocolVersion > 737 ? HIGHER_THAN_V_1_16_2 : INVALID;
}
/**
* Returns if the client's version is more up to date than the argument passed version
*
* @param version
* @return
* @param version The version to compare to the client's value.
* @return True if the supplied version is lower, false if it is equal or higher than the client's version.
*/
public boolean isHigherThan(final ClientVersion version) {
if (this == version) return false;
@@ -86,14 +111,14 @@ public enum ClientVersion {
/**
* Returns if the client's version is more outdated than the argument passed version
*
* @param version
* @return
* @param version The version to compare to the client's value.
* @return True if the supplied version is higher, false if it is equal or lower than the client's version.
*/
public boolean isLowerThan(final ClientVersion version) {
if (version == this) return false;
final int len = values().length;
if (this == version) return false;
final int len = ClientVersion.values().length;
for (byte i = 0; i < len; i++) {
final ClientVersion v = values()[i];
final ClientVersion v = ClientVersion.values()[i];
if (v == this) {
return true;
} else if (v == version) {
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.enums;
public enum Direction {
@@ -0,0 +1,29 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.enums;
public enum EventSynchronization {
NORMAL, FORCE_SYNC, FORCE_ASYNC
}
@@ -0,0 +1,34 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.enums;
public interface PacketEventPriority {
byte LOWEST = 0;
byte LOW = 1;
byte NORMAL = 2;
byte HIGH = 3;
byte HIGHEST = 4;
byte MONITOR = 5;
}
@@ -1,44 +1,73 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.enums;
import io.github.retrooper.packetevents.PacketEvents;
import org.bukkit.Bukkit;
import org.bukkit.Server;
/**
* @author retrooper
*/
public enum ServerVersion {
v_1_7_10, v_1_8, v_1_8_3, v_1_8_8, v_1_9, v_1_9_4, v_1_10, v_1_11, v_1_12, v_1_13, v_1_13_2, v_1_14, v_1_15, v_1_16_1,
ERROR, EMPTY;
private static final ServerVersion[] reversedValues;
v_1_7_10, v_1_8, v_1_8_3, v_1_8_4, v_1_8_5, v_1_8_6, v_1_8_7, v_1_8_8,
v_1_9, v_1_9_2, v_1_9_4, v_1_10, v_1_10_2, v_1_11, v_1_11_1, v_1_11_2,
v_1_12, v_1_12_1, v_1_12_2, v_1_13, v_1_13_1, v_1_13_2, v_1_14, v_1_14_1,
v_1_14_2, v_1_14_3, v_1_14_4, v_1_15, v_1_15_1, v_1_15_2, v_1_16, v_1_16_1,
v_1_16_2, ERROR, EMPTY;
private static final String nmsVersionSuffix = Bukkit.getServer().getClass().getPackage().getName().replace(".", ",").split(",")[3];
public static ServerVersion[] reversedValues = new ServerVersion[values().length];
private static ServerVersion cachedVersion;
static {
reversedValues = reverse(values());
}
private static ServerVersion getVers() {
private static ServerVersion getVersionNoCache() {
if(reversedValues[0] == null) {
reversedValues = ServerVersion.reverse(values());
}
for (final ServerVersion val : reversedValues) {
String valName = val.name().substring(2).replace("_", ".");
if (Bukkit.getBukkitVersion().contains(valName)) {
return val;
} else if (PacketEvents.getSettings().getDefaultServerVersion() != null) {
return PacketEvents.getSettings().getDefaultServerVersion();
}
}
if(PacketEvents.getSettings().getDefaultServerVersion() != null) {
return PacketEvents.getSettings().getDefaultServerVersion();
}
return ERROR;
}
public static ServerVersion getVersion() {
if (cachedVersion == null) {
cachedVersion = getVers();
cachedVersion = getVersionNoCache();
}
return cachedVersion;
}
private static ServerVersion[] reverse(final ServerVersion[] arr) {
public static ServerVersion[] reverse(final ServerVersion[] arr) {
ServerVersion[] array = arr.clone();
if (array == null) {
return null;
@@ -71,8 +100,8 @@ public enum ServerVersion {
/**
* Returns if the current version is more up to date than the argument passed version
*
* @param version
* @return
* @param version The version to compare to the server's value.
* @return True if the supplied version is lower, false if it is equal or higher than the server's version.
*/
public boolean isHigherThan(final ServerVersion version) {
if (this == version) return false;
@@ -82,14 +111,14 @@ public enum ServerVersion {
/**
* Returns if the current version is more outdated than the argument passed version
*
* @param version
* @return
* @param version The version to compare to the server's value.
* @return True if the supplied version is higher, false if it is equal or lower than the server's version.
*/
public boolean isLowerThan(final ServerVersion version) {
if (version == this) return false;
final int len = values().length;
if (this == version) return false;
final int len = ServerVersion.values().length;
for (byte i = 0; i < len; i++) {
final ServerVersion v = values()[i];
final ServerVersion v = ServerVersion.values()[i];
if (v == this) {
return true;
} else if (v == version) {
@@ -99,47 +128,73 @@ public enum ServerVersion {
return false;
}
public int toProtocolVersion() {
if (this.equals(ServerVersion.v_1_7_10)) {
return 5;
/**
* Converts the server version to a protocol version.
* Recommended to cache.
* @return protocol version
*/
public short toProtocolVersion() {
switch (this) {
case v_1_7_10:
return 5;
case v_1_8:
case v_1_8_3:
case v_1_8_4:
case v_1_8_5:
case v_1_8_6:
case v_1_8_7:
case v_1_8_8:
return 47;
case v_1_9:
return 107;
case v_1_9_2:
return 109;
case v_1_9_4:
return 110;
case v_1_10:
case v_1_10_2:
return 210;
case v_1_11:
return 315;
case v_1_11_1:
case v_1_11_2:
return 316;
case v_1_12:
return 335;
case v_1_12_1:
return 338;
case v_1_12_2:
return 340;
case v_1_13:
return 393;
case v_1_13_1:
return 401;
case v_1_13_2:
return 404;
case v_1_14:
return 477;
case v_1_14_1:
return 480;
case v_1_14_2:
return 485;
case v_1_14_3:
return 490;
case v_1_14_4:
return 498;
case v_1_15:
return 573;
case v_1_15_1:
return 575;
case v_1_15_2:
return 578;
case v_1_16:
return 735;
case v_1_16_1:
return 736;
case v_1_16_2:
return 751;
default:
return -1;
}
if (this.name().startsWith("v_1_8")) {
return 47;
}
if (this.equals(ServerVersion.v_1_9)) {
return 107;
}
if (this.equals(ServerVersion.v_1_9_4)) {
return 110;
}
if (this.equals(ServerVersion.v_1_10)) {
return 210;
}
if (this.equals(ServerVersion.v_1_11)) {
return 315;
}
if (this.equals(ServerVersion.v_1_11)) {
return 315;
}
if (this.equals(ServerVersion.v_1_12)) {
return 335;
}
if (this.equals(ServerVersion.v_1_13)) {
return 393;
}
if (this.equals(ServerVersion.v_1_13_2)) {
return 404;
}
if (this.equals(ServerVersion.v_1_14)) {
return 477;
}
if (this.equals(ServerVersion.v_1_15)) {
return 573;
}
if (this.equals(ServerVersion.v_1_16_1)) {
return 735;
}
return -1;
}
}
}
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.enums;
public enum SystemOS {
@@ -1,19 +0,0 @@
package io.github.retrooper.packetevents.enums.minecraft;
public enum EntityAnimationType {
SWING_MAIN_ARM, DAMAGE, LEAVE_BED, SWING_OFFHAND, CRITICAL_EFFECT, MAGIC_CRITICAL_EFFECT;
public static final EntityAnimationType get(final int i) {
return values()[i];
}
public final int getIndex() {
for (int i = 0; i < values().length; i++) {
final EntityAnimationType curType = values()[0];
if (curType == this) {
return i;
}
}
return -1;
}
}
@@ -1,9 +0,0 @@
package io.github.retrooper.packetevents.enums.minecraft;
public enum EntityUseAction {
INTERACT, INTERACT_AT, ATTACK, INVALID;
public static EntityUseAction get(final int i) {
return values()[i];
}
}
@@ -1,25 +0,0 @@
package io.github.retrooper.packetevents.enums.minecraft;
public enum Gamemode {
NOT_SET(-1, ""),
SURVIVAL(0, "survival"),
CREATIVE(1, "creative"),
ADVENTURE(2, "adventure"),
SPECTATOR(3, "spectator");
int f;
String g;
Gamemode(int var3, String var4) {
this.f = var3;
this.g = var4;
}
public int getId() {
return this.f;
}
public String b() {
return this.g;
}
}
@@ -1,6 +0,0 @@
package io.github.retrooper.packetevents.enums.minecraft;
public enum Hand {
MAIN_HAND,
OFF_HAND
}
@@ -1,59 +0,0 @@
package io.github.retrooper.packetevents.enums.minecraft;
public enum PlayerAction {
START_SNEAKING,
STOP_SNEAKING,
STOP_SLEEPING,
START_SPRINTING,
STOP_SPRINTING,
START_RIDING_JUMP,
STOP_RIDING_JUMP,
OPEN_INVENTORY,
START_FALL_FLYING;
public static PlayerAction get(final int i) {
return values()[i];
}
public int getIndex() {
for (int i = 0; i < values().length; i++) {
final PlayerAction action = values()[i];
if (action == this) {
return i;
}
}
return -1;
}
public enum UpdatedPlayerAction {
PRESS_SHIFT_KEY, RELEASE_SHIFT_KEY, STOP_SLEEPING, START_SPRINTING, STOP_SPRINTING, START_RIDING_JUMP, STOP_RIDING_JUMP, OPEN_INVENTORY, START_FALL_FLYING;
public static UpdatedPlayerAction get(final int index) {
for (int i = 0; i < index + 1; i++) {
final UpdatedPlayerAction action = values()[i];
if (i == index) {
return action;
}
}
return null;
}
public int getIndex() {
for (int i = 0; i < values().length; i++) {
final UpdatedPlayerAction action = values()[i];
if (action == this) {
return i;
}
}
return -1;
}
}
}
@@ -1,26 +0,0 @@
package io.github.retrooper.packetevents.enums.minecraft;
public enum PlayerDigType {
START_DESTROY_BLOCK,
ABORT_DESTROY_BLOCK,
STOP_DESTROY_BLOCK,
DROP_ALL_ITEMS,
DROP_ITEM,
RELEASE_USE_ITEM,
SWAP_HELD_ITEMS,
SWAP_ITEM_WITH_OFFHAND,
WRONG_PACKET;
public static PlayerDigType get(final int i) {
return values()[i];
}
}
@@ -1,8 +0,0 @@
package io.github.retrooper.packetevents.enums.minecraft;
public enum PlayerInfoAction {
ADD_PLAYER, UPDATE_GAME_MODE, UPDATE_LATENCY, UPDATE_DISPLAY_NAME, REMOVE_PLAYER;
PlayerInfoAction() {
}
}
@@ -0,0 +1,50 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.event;
/**
* This indicates that it is possible to cancel an event,
* which should result in cancelling the planned action.
*/
public interface CancellableEvent {
/**
* Has the event been cancelled?
* @return is event cancelled
*/
boolean isCancelled();
/**
* Cancel or proceed with the event.
* @param val
*/
void setCancelled(boolean val);
/**
* Cancel the event.
* This is the same as just doing: CancellableEvent#setCancelled(true)
*/
void cancel();
}
@@ -1,16 +1,43 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.event;
import io.github.retrooper.packetevents.enums.ServerVersion;
public class PacketEvent {
protected static ServerVersion version = ServerVersion.getVersion();
/**
* An event in the PacketEvents EventManager system.
*/
public abstract class PacketEvent {
public static ServerVersion version;
private long timestamp = System.currentTimeMillis();
/**
* Timestamp of the packet
*
* @return
* @return timestamp in milliseconds
*/
public long getTimestamp() {
return timestamp;
@@ -19,4 +46,4 @@ public class PacketEvent {
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
}
}
@@ -1,4 +1,32 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.event;
/**
* A Packet listener.
* Implement this interface in your listeners.
*/
public interface PacketListener {
}
@@ -1,11 +1,15 @@
package io.github.retrooper.packetevents.event.impl;
import io.github.retrooper.packetevents.event.CancellableEvent;
import io.github.retrooper.packetevents.event.PacketEvent;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerMoveEvent;
public final class BukkitMoveEvent extends PacketEvent {
//Do not use this, I plan to remove this event.
//If you wish you may recreate this class yourself and use it.
@Deprecated
public final class BukkitMoveEvent extends PacketEvent implements CancellableEvent {
private final Player player;
private final Location to, from;
private boolean cancelled;
@@ -34,14 +38,17 @@ public final class BukkitMoveEvent extends PacketEvent {
return to;
}
public void setCancelled(final boolean val) {
this.cancelled = val;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(final boolean val) {
this.cancelled = val;
}
@Override
public void cancel() {
setCancelled(true);
}
@@ -1,10 +1,38 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.event.impl;
import io.github.retrooper.packetevents.event.CancellableEvent;
import io.github.retrooper.packetevents.event.PacketEvent;
import io.github.retrooper.packetevents.packet.PacketType;
import org.bukkit.entity.Player;
public final class PacketReceiveEvent extends PacketEvent {
/**
* This event is called each time a packet is received from a client.
*/
public final class PacketReceiveEvent extends PacketEvent implements CancellableEvent {
private final Player player;
private final Object packet;
private boolean cancelled;
@@ -15,24 +43,25 @@ public final class PacketReceiveEvent extends PacketEvent {
}
/**
* Get the player sending the packet
*
* @return
* Get the packet sender
* @return player
*/
public Player getPlayer() {
return this.player;
}
/**
* Get the packet's name (NMS packet class simple name)
* Get the packet's name (NMS packet class simple name).
* @return Name of the packet
* @deprecated It is recommended not to use this.
*/
@Deprecated
public String getPacketName() {
return this.packet.getClass().getSimpleName();
}
/**
* Get the NMS packet object
*
* Get the raw packet object
* @return packet object
*/
public Object getNMSPacket() {
@@ -41,41 +70,35 @@ public final class PacketReceiveEvent extends PacketEvent {
/**
* Get the class of the NMS packet object
*
* @deprecated It is useless, rather use getNMSPacket().getClass()
* @return packet object class
*/
@Deprecated
public Class<?> getNMSPacketClass() {
return getNMSPacket().getClass();
return packet.getClass();
}
/**
* Get the ID of the packet
*
* @return packet id
*/
public byte getPacketId() {
Byte id = PacketType.Client.packetIds.get(getNMSPacketClass());
if (id == null) {
return -1;
}
return id;
return PacketType.Client.packetIds.getOrDefault(packet.getClass(), (byte) -1);
}
/**
* Returns if the packet has been cancelled
*
* @return cancelled
*/
@Override
public void cancel() {
this.cancelled = true;
}
@Override
public boolean isCancelled() {
return cancelled;
}
/**
* Cancel the packet
*
* @param cancelled
*/
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}
@@ -1,11 +1,38 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.event.impl;
import io.github.retrooper.packetevents.event.CancellableEvent;
import io.github.retrooper.packetevents.event.PacketEvent;
import io.github.retrooper.packetevents.packet.PacketType;
import org.bukkit.entity.Player;
public final class PacketSendEvent extends PacketEvent {
/**
* This event is called each time the server sends a packet to the client.
*/
public final class PacketSendEvent extends PacketEvent implements CancellableEvent {
private final Player player;
private final Object packet;
private boolean cancelled;
@@ -23,7 +50,10 @@ public final class PacketSendEvent extends PacketEvent {
/**
* Get the packet's name (NMS packet class simple name)
* @deprecated It is recommended not to use this, as it is an expensive function to call.
* @return Name of the packet
*/
@Deprecated
public String getPacketName() {
return this.packet.getClass().getSimpleName();
}
@@ -34,12 +64,7 @@ public final class PacketSendEvent extends PacketEvent {
* @return packet id
*/
public byte getPacketId() {
Byte id =
PacketType.Server.packetIds.get(getNMSPacketClass());
if (id == null) {
return -1;
}
return id;
return PacketType.Server.packetIds.getOrDefault(packet.getClass(), (byte) -1);
}
/**
@@ -52,20 +77,29 @@ public final class PacketSendEvent extends PacketEvent {
}
/**
* Get the class of the NMS packet object
* Get the class of the NMS packet object.
* Deprecated because it is useless, rather use getNMSPacket().getClass().
*
* @return packet object class
*/
@Deprecated
public Class<?> getNMSPacketClass() {
return getNMSPacket().getClass();
return packet.getClass();
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@Override
public void cancel() {
this.cancelled = true;
}
}
@@ -1,29 +1,71 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.event.impl;
import io.github.retrooper.packetevents.event.CancellableEvent;
import io.github.retrooper.packetevents.event.PacketEvent;
import org.bukkit.entity.Player;
public final class PlayerInjectEvent extends PacketEvent {
/**
* This event is called each time you inject a player.
*/
public final class PlayerInjectEvent extends PacketEvent implements CancellableEvent {
private final Player player;
private final boolean async;
private boolean cancelled;
public PlayerInjectEvent(final Player player) {
this.player = player;
this(player, false);
}
public PlayerInjectEvent(final Player player, boolean isAsync) {
this.player= player;
this.async = isAsync;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
@Override
public void cancel() {
setCancelled(true);
this.cancelled = true;
}
public Player getPlayer() {
return player;
}
public boolean isAsync() {
return async;
}
}
@@ -1,42 +1,70 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.event.impl;
import io.github.retrooper.packetevents.event.CancellableEvent;
import io.github.retrooper.packetevents.event.PacketEvent;
import org.bukkit.entity.Player;
public final class PlayerUninjectEvent extends PacketEvent {
/**
* This event is called each time you eject a player.
*/
public final class PlayerUninjectEvent extends PacketEvent implements CancellableEvent {
private final Player player;
private final boolean async;
private boolean cancelled;
private final boolean sync;
public PlayerUninjectEvent(final Player player, final boolean sync) {
public PlayerUninjectEvent(final Player player, final boolean isAsync) {
this.player = player;
this.sync = sync;
this.async = isAsync;
}
public PlayerUninjectEvent(final Player player) {
this(player, false);
}
@Override
public void cancel() {
setCancelled(true);
this.cancelled = true;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(final boolean val) {
this.cancelled = val;
}
/**
* Whether the uninjection was called synchronously or asynchronously.
* The event is still called synchronously.
* By default all uninjections are called aynchronously in this build.
*
* @return If the uninjection was done async or sync
*/
public boolean isSync() {
return sync;
}
public Player getPlayer() {
return player;
}
public boolean isAsync() {
return async;
}
}
@@ -1,10 +1,36 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.event.manager;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.annotations.PacketHandler;
import io.github.retrooper.packetevents.annotations.data.EventSynchronization;
import io.github.retrooper.packetevents.enums.PacketEventPriority;
import io.github.retrooper.packetevents.event.CancellableEvent;
import io.github.retrooper.packetevents.event.PacketEvent;
import io.github.retrooper.packetevents.event.PacketListener;
import io.github.retrooper.packetevents.utils.protocollib.ProtocolLibListener;
import org.bukkit.Bukkit;
import java.lang.reflect.InvocationTargetException;
@@ -12,62 +38,94 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public final class EventManager {
private final ExecutorService executorService;
private final HashMap<PacketListener, List<Method>> registeredMethods = new HashMap<PacketListener, List<Method>>();
public EventManager(final int threadCount) {
executorService = Executors.newFixedThreadPool(threadCount);
}
public EventManager() {
this(Runtime.getRuntime().availableProcessors());
}
public void callEvent(final PacketEvent e) {
for (final PacketListener listener : registeredMethods.keySet()) {
//Annotated methods
final List<Method> methods = registeredMethods.get(listener);
for (final Method method : methods) {
final List<Boolean> isCancellingList = new ArrayList<Boolean>(methods.size());
int highestPriorityMethodListenerIndex = 0;
for(int i = 0; i < methods.size(); i++) {
Method method = methods.get(i);
final Class<?> parameterType = method.getParameterTypes()[0];
if (parameterType.equals(PacketEvent.class)
|| parameterType.isInstance(e)) {
final PacketHandler annotation = method.getAnnotation(PacketHandler.class);
PacketHandler annotation = methods.get(highestPriorityMethodListenerIndex).getAnnotation(PacketHandler.class);
PacketHandler competitorAnnotation = methods.get(i).getAnnotation(PacketHandler.class);
if(competitorAnnotation.priority() >= annotation.priority()) {
highestPriorityMethodListenerIndex = i;
}
boolean isCurEventCancelled = false;
final Runnable invokeMethod = new Runnable() {
@Override
public void run() {
try {
method.invoke(listener, e);
if(e instanceof CancellableEvent) {
isCancellingList.add(((CancellableEvent) e).isCancelled());
}
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
}
};
if (annotation.synchronization() == EventSynchronization.FORCE_ASYNC) {
executorService.execute(invokeMethod);
} else if (annotation.synchronization() == EventSynchronization.FORCE_SYNC) {
Bukkit.getScheduler().runTask(PacketEvents.getPlugin(), invokeMethod);
} else {
invokeMethod.run();
switch (annotation.synchronization()) {
case FORCE_ASYNC:
Bukkit.getScheduler().runTaskAsynchronously(PacketEvents.getPlugin(), invokeMethod);
break;
case FORCE_SYNC:
Bukkit.getScheduler().runTask(PacketEvents.getPlugin(), invokeMethod);
break;
default:
try {
method.invoke(listener, e);
} catch (IllegalAccessException | InvocationTargetException ex) {
ex.printStackTrace();
}
isCancellingList.add(((CancellableEvent)e).isCancelled());
break;
}
//Last iteration
if(i + 1 == methods.size()) {
if(e instanceof CancellableEvent) {
CancellableEvent cancellable = (CancellableEvent)e;
cancellable.setCancelled(isCancellingList.get(highestPriorityMethodListenerIndex));
}
}
}
}
}
}
public void registerListener(final PacketListener e) {
final List<Method> methods = new ArrayList<Method>();
for (final Method m : e.getClass().getMethods()) {
public void registerListener(final PacketListener listener) {
if (ProtocolLibListener.isProtocolLibPresent() == ProtocolLibListener.ProtocolLibPresent.UNKNOWN) {
ProtocolLibListener.load();
}
final List<Method> methods = new ArrayList<Method>();
for (final Method m : listener.getClass().getDeclaredMethods()) {
if (m.isAnnotationPresent(PacketHandler.class)
&& m.getParameterTypes().length == 1) {
methods.add(m);
}
}
if (!methods.isEmpty()) {
registeredMethods.put(e, methods);
if (ProtocolLibListener.isProtocolLibPresent() == ProtocolLibListener.ProtocolLibPresent.PRESENT) {
ProtocolLibListener.registerProtocolLibListener(listener, methods);
} else {
registeredMethods.put(listener, methods);
}
}
}
@@ -1,13 +1,31 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.example;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.annotations.PacketHandler;
import io.github.retrooper.packetevents.event.PacketListener;
import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent;
import io.github.retrooper.packetevents.packet.PacketType;
import io.github.retrooper.packetevents.packetwrappers.in.armanimation.WrappedPacketInArmAnimation;
import io.github.retrooper.packetevents.packetwrappers.in.custompayload.WrappedPacketInCustomPayload;
import io.github.retrooper.packetevents.packetwrappers.in.helditemslot.WrappedPacketInHeldItemSlot;
import org.bukkit.plugin.java.JavaPlugin;
public class MainExample extends JavaPlugin implements PacketListener {
@@ -19,15 +37,11 @@ public class MainExample extends JavaPlugin implements PacketListener {
@Override
public void onEnable() {
//Make sure you set a unique identifier, if another present plugin has the same identifier, you could run into issues
//Deprecated, as it is no longer needed
PacketEvents.getSettings().setIdentifier("official_api");
PacketEvents.start(this);
//If packetevents cannot detect your server version, it will use the default you specify version
// getAPI().getSettings().setDefaultServerVersion(ServerVersion.v_1_7_10);
PacketEvents.getAPI().getEventManager().registerListeners(this);
PacketEvents.init(this);
//PacketEvents.getAPI().getEventManager().registerListener(this);
}
@Override
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.handler;
import io.github.retrooper.packetevents.PacketEvents;
@@ -7,10 +31,13 @@ import io.github.retrooper.packetevents.event.impl.PlayerInjectEvent;
import io.github.retrooper.packetevents.event.impl.PlayerUninjectEvent;
import org.bukkit.entity.Player;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
public class NettyPacketHandler {
private static boolean v1_7_nettyMode = false;
private static final ExecutorService singleThreadedExecutor = Executors.newSingleThreadExecutor();
static {
try {
@@ -20,50 +47,103 @@ public class NettyPacketHandler {
}
}
/**
* Synchronously inject a player
*
* @param player Target player to inject
*/
public static void injectPlayer(final Player player) {
final PlayerInjectEvent injectEvent = new PlayerInjectEvent(player);
PacketEvents.getAPI().getEventManager().callEvent(injectEvent);
if (!injectEvent.isCancelled()) {
if (v1_7_nettyMode) {
NettyPacketHandler_7.injectPlayer(player);
} else {
NettyPacketHandler_8.injectPlayer(player);
}
}
}
public static Future<?> uninjectPlayer(final Player player) {
try {
final PlayerUninjectEvent uninjectEvent = new PlayerUninjectEvent(player, false);
PacketEvents.getAPI().getEventManager().callEvent(uninjectEvent);
if (!uninjectEvent.isCancelled()) {
final PlayerInjectEvent injectEvent = new PlayerInjectEvent(player);
PacketEvents.getAPI().getEventManager().callEvent(injectEvent);
if (!injectEvent.isCancelled()) {
if (v1_7_nettyMode) {
return NettyPacketHandler_7.uninjectPlayer(player);
NettyPacketHandler_7.injectPlayer(player);
} else {
return NettyPacketHandler_8.uninjectPlayer(player);
NettyPacketHandler_8.injectPlayer(player);
}
}
} catch (Exception ignored) {
}
return null;
}
public static void uninjectPlayerNow(final Player player) {
/**
* Asynchronously inject a player
*
* @param player
* @return {@link java.util.concurrent.Future}
*/
public static Future<?> injectPlayerAsync(final Player player) {
return singleThreadedExecutor.submit(() -> {
try {
final PlayerInjectEvent injectEvent = new PlayerInjectEvent(player, true);
PacketEvents.getAPI().getEventManager().callEvent(injectEvent);
if (!injectEvent.isCancelled()) {
if (v1_7_nettyMode) {
NettyPacketHandler_7.injectPlayer(player);
} else {
NettyPacketHandler_8.injectPlayer(player);
}
}
} catch (Exception ignored) {
}
});
}
/**
* Synchronously eject a player.
*
* @param player
*/
public static void ejectPlayer(final Player player) {
try {
final PlayerUninjectEvent uninjectEvent = new PlayerUninjectEvent(player, true);
final PlayerUninjectEvent uninjectEvent = new PlayerUninjectEvent(player);
PacketEvents.getAPI().getEventManager().callEvent(uninjectEvent);
if (!uninjectEvent.isCancelled()) {
if (v1_7_nettyMode) {
NettyPacketHandler_7.uninjectPlayerNow(player);
NettyPacketHandler_7.ejectPlayer(player);
} else {
NettyPacketHandler_8.uninjectPlayerNow(player);
NettyPacketHandler_8.ejectPlayer(player);
}
}
} catch (Exception ignored) {
}
}
/**
* Asynchronously eject a player
*
* @param player
* @return {@link java.util.concurrent.Future}
*/
public static Future<?> ejectPlayerAsync(final Player player) {
return singleThreadedExecutor.submit(() -> {
try {
final PlayerUninjectEvent uninjectEvent = new PlayerUninjectEvent(player, true);
PacketEvents.getAPI().getEventManager().callEvent(uninjectEvent);
if (!uninjectEvent.isCancelled()) {
if (v1_7_nettyMode) {
NettyPacketHandler_7.ejectPlayer(player);
} else {
NettyPacketHandler_8.ejectPlayer(player);
}
}
} catch (Exception ignored) {
}
});
}
/**
* This function is called each time the server plans to send a packet to the client.
*
* @param sender
* @param packet
* @return
*/
public static Object write(final Player sender, final Object packet) {
final PacketSendEvent packetSendEvent = new PacketSendEvent(sender, packet);
PacketEvents.getAPI().getEventManager().callEvent(packetSendEvent);
@@ -73,6 +153,14 @@ public class NettyPacketHandler {
return null;
}
/**
* This function is called each time the server receives a packet from the client.
*
* @param receiver
* @param packet
* @return
*/
public static Object read(final Player receiver, final Object packet) {
final PacketReceiveEvent packetReceiveEvent = new PacketReceiveEvent(receiver, packet);
PacketEvents.getAPI().getEventManager().callEvent(packetReceiveEvent);
@@ -82,5 +170,4 @@ public class NettyPacketHandler {
return null;
}
}
}
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.handler;
import io.github.retrooper.packetevents.PacketEvents;
@@ -13,6 +37,10 @@ import java.util.concurrent.Future;
final class NettyPacketHandler_7 {
/**
* Inject a player using 1.7.10's netty import location
* @param player
*/
public static void injectPlayer(final Player player) {
final ChannelDuplexHandler channelDuplexHandler = new ChannelDuplexHandler() {
@Override
@@ -37,15 +65,12 @@ final class NettyPacketHandler_7 {
pipeline.addBefore("packet_handler", PacketEvents.getHandlerName(player.getName()), channelDuplexHandler);
}
public static Future<?> uninjectPlayer(final Player player) {
final Channel channel = (Channel) NMSUtils.getChannel(player);
return channel.eventLoop().submit(() -> {
channel.pipeline().remove(PacketEvents.getHandlerName(player.getName()));
});
}
public static void uninjectPlayerNow(final Player player) {
/**
* Eject a player using 1.7.10 netty import location.
* @param player
*/
public static void ejectPlayer(final Player player) {
final Channel channel = (Channel) NMSUtils.getChannel(player);
channel.pipeline().remove(PacketEvents.getHandlerName(player.getName()));
}
}
}
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.handler;
import io.github.retrooper.packetevents.PacketEvents;
@@ -12,7 +36,10 @@ import org.bukkit.entity.Player;
import java.util.concurrent.Future;
final class NettyPacketHandler_8 {
/**
* Inject a player with 1.8+ netty import location.
* @param player
*/
public static void injectPlayer(final Player player) {
final ChannelDuplexHandler channelDuplexHandler = new ChannelDuplexHandler() {
@Override
@@ -37,15 +64,12 @@ final class NettyPacketHandler_8 {
pipeline.addBefore("packet_handler", PacketEvents.getHandlerName(player.getName()), channelDuplexHandler);
}
public static Future<?> uninjectPlayer(final Player player) {
final Channel channel = (Channel) NMSUtils.getChannel(player);
return channel.eventLoop().submit(() -> {
channel.pipeline().remove(PacketEvents.getHandlerName(player.getName()));
});
}
public static void uninjectPlayerNow(final Player player) {
/**
* Eject a player with 1.8+ netty import location.
* @param player
*/
public static void ejectPlayer(final Player player) {
final Channel channel = (Channel) NMSUtils.getChannel(player);
channel.pipeline().remove(PacketEvents.getHandlerName(player.getName()));
}
}
}
@@ -1,23 +1,35 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packet;
import java.util.HashMap;
import java.util.Map;
public class PacketType {
public static class Client {
public static class Util {
public static boolean isInstanceOfFlying(final byte packetId) {
return packetId == FLYING
|| packetId == POSITION
|| packetId == POSITION_LOOK
|| packetId == LOOK;
}
}
public static final Map<Class<?>, Byte> packetIds = new HashMap<Class<?>, Byte>();
public static final byte TELEPORT_ACCEPT = 0,
TILE_NBT_QUERY = 1, DIFFICULTY_CHANGE = 2, CHAT = 3, CLIENT_COMMAND = 4,
SETTINGS = 5, TAB_COMPLETE = 6, TRANSACTION = 7, ENCHANT_ITEM = 8,
@@ -81,11 +93,25 @@ public class PacketType {
packetIds.put(PacketTypeClasses.Client.USE_ITEM, USE_ITEM);
packetIds.put(PacketTypeClasses.Client.BLOCK_PLACE, BLOCK_PLACE);
}
public static class Util {
/**
* Is the packet an instance of the PacketPlayInFlying packet?
* @param packetID
* @return packetID == FLYING or POSITION or POSITION_LOOK or LOOK
*/
public static boolean isInstanceOfFlying(final byte packetID) {
return packetID == FLYING
|| packetID == POSITION
|| packetID == POSITION_LOOK
|| packetID == LOOK;
}
}
}
public static class Server {
public static final Map<Class<?>, Byte> packetIds = new HashMap<Class<?>, Byte>();
public static byte SPAWN_ENTITY = 0, SPAWN_ENTITY_EXPERIENCE_ORB = 1, SPAWN_ENTITY_WEATHER = 2, SPAWN_ENTITY_LIVING = 3,
public static final byte SPAWN_ENTITY = 0, SPAWN_ENTITY_EXPERIENCE_ORB = 1, SPAWN_ENTITY_WEATHER = 2, SPAWN_ENTITY_LIVING = 3,
SPAWN_ENTITY_PAINTING = 4, SPAWN_ENTITY_SPAWN = 5, ANIMATION = 6, STATISTIC = 7,
BLOCK_BREAK = 8, BLOCK_BREAK_ANIMATION = 9, TILE_ENTITY_DATA = 10, BLOCK_ACTION = 11,
BLOCK_CHANGE = 12, BOSS = 13, SERVER_DIFFICULTY = 14, CHAT = 15, MULTI_BLOCK_CHANGE = 16,
@@ -135,6 +161,7 @@ public class PacketType {
packetIds.put(PacketTypeClasses.Server.WINDOW_ITEMS, WINDOW_ITEMS);
packetIds.put(PacketTypeClasses.Server.WINDOW_DATA, WINDOW_DATA);
packetIds.put(PacketTypeClasses.Server.SET_SLOT, SET_SLOT);
packetIds.put(PacketTypeClasses.Server.SET_COOLDOWN, SET_COOLDOWN);
packetIds.put(PacketTypeClasses.Server.CUSTOM_PAYLOAD, CUSTOM_PAYLOAD);
packetIds.put(PacketTypeClasses.Server.CUSTOM_SOUND_EFFECT, CUSTOM_SOUND_EFFECT);
packetIds.put(PacketTypeClasses.Server.KICK_DISCONNECT, KICK_DISCONNECT);
@@ -145,6 +172,7 @@ public class PacketType {
packetIds.put(PacketTypeClasses.Server.OPEN_WINDOW_HORSE, OPEN_WINDOW_HORSE);
packetIds.put(PacketTypeClasses.Server.KEEP_ALIVE, KEEP_ALIVE);
packetIds.put(PacketTypeClasses.Server.MAP_CHUNK, MAP_CHUNK);
packetIds.put(PacketTypeClasses.Server.WORLD_EVENT, WORLD_EVENT);
packetIds.put(PacketTypeClasses.Server.WORLD_EVENT, SPAWN_ENTITY);
packetIds.put(PacketTypeClasses.Server.WORLD_PARTICLES, WORLD_PARTICLES);
packetIds.put(PacketTypeClasses.Server.LIGHT_UPDATE, LIGHT_UPDATE);
@@ -205,6 +233,18 @@ public class PacketType {
packetIds.put(PacketTypeClasses.Server.TAGS, TAGS);
packetIds.put(PacketTypeClasses.Server.MAP_CHUNK_BULK, MAP_CHUNK_BULK);
}
public static class Util {
/**
* Is the packet an instance of the PacketPlayOutEntity packet?
* @param packetID
* @return packetID == ENTITY or REL_ENTITY_MOVE or REL_ENTITY_MOVE_LOOK or ENTITY_LOOK
*/
public static boolean isInstanceOfEntity(final byte packetID) {
return packetID == ENTITY || packetID == REL_ENTITY_MOVE ||
packetID == REL_ENTITY_MOVE_LOOK || packetID == ENTITY_LOOK;
}
}
}
@@ -1,12 +1,36 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packet;
import io.github.retrooper.packetevents.annotations.Nullable;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
public class PacketTypeClasses {
public static class Client {
public static Class<?> POSITION, POSITION_LOOK, LOOK, CLIENT_COMMAND,
private static final String c = "PacketPlayIn";
public static Class<?> FLYING, POSITION, POSITION_LOOK, LOOK, CLIENT_COMMAND,
TRANSACTION, BLOCK_DIG, ENTITY_ACTION, USE_ENTITY,
WINDOW_CLICK, STEER_VEHICLE, CUSTOM_PAYLOAD, ARM_ANIMATION,
BLOCK_PLACE, USE_ITEM, ABILITIES, HELD_ITEM_SLOT,
@@ -17,11 +41,12 @@ public class PacketTypeClasses {
AUTO_RECIPE, RECIPE_DISPLAYED, ITEM_NAME, RESOURCE_PACK_STATUS,
ADVANCEMENTS, TR_SEL, BEACON, SET_COMMAND_BLOCK,
SET_COMMAND_MINECART, SET_JIGSAW, STRUCT, UPDATE_SIGN, SPECTATE;
private static final String c = "PacketPlayIn";
@Nullable
public static final Class<?> FLYING = NMSUtils.getNMSClassWithoutException(c + "Flying");
/**
* Initiate all server-bound packet classes.
*/
public static void load() {
FLYING = NMSUtils.getNMSClassWithoutException(c + "Flying");
try {
POSITION = NMSUtils.getNMSClass(c + "Position");
POSITION_LOOK = NMSUtils.getNMSClass(c + "PositionLook");
@@ -94,10 +119,8 @@ public class PacketTypeClasses {
}
}
PacketType.Client.init();
}
}
public static class Server {
@@ -126,6 +149,9 @@ public class PacketTypeClasses {
NBT_QUERY, COLLECT, ENTITY_TELEPORT, ADVANCEMENTS, UPDATE_ATTRIBUTES,
ENTITY_EFFECT, RECIPE_UPDATE, TAGS, MAP_CHUNK_BULK;
/**
* Initiate all client-bound packet classes.
*/
public static void load() {
SPAWN_ENTITY = NMSUtils.getNMSClassWithoutException(s + "SpawnEntity");
SPAWN_ENTITY_EXPERIENCE_ORB = NMSUtils.getNMSClassWithoutException(s + "SpawnEntityExperienceOrb");
@@ -1,5 +1,32 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers;
/**
* This interface indicates that a packet wrapper supports being sent to a client.
*/
public interface Sendable {
Object asNMSPacket();
}
@@ -1,13 +1,68 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.api;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.packetwrappers.in.abilities.WrappedPacketInAbilities;
import io.github.retrooper.packetevents.packetwrappers.in.armanimation.WrappedPacketInArmAnimation;
import io.github.retrooper.packetevents.packetwrappers.in.blockdig.WrappedPacketInBlockDig;
import io.github.retrooper.packetevents.packetwrappers.in.blockplace.WrappedPacketInBlockPlace;
import io.github.retrooper.packetevents.packetwrappers.in.chat.WrappedPacketInChat;
import io.github.retrooper.packetevents.packetwrappers.in.clientcommand.WrappedPacketInClientCommand;
import io.github.retrooper.packetevents.packetwrappers.in.custompayload.WrappedPacketInCustomPayload;
import io.github.retrooper.packetevents.packetwrappers.in.entityaction.WrappedPacketInEntityAction;
import io.github.retrooper.packetevents.packetwrappers.in.flying.WrappedPacketInFlying;
import io.github.retrooper.packetevents.packetwrappers.in.helditemslot.WrappedPacketInHeldItemSlot;
import io.github.retrooper.packetevents.packetwrappers.in.keepalive.WrappedPacketInKeepAlive;
import io.github.retrooper.packetevents.packetwrappers.in.settings.WrappedPacketInSettings;
import io.github.retrooper.packetevents.packetwrappers.in.steervehicle.WrappedPacketInSteerVehicle;
import io.github.retrooper.packetevents.packetwrappers.in.transaction.WrappedPacketInTransaction;
import io.github.retrooper.packetevents.packetwrappers.in.useentity.WrappedPacketInUseEntity;
import io.github.retrooper.packetevents.packetwrappers.in.windowclick.WrappedPacketInWindowClick;
import io.github.retrooper.packetevents.packetwrappers.out.abilities.WrappedPacketOutAbilities;
import io.github.retrooper.packetevents.packetwrappers.out.animation.WrappedPacketOutAnimation;
import io.github.retrooper.packetevents.packetwrappers.out.chat.WrappedPacketOutChat;
import io.github.retrooper.packetevents.packetwrappers.out.entity.WrappedPacketOutEntity;
import io.github.retrooper.packetevents.packetwrappers.out.entityvelocity.WrappedPacketOutEntityVelocity;
import io.github.retrooper.packetevents.packetwrappers.out.keepalive.WrappedPacketOutKeepAlive;
import io.github.retrooper.packetevents.packetwrappers.out.kickdisconnect.WrappedPacketOutKickDisconnect;
import io.github.retrooper.packetevents.packetwrappers.out.position.WrappedPacketOutPosition;
import io.github.retrooper.packetevents.packetwrappers.out.transaction.WrappedPacketOutTransaction;
import io.github.retrooper.packetevents.packetwrappers.out.updatehealth.WrappedPacketOutUpdateHealth;
import org.bukkit.entity.Player;
public class WrappedPacket {
protected static ServerVersion version = ServerVersion.getVersion();
public static ServerVersion version;
protected final Player player;
protected Object packet;
public WrappedPacket() {
this.player = null;
this.packet = null;
}
public WrappedPacket(final Object packet) {
this.player = null;
if (packet == null) return;
@@ -30,6 +85,37 @@ public class WrappedPacket {
}
}
public static void loadAllWrappers() {
//SERVER BOUND
WrappedPacketInAbilities.load();
WrappedPacketInArmAnimation.load();
WrappedPacketInBlockDig.load();
WrappedPacketInBlockPlace.load();
WrappedPacketInChat.load();
WrappedPacketInClientCommand.load();
WrappedPacketInCustomPayload.load();
WrappedPacketInEntityAction.load();
WrappedPacketInFlying.load();
WrappedPacketInHeldItemSlot.load();
WrappedPacketInKeepAlive.load();
WrappedPacketInSettings.load();
WrappedPacketInSteerVehicle.load();
WrappedPacketInTransaction.load();
WrappedPacketInUseEntity.load();
WrappedPacketInWindowClick.load();
//CLIENTBOUND
WrappedPacketOutAbilities.load();
WrappedPacketOutAnimation.load();
WrappedPacketOutChat.load();
WrappedPacketOutEntity.load();
WrappedPacketOutEntityVelocity.load();
WrappedPacketOutKeepAlive.load();
WrappedPacketOutKickDisconnect.load();
WrappedPacketOutPosition.load();
WrappedPacketOutTransaction.load();
WrappedPacketOutUpdateHealth.load();
}
protected void setup() {
@@ -1,47 +1,78 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.abilities;
import io.github.retrooper.packetevents.annotations.Nullable;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
public final class WrappedPacketInAbilities extends WrappedPacket {
private static Class<?> abilitiesClass;
static {
try {
abilitiesClass = NMSUtils.getNMSClass("PacketPlayInAbilities");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
private static boolean isMoreThanOneBoolPresent;
private boolean isVulnerable;
private boolean isFlying;
private boolean allowFly;
private boolean instantBuild;
private float flySpeed;
private float walkSpeed;
public WrappedPacketInAbilities(Object packet) {
super(packet);
}
public static void load() {
abilitiesClass = PacketTypeClasses.Client.ABILITIES;
isMoreThanOneBoolPresent = Reflection.getField(abilitiesClass, boolean.class, 1) != null;
}
@Override
protected void setup() {
try {
this.isVulnerable = Reflection.getField(abilitiesClass, boolean.class, 0).getBoolean(packet);
this.isFlying = Reflection.getField(abilitiesClass, boolean.class, 1).getBoolean(packet);
this.allowFly = Reflection.getField(abilitiesClass, boolean.class, 2).getBoolean(packet);
this.instantBuild = Reflection.getField(abilitiesClass, boolean.class, 3).getBoolean(packet);
this.flySpeed = Reflection.getField(abilitiesClass, float.class, 0).getFloat(packet);
this.walkSpeed = Reflection.getField(abilitiesClass, float.class, 1).getFloat(packet);
if (isMoreThanOneBoolPresent) {
this.isVulnerable = Reflection.getField(abilitiesClass, boolean.class, 0).getBoolean(packet);
this.isFlying = Reflection.getField(abilitiesClass, boolean.class, 1).getBoolean(packet);
this.allowFly = Reflection.getField(abilitiesClass, boolean.class, 2).getBoolean(packet);
this.instantBuild = Reflection.getField(abilitiesClass, boolean.class, 3).getBoolean(packet);
this.flySpeed = Reflection.getField(abilitiesClass, float.class, 0).getFloat(packet);
this.walkSpeed = Reflection.getField(abilitiesClass, float.class, 1).getFloat(packet);
} else {
this.isFlying = Reflection.getField(abilitiesClass, boolean.class, 0).getBoolean(packet);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
public boolean isVulnerable() {
/**
* This will return null if the server version is not available in 1.16.x and above
*
* @return Whether the player is vulnerable to damage or not.
*/
@Deprecated
@Nullable
public Boolean isVulnerable() {
return isVulnerable;
}
@@ -49,19 +80,47 @@ public final class WrappedPacketInAbilities extends WrappedPacket {
return isFlying;
}
public boolean isFlightAllowed() {
/**
* This will return null if the server version is not available in 1.16.x and above
*
* @return Whether or not the player can fly.
*/
@Deprecated
@Nullable
public Boolean isFlightAllowed() {
return allowFly;
}
public boolean canInstantlyBuild() {
/**
* This will return null if the server version is not available in 1.16.x and above
*
* @return Whether or not the player can break blocks instantly.
*/
@Deprecated
@Nullable
public Boolean canInstantlyBuild() {
return instantBuild;
}
public float getFlySpeed() {
/**
* This will return null if the server version is not available in 1.16.x and above
*
* @return The speed at which the player can fly, as a float.
*/
@Deprecated
@Nullable
public Float getFlySpeed() {
return flySpeed;
}
public float getWalkSpeed() {
/**
* This will return null if the server version is not available in 1.16.x and above
*
* @return The speed at which the player can walk, as a float.
*/
@Deprecated
@Nullable
public Float getWalkSpeed() {
return walkSpeed;
}
}
@@ -1,36 +1,46 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.armanimation;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
//TODO: Test on 1.9, 1.11, 1.13, 1.14
public final class WrappedPacketInArmAnimation extends WrappedPacket {
private static Class<?> packetClass;
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayInArmAnimation");
} catch (Exception e) {
e.printStackTrace();
}
}
private long timeStamp;
public WrappedPacketInArmAnimation(Object packet) {
super(packet);
}
@Override
public void setup() {
//Lazy way, do you really need to get the timestamp in the actual class? Edit by Retrooper: Yes lol
//TODO: Get EnumHand value sent in 1.9+, however not really necessary
timeStamp = System.currentTimeMillis();
public static void load() {
packetClass = PacketTypeClasses.Client.ARM_ANIMATION;
}
public long getTimestamp() {
return timeStamp;
@Override
public void setup() {
}
}
@@ -1,8 +1,32 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.blockdig;
import io.github.retrooper.packetevents.enums.Direction;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.enums.minecraft.PlayerDigType;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
@@ -10,11 +34,17 @@ import io.github.retrooper.packetevents.utils.vector.Vector3i;
public final class WrappedPacketInBlockDig extends WrappedPacket {
private static Class<?> blockDigClass, blockPositionClass, enumDirectionClass, digTypeClass;
private static boolean isVersionLowerThan_v_1_8;
private Vector3i blockPosition;
private Direction direction;
private PlayerDigType digType;
public WrappedPacketInBlockDig(Object packet) {
super(packet);
}
static {
public static void load() {
blockDigClass = PacketTypeClasses.Client.BLOCK_DIG;
try {
blockDigClass = NMSUtils.getNMSClass("PacketPlayInBlockDig");
if (version.isHigherThan(ServerVersion.v_1_7_10)) {
blockPositionClass = NMSUtils.getNMSClass("BlockPosition");
enumDirectionClass = NMSUtils.getNMSClass("EnumDirection");
@@ -22,33 +52,31 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
isVersionLowerThan_v_1_8 = version.isLowerThan(ServerVersion.v_1_8);
try {
digTypeClass = NMSUtils.getNMSClass("EnumPlayerDigType");
} catch (ClassNotFoundException e) {
//It is probably a subclass
digTypeClass = Reflection.getSubClass(blockDigClass, "EnumPlayerDigType");
if (version != ServerVersion.v_1_7_10) {
try {
digTypeClass = NMSUtils.getNMSClass("EnumPlayerDigType");
} catch (ClassNotFoundException e) {
//It is probably a subclass
digTypeClass = Reflection.getSubClass(blockDigClass, "EnumPlayerDigType");
}
}
}
private Vector3i blockPosition;
private Direction direction;
private PlayerDigType digType;
public WrappedPacketInBlockDig(Object packet) {
super(packet);
}
@Override
protected void setup() {
Direction enumDirection = null;
PlayerDigType enumDigType = null;
int x = 0, y = 0, z = 0;
//1.7.10
try {
if (version.isLowerThan(ServerVersion.v_1_8)) {
setupCoordinates(blockDigClass, packet);
enumDirection = Direction.get(Reflection.getField(digTypeClass, int.class, 3).getInt(packet));
enumDigType = PlayerDigType.get(Reflection.getField(digTypeClass, int.class, 4).getInt(packet));
if (isVersionLowerThan_v_1_8) {
enumDigType = PlayerDigType.values()[(Reflection.getField(blockDigClass, int.class, 4).getInt(packet))];
x = Reflection.getField(blockDigClass, int.class, 0).getInt(packet);
y = Reflection.getField(blockDigClass, int.class, 1).getInt(packet);
z = Reflection.getField(blockDigClass, int.class, 2).getInt(packet);
enumDirection = null;
} else {
//1.8+
final Object blockPosObj = Reflection.getField(blockDigClass, blockPositionClass, 0).get(packet);
@@ -56,7 +84,9 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
final Object digTypeObj = Reflection.getField(blockDigClass, digTypeClass, 0).get(packet);
Class<?> blockPosSuper = blockPositionClass;
setupCoordinates(blockPosSuper, blockPosObj);
x = Reflection.getField(blockPosSuper, int.class, 0).getInt(blockPosObj);
y = Reflection.getField(blockPosSuper, int.class, 1).getInt(blockPosObj);
z = Reflection.getField(blockPosSuper, int.class, 2).getInt(blockPosObj);
enumDirection = Direction.valueOf(((Enum) enumDirectionObj).name());
enumDigType = PlayerDigType.valueOf(((Enum) digTypeObj).name());
@@ -64,29 +94,76 @@ public final class WrappedPacketInBlockDig extends WrappedPacket {
} catch (IllegalAccessException e) {
e.printStackTrace();
}
this.direction = enumDirection;
this.blockPosition = new Vector3i(x, y, z);
if (enumDirection == null) {
this.direction = Direction.NULL;
} else {
this.direction = enumDirection;
}
this.digType = enumDigType;
}
private void setupCoordinates(final Class<?> cls, final Object object) throws IllegalAccessException {
final int x = Reflection.getField(cls, int.class, 0).getInt(object);
final int y = Reflection.getField(cls, int.class, 1).getInt(object);
final int z = Reflection.getField(cls, int.class, 2).getInt(object);
this.blockPosition = new Vector3i(x, y, z);
/**
* Get X position of the block
* @return Block Position X
*/
public int getBlockPositionX() {
return blockPosition.x;
}
/**
* Get Y position of the block
* @return Block Position Y
*/
public int getBlockPositionY() {
return blockPosition.y;
}
/**
* Get Z position of the block
* @return Block Position Z
*/
public int getBlockPositionZ() {
return blockPosition.z;
}
/**
* Use {@link #getBlockPositionX()}, {@link #getBlockPositionY()}, {@link #getBlockPositionZ()}
* @return Block Position
*/
@Deprecated
public Vector3i getBlockPosition() {
return blockPosition;
}
/**
* Get the direction
* Is Direction.NULL on 1.7.10 FOR NOW
* @return Direction
*/
public Direction getDirection() {
return direction;
}
/**
* Get the PlayerDigType enum sent in this packet.
* @return Dig Type
*/
public PlayerDigType getDigType() {
return digType;
}
public enum PlayerDigType {
START_DESTROY_BLOCK,
ABORT_DESTROY_BLOCK,
STOP_DESTROY_BLOCK,
DROP_ALL_ITEMS,
DROP_ITEM,
RELEASE_USE_ITEM,
SWAP_HELD_ITEMS,
SWAP_ITEM_WITH_OFFHAND,
WRONG_PACKET
}
}
@@ -1,5 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.blockplace;
import io.github.retrooper.packetevents.annotations.Nullable;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.utils.vector.Vector3i;
@@ -9,38 +34,40 @@ import org.bukkit.inventory.ItemStack;
public final class WrappedPacketInBlockPlace extends WrappedPacket {
static {
if (version.isHigherThan(ServerVersion.v_1_7_10)) {
WrappedPacketInBlockPlace_1_8.initStatic();
}
}
private static boolean isHigherThan_v_1_8_8, isHigherThan_v_1_7_10;
private Vector3i blockPosition;
private ItemStack itemStack;
public WrappedPacketInBlockPlace(final Player player, final Object packet) {
super(player, packet);
}
public static void load() {
isHigherThan_v_1_8_8 = version.isHigherThan(ServerVersion.v_1_8_8);
isHigherThan_v_1_7_10 = version.isHigherThan(ServerVersion.v_1_7_10);
if (isHigherThan_v_1_7_10) {
WrappedPacketInBlockPlace_1_8.load();
}
}
@Override
protected void setup() {
//1.7.10
Vector3i position = null;
ItemStack itemStack = null;
try {
if (version.isHigherThan(ServerVersion.v_1_8_8)) {
if (isHigherThan_v_1_8_8) {
final WrappedPacketInBlockPlace_1_9 blockPlace_1_9 = new WrappedPacketInBlockPlace_1_9(getPlayer(), packet);
final Block block = blockPlace_1_9.getBlock();
position = new Vector3i(block.getX(), block.getY(), block.getZ());
itemStack = new ItemStack(block.getType());
} else if (version.isHigherThan(ServerVersion.v_1_7_10)) {
} else if (isHigherThan_v_1_7_10) {
final WrappedPacketInBlockPlace_1_8 blockPlace_1_8 = new WrappedPacketInBlockPlace_1_8(packet);
position = blockPlace_1_8.getBlockPosition();
itemStack = blockPlace_1_8.getItemStack();
} else {
final WrappedPacketInBlockPlace_1_7_10 blockPlace_1_7_10 = new WrappedPacketInBlockPlace_1_7_10(getPlayer(), packet);
position = blockPlace_1_7_10.getBlockPosition();
this.itemStack = blockPlace_1_7_10.getItemStack();
itemStack = blockPlace_1_7_10.getItemStack();
}
} catch (IllegalArgumentException e) {
e.printStackTrace();
@@ -49,14 +76,52 @@ public final class WrappedPacketInBlockPlace extends WrappedPacket {
this.itemStack = itemStack;
}
/**
* Get the player that placed the block
* @return Block placer
*/
public Player getPlayer() {
return this.player;
}
/**
* Get X position of the block
* @return Block Position X
*/
public int getBlockPositionX() {
return blockPosition.x;
}
/**
* Get Y position of the block
* @return Block Position Y
*/
public int getBlockPositionY() {
return blockPosition.y;
}
/**
* Get Z position of the block
* @return Block Position Z
*/
public int getBlockPositionZ() {
return blockPosition.z;
}
/**
* Use {@link #getBlockPositionX()}, {@link #getBlockPositionY()}, {@link #getBlockPositionZ()}
* @return Block Position
*/
@Deprecated
public Vector3i getBlockPosition() {
return blockPosition;
}
/**
* The ItemStack of the placed block.
* @return ItemStack
*/
@Nullable
public ItemStack getItemStack() {
return itemStack;
}
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.blockplace;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
@@ -1,5 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.blockplace;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
@@ -9,7 +34,7 @@ import org.bukkit.inventory.ItemStack;
import java.lang.reflect.InvocationTargetException;
final class WrappedPacketInBlockPlace_1_8 extends WrappedPacket {
private static Class<?> blockPlaceClass, blockPositionClass;
private static Class<?> blockPlaceClass, blockPositionClass, blockPositionSuperClass;
private Vector3i blockPosition;
private ItemStack itemStack;
@@ -17,28 +42,25 @@ final class WrappedPacketInBlockPlace_1_8 extends WrappedPacket {
super(packet);
}
protected static void initStatic() {
protected static void load() {
blockPlaceClass = PacketTypeClasses.Client.BLOCK_PLACE;
try {
blockPlaceClass = NMSUtils.getNMSClass("PacketPlayInBlockPlace");
blockPositionClass = NMSUtils.getNMSClass("BlockPosition");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
blockPositionSuperClass = blockPositionClass.getSuperclass();
}
@Override
protected void setup() {
try {
Object nmsBlockPos = Reflection.getField(blockPlaceClass, blockPositionClass, 1).get(packet);
this.blockPosition = new Vector3i(0, 0, 0);
this.blockPosition.x = (int) Reflection.getMethod(blockPositionSuperClass, "getX", 0).invoke(nmsBlockPos);
this.blockPosition.y = (int) Reflection.getMethod(blockPositionSuperClass, "getY", 0).invoke(nmsBlockPos);
this.blockPosition.z = (int) Reflection.getMethod(blockPositionSuperClass, "getZ", 0).invoke(nmsBlockPos);
final int[] coords = new int[3];
for (int i = 0; i < 3; i++) {
final String s = "get" + (i == 0 ? "X" : i == 1 ? "Y" : "Z");
coords[i] = (int) Reflection.getMethod(blockPositionClass.getSuperclass(), s, 0).invoke(nmsBlockPos);
}
this.blockPosition = new Vector3i(coords[0], coords[1], coords[2]);
this.itemStack = NMSUtils.toBukkitItemStack(Reflection.getField(blockPlaceClass, NMSUtils.nmsItemStackClass, 0).get(packet));
} catch (IllegalAccessException | InvocationTargetException e) {
@@ -46,10 +68,23 @@ final class WrappedPacketInBlockPlace_1_8 extends WrappedPacket {
}
}
@Deprecated
public Vector3i getBlockPosition() {
return blockPosition;
}
public int getBlockPositionX() {
return blockPosition.x;
}
public int getBlockPositionY() {
return blockPosition.y;
}
public int getBlockPositionZ() {
return blockPosition.z;
}
public ItemStack getItemStack() {
return itemStack;
}
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.blockplace;
@@ -1,26 +1,44 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.chat;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
public final class WrappedPacketInChat extends WrappedPacket {
private static Class<?> chatPacketClass;
static {
try {
chatPacketClass = NMSUtils.getNMSClass("PacketPlayInChat");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
private String message;
public WrappedPacketInChat(Object packet) {
super(packet);
}
public static void load() {
chatPacketClass = PacketTypeClasses.Client.CHAT;
}
@Override
protected void setup() {
@@ -32,6 +50,10 @@ public final class WrappedPacketInChat extends WrappedPacket {
}
}
/**
* Get the message.
* @return Chat Message
*/
public String getMessage() {
return message;
}
@@ -1,66 +1,76 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.clientcommand;
import io.github.retrooper.packetevents.annotations.Nullable;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.enums.minecraft.PlayerAction;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
//TODO: Test on 1.9, 1.10, 1.11, 1.13, 1.14
public final class WrappedPacketInClientCommand extends WrappedPacket {
private static Class<?> packetClass;
@Nullable
private static Class<?> enumClientCommandClass;
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayInClientCommand");
if(version.isHigherThan(ServerVersion.v_1_7_10)) {
enumClientCommandClass = Reflection.getSubClass(packetClass, "EnumClientCommand");
}else {
enumClientCommandClass = NMSUtils.getNMSClass("EnumClientCommand");
}
} catch (Exception e) {
e.printStackTrace();
}
}
private ClientCommand clientCommand;
public WrappedPacketInClientCommand(Object packet) {
super(packet);
}
public static void load() {
packetClass = PacketTypeClasses.Client.CLIENT_COMMAND;
try {
enumClientCommandClass = NMSUtils.getNMSClass("EnumClientCommand");
} catch (ClassNotFoundException e) {
//Probably a subclass
enumClientCommandClass = Reflection.getSubClass(packetClass, "EnumClientCommand");
}
}
@Override
public void setup() {
try {
if(version.isLowerThan(ServerVersion.v_1_8)) {
clientCommand = ClientCommand.get(Reflection.getField(enumClientCommandClass, int.class, 1).getInt(packet));
} else {
final Object enumObj = Reflection.getField(packetClass, enumClientCommandClass, 0).get(packet);
this.clientCommand = ClientCommand.valueOf(enumObj.toString());
}
Object enumObj = Reflection.getField(packetClass, enumClientCommandClass, 0).get(packet);
this.clientCommand = ClientCommand.valueOf(enumObj.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Get the Client Command enum sent in the packet
* @return ClientCommand
*/
public ClientCommand getClientCommand() {
return clientCommand;
}
public static enum ClientCommand {
public enum ClientCommand {
PERFORM_RESPAWN,
REQUEST_STATS,
OPEN_INVENTORY_ACHIEVEMENT;
private ClientCommand() {
}
public static ClientCommand get(final int i) {
return values()[i];
}
OPEN_INVENTORY_ACHIEVEMENT
}
}
@@ -1,61 +1,110 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.custompayload;
import io.github.retrooper.packetevents.annotations.Nullable;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
import java.lang.reflect.Field;
public final class WrappedPacketInCustomPayload extends WrappedPacket {
private static Class<?> packetClass, nmsMinecraftKey, nmsPacketDataSerializer;
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayInCustomPayload");
nmsPacketDataSerializer = NMSUtils.getNMSClass("PacketDataSerializer");
} catch (Exception e) {
e.printStackTrace();
}
try{
//Only on 1.13+
nmsMinecraftKey = NMSUtils.getNMSClass("MinecraftKey");
} catch (Exception e) {
//Its okay, this means they are on versions 1.7.10 ~ 1.12.2
}
}
private static boolean strPresentInIndex0;
private String data;
private Object minecraftKey, dataSerializer;
public WrappedPacketInCustomPayload(Object packet) {
super(packet);
}
@Override
public void setup() {
if(Reflection.getField(packetClass, String.class, 0) == null) {
try {
this.minecraftKey = Reflection.getField(packetClass, nmsMinecraftKey, 0).get(packet);
this.dataSerializer = Reflection.getField(packetClass, nmsPacketDataSerializer, 0).get(packet);
} catch (Exception e) {
e.printStackTrace();
}
} else {
try {
this.data = (String)Reflection.getField(packetClass, String.class, 0).get(packet);
this.dataSerializer = Reflection.getField(packetClass, nmsPacketDataSerializer, 0).get(packet);
} catch (Exception e) {
//intentionally empty, allegedly 1.7.10 produces a NPE?
}
public static void load() {
packetClass = PacketTypeClasses.Client.CUSTOM_PAYLOAD;
strPresentInIndex0 = Reflection.getField(packetClass, String.class, 0) != null;
try {
nmsPacketDataSerializer = NMSUtils.getNMSClass("PacketDataSerializer");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
//Only on 1.13+
nmsMinecraftKey = NMSUtils.getNMSClass("MinecraftKey");
} catch (ClassNotFoundException e) {
//Its okay, this means they are on versions 1.7.10 ~ 1.12.2
}
}
@Override
public void setup() {
if (!strPresentInIndex0) {
try {
this.minecraftKey = Reflection.getField(packetClass, nmsMinecraftKey, 0).get(packet);
this.dataSerializer = Reflection.getField(packetClass, nmsPacketDataSerializer, 0).get(packet);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
} else {
Field dataSerializerField = Reflection.getField(packetClass, nmsPacketDataSerializer, 0);
try {
this.data = (String) Reflection.getField(packetClass, String.class, 0).get(packet);
if (dataSerializerField != null) {
this.dataSerializer = dataSerializerField.get(packet);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
}
/**
* Get the data
* @return String data
*/
public String getData() {
return data;
}
/**
* Get the minecraft key
* @return Minecraft Key object
*/
public Object getMinecraftKey() {
return minecraftKey;
}
/**
* Get the data serializer
* @return Data Serializer object
*/
@Nullable
public Object getDataSerializer() {
return dataSerializer;
}
@@ -1,96 +1,152 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.entityaction;
import io.github.retrooper.packetevents.annotations.Nullable;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.enums.minecraft.PlayerAction;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
import org.bukkit.entity.Entity;
import java.util.HashMap;
public final class WrappedPacketInEntityAction extends WrappedPacket {
private static final HashMap<String, PlayerAction> cachedPlayerActionNames = new HashMap<String, PlayerAction>();
private static final HashMap<Integer, PlayerAction> cachedPlayerActionIDs = new HashMap<Integer, PlayerAction>();
private static Class<?> entityActionClass;
@Nullable
private static Class<?> enumPlayerActionClass;
static {
try {
entityActionClass = NMSUtils.getNMSClass("PacketPlayInEntityAction");
if (version.isHigherThan(ServerVersion.v_1_7_10)) {
for (final Class<?> sub : entityActionClass.getDeclaredClasses()) {
if (sub.getSimpleName().equals("EnumPlayerAction")) {
enumPlayerActionClass = sub;
break;
}
}
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
private static boolean isLowerThan_v_1_8;
private Entity entity;
private int entityId;
private PlayerAction action;
private int jumpBoost;
public WrappedPacketInEntityAction(final Object packet) {
super(packet);
}
public static void load() {
entityActionClass = PacketTypeClasses.Client.ENTITY_ACTION;
isLowerThan_v_1_8 = version.isLowerThan(ServerVersion.v_1_8);
if (version.isHigherThan(ServerVersion.v_1_7_10)) {
enumPlayerActionClass = Reflection.getSubClass(entityActionClass, "EnumPlayerAction");
}
//All the already existing values
for (PlayerAction val : PlayerAction.values()) {
cachedPlayerActionNames.put(val.name(), val);
}
cachedPlayerActionNames.put("PRESS_SHIFT_KEY", PlayerAction.START_SNEAKING);
cachedPlayerActionNames.put("RELEASE_SHIFT_KEY", PlayerAction.STOP_SNEAKING);
cachedPlayerActionNames.put("RIDING_JUMP", PlayerAction.START_RIDING_JUMP);
cachedPlayerActionIDs.put(1, PlayerAction.START_SNEAKING);
cachedPlayerActionIDs.put(2, PlayerAction.STOP_SNEAKING);
cachedPlayerActionIDs.put(3, PlayerAction.STOP_SLEEPING);
cachedPlayerActionIDs.put(4, PlayerAction.START_SPRINTING);
cachedPlayerActionIDs.put(5, PlayerAction.STOP_SPRINTING);
cachedPlayerActionIDs.put(6, PlayerAction.START_RIDING_JUMP); //riding jump
cachedPlayerActionIDs.put(7, PlayerAction.OPEN_INVENTORY); //horse interaction
}
@Override
protected void setup() {
try {
final int entityId = Reflection.getField(entityActionClass, int.class, 0).getInt(packet);
final int jumpBoost;
if (version.isLowerThan(ServerVersion.v_1_8)) {
if (isLowerThan_v_1_8) {
jumpBoost = Reflection.getField(entityActionClass, int.class, 2).getInt(packet);
} else {
jumpBoost = Reflection.getField(entityActionClass, int.class, 1).getInt(packet);
}
int animationIndex = -1;
//1.7.10
if (version.isLowerThan(ServerVersion.v_1_8)) {
animationIndex = Reflection.getField(entityActionClass, int.class, 1).getInt(packet); // TODO: += if packetdataserializer.version < 16
if (isLowerThan_v_1_8) {
int animationIndex = Reflection.getField(entityActionClass, int.class, 1).getInt(packet); // TODO: += if packetdataserializer.version < 16
this.action = cachedPlayerActionIDs.get(animationIndex);
} else {
final Object enumObj = Reflection.getField(entityActionClass, enumPlayerActionClass, 0).get(packet);
final String enumValue = enumObj.toString();
try {
this.action = PlayerAction.valueOf(enumValue);
} catch (IllegalArgumentException e) {
//They aren't on a legacy version and the enum has changed
final PlayerAction.UpdatedPlayerAction updatedPlayerAction = PlayerAction.UpdatedPlayerAction.valueOf(enumValue);
this.action = PlayerAction.get(updatedPlayerAction.getIndex());
}
final String enumName = enumObj.toString();
this.action = cachedPlayerActionNames.get(enumName);
}
this.entityId = entityId;
this.jumpBoost = jumpBoost;
if (animationIndex != -1) {
this.action = PlayerAction.get(animationIndex);
}
this.entity = NMSUtils.getEntityById(this.entityId);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
/**
* Lookup the associated entity by the ID that was sent in the packet.
* @return Entity
*/
public Entity getEntity() {
return entity;
return NMSUtils.getEntityById(this.entityId);
}
/**
* Get the ID of the entity.
* If you do not want to use {@link #getEntity()},
* you lookup the entity by yourself with this entity ID.
* @return Entity ID
*/
public int getEntityId() {
return entityId;
}
/**
* Get the player action.
* @return Player Action
*/
public PlayerAction getAction() {
return action;
}
/**
* Get the jump boost integer.
* @return Jump Boost
*/
public int getJumpBoost() {
return jumpBoost;
}
public enum PlayerAction {
START_SNEAKING,
STOP_SNEAKING,
STOP_SLEEPING,
START_SPRINTING,
STOP_SPRINTING,
START_RIDING_JUMP,
STOP_RIDING_JUMP,
OPEN_INVENTORY,
START_FALL_FLYING
}
}
@@ -1,35 +1,52 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.flying;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
public class WrappedPacketInFlying extends WrappedPacket {
private static Class<?> flyingClass;
static {
try {
flyingClass = NMSUtils.getNMSClass("PacketPlayInFlying");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
private double x;
private double y;
private double z;
private float yaw;
private float pitch;
private boolean onGround;
private boolean isPosition;
private boolean isLook;
protected double x;
protected double y;
protected double z;
protected float yaw;
protected float pitch;
protected boolean onGround;
protected boolean isPosition;
protected boolean isLook;
public WrappedPacketInFlying(Object packet) {
super(packet);
}
public static void load() {
flyingClass = PacketTypeClasses.Client.FLYING;
}
@Override
protected void setup() {
try {
@@ -74,63 +91,63 @@ public class WrappedPacketInFlying extends WrappedPacket {
return onGround;
}
public boolean isPosition() {
public final boolean isPosition() {
return isPosition;
}
public boolean isLook() {
public final boolean isLook() {
return isLook;
}
public static class WrappedPacketInPosition extends WrappedPacketInFlying {
public WrappedPacketInPosition(Object packet) {
super(packet);
}
@Override
public boolean isPosition() {
protected void setup() {
try {
return Reflection.getField(flyingClass, boolean.class, 1).getBoolean(packet);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return true;
}
this.x = Reflection.getField(flyingClass, double.class, 0).getDouble(packet);
this.y = Reflection.getField(flyingClass, double.class, 1).getDouble(packet);
this.z = Reflection.getField(flyingClass, double.class, 2).getDouble(packet);
@Override
public boolean isLook() {
try {
return Reflection.getField(flyingClass, boolean.class, 2).getBoolean(packet);
this.yaw = Reflection.getField(flyingClass, float.class, 0).getFloat(packet);
this.pitch = Reflection.getField(flyingClass, float.class, 1).getFloat(packet);
this.onGround = Reflection.getField(flyingClass, boolean.class, 0).getBoolean(packet);
this.isPosition = Reflection.getField(flyingClass, boolean.class, 1).getBoolean(packet);
this.isLook = Reflection.getField(flyingClass, boolean.class, 2).getBoolean(packet);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return false;
}
}
public static class WrappedPacketInPosition_Look extends WrappedPacketInFlying {
public WrappedPacketInPosition_Look(Object packet) {
super(packet);
}
@Override
public boolean isPosition() {
protected void setup() {
try {
return Reflection.getField(flyingClass, boolean.class, 1).getBoolean(packet);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return true;
}
this.x = Reflection.getField(flyingClass, double.class, 0).getDouble(packet);
this.y = Reflection.getField(flyingClass, double.class, 1).getDouble(packet);
this.z = Reflection.getField(flyingClass, double.class, 2).getDouble(packet);
@Override
public boolean isLook() {
try {
return Reflection.getField(flyingClass, boolean.class, 2).getBoolean(packet);
this.yaw = Reflection.getField(flyingClass, float.class, 0).getFloat(packet);
this.pitch = Reflection.getField(flyingClass, float.class, 1).getFloat(packet);
this.onGround = Reflection.getField(flyingClass, boolean.class, 0).getBoolean(packet);
this.isPosition = Reflection.getField(flyingClass, boolean.class, 1).getBoolean(packet);
this.isLook = Reflection.getField(flyingClass, boolean.class, 2).getBoolean(packet);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return true;
}
}
@@ -141,23 +158,22 @@ public class WrappedPacketInFlying extends WrappedPacket {
}
@Override
public boolean isPosition() {
protected void setup() {
try {
return Reflection.getField(flyingClass, boolean.class, 1).getBoolean(packet);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return false;
}
this.x = Reflection.getField(flyingClass, double.class, 0).getDouble(packet);
this.y = Reflection.getField(flyingClass, double.class, 1).getDouble(packet);
this.z = Reflection.getField(flyingClass, double.class, 2).getDouble(packet);
@Override
public boolean isLook() {
try {
return Reflection.getField(flyingClass, boolean.class, 2).getBoolean(packet);
this.yaw = Reflection.getField(flyingClass, float.class, 0).getFloat(packet);
this.pitch = Reflection.getField(flyingClass, float.class, 1).getFloat(packet);
this.onGround = Reflection.getField(flyingClass, boolean.class, 0).getBoolean(packet);
this.isPosition = Reflection.getField(flyingClass, boolean.class, 1).getBoolean(packet);
this.isLook = Reflection.getField(flyingClass, boolean.class, 2).getBoolean(packet);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return true;
}
}
@@ -1,26 +1,45 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.helditemslot;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
public final class WrappedPacketInHeldItemSlot extends WrappedPacket {
private static Class<?> packetClass;
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayInHeldItemSlot");
} catch (Exception e) {
e.printStackTrace();
}
}
private int itemInHandIndex;
public WrappedPacketInHeldItemSlot(Object packet) {
super(packet);
}
public static void load() {
packetClass = PacketTypeClasses.Client.HELD_ITEM_SLOT;
}
@Override
public void setup() {
try {
@@ -30,6 +49,10 @@ public final class WrappedPacketInHeldItemSlot extends WrappedPacket {
}
}
/**
* Get the index of the item we currently have in hand.
* @return Item in hand Index
*/
public int getItemInHandIndex() {
return itemInHandIndex;
}
@@ -1,29 +1,50 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.keepalive;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
public final class WrappedPacketInKeepAlive extends WrappedPacket {
private static Class<?> packetClass;
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayInKeepAlive");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
private static boolean integerPresentInIndex0;
private long id;
public WrappedPacketInKeepAlive(final Object packet) {
super(packet);
}
public static void load() {
packetClass = PacketTypeClasses.Client.KEEP_ALIVE;
integerPresentInIndex0 = Reflection.getField(packetClass, int.class, 0) != null;
}
@Override
protected void setup() {
if (Reflection.getField(packetClass, int.class, 0) == null) {
if (!integerPresentInIndex0) {
try {
this.id = Reflection.getField(packetClass, long.class, 0).getLong(packet);
} catch (IllegalAccessException e) {
@@ -39,10 +60,11 @@ public final class WrappedPacketInKeepAlive extends WrappedPacket {
}
/**
* Optionally Cast this long to an integer if you are using 1.7.10->1.12.2!
* In 1.13.2->1.16.1 a long is sent
* Get the ID response from the client.
*
* @return response is
* You may cast this down to an int if you are on 1.7.10 - 1.12.2.
* On 1.13.2 - 1.16.2 a long is sent.
* @return response ID
*/
public long getId() {
return id;
@@ -0,0 +1,191 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.settings;
import io.github.retrooper.packetevents.annotations.Nullable;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
import java.util.HashMap;
public class WrappedPacketInSettings extends WrappedPacket {
private static Class<?> packetClass;
private static Class<?> chatVisibilityEnumClass;
private static boolean isLowerThan_v_1_8;
private String locale;
private byte viewDistance;
private ChatVisibility chatVisibility;
private boolean chatColors;
private HashMap<DisplayedSkinPart, Boolean> displayedSkinParts;
public WrappedPacketInSettings(final Object packet) {
super(packet);
}
public static void load() {
packetClass = PacketTypeClasses.Client.SETTINGS;
isLowerThan_v_1_8 = version.isLowerThan(ServerVersion.v_1_8);
try {
chatVisibilityEnumClass = NMSUtils.getNMSClass("EnumChatVisibility");
} catch (ClassNotFoundException e) {
Class<?> entityHumanClass = NMSUtils.getNMSClassWithoutException("EntityHuman");
//They are just on an outdated version
chatVisibilityEnumClass = Reflection.getSubClass(entityHumanClass, "EnumChatVisibility");
}
}
public static Class<?> getChatVisibilityEnumClass() {
return chatVisibilityEnumClass;
}
@Override
protected void setup() {
try {
//LOCALE
this.locale = Reflection.getField(packetClass, String.class, 0).get(packet).toString();
//VIEW DISTANCE
this.viewDistance = (byte) Reflection.getField(packetClass, int.class, 0).getInt(packet);
//CHAT VISIBILITY
Object chatVisibilityEnumObject = Reflection.getField(packetClass, chatVisibilityEnumClass, 0).get(packet);
String enumValueAsString = chatVisibilityEnumObject.toString();
if (enumValueAsString.equals("FULL")) {
chatVisibility = ChatVisibility.ENABLED;
} else if (enumValueAsString.equals("SYSTEM")) {
chatVisibility = ChatVisibility.COMMANDS_ONLY;
} else {
chatVisibility = ChatVisibility.HIDDEN;
}
//CHAT COLORS
this.chatColors = Reflection.getField(packetClass, boolean.class, 0).getBoolean(packet);
//DISPLAYED SKIN PARTS
this.displayedSkinParts = new HashMap<DisplayedSkinPart, Boolean>();
if (isLowerThan_v_1_8) {
//in 1.7.10 only the cape display skin part is sent
boolean capeEnabled = Reflection.getField(packetClass, boolean.class, 1).getBoolean(packet);
displayedSkinParts.put(DisplayedSkinPart.CAPE, capeEnabled);
} else {
//in 1.8, all the skin parts are sent
int skinPartFlags = Reflection.getField(packetClass, int.class, 1).getInt(packet);
displayedSkinParts.put(DisplayedSkinPart.CAPE, (skinPartFlags & 0x01) != 0);
displayedSkinParts.put(DisplayedSkinPart.JACKET, (skinPartFlags & 0x02) != 0);
displayedSkinParts.put(DisplayedSkinPart.LEFT_SLEEVE, (skinPartFlags & 0x04) != 0);
displayedSkinParts.put(DisplayedSkinPart.RIGHT_SLEEVE, (skinPartFlags & 0x08) != 0);
displayedSkinParts.put(DisplayedSkinPart.LEFT_PANTS, (skinPartFlags & 0x10) != 0);
displayedSkinParts.put(DisplayedSkinPart.RIGHT_PANTS, (skinPartFlags & 0x20) != 0);
displayedSkinParts.put(DisplayedSkinPart.HAT, (skinPartFlags & 0x40) != 0);
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Get language client setting
* @return String Locale
*/
public String getLocale() {
return locale;
}
/**
* Get client view distance.
* @return View Distance
*/
public byte getViewDistance() {
return viewDistance;
}
/**
* Get Chat Visibility
* @return Chat Visibility
*/
public ChatVisibility getChatVisibility() {
return chatVisibility;
}
/**
* Is chat colors
* @return Chat Colors
*/
public boolean isChatColors() {
return chatColors;
}
/**
* Get Displayed skin parts.
*
* It is possible for some keys to not exist.
* If that is the case, the server version is 1.7.10.
* 1.7.10 only sends the cape skin part.
*
* @return A map with a Skin Parts as a key, and a boolean as a value.
*/
@Nullable
public HashMap<DisplayedSkinPart, Boolean> getDisplayedSkinPartsMap() {
return displayedSkinParts;
}
/**
* Is the skin part enabled.
*
* On 1.7.10, some skin parts will default to 'false' as 1.7.10
* only sends the 'cape' skin part.
*
* @param part The skin part to check the status of.
* @return Is the skin part enabled
*/
public boolean isDisplaySkinPartEnabled(DisplayedSkinPart part) {
//1.7.10, we will default the other skin parts to return false.
if (!displayedSkinParts.containsKey(part)) {
return false;
}
return displayedSkinParts.get(part);
}
/**
* Enum for the client chat visibility setting
*/
public enum ChatVisibility {
ENABLED, COMMANDS_ONLY, HIDDEN
}
/**
* Enum for the client displayed skin parts settings
*/
public enum DisplayedSkinPart {
CAPE, JACKET, LEFT_SLEEVE, RIGHT_SLEEVE, LEFT_PANTS, RIGHT_PANTS, HAT
}
}
@@ -1,27 +1,45 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.steervehicle;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
public class WrappedPacketInSteerVehicle extends WrappedPacket {
private static Class<?> packetClass;
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayInSteerVehicle");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
private float side, forward;
private boolean jump, unmount;
public WrappedPacketInSteerVehicle(Object packet) {
super(packet);
}
public static void load() {
packetClass = PacketTypeClasses.Client.STEER_VEHICLE;
}
@Override
protected void setup() {
try {
@@ -35,20 +53,38 @@ public class WrappedPacketInSteerVehicle extends WrappedPacket {
}
}
//Positive side value means left, negative means right
/**
* Get the side value.
*
* If positive, they are moving to the left, if negative, they are moving to the right.
* @return Side Value
*/
public float getSideValue() {
return side;
}
//Positive forward value means forward, negative is backwards
/**
* Get the forward value.
*
* If positive, they are moving forward, if negative, they are moving backwards.
* @return Forward Value
*/
public float getForwardValue() {
return forward;
}
/**
* Is a Jump
* @return Is Jump
*/
public boolean isJump() {
return jump;
}
/**
* Is an unmount
* @return Is Unmounting
*/
public boolean isUnmount() {
return unmount;
}
@@ -1,28 +1,46 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.transaction;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
public final class WrappedPacketInTransaction extends WrappedPacket {
private static Class<?> packetClass;
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayInTransaction");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
private int windowId;
private short actionNumber;
private boolean accepted;
public WrappedPacketInTransaction(final Object packet) {
super(packet);
}
public static void load() {
packetClass = PacketTypeClasses.Client.TRANSACTION;
}
@Override
protected void setup() {
try {
@@ -35,14 +53,26 @@ public final class WrappedPacketInTransaction extends WrappedPacket {
}
/**
* Get the window ID.
* @return Window ID
*/
public int getWindowId() {
return windowId;
}
/**
* Get the action number.
* @return Action number
*/
public short getActionNumber() {
return actionNumber;
}
/**
* Is transaction accepted.
* @return Transaction Accepted
*/
public boolean isAccepted() {
return accepted;
}
@@ -1,49 +1,59 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.useentity;
import io.github.retrooper.packetevents.enums.minecraft.EntityUseAction;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
import org.bukkit.entity.Entity;
public final class WrappedPacketInUseEntity extends WrappedPacket {
private static Class<?> useEntityClass, entityClass, enumEntityUseActionClass;
private static Class<?> useEntityClass;
private static Class<?> enumEntityUseActionClass;
private int entityID;
private EntityUseAction action;
public WrappedPacketInUseEntity(final Object packet) {
super(packet);
}
static {
try {
useEntityClass = NMSUtils.getNMSClass("PacketPlayInUseEntity");
entityClass = NMSUtils.getNMSClass("Entity");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
public static void load() {
useEntityClass = PacketTypeClasses.Client.USE_ENTITY;
try {
enumEntityUseActionClass = NMSUtils.getNMSClass("EnumEntityUseAction");
} catch (ClassNotFoundException e) {
//That is fine, it is probably a subclass
for (final Class<?> sub : useEntityClass.getDeclaredClasses()) {
if (sub.getSimpleName().equals("EnumEntityUseAction")) {
enumEntityUseActionClass = sub;
break;
}
}
enumEntityUseActionClass = Reflection.getSubClass(useEntityClass, "EnumEntityUseAction");
}
}
private int entityId;
private Entity entity;
private EntityUseAction action;
public WrappedPacketInUseEntity(final Object packet) {
super(packet);
}
@Override
protected void setup() {
try {
this.entityId = Reflection.getField(useEntityClass, int.class, 0).getInt(packet);
this.entity = NMSUtils.getEntityById(this.entityId);
this.entityID = Reflection.getField(useEntityClass, int.class, 0).getInt(packet);
final Object useActionEnum = Reflection.getField(useEntityClass, enumEntityUseActionClass, 0).get(packet);
this.action = EntityUseAction.valueOf(useActionEnum.toString());
} catch (IllegalAccessException e) {
@@ -51,15 +61,33 @@ public final class WrappedPacketInUseEntity extends WrappedPacket {
}
}
/**
* Lookup the associated entity by the ID that was sent in the packet.
* @return Entity
*/
public Entity getEntity() {
return entity;
return NMSUtils.getEntityById(this.entityID);
}
/**
* Get the ID of the entity.
* If you do not want to use {@link #getEntity()},
* you lookup the entity by yourself with this entity ID.
* @return Entity ID
*/
public int getEntityId() {
return entityId;
return entityID;
}
/**
* Get the associated action.
* @return Get EntityUseAction
*/
public EntityUseAction getAction() {
return action;
}
public enum EntityUseAction {
INTERACT, INTERACT_AT, ATTACK, INVALID
}
}
@@ -0,0 +1,236 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.in.windowclick;
import io.github.retrooper.packetevents.annotations.Nullable;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
public class WrappedPacketInWindowClick extends WrappedPacket {
private static final HashMap<String, Integer> invClickTypeMapCache = new HashMap<String, Integer>();
private static final HashMap<Integer, ArrayList<WindowClickType>> windowClickTypeCache = new HashMap<Integer, ArrayList<WindowClickType>>();
private static Class<?> packetClass, invClickTypeClass;
private static boolean isClickModePrimitive = false;
private int id;
private int slot;
private int button;
private short actionNumber;
private int mode;
private ItemStack clickedItem;
public WrappedPacketInWindowClick(Object packet) {
super(packet);
}
public static void load() {
packetClass = PacketTypeClasses.Client.WINDOW_CLICK;
invClickTypeClass = NMSUtils.getNMSClassWithoutException("InventoryClickType");
invClickTypeMapCache.put("PICKUP", 0);
invClickTypeMapCache.put("QUICK_MOVE", 1);
invClickTypeMapCache.put("SWAP", 2);
invClickTypeMapCache.put("CLONE", 3);
invClickTypeMapCache.put("THROW", 4);
invClickTypeMapCache.put("QUICK_CRAFT", 5);
invClickTypeMapCache.put("PICKUP_ALL", 6);
//MODE 0
windowClickTypeCache.put(0, getArrayListOfWindowClickTypes(WindowClickType.LEFT_MOUSE_CLICK,
WindowClickType.RIGHT_MOUSE_CLICK));
//MODE 1
windowClickTypeCache.put(1, getArrayListOfWindowClickTypes(WindowClickType.SHIFT_LEFT_MOUSE_CLICK,
WindowClickType.SHIFT_RIGHT_MOUSE_CLICK));
//MODE 2
windowClickTypeCache.put(2, getArrayListOfWindowClickTypes(
WindowClickType.KEY_NUMBER1,
WindowClickType.KEY_NUMBER2,
WindowClickType.KEY_NUMBER3,
WindowClickType.KEY_NUMBER4,
WindowClickType.KEY_NUMBER5,
WindowClickType.KEY_NUMBER6,
WindowClickType.KEY_NUMBER7,
WindowClickType.KEY_NUMBER8,
WindowClickType.KEY_NUMBER9));
//MODE 3
windowClickTypeCache.put(3, getArrayListOfWindowClickTypes(WindowClickType.UNKNOWN, WindowClickType.UNKNOWN, WindowClickType.CREATIVE_MIDDLE_CLICK));
//MODE 4
windowClickTypeCache.put(4, getArrayListOfWindowClickTypes(WindowClickType.KEY_DROP,
WindowClickType.KEY_DROP_STACK));
//MODE 5
windowClickTypeCache.put(5, getArrayListOfWindowClickTypes(
WindowClickType.STARTING_LEFT_MOUSE_DRAG,
WindowClickType.ADD_SLOT_LEFT_MOUSE_DRAG,
WindowClickType.ENDING_LEFT_MOUSE_DRAG,
WindowClickType.UNKNOWN,
WindowClickType.STARTING_RIGHT_MOUSE_DRAG,
WindowClickType.ADD_SLOT_RIGHT_MOUSE_DRAG,
WindowClickType.CREATIVE_STARTING_MIDDLE_MOUSE_DRAG,
WindowClickType.ADD_SLOT_MIDDLE_MOUSE_DRAG,
WindowClickType.ENDING_MIDDLE_MOUSE_DRAG));
windowClickTypeCache.put(6, getArrayListOfWindowClickTypes(WindowClickType.DOUBLE_CLICK));
isClickModePrimitive = Reflection.getField(packetClass, int.class, 3) != null;
}
private static ArrayList<WindowClickType> getArrayListOfWindowClickTypes(WindowClickType... types) {
ArrayList<WindowClickType> arrayList = new ArrayList<WindowClickType>(types.length);
arrayList.addAll(Arrays.asList(types));
return arrayList;
}
@Override
protected void setup() {
try {
this.id = Reflection.getField(packetClass, int.class, 0).getInt(packet);
this.slot = Reflection.getField(packetClass, int.class, 1).getInt(packet);
this.button = Reflection.getField(packetClass, int.class, 2).getInt(packet);
this.actionNumber = Reflection.getField(packetClass, short.class, 0).getShort(packet);
Object nmsItemStack = Reflection.getField(packetClass, NMSUtils.nmsItemStackClass, 0).get(packet);
this.clickedItem = NMSUtils.toBukkitItemStack(nmsItemStack);
Object clickMode = Reflection.getField(packetClass, 5).get(packet);
if (isClickModePrimitive) {
mode = (int) clickMode;
} else {
mode = invClickTypeMapCache.get(clickMode.toString());
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
/**
* Get the Window ID.
* @return Get Window ID
*/
public int getWindowID() {
return id;
}
/**
* Get the Window slot.
* @return Get Window Slot
*/
public int getWindowSlot() {
return slot;
}
/**
* Get the Window button.
* @return Get Window Button
*/
public int getWindowButton() {
return button;
}
/**
* Get the action number.
* @return Get Action Number
*/
public short getActionNumber() {
return actionNumber;
}
/**
* Get the window click type.
* @return Get Window Click Type
*/
public WindowClickType getWindowClickType() {
if (windowClickTypeCache.get(mode) == null) {
return WindowClickType.UNKNOWN;
}
if (button + 1 > windowClickTypeCache.size()) {
return WindowClickType.UNKNOWN;
}
if (mode == 4) {
if (slot == -999) {
if (button == 0) {
return WindowClickType.LEFT_CLICK_OUTSIDE_WINDOW_HOLDING_NOTHING;
} else if (button == 1) {
return WindowClickType.RIGHT_CLICK_OUTSIDE_WINDOW_HOLDING_NOTHING;
}
}
}
return windowClickTypeCache.get(mode).get(button);
}
/**
* Get the Window mode.
* @return Get Window Mode.
*/
public int getMode() {
return mode;
}
/**
* Get the clicked item.
* @return Get Clicked ItemStack
*/
public ItemStack getClickedItem() {
return clickedItem;
}
public enum WindowClickType {
LEFT_MOUSE_CLICK, RIGHT_MOUSE_CLICK,
SHIFT_LEFT_MOUSE_CLICK, SHIFT_RIGHT_MOUSE_CLICK,
CREATIVE_MIDDLE_CLICK, CREATIVE_STARTING_MIDDLE_MOUSE_DRAG,
KEY_NUMBER1, KEY_NUMBER2, KEY_NUMBER3, KEY_NUMBER4,
KEY_NUMBER5, KEY_NUMBER6, KEY_NUMBER7, KEY_NUMBER8,
KEY_NUMBER9, KEY_DROP, KEY_DROP_STACK,
LEFT_CLICK_OUTSIDE_WINDOW_HOLDING_NOTHING,
RIGHT_CLICK_OUTSIDE_WINDOW_HOLDING_NOTHING,
STARTING_LEFT_MOUSE_DRAG,
STARTING_RIGHT_MOUSE_DRAG,
ADD_SLOT_LEFT_MOUSE_DRAG,
ADD_SLOT_RIGHT_MOUSE_DRAG,
ADD_SLOT_MIDDLE_MOUSE_DRAG,
ENDING_LEFT_MOUSE_DRAG,
ENDING_RIGHT_MOUSE_DRAG,
ENDING_MIDDLE_MOUSE_DRAG,
DOUBLE_CLICK,
UNKNOWN
}
}
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.out.abilities;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
@@ -1,9 +1,33 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.out.abilities;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.Sendable;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -11,31 +35,15 @@ import java.lang.reflect.InvocationTargetException;
public final class WrappedPacketOutAbilities extends WrappedPacket implements Sendable {
private static Class<?> packetClass;
private static Constructor<?> packetConstructor;
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayOutAbilities");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
packetConstructor = packetClass.getConstructor(PlayerAbilitiesUtils.playerAbilitiesClass);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
private boolean vulnerable, flying, allowFlight, instantBuild;
private float flySpeed, walkSpeed;
public WrappedPacketOutAbilities(final Object packet) {
super(packet);
}
public WrappedPacketOutAbilities(final boolean isVulnerable, final boolean isFlying, final boolean allowFlight, final boolean canBuildInstantly,
final float flySpeed, final float walkSpeed) {
super(null);
super();
this.vulnerable = isVulnerable;
this.flying = isFlying;
this.allowFlight = allowFlight;
@@ -44,6 +52,16 @@ public final class WrappedPacketOutAbilities extends WrappedPacket implements Se
this.walkSpeed = walkSpeed;
}
public static void load() {
packetClass = PacketTypeClasses.Server.ABILITIES;
try {
packetConstructor = packetClass.getConstructor(PlayerAbilitiesUtils.playerAbilitiesClass);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
@Override
protected void setup() {
try {
@@ -60,26 +78,50 @@ public final class WrappedPacketOutAbilities extends WrappedPacket implements Se
}
/**
* Should the client be vulnerable?
* @return Is Vulnerable
*/
public boolean isVulnerable() {
return vulnerable;
}
/**
* Should the client be flying?
* @return Is Flying
*/
public boolean isFlying() {
return flying;
}
/**
* Should the client be allowed to fly?
* @return Is Allowed To Fly
*/
public boolean isFlightAllowed() {
return allowFlight;
}
/**
* Should the client be able to build instantly?
* @return Is Allowed To Build Instantly
*/
public boolean canInstantlyBuild() {
return instantBuild;
}
/**
* Get the client's defined fly speed.
* @return Get Fly Speed
*/
public float getFlySpeed() {
return flySpeed;
}
/**
* Get the client's defined walk speed.
* @return Get Walk Speed
*/
public float getWalkSpeed() {
return walkSpeed;
}
@@ -1,6 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.out.animation;
import io.github.retrooper.packetevents.enums.minecraft.EntityAnimationType;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.Sendable;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
@@ -9,14 +33,31 @@ import org.bukkit.entity.Entity;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
public final class WrappedPacketOutAnimation extends WrappedPacket implements Sendable {
private static Class<?> animationClass, nmsEntityClass;
private static Constructor<?> animationConstructor;
static {
private static final HashMap<Integer, EntityAnimationType> cachedAnimationIDS = new HashMap<Integer, EntityAnimationType>();
private static final HashMap<EntityAnimationType, Integer> cachedAnimations = new HashMap<EntityAnimationType, Integer>();
private Entity entity;
private int entityID;
private EntityAnimationType type;
public WrappedPacketOutAnimation(final Object packet) {
super(packet);
}
public WrappedPacketOutAnimation(final Entity target, final EntityAnimationType type) {
super();
this.entityID = target.getEntityId();
this.entity = target;
this.type = type;
}
public static void load() {
animationClass = PacketTypeClasses.Server.ANIMATION;
try {
animationClass = NMSUtils.getNMSClass("PacketPlayOutAnimation");
nmsEntityClass = NMSUtils.getNMSClass("Entity");
} catch (ClassNotFoundException e) {
e.printStackTrace();
@@ -27,21 +68,19 @@ public final class WrappedPacketOutAnimation extends WrappedPacket implements Se
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
cachedAnimationIDS.put(0, EntityAnimationType.SWING_MAIN_ARM);
cachedAnimationIDS.put(1, EntityAnimationType.TAKE_DAMAGE);
cachedAnimationIDS.put(2, EntityAnimationType.LEAVE_BED);
cachedAnimationIDS.put(3, EntityAnimationType.SWING_OFFHAND);
cachedAnimationIDS.put(4, EntityAnimationType.CRITICAL_EFFECT);
cachedAnimationIDS.put(5, EntityAnimationType.MAGIC_CRITICAL_EFFECT);
private Entity entity;
private int entityID;
private EntityAnimationType type;
public WrappedPacketOutAnimation(final Object packet) {
super(packet);
}
public WrappedPacketOutAnimation(final Entity target, final EntityAnimationType type) {
super(null);
this.entityID = target.getEntityId();
this.entity = target;
this.type = type;
cachedAnimations.put(EntityAnimationType.SWING_MAIN_ARM, 0);
cachedAnimations.put(EntityAnimationType.TAKE_DAMAGE, 1);
cachedAnimations.put(EntityAnimationType.LEAVE_BED, 2);
cachedAnimations.put(EntityAnimationType.SWING_OFFHAND, 3);
cachedAnimations.put(EntityAnimationType.CRITICAL_EFFECT, 4);
cachedAnimations.put(EntityAnimationType.MAGIC_CRITICAL_EFFECT, 5);
}
@Override
@@ -50,22 +89,36 @@ public final class WrappedPacketOutAnimation extends WrappedPacket implements Se
//a - ID
//b - TYPE
this.entityID = Reflection.getField(animationClass, int.class, 0).getInt(packet);
this.entity = NMSUtils.getEntityById(this.entityID);
this.type = EntityAnimationType.get(Reflection.getField(animationClass, int.class, 1).getInt(packet));
int animationID = Reflection.getField(animationClass, int.class, 1).getInt(packet);
this.type = cachedAnimationIDS.get(animationID);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
/**
* Lookup the associated entity by the ID that was sent in the packet.
* @return Entity
*/
public Entity getEntity() {
return this.entity;
return NMSUtils.getEntityById(this.entityID);
}
/**
* Get the ID of the entity.
* If you do not want to use {@link #getEntity()},
* you lookup the entity by yourself with this entity ID.
* @return Entity ID
*/
public int getEntityId() {
return this.entityID;
return entityID;
}
/**
* Get the entity animation type.
* @return Get Entity Animation Type
*/
public EntityAnimationType getAnimationType() {
return type;
}
@@ -73,7 +126,7 @@ public final class WrappedPacketOutAnimation extends WrappedPacket implements Se
@Override
public Object asNMSPacket() {
final Object nmsEntity = NMSUtils.getNMSEntity(this.entity);
final int index = type.getIndex();
final int index = cachedAnimations.get(type);
try {
return animationConstructor.newInstance(nmsEntity, index);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
@@ -81,4 +134,8 @@ public final class WrappedPacketOutAnimation extends WrappedPacket implements Se
}
return null;
}
public enum EntityAnimationType {
SWING_MAIN_ARM, TAKE_DAMAGE, LEAVE_BED, SWING_OFFHAND, CRITICAL_EFFECT, MAGIC_CRITICAL_EFFECT
}
}
@@ -1,5 +1,31 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.out.chat;
import io.github.retrooper.packetevents.annotations.Beta;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.Sendable;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
@@ -7,14 +33,57 @@ import io.github.retrooper.packetevents.utils.NMSUtils;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.UUID;
/**
* This wrapper MIGHT not be stable
*/
@Beta
public final class WrappedPacketOutChat extends WrappedPacket implements Sendable {
private static Constructor<?> chatClassConstructor;
private static Class<?> chatClass, iChatBaseComponentClass, chatSerializerClass;
private static Class<?> packetClass, iChatBaseComponentClass, chatSerializerClass, chatMessageTypeEnum;
private static Method chatMessageTypeCreatorMethod;
//0 = IChatBaseComponent, Byte
//1 = IChatBaseComponent, Int
//2 = IChatBaseComponent, ChatMessageType
//3 = IChatBaseComponent, ChatMessageType, UUID
private static byte constructorMode;
static {
//0 = Byte
//1 = Byte, Boolean
private static byte chatTypeMessageEnumConstructorMode;
private static final HashMap<ChatPosition, Byte> cachedChatPositions = new HashMap<ChatPosition, Byte>();
private static final HashMap<Byte, ChatPosition> cachedChatPositionIntegers = new HashMap<Byte, ChatPosition>();
private static final HashMap<String, Byte> cachedChatMessageTypeIntegers = new HashMap<String, Byte>();
private String message;
private ChatPosition chatPosition;
private UUID uuid;
public WrappedPacketOutChat(final Object packet) {
super(packet);
}
public WrappedPacketOutChat(String message, UUID uuid) {
this(message, ChatPosition.CHAT, uuid);
}
public WrappedPacketOutChat(String message, ChatPosition chatPosition, UUID uuid) {
super();
this.uuid = uuid;
this.message = message;
this.chatPosition = chatPosition;
}
public enum ChatPosition {
CHAT, SYSTEM_MESSAGE, GAME_INFO
}
public static void load() {
try {
chatClass = NMSUtils.getNMSClass("PacketPlayOutChat");
packetClass = PacketTypeClasses.Server.CHAT;
iChatBaseComponentClass = NMSUtils.getNMSClass("IChatBaseComponent");
} catch (ClassNotFoundException e) {
e.printStackTrace();
@@ -28,24 +97,62 @@ public final class WrappedPacketOutChat extends WrappedPacket implements Sendabl
chatSerializerClass = Reflection.getSubClass(iChatBaseComponentClass, "ChatSerializer");
}
boolean isVeryOutdated = false;
try {
chatClassConstructor = chatClass.getConstructor(iChatBaseComponentClass);
} catch (NoSuchMethodException e) {
e.printStackTrace();
chatMessageTypeEnum = NMSUtils.getNMSClass("ChatMessageType");
} catch (ClassNotFoundException e) {
isVeryOutdated = true;
}
if (!isVeryOutdated) {
chatMessageTypeCreatorMethod = Reflection.getMethod(chatMessageTypeEnum, 0, byte.class);
try {
chatClassConstructor = packetClass.getConstructor(iChatBaseComponentClass, chatMessageTypeEnum);
constructorMode = 2;
} catch (NoSuchMethodException e) {
//Just a much newer version(1.16.x and above right now)
try {
chatClassConstructor = packetClass.getConstructor(iChatBaseComponentClass, chatMessageTypeEnum, UUID.class);
constructorMode = 3;
} catch (NoSuchMethodException e2) {
//Failed to resolve the constructor
e2.printStackTrace();
}
}
} else {
try {
chatClassConstructor = packetClass.getConstructor(iChatBaseComponentClass, byte.class);
constructorMode = 0;
} catch (NoSuchMethodException e) {
//That is fine, they are most likely on an older version.
try {
chatClassConstructor = packetClass.getConstructor(iChatBaseComponentClass, int.class);
constructorMode = 1;
} catch (NoSuchMethodException e2) {
e2.printStackTrace();
}
}
}
cachedChatPositions.put(ChatPosition.CHAT, (byte) 0);
cachedChatPositions.put(ChatPosition.SYSTEM_MESSAGE, (byte) 1);
cachedChatPositions.put(ChatPosition.GAME_INFO, (byte) 2);
cachedChatPositionIntegers.put((byte) 0, ChatPosition.CHAT);
cachedChatPositionIntegers.put((byte) 1, ChatPosition.SYSTEM_MESSAGE);
cachedChatPositionIntegers.put((byte) 2, ChatPosition.GAME_INFO);
cachedChatMessageTypeIntegers.put("CHAT", (byte) 0);
cachedChatMessageTypeIntegers.put("SYSTEM", (byte) 1);
cachedChatMessageTypeIntegers.put("GAME_INFO", (byte) 2);
}
private String message;
public WrappedPacketOutChat(final Object packet) {
super(packet);
}
public WrappedPacketOutChat(final String message) {
super(null);
this.message = "{\"text\": \"" + message + "\"}";
public static String fromStringToJSON(String message) {
return "{\"text\": \"" + "use entity action name: " + message + "\"}";
}
public static String toStringFromIChatBaseComponent(Object obj) {
@@ -70,11 +177,27 @@ public final class WrappedPacketOutChat extends WrappedPacket implements Sendabl
@Override
protected void setup() {
try {
final Object iChatBaseObj = Reflection.getField(chatClass, iChatBaseComponentClass, 0).get(packet);
final Object iChatBaseObj = Reflection.getField(packetClass, iChatBaseComponentClass, 0).get(packet);
final Object contentString = Reflection.getMethod(iChatBaseComponentClass, String.class, 0).invoke(iChatBaseObj);
this.message = contentString.toString();
byte chatPosInteger = 0;
switch (constructorMode) {
case 0:
chatPosInteger = Reflection.getField(packetClass, byte.class, 0).getByte(packet);
break;
case 1:
chatPosInteger = (byte) Reflection.getField(packetClass, int.class, 0).getInt(packet);
break;
case 2:
case 3:
Object chatTypeEnumInstance = Reflection.getField(packetClass, chatMessageTypeEnum, 0).get(packet);
chatPosInteger = cachedChatMessageTypeIntegers.get(chatTypeEnumInstance.toString());
break;
}
this.chatPosition = cachedChatPositionIntegers.get(chatPosInteger);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
@@ -82,16 +205,75 @@ public final class WrappedPacketOutChat extends WrappedPacket implements Sendabl
@Override
public Object asNMSPacket() {
try {
return chatClassConstructor.newInstance(toIChatBaseComponent(this.message));
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
int integerChatPos = cachedChatPositions.get(chatPosition);
Object chatMessageTypeInstance = null;
if (chatMessageTypeEnum != null) {
if (chatTypeMessageEnumConstructorMode == 0) {
try {
chatMessageTypeInstance = chatMessageTypeCreatorMethod.invoke(null, (byte) integerChatPos);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
} else if (chatTypeMessageEnumConstructorMode == 1) {
try {
chatMessageTypeInstance = chatMessageTypeCreatorMethod.invoke(null, (byte) integerChatPos);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
}
switch (constructorMode) {
case 0:
try {
return chatClassConstructor.newInstance(toIChatBaseComponent(this.message), (byte) integerChatPos);
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
break;
case 1:
try {
return chatClassConstructor.newInstance(toIChatBaseComponent(this.message), integerChatPos);
} catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
break;
case 2:
try {
return chatClassConstructor.newInstance(toIChatBaseComponent(this.message), chatMessageTypeInstance);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
break;
case 3:
try {
return chatClassConstructor.newInstance(toIChatBaseComponent(this.message), chatMessageTypeInstance, uuid);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
break;
}
return null;
}
/**
* Get the message.
* @return Get String Message
*/
public String getMessage() {
return this.message;
}
/**
* Get the chat position.
*
* On 1.7.10, Only CHAT and SYSTEM_MESSAGE exist.
* If an invalid chat position is sent, it will be defaulted it to CHAT.
* @return ChatPosition
*/
public ChatPosition getChatPosition() {
if(this.chatPosition == null) {
this.chatPosition = ChatPosition.CHAT;
}
return this.chatPosition;
}
}
@@ -1,90 +1,171 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.out.entity;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
import org.bukkit.entity.Entity;
import java.lang.reflect.Field;
public class WrappedPacketOutEntity extends WrappedPacket {
private int entityId;
private static Class<?> packetClass;
//Byte = 1.7.10->1.8.8, Int = 1.9->1.15.x, Short = 1.16.x
private static byte mode = 0; //byte = 0, int = 1, short = 2
private static double dXYZDivisor = 0.0;
private int entityID;
private double deltaX, deltaY, deltaZ;
private byte yaw, pitch;
private boolean onGround;
public WrappedPacketOutEntity(Object packet) {
super(packet);
}
public static void load() {
packetClass = PacketTypeClasses.Server.ENTITY;
Field dxField = Reflection.getField(packetClass, 1);
assert dxField != null;
if (dxField.equals(Reflection.getField(packetClass, byte.class, 0))) {
mode = 0;
} else if (dxField.equals(Reflection.getField(packetClass, int.class, 1))) {
mode = 1;
} else if (dxField.equals(Reflection.getField(packetClass, short.class, 0))) {
mode = 2;
}
if (mode == 0) {
dXYZDivisor = 32.0;
} else {
dXYZDivisor = 4096.0;
}
}
@Override
protected void setup() {
try {
this.entityId = Reflection.getField(packetClass, int.class, 0).getInt(packet);
this.entityID = Reflection.getField(packetClass, int.class, 0).getInt(packet);
this.onGround = Reflection.getField(packetClass, boolean.class, 0).getBoolean(packet);
if (version.isLowerThan(ServerVersion.v_1_9)) {
byte dX = Reflection.getField(packetClass, byte.class, 0).getByte(packet);
byte dY = Reflection.getField(packetClass, byte.class, 1).getByte(packet);
byte dZ = Reflection.getField(packetClass, byte.class, 2).getByte(packet);
this.deltaX = dX / 32.0;
this.deltaY = dY / 32.0;
this.deltaZ = dZ / 32.0;
this.yaw = Reflection.getField(packetClass, byte.class, 3).getByte(packet);
this.pitch = Reflection.getField(packetClass, byte.class, 4).getByte(packet);
} else {
short dX = Reflection.getField(packetClass, short.class, 0).getShort(packet);
short dY = Reflection.getField(packetClass, short.class, 1).getShort(packet);
short dZ = Reflection.getField(packetClass, short.class, 2).getShort(packet);
this.deltaX = dX / 4096.0;
this.deltaY = dY / 4096.0;
this.deltaZ = dZ / 4096.0;
this.yaw = Reflection.getField(packetClass, byte.class, 0).getByte(packet);
this.pitch = Reflection.getField(packetClass, byte.class, 1).getByte(packet);
int dX = 1, dY = 1, dZ = 1;
switch (mode) {
case 0:
dX = Reflection.getField(packetClass, byte.class, 0).getByte(packet);
dY = Reflection.getField(packetClass, byte.class, 1).getByte(packet);
dZ = Reflection.getField(packetClass, byte.class, 2).getByte(packet);
this.yaw = Reflection.getField(packetClass, byte.class, 3).getByte(packet);
this.pitch = Reflection.getField(packetClass, byte.class, 4).getByte(packet);
break;
case 1:
dX = Reflection.getField(packetClass, int.class, 1).getInt(packet);
dY = Reflection.getField(packetClass, int.class, 2).getInt(packet);
dZ = Reflection.getField(packetClass, int.class, 3).getInt(packet);
this.yaw = Reflection.getField(packetClass, byte.class, 0).getByte(packet);
this.pitch = Reflection.getField(packetClass, byte.class, 1).getByte(packet);
break;
case 2:
dX = Reflection.getField(packetClass, short.class, 0).getShort(packet);
dY = Reflection.getField(packetClass, short.class, 1).getShort(packet);
dZ = Reflection.getField(packetClass, short.class, 2).getShort(packet);
this.yaw = Reflection.getField(packetClass, byte.class, 0).getByte(packet);
this.pitch = Reflection.getField(packetClass, byte.class, 1).getByte(packet);
break;
}
this.deltaX = dX / dXYZDivisor;
this.deltaY = dY / dXYZDivisor;
this.deltaZ = dZ / dXYZDivisor;
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
/**
* Get the pitch.
* @return Get Byte Pitch
*/
public byte getPitch() {
return pitch;
}
/**
* Get the Yaw.
* @return Get Byte Yaw
*/
public byte getYaw() {
return yaw;
}
public double getDeltaZ() {
return deltaZ;
}
public double getDeltaY() {
return deltaY;
}
/**
* Get the Delta X
* @return Delta X
*/
public double getDeltaX() {
return deltaX;
}
public int getEntityId() {
return entityId;
/**
* Get the Delta Y
* @return Delta Y
*/
public double getDeltaY() {
return deltaY;
}
/**
* Get the Delta Z
* @return Delta Z
*/
public double getDeltaZ() {
return deltaZ;
}
/**
* Lookup the associated entity by the ID that was sent in the packet.
* @return Entity
*/
public Entity getEntity() {
return NMSUtils.getEntityById(this.entityID);
}
/**
* Get the ID of the entity.
* If you do not want to use {@link #getEntity()},
* you lookup the entity by yourself with this entity ID.
* @return Entity ID
*/
public int getEntityId() {
return entityID;
}
/**
* Is the entity on the ground?
* @return On Ground
*/
public boolean isOnGround() {
return onGround;
}
private static Class<?> packetClass;
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayOutEntity");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}
@@ -1,6 +1,31 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.out.entityvelocity;
import io.github.retrooper.packetevents.enums.ServerVersion;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.Sendable;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
@@ -13,21 +38,36 @@ import java.lang.reflect.InvocationTargetException;
public final class WrappedPacketOutEntityVelocity extends WrappedPacket implements Sendable {
private static Constructor<?> velocityConstructor, vec3dConstructor;
private static Class<?> velocityClass, vec3dClass;
private static boolean isVec3dPresent;
private int entityId;
private double velocityX, velocityY, velocityZ;
private Entity entity;
public WrappedPacketOutEntityVelocity(final Object packet) {
super(packet);
}
public WrappedPacketOutEntityVelocity(final Entity entity, final double velocityX, final double velocityY, final double velocityZ) {
super();
this.entityId = entity.getEntityId();
this.entity = entity;
this.velocityX = velocityX;
this.velocityY = velocityY;
this.velocityZ = velocityZ;
}
/**
* Velocity Constructor parameter types:
* 1.7.10->1.13.2 use int, double, double, double style,
* 1.7.10 -&gt; 1.13.2 use int, double, double, double style,
* 1.14+ use int, Vec3D style
*/
static {
try {
velocityClass = NMSUtils.getNMSClass("PacketPlayOutEntityVelocity");
if (version.isHigherThan(ServerVersion.v_1_13_2)) {
public static void load() {
velocityClass = PacketTypeClasses.Server.ENTITY_VELOCITY;
if (version.isHigherThan(ServerVersion.v_1_13_2)) {
try {
vec3dClass = NMSUtils.getNMSClass("Vec3D");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
@@ -36,6 +76,7 @@ public final class WrappedPacketOutEntityVelocity extends WrappedPacket implemen
//That is fine, just a newer version
try {
velocityConstructor = velocityClass.getConstructor(int.class, vec3dClass);
isVec3dPresent = true;
//vec3d constructor
vec3dConstructor = vec3dClass.getConstructor(double.class, double.class, double.class);
} catch (NoSuchMethodException e2) {
@@ -45,36 +86,17 @@ public final class WrappedPacketOutEntityVelocity extends WrappedPacket implemen
}
}
private Entity entity;
private int entityId;
private double velocityX, velocityY, velocityZ;
public WrappedPacketOutEntityVelocity(final Object packet) {
super(packet);
}
public WrappedPacketOutEntityVelocity(final Entity entity, final double velocityX, final double velocityY, final double velocityZ) {
super(null);
this.entityId = entity.getEntityId();
this.entity = entity;
this.velocityX = velocityX;
this.velocityY = velocityY;
this.velocityZ = velocityZ;
}
@Override
protected void setup() {
try {
int i = 0;
final int entityId = Reflection.getField(velocityClass, int.class, 0).getInt(packet);
//ENTITY ID
this.entityId = Reflection.getField(velocityClass, int.class, 0).getInt(packet);
final int x = Reflection.getField(velocityClass, int.class, 1).getInt(packet);
final int y = Reflection.getField(velocityClass, int.class, 2).getInt(packet);
final int z = Reflection.getField(velocityClass, int.class, 3).getInt(packet);
this.entityId = entityId;
this.entity = NMSUtils.getEntityById(this.entityId);
int x = Reflection.getField(velocityClass, int.class, 1).getInt(packet);
int y = Reflection.getField(velocityClass, int.class, 2).getInt(packet);
int z = Reflection.getField(velocityClass, int.class, 3).getInt(packet);
//VELOCITY XYZ
this.velocityX = x / 8000.0D;
this.velocityY = y / 8000.0D;
this.velocityZ = z / 8000.0D;
@@ -83,29 +105,51 @@ public final class WrappedPacketOutEntityVelocity extends WrappedPacket implemen
}
}
/**
* Lookup the associated entity by the ID that was sent in the packet.
* @return Entity
*/
public Entity getEntity() {
return NMSUtils.getEntityById(this.entityId);
}
/**
* Get the ID of the entity.
* If you do not want to use {@link #getEntity()},
* you lookup the entity by yourself with this entity ID.
* @return Entity ID
*/
public int getEntityId() {
return entityId;
}
public Entity getEntity() {
return entity;
}
/**
* Get the Velocity X
* @return Get Velocity X
*/
public double getVelocityX() {
return velocityX;
}
/**
* Get the Velocity Y
* @return Get Velocity Y
*/
public double getVelocityY() {
return velocityY;
}
/**
* Get the Velocity Z
* @return Get Velocity Z
*/
public double getVelocityZ() {
return velocityZ;
}
@Override
public Object asNMSPacket() {
if (version.isLowerThan(ServerVersion.v_1_14)) {
if (!isVec3dPresent) {
try {
return velocityConstructor.newInstance(entityId, velocityX, velocityY, velocityZ);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
@@ -1,30 +1,73 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.out.keepalive;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.Sendable;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
import net.minecraft.server.v1_8_R3.PacketPlayOutKeepAlive;
public class WrappedPacketOutKeepAlive extends WrappedPacket {
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
public class WrappedPacketOutKeepAlive extends WrappedPacket implements Sendable {
private static Class<?> packetClass;
private static Constructor<?> keepAliveConstructor;
private static boolean integerMode;
private long id;
public WrappedPacketOutKeepAlive(Object packet) {
super(packet);
}
/**
* Optionally Cast this long to an integer if you are using 1.7.10->1.12.2!
* In 1.13.2->1.16.1 a long is sent
*
* @return response is
*/
public long getId() {
return id;
public WrappedPacketOutKeepAlive(long id) {
super();
}
public static void load() {
packetClass = PacketTypeClasses.Server.KEEP_ALIVE;
integerMode = Reflection.getField(packetClass, int.class, 0) != null;
if (integerMode) {
try {
keepAliveConstructor = packetClass.getConstructor(int.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
} else {
try {
keepAliveConstructor = packetClass.getConstructor(long.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
}
@Override
protected void setup() {
if (Reflection.getField(packetClass, int.class, 0) == null) {
if (!integerMode) {
try {
this.id = Reflection.getField(packetClass, long.class, 0).getLong(packet);
} catch (IllegalAccessException e) {
@@ -39,14 +82,33 @@ public class WrappedPacketOutKeepAlive extends WrappedPacket {
}
}
private static Class<?> packetClass;
/**
* Get the Keep Alive ID.
*
* You may cast this down to an int if you are on 1.7.10 - 1.12.2.
* On 1.13.2 - 1.16.2 a long is sent.
*
* @return Get Keep Alive ID
*/
public long getId() {
return id;
}
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayOutKeepAlive");
} catch (ClassNotFoundException e) {
e.printStackTrace();
@Override
public Object asNMSPacket() {
if (integerMode) {
try {
return keepAliveConstructor.newInstance((int) id);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
} else {
try {
return keepAliveConstructor.newInstance(id);
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
}
PacketPlayOutKeepAlive p;
return null;
}
}
@@ -1,5 +1,30 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.out.kickdisconnect;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.Sendable;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.packetwrappers.out.chat.WrappedPacketOutChat;
@@ -12,10 +37,20 @@ import java.lang.reflect.InvocationTargetException;
public final class WrappedPacketOutKickDisconnect extends WrappedPacket implements Sendable {
private static Class<?> packetClass, iChatBaseComponentClass;
private static Constructor<?> kickDisconnectConstructor;
private String kickMessage;
static {
public WrappedPacketOutKickDisconnect(final Object packet) {
super(packet);
}
public WrappedPacketOutKickDisconnect(final String kickMessage) {
super();
this.kickMessage = kickMessage;
}
public static void load() {
packetClass = PacketTypeClasses.Server.KICK_DISCONNECT;
try {
packetClass = NMSUtils.getNMSClass("PacketPlayOutKickDisconnect");
iChatBaseComponentClass = NMSUtils.getNMSClass("IChatBaseComponent");
} catch (ClassNotFoundException e) {
e.printStackTrace();
@@ -28,17 +63,6 @@ public final class WrappedPacketOutKickDisconnect extends WrappedPacket implemen
}
}
private String kickMessage;
public WrappedPacketOutKickDisconnect(final Object packet) {
super(packet);
}
public WrappedPacketOutKickDisconnect(final String kickMessage) {
super(null);
this.kickMessage = kickMessage;
}
@Override
protected void setup() {
try {
@@ -48,6 +72,10 @@ public final class WrappedPacketOutKickDisconnect extends WrappedPacket implemen
}
}
/**
* Get the kick message.
* @return Get Kick Message
*/
public String getKickMessage() {
return kickMessage;
}
@@ -1,44 +0,0 @@
package io.github.retrooper.packetevents.packetwrappers.out.playerinfo;
import io.github.retrooper.packetevents.enums.minecraft.Gamemode;
import io.github.retrooper.packetevents.enums.minecraft.PlayerInfoAction;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
import net.minecraft.server.v1_8_R3.PacketPlayOutPlayerInfo;
public class WrappedPacketOutPlayerInfo extends WrappedPacket {
private PlayerInfoAction action;
public WrappedPacketOutPlayerInfo(Object packet) {
super(packet);
}
@Override
protected void setup() {
PacketPlayOutPlayerInfo.PlayerInfoData dl;
}
private static Class<?> packetClass, enumPlayerInfoActionClass;
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayOutPlayerInfo");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
enumPlayerInfoActionClass = NMSUtils.getNMSClass("EnumPLayerInfoAction");
} catch (ClassNotFoundException e) {
enumPlayerInfoActionClass = Reflection.getSubClass(packetClass, "EnumPlayerInfoAction");
}
}
public class PlayerDataInfo {
public PlayerDataInfo(Object gameProfile, int var, Gamemode gamemode, String s) {
}
}
}
@@ -0,0 +1,101 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.out.position;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
public final class WrappedPacketOutPosition extends WrappedPacket {
private static Class<?> packetClass;
private double x;
private double y;
private double z;
private float yaw;
private float pitch;
public WrappedPacketOutPosition(Object packet) {
super(packet);
}
public static void load() {
packetClass = PacketTypeClasses.Server.POSITION;
}
@Override
protected void setup() {
//TODO boolean onGround and flags
try {
this.x = Reflection.getField(packetClass, double.class, 0).getDouble(packet);
this.y = Reflection.getField(packetClass, double.class, 1).getDouble(packet);
this.z = Reflection.getField(packetClass, double.class, 2).getDouble(packet);
this.yaw = Reflection.getField(packetClass, float.class, 0).getFloat(packet);
this.pitch = Reflection.getField(packetClass, float.class, 1).getFloat(packet);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
/**
* Get the X position.
* @return Get X Position
*/
public double getX() {
return x;
}
/**
* Get the Y position.
* @return Get Y Position
*/
public double getY() {
return y;
}
/**
* Get the Z position.
* @return Get Z Position
*/
public double getZ() {
return z;
}
/**
* Get the Yaw.
* @return Get Yaw
*/
public float getYaw() {
return yaw;
}
/**
* Get the Pitch,
* @return Get Pitch
*/
public float getPitch() {
return pitch;
}
}
@@ -1,9 +1,33 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.out.transaction;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.Sendable;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -11,13 +35,22 @@ import java.lang.reflect.InvocationTargetException;
public class WrappedPacketOutTransaction extends WrappedPacket implements Sendable {
private static Class<?> packetClass;
private static Constructor<?> packetConstructor;
private int windowId;
private short actionNumber;
private boolean accepted;
public WrappedPacketOutTransaction(final Object packet) {
super(packet);
}
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayOutTransaction");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
public WrappedPacketOutTransaction(final int windowId, final short actionNumber, final boolean accepted) {
super();
this.windowId = windowId;
this.actionNumber = actionNumber;
this.accepted = accepted;
}
public static void load() {
packetClass = PacketTypeClasses.Server.TRANSACTION;
try {
packetConstructor = packetClass.getConstructor(int.class, short.class, boolean.class);
@@ -26,21 +59,6 @@ public class WrappedPacketOutTransaction extends WrappedPacket implements Sendab
}
}
private int windowId;
private short actionNumber;
private boolean accepted;
public WrappedPacketOutTransaction(final Object packet) {
super(packet);
}
public WrappedPacketOutTransaction(final int windowId, final short actionNumber, final boolean accepted) {
super(null);
this.windowId = windowId;
this.actionNumber = actionNumber;
this.accepted = accepted;
}
@Override
protected void setup() {
try {
@@ -53,14 +71,26 @@ public class WrappedPacketOutTransaction extends WrappedPacket implements Sendab
}
/**
* Get the Window ID.
* @return Get Window ID
*/
public int getWindowId() {
return windowId;
}
/**
* Get the action number.
* @return Get Action Number
*/
public short getActionNumber() {
return actionNumber;
}
/**
* Has the transaction packet been accepted?
* @return Is Accepted
*/
public boolean isAccepted() {
return accepted;
}
@@ -1,9 +1,33 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.packetwrappers.out.updatehealth;
import io.github.retrooper.packetevents.packet.PacketTypeClasses;
import io.github.retrooper.packetevents.packetwrappers.Sendable;
import io.github.retrooper.packetevents.packetwrappers.api.WrappedPacket;
import io.github.retrooper.packetevents.reflectionutils.Reflection;
import io.github.retrooper.packetevents.utils.NMSUtils;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
@@ -11,24 +35,8 @@ import java.lang.reflect.InvocationTargetException;
public final class WrappedPacketOutUpdateHealth extends WrappedPacket implements Sendable {
private static Class<?> packetClass;
private static Constructor<?> packetConstructor;
static {
try {
packetClass = NMSUtils.getNMSClass("PacketPlayOutUpdateHealth");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
try {
packetConstructor = packetClass.getConstructor(float.class, int.class, float.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
private float health, foodSaturation;
private int food;
public WrappedPacketOutUpdateHealth(final Object packet) {
super(packet);
}
@@ -36,17 +44,27 @@ public final class WrappedPacketOutUpdateHealth extends WrappedPacket implements
/**
* See https://wiki.vg/Protocol#Update_Health
*
* @param health
* @param food
* @param foodSaturation
* @param health 0 or less = dead, 20 = full HP
* @param food 0–20
* @param foodSaturation Seems to vary from 0.0 to 5.0 in integer increments
*/
public WrappedPacketOutUpdateHealth(final float health, final int food, final float foodSaturation) {
super(null);
super();
this.health = health;
this.food = food;
this.foodSaturation = foodSaturation;
}
public static void load() {
packetClass = PacketTypeClasses.Server.UPDATE_HEALTH;
try {
packetConstructor = packetClass.getConstructor(float.class, int.class, float.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
@Override
protected void setup() {
try {
@@ -59,14 +77,26 @@ public final class WrappedPacketOutUpdateHealth extends WrappedPacket implements
}
/**
* Get health value.
* @return Get Health
*/
public float getHealth() {
return health;
}
/**
* Get food saturation value.
* @return Get Food Saturation
*/
public float getFoodSaturation() {
return foodSaturation;
}
/**
* Get food value.
* @return Get Food
*/
public int getFood() {
return food;
}
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.reflectionutils;
@@ -1,5 +1,31 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.reflectionutils.fielddata;
import java.util.Objects;
public class FieldWithIndex {
private final Class<?> cls;
private final int index;
@@ -16,4 +42,19 @@ public class FieldWithIndex {
public int getIndex() {
return index;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FieldWithIndex that = (FieldWithIndex) o;
return index == that.index &&
Objects.equals(cls, that.cls);
}
@Override
public int hashCode() {
return Objects.hash(cls, index);
}
}
@@ -1,5 +1,31 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.reflectionutils.fielddata;
import java.util.Objects;
public class FieldWithName {
private final Class<?> cls;
@@ -17,4 +43,19 @@ public class FieldWithName {
public String getName() {
return name;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FieldWithName that = (FieldWithName) o;
return name.equals(that.name) &&
Objects.equals(cls, that.cls);
}
@Override
public int hashCode() {
return Objects.hash(cls, name);
}
}
@@ -1,5 +1,31 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.reflectionutils.fielddata;
import java.util.Objects;
public class FieldWithTypeAndIndex {
private final Class<?> cls, type;
private final int index;
@@ -21,4 +47,20 @@ public class FieldWithTypeAndIndex {
public int getIndex() {
return index;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
FieldWithTypeAndIndex that = (FieldWithTypeAndIndex) o;
return index == that.index &&
Objects.equals(cls, that.cls) &&
Objects.equals(type, that.type);
}
@Override
public int hashCode() {
return Objects.hash(cls, type, index);
}
}
@@ -1,5 +1,31 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.reflectionutils.methoddata;
import java.util.Objects;
public class MethodWithIndexAndParams {
private final Class<?> cls;
private final int index;
@@ -22,4 +48,20 @@ public class MethodWithIndexAndParams {
public Class<?>[] getParams() {
return params;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MethodWithIndexAndParams that = (MethodWithIndexAndParams) o;
return index == that.index &&
Objects.equals(cls, that.cls) &&
Objects.equals(params, that.params);
}
@Override
public int hashCode() {
return Objects.hash(cls, params, index);
}
}
@@ -0,0 +1,135 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.settings;
import io.github.retrooper.packetevents.enums.ServerVersion;
import java.util.Random;
public class PacketEventsSettings {
private ServerVersion defaultServerVersion = ServerVersion.v_1_7_10;
private String identifier = "";
private boolean autoResolveClientProtocolVersion;
private boolean uninjectAsync = false;
private boolean injectAsync = false;
/**
* If PacketEvents fails to detect your server version, it will use the recommended version
*
* @return Recommended version
*/
public ServerVersion getDefaultServerVersion() {
return this.defaultServerVersion;
}
/**
* Set the default version
*
* @param version ServerVersion
*/
public void setDefaultServerVersion(final ServerVersion version) {
this.defaultServerVersion = version;
}
/**
* The identifier is a unique string that is used to generate a player's handler name.
* Two plugins cannot have the same handler name.
* If you manually set the identifier using its setter '#setIdentifier(String)'.
* We will use that identifier to generate each player's handler name.
* If you do not set the identifier manually, we automatically generate one for you.
* @return stored identifier or new generated identifier
*/
public String getIdentifier() {
if (this.identifier.isEmpty()) {
String alphabet = "abcdefghijklmnopqrstuvwxyz";
StringBuilder sb = new StringBuilder();
Random random = new Random();
while (sb.length() < 13) {
int index = (int) (random.nextFloat() * alphabet.length());
sb.append(alphabet.charAt(index));
}
this.identifier = sb.toString();
}
return this.identifier;
}
/**
* Set a unique Identifier (Usually something that represents your plugin, For example: MyPluginPacketHandler)
* If another present plugin uses the same Identifier, It will cause incompatibilities.
*
* @param identifier Unique string
* @deprecated This method is deprecated as you no longer need to set an identifier,
* a unique identifier is already automatically generated for you.
*/
@Deprecated
public void setIdentifier(final String identifier) {
this.identifier = identifier;
}
public boolean doAutoResolveClientProtocolVersion() {
return autoResolveClientProtocolVersion;
}
/**
* If PacketEvents fails to detect a client's version
* (when ViaVersion, ProtocolLib or ProtocolSupport can't be found on the server),
* should it assume that the client is using the same version as the server?
* Returns ACCESS_FAILURE if this is set to FALSE(default value is false).
* @param autoResolveClientProtocolVersion boolean
*/
public void setDoAutoResolveClientProtocolVersion(boolean autoResolveClientProtocolVersion) {
this.autoResolveClientProtocolVersion = autoResolveClientProtocolVersion;
}
/**
* Would you like PacketEvents to Uninject players Asynchronously?
* WARNING! This might make reloading unsupported
*
* @param uninjectAsync boolean
*/
public void setUninjectAsync(boolean uninjectAsync) {
this.uninjectAsync = uninjectAsync;
}
public boolean isUninjectAsync() {
return this.uninjectAsync;
}
public boolean isInjectAsync() {
return this.injectAsync;
}
/**
* Would you like PacketEvents to Inject players Asynchronously?
* WARNING! This might make reloading unsupported
*
* @param injectAsync boolean
*/
public void setInjectAsync(boolean injectAsync) {
this.injectAsync = injectAsync;
}
}
@@ -1,57 +0,0 @@
package io.github.retrooper.packetevents.settings;
import io.github.retrooper.packetevents.enums.ServerVersion;
public class Settings {
private ServerVersion defaultServerVersion;
private String identifier = "";
private boolean autoResolveClientProtocolVersion;
/**
* If PacketEvents fails to detect your server version, it will use the recommended version
*
* @return Recommended version
*/
public ServerVersion getDefaultServerVersion() {
return defaultServerVersion;
}
/**
* Set the recommended version
*
* @param version
*/
public void setDefaultServerVersion(final ServerVersion version) {
defaultServerVersion = version;
}
public String getIdentifier() {
return identifier;
}
/**
* Set a unique Identifier (Usually something that represents your plugin, For example: MyPluginPacketHandler)
* If another present plugin uses the same Identifier, It might cause incompatibilities
*
* @param identifier
*/
public void setIdentifier(final String identifier) {
this.identifier = identifier;
}
public boolean doAutoResolveClientProtocolVersion() {
return autoResolveClientProtocolVersion;
}
/**
* If PacketEvents fails to detect a client's version
* Should it assume that the client is using the same version that the server is?
* <p>
* Returns ACCESS_FAILURE if false
*
* @param autoResolveClientProtocolVersion
*/
public void setDoAutoResolveClientProtocolVersion(boolean autoResolveClientProtocolVersion) {
this.autoResolveClientProtocolVersion = autoResolveClientProtocolVersion;
}
}
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.utils;
import org.bukkit.Location;
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.utils;
import io.github.retrooper.packetevents.annotations.Nullable;
@@ -15,10 +39,10 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public final class NMSUtils {
private static final ServerVersion version = ServerVersion.getVersion();
public static String nettyPrefix;
public static ServerVersion version;
private static final String nmsDir = ServerVersion.getNMSDirectory();
private static final String obcDir = ServerVersion.getOBCDirectory();
public static String nettyPrefix;
public static Class<?> minecraftServerClass, craftWorldsClass,
packetClass, entityPlayerClass, playerConnectionClass,
craftPlayerClass, serverConnectionClass, craftEntityClass,
@@ -26,12 +50,17 @@ public final class NMSUtils {
private static Method getCraftWorldHandleMethod, getServerConnection, getCraftPlayerHandle, getCraftEntityHandle, sendPacketMethod, asBukkitCopy;
private static Field entityPlayerPingField, playerConnectionField;
static {
public static void load() {
try {
nettyPrefix = "io.netty";
Class.forName("io.netty.channel.Channel");
Class.forName(nettyPrefix + ".channel.Channel");
} catch (ClassNotFoundException e) {
nettyPrefix = "net.minecraft.util.io.netty";
try {
Class.forName(nettyPrefix + ".channel.Channel");
} catch (ClassNotFoundException e2) {
throw new IllegalStateException("PacketEvents failed to locate Netty's location.");
}
}
try {
nettyChannelClass = getNettyClass("channel.Channel");
@@ -102,10 +131,12 @@ public final class NMSUtils {
}
public static String getChannelFutureListFieldName() {
if (version.isLowerThan(ServerVersion.v_1_8))
if (version.isLowerThan(ServerVersion.v_1_8)) {
return "e";
if (version.isLowerThan(ServerVersion.v_1_13))
}
if (version.isLowerThan(ServerVersion.v_1_13)) {
return "g";
}
return "f";
}
@@ -188,13 +219,8 @@ public final class NMSUtils {
return null;
}
public static boolean is_1_8() {
return version.isHigherThan(ServerVersion.v_1_7_10)
&& version.isLowerThan(ServerVersion.v_1_9);
}
public static void sendSendableWrapper(final Player player, final Sendable sendable) {
sendNMSPacket(player, sendable.asNMSPacket());
NMSUtils.sendNMSPacket(player, sendable.asNMSPacket());
}
public static void sendNMSPacket(final Player player, final Object nmsPacket) {
@@ -212,9 +238,4 @@ public final class NMSUtils {
e.printStackTrace();
}
}
public static String getServerConnectionFieldName() {
return "p";
}
}
@@ -1,58 +1,138 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.utils.api;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.enums.ClientVersion;
import io.github.retrooper.packetevents.handler.NettyPacketHandler;
import io.github.retrooper.packetevents.packetwrappers.Sendable;
import io.github.retrooper.packetevents.utils.NMSUtils;
import io.github.retrooper.packetevents.utils.versionlookup.VersionLookupUtils;
import org.bukkit.entity.Player;
import java.util.HashMap;
import java.util.UUID;
public final class PlayerUtils {
private final HashMap<UUID, ClientVersion> clientVersionsMap = new HashMap<UUID, ClientVersion>();
/**
* This map stores each player's client version.
*/
public final HashMap<UUID, ClientVersion> clientVersionsMap = new HashMap<UUID, ClientVersion>();
/**
* Get the player's ping.
* @param player
* @return Get Player Ping
*/
public int getPing(final Player player) {
return NMSUtils.getPlayerPing(player);
}
/**
* Get the client version by a UUID.
* @param uuid
* @return Get Client Version
*/
public ClientVersion getClientVersion(final UUID uuid) {
return clientVersionsMap.get(uuid);
}
/**
* Get the client version by a player object.
* @param player
* @return Get Client Version
*/
public ClientVersion getClientVersion(final Player player) {
return getClientVersion(player.getUniqueId());
return clientVersionsMap.get(player.getUniqueId());
}
public void setClientVersion(final UUID uuid, final ClientVersion version) {
clientVersionsMap.put(uuid, version);
}
public void setClientVersion(final Player player, final ClientVersion version) {
setClientVersion(player.getUniqueId(), version);
}
public void clearClientVersion(final UUID uuid) {
clientVersionsMap.remove(uuid);
}
public void clearClientVersion(final Player player) {
clearClientVersion(player.getUniqueId());
/**
* Get the protocol version.
* @param player
* @return Get Protocol Version
*/
public int getProtocolVersion(Player player) {
return VersionLookupUtils.getProtocolVersion(player);
}
/**
* Inject a player.
*
* (This also calls the {@link io.github.retrooper.packetevents.event.impl.PlayerInjectEvent})
* @param player
*/
public void injectPlayer(final Player player) {
NettyPacketHandler.injectPlayer(player);
if (PacketEvents.getSettings().isInjectAsync()) {
NettyPacketHandler.injectPlayerAsync(player);
} else {
NettyPacketHandler.injectPlayer(player);
}
}
/**
* Use {@link #ejectPlayer(Player)}
* @param player
*/
@Deprecated
public void uninjectPlayer(final Player player) {
NettyPacketHandler.uninjectPlayer(player);
if (PacketEvents.getSettings().isUninjectAsync()) {
NettyPacketHandler.ejectPlayerAsync(player);
} else {
NettyPacketHandler.ejectPlayer(player);
}
}
public void uninjectPlayerNow(final Player player) {
NettyPacketHandler.uninjectPlayerNow(player);
/**
* Eject a player.
* (This also calls the {@link io.github.retrooper.packetevents.event.impl.PlayerUninjectEvent})
* @param player
*/
public void ejectPlayer(final Player player) {
if (PacketEvents.getSettings().isUninjectAsync()) {
NettyPacketHandler.ejectPlayerAsync(player);
} else {
NettyPacketHandler.ejectPlayer(player);
}
}
/**
* Send a {@link Sendable} wrapper to a player.
* @param player
* @param sendable
*/
public void sendPacket(final Player player, final Sendable sendable) {
NMSUtils.sendSendableWrapper(player, sendable);
}
}
/**
* Send a raw NMS packet to a player.
* @param player
* @param nmsPacket
*/
public void sendNMSPacket(final Player player, Object nmsPacket) {
NMSUtils.sendNMSPacket(player, nmsPacket);
}
}
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.utils.api;
import io.github.retrooper.packetevents.enums.ServerVersion;
@@ -7,25 +31,19 @@ import io.github.retrooper.packetevents.utils.NMSUtils;
import java.lang.reflect.InvocationTargetException;
public final class ServerUtils {
@Deprecated
public ServerVersion getServerVersion() {
return getVersion();
}
@Deprecated
public double[] getRecentServerTPS() {
return getRecentTPS();
}
@Deprecated
public double getCurrentServerTPS() {
return getCurrentTPS();
}
/**
* Get the server version.
* @return Get Server Version
*/
public ServerVersion getVersion() {
return ServerVersion.getVersion();
}
/**
* Get recent TPS array from NMS.
* @return Get Recent TPS
*/
public double[] getRecentTPS() {
double[] tpsArray = new double[0];
try {
@@ -36,11 +54,38 @@ public final class ServerUtils {
return tpsArray;
}
/**
* Get the current TPS.
* @return Get Current TPS
*/
public double getTPS() {
return getRecentTPS()[0];
}
/**
* Use {@link #getTPS()}
* @return Get Current TPS
*/
@Deprecated
public double getCurrentTPS() {
return getRecentTPS()[0];
}
/**
* Use {@link #getOperatingSystem()}
* @deprecated Method rename pending to next minor update.
* @return
*/
@Deprecated
public SystemOS getPlatform() {
return SystemOS.getOperatingSystem();
}
/**
* Get the Operating System the server is running on.
* @return Get Server Operating System
*/
public SystemOS getOperatingSystem() {
return SystemOS.getOperatingSystem();
}
}
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.utils.nms_entityfinder;
import io.github.retrooper.packetevents.annotations.Nullable;
@@ -12,7 +36,7 @@ import java.lang.reflect.Method;
public final class EntityFinderUtils {
@Nullable
private static final ServerVersion version = ServerVersion.getVersion();
public static ServerVersion version;
private static Class<?> worldServerClass;
private static Class<?> craftWorldClass;
private static Class<?> entityClass;
@@ -20,7 +44,10 @@ public final class EntityFinderUtils {
private static Method craftWorldGetHandle;
private static Method getBukkitEntity;
static {
private static boolean isServerVersion_v_1_8_x;
public static void load() {
isServerVersion_v_1_8_x = version.isHigherThan(ServerVersion.v_1_7_10) && version.isLowerThan(ServerVersion.v_1_9);
try {
worldServerClass = NMSUtils.getNMSClass("WorldServer");
craftWorldClass = NMSUtils.getOBCClass("CraftWorld");
@@ -30,7 +57,7 @@ public final class EntityFinderUtils {
}
try {
getEntityByIdMethod = worldServerClass.getMethod(getEntityByNameMethodName(), int.class);
getEntityByIdMethod = worldServerClass.getMethod(getEntityByIDMethodName(), int.class);
craftWorldGetHandle = craftWorldClass.getMethod("getHandle");
getBukkitEntity = entityClass.getMethod("getBukkitEntity");
} catch (NoSuchMethodException e) {
@@ -38,6 +65,11 @@ public final class EntityFinderUtils {
}
}
/**
* Get an entity by their ID.
* @param id
* @return Entity
*/
public static Entity getEntityById(final int id) {
for (final World world : Bukkit.getWorlds()) {
final Entity entity = getEntityByIdWithWorld(world, id);
@@ -45,14 +77,23 @@ public final class EntityFinderUtils {
return entity;
}
}
return null;
return null;
}
/**
* Get an entity by their ID, guaranteed to be in the specified world.
* @param world
* @param id
* @return Entity
*/
@Nullable
public static Entity getEntityByIdWithWorld(final World world, final int id) {
if (world == null) {
return null;
}
else if(craftWorldClass == null) {
throw new IllegalStateException("PacketEvents failed to locate the CraftWorld class.");
}
Object craftWorld = craftWorldClass.cast(world);
Object worldServer = null;
@@ -79,8 +120,13 @@ public final class EntityFinderUtils {
return null;
}
public static String getEntityByNameMethodName() {
if (version.isHigherThan(ServerVersion.v_1_7_10) && version.isLowerThan(ServerVersion.v_1_9)) {
/**
* This is the name of the method that returns the NMS entity when you pass in its ID.
* On 1.8-1.8.8 the function name is called 'a', on 1.7.10 and 1.9 and above the name is called 'getEntity'.
* @return entity by ID method name
*/
public static String getEntityByIDMethodName() {
if (isServerVersion_v_1_8_x) {
return "a";
}
return "getEntity";
@@ -1,16 +0,0 @@
package io.github.retrooper.packetevents.utils.onlineplayers;
import io.github.retrooper.packetevents.enums.ServerVersion;
import org.bukkit.entity.Player;
public class OnlinePlayerUtilities {
private static final ServerVersion version = ServerVersion.getVersion();
public static Player[] getOnlinePlayers() {
if (version.isLowerThan(ServerVersion.v_1_9)) {
return OnlinePlayerUtils_8.getOnlinePlayers();
} else {
return OnlinePlayerUtils_9.getOnlinePlayers();
}
}
}
@@ -1,12 +0,0 @@
package io.github.retrooper.packetevents.utils.onlineplayers;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class OnlinePlayerUtils_8 {
public static Player[] getOnlinePlayers() {
return Bukkit.getServer().getOnlinePlayers().toArray(new Player[0]);
}
}
@@ -1,10 +0,0 @@
package io.github.retrooper.packetevents.utils.onlineplayers;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class OnlinePlayerUtils_9 {
public static Player[] getOnlinePlayers() {
return Bukkit.getOnlinePlayers().toArray(new Player[0]);
}
}
@@ -0,0 +1,34 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.utils.protocollib;
import com.comphenix.protocol.ProtocolLibrary;
import org.bukkit.entity.Player;
class ProtocolLibAPIAccessor {
public static int getProtocolVersion(final Player player) {
return ProtocolLibrary.getProtocolManager().getProtocolVersion(player);
}
}
@@ -0,0 +1,146 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.utils.protocollib;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import io.github.retrooper.packetevents.PacketEvents;
import io.github.retrooper.packetevents.annotations.PacketHandler;
import io.github.retrooper.packetevents.enums.PacketEventPriority;
import io.github.retrooper.packetevents.event.PacketListener;
import io.github.retrooper.packetevents.event.impl.PacketReceiveEvent;
import io.github.retrooper.packetevents.event.impl.PacketSendEvent;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
public class ProtocolLibListener {
public enum ProtocolLibPresent {
UNKNOWN, NOT_PRESENT, PRESENT
}
private static ProtocolLibPresent plibPresent = ProtocolLibPresent.UNKNOWN;
public static void load() {
if (ProtocolLibUtils.isAvailable()) {
plibPresent = ProtocolLibPresent.PRESENT;
}
}
public static ProtocolLibPresent isProtocolLibPresent() {
return plibPresent;
}
public static void registerProtocolLibListener(PacketListener listener, List<Method> methods) {
if (plibPresent == ProtocolLibPresent.PRESENT) {
for (Method m : methods) {
if (m.getParameterTypes()[0].equals(PacketReceiveEvent.class)) {
PacketHandler annot = m.getAnnotation(PacketHandler.class);
ListenerPriority priority;
switch (annot.priority()) {
case PacketEventPriority.LOWEST:
priority = ListenerPriority.LOWEST;
break;
case PacketEventPriority.LOW:
priority = ListenerPriority.LOW;
break;
case PacketEventPriority.HIGH:
priority = ListenerPriority.HIGH;
break;
case PacketEventPriority.HIGHEST:
priority = ListenerPriority.HIGHEST;
break;
case PacketEventPriority.MONITOR:
priority = ListenerPriority.MONITOR;
break;
default:
priority = ListenerPriority.NORMAL;
break;
}
ProtocolLibrary.getProtocolManager().
addPacketListener(new PacketAdapter(PacketEvents.getPlugins().get(0),
priority, PacketType.Play.Client.getInstance().values()) {
@Override
public void onPacketReceiving(PacketEvent event) {
event.setReadOnly(false);
PacketReceiveEvent receiveEvent = new PacketReceiveEvent(event.getPlayer(), event.getPacket().getHandle());
try {
m.invoke(listener, receiveEvent);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
event.setCancelled(receiveEvent.isCancelled());
}
});
} else if (m.getParameterTypes()[0].equals(PacketSendEvent.class)) {
PacketHandler annot = m.getAnnotation(PacketHandler.class);
ListenerPriority priority;
switch (annot.priority()) {
case PacketEventPriority.LOWEST:
priority = ListenerPriority.LOWEST;
break;
case PacketEventPriority.LOW:
priority = ListenerPriority.LOW;
break;
case PacketEventPriority.HIGH:
priority = ListenerPriority.HIGH;
break;
case PacketEventPriority.HIGHEST:
priority = ListenerPriority.HIGHEST;
break;
case PacketEventPriority.MONITOR:
priority = ListenerPriority.MONITOR;
break;
default:
priority = ListenerPriority.NORMAL;
break;
}
ProtocolLibrary.getProtocolManager().
addPacketListener(new PacketAdapter(PacketEvents.getPlugins().get(0),
priority, PacketType.Play.Server.getInstance().values()) {
@Override
public void onPacketSending(PacketEvent event) {
event.setReadOnly(false);
PacketSendEvent sendEvent = new PacketSendEvent(event.getPlayer(), event.getPacket().getHandle());
try {
m.invoke(listener, sendEvent);
} catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
}
event.setCancelled(sendEvent.isCancelled());
}
});
}
}
}
}
}
@@ -0,0 +1,38 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.utils.protocollib;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class ProtocolLibUtils {
public static boolean isAvailable() {
return Bukkit.getPluginManager().isPluginEnabled("ProtocolLib");
}
public static int getProtocolVersion(final Player player) {
return ProtocolLibAPIAccessor.getProtocolVersion(player);
}
}
@@ -0,0 +1,34 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.utils.protocolsupport;
import org.bukkit.entity.Player;
import protocolsupport.api.ProtocolSupportAPI;
class ProtocolSupportAPIAccessor {
public static int getProtocolVersion(final Player player) {
return ProtocolSupportAPI.getProtocolVersion(player).getId();
}
}
@@ -0,0 +1,38 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.utils.protocolsupport;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class ProtocolSupportUtils {
public static boolean isAvailable() {
return Bukkit.getPluginManager().isPluginEnabled("ProtocolSupport");
}
public static int getProtocolVersion(final Player player) {
return ProtocolSupportAPIAccessor.getProtocolVersion(player);
}
}
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.utils.vector;
public final class Vector3d {
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.utils.vector;
public final class Vector3f {
@@ -1,3 +1,27 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.utils.vector;
public final class Vector3i {
@@ -1,10 +0,0 @@
package io.github.retrooper.packetevents.utils.versionlookup;
import com.comphenix.protocol.ProtocolLibrary;
import org.bukkit.entity.Player;
class ProtocolLibAPIAccessor {
public static int getProtocolVersion(final Player player) {
return ProtocolLibrary.getProtocolManager().getProtocolVersion(player);
}
}
@@ -1,14 +0,0 @@
package io.github.retrooper.packetevents.utils.versionlookup;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class ProtocolLibUtils {
public static boolean isAvailable() {
return Bukkit.getPluginManager().isPluginEnabled("ProtocolLib");
}
public static int getProtocolVersion(final Player player) {
return ProtocolLibAPIAccessor.getProtocolVersion(player);
}
}
@@ -1,10 +0,0 @@
package io.github.retrooper.packetevents.utils.versionlookup;
import org.bukkit.entity.Player;
import protocolsupport.api.ProtocolSupportAPI;
class ProtocolSupportAPIAccessor {
public static int getProtocolVersion(final Player player) {
return ProtocolSupportAPI.getProtocolVersion(player).getId();
}
}
@@ -1,14 +0,0 @@
package io.github.retrooper.packetevents.utils.versionlookup;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class ProtocolSupportUtils {
public static boolean isAvailable() {
return Bukkit.getPluginManager().isPluginEnabled("ProtocolSupport");
}
public static int getProtocolVersion(final Player player) {
return ProtocolSupportAPIAccessor.getProtocolVersion(player);
}
}
@@ -0,0 +1,34 @@
/*
* MIT License
*
* Copyright (c) 2020 retrooper
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package io.github.retrooper.packetevents.utils.versionlookup;
import org.bukkit.entity.Player;
public class ProtocolVersionAccessor_v_1_7 {
public static int getProtocolVersion(Player player) {
net.minecraft.server.v1_7_R4.EntityPlayer entityPlayer = ((org.bukkit.craftbukkit.v1_7_R4.entity.CraftPlayer) player).getHandle();
return entityPlayer.playerConnection.networkManager.getVersion();
}
}
Loaded 100 of 105 files, more files were not shown because too many files have changed in this diff. Show more