-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMPlayer.cs
71 lines (62 loc) · 1.79 KB
/
MPlayer.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Drawing;
using Terraria;
using Hooks;
using MySql.Data.MySqlClient;
using TShockAPI;
using TShockAPI.DB;
using System.ComponentModel;
namespace MessagePlugin
{
public class MPlayer
{
public int Index { get; set; }
public TSPlayer TSPlayer { get { return TShock.Players[Index]; } }
public MPlayer(int index)
{
Index = index;
}
//PLAYER TOOLS
// Return player by ID
public static MPlayer GetPlayerById(int index)
{
foreach (MPlayer player in MessagePlugin.Players)
{
if (player != null && player.Index == index)
return player;
}
return null;
}
// Return player by Name
public static MPlayer GetPlayerByName(string name)
{
var player = TShock.Utils.FindPlayer(name)[0];
if (player != null)
{
foreach (MPlayer ply in MessagePlugin.Players)
{
if (ply.TSPlayer == player)
{
return ply;
}
}
}
return null;
}
// Return player from TShock db
public static int GetPlayerInDb(string name)
{
int ply = 0;
if (name != null)
{
List<SqlValue> where = new List<SqlValue>();
where.Add(new SqlValue("Username", "'" + name + "'"));
ply = TDb.SQLEditor.ReadColumn("Users", "Username", where).Count;
return ply;
}
return ply;
}
}
}