1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Adding to an array faster than PureChat setting nametag

Discussion in 'Development' started by Levi, Jun 10, 2018.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    I have something that counts how many kills do you have, it adds you to an array onPlayerJoinEvent if you are not in there already. I have the kills in PureChat(nametag) PureChat sets your nameTag when you join right. So I get errors when PureChat sets the nametag faster than my kill counter that adds player to array on playerjoinevent.
     
  2. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    You've posted a lot recently... I'd have thought you'd have got the message by now that you need to include detail when asking for help: where is the code, and what are the errors?
     
  3. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    public static $kills = [];
    PHP:
    public function onJoin(PlayerJoinEvent $event)
        {
            
    $uuid $event->getPlayer()->getUniqueId();
            if (!
    in_array(strtolower($uuid), API::$kills)) {
                
    API::$kills[strtolower($uuid)] = 0;
            }
        }
     
    Last edited: Jun 10, 2018
  4. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    That's just a snippet... Now, what is the error?
     
  5. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    https://pastebin.com/szexvXu3
    API:line126
    public static function getKills(Player $player)
    {
    $uuid = strtolower($player->getUniqueId());
    return self::$kills[$uuid];
    }
     
  6. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    Why do you only post snippets, and not use code blocks (the little + on the toolbar)? I found some of the relevant code in your other post, but you'd make life easier for everyone if you just posted the full code on github. For starters, why is getKills() a static method? Static methods are stateless - that means if you call them with a given argument you must always get the same return value...
     
    Last edited: Jun 10, 2018
    EdwardHamHam likes this.
  7. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    Static is cool
     
  8. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    I give up.
     
    RyanShaw, Angel, SleepSpace9 and 2 others like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.