/toptime

/toptime

Postby ismellike » 30 Apr 2013, 02:44

TopTime

With this command you will be able to see the top ten most active players of the server.

It will filter out the people that are glitched too that have like 174283 hours in.

Code: Select all
using System.Data;
using System;

namespace MCDzienny
{
  public class CmdToptime : Command
  {
    public override string name
    {
      get
      {
        return "toptime";
      }
    }

    public override string shortcut
    {
      get
      {
        return "";
      }
    }

    public override string type
    {
      get
      {
        return "other";
      }
    }

    public override bool museumUsable
    {
      get
      {
        return true;
      }
    }

    public override LevelPermission defaultRank
    {
      get
      {
        return LevelPermission.Banned;
      }
    }
  public CmdToptime()
    {
    }

    public override void Use(Player p, string message)
    {
        int count=0;
        Player.SendMessage(p, "The most active of the server:");
        using (DataTable dataTable = DBInterface.fillData("SELECT * FROM `Players` ORDER BY TotalMinutesPlayed DESC LIMIT 20"))
        {
            for (int index = 0; index < dataTable.Rows.Count; ++index)
            {
                int time = Convert.ToInt32(dataTable.Rows[index]["TotalMinutesPlayed"]) / 60;
                if (count == 10)
                {
                    break;
                }
                if (time>10000)
                {
                    continue;
                }
                else
                {
                    count += 1;
                    Player.SendMessage(p, string.Format("%c{0}.%e {1} - time: {2} hours", (object)(count.ToString()), (object)dataTable.Rows[index]["Name"].ToString(), (object)(time.ToString())));
                }
            }
        }
    }
    public override void Help(Player p)
    {
      Player.SendMessage(p, "/toptime - Displays names of ten most active players.");
    }
  }
}
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: /toptime

Postby xJaso0ox » 30 Apr 2013, 18:21

Nice work. Does it work with both Zombie Survival and Lava Survival?
http://minecraft.net/classic/play/597d26a6d7966e162de9370ea34b6fee
-Owner of: [Jaso] Lava Survival
User avatar
xJaso0ox
 
Posts: 14
Joined: 23 Apr 2013, 21:32

Re: /toptime

Postby ismellike » 30 Apr 2013, 21:43

xJaso0ox wrote:Nice work. Does it work with both Zombie Survival and Lava Survival?


Yes it does, I find it more useful for like lava or freebuild servers though since with zombie you can practically just do /stars top.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: /toptime

Postby snakeyes12 » 03 May 2013, 01:26

Nice!
That one slitherous snake.
snakeyes12
 
Posts: 1
Joined: 15 Apr 2013, 05:25
Location: California, USA

Re: /toptime

Postby ismellike » 05 May 2013, 02:38

Here is an updated version.

It includes colors, and removes the ending of the email addresses.

Code: Select all
using System.Data;
using System;

namespace MCDzienny
{
  public class CmdToptime : Command
  {
    public override string name
    {
      get
      {
        return "toptime";
      }
    }

    public override string shortcut
    {
      get
      {
        return "";
      }
    }

    public override string type
    {
      get
      {
        return "other";
      }
    }

    public override bool museumUsable
    {
      get
      {
        return true;
      }
    }

    public override LevelPermission defaultRank
    {
      get
      {
        return LevelPermission.Banned;
      }
    }
  public CmdToptime()
    {
    }

    public override void Use(Player p, string message)
    {
        int count=0;
        Player.SendMessage(p, "The most active of the server:");
        using (DataTable dataTable = DBInterface.fillData("SELECT * FROM `Players` ORDER BY TotalMinutesPlayed DESC LIMIT 20"))
        {
            for (int index = 0; index < dataTable.Rows.Count; ++index)
            {
                int time = Convert.ToInt32(dataTable.Rows[index]["TotalMinutesPlayed"]) / 60;
                if (count == 10)
                {
                    break;
                }
                if (time > 10000)
                {
                    continue;
                }
                else
                {
                    try
                    {
                        string person = dataTable.Rows[index]["Name"].ToString();
                        if (person.Contains("@"))
                        {
                            person = person.Substring(0, person.LastIndexOf("@"))+"@";
                        }
                        count += 1;
                        Player.SendMessage(p, string.Format("%c{0}. {1} - time: {2} hours", (object)(count.ToString()), (object)(Group.findPlayerGroup(person).color + person+Server.DefaultColor), (object)(time.ToString())));
                    }
                    catch
                    {
                        Player.SendMessage(p, "Database error.");
                    }
                }
            }
        }
    }
    public override void Help(Player p)
    {
      Player.SendMessage(p, "/toptime - Displays names of ten most active players.");
    }
  }
}
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: /toptime

