-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathEconomy.cs
261 lines (241 loc) · 10.4 KB
/
Economy.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;
namespace MCForge
{
public static class Economy
{
public static class Settings
{
public static bool Enabled = false;
//Maps
public static bool Levels = false;
public static List<Level> LevelsList = new List<Level>();
public class Level
{
public int price;
public string name;
public string x;
public string y;
public string z;
public string type;
}
//Titles
public static bool Titles = false;
public static int TitlePrice = 100;
//Colors
public static bool Colors = false;
public static int ColorPrice = 100;
//Ranks
public static bool Ranks = false;
public static LevelPermission MaxRank = LevelPermission.AdvBuilder;
public static List<Rank> RanksList = new List<Rank>();
public class Rank
{
public Group group;
public int price = 1000;
}
}
public static void Load()
{
if (!File.Exists("properties/economy.properties")) { Server.s.Log("Economy properties don't exist, creating"); File.Create("properties/economy.properties").Close(); Save(); }
using (StreamReader r = File.OpenText("properties/economy.properties"))
{
string line;
while (!r.EndOfStream)
{
line = r.ReadLine().ToLower().Trim();
string[] linear = line.ToLower().Trim().Split(':');
try
{
switch (linear[0])
{
case "enabled":
if (linear[1] == "true") { Settings.Enabled = true; }
else if (linear[1] == "false") { Settings.Enabled = false; }
break;
case "title":
if (linear[1] == "price") { Settings.TitlePrice = int.Parse(linear[2]); }
if (linear[1] == "enabled")
{
if (linear[2] == "true") { Settings.Titles = true; }
else if (linear[2] == "false") { Settings.Titles = false; }
}
break;
case "color":
if (linear[1] == "price") { Settings.ColorPrice = int.Parse(linear[2]); }
if (linear[1] == "enabled")
{
if (linear[2] == "true") { Settings.Colors = true; }
else if (linear[2] == "false") { Settings.Colors = false; }
}
break;
case "rank":
if (linear[1] == "price")
{
Economy.Settings.Rank rnk = new Economy.Settings.Rank();
rnk = Economy.FindRank(linear[2]);
if (rnk == null)
{
rnk = new Economy.Settings.Rank();
rnk.group = Group.Find(linear[2]);
rnk.price = int.Parse(linear[3]);
Economy.Settings.RanksList.Add(rnk);
}
else
{
Economy.Settings.RanksList.Remove(rnk);
rnk.price = int.Parse(linear[3]);
Economy.Settings.RanksList.Add(rnk);
}
}
if (linear[1] == "maxrank")
{
Group grp = Group.Find(linear[2]);
if (grp != null) { Settings.MaxRank = grp.Permission; }
}
if (linear[1] == "enabled")
{
if (linear[2] == "true") { Settings.Ranks = true; }
else if (linear[2] == "false") { Settings.Ranks = false; }
}
break;
case "level":
if (linear[1] == "enabled")
{
if (linear[2] == "true") { Settings.Levels = true; }
else if (linear[2] == "false") { Settings.Levels = false; }
}
if (linear[1] == "levels")
{
Settings.Level lvl = new Settings.Level();
if (FindLevel(linear[2]) != null) { lvl = FindLevel(linear[2]); Settings.LevelsList.Remove(lvl); }
switch (linear[3])
{
case "name":
lvl.name = linear[4];
break;
case "price":
lvl.price = int.Parse(linear[4]);
break;
case "x":
lvl.x = linear[4];
break;
case "y":
lvl.y = linear[4];
break;
case "z":
lvl.z = linear[4];
break;
case "type":
lvl.type = linear[4];
break;
}
Settings.LevelsList.Add(lvl);
}
break;
}
}
catch { }
}
r.Close();
}
Save();
}
public static void Save()
{
if (!File.Exists("properties/economy.properties")) { Server.s.Log("Economy properties don't exist, creating"); }
//Thread.Sleep(2000);
File.Delete("properties/economy.properties");
//Thread.Sleep(2000);
using (StreamWriter w = File.CreateText("properties/economy.properties"))
{
//enabled
w.WriteLine("enabled:" + Settings.Enabled);
//title
w.WriteLine();
w.WriteLine("title:enabled:" + Settings.Titles);
w.WriteLine("title:price:" + Settings.TitlePrice);
//color
w.WriteLine();
w.WriteLine("color:enabled:" + Settings.Colors);
w.WriteLine("color:price:" + Settings.ColorPrice);
//rank
w.WriteLine();
w.WriteLine("rank:enabled:" + Settings.Ranks);
w.WriteLine("rank:maxrank:" + Settings.MaxRank);
foreach (Settings.Rank rnk in Settings.RanksList)
{
w.WriteLine("rank:price:" + rnk.group.name + ":" + rnk.price);
}
//maps
w.WriteLine();
w.WriteLine("level:enabled:" + Settings.Levels);
foreach (Settings.Level lvl in Settings.LevelsList)
{
w.WriteLine();
w.WriteLine("level:levels:" + lvl.name + ":name:" + lvl.name);
w.WriteLine("level:levels:" + lvl.name + ":price:" + lvl.price);
w.WriteLine("level:levels:" + lvl.name + ":x:" + lvl.x);
w.WriteLine("level:levels:" + lvl.name + ":y:" + lvl.y);
w.WriteLine("level:levels:" + lvl.name + ":z:" + lvl.z);
w.WriteLine("level:levels:" + lvl.name + ":type:" + lvl.type);
}
w.Close();
}
}
public static Settings.Level FindLevel(string name)
{
Settings.Level found = null;
foreach (Settings.Level lvl in Settings.LevelsList)
{
try
{
if (lvl.name.ToLower() == name.ToLower())
{
found = lvl;
}
}
catch { }
}
return found;
}
public static Settings.Rank FindRank(string name)
{
Settings.Rank found = null;
foreach (Settings.Rank rnk in Settings.RanksList)
{
try
{
if (rnk.group.name.ToLower() == name.ToLower())
{
found = rnk;
}
}
catch { }
}
return found;
}
public static Economy.Settings.Rank NextRank(Player p)
{
Group foundGroup = p.group;
Group nextGroup = null; bool nextOne = false;
for (int i = 0; i < Group.GroupList.Count; i++)
{
Group grp = Group.GroupList[i];
if (nextOne)
{
if (grp.Permission >= LevelPermission.Nobody) break;
nextGroup = grp;
break;
}
if (grp == foundGroup)
nextOne = true;
}
return Economy.FindRank(nextGroup.name);
}
}
}