API PingAPI [UPDATED]: Listen for and modify outgoing ping responses

Discussion in 'Resources' started by Skionz, May 22, 2019.

Thread Status:
Not open for further replies.
  1. Offline

    Skionz

    [​IMG]
    PingAPI lets you listen for outgoing PacketStatusOutServerInfo packets and allows you to easily modify them.

    It has been a few years since I have worked on this project, but I decided to update it for newer versions of CraftBukkit and keep backwards compatibility. I will try to keep it maintained and up to date from now on. The most important change to note is that creating animations is no longer possible for servers running newer versions of CraftBukkit.

    What can it do?
    Images (open)

    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    Note: Animations can only be made using 1.8 or before

    Links
    - GitHub

    - Javadocs
    - Download

    Usage
    To use PingAPI you have to create a Listener. This is similar to registering a Bukkit listener. Before we actually register it we need to create it. You can either create a new class that implements PingListener, or just an anonymous inner class. Here is a simple example of a PingListener

    Code:
    public class MyListener implements PingListener {
    
        public void onPing(PingEvent event) {
            event.getReply().setOnlinePlayers(5000);
        }
    }
    Now that we have created the PingListener we need to actually register it. You can do so by invoking the static method 'PingAPI.registerListener(PingListener).' Here is an example using an anonymous inner class.
    Code:
    public class MyPlugin extends JavaPlugin {
    
       public void onEnable() {
            PingAPI.registerListener(new PingListener() {
                public void onPing(PingEvent event) {
                    event.getReply().setOnlinePlayers(5000);
                }
            }
        }
    }
    There are more tutorials on GitHub. I also included some simple example plugins, FakePlayers and PingText, that are available to download on Bukkit. The source for these plugins can be found here.

    I decided to create this new thread so I could explain a few new changes and leave it open for discussion since the old thread was locked.

     
    Shqep and Zombie_Striker like this.
Thread Status:
Not open for further replies.

Share This Page