Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PlayerStats 2.1

Statistic of player on your database now!

  1. vvzar
    Offline

    vvzar New Member

    Joined:
    Mar 21, 2015
    Posts:
    40
    Hey, xpyctum.
    What is the problem:
    [CRITICAL] "Could not pass event 'pocketmine\event\player\PlayerJoinEvent' to 'PlayerStats v2': mysqli::query(): MySQL server has gone away on PlayerStats\PlayerStats"
    10:43:13 [WARNING] RuntimeException: "mysqli::query(): MySQL server has gone away" (E_WARNING) in "/PlayerStats_v2.0.phar/src/PlayerStats/PlayerStats" at line 311
    ?
    Самопроизвольно в консоль сыпет (периодически). Сервер не падает. Что-то при коннекте игроков происходит?
  2. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Your MySQL disconnected.
    How can I show all the player stats on a website? Like when someone logs in to the website with my auth plugin server auth, they can see their own statistics.
  3. vvzar
    Offline

    vvzar New Member

    Joined:
    Mar 21, 2015
    Posts:
    40
    But my mysql server runs on localhost and at the same time another services working good with their own databases.
    All looks normal and database query start working after i use "reload" server command in console
  4. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
  5. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    For those who have been requesting a way to include the PlayerStats Data on your servers website below is a class that I threw together that will allow you to do this.
    PHP:
    <?php
        
    class PlayerStats {
            public static function 
    getPlayerStats($user) {
                
    $host "localhost";
                
    $username "root";
                
    $password "password";
                
    $dbname "database";
                
    $port 3306;
                 
                
    $data = [];
                
    $user strtolower($user);
                
    $conn = new mysqli($host$username$password$dbname$port);
                if (
    $conn->connect_error) {
                    die(
    '<script>alert("It seems we are having some issues getting the required info from our database for you.  Please check back later! (Error Code: '$conn->errno .')");</script>');
                }
                 
                
    $sql "SELECT * FROM player_stats WHERE name = '"$user."'";
                
    $result $conn->query($sql);
                 
                if(
    $result->num_rows 0) {
                    while(
    $row $result->fetch_assoc()) {
                        
    $data $row;
                    }
                } else
                    
    $data null;
                
    $conn->close();
                return 
    $data;
            }
        }
    To use it just fill out the variables at the top with your database info then use include(); or require(); to add it to the needed pages.
    To get the players info do PlayerStats::getPlayerStats("Steve"); to get Steves player statistics as an array.
    If you have any questions about this class feel free to ask.
    Last edited: Jun 20, 2015
    vvzar likes this.
  6. vvzar
    Offline

    vvzar New Member

    Joined:
    Mar 21, 2015
    Posts:
    40
    have crash:
    Error: Call to a member function getCause() on null
    File: /PlayerStats_v2.1.phar/src/PlayerStats/PlayerStats
    Line: 356
    Type: E_ERROR

    THIS CRASH WAS CAUSED BY A PLUGIN
    BAD PLUGIN: PlayerStats v2.1

    Code:
    [347] }
    [348]
    [349] /**
    [350] * @param PlayerDeathEvent $event
    [351] */
    [352] public function DeathEvent(PlayerDeathEvent $event){
    [353] $victim = $event->getEntity();
    [354] if($victim instanceof Player){
    [355] $this->db->query("UPDATE player_stats SET deaths = deaths +1 WHERE name = '".strtolower($this->db->escape_string($event->getEntity()->getPlayer()->getDisplayName()))."'");
    [356] $cause = $event->getEntity()->getLastDamageCause()->getCause();
    [357] if($cause == 1){
    [358] $killer = $event->getEntity()->getLastDamageCause()->getEntity();
    [359] if($killer instanceof EntityDamageByEntityEvent){
    [360] $this->db->query("UPDATE player_stats SET kills = kills +1 WHERE name = '".strtolower($this->db->escape_string($killer))."'");
    [361] }
    [362]
    [363] }
    [364] }
    [365] }
    [366]

    Backtrace:
    #0 (): pocketmine\Server->crashDump()

    PocketMine-MP version: 1.5dev #1252 [Protocol 27; API 1.12.0]
    Git commit: 0000000000000000000000000000000000000000
    uname -a: Linux mpe 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64
    PHP Version: 5.6.4
    Zend version: 2.6.0
    OS : Linux, linux
  7. vvzar
    Offline

    vvzar New Member

    Joined:
    Mar 21, 2015
    Posts:
    40
    Thank You very much!! It is really cool thing!
    Some questions here:
    Only by $user can be selected data?

    Is there must be $dbname variable, not player_stats ?

    Sorry for my english
  8. DA_Swagnemite
    Offline

    DA_Swagnemite Notable Member Plugin Developer

    Joined:
    Nov 17, 2013
    Posts:
    386
    Plugins:
    7
    Minecraft User:
    DA_SWAGNEMITE
    Since the database name is player_stats I went ahead and set up the sql system for you. The only thing you need to provide to the function is the correct database info and a string of the users name. It will do the rest.

    Edit: the function returns an array of all of the columns
    vvzar likes this.
  9. vvzar
    Offline

    vvzar New Member

    Joined:
    Mar 21, 2015
    Posts:
    40
    Some server crash here.
    Error: Call to a member function getCause() on null
    File: /PlayerStats_v2.1.phar/src/PlayerStats/PlayerStats
    Line: 356
    Type: E_ERROR

    THIS CRASH WAS CAUSED BY A PLUGIN
    BAD PLUGIN: PlayerStats v2.1

    Code:
    [347] }
    [348]
    [349] /**
    [350] * @param PlayerDeathEvent $event
    [351] */
    [352] public function DeathEvent(PlayerDeathEvent $event){
    [353] $victim = $event->getEntity();
    [354] if($victim instanceof Player){
    [355] $this->db->query("UPDATE player_stats SET deaths = deaths +1 WHERE name = '".strtolower($this->db->escape_string($event->getEntity()->getPlayer()->getDisplayName()))."'");
    [356] $cause = $event->getEntity()->getLastDamageCause()->getCause();
    [357] if($cause == 1){
    [358] $killer = $event->getEntity()->getLastDamageCause()->getEntity();
    [359] if($killer instanceof EntityDamageByEntityEvent){
    [360] $this->db->query("UPDATE player_stats SET kills = kills +1 WHERE name = '".strtolower($this->db->escape_string($killer))."'");
    [361] }
    [362]
    [363] }
    [364] }
    [365] }
    [366]
  10. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Code:
    [05:35:06] [Server thread/INFO]: Enabling PlayerStats v2.1
    [05:35:06] [Server thread/WARNING]: RuntimeException: "mysqli::mysqli(): (HY000/2002): Connection refused" (E_WARNING) in "/PlayerStats_v2.1.phar/src/PlayerStats/PlayerStats" at line 64
    [05:35:06] [Server thread/INFO]: Disabling PlayerStats v2.1
    
    Database setting correct in the config!
  11. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    You did not open up my sql to the world...
  12. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    What do you mean??
  13. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
  14. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I mean that maybe you did not give permission?
  15. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
  16. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    I had same idea month ago :D
    Legoboy0215 likes this.
  17. Radix
    Offline

    Radix Active Member

    Joined:
    Jul 2, 2015
    Posts:
    211
    Minecraft User:
    Dicks123
    Primus PM Me
  18. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    I made a pull...
  19. Radguy23
    Offline

    Radguy23 Active Member

    Joined:
    Aug 14, 2015
    Posts:
    74
    Minecraft User:
    TheAwesomeCrew27
    Commands?
  20. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    >This plugin saves STATS...

Share This Page

Advertisement