PacketInjectorAPI [1.8-1.21.3] - Manage packets easily icon

PacketInjectorAPI [1.8-1.21.3] - Manage packets easily -----

Simple API for managing packets. Powered by LightInjector!



Packet Injector API

Manage packets easily.
If you're running from 1.8.x to the latest version, use the latest release.
If you're running on 1.7.x, use the 1.3.2 release.

Javadoc: https://frengor.com/javadocs/PacketInjectorAPI/build-server/
Jenkins: https://jenkins.frengor.com/job/PacketInjectorAPI/

To listen to packets simply create and register a PacketListener:

Code (Java):
PacketEventManager eventManager = PacketInjectorPlugin. getInstance ( ). getPacketInjectorAPI ( ). getEventManager ( ) ;
eventManager. registerPacketListener (pluginInstance, new PacketListener ( ) {
    @Override
    public void onSend (PacketSendEvent event ) {
        // code
    }

    @Override
    public void onReceive (PacketReceiveEvent event ) {
        // code
    }
} ) ;
PacketInjectorAPI uses LightInjector to inject packets. Therefore, it allows to intercept every packet intercepted by LightInjector, which are every game packet and some login packets. For the latter, a Player instance might not be always available. In this case, calling event.getPlayer() will return null.
See LightInjector javadoc for more information.

Code (Java):
Player player = event. getPlayer ( ) ; // Might be null (see above)
Object packet = event. getPacket ( ) ;
String packetClassName = event. getPacketName ( ) ;
event. setCancelled ( true ) ; // Stops the packet
event. setPacket (newPacket ) ;
Object value = event. getValue ( "fieldName" ) ;
event. setValue ( "fieldName", value ) ;

You can also register send and receive events separately (even using lambdas):
Code (Java):
eventManager. registerPacketSendListener (pluginInstance, event -> {
    // code
} ) ;

eventManager. registerPacketReceiveListener (pluginInstance, event -> {
    // code
} ) ;
Example Usage:

Banning a word:

Code (Java):
public class MainClass extends JavaPlugin {
    @Override
    public void onEnable ( ) {
       PacketEventManager eventManager = PacketInjectorPlugin. getInstance ( ). getPacketInjectorAPI ( ). getEventManager ( ) ;
       eventManager. registerPacketReceiveListener ( this, event -> {
            if (event. getPacketName ( ). equals ( "PacketPlayInChat" ) ) {
                String message = ( String ) event. getValue ( "a" ) ; // Might change between mc versions

                if (message. contains ( "bannedWord" ) ) {
                   event. setCancelled ( true ) ;
                   event. getPlayer ( ). sendMessage ( "§cDon't swear!" ) ;
                }
            }
        } ) ;
    }
}

Commands:
The plugin comes with a packet logger which can print every packet (or only certain packets) to the console. It is managed using the following commands:

Code (YAML):
# Starts the packet logger
/packetinjectorapi packetlogger start

# Stops the packet logger
/packetinjectorapi packetlogger stop

# Prints a message with the status of the packet logger (enabled|disabled)
/packetinjectorapi packetlogger status

# The filter subcommand allows to select the packets to be printed
# More on this down below
/packetinjectorapi packetlogger filter <allow|deny|list|reset|clear> ...
The filter gives you the power to exclude or to include only certain packets from being print. The filter subcommands are the following:
Code (YAML):
# Add, remove, clear or reset to default the list of allowed packets
# Allowed packets are the only ones to be printed to the console, except when they are also denied
/packetinjectorapi packetlogger filter allow <add|remove|clear|reset> ...

# Add, remove, clear or reset to default the list of denied packets
# Denied packets are not printed to the console
# By default, the deny list contains some packets to prevent the flooding of the console, run the "clear" subcommand if you need those packets
# The list of default denied packets can be seen using the "list" filter subcommand or can be found at this link:
# https://github.com/frengor/PacketInjectorAPI/blob/main/src/main/java/com/fren_gor/packetInjectorAPI/Commands.java#L50
/packetinjectorapi packetlogger filter deny <add|remove|clear|reset> ...

# Lists the allowed and denied packets
/packetinjectorapi packetlogger filter list

# Resets the allowed and denied lists to their default values
/packetinjectorapi packetlogger filter reset

# Clears the allow and deny lists
/packetinjectorapi packetlogger filter clear

Maven:
HTML:
<repositories>
    <repository>
        <id>fren_gor </id>
        <url>https://nexus.frengor.com/repository/public/ </url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>com.frengor </groupId>
        <artifactId>packetinjectorapi </artifactId>
        <version>3.2.1 </version>
        <scope>provided </scope>
    </dependency>
</dependencies>
Bugs should be reported opening an issue on GitHub.
BUG REPORTS IN THE REVIEWS WILL NOT BE CONSIDERED!

For bugs: GIT HUB

Metrics
Resource Information
Author:
----------
Total Downloads: 4,537
First Release: Jun 20, 2018
Last Update: Oct 26, 2024
Category: ---------------
All-Time Rating:
2 ratings
Version -----
Released: --------------------
Downloads: ------
Version Rating:
----------------------
-- ratings