How to get a players ping?

Discussion in 'Plugin Development' started by WolfMaster, Jun 21, 2013.

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

    WolfMaster

    Literally what the title says.

    Can anyone tell me how to get a players ping?

    I have tried to much but failed so hard
     
  2. Offline

    chasechocolate

    I think it is something like this (I'm not sure if it returns an integer, though):
    Code:java
    1. int ping = ((CraftPlayer) player).getHandle().ping;

    EDIT: Yes, it returns an integer (source).
     
  3. Offline

    WolfMaster

    I will give it a shot now

    I am try to use this in a command and its not working D:

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 2, 2016
  4. Offline

    chasechocolate

    What is your code? You have to add CraftBukkit to your build path to use NMS code.
     
  5. Offline

    WolfMaster

    So you need to add the bukkit api and the craftbukkit jar?

    My code without the command is

    Code:java
    1. package assassinhero.bukkit.pingitup;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class Main extends JavaPlugin{
    11.  
    12. Logger logger = Logger.getLogger("Minecraft");
    13.  
    14. public void onEnable(){
    15. getLogger().info("PingItUp Has Been Enabled!");
    16. }
    17.  
    18. public void onDisable(){
    19. getLogger().info("PingItUp Has Been Disabled!");
    20. }
    21.  
    22. public boolean onCommand (CommandSender sender, Command command, String label, String[] args){
    23. Player player = (Player) sender;
    24. if(command.getName().equalsIgnoreCase("SPing")){ }
    25. return true;
    26. }
    27. }
    28.  


    Pretty much very simple code up to now
     
  6. Offline

    chasechocolate

    WolfMaster yes, you need to add CraftBukkit to your build path. Get the latest recommended build here.
     
    WolfMaster likes this.
  7. Offline

    WolfMaster

    Yes! Thank you. This has worked!! I was looking for so long. haha
     
  8. Offline

    themadman300

    How would you get CraftBukkit 1.5.2 on maven?
     
  9. Offline

    WolfMaster

    I have no idea, I use eclipse
     
  10. Offline

    Cybermaxke

    themadman300
    Code:
    <repositories>
        <repository>
            <id>bukkit-repo</id>
            <url>http://repo.bukkit.org/</url>
        </repository>
    </repositories>
     
    <dependencies>
        <dependency>
            <groupId>org.bukkit</groupId>
            <artifactId>craftbukkit</artifactId>
            <version>1.5.2-R0.1</version>
        </dependency>
    </dependencies>
     
Thread Status:
Not open for further replies.

Share This Page