Postby Ultima » 08 May 2013, 14:50

Cache result please.
It doesnt like over 100k players. :|
User avatar
Ultima
 
Posts: 953
Joined: 19 Aug 2011, 23:45

Re: /toptime

Postby ismellike » 08 May 2013, 22:07

Sure, here you go

Code: Select all
using System.Data;
using System;
using System.Collections.Generic;

namespace MCDzienny
{
    public class CmdToptime : Command
    {
        public static List<string> cache = new List<string>();
        public override string name
        {
            get
            {
                return "toptime";
            }
        }

        public override string shortcut
        {
            get
            {
                return "";
            }
        }

        public override string type
        {
            get
            {
                return "other";
            }
        }

        public override bool museumUsable
        {
            get
            {
                return true;
            }
        }

        public override LevelPermission defaultRank
        {
            get
            {
                return LevelPermission.Banned;
            }
        }
        public CmdToptime()
        {
        }

        public override void Use(Player p, string message)
        {
            if (message.ToLower() == "update")
            {
                cache.Clear();
                Player.SendMessage(p, "Toptimes have been updated.");
                return;
            }
            Player.SendMessage(p, "The most active of the server:");
            if (cache.Count != 0)
            {
                foreach (string person in cache)
                {
                    Player.SendMessage(p, person);
                }
            }
            else
            {
                int count = 0;
                using (DataTable dataTable = DBInterface.fillData("SELECT * FROM `Players` ORDER BY TotalMinutesPlayed DESC LIMIT 20"))
                {
                    for (int index = 0; index < dataTable.Rows.Count; ++index)
                    {
                        int time = Convert.ToInt32(dataTable.Rows[index]["TotalMinutesPlayed"]) / 60;
                        if (count == 10)
                        {
                            break;
                        }
                        if (time > 10000)
                        {
                            continue;
                        }
                        else
                        {
                            try
                            {
                                string person = dataTable.Rows[index]["Name"].ToString();
                                if (person.Contains("@"))
                                {
                                    person = person.Substring(0, person.LastIndexOf("@")) + "@";
                                }
                                count += 1;
                                Player.SendMessage(p, string.Format("%c{0}. {1} - time: {2} hours", (object)(count.ToString()), (object)(Group.findPlayerGroup(person).color + person + Server.DefaultColor), (object)(time.ToString())));
                                cache.Add(string.Format("%c{0}. {1} - time: {2} hours", (object)(count.ToString()), (object)(Group.findPlayerGroup(person).color + person + Server.DefaultColor), (object)(time.ToString())));
                            }
                            catch
                            {
                                Player.SendMessage(p, "Database error.");
                            }
                        }
                    }
                }
            }
        }
        public override void Help(Player p)
        {
            Player.SendMessage(p, "/toptime - Displays names of ten most active players.");
            if (p.group.Permission >= LevelPermission.Admin)
            {
                Player.SendMessage(p, "/toptime update - updates the cached results for most active players.");
            }
        }
    }
}
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: /toptime

Postby Stuwie » 05 Jun 2013, 14:12

Wow this is amazing, great work!
Image
User avatar
Stuwie
 
Posts: 78
Joined: 27 Nov 2011, 23:49

Re: /toptime

Postby Ultima » 29 Jul 2013, 18:11

Nothing happens when it try it on a 100k database.
Map server which hasnt have that many works tho.
User avatar
Ultima
 
Posts: 953
Joined: 19 Aug 2011, 23:45


Return to Custom Commands

Who is online

Users browsing this forum: No registered users and 1 guest

cron