API PingAPI: Listen for and modify outgoing ping responses

Discussion in 'Resources' started by Skionz, Feb 7, 2015.

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

    UniqueNameDen

    Yah, also now I managed it to make it send 2 packets, no matter what I do it only sends 2, no more do I cancel "pong" wrongly...?
    CODE:
    http://pastebin.com/EdEfcr5p

    ALSO: in code
    1. public class TestListener implements PingListener {
    2. public void onPing(PingEvent event) {
    3. ServerInfoPacket packet = event.createNewPacket(event.getReply());
    4. packet.send();
    5. reply.setCancelled(true);
    6. }
    7. }
    From were did you get reply, or is it a mistake
     
    Last edited: Feb 25, 2015
  2. Offline

    ChipDev

    I love you!
     
    Skionz likes this.
  3. Offline

    Anbo1982

    When i try to install it on my latest spigot 1.8.3 i get:

    [13:51:48] [Server thread/INFO]: [PingAPI] Enabling PingAPI v0.1.5
    [13:51:48] [Server thread/WARN]: java.lang.ClassNotFoundException: com.skionz.pingapi.v1_8_R2.PingInjector
    [13:51:48] [Server thread/WARN]: at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    [13:51:48] [Server thread/WARN]: at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    [13:51:48] [Server thread/WARN]: at java.security.AccessController.doPrivileged(Native Method)
    [13:51:48] [Server thread/WARN]: at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    [13:51:48] [Server thread/WARN]: at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:101)
    [13:51:48] [Server thread/WARN]: at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:86)
    [13:51:48] [Server thread/WARN]: at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    [13:51:48] [Server thread/WARN]: at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    [13:51:48] [Server thread/WARN]: at java.lang.Class.forName0(Native Method)
    [13:51:48] [Server thread/WARN]: at java.lang.Class.forName(Class.java:186)
    [13:51:48] [Server thread/WARN]: at com.skionz.pingapi.PingAPI.onEnable(PingAPI.java:18)
    [13:51:48] [Server thread/WARN]: at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321)
    [13:51:48] [Server thread/WARN]: at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:335)
    [13:51:48] [Server thread/WARN]: at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405)
    [13:51:48] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_8_R2.CraftServer.loadPlugin(CraftServer.java:356)
    [13:51:48] [Server thread/WARN]: at org.bukkit.craftbukkit.v1_8_R2.CraftServer.enablePlugins(CraftServer.java:316)
    [13:51:48] [Server thread/WARN]: at net.minecraft.server.v1_8_R2.MinecraftServer.r(MinecraftServer.java:416)
    [13:51:48] [Server thread/WARN]: at net.minecraft.server.v1_8_R2.MinecraftServer.k(MinecraftServer.java:382)
    [13:51:48] [Server thread/WARN]: at net.minecraft.server.v1_8_R2.MinecraftServer.a(MinecraftServer.java:337)
    [13:51:48] [Server thread/WARN]: at net.minecraft.server.v1_8_R2.DedicatedServer.init(DedicatedServer.java:257)
    [13:51:48] [Server thread/WARN]: at net.minecraft.server.v1_8_R2.MinecraftServer.run(MinecraftServer.java:522)
    [13:51:48] [Server thread/WARN]: at java.lang.Thread.run(Thread.java:722)
     
  4. Offline

    Skionz

    It hasn't been updated.
     
  5. Offline

    UniqueNameDen

    @Anbo1982 you can easily update it your self by adding v1_8_R2 coping over contents from v1_8_R1 and changing the imports
     
  6. Offline

    Skionz

    If it was that easy I would have updated it by now.
     
  7. Offline

    UniqueNameDen

    I did that fixed errors and it works for me?
     
  8. Offline

    Skionz

    Everything should work besides animations which seem to be the most popular reason for using this API.
     
  9. Offline

    UniqueNameDen

    I can only send 2 packets /w the 1.8.3 version... I guess mojang cuts down the connection after 2 packets now...
     
  10. Offline

    Skionz

    There is a field that represents the status of the ping and is incremented when certain packets are sent, or received and when the integer is three it closes the connection. I'm not entirely sure on the specifics, but there isn't a good, clean solution so I may get rid of the feature.
     
  11. Offline

    UniqueNameDen

    Maybe make it always force opened by default and add ping.closeConnection();

    EDIT: I decompiled animatedMOTDD from spigot he uses a packet spam to keep the connection open
     
  12. Offline

    Skionz

    It's an issue with Mojang's NMS.
     
  13. I've been looking into it for a bit, and I found a fix for that it only works twice. Go into the DuplexHandler class and override the close(ChannelHandlerContext, ChannelPromise) method, and only call the super method if the pong isn't cancelled. Here's how it looks for me:
    Code:
    @Override
        public void close(ChannelHandlerContext ctx, ChannelPromise future) throws Exception {
            if(this.event == null || !this.event.isPongCancelled())
                super.close(ctx, future);
        }
    Edit: Null Check
     
    Last edited: Apr 14, 2015
  14. Offline

    Skionz

    I'll look into it later tonight, but this looks really promising!
     
  15. Hey, is there a Maven repo for this? I'd love to use this but my project's a maven project.
     
  16. Offline

    teej107

    Use the code tags
     
    Skionz likes this.
  17. Offline

    Skionz

    Delayed tasks
     
    raton023 likes this.
  18. Offline

    teej107

    code tags on this site

    Code:
    Like this! This makes code easier to read.
    There is a button for it on the text editor where you post.
     
  19. Offline

    raton023

    Is working but it is paused like 5 seconds and then do the motd to fast and again 5 sec and do it to fast

    public class Main extends JavaPlugin {
    @Override
    public void onEnable() {
    PingAPI.registerListener(new PingListener() {
    public void onPing(PingEvent event) {
    event.cancelPong(false);
    ServerInfoPacket packet = event.createNewPacket(event.getReply());
    event.getReply().setOnlinePlayers(5000);
    List<String> sample = new ArrayList<String>();
    sample.add(ChatColor.BLUE + "GenericCraft");
    sample.add("-------------------------");
    sample.add(ChatColor.GOLD + "New game thing available");
    sample.add(ChatColor.AQUA + "Join for free stuff now!");
    event.getReply().setPlayerSample(sample);
    event.getReply().setMOTD(ChatColor.RED + "as sdsad dlf");
    packet.send();
    event.getReply().setMOTD(ChatColor.BLUE + "HO sd sdf I");
    packet.send();
    event.getReply().setMOTD(ChatColor.RED + "as asdasd wewdlf");
    packet.send();
    event.getReply().setMOTD(ChatColor.BLUE + "H asdas OI");
    packet.send();
    event.getReply().setMOTD(ChatColor.RED + "asd asdasd sadaslf");
    packet.send();
    event.cancelPong(true);
    timer(event);
    }});}
    protected void timer(final PingEvent event) {
    Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    @Override
    public void run() {
    onEnable();
    }}, 40, 100);}

    }


    the code from above is using delayed task and working but it holds 5 seconds and do the motd to fast, and again and again

    how can we improve this code, any insight?



    if (helm.getType() == Material.397::)") {
    p.sendMessage("Hello!");
    }
     
    Last edited by a moderator: Apr 27, 2015
  20. Offline

    teej107

    I can help when I find your code readable.
     
  21. Offline

    raton023

    I will add a loop lets see what happens :)
     
  22. @raton023
    First of all, you put that timer to call onEnable each 10 seconds, which means you register the listener each time, I wouldn't do that, because that might end up in a memory leak. Second, you need to put a delay between the sending, all you're doing is send it in the same method without a delay, just create a delayed/repeating task when the event is called and set the motd after each delay.
     
  23. Offline

    raton023

    you are right with the onEnable thing !!! I will check it out and fix that xD let's see what happen xD
    I'll work that out pal.
     
  24. Offline

    BagduFagdu

    @Skionz is it possible to get the player involved in the PingEvent?
     
  25. Offline

    Gamecube762

    @BagduFagdu You can grab the IP.
    If you create your own system that logs IPs, you can then check if the IP that Pinged is an IP that you have saved. From there, you can grab the matching Username or UUID(whichever you saved).
     
    BagduFagdu likes this.
  26. Offline

    Krumb069

    Is it working on 1.8.6 ?
     
  27. Offline

    ShadowBoy_

    Can you help me? which of the codes I use to be able to change the color of the number of online players?
     
  28. @Krumb069
    Yes, unless you want animated stuff, for that you need to do some special stuff yourself.
    @ShadowBoy_
    On the main page is a spoiler which says "Changing the player count to text", you can call Bukkit.getOnlinePlayers() and Bukkit.getMaxPlayers() or something
     
  29. Offline

    Krumb069

    @megamichiel
    Another question is it working on bukkit 1.7.10/1.7.2 or spigot 1.7-1.8 ?
     
  30. @Krumb069
    It works from version 1.7.9-1.8, I think only supports spigot because Craftbukkit doesn't have the method getServerConnection() in the MinecraftServer class.
     
Thread Status:
Not open for further replies.

Share This Page