Ping Glitch

Discussion in 'Plugin Development' started by tvtad202020, Jun 26, 2017.

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

    tvtad202020

    i've made a ping plugin , and i want when i write /ping it shows to messages and wait for 4500 M.s and give him real ping like big servers , i made this
    sender.sendMessage("§8§l┃ §a§lBlocks§e§lMC §8┃ §aCalculating your ping, please wait...");
    try
    {
    Thread.sleep(4500L);
    }
    catch (InterruptedException ex)
    {
    Thread.currentThread().interrupt();
    }
    sender.sendMessage("§8§l┃ §a§lBlocks§e§lMC §8┃ §aYour latency (ping) is: §a" + RealPing.getPing((Player)sender));
    --------
    but when i do that it stop the server for 4500L , i want to send the first to messages after that the realpingmessages , thx.
     
  2. Offline

    InstanceofDeath

    Well I really didn't understand what you are trying to tell, just step your grammar up a bit.

    But one thing is more than clear: NEVER NEVER use the the Thread#sleep() Method in one of your plugins!

    Switch it out with this Codesnippet

    Code:java
    1.  
    2. // Put your first Message here
    3.  
    4. Bukkit.getScheduler.runTaskLater(this, new Runnable() {
    5.  
    6. @Override
    7. public void run() {
    8. // Put your second Message here
    9. }
    10.  
    11. }, 4.5 * 20L);
    12.  
     
  3. Offline

    tvtad202020

    i meant that in big servers like HiveMc , when i type /ping it gives me
    ! Pong
    ! Calculating your ping
    and no thing happen for 4 seconds after that it tells me my ping
    ! your ping is : ..
    that i meant i want to wait for 4 seconds after that i want it to tell me the ping ,, i don't want to use Runnable :/
    @InstanceofDeath
     
  4. Offline

    Zombie_Striker

    @tvtad202020
    Unless you have a terrible connection, it should not take four seconds to calculate the ping. Instead, just use this:
    Code:
        int ping = ((CraftPlayer) player).getHandle().ping;
    Note, this is version dependent, but this should work if you are building this plugin for only your server.
     
  5. Offline

    tvtad202020

    I mean send the 2 messages after that send the ping message like
    !Pong
    !Calculate your ping
    Nand here i want not to do anything after 4 seconds without doing thing send this msg
    !your ping is **
    And i have the code to calculate i just dont now how to make the plugin wait 4 seconds and send the last msg *ping msg*
    @Zombie_Striker
     
  6. For the thing you want to do, you HAVE to use BukkitRunnable, because if you don't, it's going to block your server from functioning while it's gonna wait for those 4 seconds. If you put it in a runnable, it's not going to block your server and it's still going to reply in 4500ms if you set it to.

    If you have any more questions, tag me.

    Sent from my Xperia M4 Aqua using Tapatalk
     
  7. Offline

    tvtad202020

  8. Offline

    InstanceofDeath

    Dude I alread wrote it to you. It is exactely what he mentioned
     
  9. Offline

    tvtad202020

    okay , another Question sorry , how can i add a team in the display name of a scoreboard?
     
  10. Offline

    InstanceofDeath

    Lol you need to describe this "better". Do you want to add a Team Scoreboard and add players to it? Or do you want that every player in a team has a scoreboard on a sidebar with the display name of that team?
     
  11. For different questions you should create a new thread.

    Sent from my Xperia M4 Aqua using Tapatalk
     
  12. Offline

    tvtad202020

Thread Status:
Not open for further replies.

Share This Page