forked from ClassiCube/MCGalaxy-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CmdBiggestTables.cs
38 lines (30 loc) · 1.19 KB
/
CmdBiggestTables.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Collections.Generic;
using MCGalaxy;
using MCGalaxy.SQL;
public sealed class CmdBiggestTables : Command
{
public override string name { get { return "BiggestTables"; } }
public override string type { get { return CommandTypes.Information; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
struct TableEntry { public string Name; public int Count; }
public override void Use(Player p, string message) {
List<string> tables = Database.Backend.AllTables();
TableEntry[] entries = new TableEntry[tables.Count];
for (int i = 0; i < tables.Count; i++) {
try {
string maxID = Database.ReadString(tables[i], "MAX(_ROWID_)", "LIMIT 1");
if (maxID == null || maxID == "") continue;
int count;
if (!int.TryParse(maxID, out count) || count == 0) continue;
entries[i] = new TableEntry() { Name = tables[i], Count = count };
} catch {
}
}
Array.Sort<TableEntry>(entries, (a, b) => b.Count.CompareTo(a.Count));
for (int i = 0; i < Math.Min(20, entries.Length); i++) {
p.Message("Table {0} has {1} entries", entries[i].Name, entries[i].Count);
}
}
public override void Help(Player p) { }
}