forked from OMARATION/mcforge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ban.cs
142 lines (138 loc) · 5.53 KB
/
Ban.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
Copyright 2011 MCForge
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
http://www.opensource.org/licenses/ecl2.php
http://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace MCForge
{
public static class Ban
{
/// <summary>
/// with Ban you can check the info about someone's ban, find out if there's info about someone, and add / remove someone to the baninfo (NOT THE BANNED.TXT !)
/// </summary>
/// <param name="p">The player who executed the command</param>
/// <param name="who">The player that's banned</param>
/// <param name="reason">The reason for the ban</param>
/// <param name="stealth">bool, to check if the ban is a stealth ban.</param>
/// <param name="oldrank">The rank the who player used to have.</param>
public static void Banplayer(Player p, string who, string reason, bool stealth, string oldrank)
{
// Getting date and time.
string dayname = DateTime.Now.DayOfWeek.ToString();
string daynumber = DateTime.Now.Day.ToString();
string month = DateTime.Now.Month.ToString();
string year = DateTime.Now.Year.ToString();
string hour = DateTime.Now.Hour.ToString();
string minute = DateTime.Now.Minute.ToString();
// Creating date + time string that looks nice to read:
string datetime = dayname + "%20" + daynumber + "%20" + month + "%20" + year + ",%20at%20" + hour + ":" + minute;
// checking if p = player or console
string player;
if (p == null) player = "Console";
else player = p.name;
// Checking stealth
string stealthn;
if (stealth) stealthn = "true";
else stealthn = "false";
if (reason == "") reason = "&c-";
Write(player, who, reason, stealthn, datetime, oldrank);
}
static void Write(string pl, string whol, string reasonl, string stealthstr, string datetimel, string oldrankl)
{
if (!File.Exists("text/bans.txt"))
{
File.CreateText("text/bans.txt").Close();
}
File.AppendAllText("text/bans.txt", pl + " " + whol + " " + reasonl + " " + stealthstr + " " + datetimel + " " + oldrankl + "\r\n");
}
public static bool Isbanned(string who)
{
foreach (string line in File.ReadAllLines("text/bans.txt"))
{
if (line.Split(' ')[1] == who) return true;
}
return false;
}
public static string[] Getbandata(string who)
{
string bannedby = "", reason = "", timedate = "", oldrank = "", stealth = "";
foreach (string line in File.ReadAllLines("text/bans.txt"))
{
if (line.Split(' ')[1] == who)
{
bannedby = line.Split(' ')[0];
reason = line.Split(' ')[2];
stealth = line.Split(' ')[3];
timedate = line.Split(' ')[4];
oldrank = line.Split(' ')[5];
}
}
string[] end = { bannedby, reason, timedate, oldrank, stealth };
return end;
}
public static bool Deleteban(string name)
{
bool success = false;
StringBuilder sb = new StringBuilder();
foreach (string line in File.ReadAllLines("text/bans.txt"))
{
if (line.Split(' ')[1] != name)
sb.Append(line + "\r\n");
else
success = true;
}
File.WriteAllText("text/bans.txt", sb.ToString());
return success;
}
public static string Editreason(string who, string reason)
{
bool found = false;
string endproduct = "";
if (Isbanned(who))
{
foreach (string line in File.ReadAllLines("text/bans.txt"))
{
if (line.Split(' ')[1] == who)
{
string replacethis = line.Split(' ')[2];
string oldline = line;
string newline = oldline.Replace(replacethis, reason);
endproduct = endproduct + newline + "\r\n";
found = true;
}
else
{
endproduct = endproduct + line + "\r\n";
}
}
if (found)
{
File.WriteAllText("text/bans.txt", endproduct);
return "";
}
else
{
return "Couldn't find baninfo about this player!";
}
}
else
{
return "This player isn't banned!";
}
}
}
}