Solved [Bug solved, not question]Question about OfflinePlayer

Discussion in 'Plugin Development' started by Kilorbine, Apr 2, 2016.

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

    Kilorbine

    Hi dude,
    I have a little bug/question.

    I'm making an uhc plugin, and I've made my code to handle player disconnection/reconection.
    Every instance of player is an OfflinePlayer.
    Before every action, I check if player is online as well, but i've went against a bug :

    When player are in same team, the have a private chat.
    It works well, until I disconect/reconect one of my player...

    Here's the code which handle that :


    Code:
    for (int i = 0; i < playerinTheTeam.size(); i++)
     {
      System.out.println("nom : " + playerinTheTeam.get(i).getName());
      System.out.println(Boolean.toString(playerinTheTeam.get(i).isOnline()));
      if (playerinTheTeam.get(i).isOnline())
         playerinTheTeam.get(i).getPlayer().sendMessage("<" + sender.getDisplayName() + ">" + str);
     }
    
    Here is my log :

    Code:
    [19:35:35 INFO]: taille : 2
    [19:35:35 INFO]: nom : Aredos
    [19:35:35 INFO]: true
    [19:35:35 INFO]: nom : jc
    [19:35:35 INFO]: true
    So, I get that : there is 2 player in the team, as well.
    The first one name is Aredos, and is connected.
    The second is Jc and is connected.
    Aredos get the message, but Jc(who disconect/reconnect) doesn't

    Just... Why?
    Is it getPlayer() that do bullshit?
    Or the offlinePlayer that bug when the player disconnect?

    If you have an idea, i take it...
     
  2. Offline

    mcdorli

    System.out.println can take in any types of argument, you don't need the Boolean.toString

    Post the full code
     
  3. Offline

    Kilorbine

    playerinTheTeam is a List<OfflinePlayer>
    The full code is wayy too long.
     
  4. Offline

    WolfMage1

    And dont store player objects unless your handing them correctly on disconnect (Or just use WeakReference)
     
  5. Offline

    Kilorbine

    I Store offlinePlayer and I always check if he is conected before doing anything.
    Do you any idea of what player don't get the message?
     
  6. Offline

    mcdorli

    It's not about checking if it is online, it's about memory, if you don't remove the players from the hashmap, if they disconnect, then that will cause ram leaks

    You need to delay everything with 1 tick, use a scheduler.
     
  7. Offline

    Kilorbine

    You mean that OfflinePlayer won't be good if player disconnect/reconnect?
     
  8. Online

    timtower Administrator Administrator Moderator

    @Kilorbine He means that your plugin will have the potentional to increase the memory usage on the server when you don't want that.
     
  9. Offline

    Kilorbine

    Ho...
    I will kick them...
    If they don't reconnect after 5minutes, I kick them.
    And, by the way, I add them in the list only if the game has begun.
    And player can't join during a game (exept if it's a reconection)
    That's mean at maximum, I will have 60 OfflinePlayer in this list ;)
     
  10. Online

    timtower Administrator Administrator Moderator

    @Kilorbine Kicking them is the thing that will increase the memory usage.
    Use UUID's instead. You don't need the offlineplayer object.
     
    Kilorbine likes this.
  11. Offline

    Kilorbine

    That's what i've done ^^
    Still asking for mysel what player didn't get message with the offlineplayer...
     
  12. You can't send a message to an OfflinePlayer. As a lot of people have said - use UUIDs then get the player from their UUID.

    Astrophylite.
     
Thread Status:
Not open for further replies.

Share This Page