Code Monkey home page Code Monkey logo

packetlistener's Introduction

Packet Listener

This library for Bukkit allows you to have greater control over the packets sent and received on the server. You can modify packet, execute actions and cancel the packet.

It allows packets to be retrieved in an event system similar to that of Bukkit. You can also pause the program while waiting for a packet to be sent or received.

Note: This library is currently only compatible with Minecraft 1.18.2.

How to use it ?

Listener

First, you need to tell the api which classes contain handlers. This action is usually in the JavaPlugin#onEnable().

PacketListener.registerListeners(this, ServerboundPackets.class, ClientboundPackets.class, ...);

Afterwards, to create a handler you must create a method in public static void with the annotation @PacketHandler and in parameter PacketEvent<?> by replacing the ? by the desired packet, or leave it if you want your method to handle all packets.

@PacketHandler
public static void inChat(PacketEvent<ServerboundChatPacket> event) {
    // do something
    // you can prevent the packet from being sent or received with
    event.setCancelled(true);
}

Waiting a packet

This API also allows you to wait for a packet through a blocking method

PacketListener.waitPacket(ServerboundSignUpdatePacket.class /* The packet class */,
        Bukkit.getPlayer("DailyCraft") /* The player */,
        event -> {} /* A Consumer with a PacketEvent for make actions with the packet */,
        1000 /* A timeout in ms. Note: this arg is optional */);

And there's also PacketListener.waitPacketAsync(...) so the method isn't blocking because running in an async thread. Note: The arguments are the same except that you must add the instance of your JavaPlugin class as the first argument.

Example

You can find an example here

packetlistener's People

Contributors

dailycraft avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.