Shading PacketEvents - retrooper/packetevents GitHub Wiki

Learn how to safely shade PacketEvents by following this guide. Make sure to follow each step to avoid any issues.

Step 1 - Get the Maven/Gradle dependency

Using Maven

Add this repository to your pom.xml

<repository>
    <id>codemc-releases</id>
    <url>https://repo.codemc.io/repository/maven-releases/</url>
</repository>

Add the packetevents dependency to your pom.xml.
Replace PLATFORM with the platform you are developing for. (Supported platforms: spigot, bungeecord or velocity)

<dependency>
    <groupId>com.github.retrooper.packetevents</groupId>
    <artifactId>PLATFORM</artifactId>
    <version>2.3.0</version>
    <scope>compile</scope>
</dependency>

Using Gradle

Add this repository to your build.gradle

maven { url 'https://repo.codemc.io/repository/maven-releases/' }

Add the packetevents dependency to your build.gradle
Replace PLATFORM with the platform you are developing for. (Supported platforms: spigot, bungeecord or velocity)

implementation 'com.github.retrooper.packetevents:PLATFORM:2.3.0'

Step 2 - Relocate PacketEvents packages

Now that you have the dependency, you can use the maven-shade-plugin(on Maven) or shadowJar(on Gradle) to shade this dependency. Please relocate the following packetevents packages to avoid issues with multiple projects shading the library. Pick unique packages.

com.github.retrooper.packetevents -> me.username.firstplugin.packetevents.api
io.github.retrooper.packetevents -> me.username.firstplugin.packetevents.impl

The relocated packages I made up are just examples, you may pick whatever you wish.

Step 3 - (Optional) Minimize PacketEvents

You can minimize the dependency to save space. Classes you don't use will not be shipped with your plugin allowing you to have a much smaller jar. This should clear up the packet wrappers you aren't using. On Gradle you insert a minimize() inside the shadowJar task. On Maven you can set <minimizeJar> to true in your maven-shade-plugin configuration.

Step 4 - Add necessary Soft-Depends (Only applies to the Spigot module)

If you are developing a Spigot/Paper/etc server plugin, read this carefully. You are going to want to open up your plugin.yml and soft-depend these plugins:

softdepend:
  - ProtocolLib
  - ProtocolSupport
  - ViaVersion
  - ViaBackwards
  - ViaRewind
  - Geyser-Spigot

This ensures that our injector is loaded last and will therefore operate correctly.

Discord Server

If you need any more support, consider joining the discord server: https://discord.gg/prqzNg9tRU

⚠️ **GitHub.com Fallback** ⚠️